1
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;
我是通过从start_index
在cubeIndices
每个索引循环渲染组中的每个FaceGroup
到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);
,但它似乎只是使每一组头像(*初步分析,可能是我错了)的第一个。我究竟做错了什么?
谢谢!它现在可以... :) 在我的防守中,我只发现了关于'glVertexAttribI1ui',因为我最初尝试过'glVertexAttrib1i',它不存在,然后将其导向到'glVertexAttrib'手册页,我在其中找到'glVertexAttribI *'函数。 – larvyde