gpt4 book ai didi

iphone - glDrawElements VAO/VBO 在 iOS 上崩溃

转载 作者:行者123 更新时间:2023-11-29 04:44:45 25 4
gpt4 key购买 nike

我正在创建一个使用 VAO 和 VBO 来管理网格的批处理类。但是,当尝试使用 glDrawElements 时,我在绑定(bind)回 VAO 时收到 EXEC_BAD_ACCESS 和 GL_INVALID_OPERATION 。这是代码:

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);

知道为什么我在尝试使用 GL_ELEMENT_ARRAY_BUFFER VBO 时收到 EXEC_BAD_ACCESS 吗?

最佳答案

您确定以下陈述正确吗?

  • 所有 OpenGL 函数都不会设置错误 - 在每个 glXYZ 函数之后调用 glGetError 并检查结果。
  • kStride >= 24
  • 长度 == vertCount * kStride
  • 索引数组包含 GLushort 类型的 indexCount 个元素
  • 索引数组的所有元素的值都小于 vertCount 值
  • 没有其他 glEnableVertexAttribArray 调用

关于iphone - glDrawElements VAO/VBO 在 iOS 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9814912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com