glEnableVertexAttribArray提供无效操作

时间:2013-02-27 00:43:01

标签: cocoa opengl

我正在尝试浏览OS X上的ArcSynthesis教程,并在调用glEnableVertexAttribArray后得到OpenGL错误“无效操作”。根据{{​​3}}的讨论,我已经检查过我确实有一个VBO绑定,并且我不确定接下来要检查什么。

我正在使用OS X 10.8,OpenGL 3.2配置文件和Xcode 4.6。

我正在尝试编写一个将加载教程中使用的XML模型文件的类,并且认为我正在以与早期程序相同的顺序执行相同的操作绘制编码模型。但我必须以某种方式做一些不同或错误的事情,并且无法弄清楚是什么。参考OpenGL 3.2文档说通过发送超过OpenGL实现允许的最大值的索引值来获得无效操作,但我使用的是0和1,我以前使用过。

这是代码,为清楚起见,编辑了所有OpenGL错误检查:

    glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
    for (int iAttribLoop = 0; iAttribLoop < [attributeAnalyzers count]; iAttribLoop++) {
        AttributeAnalyzer *theAnalyzer = [attributeAnalyzers objectAtIndex:iAttribLoop];
        GLuint theIndex = [theAnalyzer index];
        NSLog(@"theIndex is %d", theIndex);
        glEnableVertexAttribArray(theIndex);
        glVertexAttribPointer(theIndex, [theAnalyzer size], theType, GL_FALSE, 0, dataOffset);
        dataOffset += sizeof(theType)*[theAnalyzer size]*[theAnalyzer vertexCount];
    }

1 个答案:

答案 0 :(得分:6)

  

参考OpenGL 3.2文档说通过发送超过OpenGL实现允许的最大值的索引值来获得无效操作

不,不。这样做会为您提供GL_INVALID_VALUEGL_INVALID_OPERATION仅由glEnableVertexAttribArray when you call it and no VAO is bound提供。

所以你应该这样做。