OpenWalnut  1.4.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes
WGraphicsEngine Class Reference

Base class for initializing the graphics engine. More...

#include <WGraphicsEngine.h>

+ Inheritance diagram for WGraphicsEngine:

List of all members.

Public Member Functions

virtual ~WGraphicsEngine ()
 Destructor.
osg::ref_ptr< WGEScenegetScene ()
 Returns the root node of the WGraphicsEngine (this is not the root node of the OSG).
boost::shared_ptr< WGEViewercreateViewer (std::string name, osg::ref_ptr< osg::Referenced > wdata, int x, int y, int width, int height, WGECamera::ProjectionMode projectionMode=WGECamera::ORTHOGRAPHIC, WColor bgColor=WColor(1.0, 1.0, 1.0, 1.0))
 Creates a new viewer.
void closeViewer (const std::string name)
 Closes a viewer and deletes it from the list of viewers.
boost::shared_ptr< WGEViewergetViewerByName (std::string name)
 Searches for a viewer with a given name and returns it, if found.
boost::shared_ptr< WGEViewergetViewer ()
 Returns the unnamed view, which is the view for the default scene which can be acquired using getScene().
void requestShaderReload ()
 This requests all shaders to reload during the next update cycle.
boost::signals2::connection subscribeSignal (GE_SIGNAL signal, t_GEGenericSignalHandlerType notifier)
 Subscribe a specified handler to the specified signal emited by the GE.
void finalizeStartup ()
 Function notifies the viewer threads (if any) to start.
void waitForFinalize ()
 Wait until someone called finalizeStartup().
void setMultiThreadedViews (bool enable=true)
 Enables multithreaded view.
bool isMultiThreadedViews () const
 Checks whether the viewers work multithreaded.

Static Public Member Functions

static boost::shared_ptr
< WGraphicsEngine
getGraphicsEngine ()
 Returns instance of the graphics engine.
static bool isRunning ()
 Checks whether the graphics engine is currently running or not.
static bool waitForStartupComplete ()
 Waits for the GE to come up.

Protected Member Functions

 WGraphicsEngine ()
 Constructors are protected because this is a Singleton.
virtual void threadMain ()
 Handler for repainting and event handling.
virtual void notifyStop ()
 Gets called when the thread should be stopped.

Protected Attributes

osg::ref_ptr< WGEScenem_rootNode
 OpenSceneGraph root node.
std::map< std::string,
boost::shared_ptr< WGEViewer > > 
m_viewers
 All registered viewers.
boost::mutex m_viewersLock
 Mutex used to lock the map of viewers.
osg::ref_ptr
< osgViewer::CompositeViewer > 
m_viewer
 OpenSceneGraph composite viewer.
t_GEGenericSignalType m_reloadShadersSignal
 Signal getting emitted whenever a reload shader request is waiting.

Private Attributes

bool m_running
 True if graphics engine is running.
WConditionOneShot m_startThreadingCondition
 This condition is fired externally if all the GUI startup is done to ensure all OGL stuff is initialized prior to OSG threading startup.

Static Private Attributes

static boost::shared_ptr
< WGraphicsEngine
m_instance = boost::shared_ptr< WGraphicsEngine >()
 Singleton instance of WGraphicsEngine.

Detailed Description

Base class for initializing the graphics engine.

This Class also serves as adaptor to access the graphics engine.

Definition at line 55 of file WGraphicsEngine.h.


Constructor & Destructor Documentation

Destructor.

Definition at line 75 of file WGraphicsEngine.cpp.

References WLogger::addLogMessage(), and WLogger::getLogger().

WGraphicsEngine::WGraphicsEngine ( ) [explicit, protected]

Constructors are protected because this is a Singleton.

Definition at line 58 of file WGraphicsEngine.cpp.

References WLogger::addLogMessage(), WLogger::getLogger(), m_rootNode, m_viewer, and WThreadedRunner::setThreadName().

Referenced by getGraphicsEngine().


Member Function Documentation

void WGraphicsEngine::closeViewer ( const std::string  name)

Closes a viewer and deletes it from the list of viewers.

Parameters:
namethe name of the viewer

Definition at line 155 of file WGraphicsEngine.cpp.

References m_viewers, and m_viewersLock.

boost::shared_ptr< WGEViewer > WGraphicsEngine::createViewer ( std::string  name,
osg::ref_ptr< osg::Referenced >  wdata,
int  x,
int  y,
int  width,
int  height,
WGECamera::ProjectionMode  projectionMode = WGECamera::ORTHOGRAPHIC,
WColor  bgColor = WColor( 1.0, 1.0, 1.0, 1.0 ) 
)

Creates a new viewer.

Does basic initialization and sets the default scene.

Parameters:
namethe name of the viewer
wdatathe WindowData instance for the widget to use as render widget
xX coordinate of widget where to create the context.
yY coordinate of widget where to create the context.
widthWidth of the widget.
heightHeight of the Widget.
projectionModeProjection mode of the viewer.
bgColorbackground color shown in the viewer.
Returns:
the new instance, ready to be used.
Exceptions:
WGEInitFailedthrown if initialization of graphics context or graphics window has failed.

Definition at line 133 of file WGraphicsEngine.cpp.

References getScene(), m_viewer, m_viewers, and m_viewersLock.

Function notifies the viewer threads (if any) to start.

This should only be called AFTER the OpenGL widgets/windows have been initialized.

Definition at line 239 of file WGraphicsEngine.cpp.

References m_startThreadingCondition, and WConditionOneShot::notify().

boost::shared_ptr< WGraphicsEngine > WGraphicsEngine::getGraphicsEngine ( ) [static]

Returns instance of the graphics engine.

If it does not exists, it will be created.

Returns:
the running graphics engine instance.

Definition at line 118 of file WGraphicsEngine.cpp.

References m_instance, and WGraphicsEngine().

Referenced by WGEProjectFileIO::done(), WGEZoomTrackballManipulator::handle(), WGEBorderLayout::SafeUpdateCallback::operator()(), WRMBranch::removeAllRois(), WROIManager::removeRoi(), WGEProjectFileIO::save(), WGEShader::WGEShader(), WROIArbitrary::WROIArbitrary(), WROIBox::WROIBox(), and WROISphere::WROISphere().

osg::ref_ptr< WGEScene > WGraphicsEngine::getScene ( )

Returns the root node of the WGraphicsEngine (this is not the root node of the OSG).

Returns:
the root node.

Definition at line 128 of file WGraphicsEngine.cpp.

References m_rootNode.

Referenced by createViewer().

boost::shared_ptr< WGEViewer > WGraphicsEngine::getViewer ( )

Returns the unnamed view, which is the view for the default scene which can be acquired using getScene().

Returns:
the viewer for the default scene.

Definition at line 175 of file WGraphicsEngine.cpp.

References m_viewers, and m_viewersLock.

boost::shared_ptr< WGEViewer > WGraphicsEngine::getViewerByName ( std::string  name)

Searches for a viewer with a given name and returns it, if found.

Parameters:
namethe name of the viewer
Returns:
a shared pointer to the viewer or NULL if not found

Definition at line 166 of file WGraphicsEngine.cpp.

References m_viewers, and m_viewersLock.

Checks whether the viewers work multithreaded.

Returns:
true if multithreaded

Definition at line 109 of file WGraphicsEngine.cpp.

References m_viewer.

bool WGraphicsEngine::isRunning ( ) [static]

Checks whether the graphics engine is currently running or not.

Returns:
true if running

Definition at line 181 of file WGraphicsEngine.cpp.

References m_instance.

Referenced by waitForStartupComplete().

void WGraphicsEngine::notifyStop ( ) [protected, virtual]

Gets called when the thread should be stopped.

Reimplemented from WThreadedRunner.

Definition at line 229 of file WGraphicsEngine.cpp.

References WLogger::addLogMessage(), WLogger::getLogger(), m_startThreadingCondition, m_viewer, and WConditionOneShot::notify().

This requests all shaders to reload during the next update cycle.

Definition at line 249 of file WGraphicsEngine.cpp.

References m_reloadShadersSignal.

void WGraphicsEngine::setMultiThreadedViews ( bool  enable = true)

Enables multithreaded view.

This MUST be called before run(). On Mac, this has no function.

Parameters:
enabletrue if multithreaded

Definition at line 81 of file WGraphicsEngine.cpp.

References WLogger::addLogMessage(), WLogger::getLogger(), and m_viewer.

boost::signals2::connection WGraphicsEngine::subscribeSignal ( GE_SIGNAL  signal,
t_GEGenericSignalHandlerType  notifier 
)

Subscribe a specified handler to the specified signal emited by the GE.

Parameters:
signalthe signal to connect to
notifierthe signal handler
Returns:
connection object.

Definition at line 254 of file WGraphicsEngine.cpp.

References m_reloadShadersSignal, m_startThreadingCondition, and WCondition::subscribeSignal().

void WGraphicsEngine::threadMain ( ) [protected, virtual]

Handler for repainting and event handling.

Gets executed in separate thread.

Reimplemented from WThreadedRunner.

Definition at line 208 of file WGraphicsEngine.cpp.

References WLogger::addLogMessage(), WLogger::getLogger(), WGEPostprocessor::initPostprocessors(), m_running, m_startThreadingCondition, m_viewer, and WConditionOneShot::wait().

Wait until someone called finalizeStartup().

Definition at line 244 of file WGraphicsEngine.cpp.

References m_startThreadingCondition, and WConditionOneShot::wait().

Waits for the GE to come up.

Fails if engine is not started.

Returns:
true if engine now running

Definition at line 191 of file WGraphicsEngine.cpp.

References WLogger::addLogMessage(), WLogger::getLogger(), isRunning(), and m_instance.

Referenced by WGERequirement::isComplied().


Member Data Documentation

boost::shared_ptr< WGraphicsEngine > WGraphicsEngine::m_instance = boost::shared_ptr< WGraphicsEngine >() [static, private]

Singleton instance of WGraphicsEngine.

Definition at line 215 of file WGraphicsEngine.h.

Referenced by getGraphicsEngine(), isRunning(), and waitForStartupComplete().

t_GEGenericSignalType WGraphicsEngine::m_reloadShadersSignal [protected]

Signal getting emitted whenever a reload shader request is waiting.

Definition at line 209 of file WGraphicsEngine.h.

Referenced by requestShaderReload(), and subscribeSignal().

osg::ref_ptr<WGEScene> WGraphicsEngine::m_rootNode [protected]

OpenSceneGraph root node.

Definition at line 189 of file WGraphicsEngine.h.

Referenced by getScene(), and WGraphicsEngine().

True if graphics engine is running.

Definition at line 220 of file WGraphicsEngine.h.

Referenced by threadMain().

This condition is fired externally if all the GUI startup is done to ensure all OGL stuff is initialized prior to OSG threading startup.

Definition at line 225 of file WGraphicsEngine.h.

Referenced by finalizeStartup(), notifyStop(), subscribeSignal(), threadMain(), and waitForFinalize().

osg::ref_ptr<osgViewer::CompositeViewer> WGraphicsEngine::m_viewer [protected]

OpenSceneGraph composite viewer.

Contains all created osgViewer::Views.

Definition at line 204 of file WGraphicsEngine.h.

Referenced by createViewer(), isMultiThreadedViews(), notifyStop(), setMultiThreadedViews(), threadMain(), and WGraphicsEngine().

std::map< std::string, boost::shared_ptr< WGEViewer > > WGraphicsEngine::m_viewers [protected]

All registered viewers.

Definition at line 194 of file WGraphicsEngine.h.

Referenced by closeViewer(), createViewer(), getViewer(), and getViewerByName().

boost::mutex WGraphicsEngine::m_viewersLock [protected]

Mutex used to lock the map of viewers.

Definition at line 199 of file WGraphicsEngine.h.

Referenced by closeViewer(), createViewer(), getViewer(), and getViewerByName().


The documentation for this class was generated from the following files: