GLSL Texture and variables

Started by
3 comments, last by me_here_me 17 years, 3 months ago
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. void display() { glActiveTexture(GL_TEXTURE0); 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"); glUniform1iARB(locminX, minX); glUniform1iARB(locmaxX, maxX); glUniform1iARB(locminY, minY); glUniform1iARB(locmaxY, maxY); glUniform1iARB(locminZ, minZ); glUniform1iARB(locmaxZ, maxZ); glBegin(GL_POLYGON); glVertex2d(-50.0,-50.0); glVertex2d(-50.0,50.0); glVertex2d(9.0,50.0); glVertex2d(9.0,-50.0); glEnd(); } thanks in advance
Advertisement
I wouldn't worry about 1 texture bind.

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;

val = max( min_vec, vec3(0) );
thanks for the valuable input :)
thanks for the valuable input :)

This topic is closed to new replies.

Advertisement