Commit 65c5f533 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - cleaned up the mess with different viewers, engines and stuff for...

[CHANGE] - cleaned up the mess with different viewers, engines and stuff for mac, for win for linux, for win with msvc ...
parent 0750d9a3
......@@ -98,9 +98,8 @@ IF( CMAKE_GENERATOR MATCHES "Visual Studio" )
ELSE()
# Unfortunately libstdc++'s header files don't work with mingw in ansi mode (basically libstdc++'s fault)
IF( CMAKE_HOST_SYSTEM MATCHES "Windows" )
SET( CMAKE_CXX_FLAGS "-frtti -pedantic -Wall -Wno-long-long -Wextra " CACHE STRING "" FORCE )
SET( CMAKE_CXX_FLAGS "-frtti -pedantic -Wall -Wno-long-long -Wextra " CACHE STRING "" FORCE )
ELSE()
# SET( CMAKE_CXX_FLAGS "-frtti -pedantic -ansi -Wall -Wno-long-long -Wextra -Wold-style-cast" CACHE STRING "" FORCE )
SET( CMAKE_CXX_FLAGS "-frtti -pedantic -ansi -Wall -Wno-long-long -Wextra " CACHE STRING "" FORCE )
ENDIF()
......@@ -117,10 +116,8 @@ SET( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -DDEBUG -O2" CACHE STRING "" FORCE )
# -----------------------------------------------------------------------------------------------------------------------------------------------
# Eigen3 specifics
# NOTE: this is included in ext. But we need to set several definitions to make (who else?) Visual Studio work
IF( CMAKE_GENERATOR MATCHES "Visual Studio" )
ADD_DEFINITIONS( -DEIGEN_DONT_VECTORIZE -DEIGEN_DONT_ALIGN -DEIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT )
ENDIF()
# NOTE: this is included in ext. But we need to set several definitions to make this work on 32 Bit machines due to alignment problems
ADD_DEFINITIONS( -DEIGEN_DONT_VECTORIZE -DEIGEN_DONT_ALIGN -DEIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
......
......@@ -25,8 +25,9 @@
#ifndef WLINEARALGEBRA_H
#define WLINEARALGEBRA_H
#include "WMatrixFixed.h"
#include "WMatrixEigen.h"
#include "WMatrixFixed.h"
#include "WVectorFixed.h"
#include "WPosition.h"
......
......@@ -22,4 +22,133 @@
//
//---------------------------------------------------------------------------
#include <iostream>
#include "WGEGraphicsWindow.h"
#include "exceptions/WGEInitFailed.h"
WGEGraphicsWindow::WGEGraphicsWindow( osg::ref_ptr<osg::Referenced> wdata,
int x,
int y,
int width,
int height )
{
#ifndef __APPLE__
m_WindowData = wdata;
// initialize context
try
{
createContext( x, y, width, height );
}
catch( ... )
{
// use our own exceptions
throw WGEInitFailed( "Initialization of OpenGL graphics context failed." );
}
#else
m_GraphicsWindow( new osgViewer::GraphicsWindowEmbedded( x, y, width, height ) );
#endif
}
WGEGraphicsWindow::~WGEGraphicsWindow()
{
// cleanup
}
osg::ref_ptr<osgViewer::GraphicsWindow> WGEGraphicsWindow::getGraphicsWindow()
{
return m_GraphicsWindow;
}
#ifndef __APPLE__
void WGEGraphicsWindow::createContext( int x, int y, int width, int height )
{
// Create traits for graphics contest request
osg::ref_ptr<osg::DisplaySettings> ds = osg::DisplaySettings::instance();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
// ensure correct $DISPLAY variable
traits->readDISPLAY();
if ( traits->displayNum < 0 )
{
traits->displayNum = 0;
}
// set a lot of values
traits->windowName = "OpenWalnut";
traits->screenNum = 0; // XXX is this a good idea?
traits->x = x;
traits->y = y;
traits->width = width;
traits->height = height;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
// traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
traits->inheritedWindowData = m_WindowData;
// finally create graphics context and window
m_GraphicsContext = osg::GraphicsContext::createGraphicsContext( traits.get() );
m_GraphicsWindow = osg::ref_ptr<osgViewer::GraphicsWindow>(
static_cast<osgViewer::GraphicsWindow*>( m_GraphicsContext.get() ) );
// get around dearranged traits on X11 (MTCompositeViewer only)
traits->x = x;
traits->y = x;
traits->width = width;
traits->height = height;
}
#endif
void WGEGraphicsWindow::resize( int width, int height )
{
m_GraphicsWindow->getEventQueue()->windowResize( 0, 0, width, height );
m_GraphicsWindow->resized( 0, 0, width, height );
}
void WGEGraphicsWindow::close()
{
m_GraphicsWindow->getEventQueue()->closeWindow();
}
void WGEGraphicsWindow::keyEvent( KeyEvents eventType, int key )
{
switch( eventType )
{
case KEYPRESS:
m_GraphicsWindow->getEventQueue()->keyPress( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
break;
case KEYRELEASE:
m_GraphicsWindow->getEventQueue()->keyRelease( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
break;
}
}
void WGEGraphicsWindow::mouseEvent( MouseEvents eventType, int x, int y, int button )
{
switch( eventType )
{
case MOUSEPRESS:
m_GraphicsWindow->getEventQueue()->mouseButtonPress( x, y, button );
break;
case MOUSERELEASE:
m_GraphicsWindow->getEventQueue()->mouseButtonRelease( x, y, button );
break;
case MOUSEDOUBLECLICK:
m_GraphicsWindow->getEventQueue()->mouseDoubleButtonPress( x, y, button );
break;
case MOUSEMOVE:
m_GraphicsWindow->getEventQueue()->mouseMotion( x, y );
break;
case MOUSESCROLL:
m_GraphicsWindow->getEventQueue()->mouseScroll2D( x, y );
break;
}
}
......@@ -25,13 +25,118 @@
#ifndef WGEGRAPHICSWINDOW_H
#define WGEGRAPHICSWINDOW_H
#if defined( __APPLE__ )
#include "platformDependent/WGEGraphicsWindowMac.h"
typedef WGEGraphicsWindowMac WGEGraphicsWindow;
#else
#include "platformDependent/WGEGraphicsWindowAll.h"
typedef WGEGraphicsWindowAll WGEGraphicsWindow;
#include <boost/shared_ptr.hpp>
#include <osgViewer/GraphicsWindow>
/**
* Class managing a single graphics context and OSG GraphicsWindow.
* \ingroup ge
*/
class WGEGraphicsWindow
{
public:
/**
* Default constructor.
*
* \param wdata the WindowData instance for the widget to use as render widget. NULL on Mac!
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
* \param height Height of the Widget.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
WGEGraphicsWindow( osg::ref_ptr<osg::Referenced> wdata, int x, int y, int width, int height );
/**
* Destructor.
*/
virtual ~WGEGraphicsWindow();
/**
* Getter for m_GraphicsWindow.
*
* \return the OSG GraphicsWindow instance.
*/
osg::ref_ptr<osgViewer::GraphicsWindow> getGraphicsWindow();
/**
* Event types for the keyEvent() handler.
*/
enum KeyEvents
{
KEYPRESS, KEYRELEASE
};
/**
* Mouse event types for the mouseEvent() handler.
*/
enum MouseEvents
{
MOUSEPRESS, MOUSERELEASE, MOUSEDOUBLECLICK, MOUSEMOVE, MOUSESCROLL
};
/**
* Updates size information.
*
* \param width new width.
* \param height new height.
*/
virtual void resize( int width, int height );
/**
* Initiates a close event for this viewer. It destroys the graphics context and invalidates the viewer.
* This should be called whenever a QT Widget closes to also free its OSG Viewer resources.
*/
virtual void close();
/**
* Handles key events (if forwarded to this Viewer instance).
*
* \param key the key code.
* \param eventType the type of event.
*/
virtual void keyEvent( KeyEvents eventType, int key );
/**
* Handles mouse events forwarded from widget.
*
* \param eventType the event type.
* \param x x coordinate of event.
* \param y y coordinate of event.
* \param button mouse button.
*/
virtual void mouseEvent( MouseEvents eventType, int x, int y, int button );
protected:
/**
* OpenSceneGraph render window.
*/
osg::ref_ptr<osgViewer::GraphicsWindow> m_GraphicsWindow;
#ifndef __APPLE__
/**
* Creates a new OpenGL context in the calling thread. Needs to be called before any other OpenGL operation.
*
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
* \param height Height of the Widget.
*/
void createContext( int x, int y, int width, int height );
/**
* OpenSceneGraph render context.
*/
osg::ref_ptr<osg::GraphicsContext> m_GraphicsContext;
/**
* Widget window data.
*/
osg::ref_ptr<osg::Referenced> m_WindowData;
#endif
private:
};
#endif // WGEGRAPHICSWINDOW_H
......@@ -22,4 +22,177 @@
//
//---------------------------------------------------------------------------
#include <string>
#include <iostream>
#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/UFOManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/View>
#include <osgDB/ReadFile>
#include "exceptions/WGEInitFailed.h"
#include "WGE2DManipulator.h"
#include "WGEZoomTrackballManipulator.h"
#include "WPickHandler.h"
#include "WGEViewer.h"
WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode )
: WGEGraphicsWindow( wdata, x, y, width, height ),
boost::enable_shared_from_this< WGEViewer >(),
m_name( name )
{
try
{
#ifndef __APPLE__
m_View = osg::ref_ptr<osgViewer::View>( new osgViewer::View );
#else
// on mac, this is a viewer!
m_View = osg::ref_ptr<osgViewer::Viewer>( new osgViewer::Viewer );
#endif
m_View->setCamera( new WGECamera( width, height, projectionMode ) );
#ifndef __APPLE__
m_View->getCamera()->setGraphicsContext( m_GraphicsContext.get() );
#else
m_View->getCamera()->setGraphicsContext( m_GraphicsWindow.get() );
#endif
switch( projectionMode )
{
case( WGECamera::ORTHOGRAPHIC ):
m_pickHandler = new WPickHandler( name );
m_View->addEventHandler( m_pickHandler );
if ( name != std::string( "main" ) )
break;
case( WGECamera::PERSPECTIVE ):
// camera manipulator
m_View->setCameraManipulator( new WGEZoomTrackballManipulator() );
m_View->setLightingMode( osg::View::HEADLIGHT ); // this is the default anyway
break;
case( WGECamera::TWO_D ):
// no manipulators nor gui handlers
break;
default:
throw WGEInitFailed( std::string( "Unknown projection mode" ) );
}
// add the stats handler
m_View->addEventHandler( new osgViewer::StatsHandler );
}
catch( ... )
{
throw WGEInitFailed( std::string( "Initialization of WGEViewer failed" ) );
}
}
WGEViewer::~WGEViewer()
{
// cleanup
close();
}
#ifdef __APPLE__
osg::ref_ptr<osgViewer::Viewer>
#else
osg::ref_ptr<osgViewer::View>
#endif
WGEViewer::getView()
{
return m_View;
}
void WGEViewer::setCameraManipulator( osg::ref_ptr<osgGA::MatrixManipulator> manipulator )
{
m_View->setCameraManipulator( manipulator );
// redraw request?? no since it redraws permanently and uses the new settings
}
osg::ref_ptr<osgGA::MatrixManipulator> WGEViewer::getCameraManipulator()
{
return m_View->getCameraManipulator();
}
void WGEViewer::setCamera( osg::ref_ptr<osg::Camera> camera )
{
m_View->setCamera( camera );
// redraw request?? No since it redraws permanently and uses the new settings
}
osg::ref_ptr<osg::Camera> WGEViewer::getCamera()
{
return m_View->getCamera();
}
void WGEViewer::setScene( osg::ref_ptr< WGEGroupNode > node )
{
m_View->setSceneData( node );
m_scene = node;
}
osg::ref_ptr< WGEGroupNode > WGEViewer::getScene()
{
return m_scene;
}
void WGEViewer::setBgColor( const WColor& bgColor )
{
m_View->getCamera()->setClearColor( bgColor );
}
void WGEViewer::paint()
{
#ifdef __APPLE__
m_View->frame();
#endif
}
void WGEViewer::resize( int width, int height )
{
m_View->getEventQueue()->windowResize( 0, 0, width, height );
WGEGraphicsWindow::resize( width, height );
// also update the camera
m_View->getCamera()->setViewport( 0, 0, width, height );
WGECamera* camera = dynamic_cast< WGECamera* >( m_View->getCamera() );
if( camera )
{
camera->resize();
}
}
void WGEViewer::close()
{
// forward close event
WGEGraphicsWindow::close();
}
std::string WGEViewer::getName() const
{
return m_name;
}
osg::ref_ptr< WPickHandler > WGEViewer::getPickHandler()
{
return m_pickHandler;
}
void WGEViewer::reset()
{
m_View->home();
}
......@@ -25,12 +25,190 @@
#ifndef WGEVIEWER_H
#define WGEVIEWER_H
#if defined( __APPLE__ )
#include "platformDependent/WGEViewerMac.h"
typedef WGEViewerMac WGEViewer;
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <osg/Node>
#include <osg/Version>
#include <osgGA/DriveManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/UFOManipulator>
#include <osgViewer/View>
// OSG interface changed in 2.9.7, to make it compile also with those versions we do this:
// OSG_MIN_VERSION_REQUIRED(2, 9, 8) macro is not available in e.g. OSG 2.8.1, hence we use the old way
#if ( ( OPENSCENEGRAPH_MAJOR_VERSION > 2 ) || ( OPENSCENEGRAPH_MAJOR_VERSION == 2 && ( OPENSCENEGRAPH_MINOR_VERSION > 9 || \
( OPENSCENEGRAPH_MINOR_VERSION == 9 && OPENSCENEGRAPH_PATCH_VERSION >= 8 ) ) ) )
#include <osgGA/CameraManipulator>
namespace osgGA
{
typedef CameraManipulator MatrixManipulator;
}
#else
#include <osgGA/MatrixManipulator>
#endif
#include "../common/WColor.h"
#include "../common/WThreadedRunner.h"
#include "WExportWGE.h"
#include "WGECamera.h"
#include "WGEGraphicsWindow.h"
#include "WGEGroupNode.h"
#include "WPickHandler.h"
/**
* Class for managing one view to the scene. This includes viewport, camera and graphics context.
* It is, besides WGraphicsEngine, the ONLY entry point for each widget for accessing the graphics engine.
* \ingroup ge
*/
class WGE_EXPORT WGEViewer: public WGEGraphicsWindow,
public boost::enable_shared_from_this< WGEViewer >
{
public:
/**
* Default constructor.
*
* \param name the name of the viewer
* \param wdata the WindowData instance for the widget to use as render widget
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
* \param height Height of the Widget.
* \param projectionMode Projection mode of the viewer.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int x, int y, int width, int height,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
* Destructor.
*/
virtual ~WGEViewer();
/**
* Repaints the contents. Mac only.
*/
virtual void paint();
/**
* Updates size information. Also updates camera.
*
* \param width new width.
* \param height new height.
*/
virtual void resize( int width, int height );
/**
* Close the viewer, but wait for the rendering thread to finish.
*/
virtual void close();
/**
* Getter for OpenSceneGraph View instance.
*
* \return the OSG Viewer instance.
*/
#ifdef __APPLE__
osg::ref_ptr<osgViewer::Viewer> getView();
#else
osg::ref_ptr<osgViewer::View> getView();
#endif
/**
* Resets the view using the installed manipulator.
*/
void reset();
/**
* Sets the camera manipulator to use.
*
* \param manipulator the manipulator to use.
*/
void setCameraManipulator( osg::ref_ptr<osgGA::MatrixManipulator> manipulator );
/**
* Returns current active camera manipulator
*
* \return the active camera manipulator.
*/
osg::ref_ptr<osgGA::MatrixManipulator> getCameraManipulator();
/**
* Sets the current camera.
*
* \param camera the OSG camera instance.
*/
void setCamera( osg::ref_ptr<osg::Camera> camera );
/**
* Returns the camera currently in use.
*
* \return the camera currently in use.
*/
osg::ref_ptr<osg::Camera> getCamera();
/**
* Sets the scene graph node to be used for rendering.
*
* \param node part of the scene graph
*/
void setScene( osg::ref_ptr< WGEGroupNode > node );
/**
* Returns the currently set OSG node.
*
* \return the node.
*/
osg::ref_ptr< WGEGroupNode > getScene();
/**
* Returns the name of the viewer.
*
* \return the name
*/
std::string getName() const;