Я создаю класс пакетной обработки, который использует VAO и VBO для управления сетками. Однако при попытке использовать glDrawElements я получаю EXEC_BAD_ACCESS и GL_INVALID_OPERATION при привязке к моей VAO. Вот код:
glGenVertexArraysOES(1, &arrayID);
glBindVertexArrayOES(arrayID); // Bind INTO VAO, opening state
// Load shaders and textures and bind them using glUseProgram etc.
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glGenBuffers(1, &indexID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexID);
glBindVertexArrayOES(0); // Bind AWAY from VAO, saving state
Glfloat data[length];
glBindVertexArrayOES(arrayID); // Bind INTO VAO, open state
unsigned int glfloatsize = sizeof(GLfloat);
unsigned int stride = kStride * glfloatsize;
// Fill Vertex information
glBufferData(GL_ARRAY_BUFFER, vertCount * glfloatsize * kStride, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertCount * glfloatsize * kStride, data);
glEnableVertexAttribArray(kPositionLocation);
glVertexAttribPointer(kPositionLocation, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(0));
glEnableVertexAttribArray(kNormalLocation);
glVertexAttribPointer(kNormalLocation, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(3));
glEnableVertexAttribArray(kColorLocation);
glVertexAttribPointer(kColorLocation, 4, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(6));
glClientActiveTexture(GL_TEXTURE0);
glEnableVertexAttribArray(kTextureLocation);
glVertexAttribPointer(kTextureLocation, 2, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(10));
// Fill Index information
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * sizeof(GLushort), NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexCount * sizeof(GLushort), index);
glBindVertexArrayOES(0); // Bind AWAY from VAO, saving state
// DO OTHER STUFF
/** RENDER (EXPLODES WITH EXEC_BAD_ACCESS) **/
glBindVertexArrayOES(arrayID);
glDrawElements(renderMode, indexCount, GL_UNSIGNED_SHORT, 0);
glBindVertexArrayOES(0);
/** RENDER (WORKS CORRECTLY [index is a scoped array of GLushorts that are uploaded to the VBO above...]) **/
glBindVertexArrayOES(arrayID);
glDrawElements(renderMode, indexCount, GL_UNSIGNED_SHORT, index);
glBindVertexArrayOES(0);
Есть идеи, почему я получаю EXEC_BAD_ACCESS при попытке использовать GL_ELEMENT_ARRAY_BUFFER VBO?