7

I had some 3D code that I noticed wouldn't render in a strict core profile but fine in a "normal" (not explicitly requested-as-core-only) profile context. To isolate the issue, I have written the smallest simplest possible OpenGL program drawing just a triangle and a rectangle:

enter image description here

I have posted that OpenGL program as a Gist here.

With the useStrictCoreProfile variable set to false, the program outputs no error messages to the console and draws a quad and a triangle as per the above screenshot, both on an Intel HD OpenGL 3.3 and on a GeForce with OpenGL 4.2.

However, with useStrictCoreProfile set to true, it clears the background color but does not draw the tri & quad, console output is this:

GLCONN: OpenGL 3.2.0 @ NVIDIA Corporation GeForce GT 640M LE/PCIe/SSE2 (GLSL: 1.50 NVIDIA via Cg compiler)
LASTERR: OpenGL error at step 'render.VertexAttribPointer()': GL_INVALID_OPERATION
LASTERR: OpenGL error at step 'render.DrawArrays()': GL_INVALID_OPERATION
LASTERR: OpenGL error at step 'render.VertexAttribPointer()': GL_INVALID_OPERATION
LASTERR: OpenGL error at step 'render.DrawArrays()': GL_INVALID_OPERATION
LASTERR: OpenGL error at step '(post loop)': GL_INVALID_OPERATION
EXIT

... if a 4.2 strict core profile is requested instead of 3.2, same issue. Applies to 3 different nvidia GPUs so I assume I'm not conforming to the strict core profile properly. What was I doing wrong, and how can I fix this?

Note, you won't find a glEnableVertexAttribArray call in the above Gist, as it's inside the glutil package I'm importing -- but this does get called as the last step in the gist's compileShaders() func.

postgoodism
  • 948
  • 9
  • 14
metaleap
  • 2,132
  • 2
  • 22
  • 40
  • 1
    Have you tried using the GL_ARB_debug_output extension to get more useful error messages than "GL_INVALID_OPERATION"? It's a bit of a hassle to set up, but absolutely worth it. – postgoodism Oct 25 '12 at 06:26
  • +1 for sharing an example of a smallest simplest possible OpenGL program for Go – ANisus Oct 25 '12 at 08:06
  • Well to be fair, it's not *really* the "smallest simplest-possible OpenGL program for Go", to be fair... one could cut it down ;) – metaleap Oct 25 '12 at 08:14

1 Answers1

15

You're not creating/binding a Vertex Array Object with glGenVertexArrays() and glBindVertexArray(). VAOs encapsulate a bunch of vertex attribute state, including which attributes are enabled, detailed per-attribute information, etc. They were optional when the feature was originally introduced, but they're now required in strict/core contexts according to section 10.4 of the OpenGL core specification:

An INVALID_OPERATION error is generated by any commands which modify, draw from, or query vertex array state when no vertex array is bound. This occurs in the initial GL state, and may occur as a result of BindVertexArray or a side effect of DeleteVertexArrays.

Here's a very rough example of how VAOs are used:

// At initialization time:
GLuint vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
// Set up your vertex attribute state:
//  - glBindBuffer(GL_ARRAY_BUFFER,...);
//  - glEnableVertexAttribArray(...);
//  - glVertexAttribPointer(...);
//  - etc. -- Refer to OpenGL docs to see what is/isn't included in the VAO!
glBindVertexArray(0); // unbinds vao

// At draw time:
glBindVertexArray(vao); // automatically sets up previously-bound vertex attribute state
glDrawArrays(...);
glBindVertexArray(0); // unbinds vao
postgoodism
  • 948
  • 9
  • 14
  • Wow, I dug around some more based on your answer and what you're saying really seems to be the case... will try it and report back! – metaleap Oct 25 '12 at 06:49
  • And you're right! That's it. Will stick to core profile from now on during development to catch such things earlier. – metaleap Oct 25 '12 at 08:19
  • Great! What I'd love to see is some official OpenGL doc (rather than forum/SE posts) that confirms this difference (and others) between compatibility and core GL contexts, but so far I haven't been able to find one. – postgoodism Oct 25 '12 at 15:58
  • 1
    Well to be fair... the spec pdf for the strict core profile totally mentions this and I believe is actually quite complete -- but a caveman coder like me will tweak endlessly and ask in forums for days before taking half an hour to study and inspect the relevant sections... ;)) – metaleap Oct 25 '12 at 17:12
  • Hey, you're right, there it is! Let me update my answer with an actual spec citation... – postgoodism Oct 25 '12 at 18:13
  • +1 for "caveman coding". I believe you just coined a new term. – Qix - MONICA WAS MISTREATED Feb 11 '13 at 07:44