Question on vertex arrays

Started by
2 comments, last by V-man 15 years, 6 months ago
I have read that it is better to send less, but larger vertex arrays than a bunch of small ones. What I don't understand is how to put objects into a vertex array "post transformation". So if I had an object defined by an array of points, then I translate, rotate, scale it - how do I add these transformed vertices to an array, for sending to glDrawArrays? Right now I am putting each object into an array, and then push/trans/drawArray/pop.
Advertisement
Why do you want to do this? It's more efficient to use the GPU's built-in matrix transformations. Just put all your objects in one array, but do the modelview matrix operations as normal.
>Why do you want to do this? It's more efficient to use the GPU's built-in matrix
>transformations. Just put all your objects in one array, but do the modelview
>matrix operations as normal.

That's what I don't understand. If the objects are all in a single array, how do I transform them individually? They all have different positions, scales and rotations.

Is this what you are suggesting?

1. build objects (with normalized coordinates), push each into large array
2. transform with glTranslate, etc
3. draw arrays for vertices in a single object
4. Go to 2 with next object


But then I am calling draw arrays bunches of times, which is what I wanted to avoid, no?



If calling glDrawArrays too often is your bottleneck, then what you can do is put the XYZ for your translation in a texture coordinate.
In a vertex shader, you use that texture coordinate to translate your vertices

//GLSL vertex shaderuniform mat4 ProjectionMatrix;void main(){  vec3 myvertex;  myvertex = gl_Vertex.xyz + gl_MultiTexCoord0.xyz;  gl_Position = ProjectionMatrix * vec4(myvertex, 1.0);}


Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement