gl_renderer readTexture fallback for gles based renderers (#1123)

* * Implement readTexture fallback when texture read-back is not supported ( gles based renderer )

* Add test to support readTexture fallback for non compressed texture only
This commit is contained in:
Harold Comere 2017-07-22 19:05:24 +02:00 committed by Branimir Karadžić
parent ab7adad0c3
commit 4d61bfd35c

View File

@ -2763,6 +2763,42 @@ namespace bgfx { namespace gl
GL_CHECK(glBindTexture(texture.m_target, 0) );
}
else
{
const TextureGL& texture = m_textures[_handle.idx];
const bool compressed = bimg::isCompressed(bimg::TextureFormat::Enum(texture.m_textureFormat) );
if(!compressed)
{
Attachment attachment[1];
attachment[0].handle = _handle;
attachment[0].mip = 0;
attachment[0].layer = 0;
FrameBufferGL frameBuffer;
frameBuffer.create(1, attachment);
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.m_id, attachment[0].mip);
if (!BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) && !BX_ENABLED(BX_PLATFORM_IOS))
{
GL_CHECK(glReadBuffer(GL_COLOR_ATTACHMENT0));
}
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
{
GL_CHECK(glReadPixels(0
, 0
, texture.m_width
, texture.m_height
, m_readPixelsFmt
, GL_UNSIGNED_BYTE
, _data
));
}
frameBuffer.destroy();
}
}
}
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) override