Scamp Dog
Scamp Dog

Reputation: 88

glEnableVertexAttribArray gives invalid operation

I'm trying to go through the ArcSynthesis tutorials on OS X, and I'm getting the OpenGL error "Invalid Operation" after calling glEnableVertexAttribArray. I've checked that I do have a VBO bound, per the discussion at glEnableClientState and glEnableVertexAttribArray, and am not sure what to check next.

I'm using OS X 10.8, the OpenGL 3.2 profile, and Xcode 4.6.

I'm trying to write a class that will load in the XML model files used in the tutorials, and I think that I'm doing the same operations in the same order as an earlier program that draws a coded-in model. But I must be doing something different or wrong somehow, and can't figure out what. Referring to the OpenGL 3.2 documentation says that you get an invalid operation by sending in an index value over the maximum allowed by the OpenGL implementation, but I'm using 0 and 1, which I've used before.

Here's the code, with all the OpenGL error checking edited out for clarity:

    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];
    }

Upvotes: 2

Views: 3101

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473212

Referring to the OpenGL 3.2 documentation says that you get an invalid operation by sending in an index value over the maximum allowed by the OpenGL implementation

No it doesn't. Doing that gives you GL_INVALID_VALUE. GL_INVALID_OPERATION is given by glEnableVertexAttribArray only when you call it and no VAO is bound.

So you should probably do that.

Upvotes: 6

Related Questions