2
votes

I have a program where I use a shader program to render to a texture attached to a FBO then change the parameters of the program (by changing the values of the uniforms) and render to a second texture after attaching it to the FBO. The two rendered images are then used to generate a third one.

I'm not sure if the results I'm getting is correct. I understand that the GPU will be free to choose the time at which to execute an OpenGL command. But that should not be a problem so long as the order of execution does follow the sequence in which the commands appear in the code. Is this actually the case?

A follow-up question. I need to save the generated frames to disk. I know how to that. But I need to make sure that the GPU has completed the rendering before doing so. How can I enforce that?

1
This will work, provided you never try to sample from the same texture you are drawing into (that will create feedback loops). And generally what you are describing is not a problem, some newer stuff that was introduced to GL4 like image load/store throws a lot of this stuff on its head, but you should pretend I never mentioned that and avoid panicking over a falling sky :)Andon M. Coleman
@AndonM.Coleman Thanks Ando. That's exactly what I'm not so sure about. The steps I'm following are the ones I mention in the comment on user1781290's answer. I use one shader program when drawing to the first two textures, and a second shader program to draw to the third texture. At all times, there is only one FBO. I only change the attached texture at each stage. I also tried adding glFinish() but I still have this mismatch problem I mention in my second comment on user1781290's answer.informer2000

1 Answers

2
votes

OpenGL will execute the commands in the order they're issued (or at least simulate this behavior). This means, that there is no problem with using 2 different FBOs, one after another. Also this means OpenGL will make sure, that your rendering is complete at the time you get your result from the FBO.

You can call glFinish() to have your program wait until all pending OpenGL commands have been processed by the pipeline, but this is unnecessary in almost all cases.