Problem using GLSL attributes

Started by
0 comments, last by 21st Century Moose 12 years, 1 month ago
Hey there, I'm making some skeletal animation coe using bones, for the vertex transformations I want to use GLSL, my buffer/rendering code is something like this:

-Generate a buffer with this function
GLuint generateBuffer(GLenum target, GLsizeiptr size, GLvoid* data, GLenum usage){
GLuint ret;
glGenBuffers(1, &ret);

glBindBuffer(target, ret);
glBufferData(target, size, data, usage);
return ret;
}


-Then I bind the buffer and call the drawing function
glBindBuffer(GL_ARRAY_BUFFER, mesh->bufferID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->indicesID);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(3, GL_FLOAT, sizeof(BufferVertex), BUFFER_OFFSET(24));
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(BufferVertex), BUFFER_OFFSET(12));
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(BufferVertex), BUFFER_OFFSET(0));


The BufferVertex is a structure with this format:
struct BufferVertex{
float x, y, z; //Vertex
float nx, ny, nz; //Normal
float s0, t0, z0; //Texcoord0
};


To implement my shader for the skeletal animation I want make another buffer with attribute variables, something like what is found in this site http://www.lighthous...bute-variables/ . My problem is that I'm not using VAOs, instead I'm making two VBOs, one for the geometry (BufferVertex structure) and another for the indices.

I there a way to implement another buffer to pass to the shader without using VAOs? If yes, can anyone explain me the changes I have to do?

Cumps
Advertisement
You should probably be using glVertexAttribPointer instead of glVertexPointer and friends (and glEnableVertexAttribArray instead of glEnableClientState) - it's a much cleaner API. You'll need to declare your own input attributes in your vertex shader instead of using the built-in ones, and (in older GLSL) use glBindAttribLocation to bind them to an attribute slot number (newer GLSL allows you to specify slot numbers in your shader code).

If you don't want to make that kind of change to your code you can just glBindBuffer your extra buffer and set more glTexCoordPointers for it, then use the extra texcoord slots. Don't forget glClientActiveTexture if you go down this route (this is where the old gl*Pointer API starts getting ugly).

VAOs are not needed for either of these aproaches.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement