OpenGL why not choose a shader program?

Possible duplicate:
Is gldisableClientState required?

In OpenGL, I saw this code that follows this pattern quite often:

glUseProgram(prog_id); // ... do some stuff glUseProgram(0); 

I understand that glUseProgram(0) deselects any shader programs. Now my question is, what does it mean to deselect a shader program?

For example, why or not do something like this in the render loop?

 while(render_loop_condition) { glUseProgram(prog_id); // do some stuff } // various cleanup code glUseProgram(0); 

Like in a rendering loop that uses multiple shader programs, can I do something like this:

 while(render_loop_condition) { glUseProgram(prog_id1); // do some stuff glUseProgram(prog_id2); // do some other stuff } // various cleanup code glUseProgram(0); 
+4
source share
1 answer

He used to avoid any unintended side effects on what happened next. This is fine (and, in my opinion, preferable) to switch between programs inside the method, but choose the default program ( 0 ) at the end of the method. This way, you will not encounter any strange side effect after calling this method.

There are not many side effects that I can think of, but I think that if you draw something with a fixed function, you would accidentally draw using the last program you linked.

And just a note: in the second block of code, you can transfer the first call to glUseProgram outside the while loop to prevent the binding of the same program several times.

+5
source

Source: https://habr.com/ru/post/1438314/


All Articles