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
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<KRTexture *>::iterator itr=m_activeTextures_streamer.begin(); itr != m_activeTextures_streamer.end() && memory_available > 0; itr++) {
|
||||
KRTexture *activeTexture = *itr;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user