1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
25
#ifndef WGRAPHICSENGINE_H
26
#define WGRAPHICSENGINE_H
32
#include <boost/shared_ptr.hpp>
33
#include <boost/signals2/signal.hpp>
34
#include <boost/function.hpp>
35
#include <boost/thread/mutex.hpp>
36
#include <boost/thread/thread.hpp>
39
#include <osg/Texture3D>
42
#include <osg/ref_ptr>
43
#include <osgViewer/CompositeViewer>
44
#include <osgViewer/View>
45
#include <osgViewer/Viewer>
47
#include "../common/WThreadedRunner.h"
48
#include "../common/WConditionOneShot.h"
49
#include "../common/WColor.h"
50
#include "../common/math/linearAlgebra/WLinearAlgebra.h"
51
#include "WGEGraphicsWindow.h"
53
#include "WGEViewer.h"
54
#include "WGESignals.h"
56
#include "WExportWGE.h"
59
* Base class for initializing the graphics engine. This Class also serves as adaptor to access the graphics
63
class WGE_EXPORT WGraphicsEngine: public WThreadedRunner
70
virtual ~WGraphicsEngine();
73
* Returns the root node of the WGraphicsEngine (this is not the root node of the OSG).
75
* \return the root node.
77
osg::ref_ptr<WGEScene> getScene();
80
* Creates a new viewer. Does basic initialization and sets the default scene.
82
* \param name the name of the viewer
83
* \param wdata the WindowData instance for the widget to use as render widget
84
* \param x X coordinate of widget where to create the context.
85
* \param y Y coordinate of widget where to create the context.
86
* \param width Width of the widget.
87
* \param height Height of the Widget.
88
* \param projectionMode Projection mode of the viewer.
89
* \param bgColor background color shown in the viewer.
90
* \return the new instance, ready to be used.
91
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
93
boost::shared_ptr< WGEViewer > createViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int x, int y,
94
int width, int height, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC,
95
WColor bgColor = WColor( 0.9, 0.9, 0.9, 1.0 ) );
98
* Closes a viewer and deletes it from the list of viewers.
100
* \param name the name of the viewer
102
void closeViewer( const std::string name );
105
* Searches for a viewer with a given name and returns it, if found.
107
* \param name the name of the viewer
108
* \returns a shared pointer to the viewer or NULL if not found
110
boost::shared_ptr< WGEViewer > getViewerByName( std::string name );
113
* Returns the unnamed view, which is the view for the default scene which can be acquired using getScene().
115
* \return the viewer for the default scene.
117
boost::shared_ptr< WGEViewer > getViewer();
120
* Returns instance of the graphics engine. If it does not exists, it will be created.
122
* \return the running graphics engine instance.
124
static boost::shared_ptr< WGraphicsEngine > getGraphicsEngine();
127
* This requests all shaders to reload during the next update cycle.
129
void requestShaderReload();
132
* Subscribe a specified handler to the specified signal emited by the GE.
134
* \param signal the signal to connect to
135
* \param notifier the signal handler
137
* \return connection object.
139
boost::signals2::connection subscribeSignal( GE_SIGNAL signal, t_GEGenericSignalHandlerType notifier );
142
* Checks whether the graphics engine is currently running or not.
144
* \return true if running
146
static bool isRunning();
149
* Waits for the GE to come up. Fails if engine is not started.
151
* \return true if engine now running
153
static bool waitForStartupComplete();
156
* Function notifies the viewer threads (if any) to start. This should only be called AFTER the OpenGL widgets/windows have been initialized.
158
void finalizeStartup();
161
* Enables multithreaded view. This MUST be called before run(). On Mac, this has no function.
163
* \param enable true if multithreaded
165
void setMultiThreadedViews( bool enable = true );
168
* Checks whether the viewers work multithreaded.
170
* \return true if multithreaded
172
bool isMultiThreadedViews() const;
177
* Constructors are protected because this is a Singleton.
179
explicit WGraphicsEngine();
182
* Handler for repainting and event handling. Gets executed in separate thread.
184
virtual void threadMain();
187
* Gets called when the thread should be stopped.
189
virtual void notifyStop();
192
* OpenSceneGraph root node.
194
osg::ref_ptr<WGEScene> m_rootNode;
197
* All registered viewers.
199
std::map< std::string, boost::shared_ptr< WGEViewer > > m_viewers;
202
* Mutex used to lock the map of viewers.
204
boost::mutex m_viewersLock;
207
* OpenSceneGraph composite viewer. Contains all created osgViewer::Views.
209
osg::ref_ptr<osgViewer::CompositeViewer> m_viewer;
212
* Signal getting emitted whenever a reload shader request is waiting.
214
t_GEGenericSignalType m_reloadShadersSignal;
218
* Singleton instance of WGraphicsEngine.
220
static boost::shared_ptr< WGraphicsEngine > m_instance;
223
* True if graphics engine is running.
228
* This condition is fired externally if all the GUI startup is done to ensure all OGL stuff is initialized prior to OSG threading startup.
230
WConditionOneShot m_startThreadingCondition;
234
* \defgroup ge GraphicsEngine
237
* This library implements the graphics engine for OpenWalnut.
241
* Convinient functions for use with the graphics engine of OpenWalnut. ATM the
242
* namespace is filled by several files: WGEGeodeUtils, WGEGeometryUtils and
247
} // end of namespace
249
#endif // WGRAPHICSENGINE_H