• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 顶点数组对象在 OpenGL 4.1 中没有正确绑定(bind)

[复制链接]
菜鸟教程小白 发表于 2022-12-12 15:59:33 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在将一些绘图代码从 OpenGLES 2.0 移植到 OpenGL 4.0,并且在绑定(bind)我的顶点数组对象时遇到了问题。当我运行 glValidateProgram 时出现此错误:Validation Failed: No vertex array object bound

这是我用于绘图的代码:

void RendererRender(RendererRef* renderer) {

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glUseProgram(program);

    glViewport(0, 0, renderer->viewportWidth, renderer->viewportHeight);
    glClearColor(0.2, 0.3, 0.4, 0);
    glClear(GL_COLOR_BUFFER_BIT);

    GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(M_PI/4.0, 1.0f, 0.1f, 10000.0f);

    GLKMatrix4 modelViewMatrix = GLKMatrix4MakeLookAt(0,0,-10,
                                            0,0,0,
                                            0,1,0);

    glUniformMatrix4fv(modelViewMatrixUniformLocation, 1, GL_FALSE, modelViewMatrix.m);
    glUniformMatrix4fv(projectionMatrixUniformLocation, 1, GL_FALSE, projectionMatrix.m);

    glGetError();

    glBindVertexArray(triangleVAOId);
    if(!validateProgram(program)){
        NSLog(@"Error validating program");
        glGetError();
    }

    glPointSize(10.0f);
    glDrawElements(GL_POINTS, 3, GL_UNSIGNED_SHORT, NULL);

}

因此,似乎此时 VAO 肯定应该被绑定(bind)。 VAO 是使用以下代码生成的:

typedef struct {
    GLfloat position[3];
} Vertex;


GLuint buildVAO(int vertexCount, Vertex* vertexData, GLushort* indexData, BOOL hasTexture)
{

    GLuint vaoId;
    GLuint indexId;

    //generate the VAO & bind
    glGenVertexArrays(1, &vaoId);
    glBindVertexArray(vaoId);

    GLuint positionBufferId;

    //generate the VBO & bind
    glGenBuffers(1, &positionBufferId);
    glBindBuffer(GL_ARRAY_BUFFER, positionBufferId);

    //populate the buffer data
    glBufferData(GL_ARRAY_BUFFER,
                 vertexCount*sizeof(Vertex),
                 vertexData,
                 GL_DYNAMIC_DRAW);

    //setup the attribute pointer to reference the vertex position attribute
    glEnableVertexAttribArray(kVertexPositionAttributeLocation);
    glVertexAttribPointer(kVertexPositionAttributeLocation,
                          kVertexSize,
                          kPositionVertexTypeEnum,
                          GL_FALSE,
                          sizeof(Vertex),
                          (void*)offsetof(Vertex, position));

    }

    //create & bind index information
    glGenBuffers(1, &indexId);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexCount*sizeof(GLushort), indexData, GL_DYNAMIC_DRAW);

    //restore default state
    glBindVertexArray(0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    return vaoId;
}

我注意到的另一件事是我从 glGenVertexArrays 得到的 VAO id 是一个很大的值,例如 1606408096,在我工作的示例中,它总是类似于 1 或 2 .

这一切都发生在主线程上。

知道可能出了什么问题吗?



Best Answer-推荐答案


想通了——原来是因为我使用了错误版本的 glGenVertexArray

我之前有过这样的声明:

#define glGenVertexArrays glGenVertexArraysAPPLE

事实证明,这仅在 3.0 之前的 OpenGL 版本上是必需的。

关于ios - 顶点数组对象在 OpenGL 4.1 中没有正确绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32067530/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap