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;
*
* 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
*/
......@@ -594,12 +594,12 @@ void actionMode ( Viewer::ActionMode _mode) {
viewerProperties().actionMode(_mode);
}
void shareGLWidget (QGLWidget *_widget)
void shareGLWidget(OFGLWidget *_widget)
{
shareGLWidget_ = _widget;
}
QGLWidget *shareGLWidget ()
OFGLWidget *shareGLWidget()
{
return shareGLWidget_;
}
......
......@@ -70,12 +70,13 @@
#include <QPair>
#include <QFileDialog>
#include <OpenFlipper/common/OFGLWidget.hh>
#include <ACG/Scenegraph/SceneGraph.hh>
#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
//== FORWARDDECLARATIONS ======================================================
class ViewObjectMarker;
class QGLWidget;
/** 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. */
......@@ -375,11 +376,11 @@ Viewer::ActionMode actionMode();
/// Sets the main QGLWidget for gl data sharing.
DLLEXPORT
void shareGLWidget (QGLWidget* _widget);
void shareGLWidget(OFGLWidget* _widget);
/// Returns the main QGLWidget for gl data sharing.
DLLEXPORT
QGLWidget* shareGLWidget ();
OFGLWidget* shareGLWidget();
/** Lock scene rotation via mouse
*
......
......@@ -459,9 +459,41 @@ int main(int argc, char **argv)
if ( !OpenFlipper::Options::nogui() ) {
// OpenGL check
#if (QT_VERSION >= QT_VERSION_CHECK(5,4,0))
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#endif
QApplication::setColorSpec( QApplication::CustomColor );
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
QCoreApplication::setOrganizationName("rwth-aachen.de");
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,
splitter_ = new QSplitter(Qt::Vertical,toolSplitter_);
stackedWidget_ = new QStackedWidget(splitter_);
QGLFormat format = QGLFormat::defaultFormat();
#ifdef ARCH_DARWIN
OFGLFormat format = OFGLFormat::defaultFormat();
#ifdef ARCH_DARWIN
format.setStereo(false);
#else
format.setStereo( OpenFlipper::Options::stereo() );
#endif
#else
format.setStereo(OpenFlipper::Options::stereo());
#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.setStencil(true);
format.setSampleBuffers(true);
QGLFormat::setDefaultFormat(format);
#endif
OFGLFormat::setDefaultFormat(format);
// Construct GL context & widget
baseLayout_ = new QtMultiViewLayout;
......@@ -228,11 +234,17 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
// 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
// ===============================================================================
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() ) {
// std::cerr << "No stereo ... disabling stereo for real context!" << std::endl;
format.setStereo(false);
QGLFormat::setDefaultFormat(format);
OFGLFormat::setDefaultFormat(format);
}/* else {
std::cerr << "Stereo found ok" << std::endl;
}*/
......@@ -241,7 +253,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
// force the compatibility profile since OpenFlipper does not work with the
// Core profile
format.setProfile(QGLFormat::CompatibilityProfile);
format.setProfile(OFGLFormat::CompatibilityProfile);
#if QT_VERSION >= 0x050000
// request the highest OpenGL version
......@@ -249,7 +261,18 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
format.setVersion(4,3);
#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_);
glView_ = new QtGLGraphicsView(stackedWidget_);
......
......@@ -96,6 +96,8 @@
#include <QDockWidget>
#include <OpenFlipper/common/OFGLWidget.hh>
#include <OpenFlipper/widgets/aboutWidget/aboutWidget.hh>
#include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh>
#include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh>
......@@ -696,7 +698,7 @@ public:
QAction* AC_ShowViewModeControls_;
/// gl widget used as drawing area to paint the graphics scene
QGLWidget* glWidget_;
OFGLWidget* glWidget_;
/// graphics scene used to paint gl context and widgets
QtGLGraphicsScene* glScene_;
......
......@@ -73,7 +73,6 @@
#include <QGraphicsWidget>
#include <QString>
#include <QGLFormat>
#include <QBoxLayout>
#include <QtNetwork/QUdpSocket>
#include <QToolBar>
......@@ -126,7 +125,7 @@ static const char COPY_PASTE_VIEW_START_STRING[] =
glViewer::glViewer( QGraphicsScene* _scene,
QGLWidget* _glWidget,
OFGLWidget* _glWidget,
Viewer::ViewerProperties& _properties,
QGraphicsWidget* _parent) :
QGraphicsWidget(_parent),
......@@ -230,10 +229,6 @@ void glViewer::makeCurrent() {
glWidget_->makeCurrent();
}
void glViewer::swapBuffers() {
glWidget_->swapBuffers();
}
//-----------------------------------------------------------------------------
......@@ -519,7 +514,12 @@ glViewer::copyToImage( QImage& _image,
// 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)
postproc_->resolveStereoAnyglyph(properties_.viewerId());
// =================================================================================
glBindFramebuffer(GL_FRAMEBUFFER, backbufferFbo);
glDrawBuffer(backbufferTarget);
// unbind vbo for qt log window
ACG::GLState::bindBuffer(GL_ARRAY_BUFFER, 0);
ACG::GLState::activeTexture(GL_TEXTURE0);
ACG::GLState::bindTexture(GL_TEXTURE_2D, 0);
// fbo.release();
//
// QRect blitRect(0,0,glstate_->viewport_width(),glstate_->viewport_height());
......@@ -739,7 +736,6 @@ void glViewer::drawScene(double _aspect)
// //time.restart();
// QGLFramebufferObject::blitFramebuffer( 0 , blitRect, &fbo, blitRect , GL_COLOR_BUFFER_BIT );
// //std::cerr << "Elapsed for blit: " << time.elapsed() << std::endl;
glFinish();
frame_time_ = timer.elapsed();
......@@ -747,7 +743,6 @@ void glViewer::drawScene(double _aspect)
// Inside the glWidget rendering, the system should not send extra updates
properties_.blockSignals(false);
}
......@@ -921,7 +916,6 @@ void glViewer::home()
void glViewer::viewAll()
{
makeCurrent();
// update scene graph (get new bounding box and set projection right, including near and far plane)
properties_.lockUpdate();
......@@ -996,7 +990,6 @@ void glViewer::initializeGL()
glstate_->translate(0.0, 0.0, -3.0);
setHome();
// pixel transfer
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
......@@ -1020,7 +1013,6 @@ void glViewer::initializeGL()
ACG::SceneGraph::analyzeSceneGraph(sceneGraphRoot_,maxPases,bbmin,bbmax);
sceneGraph ( sceneGraphRoot_, maxPases,bbmin,bbmax,true);
viewAll();
}
}
......@@ -1033,7 +1025,6 @@ void glViewer::paintGL(double _aspect)
{
if (!initialized_)
initializeGL ();
if (!properties_.updateLocked())
{
properties_.lockUpdate();
......@@ -1074,7 +1065,8 @@ void glViewer::paintGL(double _aspect)
glPopAttrib ();
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
......
......@@ -64,6 +64,8 @@
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/common/ViewerProperties.hh>
#include <OpenFlipper/common/OFGLWidget.hh>
#include <ACG/GL/GLState.hh>
#include <ACG/GL/FBO.hh>
#include <ACG/Scenegraph/SceneGraph.hh>
......@@ -90,7 +92,6 @@ class QSplitter;
class QImage;
class QSocketNotifier;
class QPropertyAnimation;
class QGLWidget;
struct PostProcessorInput;
......@@ -145,7 +146,7 @@ public:
*
*/
glViewer( QGraphicsScene* _scene,
QGLWidget* _glWidget,
OFGLWidget* _glWidget,
Viewer::ViewerProperties& _properties,
QGraphicsWidget* _parent = 0 );
......@@ -596,7 +597,7 @@ private:
QGraphicsScene* glScene_;
// gl widget used as drawing area to paint the graphics scene
QGLWidget* glWidget_;
OFGLWidget* glWidget_;
// Base graphics widget layout
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))
#include <QOpenGLContext>
#endif
//== NAMESPACES ===============================================================
//== IMPLEMENTATION ==========================================================
void glViewer::swapBuffers() {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 4))
glWidget_->context()->swapBuffers(glWidget_->context()->surface());
#else
glWidget_->swapBuffers();
#endif
}
//-----------------------------------------------------------------------------
//=============================================================================
//=============================================================================
......@@ -67,6 +67,10 @@
#include "simpleViewer.hh"
#if (QT_VERSION >= QT_VERSION_CHECK(5,4,0))
#include <QOpenGLWidget>
#endif
//== NAMESPACES ===============================================================
......@@ -78,9 +82,9 @@ SimpleViewer::SimpleViewer(QWidget* _parent, bool useDefaultSceneGraph) :
props_(-1),
actionMode_ (Viewer::ExamineMode)
{
QGLWidget *share = PluginFunctions::shareGLWidget ();
OFGLWidget *share = PluginFunctions::shareGLWidget ();
if (!share)
initialize (QGLFormat::defaultFormat (), 0, useDefaultSceneGraph);
initialize (OFGLFormat::defaultFormat (), 0, useDefaultSceneGraph);
else
initialize (share->format(), share, useDefaultSceneGraph);
}
......@@ -103,7 +107,7 @@ void SimpleViewer::resizeEvent(QResizeEvent *_event) {
//=============================================================================
//=============================================================================
void SimpleViewer::initialize (const QGLFormat & _format, QGLWidget *_shareWidget, bool useDefaultSceneGraph)
void SimpleViewer::initialize(const OFGLFormat & _format, OFGLWidget *_shareWidget, bool useDefaultSceneGraph)
{
connect (&props_, SIGNAL( getPickMode(std::string&) ),
......@@ -113,7 +117,12 @@ void SimpleViewer::initialize (const QGLFormat & _format, QGLWidget *_shareWidge
connect (&props_, SIGNAL( setActionMode(const Viewer::ActionMode) ),
this, SLOT( setActionMode(const Viewer::ActionMode)), Qt::DirectConnection );
glWidget_ = new QGLWidget (_format, 0, _shareWidget);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
glWidget_ = new OFGLWidget();
glWidget_->setFormat(_format);
#else
glWidget_ = new OFGLWidget(_format, 0, _shareWidget);
#endif
setFocusPolicy (Qt::StrongFocus);
setAcceptDrops (true);
......
......@@ -62,7 +62,8 @@
#include <OpenFlipper/common/ViewerProperties.hh>
#include <OpenFlipper/common/GlobalDefines.hh>
#include <QGraphicsView>
#include <QGLFormat>
#include <OpenFlipper/common/OFGLWidget.hh>
......@@ -107,7 +108,7 @@ class DLLEXPORT SimpleViewer : public QGraphicsView
private:
// initalisation
void initialize (const QGLFormat &_format, QGLWidget *_shareWidget = NULL, bool useDefaultSceneGraph = true);
void initialize(const OFGLFormat &_format, OFGLWidget *_shareWidget = NULL, bool useDefaultSceneGraph = true);
private slots:
......@@ -119,7 +120,7 @@ class DLLEXPORT SimpleViewer : public QGraphicsView
void getPickMode(std::string& _name);
private:
QGLWidget *glWidget_;
OFGLWidget *glWidget_;
Viewer::ViewerProperties props_;
......
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