Commit e15fb52b authored by Jan Möbius's avatar Jan Möbius
Browse files

Merge branch 'feature_QOpenGLWidget' into 'master'

stripped the changes of QOpenGL branch to use QOpenGLWidgets on Qt5.4 or newer.

See merge request !15
parents 227b1c2c 4d7a0a2b
...@@ -128,7 +128,7 @@ static ViewObjectMarker* defaultMarker_ = 0; ...@@ -128,7 +128,7 @@ static ViewObjectMarker* defaultMarker_ = 0;
* *
* This pointer is used internally * This pointer is used internally
*/ */
static QGLWidget* shareGLWidget_ = 0; static OFGLWidget* shareGLWidget_ = 0;
/** This is a unique id for the running OpenFlipper instance. Use it to identify yourself on the network /** This is a unique id for the running OpenFlipper instance. Use it to identify yourself on the network
*/ */
...@@ -594,12 +594,12 @@ void actionMode ( Viewer::ActionMode _mode) { ...@@ -594,12 +594,12 @@ void actionMode ( Viewer::ActionMode _mode) {
viewerProperties().actionMode(_mode); viewerProperties().actionMode(_mode);
} }
void shareGLWidget (QGLWidget *_widget) void shareGLWidget(OFGLWidget *_widget)
{ {
shareGLWidget_ = _widget; shareGLWidget_ = _widget;
} }
QGLWidget *shareGLWidget () OFGLWidget *shareGLWidget()
{ {
return shareGLWidget_; return shareGLWidget_;
} }
......
...@@ -70,12 +70,13 @@ ...@@ -70,12 +70,13 @@
#include <QPair> #include <QPair>
#include <QFileDialog> #include <QFileDialog>
#include <OpenFlipper/common/OFGLWidget.hh>
#include <ACG/Scenegraph/SceneGraph.hh> #include <ACG/Scenegraph/SceneGraph.hh>
#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh> #include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
//== FORWARDDECLARATIONS ====================================================== //== FORWARDDECLARATIONS ======================================================
class ViewObjectMarker; class ViewObjectMarker;
class QGLWidget;
/** The Namespace PluginFunctions contains functions for all plugins. These functions should be used to get the /** The Namespace PluginFunctions contains functions for all plugins. These functions should be used to get the
* objects to work on or to set modes in the examiner widget. */ * objects to work on or to set modes in the examiner widget. */
...@@ -375,11 +376,11 @@ Viewer::ActionMode actionMode(); ...@@ -375,11 +376,11 @@ Viewer::ActionMode actionMode();
/// Sets the main QGLWidget for gl data sharing. /// Sets the main QGLWidget for gl data sharing.
DLLEXPORT DLLEXPORT
void shareGLWidget (QGLWidget* _widget); void shareGLWidget(OFGLWidget* _widget);
/// Returns the main QGLWidget for gl data sharing. /// Returns the main QGLWidget for gl data sharing.
DLLEXPORT DLLEXPORT
QGLWidget* shareGLWidget (); OFGLWidget* shareGLWidget();
/** Lock scene rotation via mouse /** Lock scene rotation via mouse
* *
......
...@@ -459,9 +459,41 @@ int main(int argc, char **argv) ...@@ -459,9 +459,41 @@ int main(int argc, char **argv)
if ( !OpenFlipper::Options::nogui() ) { if ( !OpenFlipper::Options::nogui() ) {
// OpenGL check // OpenGL check
#if (QT_VERSION >= QT_VERSION_CHECK(5,4,0))
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#endif
QApplication::setColorSpec( QApplication::CustomColor ); QApplication::setColorSpec( QApplication::CustomColor );
QApplication app(argc,argv); QApplication app(argc,argv);
#if QT_VERSION >= 0x050500
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
format.setVersion(4, 4);
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setOption(QSurfaceFormat::DeprecatedFunctions);
if (OpenFlipper::Options::debug())
format.setOption(format.options() | QSurfaceFormat::DebugContext);
QSurfaceFormat::setDefaultFormat(format);
QScreen *screen = app.primaryScreen();
QOffscreenSurface *surface = new QOffscreenSurface();
surface->create();
QOpenGLContext context;
context.setScreen(screen);
context.create();
context.makeCurrent(surface);
#endif
// Set organization and application names // Set organization and application names
QCoreApplication::setOrganizationName("rwth-aachen.de"); QCoreApplication::setOrganizationName("rwth-aachen.de");
QCoreApplication::setApplicationName(TOSTRING(PRODUCT_STRING)); QCoreApplication::setApplicationName(TOSTRING(PRODUCT_STRING));
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#pragma once
#include <QtGlobal>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 4))
#include <QOpenGLWidget>
#include <QSurfaceFormat>
typedef QOpenGLWidget OFGLWidget;
typedef QSurfaceFormat OFGLFormat;
#else
#include <QGLWidget>
#include <QGLFormat>
typedef QGLWidget OFGLWidget;
typedef QGLFormat OFGLFormat;
#endif
...@@ -207,17 +207,23 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -207,17 +207,23 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
splitter_ = new QSplitter(Qt::Vertical,toolSplitter_); splitter_ = new QSplitter(Qt::Vertical,toolSplitter_);
stackedWidget_ = new QStackedWidget(splitter_); stackedWidget_ = new QStackedWidget(splitter_);
QGLFormat format = QGLFormat::defaultFormat(); OFGLFormat format = OFGLFormat::defaultFormat();
#ifdef ARCH_DARWIN
#ifdef ARCH_DARWIN
format.setStereo(false); format.setStereo(false);
#else #else
format.setStereo( OpenFlipper::Options::stereo() ); format.setStereo(OpenFlipper::Options::stereo());
#endif #endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
format.setAlphaBufferSize(8);
format.setStencilBufferSize(8);
format.setSamples(4); // todo: get sample count from settings
#else
format.setAlpha(true); format.setAlpha(true);
format.setStencil(true); format.setStencil(true);
format.setSampleBuffers(true); format.setSampleBuffers(true);
QGLFormat::setDefaultFormat(format); #endif
OFGLFormat::setDefaultFormat(format);
// Construct GL context & widget // Construct GL context & widget
baseLayout_ = new QtMultiViewLayout; baseLayout_ = new QtMultiViewLayout;
...@@ -228,11 +234,17 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -228,11 +234,17 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
// If we get stereo buffers, we use them .. which might disable multisampling // If we get stereo buffers, we use them .. which might disable multisampling
// If we don't have stereo, we disable it to not interfere with multisampling // If we don't have stereo, we disable it to not interfere with multisampling
// =============================================================================== // ===============================================================================
QGLWidget* test = new QGLWidget(format); #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
OFGLWidget* test = new OFGLWidget();
test->setFormat(format);
#else
OFGLWidget* test = new OFGLWidget(format);
#endif
if ( ! test->format().stereo() ) { if ( ! test->format().stereo() ) {
// std::cerr << "No stereo ... disabling stereo for real context!" << std::endl; // std::cerr << "No stereo ... disabling stereo for real context!" << std::endl;
format.setStereo(false); format.setStereo(false);
QGLFormat::setDefaultFormat(format); OFGLFormat::setDefaultFormat(format);
}/* else { }/* else {
std::cerr << "Stereo found ok" << std::endl; std::cerr << "Stereo found ok" << std::endl;
}*/ }*/
...@@ -241,7 +253,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -241,7 +253,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
// force the compatibility profile since OpenFlipper does not work with the // force the compatibility profile since OpenFlipper does not work with the
// Core profile // Core profile
format.setProfile(QGLFormat::CompatibilityProfile); format.setProfile(OFGLFormat::CompatibilityProfile);
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
// request the highest OpenGL version // request the highest OpenGL version
...@@ -249,7 +261,18 @@ CoreWidget( QVector<ViewMode*>& _viewModes, ...@@ -249,7 +261,18 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
format.setVersion(4,3); format.setVersion(4,3);
#endif #endif
glWidget_ = new QGLWidget(format,0);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 4))
if (OpenFlipper::Options::debug())
format.setOption(format.options() | QSurfaceFormat::DebugContext);
glWidget_ = new OFGLWidget();
glWidget_->setFormat(format);
glWidget_->makeCurrent();
#else
glWidget_ = new OFGLWidget(format, 0);
#endif
PluginFunctions::shareGLWidget (glWidget_); PluginFunctions::shareGLWidget (glWidget_);
glView_ = new QtGLGraphicsView(stackedWidget_); glView_ = new QtGLGraphicsView(stackedWidget_);
......
...@@ -96,6 +96,8 @@ ...@@ -96,6 +96,8 @@
#include <QDockWidget> #include <QDockWidget>
#include <OpenFlipper/common/OFGLWidget.hh>
#include <OpenFlipper/widgets/aboutWidget/aboutWidget.hh> #include <OpenFlipper/widgets/aboutWidget/aboutWidget.hh>
#include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh> #include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh>
#include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh> #include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh>
...@@ -696,7 +698,7 @@ public: ...@@ -696,7 +698,7 @@ public:
QAction* AC_ShowViewModeControls_; QAction* AC_ShowViewModeControls_;
/// gl widget used as drawing area to paint the graphics scene /// gl widget used as drawing area to paint the graphics scene
QGLWidget* glWidget_; OFGLWidget* glWidget_;
/// graphics scene used to paint gl context and widgets /// graphics scene used to paint gl context and widgets
QtGLGraphicsScene* glScene_; QtGLGraphicsScene* glScene_;
......
...@@ -73,7 +73,6 @@ ...@@ -73,7 +73,6 @@
#include <QGraphicsWidget> #include <QGraphicsWidget>
#include <QString> #include <QString>
#include <QGLFormat>
#include <QBoxLayout> #include <QBoxLayout>
#include <QtNetwork/QUdpSocket> #include <QtNetwork/QUdpSocket>
#include <QToolBar> #include <QToolBar>
...@@ -126,7 +125,7 @@ static const char COPY_PASTE_VIEW_START_STRING[] = ...@@ -126,7 +125,7 @@ static const char COPY_PASTE_VIEW_START_STRING[] =
glViewer::glViewer( QGraphicsScene* _scene, glViewer::glViewer( QGraphicsScene* _scene,
QGLWidget* _glWidget, OFGLWidget* _glWidget,
Viewer::ViewerProperties& _properties, Viewer::ViewerProperties& _properties,
QGraphicsWidget* _parent) : QGraphicsWidget* _parent) :
QGraphicsWidget(_parent), QGraphicsWidget(_parent),
...@@ -230,10 +229,6 @@ void glViewer::makeCurrent() { ...@@ -230,10 +229,6 @@ void glViewer::makeCurrent() {
glWidget_->makeCurrent(); glWidget_->makeCurrent();
} }
void glViewer::swapBuffers() {
glWidget_->swapBuffers();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -519,7 +514,12 @@ glViewer::copyToImage( QImage& _image, ...@@ -519,7 +514,12 @@ glViewer::copyToImage( QImage& _image,
// makeCurrent(); // makeCurrent();
_image = glWidget_->grabFrameBuffer(true).copy (_l, _t, _w, _h).convertToFormat (QImage::Format_RGB32); #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 4))
_image = glWidget_->grabFramebuffer()
#else
_image = glWidget_->grabFrameBuffer(true)
#endif
.copy(_l, _t, _w, _h).convertToFormat(QImage::Format_RGB32);
} }
...@@ -721,15 +721,12 @@ void glViewer::drawScene(double _aspect) ...@@ -721,15 +721,12 @@ void glViewer::drawScene(double _aspect)
postproc_->resolveStereoAnyglyph(properties_.viewerId()); postproc_->resolveStereoAnyglyph(properties_.viewerId());
// ================================================================================= // =================================================================================
glBindFramebuffer(GL_FRAMEBUFFER, backbufferFbo);
glDrawBuffer(backbufferTarget); glDrawBuffer(backbufferTarget);
// unbind vbo for qt log window // unbind vbo for qt log window
ACG::GLState::bindBuffer(GL_ARRAY_BUFFER, 0); ACG::GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
ACG::GLState::activeTexture(GL_TEXTURE0); ACG::GLState::activeTexture(GL_TEXTURE0);
ACG::GLState::bindTexture(GL_TEXTURE_2D, 0); ACG::GLState::bindTexture(GL_TEXTURE_2D, 0);
// fbo.release(); // fbo.release();
// //
// QRect blitRect(0,0,glstate_->viewport_width(),glstate_->viewport_height()); // QRect blitRect(0,0,glstate_->viewport_width(),glstate_->viewport_height());
...@@ -739,7 +736,6 @@ void glViewer::drawScene(double _aspect) ...@@ -739,7 +736,6 @@ void glViewer::drawScene(double _aspect)
// //time.restart(); // //time.restart();
// QGLFramebufferObject::blitFramebuffer( 0 , blitRect, &fbo, blitRect , GL_COLOR_BUFFER_BIT ); // QGLFramebufferObject::blitFramebuffer( 0 , blitRect, &fbo, blitRect , GL_COLOR_BUFFER_BIT );
// //std::cerr << "Elapsed for blit: " << time.elapsed() << std::endl; // //std::cerr << "Elapsed for blit: " << time.elapsed() << std::endl;
glFinish(); glFinish();
frame_time_ = timer.elapsed(); frame_time_ = timer.elapsed();
...@@ -747,7 +743,6 @@ void glViewer::drawScene(double _aspect) ...@@ -747,7 +743,6 @@ void glViewer::drawScene(double _aspect)
// Inside the glWidget rendering, the system should not send extra updates // Inside the glWidget rendering, the system should not send extra updates
properties_.blockSignals(false); properties_.blockSignals(false);
} }
...@@ -921,7 +916,6 @@ void glViewer::home() ...@@ -921,7 +916,6 @@ void glViewer::home()
void glViewer::viewAll() void glViewer::viewAll()
{ {
makeCurrent(); makeCurrent();
// update scene graph (get new bounding box and set projection right, including near and far plane) // update scene graph (get new bounding box and set projection right, including near and far plane)
properties_.lockUpdate(); properties_.lockUpdate();
...@@ -996,7 +990,6 @@ void glViewer::initializeGL() ...@@ -996,7 +990,6 @@ void glViewer::initializeGL()
glstate_->translate(0.0, 0.0, -3.0); glstate_->translate(0.0, 0.0, -3.0);
setHome(); setHome();
// pixel transfer // pixel transfer
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
...@@ -1020,7 +1013,6 @@ void glViewer::initializeGL() ...@@ -1020,7 +1013,6 @@ void glViewer::initializeGL()
ACG::SceneGraph::analyzeSceneGraph(sceneGraphRoot_,maxPases,bbmin,bbmax); ACG::SceneGraph::analyzeSceneGraph(sceneGraphRoot_,maxPases,bbmin,bbmax);
sceneGraph ( sceneGraphRoot_, maxPases,bbmin,bbmax,true); sceneGraph ( sceneGraphRoot_, maxPases,bbmin,bbmax,true);
viewAll(); viewAll();
} }
} }
...@@ -1033,7 +1025,6 @@ void glViewer::paintGL(double _aspect) ...@@ -1033,7 +1025,6 @@ void glViewer::paintGL(double _aspect)
{ {
if (!initialized_) if (!initialized_)
initializeGL (); initializeGL ();
if (!properties_.updateLocked()) if (!properties_.updateLocked())
{ {
properties_.lockUpdate(); properties_.lockUpdate();
...@@ -1074,7 +1065,8 @@ void glViewer::paintGL(double _aspect) ...@@ -1074,7 +1065,8 @@ void glViewer::paintGL(double _aspect)
glPopAttrib (); glPopAttrib ();
} }
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
} }
......
...@@ -64,6 +64,8 @@ ...@@ -64,6 +64,8 @@
#include <OpenFlipper/common/Types.hh> #include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/common/ViewerProperties.hh> #include <OpenFlipper/common/ViewerProperties.hh>
#include <OpenFlipper/common/OFGLWidget.hh>
#include <ACG/GL/GLState.hh> #include <ACG/GL/GLState.hh>
#include <ACG/GL/FBO.hh> #include <ACG/GL/FBO.hh>
#include <ACG/Scenegraph/SceneGraph.hh> #include <ACG/Scenegraph/SceneGraph.hh>
...@@ -90,7 +92,6 @@ class QSplitter; ...@@ -90,7 +92,6 @@ class QSplitter;
class QImage; class QImage;
class QSocketNotifier; class QSocketNotifier;
class QPropertyAnimation; class QPropertyAnimation;
class QGLWidget;
struct PostProcessorInput; struct PostProcessorInput;
...@@ -145,7 +146,7 @@ public: ...@@ -145,7 +146,7 @@ public:
* *
*/ */
glViewer( QGraphicsScene* _scene, glViewer( QGraphicsScene* _scene,
QGLWidget* _glWidget, OFGLWidget* _glWidget,
Viewer::ViewerProperties& _properties, Viewer::ViewerProperties& _properties,
QGraphicsWidget* _parent = 0 ); QGraphicsWidget* _parent = 0 );
...@@ -596,7 +597,7 @@ private: ...@@ -596,7 +597,7 @@ private:
QGraphicsScene* glScene_; QGraphicsScene* glScene_;
// gl widget used as drawing area to paint the graphics scene // gl widget used as drawing area to paint the graphics scene
QGLWidget* glWidget_; OFGLWidget* glWidget_;
// Base graphics widget layout // Base graphics widget layout
QtGLViewerLayout* glBaseLayout_; QtGLViewerLayout* glBaseLayout_;
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
// QOpenGL headers and glew are in conflict,
// so implement functions that make use of QOpenGL classes in separate file
//=============================================================================
//
// CLASS glViewer - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "QtBaseViewer.hh"
#include <OpenFlipper/common/GlobalOptions.hh>
#if (QT_VERSION >= QT_VERSION_CHECK(5,4,4))