I’m writing a shader for skeletal animations that requires an int[] attribute to hold the indices to a mat4[] that contains the transformation matrices for the joints. My problem is that I can not create a VBO that stores a int[]. I’ve tried using GL30.glVertexAttribIPointer() however, my computer does not support Opengl 3.0. So I’m forced to use glVertexAttribPointer() which I’ve read converts all values to floats. What is the best way to store a int[] in a VBO that can be accessed by a shader.
I’m writing a shader for skeletal animations that requires an int[] attribute to hold
Share
There are two problems with what you’re trying to do.
The first problem is that you’re trying to pass integers. Use floats; there’s nothing wrong with using a float as an index into an array. If you pass
GL_FALSEfor thenormalizedparameter ofglVertexAttribPointer, you will get what are effectively integers. You can pass each index as aGL_UNSIGNED_BYTE.The second problem is that you’re trying to pass an array. Stop doing that; you want a
vec4, not an array. The XYZW represent the four indices that you use with the matrices.What if a vertex needs more than 4 matrices? Stop doing that too; that’s how everyone else does skinning. The way this works is, when you’re building your vertex data, if a vertex is affected by more than 4 matrices, you only take the 4 with the largest weights (readjusting the weights accordingly).