Sign in to follow this  
k-rock

Question on vertex arrays

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
>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?



Share this post


Link to post
Share on other sites
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 shader
uniform mat4 ProjectionMatrix;

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



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this