Pbuffer read backs

Hello:

The main problem is the following

“glReadPixels” is much slower once it is called on off-screen texture based p-buffer (comparing to when it is called on framebuffer). It seems that even “glGetTexImage” is slow. Please let me know if you have some insights regarding this. I have minimally modified the “simple render to texture” example of the Nvidia SDK. If you replace your original file with this compile and execute, you can change the read back modes by pressing ‘t’ for ‘texture’, and ‘f’ for 'framebuffer. The difference in speed is quite something.

Thanks,

 
 draw_rentex();

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf(camera_mat.mat_array);
    glMultMatrixf(manip[0]->get_mat().mat_array );
	int static frame1=0;

	glRotatef(frame1++ % 360, 0, 1, 0);

    glBindTexture(GL_TEXTURE_2D, render_texture);
	
// slow read back ~20-30(ms)
	if (texReadingBackOn){
		glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, buffer);
	}

    // and draw textured quad with our rendered texture
    glEnable(GL_TEXTURE_2D);
    glBegin( GL_QUADS );
		glTexCoord2f(0, 0);
		glVertex2f(-1, -1);
		glTexCoord2f(0, 1);
		glVertex2f(-1,  1);
		glTexCoord2f(1, 1);
		glVertex2f( 1,  1);
		glTexCoord2f(1, 0);
		glVertex2f( 1, -1);
    glEnd();
    glDisable(GL_TEXTURE_2D);

// fast read back ~1-2(ms)
	if (frameBufferReadingBackOn)
		glReadPixels(0, 0, TEX_SIZE, TEX_SIZE, GL_BGRA_EXT, GL_UNSIGNED_BYTE, buffer);

    drawtext();
    glutSwapBuffers();
 

getteximage is pretty slow, yes.

It is a known problem that reading pack from a render-to-texture pbuffer is very slow. In fact, it has been discussed recently on this board.

A possible workaround might be to draw a full-screen quad to a non-render-to-texture pbuffer and do a readpixels from the that context. I’ve never bothered to do this, though.

If you have access to NVIDIA’s pixel data range extension, use it to mask the download latency.

-Won

That problem persists for all the off-screen p-buffers texture based or not. So please suggest another solution!

Do you think NVIDIA’s pixel data range extension might help? If yes how much?

You said the PBuffers are much slower to read than the “frame buffer” - does that include the frame-buffer’s back buffer?

Try the texture mapped quad idea rendered to the back buffer and read it from there. I don’t know if it will make a difference with the performance you are experiencing.

Just as a test you can try rendering the quad to the front buffer and read from there to validate that the read speed really is different.

Hope that helps.

Hello,
I’ve tried the PDR extensions some time ago with 45.23 old drivers, and found out approx 10% of performance increase using glReadPixels.
However, I’m doing glReadPixels from a Pbuffer, and don’t experience any difference from reading back from the framebuffer.
In some NVidia SDK samples, automatic mipmaps are generated, while performing the draw_rentex(), which makes a significant slow down, at the time you want the texture contents to be effectively generated.

Maybe it is not related with your problem. It`s just from my experience with PBuffer. When I read GL_LUMINANCE8 it was average 10times slower than reading GL_RGB or RGBA and then I did luminance from rgb my way. So its just my idea that hardware is optimalized for base format rgb rgba. So maye it can help when you will read not GL_BGRA_EXT but GL_RGB or GL_RGBA but Im not sure :-)???