OpenGL: Mipmaps for GFXGLCubemap. Fix compressed textures.

This commit is contained in:
LuisAntonRebollo 2014-12-27 00:01:21 +01:00
parent 2f8f89d486
commit c2c9cf4a2d
2 changed files with 35 additions and 14 deletions

View file

@ -88,13 +88,23 @@ void GFXGLCubemap::fillCubeTextures(GFXTexHandle* faces)
GFXFormat faceFormat = faces[i]->getFormat(); GFXFormat faceFormat = faces[i]->getFormat();
GFXGLTextureObject* glTex = static_cast<GFXGLTextureObject*>(faces[i].getPointer()); GFXGLTextureObject* glTex = static_cast<GFXGLTextureObject*>(faces[i].getPointer());
const U32 mipCount = isCompressed ? mMipLevels : 1; if( isCompressed )
for( U32 mip = 0; mip < mipCount; ++mip )
{ {
U8* buf = glTex->getTextureData( mip ); for( U32 mip = 0; mip < mMipLevels; ++mip )
const U32 mipWidth = getMax( U32(1), faces[i]->getWidth() >> mip ); {
const U32 mipHeight = getMax( U32(1), faces[i]->getHeight() >> mip ); const U32 mipWidth = getMax( U32(1), faces[i]->getWidth() >> mip );
glTexImage2D(faceList[i], mip, GFXGLTextureInternalFormat[faceFormat], mipWidth, mipHeight, const U32 mipHeight = getMax( U32(1), faces[i]->getHeight() >> mip );
const U32 mipDataSize = getCompressedSurfaceSize( mFaceFormat, mWidth, mHeight, mip );
U8* buf = glTex->getTextureData( mip );
glCompressedTexImage2D(faceList[i], mip, GFXGLTextureInternalFormat[mFaceFormat], mipWidth, mipHeight, 0, mipDataSize, buf);
delete[] buf;
}
}
else
{
U8* buf = glTex->getTextureData();
glTexImage2D(faceList[i], 0, GFXGLTextureInternalFormat[faceFormat], mWidth, mHeight,
0, GFXGLTextureFormat[faceFormat], GFXGLTextureType[faceFormat], buf); 0, GFXGLTextureFormat[faceFormat], GFXGLTextureType[faceFormat], buf);
delete[] buf; delete[] buf;
} }
@ -192,16 +202,23 @@ void GFXGLCubemap::initDynamic(U32 texSize, GFXFormat faceFormat)
mWidth = texSize; mWidth = texSize;
mHeight = texSize; mHeight = texSize;
for(U32 i = 0; i < 6; i++) for(U32 i = 0; i < 6; i++)
{ {
const U32 mipCount = isCompressed ? mMipLevels : 1; if( isCompressedFormat(faceFormat) )
for( U32 mip = 0; mip < mipCount; ++mip )
{ {
const U32 mipSize = getMax( U32(1), texSize >> mip ); for( U32 mip = 0; mip < mMipLevels; ++mip )
glTexImage2D( faceList[i], mip, GFXGLTextureInternalFormat[faceFormat], mipSize, mipSize, {
const U32 mipSize = getMax( U32(1), texSize >> mip );
const U32 mipDataSize = getCompressedSurfaceSize( mFaceFormat, texSize, texSize, mip );
glCompressedTexImage2D(faceList[i], mip, GFXGLTextureInternalFormat[mFaceFormat], mipSize, mipSize, 0, mipDataSize, NULL);
}
}
else
{
glTexImage2D( faceList[i], 0, GFXGLTextureInternalFormat[faceFormat], texSize, texSize,
0, GFXGLTextureFormat[faceFormat], GFXGLTextureType[faceFormat], NULL); 0, GFXGLTextureFormat[faceFormat], GFXGLTextureType[faceFormat], NULL);
} }
} }
if( !isCompressed ) if( !isCompressed )
glGenerateMipmap(GL_TEXTURE_CUBE_MAP); glGenerateMipmap(GL_TEXTURE_CUBE_MAP);

View file

@ -255,7 +255,11 @@ U8* GFXGLTextureObject::getTextureData( U32 mip )
U8* data = new U8[dataSize]; U8* data = new U8[dataSize];
PRESERVE_TEXTURE(mBinding); PRESERVE_TEXTURE(mBinding);
glBindTexture(mBinding, mHandle); glBindTexture(mBinding, mHandle);
glGetTexImage(mBinding, mip, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], data);
if( isCompressedFormat(mFormat) )
glGetCompressedTexImage( mBinding, mip, data );
else
glGetTexImage(mBinding, mip, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], data);
return data; return data;
} }