Link to home
Start Free TrialLog in
Avatar of kradloff
kradloffFlag for United States of America

asked on

OpenGL RCs and GDI DCs and SwapBuffers call

According to all the documentation a Win32 window can have one DC and OpenGL needs to create and attach an RC to that DC to render.  I understand you may have multiple RCs but only one can be current at a time.  I create several threads, each creating their own window, each window has a DC and an RC.  The question is when I call SwapBuffers with a DC within one thread do I swap all the RCs of all the threads or just the one for that window/thread?

I have read the red, blue, white and superbible OpenGL books and some advanced Windows32 books.  The question of how DCs and RCs are (in)dependant of a window or thread and how SwapBuffers affects all the existing DCs and RCs is unclear?

Keith Radloff
ACi
kradloff@flyaci.com
937-426-1700
ASKER CERTIFIED SOLUTION
Avatar of Lischke
Lischke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kradloff

ASKER

The answer you provided makes sense.  However I will disagree that the documentation is quite clear.  I cannot find any reference that in creating a thread/window/DC/RC combination that each DC for each thread/window is unique and/or different.

Could you point out a page and book that documents this?  I have the Red, Blue, Green, White, and SuperBible OpenGL books.

As well as if you have many different RCs based upon the same DC in the same thread, and you call swapbuffers() I would assume that all the RCs swap?  This would require the critical section that you mentioned, correct?

Thanks for your time Mike!

Avatar of Lischke
Lischke

Well, you are right concerning the uniqueness of DC/RC combinations. What I meant with this comment was that you can only have one active RC at a given time.

MSDN states:

Multithread OpenGL Drawing Strategies
The GDI does not support multiple threads. You must use a distinct device context and a distinct rendering context for each thread. This tends to limit the performance advantages of using multiple threads with single-processor systems running OpenGL applications. However, there are ways to use threads with a single processor system to greatly increase performance. For example, you can use a separate thread to pass OpenGL rendering calls to dedicated 3-D hardware.

Symmetric multiprocessing (SMP) systems can greatly benefit from using multiple threads. An obvious strategy is to use a separate thread for each processor to handle OpenGL rendering in separate windows. For example, in a flight-simulation application you could use separate processors and threads to render the front, back, and side views.

A thread can have only one current, active rendering context. When you use multiple threads and multiple rendering contexts, you must be careful to synchronize their use. For example, use one thread only to call SwapBuffers after all threads finish drawing.

<end of quote>

I never tried to use several RCs on one DC, but from my experience I'd assume that swapping the buffers on such a single DC means also swapping the buffers for all RCs.

What you should keep in mind is that an RC is just a set of context variables for a specific DC. As such one cannot speak of swapping the buffers of an RC. SwapBuffers is a GDI function not an OpenGL function!

Does this also make sense to you?

Ciao, Mike

This clears this up considerably, Thankyou!