mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-23 00:23:46 +00:00
Merge pull request #238 from Azaezel/alpha40_gl_cubemapWipwork
fix cubemap capture for gl
This commit is contained in:
commit
d86c6aff35
5 changed files with 71 additions and 38 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue