Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

vrj::GlPipe Class Reference

Handles the rendering on multiple GLWindows in a single process. More...

#include <GlPipe.h>

Collaboration diagram for vrj::GlPipe:

Collaboration graph
[legend]
List of all members.

Public Methods

 GlPipe (int num, GlDrawManager *glMgr)
 Constructor. More...

int start ()
 Starts the pipe running. More...

void controlLoop (void *nullParam)
 The main loop routine. More...

void stop ()
 Stops the pipe. More...

void triggerRender ()
 Triggers rendering of the pipe to start. More...

void completeRender ()
 Blocks until rendering of the windows is completed. More...

void triggerSwap ()
 Triggers swapping of all pipe's windows. More...

void completeSwap ()
 Blocks until swapping of the windows is completed. More...

void addWindow (GlWindow *win)
 Adds a GLWindow to the window list. More...

void removeWindow (GlWindow *win)
 Removes a GLWindow from the window list. More...

int hasWindows ()
 Returns true if pipe has any windows. More...

std::vector< GlWindow * > getOpenWindows ()
 Return a list of open windows. More...


Detailed Description

Handles the rendering on multiple GLWindows in a single process.

This class can be used to group glWindows to render efficiently on one pipe (SGI terminology).

Date:
1-12-98

Definition at line 56 of file GlPipe.h.


Constructor & Destructor Documentation

vrj::GlPipe::GlPipe int    num,
GlDrawManager   glMgr
[inline]
 

Constructor.

Parameters:
num  The id number of the pipe.
glMgr  The GL Draw Manager instance associated with this pipe.
Note:
All contained windows SHOULD have the same pipe number.

Definition at line 67 of file GlPipe.h.

00068       : mActiveThread(NULL)
00069       , mPipeNum(num)
00070       , controlExit(0)
00071       , glManager(glMgr)
00072       , renderTriggerSema(0)
00073       , renderCompleteSema(0)
00074       , swapTriggerSema(0)
00075       , swapCompleteSema(0)
00076    {
00077       mThreadRunning = false;
00078    }


Member Function Documentation

int vrj::GlPipe::start  
 

Starts the pipe running.

Precondition:
The pipe should not have a thread of control yet.
Postcondition:
The pipe has it's own thread of control and is ready to operate The Thread of control is running controlLoop.
Note:
The pipe does NOT have to have any windows in order to run that way we can add windows to pipes at run-time.

Definition at line 63 of file GlPipe.cpp.

References vrjDBG_DRAW_MGR.

00064 {
00065     vprASSERT(mThreadRunning == false);        // We should not be running yet
00066 
00067     // Create a new thread to call the control loop
00068     vpr::ThreadMemberFunctor<GlPipe>* memberFunctor =
00069          new vpr::ThreadMemberFunctor<GlPipe>(this, &GlPipe::controlLoop, NULL);
00070 
00071     mActiveThread = new vpr::Thread(memberFunctor);
00072 
00073     vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00074        << "vjGlPipe::start: Started control loop. " << mActiveThread
00075        << std::endl << vprDEBUG_FLUSH;
00076     return 1;        // XXX: Is this always true?
00077 }

void vrj::GlPipe::controlLoop void *    nullParam
 

The main loop routine.

-Checks for new windows
-renders all windows when triggered

Definition at line 160 of file GlPipe.cpp.

00161 {
00162    boost::ignore_unused_variable_warning(nullParam);
00163    mThreadRunning = true;     // We are running so set flag
00164    // Loop until flag set
00165    while (!controlExit)
00166    {
00167       checkForWindowsToClose();  // Checks for closing windows
00168       checkForNewWindows();      // Checks for new windows to open
00169 
00170       // --- handle EVENTS for the windows --- //
00171       // XXX: This may have to be here because of need to get open window event (Win32)
00172       // otherwise I would like to move it to being after the swap to get better performance
00173       {
00174          for(unsigned int winId=0;winId<mOpenWins.size();winId++)
00175             mOpenWins[winId]->checkEvents();
00176       }
00177 
00178       // --- RENDER the windows ---- //
00179       {
00180          renderTriggerSema.acquire();
00181 
00182          GlApp* the_app = glManager->getApp();
00183 
00184          // --- pipe PRE-draw function ---- //
00185          the_app->pipePreDraw();      // Can't get a context since I may not be guaranteed a window
00186 
00187          // Render the windows
00188          for (unsigned int winId=0;winId < mOpenWins.size();winId++) {
00189             renderWindow(mOpenWins[winId]);
00190          }
00191          renderCompleteSema.release();
00192       }
00193 
00194       // ----- SWAP the windows ------ //
00195       {
00196          swapTriggerSema.acquire();
00197 
00198          // Swap all the windows
00199          for(unsigned int winId=0;winId < mOpenWins.size();winId++)
00200          {
00201             swapWindowBuffers(mOpenWins[winId]);
00202          }
00203 
00204          swapCompleteSema.release();
00205       }
00206    }
00207 
00208    mThreadRunning = false;     // We are not running
00209 }

void vrj::GlPipe::stop   [inline]
 

Stops the pipe.

Postcondition:
Flag is set to tell pipe to stop rendering.

Definition at line 102 of file GlPipe.h.

00103    { controlExit = 1; }     // Set the control loop exit flag

void vrj::GlPipe::triggerRender  
 

Triggers rendering of the pipe to start.

Precondition:
The pipe must have a thread of control.
Postcondition:
The pipe has be told to start rendering.

Definition at line 83 of file GlPipe.cpp.

References vrjDBG_DRAW_MGR.

00084 {
00085    //vprASSERT(mThreadRunning == true);      // We must be running
00086    while(!mThreadRunning)
00087    {
00088       vprDEBUG(vrjDBG_DRAW_MGR,vprDBG_HVERB_LVL) << "Waiting in for thread to start triggerRender.\n" << vprDEBUG_FLUSH;
00089       vpr::Thread::yield();
00090    }
00091 
00092    renderTriggerSema.release();
00093 }

void vrj::GlPipe::completeRender  
 

Blocks until rendering of the windows is completed.

Precondition:
The pipe must have a thread of control.
Postcondition:
The pipe has completed its rendering.

Definition at line 99 of file GlPipe.cpp.

00100 {
00101    vprASSERT(mThreadRunning == true);      // We must be running
00102 
00103    renderCompleteSema.acquire();
00104 }

void vrj::GlPipe::triggerSwap  
 

Triggers swapping of all pipe's windows.

Precondition:
The pipe must have a thread of control.
Postcondition:
The pipe has be told to swap.

Definition at line 107 of file GlPipe.cpp.

00108 {
00109    vprASSERT(mThreadRunning == true);
00110    swapTriggerSema.release();
00111 }

void vrj::GlPipe::completeSwap  
 

Blocks until swapping of the windows is completed.

Precondition:
The pipe must have a thread of control.
Postcondition:
The pipe has completed its rendering.

Definition at line 114 of file GlPipe.cpp.

00115 {
00116    vprASSERT(mThreadRunning == true);
00117    swapCompleteSema.acquire();
00118 }

void vrj::GlPipe::addWindow GlWindow   win
 

Adds a GLWindow to the window list.

Control loop must now open the window on the next frame.

Definition at line 125 of file GlPipe.cpp.

References vrjDBG_DRAW_MGR.

00126 {
00127    vpr::Guard<vpr::Mutex> guardNew(mNewWinLock);       // Protect the data
00128    vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00129       << "vjGlPipe::addWindow: Pipe: " << mPipeNum
00130       << " adding window (to new wins):\n" << win
00131       << std::endl << vprDEBUG_FLUSH;
00132    mNewWins.push_back(win);
00133 }

void vrj::GlPipe::removeWindow GlWindow   win
 

Removes a GLWindow from the window list.

Note:
The window is not actually removed until the next draw trigger.

Definition at line 139 of file GlPipe.cpp.

References vrjDBG_DRAW_MGR.

00140 {
00141    vpr::Guard<vpr::Mutex> guardClosing(mClosingWinLock);
00142    vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00143       << "vjGlPipe:: removeWindow: Pipe: " << mPipeNum
00144       << " window added to closingWins.\n" << win
00145       << std::endl << vprDEBUG_FLUSH;
00146    mClosingWins.push_back(win);
00147 }

int vrj::GlPipe::hasWindows   [inline]
 

Returns true if pipe has any windows.

Definition at line 149 of file GlPipe.h.

00150    {
00151       return ( (mNewWins.size() > 0) || (mOpenWins.size() > 0));
00152    }

std::vector<GlWindow*> vrj::GlPipe::getOpenWindows   [inline]
 

Return a list of open windows.

Definition at line 155 of file GlPipe.h.

00156    {
00157       return mOpenWins;
00158    }


The documentation for this class was generated from the following files:
Generated on Sun May 2 15:11:10 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002