OpenGL questions

Ideas, enhancements, feature requests and development related discussion.

OpenGL questions

Postby sascha » Sun May 11, 2008 3:04 pm

I'm looking for a portable way of doing offscreen rendering. I need this to render overlays on the viewports (e.g. tools, or to highlight selections) without redrawing everything.

The current implementation works like this:

* The image is rendered to the back-buffer, just as usual
* When rendering is done, the content of the back-buffer is copied into a texture using glCopyTexImage2D()
* Buffers are flipped
* When something needs to be rendered on top of the viewport, the back-buffer is filled with a screen-filling quad and the previously copied texture, then the overlay is drawn and buffers are flipped.

This works well, but on some graphics cards the glCopyTexImage2D() function is extremely slow, so I can't call it upon each repaint event. It's now only copied when the screen content has changed and the texture is actually needed.

I'd like to use one of the auxiliary buffers instead of the textures, but some graphics cards have no support for them, and it's still a question whether the glCopyPixels() method is fast on all cards.

The third option would be to use pBuffers and render directly into the texture. Does anybody have experience with pBuffers and JOGL? I don't know how to work with them. Are pBuffers supposed to work on all modern graphicscards - what about the render-to-texture extension?
sascha
Site Admin
 
Posts: 2792
Joined: Thu May 20, 2004 9:16 am
Location: Austria

Re: OpenGL questions

Postby dcuny » Sun May 11, 2008 10:31 pm

I was under the impression that the pBuffer was around the longest, followed by the FBO (framebuffer object). I could be wrong about that.

I've always been bad when it comes to figuring out OpenGL stuff. I think I ended up using the FBOs in my code, but my (perhaps faulty) recollection was that my code wouldn't work on my crappy work machine. I could be wrong about that, though. I'll be happy to test stuff on various machines - we've got three different machines here at home, and a couple more at work.
dcuny
 
Posts: 2902
Joined: Fri May 21, 2004 6:07 am

Re: OpenGL questions

Postby sascha » Tue May 13, 2008 9:50 am

I've just tried a pBuffer with the render-to-texture extension and it doesn't work on Linux with the NVIDIA card (it says something like "render-to-texture not supported on X11") :?
The AUX buffers would be the ideal solution, but alas, they're optional (they could make at least one auxiliary buffer mandatory, who needs four after all?).

The thing with copying from the back buffer into a texture works well, but with my performance optimization it causes some troubles: Because copyTexImage2D is kind of slow (on my work machine - it's actually pretty fast on my home desktop, I yet have to check the MacBook), I only update the texture when necessary. But this also means that when a tool is in action (e.g. you move an object), the tool doesn't render itself as overlay, but directly into the viewport. So to get a valid "background image" when the mousebutton is released, I'll have to re-render the viewport without the tool.

The only option I can think of is checking which GL functions are available, use auxiliary buffers if they are available and fallback to the texture copied from the back-buffer. I can also add an option to do this copy-to-texture lazily, so people could switch it on if they experience performance problems.

I really hope that OpenGL 3.0 comes with a reasonable set of mandatory features and leave the optional extensions for vendor-specific bleeding edge stuff.
I could imagine that this kind of incompatibilities is what drive game developers towards DirectX :(
sascha
Site Admin
 
Posts: 2792
Joined: Thu May 20, 2004 9:16 am
Location: Austria

Re: OpenGL questions

Postby John VanSickle » Tue May 13, 2008 1:30 pm

sascha wrote:I'm looking for a portable way of doing offscreen rendering. I need this to render overlays on the viewports (e.g. tools, or to highlight selections) without redrawing everything.

The current implementation works like this:

* The image is rendered to the back-buffer, just as usual
* When rendering is done, the content of the back-buffer is copied into a texture using glCopyTexImage2D()
* Buffers are flipped
* When something needs to be rendered on top of the viewport, the back-buffer is filled with a screen-filling quad and the previously copied texture, then the overlay is drawn and buffers are flipped.

Can't you copy the displayed buffer to the back buffer? If so, then it should be a simple matter to make the copy, clear the depth buffer (or turn off depth testing altogether), render the overlays into the back-buffer.
John VanSickle
 
Posts: 189
Joined: Sat Feb 16, 2008 2:17 am

Re: OpenGL questions

Postby sascha » Tue May 13, 2008 3:29 pm

I don't understand.

What I'd need is a method to draw overlays (cheap) without the need to re-render the viewports (potentially expensive).

Imagine a scene with a complex model that takes 100ms to render. Now if the user hovers the mousepointer over the models, the face under the pointer should become highlighted. I don't like these XOR highlighting modes, so I'd like to render a semi-transparent yellow face as highlight. Traditionally this would require a repaint of the entire viewport (100ms in this example) each time the highlighted face changed. If however the viewport contents (without the highlights) as stored in a different buffer or texture, only the buffer/texture content has to be clipped into the back-buffer before the new highlight can be drawn, which should be much faster.

Did I miss something obvious?

Anyway, I'm currently reimplementing it using the strategy pattern. I've got three strategies:
1. Use auxiliary buffer (not available on all GL implementations)
2. Use texture and update it with every redraw (slow on some implementations)
3. Use texture and update it lazily (should work everywhere, but requires an extra viewport-repaint in some circumstances)

I'll make 1 the default on systems where the AUX buffers are available, and 3 on all other systems (with the possibility of using 2 by manual override).
If someone comes up with a better idea it should be easy to implement it as another strategy (and perhaps using it as default).
sascha
Site Admin
 
Posts: 2792
Joined: Thu May 20, 2004 9:16 am
Location: Austria


Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron