Search code examples
openglvaoopengl-2.0

Is it possible to write vertex array code that's portable between OpenGL 2.x and 3.x?


The OpenGL 3.0 spec says:

E.1 Profiles and Deprecated Features of OpenGL 3.0

...

Client vertex arrays - all vertex array attribute pointers must refer to buffer objects (section 2.9.2). The default vertex array object (the name zero) is also deprecated. Calling VertexAttribPointer when no buffer object or no vertex array object is bound will generate an INVALID_OPERATION error, as will calling any array drawing command when no vertex array object is bound.

The ref page for glEnableVertexAttribArray says:

GL_INVALID_OPERATION is generated by glEnableVertexAttribArray and glDisableVertexAttribArray if no vertex array object is bound.

The message I'm hearing is that comprehensive vertex array code that's fully portable between OpenGL 2.x and OpenGL 3.x/3.2+ is impossible, since 2.x can't use VAOs (which the API surface can strictly enforce -- thanks GLAD!), and 3.x must use VAOs (which...some drivers maaaybe enforce?)

It seems to me that robust code must branch between dedicated 2.x and 3.x codepaths (detected at runtime) at some point. Is this true?


Solution

  • When you use a compatibility profile OpenGL Context, then you can run the code of all previous OpenGL versions. Vertex array object 0 is valid and you can use fixed function attributes, immediate mode (glBegin/glEnd sequences) or even mix them all together.
    Compare OpenGL 4.6 API Core Profile Specification and OpenGL 4.6 API Compatibility Profile Specification.

    The specification of all OpenGL versions can be found at Khronos OpenGL registry.