From 5d625223c121c5756de4423d875da4d3a902e1a4 Mon Sep 17 00:00:00 2001 From: Sigurd Pettersen Date: Tue, 9 Jan 2024 22:06:20 +0100 Subject: [PATCH] Refactor to deprecate existing QGLWidget derived widget Renamed cvfqt::OpenGLWidget to cvfqt::GLWidget_deprecated Renamed cvfqt::CvfBoundQGLContext to cvfqt::CvfBoundQGLContext_deprecated Renamed cvfqt::OpenGLContext to cvfqt::OpenGLContext_QGLContextAdapter_deprecated Added cvf::OpenGLUtils --- Fwk/AppFwk/cafViewer/cafOpenGLWidget.cpp | 8 +- Fwk/AppFwk/cafViewer/cafViewer.cpp | 6 +- Fwk/VizFwk/LibGuiQt/CMakeLists.txt | 12 +- .../LibGuiQt/cvfqtCvfBoundQGLContext.cpp | 93 ----------- ...=> cvfqtCvfBoundQGLContext_deprecated.cpp} | 123 +++++--------- ...h => cvfqtCvfBoundQGLContext_deprecated.h} | 30 +++- ...idget.cpp => cvfqtGLWidget_deprecated.cpp} | 20 +-- ...nGLWidget.h => cvfqtGLWidget_deprecated.h} | 8 +- Fwk/VizFwk/LibRender/CMakeLists.txt | 2 + Fwk/VizFwk/LibRender/cvfLibRender.h | 1 + Fwk/VizFwk/LibRender/cvfOpenGLUtils.cpp | 152 ++++++++++++++++++ .../cvfOpenGLUtils.h} | 20 +-- Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.cpp | 8 +- Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.h | 4 +- .../TestApps/Qt/QtMultiView/QMVWidget.cpp | 10 +- .../TestApps/Qt/QtMultiView/QMVWidget.h | 4 +- .../Qt/QtSnippetRunner/QSRSnippetWidget.cpp | 7 +- .../Qt/QtSnippetRunner/QSRSnippetWidget.h | 4 +- 18 files changed, 265 insertions(+), 247 deletions(-) delete mode 100644 Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext.cpp rename Fwk/VizFwk/LibGuiQt/{cvfqtOpenGLContext.cpp => cvfqtCvfBoundQGLContext_deprecated.cpp} (63%) rename Fwk/VizFwk/LibGuiQt/{cvfqtOpenGLContext.h => cvfqtCvfBoundQGLContext_deprecated.h} (73%) rename Fwk/VizFwk/LibGuiQt/{cvfqtOpenGLWidget.cpp => cvfqtGLWidget_deprecated.cpp} (86%) rename Fwk/VizFwk/LibGuiQt/{cvfqtOpenGLWidget.h => cvfqtGLWidget_deprecated.h} (87%) create mode 100644 Fwk/VizFwk/LibRender/cvfOpenGLUtils.cpp rename Fwk/VizFwk/{LibGuiQt/cvfqtCvfBoundQGLContext.h => LibRender/cvfOpenGLUtils.h} (81%) diff --git a/Fwk/AppFwk/cafViewer/cafOpenGLWidget.cpp b/Fwk/AppFwk/cafViewer/cafOpenGLWidget.cpp index c343eccc69..8da8fa837a 100644 --- a/Fwk/AppFwk/cafViewer/cafOpenGLWidget.cpp +++ b/Fwk/AppFwk/cafViewer/cafOpenGLWidget.cpp @@ -37,7 +37,7 @@ #include "cafOpenGLWidget.h" #include "cvfBase.h" #include "cvfOpenGLContextGroup.h" -#include "cvfqtCvfBoundQGLContext.h" +#include "cvfqtCvfBoundQGLContext_deprecated.h" namespace caf { @@ -58,7 +58,7 @@ OpenGLWidget::OpenGLWidget( cvf::OpenGLContextGroup* contextGroup, QWidget* parent, OpenGLWidget* shareWidget, Qt::WindowFlags f ) - : QGLWidget( new cvfqt::CvfBoundQGLContext( contextGroup, format ), parent, shareWidget, f ) + : QGLWidget( new cvfqt::CvfBoundQGLContext_deprecated( contextGroup, format ), parent, shareWidget, f ) { if ( isValid() ) { @@ -106,7 +106,7 @@ OpenGLWidget::OpenGLWidget( cvf::OpenGLContextGroup* contextGroup, /// If the context is not valid, sharing failed and the newly created widget/context be discarded. //-------------------------------------------------------------------------------------------------- OpenGLWidget::OpenGLWidget( OpenGLWidget* shareWidget, QWidget* parent, Qt::WindowFlags f ) - : QGLWidget( new cvfqt::CvfBoundQGLContext( shareWidget->cvfOpenGLContext()->group(), shareWidget->format() ), + : QGLWidget( new cvfqt::CvfBoundQGLContext_deprecated( shareWidget->cvfOpenGLContext()->group(), shareWidget->format() ), parent, shareWidget, f ) @@ -145,7 +145,7 @@ OpenGLWidget::OpenGLWidget( OpenGLWidget* shareWidget, QWidget* parent, Qt::Wind cvf::OpenGLContext* OpenGLWidget::cvfOpenGLContext() const { const QGLContext* qglContext = context(); - const cvfqt::CvfBoundQGLContext* contextBinding = dynamic_cast( qglContext ); + const cvfqt::CvfBoundQGLContext_deprecated* contextBinding = dynamic_cast( qglContext ); CVF_ASSERT( contextBinding ); return contextBinding->cvfOpenGLContext(); diff --git a/Fwk/AppFwk/cafViewer/cafViewer.cpp b/Fwk/AppFwk/cafViewer/cafViewer.cpp index d4bd7f2a27..22ae1b00ae 100644 --- a/Fwk/AppFwk/cafViewer/cafViewer.cpp +++ b/Fwk/AppFwk/cafViewer/cafViewer.cpp @@ -52,6 +52,7 @@ #include "cvfModel.h" #include "cvfOpenGLCapabilities.h" #include "cvfOpenGLResourceManager.h" +#include "cvfOpenGLUtils.h" #include "cvfOverlayImage.h" #include "cvfPart.h" #include "cvfRay.h" @@ -69,7 +70,6 @@ #include "cvfUniform.h" #include "cvfUniformSet.h" -#include "cvfqtOpenGLContext.h" #include "cvfqtPerformanceInfoHud.h" #include "cvfqtUtils.h" @@ -850,7 +850,7 @@ void caf::Viewer::paintEvent( QPaintEvent* event ) if ( isShadersSupported() ) { - cvfqt::OpenGLContext::saveOpenGLState( myOglContext.p() ); + cvf::OpenGLUtils::pushOpenGLState( myOglContext.p() ); } optimizeClippingPlanes(); @@ -880,7 +880,7 @@ void caf::Viewer::paintEvent( QPaintEvent* event ) if ( isShadersSupported() ) { - cvfqt::OpenGLContext::restoreOpenGLState( myOglContext.p() ); + cvf::OpenGLUtils::popOpenGLState( myOglContext.p() ); } painter.endNativePainting(); diff --git a/Fwk/VizFwk/LibGuiQt/CMakeLists.txt b/Fwk/VizFwk/LibGuiQt/CMakeLists.txt index f0c5385f35..22b9f12edc 100644 --- a/Fwk/VizFwk/LibGuiQt/CMakeLists.txt +++ b/Fwk/VizFwk/LibGuiQt/CMakeLists.txt @@ -20,22 +20,20 @@ set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::Widgets Qt5::OpenGL) set(CEE_HEADER_FILES cvfqtBasicAboutDialog.h -cvfqtCvfBoundQGLContext.h cvfqtMouseState.h -cvfqtOpenGLContext.h -cvfqtOpenGLWidget.h cvfqtPerformanceInfoHud.h cvfqtUtils.h +cvfqtCvfBoundQGLContext_deprecated.h +cvfqtGLWidget_deprecated.h ) set(CEE_SOURCE_FILES cvfqtBasicAboutDialog.cpp -cvfqtCvfBoundQGLContext.cpp cvfqtMouseState.cpp -cvfqtOpenGLContext.cpp -cvfqtOpenGLWidget.cpp cvfqtPerformanceInfoHud.cpp cvfqtUtils.cpp +cvfqtCvfBoundQGLContext_deprecated.cpp +cvfqtGLWidget_deprecated.cpp ) add_library(${PROJECT_NAME} ${CEE_HEADER_FILES} ${CEE_SOURCE_FILES}) @@ -58,6 +56,6 @@ source_group("" FILES ${PROJECT_FILES}) # Unity Build if (CMAKE_UNITY_BUILD) - set_source_files_properties (cvfqtOpenGLWidget.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE) + set_source_files_properties (cvfqtGLWidget_deprecated.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE) set_source_files_properties (cvfqtOpenGLContext.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE) endif() diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext.cpp b/Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext.cpp deleted file mode 100644 index c3734d7af2..0000000000 --- a/Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext.cpp +++ /dev/null @@ -1,93 +0,0 @@ -//################################################################################################## -// -// Custom Visualization Core library -// Copyright (C) 2011-2013 Ceetron AS -// -// This library may be used under the terms of either the GNU General Public License or -// the GNU Lesser General Public License as follows: -// -// GNU General Public License Usage -// This library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This library 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 General Public License at <> -// for more details. -// -// GNU Lesser General Public License Usage -// This library 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 2.1 of the License, or -// (at your option) any later version. -// -// This library 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 at <> -// for more details. -// -//################################################################################################## - - -#include "cvfBase.h" -#include "cvfqtCvfBoundQGLContext.h" -#include "cvfqtOpenGLContext.h" - -namespace cvfqt { - - - -//================================================================================================== -/// -/// \class cvfqt::CvfBoundQGLContext -/// \ingroup GuiQt -/// -/// -/// -//================================================================================================== - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -CvfBoundQGLContext::CvfBoundQGLContext(cvf::OpenGLContextGroup* contextGroup, const QGLFormat & format) -: QGLContext(format) -{ - m_cvfGLContext = new OpenGLContext(contextGroup, this); -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -CvfBoundQGLContext::~CvfBoundQGLContext() -{ - if (m_cvfGLContext.notNull()) - { - // TODO - // Need to resolve the case where the Qt QGLcontext (that we're deriving from) is deleted - // and we are still holding a reference to one or more OpenGLContext objects - // By the time we get here we expect that we're holding the only reference - CVF_ASSERT(m_cvfGLContext->refCount() == 1); - m_cvfGLContext = NULL; - } -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::OpenGLContext* CvfBoundQGLContext::cvfOpenGLContext() const -{ - return const_cast(m_cvfGLContext.p()); -} - - -} // namespace cvfqt - - diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.cpp b/Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext_deprecated.cpp similarity index 63% rename from Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.cpp rename to Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext_deprecated.cpp index 7d29682d30..5fbcfd286f 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.cpp +++ b/Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext_deprecated.cpp @@ -36,12 +36,8 @@ #include "cvfBase.h" -#include "cvfOpenGL.h" -#include "cvfqtOpenGLContext.h" -#include "cvfqtCvfBoundQGLContext.h" - -#include "cvfOpenGLContextGroup.h" #include "cvfOpenGLCapabilities.h" +#include "cvfqtCvfBoundQGLContext_deprecated.h" namespace cvfqt { @@ -49,7 +45,7 @@ namespace cvfqt { //================================================================================================== /// -/// \class cvfqt::OpenGLContext +/// \class cvfqt::OpenGLContext_QGLContextAdapter_deprecated /// \ingroup GuiQt /// /// Derived OpenGLContext that adapts a Qt QGLContext @@ -59,7 +55,7 @@ namespace cvfqt { //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -OpenGLContext::OpenGLContext(cvf::OpenGLContextGroup* contextGroup, QGLContext* backingQGLContext) +OpenGLContext_QGLContextAdapter_deprecated::OpenGLContext_QGLContextAdapter_deprecated(cvf::OpenGLContextGroup* contextGroup, QGLContext* backingQGLContext) : cvf::OpenGLContext(contextGroup), m_isCoreOpenGLProfile(false), m_majorVersion(0), @@ -78,7 +74,7 @@ OpenGLContext::OpenGLContext(cvf::OpenGLContextGroup* contextGroup, QGLContext* //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -OpenGLContext::~OpenGLContext() +OpenGLContext_QGLContextAdapter_deprecated::~OpenGLContext_QGLContextAdapter_deprecated() { m_qtGLContext = NULL; } @@ -87,7 +83,7 @@ OpenGLContext::~OpenGLContext() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool OpenGLContext::initializeContext() +bool OpenGLContext_QGLContextAdapter_deprecated::initializeContext() { if (!cvf::OpenGLContext::initializeContext()) { @@ -107,7 +103,7 @@ bool OpenGLContext::initializeContext() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void OpenGLContext::makeCurrent() +void OpenGLContext_QGLContextAdapter_deprecated::makeCurrent() { CVF_ASSERT(m_qtGLContext); m_qtGLContext->makeCurrent(); @@ -117,7 +113,7 @@ void OpenGLContext::makeCurrent() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool OpenGLContext::isCurrent() const +bool OpenGLContext_QGLContextAdapter_deprecated::isCurrent() const { if (m_qtGLContext) { @@ -131,93 +127,50 @@ bool OpenGLContext::isCurrent() const } + + +//================================================================================================== +/// +/// \class cvfqt::CvfBoundQGLContext_deprecated +/// \ingroup GuiQt +/// +/// +/// +//================================================================================================== + //-------------------------------------------------------------------------------------------------- -/// Make an effort to save current OpenGL state. Must be matched by a call to restoreOpenGLState() +/// //-------------------------------------------------------------------------------------------------- -void OpenGLContext::saveOpenGLState(cvf::OpenGLContext* oglContext) +CvfBoundQGLContext_deprecated::CvfBoundQGLContext_deprecated(cvf::OpenGLContextGroup* contextGroup, const QGLFormat & format) +: QGLContext(format) { - CVF_CALLSITE_OPENGL(oglContext); - const cvf::OpenGLCapabilities* oglCaps = oglContext->capabilities(); - - // Only relevant for fixed function - if (!oglCaps->supportsFixedFunction()) - { - return; - } - - CVF_CHECK_OGL(oglContext); - - glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); - CVF_CHECK_OGL(oglContext); - - // For now disable pushing of the vertex array related attributes as it gives a mystical - // crash on Redhat5 under VMWare. Not a big issue, but maybe we can do without this push? - //glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); - CVF_CHECK_OGL(oglContext); - - glPushAttrib(GL_ALL_ATTRIB_BITS); - CVF_CHECK_OGL(oglContext); - - // Note: Only preserves matrix stack for texture unit 0 - if (oglCaps->supportsOpenGL2()) - { - glActiveTexture(GL_TEXTURE0); - } - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - CVF_CHECK_OGL(oglContext); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - CVF_CHECK_OGL(oglContext); - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - CVF_CHECK_OGL(oglContext); + m_cvfGLContext = new OpenGLContext_QGLContextAdapter_deprecated(contextGroup, this); } //-------------------------------------------------------------------------------------------------- -/// Restore OpenGL state that has been saved by saveOpenGLState() +/// //-------------------------------------------------------------------------------------------------- -void OpenGLContext::restoreOpenGLState(cvf::OpenGLContext* oglContext) +CvfBoundQGLContext_deprecated::~CvfBoundQGLContext_deprecated() { - CVF_CALLSITE_OPENGL(oglContext); - const cvf::OpenGLCapabilities* oglCaps = oglContext->capabilities(); - - // Only relevant for fixed function - if (!oglCaps->supportsFixedFunction()) + if (m_cvfGLContext.notNull()) { - return; + // TODO + // Need to resolve the case where the Qt QGLcontext (that we're deriving from) is deleted + // and we are still holding a reference to one or more OpenGLContext objects + // By the time we get here we expect that we're holding the only reference + CVF_ASSERT(m_cvfGLContext->refCount() == 1); + m_cvfGLContext = NULL; } +} - CVF_CHECK_OGL(oglContext); - // Note: Only preserves matrix stack for texture unit 0 - if (oglCaps->supportsOpenGL2()) - { - glActiveTexture(GL_TEXTURE0); - } - glMatrixMode(GL_TEXTURE); - glPopMatrix(); - CVF_CHECK_OGL(oglContext); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - CVF_CHECK_OGL(oglContext); - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - CVF_CHECK_OGL(oglContext); - - glPopAttrib(); - CVF_CHECK_OGL(oglContext); - - // Currently not pushing vertex attribs, so comment out the pop - //glPopClientAttrib(); - - glPopClientAttrib(); - CVF_CHECK_OGL(oglContext); +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::OpenGLContext* CvfBoundQGLContext_deprecated::cvfOpenGLContext() const +{ + return const_cast(m_cvfGLContext.p()); } diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.h b/Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext_deprecated.h similarity index 73% rename from Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.h rename to Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext_deprecated.h index 89dc0bc57b..28ffb7d83d 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLContext.h +++ b/Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext_deprecated.h @@ -39,7 +39,7 @@ #include "cvfOpenGLContext.h" -class QGLContext; +#include namespace cvfqt { @@ -49,20 +49,17 @@ namespace cvfqt { // Derived OpenGLContext that adapts a Qt QGLContext // //================================================================================================== -class OpenGLContext : public cvf::OpenGLContext +class OpenGLContext_QGLContextAdapter_deprecated : public cvf::OpenGLContext { public: - OpenGLContext(cvf::OpenGLContextGroup* contextGroup, QGLContext* backingQGLContext); - virtual ~OpenGLContext(); + OpenGLContext_QGLContextAdapter_deprecated(cvf::OpenGLContextGroup* contextGroup, QGLContext* backingQGLContext); + virtual ~OpenGLContext_QGLContextAdapter_deprecated(); virtual bool initializeContext(); virtual void makeCurrent(); virtual bool isCurrent() const; - static void saveOpenGLState(cvf::OpenGLContext* oglContext); - static void restoreOpenGLState(cvf::OpenGLContext* oglContext); - private: QGLContext* m_qtGLContext; bool m_isCoreOpenGLProfile; // This is a Core OpenGL profile. Implies OpenGL version of 3.2 or more @@ -70,4 +67,23 @@ private: int m_minorVersion; }; + + +//================================================================================================== +// +// Utility class used to piggyback OpenGLContext onto Qt's QGLContext +// +//================================================================================================== +class CvfBoundQGLContext_deprecated : public QGLContext +{ +public: + CvfBoundQGLContext_deprecated(cvf::OpenGLContextGroup* contextGroup, const QGLFormat & format); + virtual ~CvfBoundQGLContext_deprecated(); + + cvf::OpenGLContext* cvfOpenGLContext() const; + +private: + cvf::ref m_cvfGLContext; +}; + } diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLWidget.cpp b/Fwk/VizFwk/LibGuiQt/cvfqtGLWidget_deprecated.cpp similarity index 86% rename from Fwk/VizFwk/LibGuiQt/cvfqtOpenGLWidget.cpp rename to Fwk/VizFwk/LibGuiQt/cvfqtGLWidget_deprecated.cpp index fbfb54f65a..0102185852 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLWidget.cpp +++ b/Fwk/VizFwk/LibGuiQt/cvfqtGLWidget_deprecated.cpp @@ -37,8 +37,8 @@ #include "cvfBase.h" #include "cvfOpenGLContextGroup.h" -#include "cvfqtCvfBoundQGLContext.h" -#include "cvfqtOpenGLWidget.h" +#include "cvfqtCvfBoundQGLContext_deprecated.h" +#include "cvfqtGLWidget_deprecated.h" namespace cvfqt { @@ -46,7 +46,7 @@ namespace cvfqt { //================================================================================================== /// -/// \class cvfqt::OpenGLWidget +/// \class cvfqt::GLWidget_deprecated /// \ingroup GuiQt /// /// @@ -56,8 +56,8 @@ namespace cvfqt { //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -OpenGLWidget::OpenGLWidget(cvf::OpenGLContextGroup* contextGroup, const QGLFormat& format, QWidget* parent, Qt::WindowFlags f) -: QGLWidget(new CvfBoundQGLContext(contextGroup, format), parent, NULL, f) +GLWidget_deprecated::GLWidget_deprecated(cvf::OpenGLContextGroup* contextGroup, const QGLFormat& format, QWidget* parent, Qt::WindowFlags f) +: QGLWidget(new CvfBoundQGLContext_deprecated(contextGroup, format), parent, NULL, f) { // This constructor can only be used with an empty context group! // We're not able to check this up front, but assert that the count is 1 by the time we get here @@ -86,8 +86,8 @@ OpenGLWidget::OpenGLWidget(cvf::OpenGLContextGroup* contextGroup, const QGLForma /// /// If the context is not valid, sharing failed and the newly created widget/context be discarded. //-------------------------------------------------------------------------------------------------- -OpenGLWidget::OpenGLWidget(OpenGLWidget* shareWidget, QWidget* parent , Qt::WindowFlags f) -: QGLWidget(new CvfBoundQGLContext(shareWidget->cvfOpenGLContext()->group(), shareWidget->format()), parent, shareWidget, f) +GLWidget_deprecated::GLWidget_deprecated(GLWidget_deprecated* shareWidget, QWidget* parent , Qt::WindowFlags f) +: QGLWidget(new CvfBoundQGLContext_deprecated(shareWidget->cvfOpenGLContext()->group(), shareWidget->format()), parent, shareWidget, f) { CVF_ASSERT(shareWidget); cvf::ref shareContext = shareWidget->cvfOpenGLContext(); @@ -120,10 +120,10 @@ OpenGLWidget::OpenGLWidget(OpenGLWidget* shareWidget, QWidget* parent , Qt::Wind //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::OpenGLContext* OpenGLWidget::cvfOpenGLContext() const +cvf::OpenGLContext* GLWidget_deprecated::cvfOpenGLContext() const { const QGLContext* qglContext = context(); - const CvfBoundQGLContext* contextBinding = dynamic_cast(qglContext); + const CvfBoundQGLContext_deprecated* contextBinding = dynamic_cast(qglContext); CVF_ASSERT(contextBinding); return contextBinding->cvfOpenGLContext(); @@ -133,7 +133,7 @@ cvf::OpenGLContext* OpenGLWidget::cvfOpenGLContext() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void OpenGLWidget::cvfShutdownOpenGLContext() +void GLWidget_deprecated::cvfShutdownOpenGLContext() { // It should be safe to call shutdown multiple times so this call should // amount to a no-op if the user has already shut down the context diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLWidget.h b/Fwk/VizFwk/LibGuiQt/cvfqtGLWidget_deprecated.h similarity index 87% rename from Fwk/VizFwk/LibGuiQt/cvfqtOpenGLWidget.h rename to Fwk/VizFwk/LibGuiQt/cvfqtGLWidget_deprecated.h index c598f9997d..41ba933ccf 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtOpenGLWidget.h +++ b/Fwk/VizFwk/LibGuiQt/cvfqtGLWidget_deprecated.h @@ -37,7 +37,7 @@ #pragma once -#include +#include namespace cvf { @@ -53,11 +53,11 @@ namespace cvfqt { // Derived QGLWidget // //================================================================================================== -class OpenGLWidget : public QGLWidget +class GLWidget_deprecated : public QGLWidget { public: - OpenGLWidget(cvf::OpenGLContextGroup* contextGroup, const QGLFormat& format, QWidget* parent, Qt::WindowFlags f = 0); - OpenGLWidget(OpenGLWidget* shareWidget, QWidget* parent , Qt::WindowFlags f = 0); + GLWidget_deprecated(cvf::OpenGLContextGroup* contextGroup, const QGLFormat& format, QWidget* parent, Qt::WindowFlags f = 0); + GLWidget_deprecated(GLWidget_deprecated* shareWidget, QWidget* parent , Qt::WindowFlags f = 0); cvf::OpenGLContext* cvfOpenGLContext() const; void cvfShutdownOpenGLContext(); diff --git a/Fwk/VizFwk/LibRender/CMakeLists.txt b/Fwk/VizFwk/LibRender/CMakeLists.txt index 3b0e23d5b0..c0f342b58a 100644 --- a/Fwk/VizFwk/LibRender/CMakeLists.txt +++ b/Fwk/VizFwk/LibRender/CMakeLists.txt @@ -47,6 +47,7 @@ cvfOpenGLContext.h cvfOpenGLContextGroup.h cvfOpenGLResourceManager.h cvfOpenGLTypes.h +cvfOpenGLUtils.h cvfOverlayAxisCross.h cvfOverlayScalarMapperLegend.h cvfOverlayColorLegend.h @@ -123,6 +124,7 @@ cvfOpenGLCapabilities.cpp cvfOpenGLContext.cpp cvfOpenGLContextGroup.cpp cvfOpenGLResourceManager.cpp +cvfOpenGLUtils.cpp cvfOpenGL.cpp cvfOverlayAxisCross.cpp cvfOverlayScalarMapperLegend.cpp diff --git a/Fwk/VizFwk/LibRender/cvfLibRender.h b/Fwk/VizFwk/LibRender/cvfLibRender.h index c24391290b..1821a4fcd6 100644 --- a/Fwk/VizFwk/LibRender/cvfLibRender.h +++ b/Fwk/VizFwk/LibRender/cvfLibRender.h @@ -61,6 +61,7 @@ #include "cvfOpenGLContextGroup.h" #include "cvfOpenGLResourceManager.h" #include "cvfOpenGLTypes.h" +#include "cvfOpenGLUtils.h" #include "cvfOverlayAxisCross.h" #include "cvfOverlayColorLegend.h" #include "cvfOverlayImage.h" diff --git a/Fwk/VizFwk/LibRender/cvfOpenGLUtils.cpp b/Fwk/VizFwk/LibRender/cvfOpenGLUtils.cpp new file mode 100644 index 0000000000..70bb4440a8 --- /dev/null +++ b/Fwk/VizFwk/LibRender/cvfOpenGLUtils.cpp @@ -0,0 +1,152 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library 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 General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library 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 2.1 of the License, or +// (at your option) any later version. +// +// This library 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 at <> +// for more details. +// +//################################################################################################## + + +#include "cvfBase.h" +#include "cvfOpenGLUtils.h" +#include "cvfOpenGL.h" +#include "cvfOpenGLContext.h" +#include "cvfOpenGLCapabilities.h" + +namespace cvf { + + + +//================================================================================================== +/// +/// \class cvf::OpenGLUtils +/// \ingroup Render +/// +/// Static class providing OpenGL helpers +/// +//================================================================================================== + +//-------------------------------------------------------------------------------------------------- +/// Store the current OpenGL context settings by using OpenGL's built in push methods. +/// +/// Note: This call MUST be matched with a corresponding popOpenGLState() call. +//-------------------------------------------------------------------------------------------------- +void OpenGLUtils::pushOpenGLState(OpenGLContext* oglContext) +{ + CVF_CALLSITE_OPENGL(oglContext); + const cvf::OpenGLCapabilities* oglCaps = oglContext->capabilities(); + + // Only relevant for fixed function + if (!oglCaps->supportsFixedFunction()) + { + return; + } + + CVF_CHECK_OGL(oglContext); + + glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); + CVF_CHECK_OGL(oglContext); + + // For now disable pushing of the vertex array related attributes as it gives a mystical + // crash on Redhat5 under VMWare. Not a big issue, but maybe we can do without this push? + //glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); + CVF_CHECK_OGL(oglContext); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + CVF_CHECK_OGL(oglContext); + + // Note: Only preserves matrix stack for texture unit 0 + if (oglCaps->supportsOpenGL2()) + { + glActiveTexture(GL_TEXTURE0); + } + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + CVF_CHECK_OGL(oglContext); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + CVF_CHECK_OGL(oglContext); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + CVF_CHECK_OGL(oglContext); +} + + +//-------------------------------------------------------------------------------------------------- +/// Set back the stored OpenGL context settings by using OpenGL's built in pop methods. +/// +/// Note: This call MUST be matched with a corresponding pushOpenGLState() call. +//-------------------------------------------------------------------------------------------------- +void OpenGLUtils::popOpenGLState(OpenGLContext* oglContext) +{ + CVF_CALLSITE_OPENGL(oglContext); + const cvf::OpenGLCapabilities* oglCaps = oglContext->capabilities(); + + // Only relevant for fixed function + if (!oglCaps->supportsFixedFunction()) + { + return; + } + + CVF_CHECK_OGL(oglContext); + + // Note: Only preserves matrix stack for texture unit 0 + if (oglCaps->supportsOpenGL2()) + { + glActiveTexture(GL_TEXTURE0); + } + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + CVF_CHECK_OGL(oglContext); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + CVF_CHECK_OGL(oglContext); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + CVF_CHECK_OGL(oglContext); + + glPopAttrib(); + CVF_CHECK_OGL(oglContext); + + // Currently not pushing vertex attribs, so comment out the pop + //glPopClientAttrib(); + + glPopClientAttrib(); + CVF_CHECK_OGL(oglContext); +} + + +} // namespace cvf + diff --git a/Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext.h b/Fwk/VizFwk/LibRender/cvfOpenGLUtils.h similarity index 81% rename from Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext.h rename to Fwk/VizFwk/LibRender/cvfOpenGLUtils.h index 5160f372fc..3297b18edd 100644 --- a/Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext.h +++ b/Fwk/VizFwk/LibRender/cvfOpenGLUtils.h @@ -37,28 +37,22 @@ #pragma once -#include "cvfOpenGLContext.h" +namespace cvf { -#include - -namespace cvfqt { +class OpenGLContext; //================================================================================================== // -// Utility class used to piggyback OpenGLContext onto Qt's QGLContext +// // //================================================================================================== -class CvfBoundQGLContext : public QGLContext +class OpenGLUtils { public: - CvfBoundQGLContext(cvf::OpenGLContextGroup* contextGroup, const QGLFormat & format); - virtual ~CvfBoundQGLContext(); - - cvf::OpenGLContext* cvfOpenGLContext() const; - -private: - cvf::ref m_cvfGLContext; + static void pushOpenGLState(OpenGLContext* oglContext); + static void popOpenGLState(OpenGLContext* oglContext); }; } + diff --git a/Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.cpp b/Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.cpp index 81dbbaf395..9cc8718c14 100644 --- a/Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.cpp +++ b/Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.cpp @@ -42,8 +42,6 @@ #include "QMWidget.h" -#include "cvfqtOpenGLContext.h" - #include using cvf::ref; @@ -54,7 +52,7 @@ using cvf::ref; /// //-------------------------------------------------------------------------------------------------- QMWidget::QMWidget(cvf::OpenGLContextGroup* contextGroup, QWidget* parent) -: cvfqt::OpenGLWidget(contextGroup, QGLFormat(), parent) +: cvfqt::GLWidget_deprecated(contextGroup, QGLFormat(), parent) { m_camera = new cvf::Camera; @@ -130,14 +128,14 @@ void QMWidget::paintEvent(QPaintEvent* /*event*/) painter.beginNativePainting(); - cvfqt::OpenGLContext::saveOpenGLState(currentOglContext); + cvf::OpenGLUtils::pushOpenGLState(currentOglContext); if (m_renderSequence.notNull()) { m_renderSequence->render(currentOglContext); } - cvfqt::OpenGLContext::restoreOpenGLState(currentOglContext); + cvf::OpenGLUtils::popOpenGLState(currentOglContext); painter.endNativePainting(); } diff --git a/Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.h b/Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.h index 0a789c9eb7..ab9663a52e 100644 --- a/Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.h +++ b/Fwk/VizFwk/TestApps/Qt/QtMinimal/QMWidget.h @@ -44,7 +44,7 @@ #include "cvfScene.h" #include "cvfOpenGLContextGroup.h" -#include "cvfqtOpenGLWidget.h" +#include "cvfqtGLWidget_deprecated.h" @@ -53,7 +53,7 @@ // // //================================================================================================== -class QMWidget : public cvfqt::OpenGLWidget +class QMWidget : public cvfqt::GLWidget_deprecated { Q_OBJECT diff --git a/Fwk/VizFwk/TestApps/Qt/QtMultiView/QMVWidget.cpp b/Fwk/VizFwk/TestApps/Qt/QtMultiView/QMVWidget.cpp index 586d64f352..50a74d8c37 100644 --- a/Fwk/VizFwk/TestApps/Qt/QtMultiView/QMVWidget.cpp +++ b/Fwk/VizFwk/TestApps/Qt/QtMultiView/QMVWidget.cpp @@ -42,8 +42,6 @@ #include "QMVWidget.h" -#include "cvfqtOpenGLContext.h" - #include using cvf::ref; @@ -54,7 +52,7 @@ using cvf::ref; /// //-------------------------------------------------------------------------------------------------- QMVWidget::QMVWidget(cvf::OpenGLContextGroup* contextGroup, const QGLFormat& format, QWidget* parent) -: cvfqt::OpenGLWidget(contextGroup, format, parent) +: cvfqt::GLWidget_deprecated(contextGroup, format, parent) { m_trackball = new cvf::ManipulatorTrackball; } @@ -64,7 +62,7 @@ QMVWidget::QMVWidget(cvf::OpenGLContextGroup* contextGroup, const QGLFormat& for /// //-------------------------------------------------------------------------------------------------- QMVWidget::QMVWidget(QMVWidget* shareWidget, QWidget* parent) -: cvfqt::OpenGLWidget(shareWidget, parent) +: cvfqt::GLWidget_deprecated(shareWidget, parent) { m_trackball = new cvf::ManipulatorTrackball; } @@ -141,7 +139,7 @@ void QMVWidget::paintGL() CVF_ASSERT(currentOglContext); CVF_CHECK_OGL(currentOglContext); - cvfqt::OpenGLContext::saveOpenGLState(currentOglContext); + cvf::OpenGLUtils::pushOpenGLState(currentOglContext); if (m_renderSequence.notNull()) { @@ -153,7 +151,7 @@ void QMVWidget::paintGL() glClear(GL_COLOR_BUFFER_BIT); } - cvfqt::OpenGLContext::restoreOpenGLState(currentOglContext); + cvf::OpenGLUtils::popOpenGLState(currentOglContext); } diff --git a/Fwk/VizFwk/TestApps/Qt/QtMultiView/QMVWidget.h b/Fwk/VizFwk/TestApps/Qt/QtMultiView/QMVWidget.h index f9d1d0812c..9eaf9dcc15 100644 --- a/Fwk/VizFwk/TestApps/Qt/QtMultiView/QMVWidget.h +++ b/Fwk/VizFwk/TestApps/Qt/QtMultiView/QMVWidget.h @@ -40,7 +40,7 @@ #include "cvfBase.h" #include "cvfRenderSequence.h" #include "cvfManipulatorTrackball.h" -#include "cvfqtOpenGLWidget.h" +#include "cvfqtGLWidget_deprecated.h" //================================================================================================== @@ -48,7 +48,7 @@ // // //================================================================================================== -class QMVWidget : public cvfqt::OpenGLWidget +class QMVWidget : public cvfqt::GLWidget_deprecated { Q_OBJECT diff --git a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRSnippetWidget.cpp b/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRSnippetWidget.cpp index d8352af623..8044566413 100644 --- a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRSnippetWidget.cpp +++ b/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRSnippetWidget.cpp @@ -40,7 +40,6 @@ #include "QSRTranslateEvent.h" #include "cvfqtPerformanceInfoHud.h" -#include "cvfqtOpenGLContext.h" #include @@ -54,7 +53,7 @@ using cvfu::TestSnippet; /// //-------------------------------------------------------------------------------------------------- QSRSnippetWidget::QSRSnippetWidget(TestSnippet* snippet, cvf::OpenGLContextGroup* contextGroup, const QGLFormat& format, QWidget* parent) -: cvfqt::OpenGLWidget(contextGroup, format, parent), +: cvfqt::GLWidget_deprecated(contextGroup, format, parent), m_drawHUD(false), m_lastSetRenderMode(DrawableGeo::VERTEX_ARRAY), m_enableMultisampleWhenDrawing(false) @@ -595,7 +594,7 @@ void QSRSnippetWidget::paintEvent(QPaintEvent* /*event*/) painter.beginNativePainting(); CVF_CHECK_OGL(currentOglContext); - cvfqt::OpenGLContext::saveOpenGLState(currentOglContext); + cvf::OpenGLUtils::pushOpenGLState(currentOglContext); CVF_CHECK_OGL(currentOglContext); if (m_enableMultisampleWhenDrawing) @@ -612,7 +611,7 @@ void QSRSnippetWidget::paintEvent(QPaintEvent* /*event*/) glDisable(GL_MULTISAMPLE); } - cvfqt::OpenGLContext::restoreOpenGLState(currentOglContext); + cvf::OpenGLUtils::popOpenGLState(currentOglContext); CVF_CHECK_OGL(currentOglContext); if (postEventAction == cvfu::REDRAW) diff --git a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRSnippetWidget.h b/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRSnippetWidget.h index 9a74e7f514..3ed9b7b3f5 100644 --- a/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRSnippetWidget.h +++ b/Fwk/VizFwk/TestApps/Qt/QtSnippetRunner/QSRSnippetWidget.h @@ -45,7 +45,7 @@ #include "cvfuTestSnippet.h" -#include "cvfqtOpenGLWidget.h" +#include "cvfqtGLWidget_deprecated.h" class QTimer; @@ -55,7 +55,7 @@ class QTimer; // // //================================================================================================== -class QSRSnippetWidget : public cvfqt::OpenGLWidget +class QSRSnippetWidget : public cvfqt::GLWidget_deprecated { Q_OBJECT