Hey, it seems, like i don’t quite get how does TF interact with VAO’s and GL_ELEMENT_ARRAY_BUFFER’s. I try to make my animation system to work with transform feedback. So i have initial VAO1 containing all necessary attributes and i want to draw it with transform feedback enabled, outputting results into ARRAY_BUFFER, which is bound to another VAO2 used to finally draw.
Here’s initialization of TF and related buffers:
//transform feedback
if(isAnimated) {
//setup transform feedback
glGenTransformFeedbacks(1, &transformFeedbackObject);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedbackObject);
//create output VAO
glGenVertexArrays(1, &animationOutputVAO);
glBindVertexArray(animationOutputVAO);
glGenBuffers(1, &animationOutputBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, animationOutputBufferObject);
glBufferData(GL_ARRAY_BUFFER, modelStorage[modelId].data.numVertices * sizeof(float), NULL, GL_DYNAMIC_COPY);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, animationOutputBufferObject); //bind as TF output
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelStorage[modelId].data.indexObject); //use original indices
//i thought, maybe i can't just bind orginal element array here, but this doesn't make any difference:
/*glGenBuffers(1, &animationOutputIndexObject);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, animationOutputIndexObject);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, modelStorage[modelId].data.indices.size() * sizeof(short), &modelStorage[modelId].data.indices[0], GL_DYNAMIC_DRAW);*/
//vx, nx, tx
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * attributeStride, BUFFER_OFFSET(0));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(float) * attributeStride, BUFFER_OFFSET(12));
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(float) * attributeStride, BUFFER_OFFSET(24));
//bone ids, bone weight
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(float) * attributeStride, BUFFER_OFFSET(32));
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(float) * attributeStride, BUFFER_OFFSET(44));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glBindVertexArray(0);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
}
disclamer: some function call order is a consequence of a bit of desperation.
Drawing to TF:
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedbackObject);
currentShader.applyProgram(15, 0);
glUniformMatrix4fv(currentShader.uniform_bones, maxNumBones, GL_FALSE, &boneMatrices[0]);
glBindVertexArray(modelStorage[modelId].data.vertexArrayObject); //source VAO
glBeginTransformFeedback(GL_TRIANGLES);
for(unsigned s = 0, off = 0; s < modelStorage[modelId].data.numSurfaces; s++)
{
glDrawElements(GL_TRIANGLES, modelStorage[modelId].data.numIndices[s], GL_UNSIGNED_SHORT, BUFFER_OFFSET(off));
off += modelStorage[modelId].data.numIndices[s] * sizeof(short);
}
glEndTransformFeedback();
glBindVertexArray(0);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
So… When i draw animationOutputVAO with glDrawElements, i get just a mess of triangles. Any clues on what am i doing wrong? The problem is that couple of examples on TF i found are used for particles and they don’t use neither VAO, nor element buffers, so i’m not sure how do i accomplish what i’m trying to do. So i’m resorting to forum and heavy documentation + source code googling.