Merge pull request #238 from Azaezel/alpha40_gl_cubemapWipwork

fix cubemap capture for gl
This commit is contained in:
Brian Roberts 2020-07-05 20:38:53 -05:00 committed by GitHub
commit d86c6aff35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 38 deletions

View file

@ -471,32 +471,61 @@ void GFXGLDevice::copyResource(GFXTextureObject* pDst, GFXCubemap* pSrc, const U
GFXGLTextureObject* gGLDst = static_cast<GFXGLTextureObject*>(pDst);
GFXGLCubemap* pGLSrc = static_cast<GFXGLCubemap*>(pSrc);
GFXFormat format = pGLSrc->getFormat();
const GFXFormat format = pGLSrc->getFormat();
const bool isCompressed = ImageUtil::isCompressedFormat(format);
const U32 mipLevels = pGLSrc->getMipMapLevels();
const U32 texSize = pGLSrc->getSize();
//set up pbo if we don't have copyImage support
if (!GFXGL->mCapabilities.copyImage)
{
const GLuint pbo = gGLDst->getBuffer();
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
//allocate data
glBufferData(GL_PIXEL_PACK_BUFFER, texSize * texSize * GFXFormat_getByteSize(format), NULL, GL_STREAM_COPY);
}
U32 mipLevels = pGLSrc->getMipMapLevels();
if (mipLevels < 1) mipLevels = 1;//ensure we loop at least the once
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)
const U32 mipSize = texSize >> mip;
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);
//pbo id
const GLuint pbo = gGLDst->getBuffer();
delete[] pixelData;
//copy source texture data to pbo
glBindTexture(GL_TEXTURE_CUBE_MAP, pGLSrc->mCubemap);
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
if (isCompressed)
glGetCompressedTexImage(GFXGLFaceType[face], mip, NULL);
else
glGetTexImage(GFXGLFaceType[face], mip, GFXGLTextureFormat[format], GFXGLTextureType[format], NULL);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
//copy data from pbo to destination
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
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, NULL);
}
else
{
glTexSubImage2D(gGLDst->getBinding(), mip, 0, 0, mipSize, mipSize, GFXGLTextureFormat[format], GFXGLTextureType[format], NULL);
}
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glBindTexture(gGLDst->getBinding(), 0);
}
}
}