#include <GlDrawManager.h>
Inheritance diagram for vrj::GlDrawManager:


Public Methods | |
| virtual void | start () |
| Starts the control loop. More... | |
| virtual void | draw () |
| Enables a frame to be drawn. More... | |
| virtual void | sync () |
| Blocks until the end of the frame. More... | |
| void | main (void *nullParam) |
| This is the control loop for the manager. More... | |
| virtual void | initAPI () |
| Initializes the drawing API (if not already running). More... | |
| virtual void | addDisplay (Display *disp) |
| Callback when display is added to display manager. More... | |
| virtual void | removeDisplay (Display *disp) |
| Callback when display is removed to display manager. More... | |
| virtual void | closeAPI () |
| Shutdown the drawing API. More... | |
| virtual void | outStream (std::ostream &out) |
| dumps the object's internal state. More... | |
| void | drawAllPipes () |
| Draws all the ogl pipes/windows. More... | |
| virtual void | setApp (App *_app) |
| Sets the app the draw should interact with. More... | |
| GlApp * | getApp () |
| Returns the app we are rednering. More... | |
| virtual bool | configAdd (jccl::ConfigElementPtr element) |
| Adds the element to the draw manager config. More... | |
| virtual bool | configRemove (jccl::ConfigElementPtr element) |
| Removes the element from the current configuration. More... | |
| virtual bool | configCanHandle (jccl::ConfigElementPtr element) |
| Can the handler handle the given element? More... | |
| GlUserData * | currentUserData () |
| Gets ptr to the current user data. More... | |
| int | getCurrentContext () |
| Returns a unique identifier for the current context. More... | |
Protected Methods | |
| GlWindow * | getGLWindow () |
| Factory function to get system specific OpenGL window. More... | |
| void | setCurrentContext (int val) |
| void | dirtyAllWindows () |
| Sets the dirty bits off all the gl windows. More... | |
| bool | isValidWindow (GlWindow *win) |
| Is the window a valid window for the draw manager? More... | |
| GlDrawManager () | |
| virtual | ~GlDrawManager () |
| GlDrawManager (const GlDrawManager &o) | |
| void | operator= (const GlDrawManager &o) |
| vprSingletonHeader (GlDrawManager) | |
Protected Attributes | |
| int | numPipes |
| The number of pipes in the system. More... | |
| GlApp * | mApp |
| The OpenGL application. More... | |
| std::vector< GlWindow * > | mWins |
| A list of the windows in the system. More... | |
| std::vector< GlPipe * > | pipes |
| A list of the pipes in the system. More... | |
| vpr::TSObjectProxy< int > | mContextId |
| TS Data for context id. More... | |
| vpr::TSObjectProxy< GlUserData > | mUserData |
| vpr::Semaphore | drawTriggerSema |
| Semaphore for draw trigger. More... | |
| vpr::Semaphore | drawDoneSema |
| Semaphore for drawing done. More... | |
| bool | mRunning |
| Used to stop the drawing thread. More... | |
| vpr::ThreadMemberFunctor< GlDrawManager > * | mMemberFunctor |
| vpr::Thread * | mControlThread |
Friends | |
| class | GlPipe |
| class | GlContextDataBase |
Responsible for all OGL based rendering.
GlDrawManager is an active object. It manages ogl pipes and windows. In addition, it triggers rendering, swapping, and syncing of the windows under it's control.
All access to the ogl rendering structures has to happen from the control thread or in the case of context sensitive functions, from the control thread of the managed pipes. Because of this, the object uses queues to hold new windows.
Definition at line 85 of file GlDrawManager.h.
|
|
Definition at line 68 of file GlDrawManager.cpp.
00069 : mApp(NULL) 00070 , drawTriggerSema(0) 00071 , drawDoneSema(0) 00072 // , mRuntimeConfigSema(0) 00073 , mRunning(false) 00074 , mMemberFunctor(NULL) 00075 , mControlThread(NULL) 00076 { 00077 } |
|
|
Definition at line 233 of file GlDrawManager.h.
00234 {
00235 // XXX: Need to shut down the control thread and free the memory pointed
00236 // to by mMemberFunctor and mControlThread.
00237 }
|
|
|
Definition at line 239 of file GlDrawManager.h.
00240 : DrawManager() 00241 {;} |
|
|
Starts the control loop.
Definition at line 108 of file GlDrawManager.cpp. References mControlThread, mMemberFunctor, mRunning, and vrjDBG_DRAW_MGR. Referenced by initAPI.
00109 {
00110 // --- Setup Multi-Process stuff --- //
00111 // Create a new thread to handle the control
00112 mRunning = true;
00113
00114 mMemberFunctor =
00115 new vpr::ThreadMemberFunctor<GlDrawManager>(this, &GlDrawManager::main,
00116 NULL);
00117 mControlThread = new vpr::Thread(mMemberFunctor);
00118
00119 vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00120 << "vrj::GlDrawManager started (thread: " << mControlThread << ")\n"
00121 << vprDEBUG_FLUSH;
00122 }
|
|
|
Enables a frame to be drawn.
Implements vrj::DrawManager. Definition at line 127 of file GlDrawManager.cpp. References drawTriggerSema.
00128 {
00129 drawTriggerSema.release();
00130 }
|
|
|
Blocks until the end of the frame.
Implements vrj::DrawManager. Definition at line 137 of file GlDrawManager.cpp. References drawDoneSema.
00138 {
00139 drawDoneSema.acquire();
00140 }
|
|
|
This is the control loop for the manager.
Definition at line 144 of file GlDrawManager.cpp. References drawAllPipes, drawDoneSema, and drawTriggerSema.
00145 {
00146 boost::ignore_unused_variable_warning(nullParam);
00147
00148 while(mRunning)
00149 {
00150 //**// Runtime config will happen here
00151 // Because the kernel is the only one that can trigger it
00152 // we will be waiting here at that time
00153
00154 // Wait for trigger
00155 drawTriggerSema.acquire();
00156
00157 // While closing the GlDrawManager this thread will be waiting at
00158 // drawTriggerSema.acquire(). To properly stop this thread we must
00159 // allow it to fall through the semaphore and not execute drawAllPipes()
00160 if (mRunning)
00161 {
00162 // THEN --- Do Rendering --- //
00163 drawAllPipes();
00164 }
00165
00166 // -- Done rendering --- //
00167 drawDoneSema.release();
00168
00169 // Allow run-time config
00170 //**//mRuntimeConfigSema.release();
00171 // This is the time that reconfig can happen
00172 // configProcessPending();
00173 //**//mRuntimeConfigSema.acquire();
00174 }
00175 }
|
|
|
Initializes the drawing API (if not already running).
Implements vrj::DrawManager. Definition at line 218 of file GlDrawManager.cpp. References start.
00219 {
00220 start();
00221 }
|
|
|
Callback when display is added to display manager.
Implements vrj::DrawManager. Definition at line 233 of file GlDrawManager.cpp. References getGLWindow, GlPipe, isValidWindow, mWins, pipes, and vrjDBG_DRAW_MGR.
00234 {
00235 vprASSERT(disp != NULL); // Can't add a null display
00236
00237 vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00238 << "vrj::GlDrawManager:addDisplay: " << disp
00239 << std::endl << vprDEBUG_FLUSH;
00240
00241
00242 // -- Finish Simulator setup
00243 int num_vp(disp->getNumViewports());
00244
00245 for (int i = 0 ; i < num_vp ; i++)
00246 {
00247 Viewport* vp = disp->getViewport(i);
00248
00249 if (vp->isSimulator())
00250 {
00251 jccl::ConfigElementPtr vp_element = vp->getConfigElement();
00252
00253 SimViewport* sim_vp(NULL);
00254 sim_vp = dynamic_cast<SimViewport*>(vp);
00255 vprASSERT(NULL != sim_vp);
00256
00257 sim_vp->setDrawSimInterface(NULL);
00258
00259 // Create the simulator stuff
00260 vprASSERT(1 == vp_element->getNum("simulator_plugin") && "You must supply a simulator plugin.");
00261
00262 // Create the simulator stuff
00263 jccl::ConfigElementPtr sim_element =
00264 vp_element->getProperty<jccl::ConfigElementPtr>("simulator_plugin");
00265
00266 vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00267 << "GlDrawManager::addDisplay() creating simulator of type '"
00268 << sim_element->getID() << "'\n" << vprDEBUG_FLUSH;
00269
00270 DrawSimInterface* new_sim_i =
00271 GlSimInterfaceFactory::instance()->createObject(sim_element->getID());
00272
00273 // XXX: Change this to an error once the new simulator loading code is
00274 // more robust. -PH (4/13/2003)
00275 vprASSERT(NULL != new_sim_i && "Failed to create draw simulator");
00276 sim_vp->setDrawSimInterface(new_sim_i);
00277 new_sim_i->initialize(sim_vp);
00278 new_sim_i->config(sim_element);
00279 }
00280 }
00281
00282
00283 // -- Create a window for new display
00284 // -- Store the window in the wins vector
00285 // Create the gl window object. NOTE: The glPipe actually "creates" the opengl window and context later
00286 GlWindow* new_win = getGLWindow();
00287 new_win->configWindow(disp); // Configure it
00288 mWins.push_back(new_win); // Add to our local window list
00289
00290 // -- Create any needed Pipes & Start them
00291 unsigned int pipe_num = new_win->getDisplay()->getPipe(); // Find pipe to add it too
00292
00293 if(pipes.size() < (pipe_num+1)) // ASSERT: Max index of pipes is < our pipe
00294 { // +1 because if pipeNum = 0, I still need size() == 1
00295 while(pipes.size() < (pipe_num+1)) // While we need more pipes
00296 {
00297 GlPipe* new_pipe = new GlPipe(pipes.size(), this); // Create a new pipe to use
00298 pipes.push_back(new_pipe); // Add the pipe
00299 new_pipe->start(); // Start the pipe running
00300 // NOTE: Run pipe even if no windows. Then it waits for windows.
00301 }
00302 }
00303
00304 // -- Add window to the correct pipe
00305 GlPipe* pipe; // The pipe to assign it to
00306 pipe = pipes[pipe_num]; // ASSERT: pipeNum is in the valid range
00307 pipe->addWindow(new_win); // Window has been added
00308
00309 vprASSERT(isValidWindow(new_win)); // Make sure it was added to draw manager
00310 }
|
|
|
Callback when display is removed to display manager.
Implements vrj::DrawManager. Definition at line 318 of file GlDrawManager.cpp. References GlPipe, isValidWindow, mWins, and pipes.
00319 {
00320 GlPipe* pipe; pipe = NULL;
00321 GlWindow* win; win = NULL; // Window to remove
00322
00323 for(unsigned int i=0;i<mWins.size();i++)
00324 {
00325 if(mWins[i]->getDisplay() == disp) // FOUND it
00326 {
00327 win = mWins[i];
00328 pipe = pipes[win->getDisplay()->getPipe()];
00329 }
00330 }
00331
00332 // Remove the window from the pipe and our local list
00333 if(win != NULL)
00334 {
00335 vprASSERT(pipe != NULL);
00336 vprASSERT(isValidWindow(win));
00337 pipe->removeWindow(win); // Remove from pipe
00338 mWins.erase(std::remove(mWins.begin(),mWins.end(),win), mWins.end()); // Remove from draw manager
00339 vprASSERT(!isValidWindow(win));
00340 }
00341 else
00342 {
00343 vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL) << clrOutNORM(clrRED,"ERROR:") << "vrj::GlDrawManager::removeDisplay: Attempted to remove a display that was not found.\n" << vprDEBUG_FLUSH;
00344 vprASSERT(false);
00345 }
00346
00347 }
|
|
|
Shutdown the drawing API.
Implements vrj::DrawManager. Definition at line 351 of file GlDrawManager.cpp. References drawDoneSema, drawTriggerSema, mRunning, and vrjDBG_DRAW_MGR.
00352 {
00353 vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL) << "vrj::GlDrawManager::closeAPI\n" << vprDEBUG_FLUSH;
00354
00355 mRunning = false;
00356
00357 drawTriggerSema.release();
00358 drawDoneSema.acquire();
00359
00360 // TODO: Must shutdown and delete all pipes.
00361 // Stop and delete all pipes
00362
00363 // TODO: We must fix the closing of EventWindows and GlWindows before we can do this.
00364 // Close and delete all glWindows
00365 }
|
|
|
dumps the object's internal state.
Definition at line 426 of file GlDrawManager.cpp.
00427 {
00428 out << clrSetNORM(clrGREEN)
00429 << "========== GlDrawManager: " << (void*)this << " ========="
00430 << clrRESET << std::endl
00431 << clrOutNORM(clrCYAN,"\tapp: ") << (void*)mApp << std::endl
00432 << clrOutNORM(clrCYAN,"\tWindow count: ") << mWins.size()
00433 << std::endl << std::flush;
00434
00435 for(unsigned int i = 0; i < mWins.size(); i++)
00436 {
00437 vprASSERT(mWins[i] != NULL);
00438 out << clrOutNORM(clrCYAN,"\tGlWindow:\n") << *(mWins[i]) << std::endl;
00439 }
00440 out << "=======================================" << std::endl;
00441 }
|
|
|
Draws all the ogl pipes/windows.
Definition at line 177 of file GlDrawManager.cpp. References pipes, and vrjDBG_DRAW_MGR. Referenced by main.
00178 {
00179 vprDEBUG_BEGIN(vrjDBG_DRAW_MGR,vprDBG_HVERB_LVL)
00180 << "vjGLDrawManager::drawAllPipes: " << std::endl << std::flush
00181 << vprDEBUG_FLUSH;
00182 unsigned int pipeNum;
00183
00184 // RENDER
00185 // Start rendering all the pipes
00186 for(pipeNum=0; pipeNum<pipes.size(); pipeNum++)
00187 pipes[pipeNum]->triggerRender();
00188
00189 // Wait for rendering to finish on all the pipes
00190 for(pipeNum=0; pipeNum<pipes.size(); pipeNum++)
00191 pipes[pipeNum]->completeRender();
00192
00193 // Barrier for Cluster
00194 //vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) << "BARRIER: Going to sleep for: " << num << std::endl << vprDEBUG_FLUSH;
00195 cluster::ClusterManager::instance()->createBarrier();
00196 //vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) << "BARRIER: IS DONE" << std::endl << vprDEBUG_FLUSH;
00197
00198
00199 // SWAP
00200 // Start swapping all the pipes
00201 for(pipeNum=0; pipeNum<pipes.size(); pipeNum++)
00202 pipes[pipeNum]->triggerSwap();
00203
00204 // Wait for swapping to finish on all the pipes
00205 for(pipeNum=0; pipeNum<pipes.size(); pipeNum++)
00206 pipes[pipeNum]->completeSwap();
00207
00208
00209 vprDEBUG_END(vrjDBG_DRAW_MGR,vprDBG_HVERB_LVL)
00210 << "vjGLDrawManager::drawAllPipes: Done" << std::endl << std::flush
00211 << vprDEBUG_FLUSH;
00212 }
|
|
|
Sets the app the draw should interact with.
Implements vrj::DrawManager. Definition at line 80 of file GlDrawManager.cpp. References dirtyAllWindows, and mApp.
00081 {
00082 mApp = dynamic_cast<GlApp*>(_app);
00083
00084 // We have a new app, so the contexts must be re-initialized
00085 // so... dirty them all.
00086 dirtyAllWindows();
00087 vprASSERT(mApp != NULL);
00088 }
|
|
|
Returns the app we are rednering.
Definition at line 91 of file GlDrawManager.cpp. References mApp.
00092 {
00093 return mApp;
00094 }
|
|
|
Adds the element to the draw manager config.
Definition at line 372 of file GlDrawManager.cpp.
00373 {
00374 boost::ignore_unused_variable_warning(element);
00375 return false;
00376 }
|
|
|
Removes the element from the current configuration.
Definition at line 383 of file GlDrawManager.cpp.
00384 {
00385 boost::ignore_unused_variable_warning(element);
00386 return false;
00387 }
|
|
|
Can the handler handle the given element?
Definition at line 393 of file GlDrawManager.cpp.
00394 {
00395 boost::ignore_unused_variable_warning(element);
00396 return false;
00397 }
|
|
|
Gets ptr to the current user data. Should be used in the draw function.
Definition at line 178 of file GlDrawManager.h. Referenced by vrj::OpenSGApp::draw.
00179 { return &(*mUserData); }
|
|
|
Returns a unique identifier for the current context.
Definition at line 186 of file GlDrawManager.h.
00187 { return (*mContextId); }
|
|
|
Factory function to get system specific OpenGL window.
Definition at line 457 of file GlDrawManager.cpp. Referenced by addDisplay.
00458 {
00459 #if defined(VPR_OS_Win32)
00460 return new vrj::GlWindowWin32;
00461 #elif defined(VPR_OS_Darwin) && ! defined(VRJ_USE_X11)
00462 return new vrj::GlWindowOSX;
00463 #else
00464 return new vrj::GlWindowXWin;
00465 #endif
00466 }
|
|
|
Definition at line 197 of file GlDrawManager.h.
00198 { (*mContextId) = val; }
|
|
|
Sets the dirty bits off all the gl windows. Dirty all the window contexts. Definition at line 404 of file GlDrawManager.cpp. References mWins. Referenced by setApp.
|
|
|
Is the window a valid window for the draw manager?
Definition at line 414 of file GlDrawManager.cpp. References mWins. Referenced by addDisplay, and removeDisplay.
|
|
|
Definition at line 243 of file GlDrawManager.h.
00243 {;}
|
|
|
|
|
|
Definition at line 88 of file GlDrawManager.h. Referenced by addDisplay, and removeDisplay. |
|
|
Definition at line 89 of file GlDrawManager.h. |
|
|
The number of pipes in the system.
Definition at line 209 of file GlDrawManager.h. |
|
|
The OpenGL application.
Definition at line 212 of file GlDrawManager.h. |
|
|
A list of the windows in the system.
Definition at line 213 of file GlDrawManager.h. Referenced by addDisplay, dirtyAllWindows, isValidWindow, outStream, and removeDisplay. |
|
|
A list of the pipes in the system.
Definition at line 214 of file GlDrawManager.h. Referenced by addDisplay, drawAllPipes, and removeDisplay. |
|
|
TS Data for context id.
Definition at line 217 of file GlDrawManager.h. |
|
|
Definition at line 218 of file GlDrawManager.h. |
|
|
Semaphore for draw trigger.
Definition at line 221 of file GlDrawManager.h. |
|
|
Semaphore for drawing done.
Definition at line 222 of file GlDrawManager.h. |
|
|
Used to stop the drawing thread.
Definition at line 225 of file GlDrawManager.h. |
|
|
Definition at line 227 of file GlDrawManager.h. Referenced by start. |
|
|
Definition at line 228 of file GlDrawManager.h. Referenced by start. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002