PDA

View Full Version : Using GL_NV_vertex_array_range



PSilva
03-14-2002, 06:11 PM
I am trying to use the glVertexArrayRangeNV.

I have a buffer with numTriangles (about 130000) triangles:

sizeX = 1188882;

GLFloat* triangles=(GLFloat*)calloc(sizeX, sizeof(GLFloat));

trianglesArray[0] is triangle1 1st vertex
trianglesArray[1] is triangle1 2st vertex
trianglesArray[2] is triangle1 3st vertex
trianglesArray[3] is triangle2 1st vertex
trianglesArray[4] is triangle2 2st vertex
....

big_array = (GLfloat*)wglAllocateMemoryNV(sizeX*sizeof(GLfloat ), 0, 0, 0.5f);

if(big_array)
{
m_memory = big_array;
}

glVertexArrayRangeNV(sizeX*sizeof(GLfloat), big_array);
glEnableClientState(GL_VERTEX_ARRAY_RANGE_NV);
glEnableClientState(GL_VERTEX_ARRAY);

This is done once.

The following code is done every frame:

glVertexPointer(3, GL_FLOAT, 0, trianglesArray);

glLockArraysEXT(0, numTriangles*3); //number of triangles * 3 vertexs per triangle
glDrawArrays(GL_TRIANGLES,0,numTriangles*3);
glUnlockArraysEXT();

This renders 130000 triangles correctly but decreases framerate from 500 fps to 12 fps!

This is with a Celeron 850MHz and a GeForce3 running with OpenGL 1.3.0 and WindowsXP Professional.

What am I doing wrong?

Where can I find a good tutorial or example on GL_NV_vertex_array_range?

Thank you.

PS- I don't know how to setup the index array to use glDrawElements.....

Korval
03-14-2002, 10:03 PM
This renders 130000 triangles correctly but decreases framerate from 500 fps to 12 fps!

You were running 130000 polygons per frame at 500 fps on a GeForce3? No way. I'd say your framerate counter is unreliable.

BTW, glLockArraysEXT and glUnLockArrayEXT are for CVA's, not VAR.

Also, you have to actually store your vertex data in the memory you allocated by wglAllocateMemoryNV.

[This message has been edited by Korval (edited 03-14-2002).]

timfoleysama
03-14-2002, 10:47 PM
From the looks of the code you have there, your "triangles" array was allocated in system memory, and therefore when you call glVertexPointer you are giving it a chunk of memory not within the "vertex array range." This would explain the drop in performance.

Any vertex array you specify with glXXXPointer had better be stored in the memory you have previously allocated with wglAllocateMemoryNV. So you should probably copy your vertex data into your "big_array" storage and pass that memory into glVertexPointer.

PSilva
03-15-2002, 04:16 AM
If I change the code like this:

big_array = (GLfloat*)wglAllocateMemoryNV(sizeX*sizeof(GLfloat ), 0, 0, 0.5f);

glVertexArrayRangeNV(sizeX*sizeof(GLfloat), big_array);
glEnableClientState(GL_VERTEX_ARRAY_RANGE_NV);
glEnableClientState(GL_VERTEX_ARRAY);

memcpy(big_array, triangles , sizeX*sizeof(GLfloat));

glVertexPointer(3, GL_FLOAT, 0, big_array);


If I run the code without the glDrawElements I get 500 fps without rendering the triangles.

If I run with:

glDrawArrays(GL_TRIANGLES,0,numTriangles*3);

...the framerate drops to 12 fps.

jide
03-15-2002, 04:24 AM
there are some extensions functions that are store to draw.
i think it's glDrawArrayExt, glDrawRangeElementExt. this may help too.

the same from glVertexPointer(3, GL_FLOAT, 0, trianglesArray); maybe a special extension or nv extension for that.

jide