mixing vbo and vertexattribarrays

Started by
7 comments, last by christian h 17 years, 4 months ago
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'm a troll and I have 4,561 different ways to hide my IP.
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
HellRaiZer
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.
I'm a troll and I have 4,561 different ways to hide my IP.
sure it works. the init code could help.
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.
I'm a troll and I have 4,561 different ways to hide my IP.
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?
I just got it to work. I was binding the vertex attrib array after the VBO stuff, and I think it messed it up for some reason.
I'm a troll and I have 4,561 different ways to hide my IP.
christian h: you can bind as much vbos as you like (from performance view this isnt really efficient but theoretically...)
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(..)


This topic is closed to new replies.

Advertisement