From 24e6d8c73c62cf2b03bdcf3a13ee5e0271849138 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Thu, 25 Jun 2020 17:34:48 -0500 Subject: [PATCH] partial followup to #202. largely cleanups, though does include glCopyImageSubData for gl revs that support it TODOS: 1) non glCopyImageSubData for `void GFXGLCubemapArray::copyTo(GFXCubemapArray *pDstCubemap)` 2) while we don't get corruption showing in >0 mips for irradiance maps using the newer code, it nevertheless renders wrong. not 100% sure if renderdoc is showing blank mips because it expects it due to size, or if we are in fact generating em even though we don't use em in the end for irradiance references. --- Engine/source/gfx/gl/gfxGLCubemap.cpp | 2 +- Engine/source/gfx/gl/gfxGLDevice.cpp | 33 ++++++++++++--------- Engine/source/gfx/gl/gfxGLTextureObject.cpp | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Engine/source/gfx/gl/gfxGLCubemap.cpp b/Engine/source/gfx/gl/gfxGLCubemap.cpp index 541cd4fc7..7d70c1795 100644 --- a/Engine/source/gfx/gl/gfxGLCubemap.cpp +++ b/Engine/source/gfx/gl/gfxGLCubemap.cpp @@ -227,7 +227,7 @@ void GFXGLCubemap::initDynamic(U32 texSize, GFXFormat faceFormat, U32 mipLevels) } } - if( !isCompressed ) + if( !isCompressed && !mipLevels) glGenerateMipmap(GL_TEXTURE_CUBE_MAP); mInitialized = true; } diff --git a/Engine/source/gfx/gl/gfxGLDevice.cpp b/Engine/source/gfx/gl/gfxGLDevice.cpp index 57066acf9..5c9c8aea2 100644 --- a/Engine/source/gfx/gl/gfxGLDevice.cpp +++ b/Engine/source/gfx/gl/gfxGLDevice.cpp @@ -475,28 +475,33 @@ void GFXGLDevice::copyResource(GFXTextureObject* pDst, GFXCubemap* pSrc, const U const bool isCompressed = ImageUtil::isCompressedFormat(format); - U32 mipLevels = pGLSrc->getMipMapLevels(); - if (mipLevels < 1) mipLevels = 1;//ensure we loop at least the once + U32 mipLevels = gGLDst->getMipLevels(); for (U32 mip = 0; mip < mipLevels; mip++) { - U8* pixelData = pGLSrc->getTextureData(face, mip); - - glBindTexture(gGLDst->getBinding(), gGLDst->getHandle()); const U32 mipSize = getMax(U32(1), pGLSrc->getSize() >> mip); - if (isCompressed) + if (GFXGL->mCapabilities.copyImage) { - const U32 mipDataSize = getCompressedSurfaceSize(format, pGLSrc->getSize(), pGLSrc->getSize(), 0); - - glCompressedTexSubImage2D(gGLDst->getBinding(), mip, 0, 0, mipSize, mipSize, GFXGLTextureFormat[format], mipDataSize, pixelData); + glCopyImageSubData(pGLSrc->mCubemap, GL_TEXTURE_CUBE_MAP, mip, 0, 0, face, gGLDst->getHandle(), GL_TEXTURE_2D, mip, 0, 0, 0, mipSize, mipSize, 1); } else { - //glCopyImageSubData(pGLSrc->mCubemap, GFXGLCubemap::getEnumForFaceNumber(face), mip, 0, 0, face, gGLDst->getHandle(), GL_TEXTURE_2D, mip, 0, 0, 0, mipSize, mipSize, mip); - glTexSubImage2D(gGLDst->getBinding(), mip, 0, 0, mipSize, mipSize, GFXGLTextureFormat[format], GFXGLTextureType[format], pixelData); - } - glBindTexture(gGLDst->getBinding(), 0); + U8* pixelData = pGLSrc->getTextureData(face, mip); - delete[] pixelData; + glBindTexture(gGLDst->getBinding(), gGLDst->getHandle()); + if (isCompressed) + { + const U32 mipDataSize = getCompressedSurfaceSize(format, pGLSrc->getSize(), pGLSrc->getSize(), 0); + + glCompressedTexSubImage2D(gGLDst->getBinding(), mip, 0, 0, mipSize, mipSize, GFXGLTextureFormat[format], mipDataSize, pixelData); + } + else + { + glTexSubImage2D(gGLDst->getBinding(), mip, 0, 0, mipSize, mipSize, GFXGLTextureFormat[format], GFXGLTextureType[format], pixelData); + } + glBindTexture(gGLDst->getBinding(), 0); + + delete[] pixelData; + } } } diff --git a/Engine/source/gfx/gl/gfxGLTextureObject.cpp b/Engine/source/gfx/gl/gfxGLTextureObject.cpp index 4dac801d3..29c18bf6f 100644 --- a/Engine/source/gfx/gl/gfxGLTextureObject.cpp +++ b/Engine/source/gfx/gl/gfxGLTextureObject.cpp @@ -177,7 +177,6 @@ bool GFXGLTextureObject::copyToBmp(GBitmap * bmp) U32 mipLevels = getMipLevels(); - if (mipLevels < 1) mipLevels = 1;//ensure we loop at least the once for (U32 mip = 0; mip < mipLevels; mip++) { U32 srcPixelCount = bmp->getSurfaceSize(mip)/ srcBytesPerPixel; @@ -207,6 +206,7 @@ bool GFXGLTextureObject::copyToBmp(GBitmap * bmp) } } } + glBindTexture(mBinding, NULL); PROFILE_END(); return true;