Commit 6f51a2ef authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - now it is possible to query openGL settings safely

parent cdccd1e8
......@@ -27,6 +27,7 @@
#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osg/Camera>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
......@@ -45,6 +46,7 @@
#include "WGENoOpManipulator.h"
#include "WGEZoomTrackballManipulator.h"
#include "WPickHandler.h"
#include "../common/WConditionOneShot.h"
#include "WGEViewer.h"
......@@ -52,7 +54,8 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
int width, int height, WGECamera::ProjectionMode projectionMode )
: WGEGraphicsWindow( wdata, x, y, width, height ),
boost::enable_shared_from_this< WGEViewer >(),
m_name( name )
m_name( name ),
m_rendered( WBoolFlag::SPtr( new WBoolFlag( new WConditionOneShot(), false) ) )
{
try
{
......@@ -64,6 +67,9 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
#endif
m_View->setCamera( new WGECamera( width, height, projectionMode ) );
m_queryCallback = new QueryCallback( m_View->getCamera(), m_rendered );
m_View->getCamera()->setInitialDrawCallback( m_queryCallback );
#ifndef __APPLE__
m_View->getCamera()->setGraphicsContext( m_GraphicsContext.get() );
#else
......@@ -201,3 +207,41 @@ void WGEViewer::reset()
m_View->home();
}
std::string WGEViewer::getOpenGLVendor() const
{
return m_queryCallback->getVendor();
}
WBoolFlag::SPtr WGEViewer::isFrameRendered() const
{
return m_rendered;
}
WGEViewer::QueryCallback::QueryCallback( osg::ref_ptr<osg::Camera> camera, WBoolFlag::SPtr run ):
m_vendor( "" ),
m_run( run ),
m_camera( camera )
{
// init
}
WGEViewer::QueryCallback::~QueryCallback()
{
// cleanup
}
void WGEViewer::QueryCallback::operator()( osg::RenderInfo& /* renderInfo */ ) const
{
const GLubyte* vendor = glGetString( GL_VENDOR );
m_vendor = reinterpret_cast< const char* >( vendor );
// job done. De-register.
m_camera->setInitialDrawCallback( NULL );
m_run->set( true );
}
std::string WGEViewer::QueryCallback::getVendor() const
{
return m_vendor;
}
......@@ -52,6 +52,7 @@
#endif
#include "../common/WColor.h"
#include "../common/WFlag.h"
#include "../common/WThreadedRunner.h"
#include "WExportWGE.h"
#include "WGECamera.h"
......@@ -183,6 +184,20 @@ public:
*/
osg::ref_ptr< WPickHandler > getPickHandler();
/**
* Queries the OpenGL vendor info.
*
* \return Vendor string.
*/
std::string getOpenGLVendor() const;
/**
* Returns the flag which denotes whether a frame was rendered.
*
* \return the flag.
*/
WBoolFlag::SPtr isFrameRendered() const;
protected:
/**
* The OpenSceneGraph view used in this (Composite)Viewer.
......@@ -208,6 +223,65 @@ protected:
*/
osg::ref_ptr< WGEGroupNode > m_scene;
/**
* This flag is true and notifies after the first rendered frame.
*/
WBoolFlag::SPtr m_rendered;
/**
* Small class used for querying glGet info during rendering.
*/
class QueryCallback: public osg::Camera::DrawCallback
{
public:
/**
* Constructor. Automatically de-registers from camera after one run.
*
* \param camera the cam to which this was registered
* \param run notifies the flag when run.
*/
QueryCallback( osg::ref_ptr<osg::Camera> camera, WBoolFlag::SPtr run );
/**
* Destructor.
*/
virtual ~QueryCallback();
/**
* Query operator.
*
* \param renderInfo render info object
*/
virtual void operator()( osg::RenderInfo& renderInfo ) const;
/**
* Returns the queried vendor string.
*
* \return the vendor
*/
std::string getVendor() const;
protected:
/**
* The vendor string.
*/
mutable std::string m_vendor;
/**
* True if callback was run once.
*/
WBoolFlag::SPtr m_run;
/**
* The camera to which this was connected.
*/
osg::ref_ptr<osg::Camera> m_camera;
};
/**
* The callback used for querying OpenGL features
*/
osg::ref_ptr< QueryCallback > m_queryCallback;
private:
};
......
......@@ -222,6 +222,7 @@ void WMainWindow::setupGUI()
mainGLDock->getGLWidget()->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
m_mainGLWidget = mainGLDock->getGLWidget();
m_glDock->addDockWidget( Qt::RightDockWidgetArea, mainGLDock );
connect( m_mainGLWidget.get(), SIGNAL( renderedFirstFrame() ), this, SLOT( handleGLVendor() ) );
m_permanentToolBar = new WQtToolBar( "Standard Toolbar", this );
addToolBar( Qt::TopToolBarArea, m_permanentToolBar );
......@@ -1005,3 +1006,10 @@ void WMainWindow::handleLogLevelUpdate( unsigned int logLevel )
WLogger::getLogger()->setDefaultLogLevel( static_cast< LogLevel >( logLevel ) );
}
void WMainWindow::handleGLVendor()
{
// WARNING: never put blocking code here, as it might freeze the mainGLWidget.
std::string vendor = m_mainGLWidget->getViewer()->getOpenGLVendor();
// TODO(ebaum): warning
}
......@@ -344,6 +344,12 @@ private:
* The action controlling the auto-display feature.
*/
WSettingAction* m_autoDisplaySetting;
private slots:
/**
* Handles some special GL vendors and shows the user a dialog.
*/
void handleGLVendor();
};
#endif // WMAINWINDOW_H
......@@ -25,6 +25,7 @@
#include <string>
#include <iostream>
#include <QtGui/QApplication>
#include <QtGui/QColorDialog>
#include <QtGui/QFileDialog>
#include <QtGui/QKeyEvent>
......@@ -44,6 +45,8 @@
#include "core/graphicsEngine/WGraphicsEngine.h"
#include "core/kernel/WKernel.h"
#include "events/WRenderedFrameEvent.h"
#include "events/WEventTypes.h"
#include "WSettingAction.h"
#include "WMainWindow.h"
......@@ -96,6 +99,8 @@ WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::
m_Timer.start( 10 );
#endif
m_Viewer->isFrameRendered()->getCondition()->subscribeSignal( boost::bind( &WQtGLWidget::notifyFirstRenderedFrame, this ) );
// set bg color
updateViewerBackground();
// this action manages the above settings
......@@ -315,6 +320,17 @@ void WQtGLWidget::wheelEvent( QWheelEvent* event )
m_Viewer->mouseEvent( WGEViewer::MOUSESCROLL, x, y, 0 );
}
bool WQtGLWidget::event( QEvent* event )
{
if( event->type() == WQT_RENDERED_FRAME_EVENT )
{
emit renderedFirstFrame();
return true;
}
return WQtGLWidgetParent::event( event );
}
void WQtGLWidget::reset()
{
m_Viewer->reset();
......@@ -379,3 +395,8 @@ void WQtGLWidget::makeScreenshot()
WLogger::getLogger()->addLogMessage( std::string( "Screenshot saved to " ) + fileName.toStdString(), "QtGLWidgetAll", LL_INFO );
}
}
void WQtGLWidget::notifyFirstRenderedFrame()
{
QCoreApplication::postEvent( this, new WRenderedFrameEvent() );
}
......@@ -41,18 +41,19 @@
class WSettingAction;
#ifndef _WIN32
typedef QGLWidget WQtGLWidgetParent;
#else
typedef QWidget WQtGLWidgetParent;
#endif
/**
* A widget containing an open gl display area. This initializes OpenGL context and adds a view to the
* engine.
* \ingroup gui
*/
// NOTE: to make this work with MOC, the defines must be set before MOC runs (ensured in Build system)
class WQtGLWidget: public
#ifndef _WIN32
QGLWidget
#else
QWidget
#endif
class WQtGLWidget: public WQtGLWidgetParent
{
Q_OBJECT
......@@ -131,6 +132,13 @@ public:
*/
QAction* getBackgroundColorAction() const;
signals:
/**
* Signals that the first frame was rendered.
*/
void renderedFirstFrame();
public slots:
/**
* Resets the contained view using the installed manipulator.
......@@ -249,6 +257,18 @@ protected:
*/
void makeScreenshot();
/**
* Custom event dispatcher. Gets called by QT's Event system every time an event got sent to this widget. This event handler
* processes the notifyrender events. Others get forwarded.
*
* \note QT Doc says: use event() for custom events.
*
* \param event the event that got transmitted.
*
* \return true if the event got handled properly.
*/
virtual bool event( QEvent* event );
private:
/**
* Timer for periodic repaints.
......@@ -275,6 +295,11 @@ private:
*/
QAction* m_changeBGColorAction;
/**
* Called by the WGEViewer to notify about the first frame rendered
*/
void notifyFirstRenderedFrame();
private slots:
/**
* Function to handle updates in the setting \ref m_allowThrowSetting.
......
......@@ -66,4 +66,7 @@
// when a module connection got closed.
#define WQT_MODULE_DISCONNECT_EVENT QEvent::User + 11
// a frame got rendered
#define WQT_RENDERED_FRAME_EVENT QEvent::User + 12
#endif // WEVENTTYPES_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/>.
//
//---------------------------------------------------------------------------
#include "WEventTypes.h"
#include "WRenderedFrameEvent.h"
WRenderedFrameEvent::WRenderedFrameEvent()
: QEvent( static_cast< QEvent::Type >( WQT_RENDERED_FRAME_EVENT ) )
{
// initialize members
}
WRenderedFrameEvent::~WRenderedFrameEvent()
{
// 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 WRENDEREDFRAMEEVENT_H
#define WRENDEREDFRAMEEVENT_H
#include <boost/shared_ptr.hpp>
#include <QtCore/QEvent>
/**
* Event signalling a frame was rendered.
*/
class WRenderedFrameEvent: public QEvent
{
public:
/**
* Creates a new event instance.
*/
WRenderedFrameEvent();
/**
* Destructor.
*/
virtual ~WRenderedFrameEvent();
protected:
private:
};
#endif // WRENDEREDFRAMEEVENT_H
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