用于JPEG的iPhone OpenGL ES纹理管道

用于JPEG的iPhone OpenGL ES纹理管道,iphone,opengl-es,texture2d,Iphone,Opengl Es,Texture2d,我很难让我的纹理管道为JPEG工作。PNG的一切正常,但转换一直是个问题 我通过UIImage和CGBitmapContextCreate按图像数据加载 UIImage* tI = [UIImage imageWithContentsOfFile:fileName]; Image = tI.CGImage; mWidth = CGImageGetWidth(Image); mHeight = CGImageGetHeight(Image); mData = new uint8[mWidth

我很难让我的纹理管道为JPEG工作。PNG的一切正常,但转换一直是个问题

我通过UIImage和CGBitmapContextCreate按图像数据加载

UIImage* tI = [UIImage imageWithContentsOfFile:fileName];
Image = tI.CGImage;

mWidth = CGImageGetWidth(Image);
mHeight = CGImageGetHeight(Image);

mData = new uint8[mWidth * mHeight * 4];

Context = CGBitmapContextCreate(mData, mWidth, mHeight, CGImageGetBitsPerComponent(Image), CGImageGetBytesPerRow(Image), 
                                CGImageGetColorSpace(Image), 
                                CGImageGetBitmapInfo(Image));

CGContextDrawImage(Context, CGRectMake(0.0, 0.0, float(mWidth), float(mHeight)), Image);
CGContextRelease(Context);
然后我通过调用设置我的GLTexture

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->Width(), texture->Height(), 0, GL_RGB, GL_UNSIGNED_BYTE, texture->Data());
我怀疑这个glTexImage2D调用就是问题所在。我一直在使用不同的组合来尝试让事情顺利进行。alpha的BitmapInfo状态为“kCGImageAlphaNoneSkipLast”,因此我不确定是否应该使用RGBA和GL_UNSIGNED_SHORT_5_5_5_1,但到目前为止,我还没有尝试过任何组合。我最接近的是

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->Width(), texture->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->Data());
这给了我非常夸张的质感(颜色边缘可以辨别,但一切都太亮了)


任何帮助都会很好。我正在使用JPEG试图通过PNG节省空间。

您的mData缓冲区太大。JPEG图像不支持alpha,因此每像素只有三个组件(RGB),而PNG(RGBA)通常使用四个组件。

是否应该忽略末尾的额外缓冲区空间?我向GL传递每个组件的宽度、高度和尺寸。。它计算出缓冲区的大小,所以它不应该关心内存中超出该点的内容?