Skip to main content
gamedev.net
🔒 Locked

wierd vertex array performance

Started by nitzan 2 replies 250+ views
Original Post
nitzan
nitzan
The following code renders at 170fps: glBegin(GL_TRIANGLE_STRIP); glNormal3f(normals[0], normals[1], normals[2]); glTexCoord2f(t[0], t[1]); glColor3f(colors[0], colors[1], colors[2]); p1.vertex(); glDisable(GL_COLOR_MATERIAL); glNormal3f(normals[3], normals[4], normals[5]); glTexCoord2f(t[2], t[3]); glColor3f(colors[3], colors[4], colors[5]); p2.vertex(); glDisable(GL_COLOR_MATERIAL); glNormal3f(normals[6], normals[7], normals[8]); glTexCoord2f(t[4], t[5]); glColor3f(colors[6], colors[7], colors[8]); p4.vertex(); glDisable(GL_COLOR_MATERIAL); glNormal3f(normals[9], normals[10], normals[11]); glTexCoord2f(t[6], t[7]); glColor3f(colors[9], colors[10], colors[11]); p3.vertex(); glDisable(GL_COLOR_MATERIAL); glEnd(); If I place the code in the vertex arrays as follows, I only get 150fps! What gives ? Why are my vertex arrays slower ? glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vertices); glColorPointer(3, GL_FLOAT, 0, colors); glTexCoordPointer(2, GL_FLOAT, 0, t); glNormalPointer(GL_FLOAT, 0, normals); glDrawElements(GL_TRIANGLE_STRIP, 12, GL_UNSIGNED_BYTE, indices); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); Anyone ? Another wierd thing (maybe its related)... The vertex arrays draw fine in Release mode, but the vertices are completely f****d in Debug mode. Its like one vertex from each square wants to go to a random location, mostly across the axis. Thanks! Nitzan ------------------------- www.geocities.com/nitzanw www.scorchedearth3d.net -------------------------
vincoof
vincoof
An object with 4 elements is not worthy of vertex arrays. You have to enable and disable client states, which costs a bit of time.

Try with 1000 elements and you''ll see the difference.

Also, why do you disable GL_COLOR_MATERIAL after each call to glVertex ?
Wavarian
Wavarian
Whoa.. whats with all the enable & disable client states? in my engine, i only enable all the states in my setup procedure.. just because you enable vertex arrays, doesnt mean that you have to disable them every frame.
vincoof
vincoof
You''re right. There''s no need to enable/disable them at each frame for this example.

But if you have more than one object that use vertex arrays, then you have to switch between the objects with calls to glVertexPointer-like functions.
And if some objects (I mean, those drawn with vertex arrays) are textured, some not, if some are coloured, some not, etc, then you''ll have to switch the Client States (eg call glEnableClientState or glDisableClientState) between the draw of each object.

That''s why I do not recommend using vertex arrays for low-polygonal models. It''s too heavy management to switch set up vertex array client states and pointers.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.