Sign in to follow this  
GrumpyAndTired

mixing vbo and vertexattribarrays

Recommended Posts

HellRaiZer    1001
Quote:
Original post by GrumpyAndTired
is there anyway you can mix using vbos and vertex attribute arrays? It doesn't work, should it, or is it a driver bug?

I think it should (i'm doing this all the time).
Because glVertexAttribPointerARB define a generic vertex attribute, i think you must use a vertex program with it. Given that glVertexAttribPointerARB (and the others) are introduced by GL_ARB_vertex_program, this seems a logical explanation. I think i've read this somewhere i don't remember where (and i can't find it now).

Have you tried them with a vp?

HellRaiZer

Share this post


Link to post
Share on other sites
GrumpyAndTired    100
yes, well I am using VBO for my geometry, and doing bump mapping with shaders. However, when I use a VBO, my tangent vertex array doesn't upload. If I turn off using VBOs, it works fine. I am not sure why.

Share this post


Link to post
Share on other sites
GrumpyAndTired    100

void geom_BuildVBO( GLGeometry * pG, bool mode)
{
GLenum flags;
if(mode)
flags = GL_STATIC_DRAW_ARB;
else
flags = GL_DYNAMIC_DRAW_ARB;

if(!GLEW_ARB_vertex_buffer_object)
return;

gpu_GenBuffers(1,&pG->vbxyz);
gpu_BindBuffer(GL_ARRAY_BUFFER_ARB,pG->vbxyz);
gpu_BufferData(GL_ARRAY_BUFFER_ARB,(pG->numverts*4)*sizeof(jreal_t),pG->xyz,flags);

if(pG->normals)
{
gpu_GenBuffers(1,&pG->vbnormals);
gpu_BindBuffer(GL_ARRAY_BUFFER_ARB,pG->vbnormals);
gpu_BufferData(GL_ARRAY_BUFFER_ARB,(pG->numverts*4)*sizeof(jreal_t),pG->normals,flags);
}

if(pG->color)
{
gpu_GenBuffers(1,&pG->vbcolor);
gpu_BindBuffer(GL_ARRAY_BUFFER_ARB,pG->vbcolor);
gpu_BufferData(GL_ARRAY_BUFFER_ARB,(pG->numverts*4)*sizeof(jcolortype_t),pG->color,flags);
}

if(pG->bcolor)
{
gpu_GenBuffers(1,&pG->vbbcolor);
gpu_BindBuffer(GL_ARRAY_BUFFER_ARB,pG->vbbcolor);
gpu_BufferData(GL_ARRAY_BUFFER_ARB,(pG->numverts*4)*sizeof(jcolortype_t),pG->bcolor,flags);
}

for(int i = 0; i < pG->numtexsets; i++)
{
if( pG->st[i] )
{
gpu_GenBuffers(1,&pG->vbst[i]);
gpu_BindBuffer(GL_ARRAY_BUFFER_ARB,pG->vbst[i]);
gpu_BufferData(GL_ARRAY_BUFFER_ARB,(pG->numverts*2)*sizeof(jreal_t),pG->st[i],flags);
}
}

if( pG->index )
{
gpu_GenBuffers(1,&pG->vbindex);
gpu_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,pG->vbindex);
gpu_BufferData(GL_ELEMENT_ARRAY_BUFFER_ARB,(pG->numindices)*sizeof(jushort),pG->index,flags);
}

if( pG->p_packed )
{
for( int i = 0; i < pG->num_packed; i++)
{
gpu_GenBuffers(1,&pG->p_packed[i].vbindex);
gpu_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,pG->p_packed[i].vbindex);
gpu_BufferData(GL_ELEMENT_ARRAY_BUFFER_ARB,(pG->p_packed[i].numindices)*sizeof(jushort),pG->p_packed[i].index,flags);
}
}

gpu_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
gpu_BindBuffer(GL_ARRAY_BUFFER_ARB,0);
}



This is how I initialize the VBOs.

Share this post


Link to post
Share on other sites
christian h    200
I think you need to put all this data into single VBO, since you can have only 1 vbo binded per draw call.

So figure out the size of the buffer based on what attributes you need, like

buffer_size = numverts * sizeof(vertex);
if ( normals )
buffer_size += numverts*sizeof(normal);
if ( colors )
buffer_size += numverts*sizeof(color);
if ( texcoords )
buffer_size += numverts*sizeof(texcoord);

char *data = new char[buffer_size];

ofs = 0;
memcpy ( data, verts, numverts*sizeof(vertex));
ofs += numverts*sizeof(vertex);
if( normals ) {
memcpy ( data + ofs, normals, numverts*sizeof(normal));
ofs += numverts*sizeof(normal);
}
if( colors ) {
...
}
etc..

glGenBuffers(1, &vbo );
glBindBuffer(GL_ARRAY_BUFFER_ARB,vbo);
glBufferData(GL_ARRAY_BUFFER_ARB,buffer_size,data,flags);

free[] data;



p.s. why aren't plus signs showing up?

Share this post


Link to post
Share on other sites
christian h    200
Quote:
Original post by Eitsch
christian h: you can bind as much vbos as you like (from performance view this isnt really efficient but theoretically...)


Really? I never figured that out. So does it work like this:

BindBuffer(..)
VertexPointer(..)
BindBuffer( another buffer )
NormalPointer(..)
BindBuffer( yet another buffer )
..
DrawElements(..)


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