How to check compliance of OpenGL version?

I want to make sure my application complies with OpenGL 2.1. How can I check this?

Since my computer supports GL4.4, even if I use, for example, glGenVertexArrays() , it will work successfully. But glGenVertexArrays() is only available with GL3 +.

So, I want to check that my application uses only GL2.1 functions. One way is to run it on my old PC, which only supports GL2.1, but I'm looking for an easier way.

+7
c ++ version opengl
source share
3 answers

You can compile it in an environment in which only OpenGL-2.1 characters are available. Depending on which extender / bootloader you are using, this can be easy or difficult.

For example, if you use the glloadgen OpenGL loader generator , you can create a header file and a compilation unit that will only cover OpenGL -2.1 characters and tokens exactly. If you then compile your project using this, the compiler will output errors to anything that does not apply.

+1
source share

If you find an extension loader that supports creating version-specific headers as described by @datenwolf, this is probably the easiest solution. There is another option that you can try if necessary.

The official OpenGL headers, which you can find at https://www.opengl.org/registry , contain definitions grouped by version and enclosed in preprocessing conditions. The layout is as follows:

 ... #ifndef GL_VERSION_2_1 #define GL_VERSION_2_1 1 // GL 2.1 definitions #endif #ifndef GL_VERSION_3_0 #define GL_VERSION_3_0 1 // GL 3.0 definitions #endif #ifndef GL_VERSION_3_1 #define GL_VERSION_3_1 1 // GL 3.1 definitions #endif ... 

You should be able to include the official title at least for version verification. If you disable versions that you do not want to use by specifying the appropriate preprocessor symbol, you will get compilation errors if you try to use functions from these versions. For example, for GL 2.1:

 #define GL_VERSION_3_0 1 #define GL_VERSION_3_1 1 #define GL_VERSION_3_2 1 #define GL_VERSION_3_3 1 #define GL_VERSION_4_0 1 #define GL_VERSION_4_1 1 #define GL_VERSION_4_2 1 #define GL_VERSION_4_3 1 #define GL_VERSION_4_4 1 #define GL_VERSION_4_5 1 #include <GL/glext.h> // your code 
0
source share

Try https://github.com/cginternals/glbinding . This is an OpenGL wrapper library that supports exactly what you ask for:

Functional header design

The OpenGL API is iteratively developed and released in versions internally (for the API specification) named functions. The latest Function / Version of OpenGL is 4.5. Previous version 1.0, 1.1, 1,2, 1,3, 1,4, 1,5, 2,0, 2,1, 3,0, 3,1, 3,2, 3,3, 4,0, 4.1, 4.2, 4.3 and 4.4. OpenGL uses the deprecation model to remove obsolete parts of its API, which results in compatibility (with the deprecated API) and (without the use of deprecated APIs) that manifest in the target OpenGL Context. In addition, new API concepts are proposed as extensions (often vendor-specific) that can be integrated into future versions. All this leads to manifestations of the OpenGL API that you can use in your program.

One difficult task is to stick to one consistent set of functions in your own OpenGL (for example, OpenGL 3.2 Core, if you want to develop for every Windows, macOS and Linux released in the last 4 years). glbinding facilitates this by providing the headers of each function with well-defined / generated subsets of the OpenGL API.

All OpenGL Headers

If you do not use headers for each function, the OpenGL program might look like this: this:

 #include <glbinding/gl/gl.h> // draw code gl::glClear(gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT); gl::glUniform1i(u_numcubes, m_numcubes); gl::glDrawElementsInstanced(gl::GL_TRIANGLES, 18, gl::GL_UNSIGNED_BYTE, 0, m_numcubes * m_numcubes); 

OpenGL Headers with One Functionality

When developing code on Windows with the latest drivers installed, the above code will most likely compile and run. But if you want a port that is a system with less mature driver support (for example, macOS or Linux using open source drivers), you may wonder if glDrawElementsInstanced is available. In this case, just switch to the headers for each glbinding function and select the OpenGL 3.2 Core headers (as you know, at least this version is available on all target platforms):

 #include <glbinding/gl32core/gl.h> // draw code gl32core::glClear(gl32core::GL_COLOR_BUFFER_BIT | gl32core::GL_DEPTH_BUFFER_BIT); gl32core::glUniform1i(u_numcubes, m_numcubes); gl32core::glDrawElementsInstanced(gl32core::GL_TRIANGLES, 18, gl32core::GL_UNSIGNED_BYTE, 0, m_numcubes * m_numcubes); 

If the code compiles, you can be sure that it is OpenGL 3.2 Core compatible. Using features that are not yet available or the deprecated feature is prohibited.

0
source share

All Articles