I m using GLSL for rendering a 3D texture. I am new to GLSL and i feel that i am performing the operaations in not a very efficient manner. I am binding a texture everytime when a display function is called which i feel can be made more efficient.
can i activate and bind a texture once and use it everytime the display function is called.
glBindTexture(GL_TEXTURE_3D, txVolume); // txVolume is already loaded
glUniform1iARB(glGetUniformLocation(p, "txVolume"), 0);
int minX, maxX, minY, maxY, minZ, maxZ = 0;
determineCorners(&Ddim,&matrixMVFinalTemp, &minX, &maxX, &minY, &maxY, &minZ,
&maxZ); // a method that determines values for its arguments
locminX = glGetUniformLocationARB(p, "minX");
locmaxX = glGetUniformLocationARB(p, "maxX");
locminY = glGetUniformLocationARB(p, "minY");
locmaxY = glGetUniformLocationARB(p, "maxY");
locminZ = glGetUniformLocationARB(p, "minZ");
locmaxZ = glGetUniformLocationARB(p, "maxZ");
thanks in advance
You may want to try to entirely eliminate redundant state changes, but in general, it's much better for your sanity to just set it up at the begining of a frame, rather than trying to track state across frames (for a program this small it probably does not matter, but as they get larger...)
However, the glGetUniformLocation calls might actually be a performance issue. They exist so OpenGL doesn't have to do string comparisions and table lookups every time you load a new uniform. Using the API in this way negates that advantage.
Query the uniform locations once during setup, and cache the values. It'll have far more of an effect than removing the BindTexture.
in addition to what richard saiz (without seeing the shader) u have 6 different variables minX minY minZ max now im guessing u do perhaps something like valX = max( minX, 0.0 ); valY = max( minY, 0.0 );
but cause of the way graphic hardware works on vectors youll get much better performance bby working on all at once uniform vec3 min_vec;