glEnableVertexAttribArray提供无效操作

Sca*_*Dog 2 opengl cocoa

我正在尝试浏览OS X上的ArcSynthesis教程,并在调用glEnableVertexAttribArray后得到OpenGL错误"无效操作".根据glEnableClientState和glEnableVertexAttribArray的讨论,我已经检查过我确实有一个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];
    }
Run Code Online (Sandbox Code Playgroud)

Nic*_*las 6

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

不,不.这样做会给你GL_INVALID_VALUE.仅在您调用它时GL_INVALID_OPERATION才会给出,并且不会绑定任何VAO.glEnableVertexAttribArray

所以你应该这样做.