3
  • is it possible to do GPU accelerated 3D rendering faster than screen refresh rate?

  • is it possible to do it with OpenGL? If yes, how, if not, what tool to use?

note

since I want the rendering to be faster than screen refresh rate, I don't mind not having output to the screen. In fact, not having an output window would be an advantage.

I will use render output either programatically (via glReadPixels for example), or outputting to a file as a video for humans to watch it later.

why I want to do this

I want to do computer simulations of robots for computer vision. The simulated robot will have a virtual camera to see this world, and will act depending on the camera input. Therefore, I want simulations to run as fast as possible, disregarding screen refresh rates.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985

2 Answers2

7

Yes, this should definitely be possible with OpenGL. Rendering rate isn't tied to screen refresh rate (this is why you can see demos running at 500 FPS and suchlike).

As for the mechanics, you can render into an offscreen framebuffer and read the resulting image back into main memory. You can then process / analyse it however you like. See:

Community
  • 1
  • 1
mikera
  • 105,238
  • 25
  • 256
  • 415
1

to do it with OpenGL, I had to simply replace the glutSwapBuffers at the end of my display callback function by a glFlush, which took me from 60FPS to 600FPS on a very simple scene.

glutSwapBuffers ensures that each calculated frame is displayed, and therefore stops your program until the screen is refreshed, at which time it puts the back buffer into the front buffer, which can be seen on the screen.

glFlush on the other hand, only ensures that the scene has been calculated and updates the backbuffer (which cannot be seen on the screen) with the new scene. Therefore the new scene calculation stops only until the new scene has been rendered. glutSwapBuffers calls glFlush before swapping the buffers to ensure that the scene has been calculated.

note

on my application, glReadPixels allowed me to read the pixels correctly even without glutSwapBuffers, so it is reading from the backbuffer.

however, there is a great performance penalty in merely calling glReadPixels to retrieve 700 pixels: FPS fell to 200FPS. I'm guessing this is because the backbuffer must be somewhere on GPU memory (please correct/confirm this), and glReadPixels is doing GPU -> CPU communication, which is very costly.

This means that however fast the render is calculated, my application will still be bottlenecked at 200FPS, unless I grow up and learn how to do the processing on a GPGPU and access the backbuffer from there.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985