Jump to content
  • Advertisement
Sign in to follow this  
GrumpyAndTired

mixing vbo and vertexattribarrays

This topic is 4255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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
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

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 )
{
gpu_GenBuffers(1,&pG->vbst);
gpu_BindBuffer(GL_ARRAY_BUFFER_ARB,pG->vbst);
gpu_BufferData(GL_ARRAY_BUFFER_ARB,(pG->numverts*2)*sizeof(jreal_t),pG->st,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.vbindex);
gpu_BindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,pG->p_packed.vbindex);
gpu_BufferData(GL_ELEMENT_ARRAY_BUFFER_ARB,(pG->p_packed.numindices)*sizeof(jushort),pG->p_packed.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
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: you can bind as much vbos as you like (from performance view this isnt really efficient but theoretically...)

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!