Question

I want to know when exactly the vertex and fragment shader is called exactly in the opengl loop. Is it at the end of your glutDisplayFunc() or glutMainLoop(), or is it at every vertex draw call? And do the vertex and fragment get consecutively called one after the other(ie: vertex then fragment), or a completely different times?

Say i have the following snippet of code:

glPushMatrix();
    glRotatef(rot,0.0f,1.0f,0.0);
    glTranslatef(0.0f,0.0f,25);
    glColor3f(0.0,0.0,1.0);
    drawSphere(4,20,20); // draw triangles

    glColor3f(1.0,0.0,0.0);
    glTranslatef(0.0f,0.0f,5);
    drawSphere(4,20,20); // draw triangles
glPopMatrix();

Does the vertex shader get called after each vertex call, then reads the current matrix on top of stack, then send that pre-defined ModelView matrix uniform to the vertex shader? When is the fragment shader run?

Was it helpful?

Solution

Is it at the end of your glutDisplayFunc() or glutMainLoop(),

Neither, because GLUT is not part of OpenGL. It's just some library (for creating simple OpenGL applications).

or is it at every vertex draw call?

From the programmers point of view it's not specified when it happens exactly. OpenGL has a command queue and things are asserted to be processed between them entering the command queue and reaching a so called "synchronization point". A synchronization point is any command that makes use or transfers data outside of the OpenGL context (like an image read with glReadPixels) produced by former OpenGL commands.

For all practical means you can assume that vertices and fragments get processed, as soon as a whole primitive has been specified. So if you draw triangles, then every 3 vertices you got all you need to draw a triangle and processing it commences.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top