iOS texture management fixes
This commit is contained in:
+28
-38
@@ -1995,14 +1995,33 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm
|
|||||||
TextureInfo textureInfo;
|
TextureInfo textureInfo;
|
||||||
JTexture *tex = NULL;
|
JTexture *tex = NULL;
|
||||||
textureInfo.mBits = NULL;
|
textureInfo.mBits = NULL;
|
||||||
|
int rawsize = 0;
|
||||||
|
BYTE* rawdata = NULL;
|
||||||
|
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||||
|
NSData *texData = NULL;
|
||||||
|
UIImage *image = NULL;
|
||||||
|
|
||||||
NSString *path = [NSString stringWithUTF8String: JGE_GET_RES(filename).c_str()];
|
do {
|
||||||
NSData *texData = [[NSData alloc] initWithContentsOfFile:path];
|
if (!fileSystem->OpenFile(filename))
|
||||||
UIImage *image = [[UIImage alloc] initWithData:texData];
|
break;
|
||||||
|
|
||||||
|
rawsize = fileSystem->GetFileSize();
|
||||||
|
rawdata = new BYTE[rawsize];
|
||||||
|
|
||||||
|
if (!rawdata)
|
||||||
|
{
|
||||||
|
fileSystem->CloseFile();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileSystem->ReadFile(rawdata, rawsize);
|
||||||
|
fileSystem->CloseFile();
|
||||||
|
|
||||||
|
texData = [[NSData alloc] initWithBytes:rawdata length:rawsize];
|
||||||
|
image = [[UIImage alloc] initWithData:texData];
|
||||||
CGImageAlphaInfo info;
|
CGImageAlphaInfo info;
|
||||||
BOOL hasAlpha;
|
BOOL hasAlpha;
|
||||||
|
|
||||||
do {
|
|
||||||
info = CGImageGetAlphaInfo(image.CGImage);
|
info = CGImageGetAlphaInfo(image.CGImage);
|
||||||
hasAlpha = ((info == kCGImageAlphaPremultipliedLast) || (info == kCGImageAlphaPremultipliedFirst) || (info == kCGImageAlphaLast) || (info == kCGImageAlphaFirst) ? YES : NO);
|
hasAlpha = ((info == kCGImageAlphaPremultipliedLast) || (info == kCGImageAlphaPremultipliedFirst) || (info == kCGImageAlphaLast) || (info == kCGImageAlphaFirst) ? YES : NO);
|
||||||
|
|
||||||
@@ -2025,7 +2044,7 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm
|
|||||||
}
|
}
|
||||||
|
|
||||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||||
info = hasAlpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipLast;
|
info = /*hasAlpha ?*/ kCGImageAlphaPremultipliedLast /*: kCGImageAlphaNoneSkipLast*/;
|
||||||
|
|
||||||
CGContextRef context =
|
CGContextRef context =
|
||||||
CGBitmapContextCreate(textureInfo.mBits,
|
CGBitmapContextCreate(textureInfo.mBits,
|
||||||
@@ -2037,13 +2056,8 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm
|
|||||||
CGColorSpaceRelease(colorSpace);
|
CGColorSpaceRelease(colorSpace);
|
||||||
CGContextClearRect( context, CGRectMake( 0, 0, textureInfo.mTexWidth, textureInfo.mTexHeight ) );
|
CGContextClearRect( context, CGRectMake( 0, 0, textureInfo.mTexWidth, textureInfo.mTexHeight ) );
|
||||||
CGContextTranslateCTM( context, 0, textureInfo.mTexHeight - textureInfo.mHeight );
|
CGContextTranslateCTM( context, 0, textureInfo.mTexHeight - textureInfo.mHeight );
|
||||||
if(!hasAlpha) {
|
|
||||||
CGContextSetAlpha(context, 1.0f);
|
|
||||||
}
|
|
||||||
CGContextDrawImage( context, CGRectMake( 0, 0, textureInfo.mWidth, textureInfo.mHeight ), image.CGImage );
|
CGContextDrawImage( context, CGRectMake( 0, 0, textureInfo.mWidth, textureInfo.mHeight ), image.CGImage );
|
||||||
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
tex = new JTexture();
|
tex = new JTexture();
|
||||||
|
|
||||||
if (tex)
|
if (tex)
|
||||||
@@ -2056,44 +2070,20 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm
|
|||||||
tex->mHeight = textureInfo.mHeight;
|
tex->mHeight = textureInfo.mHeight;
|
||||||
tex->mTexWidth = textureInfo.mTexWidth;
|
tex->mTexWidth = textureInfo.mTexWidth;
|
||||||
tex->mTexHeight = textureInfo.mTexHeight;
|
tex->mTexHeight = textureInfo.mTexHeight;
|
||||||
|
tex->mBuffer = textureInfo.mBits;
|
||||||
GLuint texid;
|
|
||||||
checkGlError();
|
|
||||||
glGenTextures(1, &texid);
|
|
||||||
tex->mTexId = texid;
|
|
||||||
// glError = glGetError();
|
|
||||||
|
|
||||||
mCurrentTex = texid;
|
|
||||||
glBindTexture(GL_TEXTURE_2D, mCurrentTex); // Bind To The Texture ID
|
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureInfo.mTexWidth, textureInfo.mTexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureInfo.mBits);
|
|
||||||
|
|
||||||
ret = true;
|
|
||||||
} else {
|
} else {
|
||||||
NSLog(@"JTexture for %s not created\n", filename);
|
NSLog(@"JTexture for %s not created\n", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGContextRelease(context);
|
CGContextRelease(context);
|
||||||
|
} while(0);
|
||||||
|
|
||||||
delete [] textureInfo.mBits;
|
if(rawdata)
|
||||||
//delete textureInfo;
|
delete[] rawdata;
|
||||||
|
|
||||||
[image release];
|
[image release];
|
||||||
[texData release];
|
[texData release];
|
||||||
|
|
||||||
if (!ret)
|
|
||||||
{
|
|
||||||
if (tex)
|
|
||||||
delete tex;
|
|
||||||
tex = NULL;
|
|
||||||
}
|
|
||||||
} while(0);
|
|
||||||
|
|
||||||
checkGlError();
|
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
#elif (defined QT_CONFIG)
|
#elif (defined QT_CONFIG)
|
||||||
|
|||||||
Reference in New Issue
Block a user