Commit 27d61a57 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[FIX] made it compile on mac by decoupling gui and graphics engine from...

[FIX] made it compile on mac by decoupling gui and graphics engine from kernel. Now only kernel knows graphics eginen and qtgui knows kernel. kernel knows gui. qtgui knows gui.

It just compiles ... it does not work yet.
parent 24e0d0f0
......@@ -32,7 +32,7 @@ ENDIF( CMAKE_BUILD_TYPE STREQUAL "Static" )
# To see which boost libs we currently use, you may run the following command
# in the trunk/src directory on a linux box to make some investigations:
# grep -i include `find . -type f` | grep boost | awk '{print $2}' | sort | uniq
FIND_PACKAGE( Boost REQUIRED program_options thread filesystem date_time )
FIND_PACKAGE( Boost REQUIRED program_options thread system filesystem date_time )
ASSERT_GE_VERSION( "Boost" "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}" 1.36.0 )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
......@@ -98,7 +98,7 @@ IF( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
ADD_SUBDIRECTORY( kernel )
ADD_SUBDIRECTORY( common )
ADD_EXECUTABLE( walnut OpenWalnut.cpp utils/WOptionHandler.cpp )
TARGET_LINK_LIBRARIES( walnut kernel dataHandler guiqt4 common ${Boost_LIBRARIES} )
TARGET_LINK_LIBRARIES( walnut kernel dataHandler gui guiqt4 common ${Boost_LIBRARIES} )
ELSE( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
FILE( GLOB_RECURSE ALL_SRC ${PROJECT_SOURCE_DIR}/*.cpp )
......
......@@ -26,6 +26,9 @@
#include "common/WException.h"
#include "common/WSegmentationFault.h"
#include "common/WLogger.h"
#include "gui/WGUI.h"
#include "kernel/WKernel.h"
......@@ -51,8 +54,16 @@ int main( int argc, char* argv[] )
// install signal handler as early as possible
WSegmentationFault::installSignalHandler();
// initialize GUI
boost::shared_ptr< WGUI > gui = boost::shared_ptr< WGUI >( new WMainApplication() );
// init logger
WLogger logger;
logger.run();
// init the kernel
WKernel kernel = WKernel( argc, argv );
WKernel kernel = WKernel( argc, argv, gui );
int code = kernel.run();
return code;
}
......@@ -30,6 +30,10 @@
#include "WLogger.h"
/**
* Used for program wide access to the logger.
*/
WLogger* logger = NULL;
WLogger::WLogger( std::string fileName, LogLevel level ):
WThreadedRunner(),
......@@ -41,6 +45,8 @@ WLogger::WLogger( std::string fileName, LogLevel level ):
m_LogFileName( fileName ),
m_QueueMutex()
{
logger = this;
addLogMessage( "Initalizing Logger", "Logger", LL_DEBUG );
addLogMessage( "===============================================================================", "Logger", LL_INFO );
addLogMessage( "= Starting Log Session =", "Logger", LL_INFO );
......@@ -51,6 +57,11 @@ WLogger::~WLogger()
{
}
WLogger* WLogger::getLogger()
{
return logger;
}
void WLogger::setLogLevel( LogLevel level )
{
......
......@@ -53,6 +53,13 @@ public:
*/
virtual ~WLogger();
/**
* Returns pointer to the currently running logger.
*
* \return pointer to logger instance.
*/
static WLogger* getLogger();
/**
*
*/
......@@ -98,6 +105,14 @@ public:
protected:
private:
/**
* We do not want a copy constructor, so we define it private.
*/
WLogger( const WLogger& )
{
};
/**
*
*/
......
......@@ -28,21 +28,21 @@
#include <osg/Group>
#include <osg/Geode>
#include "../kernel/WKernel.h"
#include "../common/WLogger.h"
#include "WGEScene.h"
WGEScene::WGEScene():
osg::Group()
{
WKernel::getRunningKernel()->getLogger()->addLogMessage( "Initializing OpenSceneGraph Root Node", "GE", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Initializing OpenSceneGraph Root Node", "GE", LL_DEBUG );
// initialize members
}
WGEScene::~WGEScene()
{
WKernel::getRunningKernel()->getLogger()->addLogMessage( "Shutting down OpenSceneGraph Root Node", "GE", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Shutting down OpenSceneGraph Root Node", "GE", LL_DEBUG );
// cleanup
}
......
......@@ -25,19 +25,21 @@
#include <iostream>
#include <list>
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/thread/locks.hpp>
#include "exceptions/WGEInitFailed.h"
#include "../kernel/WKernel.h"
#include "../common/WLogger.h"
#include "WGraphicsEngine.h"
#include "WGEViewer.h"
WGraphicsEngine::WGraphicsEngine():
WThreadedRunner()
WGraphicsEngine::WGraphicsEngine( std::string shaderPath ):
WThreadedRunner(),
m_shaderPath( shaderPath )
{
WKernel::getRunningKernel()->getLogger()->addLogMessage( "Initializing Graphics Engine", "GE", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Initializing Graphics Engine", "GE", LL_DEBUG );
// initialize members
m_RootNode = new WGEScene();
......@@ -46,7 +48,7 @@ WGraphicsEngine::WGraphicsEngine():
WGraphicsEngine::~WGraphicsEngine()
{
// cleanup
WKernel::getRunningKernel()->getLogger()->addLogMessage( "Shutting down Graphics Engine", "GE", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Shutting down Graphics Engine", "GE", LL_DEBUG );
}
osg::ref_ptr<WGEScene> WGraphicsEngine::getScene()
......@@ -54,6 +56,11 @@ osg::ref_ptr<WGEScene> WGraphicsEngine::getScene()
return m_RootNode;
}
std::string WGraphicsEngine::getShaderPath()
{
return m_shaderPath;
}
void WGraphicsEngine::threadMain()
{
// TODO(ebaum): is this thread actually needed since each viewer runs in separate thread
......@@ -67,7 +74,7 @@ void WGraphicsEngine::threadMain()
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height )
{
boost::shared_ptr<WGEViewer> viewer = boost::shared_ptr<WGEViewer>( new WGEViewer( wdata, x, y, width, height ) );
viewer->setScene( WKernel::getRunningKernel()->getGraphicsEngine()->getScene() );
viewer->setScene( this->getScene() );
// start rendering
viewer->run();
......
......@@ -26,6 +26,8 @@
#define WGRAPHICSENGINE_H
#include <list>
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/thread/thread.hpp>
......@@ -52,7 +54,7 @@ public:
/**
* Default constructor.
*/
WGraphicsEngine();
explicit WGraphicsEngine( std::string shaderPath );
/**
* Destructor.
......@@ -66,6 +68,13 @@ public:
*/
osg::ref_ptr<WGEScene> getScene();
/**
* Return the path where the shaders are expected to be located.
*
* \return shader path
*/
std::string getShaderPath();
/**
* Creates a new viewer. Does basic initialization and sets the default scene.
*
......@@ -102,6 +111,7 @@ protected:
boost::mutex m_ViewerLock;
private:
std::string m_shaderPath;
};
/**
......
......@@ -39,8 +39,8 @@ WShader::WShader()
{
}
WShader::WShader( std::string fileName )
WShader::WShader( std::string fileName, std::string shaderPath ):
m_shaderPath( shaderPath )
{
m_VertexObject = readShaderFromFile( fileName + ".vs", osg::Shader::VERTEX );
m_FragmentObject = readShaderFromFile( fileName + ".fs", osg::Shader::FRAGMENT );
......@@ -80,7 +80,7 @@ std::string WShader::readTextFile( std::string fileName )
{
std::string fileText;
std::ifstream ifs( ( WKernel::getRunningKernel()->getShaderPath() + fileName ).c_str() );
std::ifstream ifs( ( m_shaderPath + fileName ).c_str() );
std::string line;
std::map< std::string, float >::const_iterator mi = m_defines.begin();
......
......@@ -43,7 +43,7 @@ public:
/**
*
*/
explicit WShader( std::string fileName );
explicit WShader( std::string fileName, std::string shaderPath );
/**
* destructor
......@@ -88,6 +88,7 @@ private:
*/
std::string getIncludeFileName( std::string line );
std::string m_shaderPath;
/**
*
*/
......
......@@ -24,15 +24,13 @@
#include <iostream>
#include <QtGui/QApplication>
#include "WMainApplication.h"
#include "WMainWindow.h"
#include "../../kernel/WKernel.h"
WMainApplication::WMainApplication():
WThreadedRunner()
WGUI()
{
}
......@@ -43,8 +41,14 @@ WMainApplication::~WMainApplication()
void WMainApplication::threadMain()
{
// TODO(ebaum): currently removed argument stuff. will be done later in conjunction with a better
// option handler.
// option handler.+
#ifdef __APPLE__
char * dummy = "";
int dummyInt = 0;
QApplication appl( dummyInt, &dummy, 0 );
#else
QApplication appl( 0, NULL );
#endif
QMainWindow* widget = new QMainWindow;
WMainWindow gui;
gui.setupGUI( widget );
......
......@@ -25,13 +25,16 @@
#ifndef WMAINAPPLICATION_H
#define WMAINAPPLICATION_H
#include "../../common/WThreadedRunner.h"
#include <QtGui/QApplication>
#include "../WGUI.h"
/**
* Starts up the QT GUI.
* \ingroup gui
*/
class WMainApplication: public WThreadedRunner
class WMainApplication : public WGUI
{
public:
......
......@@ -45,9 +45,11 @@ WQtGLWidget::WQtGLWidget( QWidget* parent )
// Extract a WindowPtr from the HIViewRef that QWidget::winId() returns.
// Without this change, the peer tries to call GetWindowPort on the HIViewRef
// which returns 0 and we only render white.
osg::ref_ptr<WindowData> wdata = osg::ref_ptr<WindowData>(
new WindowData( HIViewGetWindow( static_cast<HIViewRef>winId() ) )
);
osg::ref_ptr<WindowData> wdata;
#warning This must be commented back in soon
// wdata = osg::ref_ptr<WindowData>(
// new WindowData( HIViewGetWindow( static_cast<HIViewRef>winId() ) )
// );
#else // all others
osg::ref_ptr<WindowData> wdata = osg::ref_ptr<WindowData>( new WindowData( winId() ) );
#endif
......
......@@ -41,7 +41,8 @@
*/
WKernel* kernel = NULL;
WKernel::WKernel( int argc, char* argv[] )
WKernel::WKernel( int argc, char* argv[], boost::shared_ptr< WGUI > gui )
: m_Gui( gui )
{
std::cout << "Initializing Kernel" << std::endl;
......@@ -62,12 +63,12 @@ WKernel::WKernel( int argc, char* argv[] )
WKernel::~WKernel()
{
// cleanup
m_Logger->addLogMessage( "Shutting down Kernel", "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Shutting down Kernel", "Kernel", LL_DEBUG );
// finish running thread
m_Logger->wait( true );
WLogger::getLogger()->wait( true );
// write remaining log messages
m_Logger->processQueue();
WLogger::getLogger()->processQueue();
}
WKernel::WKernel( const WKernel& other )
......@@ -90,11 +91,15 @@ boost::shared_ptr<WDataHandler> WKernel::getDataHandler() const
return m_DataHandler;
}
boost::shared_ptr<WMainApplication> WKernel::getGui()
boost::shared_ptr< WGUI > WKernel::getGui()
{
return m_Gui;
}
void WKernel::setGui( boost::shared_ptr< WGUI > gui )
{
m_Gui = gui;
}
int WKernel::getArgumentCount() const
{
......@@ -108,7 +113,7 @@ char** WKernel::getArguments() const
int WKernel::run()
{
m_Logger->addLogMessage( "Starting Kernel", "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Starting Kernel", "Kernel", LL_DEBUG );
// TODO(ebaum): add separate graphics thread here
m_GraphicsEngine->run();
......@@ -122,11 +127,11 @@ int WKernel::run()
// run module execution threads
// TODO(ebaum): after having modules loaded they should be started here.
// currently this is just the test module
m_Logger->addLogMessage( "*** Starting modules:", "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "*** Starting modules:", "Kernel", LL_DEBUG );
for( std::list<WModule*>::iterator list_iter = m_modules.begin(); list_iter != m_modules.end();
++list_iter )
{
m_Logger->addLogMessage( "Starting module: " + ( *list_iter )->getName(), "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Starting module: " + ( *list_iter )->getName(), "Kernel", LL_DEBUG );
( *list_iter )->run();
}
......@@ -151,11 +156,11 @@ int WKernel::run()
void WKernel::loadModules()
{
// TODO(ebaum): add dynamic loading here
m_Logger->addLogMessage( "*** Loading Modules: ", "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "*** Loading Modules: ", "Kernel", LL_DEBUG );
m_modules.clear();
WModule* m = new WNavigationSliceModule();
m_Logger->addLogMessage( "Loading module: " + m->getName(), "Kernel", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Loading module: " + m->getName(), "Kernel", LL_DEBUG );
m_modules.push_back( m );
......@@ -166,17 +171,11 @@ void WKernel::init()
// initialize
findAppPath();
// initalize Logger
m_Logger = boost::shared_ptr<WLogger>( new WLogger() );
m_Logger->run();
// initialize graphics engine
// this also includes initialization of WGEScene and OpenSceneGraph
m_GraphicsEngine = boost::shared_ptr<WGraphicsEngine>( new WGraphicsEngine );
m_GraphicsEngine = boost::shared_ptr<WGraphicsEngine>( new WGraphicsEngine( m_shaderPath ) );
// initialize GUI
// TODO(all): clean up this option handler mess
m_Gui = boost::shared_ptr<WMainApplication>( new WMainApplication() );
// initialize Datahandler
m_DataHandler = boost::shared_ptr<WDataHandler>( new WDataHandler() );
......@@ -217,7 +216,7 @@ bool WKernel::findAppPath()
m_AppPath = appPath;
std::string shaderPath( appPath );
m_ShaderPath = shaderPath + "shaders/";
m_shaderPath = shaderPath + "shaders/";
return true;
}
......@@ -244,10 +243,5 @@ std::string WKernel::getAppPath()
std::string WKernel::getShaderPath()
{
return m_ShaderPath;
}
boost::shared_ptr<WLogger> WKernel::getLogger()
{
return m_Logger;
return m_shaderPath;
}
......@@ -52,7 +52,7 @@ public:
* \param argc number of arguments
* \param argv arguments
*/
WKernel( int argc, char* argv[] );
WKernel( int argc, char* argv[], boost::shared_ptr< WGUI > gui );
/**
* Destructor.
......@@ -127,12 +127,12 @@ public:
/**
*
*/
boost::shared_ptr<WMainApplication> getGui();
boost::shared_ptr<WGUI> getGui();
/**
*
*/
boost::shared_ptr<WLogger> getLogger();
void setGui( boost::shared_ptr< WGUI > gui );
/**
*
......@@ -159,18 +159,13 @@ protected:
/**
* The Gui.
*/
boost::shared_ptr<WMainApplication> m_Gui;
boost::shared_ptr<WGUI> m_Gui;
/**
* The Datahandler.
*/
boost::shared_ptr<WDataHandler> m_DataHandler;
/**
* The logging device
*/
boost::shared_ptr<WLogger> m_Logger;
private:
/**
* Loads all the modules it can find.
......@@ -210,7 +205,7 @@ private:
/**
* the location of the openwalnut executable
*/
std::string m_ShaderPath;
std::string m_shaderPath;
};
/**
......
......@@ -46,7 +46,8 @@ WNavigationSliceModule::WNavigationSliceModule():
WModule()
{
// initialize members
m_shader = boost::shared_ptr< WShader > ( new WShader( "slice" ) );
std::string shaderPath = WKernel::getRunningKernel()->getGraphicsEngine()->getShaderPath();
m_shader = boost::shared_ptr< WShader > ( new WShader( "slice", shaderPath ) );
m_textureAssigned = false;
}
......
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