OpenWalnut
1.5.0dev
|
Base class for initializing the graphics engine. More...
#include <WGraphicsEngine.h>
Public Member Functions | |
virtual | ~WGraphicsEngine () |
Destructor. More... | |
osg::ref_ptr< WGEScene > | getScene () |
Returns the root node of the WGraphicsEngine (this is not the root node of the OSG). More... | |
std::shared_ptr< WGEViewer > | 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. More... | |
void | closeViewer (const std::string name) |
Closes a viewer and deletes it from the list of viewers. More... | |
void | closeViewer (std::shared_ptr< WGEViewer > viewer) |
Closes a viewer and deletes it from the list of viewers. More... | |
std::shared_ptr< WGEViewer > | getViewerByName (std::string name) |
Searches for a viewer with a given name and returns it, if found. More... | |
std::shared_ptr< WGEViewer > | getViewer () |
Returns the unnamed view, which is the view for the default scene which can be acquired using getScene(). More... | |
void | requestShaderReload () |
This requests all shaders to reload during the next update cycle. More... | |
boost::signals2::connection | subscribeSignal (GE_SIGNAL signal, t_GEGenericSignalHandlerType notifier) |
Subscribe a specified handler to the specified signal emited by the GE. More... | |
void | finalizeStartup () |
Function notifies the viewer threads (if any) to start. More... | |
void | waitForFinalize () |
Wait until someone called finalizeStartup(). More... | |
void | setMultiThreadedViews (bool enable=true) |
Enables multithreaded view. More... | |
bool | isMultiThreadedViews () const |
Checks whether the viewers work multithreaded. More... | |
virtual boost::signals2::connection | subscribeSignal (THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier) |
Connects a specified notify function with a signal this thread instance is offering. More... | |
Public Member Functions inherited from WThreadedRunner | |
WThreadedRunner () | |
Default constructor. More... | |
virtual | ~WThreadedRunner () |
Destructor. More... | |
virtual void | run () |
Run thread. More... | |
void | run (THREADFUNCTION f) |
Run thread. More... | |
void | wait (bool requestFinish=false) |
Wait for the thread to be finished. More... | |
virtual void | requestStop () |
This method's purpose is to request a stop without waiting for it. More... | |
virtual boost::signals2::connection | subscribeSignal (THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier) |
Connects a specified notify function with a signal this thread instance is offering. More... | |
const WBoolFlag & | isCrashed () const |
Checks whether this thread has been crashed. More... | |
const std::string & | getCrashMessage () const |
Get the message of the exception finally causing the crash. More... | |
void | setThreadName (std::string name) |
Set the name of the thread. More... | |
std::string | getThreadName () const |
Returns the current thread name. More... | |
Static Public Member Functions | |
static std::shared_ptr< WGraphicsEngine > | getGraphicsEngine () |
Returns instance of the graphics engine. More... | |
static bool | isRunning () |
Checks whether the graphics engine is currently running or not. More... | |
static bool | waitForStartupComplete () |
Waits for the GE to come up. More... | |
Static Public Member Functions inherited from WThreadedRunner | |
static void | setThisThreadName (std::string name) |
Static function to set the name of the calling thread. More... | |
Protected Types | |
typedef std::map< std::string, std::shared_ptr< WGEViewer > > | ViewerMap |
Map between name of viewer and viewer. More... | |
Protected Member Functions | |
WGraphicsEngine () | |
Constructors are protected because this is a Singleton. More... | |
virtual void | threadMain () |
Handler for repainting and event handling. More... | |
virtual void | notifyStop () |
Gets called when the thread should be stopped. More... | |
Protected Member Functions inherited from WThreadedRunner | |
void | yield () const |
Give remaining execution timeslice to another thread. More... | |
void | sleep (const int32_t t) const |
Sets thread asleep. More... | |
void | msleep (const int32_t t) const |
Sets thread asleep. More... | |
void | waitForStop () |
Let the thread sleep until a stop request was given. More... | |
virtual void | onThreadException (const WException &e) |
This method is called if an exception was caught, which came from the custom thread code. More... | |
void | handleDeadlyException (const WException &e, std::string sender="WThreadedRunner") |
Handle the specified exception which was not caught in the thread, which basically means the thread has crashed. More... | |
Protected Attributes | |
osg::ref_ptr< WGEScene > | m_rootNode |
OpenSceneGraph root node. More... | |
ViewerMap | m_viewers |
All registered viewers. More... | |
std::shared_mutex | m_viewersLock |
Mutex used to lock the map of viewers. More... | |
bool | m_viewersUpdate |
If true, the view thread checks for updates in the m_viewers list. More... | |
std::vector< WGEViewer::SPtr > | m_addViewers |
List of viewers to add to m_viewer via addView. More... | |
std::vector< WGEViewer::SPtr > | m_removeViewers |
List of viewers to remove from m_viewer via addView. More... | |
std::vector< WCondition::SPtr > | m_viewerUpdateNotifiers |
A list of conditions to notify when the GE thread processed the m_addViewers and m_removeViewers lists. More... | |
osg::ref_ptr< osgViewer::CompositeViewer > | m_viewer |
OpenSceneGraph composite viewer. More... | |
t_GEGenericSignalType | m_reloadShadersSignal |
Signal getting emitted whenever a reload shader request is waiting. More... | |
Protected Attributes inherited from WThreadedRunner | |
boost::thread | m_thread |
Thread instance. More... | |
WBoolFlag | m_shutdownFlag |
Condition getting fired whenever the thread should quit. More... | |
WBoolFlag | m_isCrashed |
True whenever an exception is thrown during threadMain. More... | |
std::string | m_crashMessage |
The crash message. More... | |
Private Member Functions | |
void | applyViewerListUpdates () |
Apply updates in m_addViewers and m_removeViewers. More... | |
Private Attributes | |
bool | m_running |
True if graphics engine is running. More... | |
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. More... | |
Static Private Attributes | |
static std::shared_ptr< WGraphicsEngine > | m_instance = std::shared_ptr< WGraphicsEngine >() |
Singleton instance of WGraphicsEngine. More... | |
Additional Inherited Members | |
Public Types inherited from WThreadedRunner | |
typedef std::shared_ptr< WThreadedRunner > | SPtr |
Abbreviation to a shared_ptr to this type. More... | |
typedef std::shared_ptr< const WThreadedRunner > | ConstSPtr |
Abbreviation to a const shared_ptr to this type. More... | |
typedef boost::function< void(void) > | THREADFUNCTION |
Type used for simple thread functions. More... | |
Base class for initializing the graphics engine.
This Class also serves as adaptor to access the graphics engine.
Definition at line 57 of file WGraphicsEngine.h.
|
protected |
Map between name of viewer and viewer.
Definition at line 207 of file WGraphicsEngine.h.
|
virtual |
Destructor.
Definition at line 72 of file WGraphicsEngine.cpp.
References WLogger::addLogMessage(), and WLogger::getLogger().
|
explicitprotected |
Constructors are protected because this is a Singleton.
Definition at line 54 of file WGraphicsEngine.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), m_rootNode, m_viewer, m_viewersUpdate, and WThreadedRunner::setThreadName().
Referenced by getGraphicsEngine().
|
private |
Apply updates in m_addViewers and m_removeViewers.
Needs to be run in the GE thread
Definition at line 208 of file WGraphicsEngine.cpp.
References m_addViewers, m_removeViewers, m_viewer, m_viewersLock, m_viewersUpdate, and m_viewerUpdateNotifiers.
void WGraphicsEngine::closeViewer | ( | const std::string | name | ) |
Closes a viewer and deletes it from the list of viewers.
name | the name of the viewer |
Definition at line 146 of file WGraphicsEngine.cpp.
References m_viewer, m_viewers, and m_viewersLock.
void WGraphicsEngine::closeViewer | ( | std::shared_ptr< WGEViewer > | viewer | ) |
Closes a viewer and deletes it from the list of viewers.
viewer | the viewer |
Definition at line 130 of file WGraphicsEngine.cpp.
References m_viewer, m_viewers, and m_viewersLock.
std::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.
name | the name of the viewer. Must be unique. |
wdata | the WindowData instance for the widget to use as render widget |
x | X coordinate of widget where to create the context. |
y | Y coordinate of widget where to create the context. |
width | Width of the widget. |
height | Height of the Widget. |
projectionMode | Projection mode of the viewer. |
bgColor | background color shown in the viewer. |
WGEInitFailed | thrown if initialization of graphics context or graphics window has failed. |
WNameNotUnique | if the name if the viewer was not unique |
Definition at line 107 of file WGraphicsEngine.cpp.
References getScene(), m_viewer, m_viewers, and m_viewersLock.
void WGraphicsEngine::finalizeStartup | ( | ) |
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 255 of file WGraphicsEngine.cpp.
References m_startThreadingCondition, and WConditionOneShot::notify().
|
static |
Returns instance of the graphics engine.
If it does not exists, it will be created.
Definition at line 92 of file WGraphicsEngine.cpp.
References m_instance, and WGraphicsEngine().
Referenced by WMDatasetProfile::addKnob(), WGEProjectFileIO::done(), WGEAdvancedManipulator::handle(), WGEZoomTrackballManipulator::handle(), WMArbitraryPlane::initPlane(), WQtGLWidget::keyReleaseEvent(), WMArbitraryPlane::moduleMain(), WMDatasetProfile::moduleMain(), WMGridRenderer::moduleMain(), WGEBorderLayout::SafeUpdateCallback::operator()(), WMNavigationSlices::PickCallback::PickCallback(), WMPickingDVR::pickHandler(), WRMBranch::removeAllRois(), WROIManager::removeRoi(), WQtGui::run(), WScriptUI::run(), WGEProjectFileIO::save(), WMPickingDVR::setPickPositionFromConnector(), WMPickingDVR::setPickPositionSource(), WMainWindow::setupGUI(), WGEProjectFileIO::WGEProjectFileIO(), 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).
Definition at line 102 of file WGraphicsEngine.cpp.
References m_rootNode.
Referenced by createViewer().
std::shared_ptr< WGEViewer > WGraphicsEngine::getViewer | ( | ) |
Returns the unnamed view, which is the view for the default scene which can be acquired using getScene().
Definition at line 173 of file WGraphicsEngine.cpp.
References m_viewers, and m_viewersLock.
std::shared_ptr< WGEViewer > WGraphicsEngine::getViewerByName | ( | std::string | name | ) |
Searches for a viewer with a given name and returns it, if found.
name | the name of the viewer |
Definition at line 163 of file WGraphicsEngine.cpp.
References m_viewers, and m_viewersLock.
bool WGraphicsEngine::isMultiThreadedViews | ( | ) | const |
Checks whether the viewers work multithreaded.
Definition at line 86 of file WGraphicsEngine.cpp.
|
static |
Checks whether the graphics engine is currently running or not.
Definition at line 181 of file WGraphicsEngine.cpp.
References m_instance.
Referenced by waitForStartupComplete().
|
protectedvirtual |
Gets called when the thread should be stopped.
Reimplemented from WThreadedRunner.
Definition at line 248 of file WGraphicsEngine.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), m_startThreadingCondition, and WConditionOneShot::notify().
void WGraphicsEngine::requestShaderReload | ( | ) |
This requests all shaders to reload during the next update cycle.
Definition at line 265 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.
enable | true if multithreaded |
Definition at line 78 of file WGraphicsEngine.cpp.
References WLogger::addLogMessage(), and WLogger::getLogger().
boost::signals2::connection WGraphicsEngine::subscribeSignal | ( | GE_SIGNAL | signal, |
t_GEGenericSignalHandlerType | notifier | ||
) |
Subscribe a specified handler to the specified signal emited by the GE.
signal | the signal to connect to |
notifier | the signal handler |
Definition at line 270 of file WGraphicsEngine.cpp.
References m_reloadShadersSignal, m_startThreadingCondition, and WCondition::subscribeSignal().
boost::signals2::connection WThreadedRunner::subscribeSignal |
Connects a specified notify function with a signal this thread instance is offering.
WSignalSubscriptionFailed | thrown if the signal can't be connected. |
signal | the signal to connect to. |
notifier | the notifier function to bind. |
Definition at line 105 of file WThreadedRunner.cpp.
|
protectedvirtual |
Handler for repainting and event handling.
Gets executed in separate thread.
Reimplemented from WThreadedRunner.
Definition at line 238 of file WGraphicsEngine.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), WGEPostprocessor::initPostprocessors(), and m_running.
void WGraphicsEngine::waitForFinalize | ( | ) |
Wait until someone called finalizeStartup().
Definition at line 260 of file WGraphicsEngine.cpp.
References m_startThreadingCondition, and WConditionOneShot::wait().
|
static |
Waits for the GE to come up.
Fails if engine is not started.
Definition at line 191 of file WGraphicsEngine.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), isRunning(), and m_instance.
Referenced by WGERequirement::isComplied().
|
protected |
List of viewers to add to m_viewer via addView.
Protected by m_viewersLock.
Definition at line 227 of file WGraphicsEngine.h.
Referenced by applyViewerListUpdates().
|
staticprivate |
Singleton instance of WGraphicsEngine.
Definition at line 254 of file WGraphicsEngine.h.
Referenced by getGraphicsEngine(), isRunning(), and waitForStartupComplete().
|
protected |
Signal getting emitted whenever a reload shader request is waiting.
Definition at line 248 of file WGraphicsEngine.h.
Referenced by requestShaderReload(), and subscribeSignal().
|
protected |
List of viewers to remove from m_viewer via addView.
Protected by m_viewersLock.
Definition at line 232 of file WGraphicsEngine.h.
Referenced by applyViewerListUpdates().
|
protected |
OpenSceneGraph root node.
Definition at line 202 of file WGraphicsEngine.h.
Referenced by getScene(), and WGraphicsEngine().
|
private |
True if graphics engine is running.
Definition at line 259 of file WGraphicsEngine.h.
Referenced by threadMain().
|
private |
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 264 of file WGraphicsEngine.h.
Referenced by finalizeStartup(), notifyStop(), subscribeSignal(), and waitForFinalize().
|
protected |
OpenSceneGraph composite viewer.
Contains all created osgViewer::Views.
Definition at line 243 of file WGraphicsEngine.h.
Referenced by applyViewerListUpdates(), closeViewer(), createViewer(), and WGraphicsEngine().
|
protected |
All registered viewers.
Definition at line 212 of file WGraphicsEngine.h.
Referenced by closeViewer(), createViewer(), getViewer(), and getViewerByName().
|
protected |
Mutex used to lock the map of viewers.
Definition at line 217 of file WGraphicsEngine.h.
Referenced by applyViewerListUpdates(), closeViewer(), createViewer(), getViewer(), and getViewerByName().
|
protected |
If true, the view thread checks for updates in the m_viewers list.
Definition at line 222 of file WGraphicsEngine.h.
Referenced by applyViewerListUpdates(), and WGraphicsEngine().
|
protected |
A list of conditions to notify when the GE thread processed the m_addViewers and m_removeViewers lists.
Protected by m_viewersLock.
Definition at line 238 of file WGraphicsEngine.h.
Referenced by applyViewerListUpdates().