0

Does ist make sense to release a GL context after usage with wglMakeCurrent(0,0)?

Is there any performance advantage to release after usage instead of switching to another context while a context is current?

Christopher Oezbek
  • 17,629
  • 3
  • 48
  • 71

2 Answers2

2

As wglMakeCurrent() will internally call into the GPU driver, this is totally implementation-specific. However, even if there would be a technical reason for releasing the conext before binding a new one to be more efficient, every sensible implementation should internally do the release;bind sequence also when doing a direct switch.

However, the performance issue with switching rendering contexts is usually not the overhead of wglMakeCurrent. It is the actual GL flush which is implied by the switch by default. If you are interested in switching between multiple GL context most efficiently, you should have a look at the WGL_ARB_context_flush_control extension, which allows for controlling the flushing behavior on context switches.

derhass
  • 38,787
  • 2
  • 42
  • 61
  • So let's say I have 4x contexts that I am rendering to: Does it makes sense to disable flush control, render in all 4 contexts and then after the 4th context is done to go through all views and flush them? – Christopher Oezbek Apr 19 '18 at 19:03
  • Why do you want an explicit flush at all? If you need some kind of synchronization between those contexts, there are much better alternatives. – derhass Apr 19 '18 at 19:12
  • I was under the impression that without explicit flush there is no guarantee that the commands would ever be dispatched to the GPU / OpenGL Server at all. All synchronization between the contexts (if any) is done with glFenceSync. – Christopher Oezbek Apr 19 '18 at 19:33
  • Well, it is not clear to me what you're doing, so it is hard to give any advice. You might or might not need an explicit flush. You talk about several views becoming visible, so you probably already have swapbuffer calls for those. However, switching through all contexts to issue render commands and then siwtching through all again just to flush them sounds not like a good idea to me, I don't see any advantage this could have over directly flushing them in the first step. – derhass Apr 19 '18 at 19:51
1

It may make sense in the case where the window hasn't the style flag CS_OWNDC. In this case the device context is not private and should be released as soon as it's not needed any more.

MSDN wglMakeCurrent(hdc,hglrc) doc:

If hglrc is NULL, the function makes the calling thread's current rendering context no longer current, and releases the device context that is used by the rendering context. In this case, hdc is ignored.

.

Ripi2
  • 6,098
  • 1
  • 12
  • 28