给定
std::vector<GLuint> cubeIndices;
struct FaceGroup {
unsigned int face_index;
unsigned int start_index;
size_t length;
// comparison operators omitted
};
std::set<FaceGroup>::iterator i;
GLuint attribIndex;
FaceGroup
我通过循环遍历cubeIndices
from中的每个索引start_index
来渲染集合中的每一个,start_index + length
如下所示:
for (unsigned ix = 0; ix < i->length; ++ix) {
glDisableVertexAttribArray (attribIndex);
glVertexAttribI1ui (attribIndex, cubeIndices [i->start_index + ix]);
glDrawElements (GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, (void*) (i->face_index * sizeof (GLuint)));
}
...这给了我正确的结果。现在我想使用实例化数组渲染同样的东西。我的推理告诉我,下面的代码等价于上面的循环:
glEnableVertexAttribArray (attribIndex);
glVertexAttribDivisorARB (attribIndex, 1);
glVertexAttribPointer (attribIndex, 1, GL_UNSIGNED_INT, GL_FALSE, sizeof (GLuint), &cubeIndices [i->start_index]);
glDrawElementsInstancedARB (GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, (void*) (i->face_index * sizeof (GLuint)), i->length);
但似乎只渲染了每组人脸中的第一个(*试探,我可能错了)。我究竟做错了什么?