Commit 8d42450c authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - reload request now gets propagated using signals

parent 32c25444
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WGESignals.h"
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WGESIGNALS_H
#define WGESIGNALS_H
#include <boost/signals2/signal.hpp>
#include <boost/function.hpp>
/**
* Enum of all possible signals WGraphicsEngine instances can emit.
*/
typedef enum
{
GE_RELOADSHADERS // when a shader reload is requested
}
GE_SIGNAL;
// **************************************************************************************************************************
// Types
// **************************************************************************************************************************
/**
* Signal for generic events like "GE_RELOADSHADERS".
*
*/
typedef boost::function< void ( void ) > t_GEGenericSignalHandlerType;
/**
* Generic signal type used in the most signals.
*/
typedef boost::signals2::signal< void ( void ) > t_GEGenericSignalType;
#endif // WGESIGNALS_H
......@@ -43,6 +43,7 @@
#include "WGEViewer.h"
#include "WGraphicsEngine.h"
#include "exceptions/WGEInitFailed.h"
#include "exceptions/WGESignalSubscriptionFailed.h"
#include "WGEResourceManager.h"
// graphics engine instance as singleton
......@@ -185,6 +186,25 @@ void WGraphicsEngine::notifyStop()
m_viewer->setDone( true );
}
void WGraphicsEngine::requestShaderReload()
{
m_reloadShadersSignal();
}
boost::signals2::connection WGraphicsEngine::subscribeSignal( GE_SIGNAL signal, t_GEGenericSignalHandlerType notifier )
{
switch ( signal )
{
case GE_RELOADSHADERS:
return m_reloadShadersSignal.connect( notifier );
default:
std::ostringstream s;
s << "Could not subscribe to unknown signal.";
throw WGESignalSubscriptionFailed( s.str() );
break;
}
}
osg::Vec4 wge::osgColor( const WColor& color )
{
return osg::Vec4( color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() );
......
......@@ -30,6 +30,8 @@
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/signals2/signal.hpp>
#include <boost/function.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
......@@ -48,6 +50,7 @@
#include "WGEGraphicsWindow.h"
#include "WGEScene.h"
#include "WGEViewer.h"
#include "WGESignals.h"
/**
* Base class for initializing the graphics engine. This Class also serves as adaptor to access the graphics
......@@ -152,6 +155,21 @@ public:
*/
static boost::shared_ptr< WGraphicsEngine > getGraphicsEngine();
/**
* This requests all shaders to reload during the next update cycle.
*/
void requestShaderReload();
/**
* Subscribe a specified handler to the specified signal emited by the GE.
*
* \param signal the signal to connect to
* \param notifier the signal handler
*
* \return connection object.
*/
boost::signals2::connection subscribeSignal( GE_SIGNAL signal, t_GEGenericSignalHandlerType notifier );
protected:
/**
......@@ -191,6 +209,11 @@ protected:
*/
osg::ref_ptr<osgViewer::CompositeViewer> m_viewer;
/**
* Signal getting emitted whenever a reload shader request is waiting.
*/
t_GEGenericSignalType m_reloadShadersSignal;
private:
/**
* Singleton instance of WGraphicsEngine.
......
......@@ -31,6 +31,8 @@
#include <boost/lexical_cast.hpp>
#include <boost/tokenizer.hpp>
#include <boost/regex.hpp>
#include <boost/signals2/signal.hpp>
#include <boost/function.hpp>
#include <osg/StateSet>
#include <osg/Node>
......@@ -55,11 +57,14 @@ WShader::WShader( std::string name ):
addShader( m_vertexShader );
addShader( m_fragmentShader );
addShader( m_geometryShader );
m_reloadSignalConnection = WGraphicsEngine::getGraphicsEngine()->subscribeSignal( GE_RELOADSHADERS, boost::bind( &WShader::reload, this ) );
}
WShader::~WShader()
{
// cleanup
m_reloadSignalConnection.disconnect();
}
void WShader::apply( osg::ref_ptr< osg::Node > node )
......
......@@ -29,6 +29,7 @@
#include <string>
#include <boost/filesystem.hpp>
#include <boost/signals2/signal.hpp>
#include <osg/Shader>
#include <osg/Program>
......@@ -110,6 +111,11 @@ protected:
*/
bool m_reload;
/**
* Connection object to the reload signal from WGraphbicsEngine.
*/
boost::signals2::connection m_reloadSignalConnection;
/**
* a map of all set defines
*/
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "WGESignalSubscriptionFailed.h"
WGESignalSubscriptionFailed::WGESignalSubscriptionFailed( const std::string& msg ): WGEException( msg )
{
// initialize members
}
WGESignalSubscriptionFailed::~WGESignalSubscriptionFailed() throw()
{
// cleanup
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WGESIGNALSUBSCRIPTIONFAILED_H
#define WGESIGNALSUBSCRIPTIONFAILED_H
#include <string>
#include "WGEException.h"
/**
* Exception thrown if a notifier could not be subscribed to a signal.
* \ingroup ge
*/
class WGESignalSubscriptionFailed: public WGEException
{
public:
/**
* Default constructor.
* \param msg the exception message.
*/
explicit WGESignalSubscriptionFailed( const std::string& msg = "Could not subscribe to unknown signal." );
/**
* Destructor.
*/
virtual ~WGESignalSubscriptionFailed() throw();
protected:
private:
};
#endif // WGESIGNALSUBSCRIPTIONFAILED_H
......@@ -173,7 +173,7 @@ const std::set<boost::shared_ptr< WModuleOutputConnector > >& WModule::getOutput
boost::signals2::connection WModule::subscribeSignal( MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier )
{
switch (signal)
switch ( signal )
{
case WM_READY:
return signal_ready.connect( notifier );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment