iOS texture management fixes
This commit is contained in:
+74
-84
@@ -1992,109 +1992,99 @@ void JRenderer::LoadGIF(TextureInfo &textureInfo, const char *filename, int mode
|
|||||||
|
|
||||||
JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureFormat __attribute__((unused)))
|
JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureFormat __attribute__((unused)))
|
||||||
{
|
{
|
||||||
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;
|
||||||
CGImageAlphaInfo info;
|
|
||||||
BOOL hasAlpha;
|
|
||||||
|
|
||||||
do {
|
rawsize = fileSystem->GetFileSize();
|
||||||
info = CGImageGetAlphaInfo(image.CGImage);
|
rawdata = new BYTE[rawsize];
|
||||||
hasAlpha = ((info == kCGImageAlphaPremultipliedLast) || (info == kCGImageAlphaPremultipliedFirst) || (info == kCGImageAlphaLast) || (info == kCGImageAlphaFirst) ? YES : NO);
|
|
||||||
|
|
||||||
if (image == nil) {
|
if (!rawdata)
|
||||||
NSLog(@"Loading Texture : %s failed", filename);
|
{
|
||||||
break;
|
fileSystem->CloseFile();
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
textureInfo.mWidth = CGImageGetWidth(image.CGImage);
|
fileSystem->ReadFile(rawdata, rawsize);
|
||||||
textureInfo.mHeight = CGImageGetHeight(image.CGImage);
|
fileSystem->CloseFile();
|
||||||
textureInfo.mTexWidth = getNextPower2(textureInfo.mWidth);
|
|
||||||
textureInfo.mTexHeight = getNextPower2(textureInfo.mHeight);
|
|
||||||
|
|
||||||
NSLog(@"Loading Texture : %s : %s : %ux%u", filename, (hasAlpha?"Alpha ":"No Alpha "), textureInfo.mWidth, textureInfo.mHeight);
|
texData = [[NSData alloc] initWithBytes:rawdata length:rawsize];
|
||||||
|
image = [[UIImage alloc] initWithData:texData];
|
||||||
|
CGImageAlphaInfo info;
|
||||||
|
BOOL hasAlpha;
|
||||||
|
|
||||||
textureInfo.mBits = new u8 [ textureInfo.mTexHeight * textureInfo.mTexWidth * 4 ];
|
info = CGImageGetAlphaInfo(image.CGImage);
|
||||||
if (textureInfo.mBits == NULL) {
|
hasAlpha = ((info == kCGImageAlphaPremultipliedLast) || (info == kCGImageAlphaPremultipliedFirst) || (info == kCGImageAlphaLast) || (info == kCGImageAlphaFirst) ? YES : NO);
|
||||||
NSLog(@"Texture %s failed to load\n", filename);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
if (image == nil) {
|
||||||
info = hasAlpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipLast;
|
NSLog(@"Loading Texture : %s failed", filename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
CGContextRef context =
|
textureInfo.mWidth = CGImageGetWidth(image.CGImage);
|
||||||
CGBitmapContextCreate(textureInfo.mBits,
|
textureInfo.mHeight = CGImageGetHeight(image.CGImage);
|
||||||
textureInfo.mTexWidth,
|
textureInfo.mTexWidth = getNextPower2(textureInfo.mWidth);
|
||||||
textureInfo.mTexHeight, 8,
|
textureInfo.mTexHeight = getNextPower2(textureInfo.mHeight);
|
||||||
4 * textureInfo.mTexWidth,
|
|
||||||
colorSpace,
|
|
||||||
info /*| kCGBitmapByteOrder32Big*/);
|
|
||||||
CGColorSpaceRelease(colorSpace);
|
|
||||||
CGContextClearRect( context, CGRectMake( 0, 0, textureInfo.mTexWidth, textureInfo.mTexHeight ) );
|
|
||||||
CGContextTranslateCTM( context, 0, textureInfo.mTexHeight - textureInfo.mHeight );
|
|
||||||
if(!hasAlpha) {
|
|
||||||
CGContextSetAlpha(context, 1.0f);
|
|
||||||
}
|
|
||||||
CGContextDrawImage( context, CGRectMake( 0, 0, textureInfo.mWidth, textureInfo.mHeight ), image.CGImage );
|
|
||||||
|
|
||||||
bool ret = false;
|
NSLog(@"Loading Texture : %s : %s : %ux%u", filename, (hasAlpha?"Alpha ":"No Alpha "), textureInfo.mWidth, textureInfo.mHeight);
|
||||||
|
|
||||||
tex = new JTexture();
|
textureInfo.mBits = new u8 [ textureInfo.mTexHeight * textureInfo.mTexWidth * 4 ];
|
||||||
|
if (textureInfo.mBits == NULL) {
|
||||||
|
NSLog(@"Texture %s failed to load\n", filename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (tex)
|
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||||
{
|
info = /*hasAlpha ?*/ kCGImageAlphaPremultipliedLast /*: kCGImageAlphaNoneSkipLast*/;
|
||||||
if (mImageFilter != NULL)
|
|
||||||
mImageFilter->ProcessImage((PIXEL_TYPE*)textureInfo.mBits, textureInfo.mWidth, textureInfo.mHeight);
|
|
||||||
|
|
||||||
tex->mFilter = TEX_FILTER_LINEAR;
|
CGContextRef context =
|
||||||
tex->mWidth = textureInfo.mWidth;
|
CGBitmapContextCreate(textureInfo.mBits,
|
||||||
tex->mHeight = textureInfo.mHeight;
|
textureInfo.mTexWidth,
|
||||||
tex->mTexWidth = textureInfo.mTexWidth;
|
textureInfo.mTexHeight, 8,
|
||||||
tex->mTexHeight = textureInfo.mTexHeight;
|
4 * textureInfo.mTexWidth,
|
||||||
|
colorSpace,
|
||||||
|
info /*| kCGBitmapByteOrder32Big*/);
|
||||||
|
CGColorSpaceRelease(colorSpace);
|
||||||
|
CGContextClearRect( context, CGRectMake( 0, 0, textureInfo.mTexWidth, textureInfo.mTexHeight ) );
|
||||||
|
CGContextTranslateCTM( context, 0, textureInfo.mTexHeight - textureInfo.mHeight );
|
||||||
|
CGContextDrawImage( context, CGRectMake( 0, 0, textureInfo.mWidth, textureInfo.mHeight ), image.CGImage );
|
||||||
|
|
||||||
GLuint texid;
|
tex = new JTexture();
|
||||||
checkGlError();
|
|
||||||
glGenTextures(1, &texid);
|
|
||||||
tex->mTexId = texid;
|
|
||||||
// glError = glGetError();
|
|
||||||
|
|
||||||
mCurrentTex = texid;
|
if (tex)
|
||||||
glBindTexture(GL_TEXTURE_2D, mCurrentTex); // Bind To The Texture ID
|
{
|
||||||
|
if (mImageFilter != NULL)
|
||||||
|
mImageFilter->ProcessImage((PIXEL_TYPE*)textureInfo.mBits, textureInfo.mWidth, textureInfo.mHeight);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
tex->mFilter = TEX_FILTER_LINEAR;
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
tex->mWidth = textureInfo.mWidth;
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
tex->mHeight = textureInfo.mHeight;
|
||||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
tex->mTexWidth = textureInfo.mTexWidth;
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureInfo.mTexWidth, textureInfo.mTexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureInfo.mBits);
|
tex->mTexHeight = textureInfo.mTexHeight;
|
||||||
|
tex->mBuffer = textureInfo.mBits;
|
||||||
|
} else {
|
||||||
|
NSLog(@"JTexture for %s not created\n", filename);
|
||||||
|
}
|
||||||
|
|
||||||
ret = true;
|
CGContextRelease(context);
|
||||||
} else {
|
} while(0);
|
||||||
NSLog(@"JTexture for %s not created\n", filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
CGContextRelease(context);
|
if(rawdata)
|
||||||
|
delete[] rawdata;
|
||||||
|
|
||||||
delete [] textureInfo.mBits;
|
[image release];
|
||||||
//delete textureInfo;
|
[texData release];
|
||||||
|
|
||||||
[image release];
|
return tex;
|
||||||
[texData release];
|
|
||||||
|
|
||||||
if (!ret)
|
|
||||||
{
|
|
||||||
if (tex)
|
|
||||||
delete tex;
|
|
||||||
tex = NULL;
|
|
||||||
}
|
|
||||||
} while(0);
|
|
||||||
|
|
||||||
checkGlError();
|
|
||||||
return tex;
|
|
||||||
}
|
}
|
||||||
#elif (defined QT_CONFIG)
|
#elif (defined QT_CONFIG)
|
||||||
JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureFormat __attribute__((unused)))
|
JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureFormat __attribute__((unused)))
|
||||||
|
|||||||
Reference in New Issue
Block a user