| 481 | } |
| 482 | |
| 483 | void GFXGLDevice::copyResource(GFXTextureObject* pDst, GFXCubemap* pSrc, const U32 face) |
| 484 | { |
| 485 | AssertFatal(pDst, "GFXGLDevice::copyResource: Destination texture is null"); |
| 486 | AssertFatal(pSrc, "GFXGLDevice::copyResource: Source cubemap is null"); |
| 487 | |
| 488 | GFXGLTextureObject* gGLDst = static_cast<GFXGLTextureObject*>(pDst); |
| 489 | GFXGLCubemap* pGLSrc = static_cast<GFXGLCubemap*>(pSrc); |
| 490 | |
| 491 | const GFXFormat format = pGLSrc->getFormat(); |
| 492 | const bool isCompressed = ImageUtil::isCompressedFormat(format); |
| 493 | const U32 mipLevels = pGLSrc->getMipMapLevels(); |
| 494 | const U32 texSize = pGLSrc->getSize(); |
| 495 | |
| 496 | //set up pbo if we don't have copyImage support |
| 497 | if (!GFXGL->mCapabilities.copyImage) |
| 498 | { |
| 499 | const GLuint pbo = gGLDst->getBuffer(); |
| 500 | glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); |
| 501 | //allocate data |
| 502 | glBufferData(GL_PIXEL_PACK_BUFFER, texSize * texSize * GFXFormat_getByteSize(format), NULL, GL_STREAM_COPY); |
| 503 | } |
| 504 | |
| 505 | for (U32 mip = 0; mip < mipLevels; mip++) |
| 506 | { |
| 507 | const U32 mipSize = texSize >> mip; |
| 508 | if (GFXGL->mCapabilities.copyImage) |
| 509 | { |
| 510 | glCopyImageSubData(pGLSrc->mCubemap, GL_TEXTURE_CUBE_MAP, mip, 0, 0, face, gGLDst->getHandle(), GL_TEXTURE_2D, mip, 0, 0, 0, mipSize, mipSize, 1); |
| 511 | } |
| 512 | else |
| 513 | { |
| 514 | //pbo id |
| 515 | const GLuint pbo = gGLDst->getBuffer(); |
| 516 | |
| 517 | //copy source texture data to pbo |
| 518 | glBindTexture(GL_TEXTURE_CUBE_MAP, pGLSrc->mCubemap); |
| 519 | glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); |
| 520 | |
| 521 | if (isCompressed) |
| 522 | glGetCompressedTexImage(GFXGLFaceType[face], mip, NULL); |
| 523 | else |
| 524 | glGetTexImage(GFXGLFaceType[face], mip, GFXGLTextureFormat[format], GFXGLTextureType[format], NULL); |
| 525 | |
| 526 | glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); |
| 527 | glBindTexture(GL_TEXTURE_CUBE_MAP, 0); |
| 528 | |
| 529 | //copy data from pbo to destination |
| 530 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); |
| 531 | glBindTexture(gGLDst->getBinding(), gGLDst->getHandle()); |
| 532 | |
| 533 | if (isCompressed) |
| 534 | { |
| 535 | const U32 mipDataSize = getCompressedSurfaceSize(format, pGLSrc->getSize(), pGLSrc->getSize(), 0); |
| 536 | glCompressedTexSubImage2D(gGLDst->getBinding(), mip, 0, 0, mipSize, mipSize, GFXGLTextureFormat[format], mipDataSize, NULL); |
| 537 | } |
| 538 | else |
| 539 | { |
| 540 | glTexSubImage2D(gGLDst->getBinding(), mip, 0, 0, mipSize, mipSize, GFXGLTextureFormat[format], GFXGLTextureType[format], NULL); |
no test coverage detected