Commit 58583a5c authored by Mathias Goldau's avatar Mathias Goldau

[MERGE]

parents f0174c53 247c71ce
......@@ -30,33 +30,10 @@
#include "exceptions/WGEInitFailed.h"
WGEGraphicsWindow::WGEGraphicsWindow( osg::ref_ptr<osg::Referenced>
#ifdef WGEMODE_MULTITHREADED
wdata // this parameter is only needed on non-mac
#endif
,
int x,
int y,
int width,
int height ):
m_closed( false )
WGEGraphicsWindow::WGEGraphicsWindow( osg::ref_ptr< osg::Referenced >, int x, int y, int width, int height ) : m_closed( false )
{
#ifdef WGEMODE_MULTITHREADED
// initialize context
m_WindowData = wdata;
try
{
createContext( x, y, width, height );
}
catch( ... )
{
// use our own exceptions
throw WGEInitFailed( "Initialization of OpenGL graphics context failed." );
}
#else
m_GraphicsWindow = osg::ref_ptr<osgViewer::GraphicsWindow>(
static_cast<osgViewer::GraphicsWindow*>( new osgViewer::GraphicsWindowEmbedded( x, y, width, height ) ) );
#endif
}
WGEGraphicsWindow::~WGEGraphicsWindow()
......@@ -69,42 +46,6 @@ osg::ref_ptr<osgViewer::GraphicsWindow> WGEGraphicsWindow::getGraphicsWindow()
return m_GraphicsWindow;
}
#ifdef WGEMODE_MULTITHREADED
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;
// set a lot of values
traits->windowName = "OpenWalnut";
traits->x = x;
traits->y = y;
traits->width = width;
traits->height = height;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
traits->inheritedWindowData = m_WindowData;
traits->vsync = true;
// 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 )
{
if( !m_GraphicsWindow )
......
......@@ -28,8 +28,6 @@
#include <boost/shared_ptr.hpp>
#include <osgViewer/GraphicsWindow>
#include "WGraphicsEngineMode.h"
/**
* Class managing a single graphics context and OSG GraphicsWindow.
* \ingroup ge
......@@ -129,27 +127,6 @@ protected:
*/
osg::ref_ptr<osgViewer::GraphicsWindow> m_GraphicsWindow;
#ifdef WGEMODE_MULTITHREADED
/**
* 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:
/**
* Mark the window opened or closed.
......
......@@ -41,6 +41,8 @@
#include <osgDB/ReadFile>
#include "core/common/WLogger.h"
#include "WGE2DManipulator.h"
#include "WGEGroupNode.h"
#include "WGENoOpManipulator.h"
......@@ -49,8 +51,8 @@
#include "WPickHandler.h"
#include "exceptions/WGEInitFailed.h"
#include "../common/WConditionOneShot.h"
#include "../common/WThreadedRunner.h"
#include "core/common/WConditionOneShot.h"
#include "core/common/WThreadedRunner.h"
#include "WGEViewer.h"
......@@ -70,12 +72,7 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
{
try
{
#ifdef WGEMODE_MULTITHREADED
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
osg::ref_ptr< WGECamera > cam( new WGECamera( width, height, projectionMode ) );
m_View->setCamera( cam );
......@@ -83,11 +80,7 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
m_View->getCamera()->setInitialDrawCallback( m_queryCallback );
m_View->getCamera()->setFinalDrawCallback( m_screenCapture );
#ifdef WGEMODE_MULTITHREADED
m_View->getCamera()->setGraphicsContext( m_GraphicsContext.get() );
#else
m_View->getCamera()->setGraphicsContext( m_GraphicsWindow.get() );
#endif
switch( projectionMode )
{
......@@ -154,12 +147,7 @@ WGEViewer::~WGEViewer()
close();
}
#ifdef WGEMODE_SINGLETHREADED
osg::ref_ptr<osgViewer::Viewer>
#else
osg::ref_ptr<osgViewer::View>
#endif
WGEViewer::getView()
osg::ref_ptr<osgViewer::Viewer> WGEViewer::getView()
{
return m_View;
}
......@@ -233,9 +221,7 @@ WColor WGEViewer::getBgColor() const
void WGEViewer::paint()
{
#ifdef WGEMODE_SINGLETHREADED
m_View->frame();
#endif
}
void WGEViewer::resize( int width, int height )
......
......@@ -53,7 +53,6 @@
#include "WGECamera.h"
#include "WGEGraphicsWindow.h"
#include "WGraphicsEngineMode.h"
class WGEGroupNode;
#include "WGEScreenCapture.h"
class WPickHandler;
......@@ -125,11 +124,7 @@ public:
*
* \return the OSG Viewer instance.
*/
#ifdef WGEMODE_SINGLETHREADED
osg::ref_ptr<osgViewer::Viewer> getView();
#else
osg::ref_ptr<osgViewer::View> getView();
#endif
/**
* If the widget is not visible, we might be able to reduce CPU load. This does not hide the widget.
......@@ -340,11 +335,7 @@ protected:
/**
* The OpenSceneGraph view used in this (Composite)Viewer.
*/
#ifdef WGEMODE_SINGLETHREADED
osg::ref_ptr< osgViewer::Viewer > m_View;
#else
osg::ref_ptr< osgViewer::View > m_View;
#endif
/**
* The name of the viewer.
......
......@@ -46,7 +46,6 @@
#include "WGEViewer.h"
#include "exceptions/WGEInitFailed.h"
#include "exceptions/WGESignalSubscriptionFailed.h"
#include "WGraphicsEngineMode.h"
#include "postprocessing/WGEPostprocessor.h"
#include "WStaticOSGSetup.h"
......@@ -82,37 +81,14 @@ WGraphicsEngine::~WGraphicsEngine()
void WGraphicsEngine::setMultiThreadedViews( bool enable )
{
#ifdef WGEMODE_SINGLETHREADED
if( enable )
{
WLogger::getLogger()->addLogMessage( "WGraphicsEngine::setMultiThreadedViews not implemented for single threaded mode", "GE", LL_INFO );
}
#else
// ThreadingModel: enum with the following possibilities
//
// SingleThreaded
// CullDrawThreadPerContext
// ThreadPerContext
// DrawThreadPerContext
// CullThreadPerCameraDrawThreadPerContext
// ThreadPerCamera
// AutomaticSelection
if( !enable )
{
m_viewer->setThreadingModel( osgViewer::Viewer::SingleThreaded );
}
else
{
m_viewer->setThreadingModel( osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext );
}
#endif
}
bool WGraphicsEngine::isMultiThreadedViews() const
{
#ifdef WGEMODE_MULTITHREADED
return ( osgViewer::Viewer::SingleThreaded != m_viewer->getThreadingModel() );
#endif
// on mac, this always is false currently
return false;
}
......@@ -149,14 +125,7 @@ boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( std::string name, os
throw WNameNotUnique( "Viewer names need to be unique." );
}
#ifdef WGEMODE_MULTITHREADED
WCondition::SPtr viewerUpdateCondition( new WConditionOneShot() );
// finally add view (in the GE thread)
m_addViewers.push_back( viewer );
m_viewersUpdate = true;
#else
m_viewer->addView( viewer->getView() );
#endif
lock.unlock();
return viewer;
......@@ -173,22 +142,9 @@ void WGraphicsEngine::closeViewer( boost::shared_ptr< WGEViewer > viewer )
m_viewers.erase( viewer->getName() );
}
#ifdef WGEMODE_MULTITHREADED
WCondition::SPtr viewerUpdateCondition( new WConditionOneShot() );
m_viewerUpdateNotifiers.push_back( viewerUpdateCondition );
// finally remove view (in the GE thread)
m_removeViewers.push_back( viewer );
m_viewersUpdate = true;
#else
m_viewer->removeView( viewer->getView() );
#endif
lock.unlock();
#ifdef WGEMODE_MULTITHREADED
// wait until the GE thread processed our request.
viewerUpdateCondition->wait();
#endif
}
void WGraphicsEngine::closeViewer( const std::string name )
......@@ -199,21 +155,8 @@ void WGraphicsEngine::closeViewer( const std::string name )
m_viewers[name]->close();
m_viewers.erase( name );
#ifdef WGEMODE_MULTITHREADED
WCondition::SPtr viewerUpdateCondition( new WConditionOneShot() );
m_viewerUpdateNotifiers.push_back( viewerUpdateCondition );
// finally remove view (in the GE thread)
m_removeViewers.push_back( m_viewers[name] );
m_viewersUpdate = true;
#else
m_viewer->removeView( m_viewers[name]->getView() );
#endif
lock.unlock();
#ifdef WGEMODE_MULTITHREADED
// wait until the GE thread processed our request.
viewerUpdateCondition->wait();
#endif
}
else
{
......@@ -303,31 +246,7 @@ void WGraphicsEngine::threadMain()
// initialize all available postprocessors
WGEPostprocessor::initPostprocessors();
#ifdef WGEMODE_MULTITHREADED
// NOTE: this is needed here since the viewer might start without any widgets being initialized properly.
m_startThreadingCondition.wait();
m_running = true;
m_viewer->startThreading();
// do this before calling realize to ensure the initial views where added
applyViewerListUpdates();
if( !m_viewer->isRealized() )
{
m_viewer->realize();
}
while( !m_viewer->done() )
{
// added or removed views?
applyViewerListUpdates();
m_viewer->frame();
}
m_viewer->stopThreading();
m_running = false;
#else
//m_startThreadingCondition.wait();
m_running = true; // we have to make sure, that we are "running"
#endif
}
void WGraphicsEngine::notifyStop()
......@@ -335,9 +254,6 @@ void WGraphicsEngine::notifyStop()
// when stopping the system while the GE is still waiting.
m_startThreadingCondition.notify();
WLogger::getLogger()->addLogMessage( "Stopping Graphics Engine", "GE", LL_INFO );
#ifdef WGEMODE_MULTITHREADED
m_viewer->setDone( true );
#endif
}
void WGraphicsEngine::finalizeStartup()
......
//---------------------------------------------------------------------------
//
// 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 "WGraphicsEngineMode.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 WGRAPHICSENGINEMODE_H
#define WGRAPHICSENGINEMODE_H
// Default mode.
#define WGEMODE_SINGLETHREADED
#ifdef __APPLE__
// Single threaded mode on Apple machines
#define WGEMODE_SINGLETHREADED
#undef WGEMODE_MULTITHREADED
#endif
#ifdef _WIN32
// Multithreaded
#endif
#endif // WGRAPHICSENGINEMODE_H
......@@ -57,21 +57,20 @@ WQtGLDockWidget::WQtGLDockWidget( QString viewTitle, QString dockTitle, QWidget*
{
setObjectName( QString( "GL - " ) + dockTitle );
// the panel contains all other widgets, including the gl widget
// This allows adding other widgets to certain docks
m_panel = new QWidget( this );
m_layout = new QVBoxLayout( m_panel );
m_layout->setContentsMargins( 1, 1, 1, 1 );
m_glWidget = new WQtGLWidget( viewTitle.toStdString(), m_panel, projectionMode, shareWidget );
// NOTE: do not remove this. When creating custom widgets using the OSG manipulators, a too small size here (or even no min size) causes the
// cull visitor to do crap ... unknown reason ...
setMinimumSize( 50, 50 );
// add panel to layout.
m_layout->addWidget( m_glWidget );
// the panel contains all other widgets, including the gl widget
// This allows adding other widgets to certain docks
m_panel = new QWidget( this );
m_layout = new QVBoxLayout;
m_panel->setLayout( m_layout );
m_glWidget = new WQtGLWidget( viewTitle.toStdString(), this, projectionMode, shareWidget );
m_layout->addWidget( m_glWidget );
m_layout->setContentsMargins( 0, 0, 0, 0 );
setWidget( m_panel );
// we need to know whether the dock is visible or not
......@@ -202,6 +201,7 @@ WQtGLScreenCapture* WQtGLDockWidget::getScreenCapture()
void WQtGLDockWidget::forceGLWidgetSize( size_t w, size_t h )
{
wlog::debug( "WQtGLDockWidget" ) << "Forcing GLWidget to be " << w << "x" << h;
m_glWidget->setFixedSize( w, h );
}
......
......@@ -42,7 +42,6 @@
#include "core/graphicsEngine/WGEViewer.h"
#include "core/graphicsEngine/WGEZoomTrackballManipulator.h"
#include "core/graphicsEngine/WGraphicsEngine.h"
#include "core/graphicsEngine/WGraphicsEngineMode.h"
#include "core/kernel/WKernel.h"
#include "WQtGui.h"
......@@ -52,39 +51,15 @@
#include "WSettingAction.h"
#include "WMainWindow.h"
// See core/graphicsEngine/WGraphicsEngineMode.h for details.
#ifdef WGEMODE_MULTITHREADED
#ifdef _WIN32
#include <osgViewer/api/Win32/GraphicsWindowWin32>
typedef osgViewer::GraphicsWindowWin32::WindowData WindowData;
#else
#ifdef __APPLE__
// HELP NEEDED
// Leave it undefined for now, as the MacOSX version uses single threaded right now.
#else
#include <osgViewer/api/X11/GraphicsWindowX11>
typedef osgViewer::GraphicsWindowX11::WindowData WindowData;
#endif
#endif
#endif
#ifdef WGEMODE_GLWIDGET
WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::ProjectionMode projectionMode, const QWidget* shareWidget ):
QGLWidget( getDefaultFormat(), parent, dynamic_cast< const QGLWidget* >( shareWidget ) ),
#else
WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::ProjectionMode projectionMode, const QWidget* ):
QWidget( parent ),
#endif
m_nameOfViewer( nameOfViewer ),
m_recommendedSize(),
m_firstPaint( true )
{
m_recommendedSize.setWidth( 200 );
m_recommendedSize.setHeight( 200 );
m_initialProjectionMode = projectionMode;
setSizePolicy( QSizePolicy( QSizePolicy::QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
// required
setAttribute( Qt::WA_PaintOnScreen );
setAttribute( Qt::WA_NoSystemBackground );
......@@ -92,17 +67,6 @@ WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::
setMouseTracking( true );
// initialize OpenGL context and OpenSceneGraph
#ifdef WGEMODE_MULTITHREADED
#ifdef _WIN32
osg::ref_ptr<osg::Referenced> wdata = new WindowData( reinterpret_cast< HWND >( winId() ) );
#else
osg::ref_ptr<osg::Referenced> wdata = new WindowData( winId() );
#endif
// create viewer
m_Viewer = WKernel::getRunningKernel()->getGraphicsEngine()->createViewer(
m_nameOfViewer, wdata, x(), y(), width(), height(), m_initialProjectionMode );
#else
osg::ref_ptr<osg::Referenced> wdata; // NULL pointer since not used on Mac
// create viewer
......@@ -111,7 +75,6 @@ WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::
connect( &m_Timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );
m_Timer.start( 33 );
#endif
m_Viewer->isFrameRendered()->getCondition()->subscribeSignal( boost::bind( &WQtGLWidget::notifyFirstRenderedFrame, this ) );
......@@ -183,11 +146,6 @@ void WQtGLWidget::closeEvent( QCloseEvent* event )
WQtGLWidgetParent::closeEvent( event );
}
QSize WQtGLWidget::sizeHint() const
{
return m_recommendedSize;
}
void WQtGLWidget::setCameraManipulator( WQtGLWidget::CameraManipulators manipulator )
{
if( !m_Viewer )
......@@ -245,8 +203,6 @@ void WQtGLWidget::paintEvent( QPaintEvent* event )
WQtGLWidgetParent::paintEvent( event );
}
#ifdef WGEMODE_SINGLETHREADED
void WQtGLWidget::paintGL()
{
if( m_Viewer )
......@@ -258,58 +214,14 @@ void WQtGLWidget::paintGL()
}
}
void WQtGLWidget::resizeEvent( QResizeEvent* event )
{
// we must hand over the event to our base class because that one takes care
// that resizeGL is eventually called
WQtGLWidgetParent::resizeEvent( event );
}
void WQtGLWidget::resizeGL( int width, int height )
{
if( m_Viewer )
{
m_Viewer->resize( width, height );
}
}
#else
void WQtGLWidget::paintGL()
{
// m_Viewer->paint();
#ifdef WGEMODE_GLWIDGET
if( m_Viewer )
{
if( !m_Viewer->getPaused() )
{
// if the parent is a GL widget, issue parent method.
WQtGLWidgetParent::paintGL();
}
}
#else
#endif
}
void WQtGLWidget::resizeEvent( QResizeEvent* event )
{
if( m_Viewer )
{
m_Viewer->resize( event->size().width(), event->size().height() );
}
WQtGLWidgetParent::resizeEvent( event );
}
void WQtGLWidget::resizeGL( int width, int height )
{
// m_Viewer->resize( width, height );
#ifdef WGEMODE_GLWIDGET
// if the parent is a GL widget, issue parent method.
WQtGLWidgetParent::resizeGL( width, height );
#endif
}
#endif
int WQtGLWidget::translateButton( QMouseEvent* event )
{
......
......@@ -44,17 +44,7 @@
class WSettingAction;
// Use a QGlWidget as Parent on all systems but Windows
//#ifndef _WIN32
#define WGEMODE_GLWIDGET
//#endif
// See core/graphicsEngine/WGraphicsEngineMode.h for details.
#ifdef WGEMODE_GLWIDGET
typedef QGLWidget WQtGLWidgetParent;
#else
typedef QWidget WQtGLWidgetParent;
#endif
typedef QGLWidget WQtGLWidgetParent;
/**
* A widget containing an open gl display area. This initializes OpenGL context and adds a view to the
......@@ -85,14 +75,6 @@ public:
*/
virtual ~WQtGLWidget();
/**
* Returns the recommended size for the widget to allow
* parent widgets to give it a proper initial layout
*
* \return size hint of widget
*/
QSize sizeHint() const;
/**
* List of currently possible camera manipulators.
*/
......@@ -230,13 +212,6 @@ protected: