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?

asked Apr 17, 2018 at 19:18

2 Answers 2

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.

answered Apr 17, 2018 at 20:07
Sign up to request clarification or add additional context in comments.

4 Comments

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?
Why do you want an explicit flush at all? If you need some kind of synchronization between those contexts, there are much better alternatives.
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.
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.
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.

.

answered Apr 18, 2018 at 0:04

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.