PDA

View Full Version : GL_ARRAY_BUFFER_ARB - doesn't work good



Bobo.Bobo
08-20-2003, 12:15 PM
Hi,
i have a proglem with GL_ARRAY_BUFFER_ARB.
Look through this code:



//------ in initialisation section --
GLfloat data[9];

GLuint buffer = 0;

int w = 0;

data[w++] = -20;
data[w++] = -20;
data[w++] = 0;

data[w++] = 20;
data[w++] = -20;
data[w++] = 0;

data[w++] = 20;
data[w++] = 20;
data[w++] = 0;

glGenBuffersARB(1, &buffer);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 9, data, GL_STATIC_DRAW_ARB);

// ----- in rendering loop ------

glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);

// first triangle
glDrawArrays(GL_TRIANGLES, 0, 3);

glDisableClientState(GL_VERTEX_ARRAY);

// second triangle
glBegin(GL_TRIANGLES);

glVertex3f(-20, -20, 0);
glVertex3f(20, -20, 0);
glVertex3f(20, 20, 0);

glEnd();


It should draw two identical triangles, but it doesn't http://www.opengl.org/discussion_boards/ubb/frown.gif
It makes something like this:
http://www.czacki.edu.pl/~tweety/scoolpage/dd.gif
This bigger triangle is the second one, ane this small one is the first one. Do you know why this happen?

Thanks for help.

Btw. have you noticed that normal vertex arrays are much slower than using glBegin...glVertex3f...glEnd ?

elias
08-20-2003, 12:36 PM
IIRC, the size argument to glBufferData is in bytes, so you need to use:

glBufferDataARB(GL_ARRAY_BUFFER_ARB, 9*4, data, GL_STATIC_DRAW_ARB);

instead of the original line.

If you want to compare vertex arrays versus glBegin/glEnd, use larger arrays. Draw 10000 triangles in one batch and see if Begin/End is still faster.

- elias

[This message has been edited by elias (edited 08-20-2003).]

[This message has been edited by elias (edited 08-20-2003).]

Bobo.Bobo
08-20-2003, 12:55 PM
It works!!! Thanks a lot!! http://www.opengl.org/discussion_boards/ubb/smile.gif
I've made my tests with 720000 triangles using GL_TRIANGLES and Vertex Arrays had 13 FPS and Begin/End had 18 FPS.
Strange...
Do you know if there is any limit of vertex buffer size? When I put more that 340000 triangles (only 3 floats per vertex) something is happening (not of them are drawn and program works very slow).

CatAtWork
08-20-2003, 01:23 PM
Large vertex buffers cause weird app behavior for me on a GF4 Ti, latest drivers. Worse problems occured on older drivers, so I guess they're slowly working it out.

Radeons have a 32 MB limit per buffer, I believe.

Tom78
08-20-2003, 02:19 PM
For me large Vertex Buffers work very well (Radeon 9800). I think NVidia messed up the Drivers. The bigger the VB the better for the App, due to less state-switching (I'm not sure, but this is what i found out after many tries).

cu
Tom

Bobo.Bobo
08-22-2003, 04:25 AM
I've made a benchmark (really chaotic code - but it's... working).
Now i see that Begin/End and Vertex Arrays are the slowest. GL_ARRAY_BUFFER_ARB and GL_VERTEX_ARRAY_RANGE_NV are the fastest but only for static scenes. When I write to buffers before every frame then NV buffer wins. I have GF4 4200 - i think NVidia drivers are not so good for mapping the ARB buffer.