PDA

View Full Version : NV: VBO Bug?



stefan
07-09-2003, 10:22 AM
I've found a problem in a program and I'm not sure whether it's a bug or I did something wrong. So if you're familiar with VBO here's your chance to help me http://www.opengl.org/discussion_boards/ubb/wink.gif

When I use a vertex program with generic attributes and VBO to draw something, then use standard vertex arrays and draw something again the latter won't be displayed.

To make it simple I've created a minimal app that shows my problem: I'm just drawing two quads. The first with VBO and a vertex program using generic attributes:



glBindProgramARB(GL_VERTEX_PROGRAM_ARB,vertexProgA ttrib);
glEnable(GL_VERTEX_PROGRAM_ARB);

glEnableVertexAttribArrayARB(0);
glEnableVertexAttribArrayARB(3);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboHandle);

glVertexAttribPointerARB(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (char*)0);
glVertexAttribPointerARB(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (char*)12);

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, &indices[0] );
glDisableVertexAttribArrayARB(0);
glDisableVertexAttribArrayARB(3);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);

glDisable(GL_VERTEX_PROGRAM_ARB);


The second one goes like that:



glPushMatrix();
glTranslatef(1.5,1.5,0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer( 3,GL_FLOAT, sizeof(Vertex), &verts[0].x );
glColorPointer( 3,GL_FLOAT, sizeof(Vertex), &verts[0].r );
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, &indices[0] );
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glPopMatrix();

This quad won't be shown on the screen!

I've only seen that issue on my GeForce 3 Ti with latest official detonators and the inofficial 44.65. The code runs fine on my ATI M9.

The full source code is available on http://home.augustakom.net/as120108/VBOBug.zip . You can use the key 'v' to switch between using VBO / standard vertex arrays for the first quad and 'a' to switch between generic attributes and conventional attributes. You can see the current mode in the console window (But make sure you press the keys in the app window...)

Thanks!

jra101
07-09-2003, 11:21 AM
Add this line:

glGenProgramsARB(1, &vertexProgAttrib);

before you ever use vertexProgAttrib and your program will work fine.

stefan
07-09-2003, 11:56 AM
Thanks Jason - what a stupid mistake!

Coriolis
07-09-2003, 04:22 PM
You don't HAVE to use glGenBuffersARB; you just have to make sure vertexProgAttrib is a unique non-zero number.

Korval
07-09-2003, 05:47 PM
You don't HAVE to use glGenBuffersARB; you just have to make sure vertexProgAttrib is a unique non-zero number.

Where in the spec does it say this?

V-man
07-09-2003, 06:27 PM
Originally posted by Korval:
Where in the spec does it say this?

It works like texture objects. Every time you call the Gen function, you get a previous+1. You can use 0 which I guess disables the vp.

genglish
07-09-2003, 06:31 PM
glGenBuffersARB ...


... These names are marked as used, for the purposes of GenBuffersARB only...

Implies that glGenBuffers is mearly a helper function. State isn't attached to the buffer before it's bound anyway so it effectively doesn't exist until that point beyond the booking of glGenBuffers. The example code also just directly starts using buffer 1 without generating it. I believe textures work the same way.

On the other hand I'd like it much better if glGen* was mandatory in all cases.

[EDIT: spelling and got beaten to the punch ... ]

[This message has been edited by genglish (edited 07-09-2003).]

stefan
07-09-2003, 09:56 PM
The problem was that the variable vertexProgAttrib was a global variable and as such was initialized to zero and this is of course the default program.
So: You needn't call glGenProgram, but if you don't make sure not to use 0 for the program object....

(It's really depressing if you have a strange problem in a big app, try to break it down into a small test case, reproduce a strange behaviour - but just due to an additional bug)