Further rendering after a call to glFinish?

Started by
3 comments, last by Grumple 13 years, 9 months ago
Hello,

I have a situation where I need to partially render a frame to the back buffer, copy the resultant back buffer contents to a raster image 'cache', then perform further (ie UI) rendering to the back buffer within the same frame. Once this is done I just do a normal swapbuffer() call.

This all seems to work fine (I have tested it a fair amount), but I had a video related crash the other day that got me wondering if this approach could cause problems (I have no real reason at this point to think this was actually the cause).

My general render flow would be:

- clear depth/color buffers
- render some geometry through vbo/ibo
- glFinish()
- glCopyTexSubImage2D() (to a raster buffer)
- render some additional overlay data to back buffer
- SwapBuffers()

Can anyone provide any insight into this? Should I be looking at alternative ways to implement this 'layered' render?

Cheers!
Advertisement
What do you need the 'raster buffer' for?

BTW I do a similar stuff in a renderer, and I have no problems with it.

But I think you don't even need the glFinish(), since glCopyTexSubImage2D flushes the render anyway (AFAIK). Did you try not using glfinish?

Anyway, many will argue against flushing the thing in the middle of the render, so I guess there are better ways to do what you want to do.
glFinish just flushes buffered-up commands, so it's perfectly safe to call it anytime you want. You definitely shouldn't need it at all in this scenario; I've code that pretty much the very same as you're doing but doesn't use it.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Quote:Original post by Grumple
- clear depth/color buffers
- render some geometry through vbo/ibo
- glFinish()
- glCopyTexSubImage2D() (to a raster buffer)
- render some additional overlay data to back buffer
- SwapBuffers()

In practice, the results of this are undefined if something overlaps the rendering area, due to the pixel ownership test. In other words, if some other window opens over your rendering area, then the backbuffer copy will yield undefined pixel values.

Quote:Original post by Grumple
Should I be looking at alternative ways to implement this 'layered' render?

Absolutely. Render everything into a cache texture using an FBO. Then you can do whatever you want with it. Not only is this a much more secure way (no undefined behaviour), it is also much faster as it doesn't require a copy.
Thanks for the quick replies! It sounds like I can safely rule this out as the source of my problem.

Just to clarify, when I said I copy to a 'raster buffer' I should have specifically said a texture. =)

I did know about the FBO option, but have yet to take the time to experiment with them. Switching to using an FBO would likely involve a lot of changes to the code base I am working with and I don't have the bandwidth to do this and deal with any debugging fallout right now. Someday! ;)

I had the glFinish in place before glCopyTexSubImage2D just because it seemed like the 'correct' thing to do (didn't realize glCopyTexSubImage2D would essentially call this itself). A quick test of removing the call seems to have caused no problems...

Thanks again!

This topic is closed to new replies.

Advertisement