fix framebuffer read

This commit is contained in:
2018-05-09 12:04:29 +02:00
parent af0e588a94
commit f16adb8fcc
6 changed files with 57 additions and 13 deletions

View File

@@ -74,6 +74,7 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format)
// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
// glBindRenderbuffer(GL_RENDERBUFFER, 0);
GLint oldFboID;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldFboID);
// Create a framebuffer object
@@ -106,7 +107,8 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format)
// Switch back to window-system-provided framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, oldFboID);
oldFboID = 0;
oldRFboID = 0;
oldDFboID = 0;
return status == GL_FRAMEBUFFER_COMPLETE;
}
@@ -123,14 +125,18 @@ void RTT::bindFramebuffer()
}
#endif // _DEBUG
bound = true;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldFboID);
glBindFramebuffer(GL_FRAMEBUFFER, fboID);
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboID);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID);
}
void RTT::unbindFramebuffer()
{
glBindFramebuffer(GL_FRAMEBUFFER, oldFboID);
oldFboID = 0;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDFboID);
glBindFramebuffer(GL_READ_FRAMEBUFFER, oldRFboID);
oldRFboID = 0;
oldDFboID = 0;
bound = false;
}
@@ -147,7 +153,7 @@ void RTT::readTextureData(uint8_t* buffer)
//glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
unbindFramebuffer();
glReadBuffer(GL_NONE);
//glReadBuffer(GL_NONE);
}
uint8_t* RTT::createBuffer()