BitmapPtr BmpTextureMover::moveTextureToBmp(GLTexture& tex, int mipmapLevel) { GLContext* pContext = GLContext::getCurrent(); unsigned fbo = pContext->genFBO(); glproc::BindFramebuffer(GL_FRAMEBUFFER, fbo); glproc::FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.getID(), mipmapLevel); FBO::checkError("BmpTextureMover::moveTextureToBmp"); IntPoint size = tex.getMipmapSize(mipmapLevel); BitmapPtr pBmp(new Bitmap(size, getPF())); if (GLContext::getMain()->isGLES() && getPF() == B5G6R5) { BitmapPtr pTmpBmp(new Bitmap(size, R8G8B8)); glReadPixels(0, 0, size.x, size.y, GL_RGB, GL_UNSIGNED_BYTE, pTmpBmp->getPixels()); FilterFlipRGB().applyInPlace(pTmpBmp); pBmp->copyPixels(*pTmpBmp); } else { int glPixelFormat = tex.getGLFormat(getPF()); glReadPixels(0, 0, size.x, size.y, glPixelFormat, tex.getGLType(getPF()), pBmp->getPixels()); } GLContext::checkError("BmpTextureMover::moveTextureToBmp: glReadPixels()"); glproc::FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); pContext->returnFBOToCache(fbo); glproc::BindFramebuffer(GL_FRAMEBUFFER, 0); return pBmp; }
void BmpTextureMover::moveBmpToTexture(BitmapPtr pBmp, GLTexture& tex) { AVG_ASSERT(pBmp->getSize() == tex.getSize()); AVG_ASSERT(getSize() == pBmp->getSize()); AVG_ASSERT(pBmp->getPixelFormat() == getPF()); tex.activate(); unsigned char * pStartPos = pBmp->getPixels(); IntPoint size = tex.getSize(); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size.x, size.y, tex.getGLFormat(getPF()), tex.getGLType(getPF()), pStartPos); tex.generateMipmaps(); GLContext::checkError("BmpTextureMover::moveBmpToTexture: glTexSubImage2D()"); }