From d906f67f769f1c497dcee58ce15d3e0e4497688f Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Fri, 24 Jan 2014 02:13:34 -0800 Subject: [PATCH] TGA Images working once again on iOS and OSX runtimes. Image import / compression pipeline fixed -- was broken with TGA support Corrected TGA RLE decompression -- 24bpp RLE compressed TGA's now tested and working. No longer attempting to generate mipmaps for cube maps automatically at runtime. --HG-- branch : nfb --- KREngine/kraken/KRTexture.cpp | 4 +--- KREngine/kraken/KRTextureCube.cpp | 6 +++--- KREngine/kraken/KRTextureManager.cpp | 4 ---- KREngine/kraken/KRTextureTGA.cpp | 24 ++++++++++++------------ KREngine/kraken/KRTextureTGA.h | 3 +++ 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/KREngine/kraken/KRTexture.cpp b/KREngine/kraken/KRTexture.cpp index ba640e5..4bc425f 100644 --- a/KREngine/kraken/KRTexture.cpp +++ b/KREngine/kraken/KRTexture.cpp @@ -79,9 +79,7 @@ void KRTexture::resize(int max_dim) if(!createGLTexture(target_dim)) { getContext().getTextureManager()->memoryChanged(-m_newTextureMemUsed); m_newTextureMemUsed = 0; -// assert(false); -// FINDME - assert commented out .. this crashes the app when running in the debug UI and changing 'Debug-Display' to show the framerate -// the FPS doesn't draw anymore either (the drop shadow draws but the text doesn't) + assert(false); // Failed to create the texture } } } diff --git a/KREngine/kraken/KRTextureCube.cpp b/KREngine/kraken/KRTextureCube.cpp index dcf8e0f..982e6bb 100644 --- a/KREngine/kraken/KRTextureCube.cpp +++ b/KREngine/kraken/KRTextureCube.cpp @@ -89,9 +89,9 @@ bool KRTextureCube::createGLTexture(int lod_max_dim) if(bMipMaps) { GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); } else { - // GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); - GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); - GLDEBUG(glGenerateMipmap(GL_TEXTURE_CUBE_MAP)); + GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + // GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); + // GLDEBUG(glGenerateMipmap(GL_TEXTURE_CUBE_MAP)); } diff --git a/KREngine/kraken/KRTextureManager.cpp b/KREngine/kraken/KRTextureManager.cpp index 58cca0e..6abd66e 100644 --- a/KREngine/kraken/KRTextureManager.cpp +++ b/KREngine/kraken/KRTextureManager.cpp @@ -329,10 +329,6 @@ void KRTextureManager::balanceTextureMemory() } } - if (maxDimActive > 512) maxDimActive = 512; // FINDME - hack to stop the texture resizer from blowing out its brains .. - // when the texture quality goes up to 1024, the app runs for about 2 mins and then - // runs out of memory. - // Resize active textures to balance the memory usage and mipmap levels for(std::set::iterator itr=m_activeTextures_streamer.begin(); itr != m_activeTextures_streamer.end() && memory_available > 0; itr++) { KRTexture *activeTexture = *itr; diff --git a/KREngine/kraken/KRTextureTGA.cpp b/KREngine/kraken/KRTextureTGA.cpp index c6b6a56..163e58b 100644 --- a/KREngine/kraken/KRTextureTGA.cpp +++ b/KREngine/kraken/KRTextureTGA.cpp @@ -77,17 +77,15 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo TGA_HEADER *pHeader = (TGA_HEADER *)m_pData->getStart(); unsigned char *pData = (unsigned char *)pHeader + (long)pHeader->idlength + (long)pHeader->colourmaplength * (long)pHeader->colourmaptype + sizeof(TGA_HEADER); -// -// FINDME - many of the GL constants in here are not defined in GLES2 -#ifdef TARGET_OS_IPHONE +#if TARGET_OS_IPHONEz GLenum base_internal_format = GL_BGRA; #else GLenum base_internal_format = pHeader->bitsperpixel == 24 ? GL_BGR : GL_BGRA; #endif - GLenum internal_format = 0; + GLenum internal_format = GL_RGBA; -#ifndef TARGET_OS_IPHONE +#if !TARGET_OS_IPHONE if(compress) { internal_format = pHeader->bitsperpixel == 24 ? GL_COMPRESSED_RGB_S3TC_DXT1_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; } @@ -169,7 +167,7 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo break; case 10: // rgb + rle switch(pHeader->bitsperpixel) { - case 24: + case 32: { unsigned char *converted_image = (unsigned char *)malloc(pHeader->width * pHeader->height * 4); unsigned char *pSource = pData; @@ -177,7 +175,7 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo unsigned char *pEnd = converted_image + pHeader->height * pHeader->width * 4; if(premultiply_alpha) { while(pDest < pEnd) { - int count = *pSource & 0x7f + 1; + int count = (*pSource & 0x7f) + 1; if(*pSource & 0x80) { // RLE Packet pSource++; @@ -202,7 +200,7 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo } } else { while(pDest < pEnd) { - int count = *pSource & 0x7f + 1; + int count = (*pSource & 0x7f) + 1; if(*pSource & 0x80) { // RLE Packet pSource++; @@ -236,14 +234,14 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo current_lod_max_dim = m_max_lod_max_dim; } break; - case 32: + case 24: { unsigned char *converted_image = (unsigned char *)malloc(pHeader->width * pHeader->height * 4); unsigned char *pSource = pData; unsigned char *pDest = converted_image; unsigned char *pEnd = converted_image + pHeader->height * pHeader->width * 4; while(pDest < pEnd) { - int count = *pSource & 0x7f + 1; + int count = (*pSource & 0x7f) + 1; if(*pSource & 0x80) { // RLE Packet pSource++; @@ -290,6 +288,8 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo return true; } +#if !TARGET_OS_IPHONE + KRTexture *KRTextureTGA::compress(bool premultiply_alpha) { m_pData->lock(); @@ -311,7 +311,7 @@ KRTexture *KRTextureTGA::compress(bool premultiply_alpha) GLint width = 0, height = 0, internal_format, base_internal_format; -#ifndef TARGET_OS_IPHONE + GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width)); GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height)); GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format)); @@ -350,7 +350,6 @@ KRTexture *KRTextureTGA::compress(bool premultiply_alpha) // err will equal GL_INVALID_VALUE when // assert(false); // Unexpected error } -#endif GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0)); getContext().getTextureManager()->selectTexture(0, NULL); @@ -369,6 +368,7 @@ KRTexture *KRTextureTGA::compress(bool premultiply_alpha) return new_texture; } +#endif long KRTextureTGA::getMemRequiredForSize(int max_dim) { diff --git a/KREngine/kraken/KRTextureTGA.h b/KREngine/kraken/KRTextureTGA.h index ddea36d..abca2a8 100644 --- a/KREngine/kraken/KRTextureTGA.h +++ b/KREngine/kraken/KRTextureTGA.h @@ -19,7 +19,10 @@ public: virtual std::string getExtension(); bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, int prev_lod_max_dim, bool compress = false, bool premultiply_alpha = false); + +#if !TARGET_OS_IPHONE virtual KRTexture *compress(bool premultiply_alpha = false); +#endif virtual long getMemRequiredForSize(int max_dim); private: