Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query highest supported OpenGL version before context initialization?

I want to know if there is a way (ideally cross platform, but if not just POSIX compliant or at least in Linux) to query for the highest supported OpenGL version in the current system.

I would like to be able to instantiate GLFW windows to be the highest supported version, rather than blindly trying different versions until one allows for valid context initialization.

EDIT:

Assume I am not creating a context. Imagine I want to replicate what glxinfo does. In other words, I want to be able to query the installed OpenGL version without EVER creating a context.

like image 449
Makogan Avatar asked Feb 23 '26 04:02

Makogan


1 Answers

When you ask for version X.Y, you are not asking for version X.Y; you're asking for at least version X.Y. Implementations are permitted to give you the highest version which is backwards compatible with X.Y.

So if you ask for 3.3 core profile, you may well get 4.6 core profile. There's no point in the implementation returning a lower version.

So just write your code against a minimum OpenGL version, then ask for that. You'll get whatever the implementation gives you, and you can query what you got later.


Imagine I want to replicate what glxinfo does.

glxinfo does what it does by creating a context. Just look at its source code.

However, the GLX_MESA_query_renderer extension does allow asking about the context that would be created for a particular display/screen/renderer combination. Of course, that only works through MESA; drivers that don't go through MESA's system will not be visible through this.

like image 101
Nicol Bolas Avatar answered Feb 25 '26 17:02

Nicol Bolas