32 #include <boost/shared_ptr.hpp>
33 #include <boost/thread/locks.hpp>
37 #include <osg/ref_ptr>
38 #include <osgViewer/CompositeViewer>
39 #include <osgViewer/View>
40 #include <osgViewer/Viewer>
42 #include "../common/WColor.h"
43 #include "../common/WLogger.h"
44 #include "../common/WPathHelper.h"
45 #include "WGEViewer.h"
46 #include "exceptions/WGEInitFailed.h"
47 #include "exceptions/WGESignalSubscriptionFailed.h"
48 #include "WGraphicsEngineMode.h"
49 #include "postprocessing/WGEPostprocessor.h"
51 #include "WStaticOSGSetup.h"
53 #include "WGraphicsEngine.h"
63 #ifdef WGEMODE_MULTITHREADED
65 m_viewer = osg::ref_ptr<osgViewer::CompositeViewer>(
new osgViewer::CompositeViewer() );
66 m_viewer->setThreadingModel( osgViewer::ViewerBase::SingleThreaded );
83 #ifdef WGEMODE_SINGLETHREADED
100 m_viewer->setThreadingModel( osgViewer::Viewer::SingleThreaded );
104 m_viewer->setThreadingModel( osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext );
111 #ifdef WGEMODE_MULTITHREADED
112 return ( osgViewer::Viewer::SingleThreaded !=
m_viewer->getThreadingModel() );
137 boost::shared_ptr<WGEViewer> viewer = boost::shared_ptr<WGEViewer>(
138 new WGEViewer( name, wdata, x, y, width, height, projectionMode ) );
139 viewer->setBgColor( bgColor );
142 #ifdef WGEMODE_MULTITHREADED
144 m_viewer->addView( viewer->getView() );
149 bool insertSucceeded =
m_viewers.insert( make_pair( name, viewer ) ).second;
150 assert( insertSucceeded ==
true );
169 boost::shared_ptr< WGEViewer > out =
m_viewers.count( name ) > 0 ?
171 boost::shared_ptr< WGEViewer >();
215 #ifdef WGEMODE_MULTITHREADED
234 #ifdef WGEMODE_MULTITHREADED
258 case GE_RELOADSHADERS:
260 case GE_STARTUPCOMPLETE:
263 std::ostringstream s;
264 s <<
"Could not subscribe to unknown signal.";
boost::signals2::connection subscribeSignal(t_ConditionNotifierType notifier) const
Subscribes a specified function to be notified on condition change.
boost::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.
static bool isRunning()
Checks whether the graphics engine is currently running or not.
static boost::shared_ptr< WGraphicsEngine > m_instance
Singleton instance of WGraphicsEngine.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
WConditionOneShot m_startThreadingCondition
This condition is fired externally if all the GUI startup is done to ensure all OGL stuff is initiali...
void requestShaderReload()
This requests all shaders to reload during the next update cycle.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
virtual void threadMain()
Handler for repainting and event handling.
ProjectionMode
List of possible camera modes.
virtual ~WGraphicsEngine()
Destructor.
osg::ref_ptr< WGEScene > getScene()
Returns the root node of the WGraphicsEngine (this is not the root node of the OSG).
Base class for all classes needing to be executed in a separate thread.
boost::mutex m_viewersLock
Mutex used to lock the map of viewers.
virtual void notifyStop()
Gets called when the thread should be stopped.
static void initPostprocessors()
Needs to be called prior to any "getPostprocessors" call.
Exception thrown if a notifier could not be subscribed to a signal.
bool isMultiThreadedViews() const
Checks whether the viewers work multithreaded.
Class for managing the OpenSceneGraph root node.
virtual void notify()
Notifies all waiting threads.
static boost::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
boost::shared_ptr< WGEViewer > getViewer()
Returns the unnamed view, which is the view for the default scene which can be acquired using getScen...
void closeViewer(const std::string name)
Closes a viewer and deletes it from the list of viewers.
std::map< std::string, boost::shared_ptr< WGEViewer > > m_viewers
All registered viewers.
Class for managing one view to the scene.
WGraphicsEngine()
Constructors are protected because this is a Singleton.
void setThreadName(std::string name)
Set the name of the thread.
void finalizeStartup()
Function notifies the viewer threads (if any) to start.
bool m_running
True if graphics engine is running.
void setMultiThreadedViews(bool enable=true)
Enables multithreaded view.
void waitForFinalize()
Wait until someone called finalizeStartup().
osg::ref_ptr< osgViewer::CompositeViewer > m_viewer
OpenSceneGraph composite viewer.
osg::ref_ptr< WGEScene > m_rootNode
OpenSceneGraph root node.
static bool waitForStartupComplete()
Waits for the GE to come up.
t_GEGenericSignalType m_reloadShadersSignal
Signal getting emitted whenever a reload shader request is waiting.
boost::signals2::connection subscribeSignal(GE_SIGNAL signal, t_GEGenericSignalHandlerType notifier)
Subscribe a specified handler to the specified signal emited by the GE.
virtual void wait() const
Wait for the condition.
boost::shared_ptr< WGEViewer > getViewerByName(std::string name)
Searches for a viewer with a given name and returns it, if found.