Makogan
Makogan

Reputation: 9540

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.

Upvotes: 2

Views: 1131

Answers (2)

Nicol Bolas
Nicol Bolas

Reputation: 473322

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.

Upvotes: 3

na2axl
na2axl

Reputation: 1948

Have you tried to create an OpenGL context without querying for a specific version?

When I use native OpenGL functions (glxCreateContext() or wglCreateContext()) to create a new OpenGL context, they always create a context with the highest OpenGL version supported by my graphic card (4.6).

I don't know if GLFW have the same behavior...

ANSWER FOR QUESTION EDIT: It's impossible to query any of OpenGL informations WHITHOUT creating a context, since you are not able to call any of glXXX() functions WHITHOUT creating a context. You can instead create a dummy context (which is not shown to the user, but stay somewhere in the memory) to query all OpenGL informations you want, and delete it when you are done (don't worry about it, many many softwares, libraries and also game engines does this, even my own)

Upvotes: 1

Related Questions