Tuesday, 12 April 2016

c++ - Is it problematic to declare variables in the main loop of a OpenGL program?

Following some tutorials of OpenGL I noticed some of them declare some variables like transform matrices and uniform locations on the main loop of the program. From my point of view I thought it would be a bad thing because it would allocate memory for the variables for each loop.



Is this a good thing to do? Why should I calculate the location of a uniform in the shaders very loop if the location won't change?




For example, a statement like this in this code GLint modelLoc = glGetUniformLocation(lightingShader.Program, "model"); will get the same value every loop, why should I use this inside the loop then?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...