Solved

OpenGL RCs and GDI DCs and SwapBuffers call

Posted on 1998-10-29
4
709 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …

739 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