32 #include <boost/thread/locks.hpp>
35 #include <osg/ref_ptr>
36 #include <osgViewer/CompositeViewer>
37 #include <osgViewer/View>
38 #include <osgViewer/Viewer>
40 #include "../common/WColor.h"
41 #include "../common/WLogger.h"
42 #include "../common/WPathHelper.h"
43 #include "../common/exceptions/WNameNotUnique.h"
44 #include "WGEViewer.h"
45 #include "WGraphicsEngine.h"
46 #include "WStaticOSGSetup.h"
47 #include "exceptions/WGEInitFailed.h"
48 #include "exceptions/WGESignalSubscriptionFailed.h"
49 #include "postprocessing/WGEPostprocessor.h"
60 m_viewer = osg::ref_ptr<osgViewer::CompositeViewer>(
new osgViewer::CompositeViewer() );
61 m_viewer->setThreadingModel( osgViewer::ViewerBase::SingleThreaded );
62 m_viewer->setRunMaxFrameRate( 60.0 );
111 std::shared_ptr<WGEViewer> viewer = std::shared_ptr<WGEViewer>(
112 new WGEViewer( name, wdata, x, y, width, height, projectionMode ) );
113 viewer->setBgColor( bgColor );
118 bool insertSucceeded =
m_viewers.insert( make_pair( name, viewer ) ).second;
119 if( !insertSucceeded )
124 m_viewer->addView( viewer->getView() );
136 if(
m_viewers.count( viewer->getName() ) > 0 )
141 m_viewer->removeView( viewer->getView() );
165 boost::shared_lock< std::shared_mutex > lock(
m_viewersLock );
166 std::shared_ptr< WGEViewer > out =
m_viewers.count( name ) > 0 ?
168 std::shared_ptr< WGEViewer >();
175 boost::shared_lock< std::shared_mutex > lock(
m_viewersLock );
176 std::shared_ptr< WGEViewer > result =
m_viewers[
"Main View" ];
218 m_viewer->addView( ( *it )->getView() );
223 m_viewer->removeView( ( *it )->getView() );
274 case GE_RELOADSHADERS:
276 case GE_STARTUPCOMPLETE:
279 std::ostringstream s;
280 s <<
"Could not subscribe to unknown signal.";
virtual void notify()
Notifies all waiting threads.
virtual void wait() const
Wait for the condition.
boost::signals2::connection subscribeSignal(t_ConditionNotifierType notifier) const
Subscribes a specified function to be notified on condition change.
ProjectionMode
List of possible camera modes.
static void initPostprocessors()
Needs to be called prior to any "getPostprocessors" call.
Class for managing the OpenSceneGraph root node.
Exception thrown if a notifier could not be subscribed to a signal.
Class for managing one view to the scene.
virtual boost::signals2::connection subscribeSignal(THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier)
Connects a specified notify function with a signal this thread instance is offering.
static std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
virtual void threadMain()
Handler for repainting and event handling.
std::vector< WGEViewer::SPtr > m_addViewers
List of viewers to add to m_viewer via addView.
static bool waitForStartupComplete()
Waits for the GE to come up.
std::shared_mutex m_viewersLock
Mutex used to lock the map of viewers.
virtual void notifyStop()
Gets called when the thread should be stopped.
std::shared_ptr< WGEViewer > getViewer()
Returns the unnamed view, which is the view for the default scene which can be acquired using getScen...
void waitForFinalize()
Wait until someone called finalizeStartup().
std::shared_ptr< WGEViewer > getViewerByName(std::string name)
Searches for a viewer with a given name and returns it, if found.
static std::shared_ptr< WGraphicsEngine > m_instance
Singleton instance of WGraphicsEngine.
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.
bool m_viewersUpdate
If true, the view thread checks for updates in the m_viewers list.
ViewerMap m_viewers
All registered viewers.
std::vector< WGEViewer::SPtr > m_removeViewers
List of viewers to remove from m_viewer via addView.
osg::ref_ptr< WGEScene > getScene()
Returns the root node of the WGraphicsEngine (this is not the root node of the OSG).
osg::ref_ptr< WGEScene > m_rootNode
OpenSceneGraph root node.
bool isMultiThreadedViews() const
Checks whether the viewers work multithreaded.
std::vector< WCondition::SPtr > m_viewerUpdateNotifiers
A list of conditions to notify when the GE thread processed the m_addViewers and m_removeViewers list...
void closeViewer(const std::string name)
Closes a viewer and deletes it from the list of viewers.
t_GEGenericSignalType m_reloadShadersSignal
Signal getting emitted whenever a reload shader request is waiting.
osg::ref_ptr< osgViewer::CompositeViewer > m_viewer
OpenSceneGraph composite viewer.
virtual ~WGraphicsEngine()
Destructor.
static bool isRunning()
Checks whether the graphics engine is currently running or not.
void finalizeStartup()
Function notifies the viewer threads (if any) to start.
WGraphicsEngine()
Constructors are protected because this is a Singleton.
void setMultiThreadedViews(bool enable=true)
Enables multithreaded view.
void applyViewerListUpdates()
Apply updates in m_addViewers and m_removeViewers.
void requestShaderReload()
This requests all shaders to reload during the next update cycle.
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 initiali...
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
Indicates that a given name is not unique in a group of names.
Base class for all classes needing to be executed in a separate thread.
void setThreadName(std::string name)
Set the name of the thread.