Solved

OpenGL RCs and GDI DCs and SwapBuffers call

Posted on 1998-10-29
4
683 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:kradloff
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Lischke earned 100 total points
ID: 1113114
I think the documentation is qite clear in this regard. You only can have one RC current at a given time (for a specific DC). By calling SwapBuffers you only swap fore- and background buffers of that specific DC (which isn't necessarily a window DC but can also be a DC of a DIB, a printer, a meta file etc.).

Since each of your threads has an own window with an own DC/RC, you have to call SwapBuffers for each DC seperately in its painting routine. But you can savely share an RC if you take care of synchronizing access to it (critical section provide an efficient way).

Ciao, Mike
0
 

Author Comment

by:kradloff
ID: 1113115
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!

0
 
LVL 10

Expert Comment

by:Lischke
ID: 1113116
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

0
 

Author Comment

by:kradloff
ID: 1113117
This clears this up considerably, Thankyou!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now