Sign in to follow this  
mxhz

Vertex Array question

Recommended Posts

I try to use vertex array for better performance but find that it seems doesn't work in my case. I want to draw scenes with their ID colors, which is an unique color for every face(triangle face). That means I want to draw objects in color per face mode,not color per vertex. From what I know, vertex array can only handl color per vertex mode as it uses same index array to index both vertex coordinate array and color array. When a vertex is shared by more than one face, it has only one index value to index its color, as a result, you can only assign one color to this shared vertex, which doesn't fit my situation as I want to assign different colors to different faces, so the shared vertex must be assigned more than one color. Is it the truth that VA can't handle these case or I am wrong about the usage of VA? I hope I have made my problem clear. Please give me some hint:)

Share this post


Link to post
Share on other sites
What you need to do is create multiple versions of each vertex, one with each different colour. So, for example, your array of vertex positions might have (1, 1) (1, 1) (1, 1) and you array of colours might have (red) (green) (blue). The same trick is needed when there are different texture coordinates or normals at the same location.

Of course, when every single vertex is duplicated, it gets a bit wasteful...

Share this post


Link to post
Share on other sites
yeah I thought of it too. But will it a little too costly?

I think using shared vertex in VA to reduce the number of primitives transformission is one of its advantanges. If we create multiple versions of shared vertexs, put memory wast aside, will it have some notable performance gain using VA over immediate mode?

Share this post


Link to post
Share on other sites
I think you'll just have to try it and see... a couple other possibilities:

1) Don't store the colour in the VAs, use glColor() to specify it for each face then glArrayElement() to load the vertices (probably a tad faster than using glVertex())

2) If the data is static, give VBOs a try. I think having things sitting nicely in graphics memory would offset a lot of the awkwardness of the data.

Share this post


Link to post
Share on other sites
Thank you for your replies and suggestions!

My scene is static, the verteices do not need any transformation since they have been already done and stored. I think I will try using VBO, but I don't know how to start although I have read some articles about VBO.

Where can I find some tutorials and demo codes on how to use VBO? A simple demo code and some explaination is prefered.

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