Hi,
I found a fast way to read data from the framebuffer. It’s faster than read data using glReadPixels directly.
First we draw the geometry into the buffer. Then a texture is binded. At last using the following code to read the data from the texture:
void ReadTexture(GLenum target, GLuint texture, float* pImage, GLenum format = GL_RGB,
GLint level = 0, char *argstring = NULL)
{
int w, h;
int prevTexBind;
glGetIntegerv(target, &prevTexBind);
glBindTexture(target, texture);
glGetTexLevelParameteriv(target, 0, GL_TEXTURE_WIDTH, &w);
glGetTexLevelParameteriv(target, 0, GL_TEXTURE_HEIGHT, &h);
glGetTexImage(target, level, format, GL_FLOAT, pImage);
std::string s = (NULL == argstring) ? format2string(format) : argstring;
glBindTexture(target, prevTexBind);
}
I don’t know why it’s faster than glReadPixels, but I tested it using the following codes.
for(int i = 0; i < 256; i++)
{
...
glReadPixels(...);
...
}
for(int i = 0; i < 256; i++)
{
...
glBindTexture(...);
glCopyTexImage2D(...);
ReadTexture(...);
...
}
Who can explain the reasons?
Thank you.