Compiling and running on different OpenGL versions

Started by
15 comments, last by ver_1_alpha 8 years, 3 months ago
Yes, I've seen drivers in the wild which will return a pointer to a function which prints 'not supported' in the log, not just Qualcomm either, this was an NV driver a few years back.

Basically Android remains the place your dreams go to die smile.png
Advertisement
The non nullptr is also the default in X11 (Linux).

Here a quote from the SDL2 wiki about getting OpenGL function pointers:

On X11, function pointers returned by this function are valid for any context, and can even be looked up before a context is created at all. This means that, for at least some common OpenGL implementations, if you look up a function that doesn't exist, you'll get a non-NULL result that is _NOT_ safe to call. You must always make sure the function is actually available for a given GL context before calling it, by checking for the existence of the appropriate extension with SDL_GL_ExtensionSupported(), or verifying that the version of OpenGL you're using offers the function as core functionality.

Thanks to all for the responses.

So basically this is what I'm planning on doing:

1) When compiling I'll use #ifdef GL_VERSION_X_Y to make sure the compilation works properly.

2) When running it, let's say that glGetString(GL_VERSION) is supported. I understand that GLEW may have a bug in this function; but if I have a reliable way of parsing this string to get the major and minor version numbers, then these will be the ones available at runtime. Let's say I define an integer iversion = 10*major + minor. Then I can use


#ifdef GL_VERSION_3_1
if(iversion >= 31) {
   /* my happy OpenGL 3.1 code here */
}
#endif

Of course, this is all predicated on two facts: (1) I can construct iversion reliably; and (2) iversion created at runtime by extracting the version through gl calls will give me the supported runtime version of gl - regardless of how it was compiled.

Am I correct?


Android, sadly.

Qualcomm's Adreno drivers always return a non-null function pointer, regardless of whether the function is actually supported.

Well on EGL platform if


EGL_KHR_get_all_proc_addresses
EGL_KHR_client_get_all_proc_addresses

is not exposed, then the implementation does not support querying non extension function entry points( hence the null return ).

As for GLEW, one thing the op should note is that GLEW is not OpenGL or is required to use OpenGL functionality. Its just a very convenient library to fetch and setup your GL function entry points. So there should be no hard dependency between the GL version and GLEW. Newer GLEW version is are just bug fixed and additional entry point that may not be available in the previous version. The fact that your application was linked with version x and use version x function pointers should not make a difference if your app was installed on a machine that does not support the version of OpenGL your application was built on as long as you are checking the validity of the function pointers before using them.

Hopefully, I didn't confuse you more.

Hi cgrant,

I think my confusion right now is just one question: regardless how the code was compiled and on what platform, and with what version of OpenGL, is GL_VERSION (major and minor) obtained at runtime reliable ways (at runtime!) do bracket the source with "if" statements to skip over code that compiled properly but should not be called because the runtime version of opengl does not support it?

In other words, if my running machine only supports GL 1.1, can I reliably count on the fact that glGetString(GL_VERSION) will tell me that the runtime version is 1.1 and that I should skip some code that uses functionality in GL > 1.1?

I'm just hoping that glGetString(GL_VERSION) has no relation to the version used for compiling the code.

Thanks.


I'm just hoping that glGetString(GL_VERSION) has no relation to the version used for compiling the code.

That is correct. glGetString(GL_VERSION) gives you the version of OpenGL running on the machine, not the version you compiled against.

However, keep in mind that glGetString(GL_VERSION) represents the minimum level of functionality provided by the running OpenGL driver. It may in fact offer many newer features, enumerated in glGetString(GL_EXTENSIONS).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

May be you need to write 2 or more renders.

The latest version will use glUniform the older will not use it.

Program starts and check version of OpenGL and dynamically load DLL module.

Windows ,linux, Java all supports dynamically loading of different modules.

This topic is closed to new replies.

Advertisement