use glReadPixels for compatibility with OpenGL ES
This commit is contained in:
@@ -115,7 +115,29 @@ Image Texture2D::get_image() const noexcept
|
||||
App::I->render_task([&]
|
||||
{
|
||||
bind();
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, ret.m_data.get());
|
||||
|
||||
GLuint fboID;
|
||||
glGenFramebuffers(1, &fboID);
|
||||
if (fboID == 0)
|
||||
return;
|
||||
|
||||
GLint oldFboID;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldFboID);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fboID);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_tex, 0);
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status == GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, ret.m_data.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("Texture2D::get_image() failed because framebuffer status = %d", (int)status);
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, oldFboID);
|
||||
glDeleteFramebuffers(1, &fboID);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user