dot_Sp0T
dot_Sp0T

Reputation: 399

Is there a way to identify the OpenGL context I am operating on?

When abstracting my game-/render-engine I hit the issue that I need a way to know reliably what context I am operating on.

I am looking for a solution that works within the OpenGL specification. That is standard OpenGL, nothing provided by wrapper library xyz.

Upvotes: 2

Views: 2253

Answers (3)

dot_Sp0T
dot_Sp0T

Reputation: 399

While I couldn't find anything for the OpenGL 3.3 Core Profile (most common version iirc), there's something available from version 4.3 onwards.

One can set a custom userpointer with glDebugMessageCallback and can retrieve that userpointer with glGetPointerv.

Thus one could abuse the userpointer to mark a context.

Upvotes: 0

genpfault
genpfault

Reputation: 52088

I am looking for a solution that works within the OpenGL specification

Nope, gotta step up a layer and ask the OS's window system binding via wglGetCurrentContext()/glXGetCurrentContext()/aglGetCurrentContext()/etc.

Upvotes: 3

Wagner Patriota
Wagner Patriota

Reputation: 5674

Short: No, there's no way to do this "within the OpenGL specification"

OpenGL specification doesn't care about HOW the context is created and managed. The operating system and/or platform is responsible for this.

Long: If you control the application, then you should be able to detect when you are switching the OpenGL context. But if this is not the way you want to use, there's no other way... unless you setup different contexts with different settings (like the OpenGL version) or if they are running in separated threads. Again, this second one is not "OpenGL specification"... just tricks...

Upvotes: 1

Related Questions