Kaynağa Gözat

OpenGL: Mipmaps for GFXGLCubemap. Fix compressed textures.

LuisAntonRebollo 10 yıl önce
ebeveyn
işleme
c2c9cf4a2d

+ 30 - 13
Engine/source/gfx/gl/gfxGLCubemap.cpp

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

+ 5 - 1
Engine/source/gfx/gl/gfxGLTextureObject.cpp

@@ -255,7 +255,11 @@ U8* GFXGLTextureObject::getTextureData( U32 mip )
    U8* data = new U8[dataSize];
    PRESERVE_TEXTURE(mBinding);
    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;
 }