Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does OpenGL prevent unnecessary API calls?

Currently I have around 15 render passes in my pipeline. For every pass, I set the correct settings before drawing and reset them afterwards. Those settings include viewport size, depth test on or off, blending function or off, stencil function, stencil operation, and more.

I wonder whether OpenGL is clever enough to ignore API calls which set a state that is already present. Because otherwise I would keep track of the state with a lot of flags and before a render pass only set the state if it is actually necessary.

like image 523
danijar Avatar asked Jun 17 '13 08:06

danijar


Video Answer


1 Answers

The short answer: It depends on the driver.

OpenGL itself doesn't do much of anything. It is up to vendors to implement the functions specified by the standard any way they see fit. Do they usually test the existing state to avoid unnecessarily stalling the pipeline? Perhaps, but short of reading advice from vendors or measuring performance yourself, there is no way to know for sure.

The consensus of the advice I have seen (no reference for this as it is spread around all over the place), is that you should avoid calling OpenGL with redundant state changes. It can't do very much harm and it might do some good.

In your case (changing state a few times per frame between passes), it probably won't make much difference.

like image 122
GuyRT Avatar answered Sep 29 '22 01:09

GuyRT