Question

I have a an application which uses OpenGl's fixed-pipeline to render images on screen along with some GUI. Before this takes place, I want to use the shaders-based pipeline, to do some image-processing manipulations on the image, and to render it to a texture. This texture I would then pass on to the existing application. Basically the current flow looks like this:

cpu image --> gpu texture --> fixed-pipeline processing --> display on screen

and I want to make it look like this:

cpu image --> gpu texture --> rendering passes to enhance the image --> gpu texture --> fixed-pipeline processing --> display on screen

My question is this: How do I switch between these different operation modes? I have seen some previous questions (1,2,3,4), but none answers my specific problem. Perhaps it's just a simple matter of unbinding the Vertex Arrays?


Edit

Now that I have a good answer for this question from @Reto Koradi, I have yet another one: Any idea how much time this sort of mode-changing might take? is there any 'flushing' going on when I switch back to the fixed pipeline?

Was it helpful?

Solution

To switch from your shader based rendering back to the fixed pipeline:

glUseProgram(0);

To switch from your FBO rendering back to rendering to the default framebuffer:

glBindFramebuffer(GL_FRAMEBUFFER, 0);

You can use vertex arrays in the fixed pipeline. But if you want to unbind your vertex arrays/buffers, it's the same thing. Just bind 0 to release your bindings, e.g.:

glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

Edit: Answer to follow-up question about the overhead.

The simple answer is... it depends. Overhead for certain operations can be very different depending on platform/hardware. As far as it can be answered in relatively general terms:

  • I'm not aware of any hardware made even moderately recently that still has the full fixed pipeline. Everything made within the last 5-10 years always runs shaders. If you use the legacy fixed pipeline, the driver generates shaders for you. That shader generation could take a bit of time when you switch to the fixed pipeline, but tends to be heavily optimized (as long as people still run old benchmarks), and most likely uses cached shaders. So it shouldn't be very significant.
  • Compiling shaders is expensive. Simply switching shaders is low overhead. I benchmarked it at sub-microsecond times on platforms I worked on, comparable to binding vertex buffers. Could be higher on other platforms, I guess, but e.g. modern games use lots of different shaders, and being able to bind them with low overhead is critical.
  • Binding/unbinding vertex buffers is low overhead. And very heavily optimized in drivers since it has big influence on many commonly used benchmarks, particularly ones that don't generate enough shader load to keep the GPU fully busy
  • The overhead for binding a different draw target (e.g. switching from FBO to default framebuffer) is highly platform dependent. But it's at least moderately expensive on most platforms, and supposedly a pretty bad performance killer on some platforms that shall rename nameless. No reason to worry if you don't switch too frequently, but you definitely don't want to do this more often than needed.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top