Take the 2-minute tour ×

After i have been played for some days with various vertex and fragments shaders seems clear to me that this programs are called by the GPU at every and each rendering cycle, the problem is that I can't really quantify this frequency and I can't tell if is based on some default values or not because I don't have a big collection of hardware right now to do extensive tests.

For what i know the answer could be really trivial like "it's the same of the refresh rate of your monitor", but i would like some good answers on that to be clear on this.

For instance looks really odd to me that all the techniques used to control the amount of FPS that i have seen until now uses a call for the OpenGL function glutGet(GLUT_ELAPSED_TIME) to retrieve a value in ms about when the rendering started but I have to relies on the CPU to do the math. Why I can't set an FPS value in OpenGL if OpenGL clearly has a counter and a timer/clock?

PS I'm referring to OpenGL 3.0+

share|improve this question
Are you talking about frame rates or shader call frequencies? The first depends on your application, the second shouldn't matter to you (unless you're in driver/hw devel). –  Jari Komppa Aug 30 '12 at 11:43
@JariKomppa both, and above all the things, if OpenGL has a timer why i can't use it? It would make things much more easier. –  user827992 Aug 30 '12 at 11:49
That's.. not.. how opengl works. It's just a render pipeline. –  Jari Komppa Aug 30 '12 at 11:50
Framerate may be limited by your display refresh rate (if vertical sync is enabled). It may be lower than that, depending on how your program commands rendering. If you, for example, sleep() couple seconds after each frame, the framerate will be rather low. –  Jari Komppa Aug 30 '12 at 11:54
Shader rates depend on your draw calls. For example, if you render one triangle, that will lead to execution of (at least) three vertex shaders and zero to lots of fragment shaders. Depending on stuff (and gl version) you're using there may also be other shader stages executed various times. But all of this is rather irrelevant for a software developer, apart from the general concept. –  Jari Komppa Aug 30 '12 at 11:55
show 4 more comments

1 Answer

up vote 7 down vote accepted

What are the factors that determine the default frequency of a shader call?

There's no such thing as a default frequency for a shader call. It depends of course on the game's frame rate, but not only.

Vertex shaders are called for each vertice of a primitive rendering. The call frequency will depend on how many primitives you render, on the current view frustum (culling), on the number of passes required by the rendering techniques...

Fragments shaders are called for each sample of each pixel of each rasterized primitive. The call frequency will depend on the same as above, plus the viewport or the render target sizes, how many post processes are run...


If by "in OpenGL" you mean in shader code, the reason is a consequence of what precedes: your shader programs can be executed a "random" number of times a second, so you can't infer the FPS from them.

Note that glutGet(GLUT_ELAPSED_TIME) is indeed an OpenGL-related function (actually, a GLUT function), but this doesn't mean that it's accessible by shaders. It isn't. Even if you could add a performance timer in shader code, you'd have no way to output your results, so this would be useless.

share|improve this answer
-1: "Fragments shaders are called for each pixel of each rasterized primitive." WRONG!!! There is a reason why OpenGL did not adopt D3D's term "Pixel shader". That's because it doesn't deal in pixels; it deals in fragments. Which are based on rasterization into samples. It is executed for every sample of the rasterized primitive, which may be more than the pixel area of the primitive. –  Nicol Bolas Aug 30 '12 at 22:58
@NicolBolas Wrong in bold and italic plus three exclamation marks, with a downvote? Care to add a link that explains how those samples are something completely different than pixels and why mixing the concepts is such a bad thing? –  Laurent Couvidou Aug 31 '12 at 8:45
Just look up "supersampling". Or read the OpenGL specification. –  Nicol Bolas Aug 31 '12 at 9:30
OK, I get your point, editing my answer. –  Laurent Couvidou Aug 31 '12 at 11:49
add comment

Your Answer


