Nominate our 2022 Qt Champions!

Keeping OpenGL Context Current

  • I have a program (game/game engine) that is going to be single-window and single-thread (for Qt/OpenGL work, at least) and I am trying to deal with Qt's internal use of the OpenGL context.

    My 3D engine, which is a custom design, assumes the same context is always bound when it is called into. Previously that was the case, but since I let Qt control the OpenGL context and window, it no longer is – Qt unbinds the context when it considers it not in use. This is a problem because if the context has been unbound, my commands disappear into the aether, which can have serious ramifications.

    I considered a couple of options for dealing with this, but they all seem bad given my situation. The most “proper” would be manually binding the context before I issue my commands. However, I'm worried that calls into Qt (that could be mixed in with 3D commands) could undo this without me knowing. I'm also worried about the performance cost of binding/unbinding contexts unnecessarily.

    Ideally, I would like a way to simply keep the same context bound from when it is created to when it is destroyed. Since I only have 1 thread and 1 window, there shouldn't be any problems with this. Unfortunately, I saw no method to do so.

    So, does anyone have an idea of how to keep an OpenGL context current/bound?

  • I'm not sure if this is best idea. But try to store pointer to that context. Then you could utilize QOpenGLContext::makeCurrent and QOpenGLContext::doneCurrent

Log in to reply