是否可以编写可在 OpenGL 2.x 和 3.x 之间移植的顶点数组代码?

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

OpenGL 3.0 spec 说:

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.

ref page for glEnableVertexAttribArray 说:

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

我听到的消息是,在 OpenGL 2.x 和 OpenGL 3.x/3.2+ 之间完全可移植的综合顶点数组代码是不可能的,因为 2.x 不能' t 使用 VAO(API 表面可以严格执行 - 感谢 GLAD!),并且 3.x 必须使用 VAO(...某些驱动程序 maaaybe 强制执行?)

在我看来,健壮的代码必须在某些时候在专用 2.x 和 3.x 代码路径(在运行时检测)之间分支。这是真的吗?

当您使用兼容性配置文件OpenGL Context 时,您可以运行 所有以前的 OpenGL 版本的代码。顶点数组对象 0 是有效的,您可以使用固定函数属性、立即模式(glBegin/glEnd 序列)甚至将它们混合在一起。
比较 OpenGL 4.6 API Core Profile Specification and OpenGL 4.6 API Compatibility Profile Specification.

所有 OpenGL 版本的规范可以在 Khronos OpenGL registry 找到。