Skip to content

Commit

Permalink
Add support in VizFwk for using QOpenGLWidget derived view widget (#1…
Browse files Browse the repository at this point in the history
…1091)

* 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

* Marked existing QtMinimal and QtMultiView as deprecated

* Additional deprecated renaming

* Added missing type

* Added missing include

* Fixes to get snippets up and running before introducing new OpenGL widgets

* Added class for OpenGLInfo

* Refactored cvf::OpenGLContext and cvf::OpenGLContextGroup, and added first cut impl of cvfqt::GLWidget and cvfqt::OpenGLWidget

* Removed unused TriggerTBBCopy.txt

* Initial support for compilation on Qt6

* Added QtMinimal and QtMinimal_GLWidget

* Refactored SnippetRunner to handle utilize cvfqt::OpenGLWidget

* Removed unused code

* Fixes and workarounds from compiling on linux

* Fixes by clang-format (#11056)

Co-authored-by: sigurdp <[email protected]>

* Added QTMultiView test app based on cvfqt::OpenGLWidget

* Removed includes of QOpenGLFunctions

* Modifications for compile with Qt6

* Added test bench for cvfqt::OpenGLWidget

* Minor fixes

* Force to use Qt5

* Fixes by cmake-format

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: sigurdp <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent 576f15d commit 10a579f
Show file tree
Hide file tree
Showing 105 changed files with 7,008 additions and 994 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,14 @@ if(CMAKE_COMPILER_IS_GNUCC)

endif()

# !!! For now, we force Qt to version 5
message(STATUS "Forcing setting of CEE_USE_QT5 to ON")
set(CEE_USE_QT5
ON
CACHE BOOL "Force usage of Qt5" FORCE
)
message(STATUS "CEE_USE_QT5=${CEE_USE_QT5}")

add_subdirectory(${VIZ_MODULES_FOLDER_NAME}/LibCore)
add_subdirectory(${VIZ_MODULES_FOLDER_NAME}/LibGeometry)
add_subdirectory(${VIZ_MODULES_FOLDER_NAME}/LibRender)
Expand Down
39 changes: 27 additions & 12 deletions Fwk/AppFwk/cafViewer/cafOpenGLWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "cafOpenGLWidget.h"
#include "cvfBase.h"
#include "cvfOpenGLContextGroup.h"
#include "cvfqtCvfBoundQGLContext.h"
#include "cvfqtCvfBoundQGLContext_deprecated.h"

namespace caf
{
Expand All @@ -58,36 +58,40 @@ 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() )
{
cvf::ref<cvf::OpenGLContext> myContext = cvfOpenGLContext();
if ( myContext.notNull() )
{
cvf::OpenGLContextGroup* myOwnerContextGroup = myContext->group();

if ( shareWidget )
{
// We need to check if we actually got a context that shares resources with shareWidget.
cvf::ref<cvf::OpenGLContext> shareContext = shareWidget->cvfOpenGLContext();
CVF_ASSERT( myOwnerContextGroup == shareContext->group() );

if ( isSharing() )
{
CVF_ASSERT( myContext->group() == shareContext->group() );
myContext->initializeContext();
makeCurrent();
myOwnerContextGroup->initializeContextGroup( myContext.p() );
}
else
{
// If we didn't, we need to remove the newly created context from the group it has been added to
// since the construction process above has already optimistically added the new context to the
// existing group. In this case, the newly context is basically defunct so we just shut it down
// (which will also remove it from the group)
myContext->shutdownContext();
myOwnerContextGroup->contextAboutToBeShutdown( myContext.p() );
CVF_ASSERT( myContext->group() == nullptr );
}
}
else
{
myContext->initializeContext();
makeCurrent();
contextGroup->initializeContextGroup( myContext.p() );
}
}
}
Expand All @@ -106,7 +110,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 )
Expand All @@ -118,13 +122,16 @@ OpenGLWidget::OpenGLWidget( OpenGLWidget* shareWidget, QWidget* parent, Qt::Wind
cvf::ref<cvf::OpenGLContext> myContext = cvfOpenGLContext();
if ( myContext.notNull() )
{
cvf::OpenGLContextGroup* myOwnerContextGroup = myContext->group();

// We need to check if we actually got a context that shares resources with shareWidget.
if ( isSharing() )
{
if ( isValid() )
{
CVF_ASSERT( myContext->group() == shareContext->group() );
myContext->initializeContext();
makeCurrent();
myOwnerContextGroup->initializeContextGroup( myContext.p() );
}
}
else
Expand All @@ -133,7 +140,7 @@ OpenGLWidget::OpenGLWidget( OpenGLWidget* shareWidget, QWidget* parent, Qt::Wind
// the construction process above has already optimistically added the new context to the existing group.
// In this case, the newly context is basically defunct so we just shut it down (which will also remove it
// from the group)
myContext->shutdownContext();
myOwnerContextGroup->contextAboutToBeShutdown( myContext.p() );
CVF_ASSERT( myContext->group() == nullptr );
}
}
Expand All @@ -144,8 +151,9 @@ OpenGLWidget::OpenGLWidget( OpenGLWidget* shareWidget, QWidget* parent, Qt::Wind
//--------------------------------------------------------------------------------------------------
cvf::OpenGLContext* OpenGLWidget::cvfOpenGLContext() const
{
const QGLContext* qglContext = context();
const cvfqt::CvfBoundQGLContext* contextBinding = dynamic_cast<const cvfqt::CvfBoundQGLContext*>( qglContext );
const QGLContext* qglContext = context();
const cvfqt::CvfBoundQGLContext_deprecated* contextBinding =
dynamic_cast<const cvfqt::CvfBoundQGLContext_deprecated*>( qglContext );
CVF_ASSERT( contextBinding );

return contextBinding->cvfOpenGLContext();
Expand All @@ -161,7 +169,14 @@ void OpenGLWidget::cvfShutdownOpenGLContext()
cvf::ref<cvf::OpenGLContext> myContext = cvfOpenGLContext();
if ( myContext.notNull() )
{
myContext->shutdownContext();
cvf::OpenGLContextGroup* myOwnerContextGroup = myContext->group();

// If shutdown has already been called, the context is no longer member of any group
if ( myOwnerContextGroup )
{
makeCurrent();
myOwnerContextGroup->contextAboutToBeShutdown( myContext.p() );
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions Fwk/AppFwk/cafViewer/cafViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -69,7 +70,6 @@
#include "cvfUniform.h"
#include "cvfUniformSet.h"

#include "cvfqtOpenGLContext.h"
#include "cvfqtPerformanceInfoHud.h"
#include "cvfqtUtils.h"

Expand Down Expand Up @@ -850,7 +850,7 @@ void caf::Viewer::paintEvent( QPaintEvent* event )

if ( isShadersSupported() )
{
cvfqt::OpenGLContext::saveOpenGLState( myOglContext.p() );
cvf::OpenGLUtils::pushOpenGLState( myOglContext.p() );
}

optimizeClippingPlanes();
Expand Down Expand Up @@ -880,7 +880,7 @@ void caf::Viewer::paintEvent( QPaintEvent* event )

if ( isShadersSupported() )
{
cvfqt::OpenGLContext::restoreOpenGLState( myOglContext.p() );
cvf::OpenGLUtils::popOpenGLState( myOglContext.p() );
}

painter.endNativePainting();
Expand Down
55 changes: 37 additions & 18 deletions Fwk/VizFwk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ cmake_minimum_required(VERSION 3.15)
project(VizFramework)


if (CEE_CEEVIZ_ROOT)
message(STATUS "CEE_CEEVIZ_ROOT: ${CEE_CEEVIZ_ROOT}")
else()
set(CEE_CEEVIZ_ROOT ${PROJECT_SOURCE_DIR})
message(STATUS "Setting CEE_CEEVIZ_ROOT to ${CEE_CEEVIZ_ROOT}")
endif()

# Determine if we're being run stand-alone or invoked from some other project
set(CEE_STAND_ALONE ON)
if (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
Expand All @@ -20,6 +27,8 @@ if (CEE_STAND_ALONE)
endif()

include(CMake/Utils/ceeDetermineCompilerFlags.cmake)

set(CMAKE_CXX_STANDARD 17)
endif()


Expand All @@ -44,36 +53,46 @@ add_subdirectory(ThirdParty/FreeType)
add_subdirectory(LibUtilities)



option(CEE_BUILD_GUI_QT "Build GUI library for Qt" ON)
if (CEE_BUILD_GUI_QT)
option(CEE_USE_QT5 "Use Qt5" ON)
option(CEE_USE_QT6 "Use Qt6" OFF)
option(CEE_USE_QT5 "Use Qt5" OFF)
add_subdirectory(LibGuiQt)
endif()


if (CEE_STAND_ALONE)

option(CEE_BUILD_UNIT_TESTS "Build unit tests" ON)
if (CEE_BUILD_UNIT_TESTS)
add_subdirectory(Tests)
endif()
option(CEE_BUILD_TEST_APPS "Build test apps" ON)
endif()

if (CEE_BUILD_UNIT_TESTS OR CEE_BUILD_TEST_APPS)
# Add CeeViz's root source dir as a preprocessor directive so unit tests and test apps can determine where to find the resources they want.
add_definitions(-DCVF_CEEVIZ_ROOT_SOURCE_DIR="${CEE_CEEVIZ_ROOT}")
endif()

option(CEE_BUILD_TEST_APPS "Build test apps" ON)
if (CEE_BUILD_TEST_APPS)
# For now, build the snippet libs here
add_subdirectory(Tests/SnippetsBasis)

if (CEE_BUILD_GUI_QT)
add_subdirectory(TestApps/Qt/QtMinimal)
add_subdirectory(TestApps/Qt/QtMultiView)
add_subdirectory(TestApps/Qt/QtSnippetRunner)
endif()
if (CEE_BUILD_UNIT_TESTS)
add_subdirectory(Tests)
endif()

if (WIN32)
add_subdirectory(TestApps/Win32/Win32SnippetRunner)
if (CEE_BUILD_TEST_APPS)
# For now, build the snippet libs here
add_subdirectory(Tests/SnippetsBasis)

if (CEE_BUILD_GUI_QT)
add_subdirectory(TestApps/Qt/QtMinimal)
add_subdirectory(TestApps/Qt/QtMultiView)
add_subdirectory(TestApps/Qt/QtTestBenchOpenGLWidget)
add_subdirectory(TestApps/Qt/QtSnippetRunner)

if (CEE_USE_QT5)
add_subdirectory(TestApps/Qt/QtMinimal_GLWidget)
add_subdirectory(TestApps/Qt/QtMinimal_deprecated)
add_subdirectory(TestApps/Qt/QtMultiView_deprecated)
endif()
endif()

if (WIN32)
add_subdirectory(TestApps/Win32/Win32SnippetRunner)
endif()
endif()
6 changes: 6 additions & 0 deletions Fwk/VizFwk/LibCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,11 @@ target_include_directories(${PROJECT_NAME}
${CMAKE_CURRENT_SOURCE_DIR}
)

if (UNIX AND NOT APPLE)
# Our core library has dependencies on librt and libpthread for timers and mutex.
target_link_libraries(${PROJECT_NAME} -lrt -lpthread)
endif()


set(PROJECT_FILES ${CEE_HEADER_FILES} ${CEE_SOURCE_FILES})
source_group("" FILES ${PROJECT_FILES})
18 changes: 17 additions & 1 deletion Fwk/VizFwk/LibCore/cvfBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
// Makes it easier to check on the current GCC version
#ifdef __GNUC__
// 40302 means version 4.3.2.
# define CVF_GCC_VER (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
#define CVF_GCC_VER (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
#endif

// Helper macro to disable (ignore) compiler warnings on GCC
Expand All @@ -80,6 +80,15 @@
#define CVF_GCC_DIAGNOSTIC_IGNORE(OPTION_STRING)
#endif

// Helper macros for push/pop of GCC diagnostics, available from GCC 4.6.x
#if defined(__GNUC__) && (CVF_GCC_VER >= 40600)
#define CVF_GCC_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
#define CVF_GCC_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#else
#define CVF_GCC_DIAGNOSTIC_PUSH
#define CVF_GCC_DIAGNOSTIC_POP
#endif


#if defined(CVF_LINUX) || defined(CVF_IOS) || defined(CVF_OSX) || defined(CVF_ANDROID)
// Used by int64_t on *nix below
Expand Down Expand Up @@ -123,6 +132,13 @@ typedef __int64 int64;
typedef int64_t int64;
#endif

// 64bit unsigned integer support via the int64 type
#ifdef WIN32
typedef unsigned __int64 uint64;
#elif defined(CVF_LINUX) || defined(CVF_IOS) || defined(CVF_OSX) || defined(CVF_ANDROID)
typedef uint64_t uint64;
#endif

}

#include "cvfConfigCore.h"
Expand Down
1 change: 1 addition & 0 deletions Fwk/VizFwk/LibCore/cvfLibCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "cvfFlags.h"
#include "cvfFunctorRange.h"
#include "cvfLogger.h"
#include "cvfLogManager.h"
#include "cvfMath.h"
#include "cvfMatrix4.h"
#include "cvfObject.h"
Expand Down
5 changes: 5 additions & 0 deletions Fwk/VizFwk/LibGeometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ endif()
# Use our strict compile flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEE_STRICT_CXX_FLAGS}")

# For now, disable warning about unknown pragmas locally here (due to usage of OpenMP)
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
endif()


set(CEE_HEADER_FILES
cvfArrowGenerator.h
Expand Down
36 changes: 27 additions & 9 deletions Fwk/VizFwk/LibGuiQt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,53 @@ endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CEE_BASE_CXX_FLAGS}")

if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long")
# Due to usage of OpenMP, disable warning about unknown pragmas
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-long-long -Wno-unknown-pragmas")
endif()

find_package(OpenGL)

find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets OpenGL)
set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::Widgets Qt5::OpenGL)

message(STATUS "In LibGuiQt, CEE_USE_QT6=${CEE_USE_QT6}")
message(STATUS "In LibGuiQt, CEE_USE_QT5=${CEE_USE_QT5}")
if (CEE_USE_QT6)
find_package(Qt6 COMPONENTS REQUIRED Core Gui Widgets OpenGLWidgets)
set(QT_LIBRARIES Qt6::Core Qt6::Gui Qt6::Widgets Qt6::OpenGLWidgets )
elseif (CEE_USE_QT5)
find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets OpenGL)
set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::Widgets Qt5::OpenGL)
else()
message(FATAL_ERROR "No supported Qt version selected for build")
endif()




set(CEE_HEADER_FILES
cvfqtBasicAboutDialog.h
cvfqtCvfBoundQGLContext.h
cvfqtMouseState.h
cvfqtOpenGLContext.h
cvfqtOpenGLWidget.h
cvfqtPerformanceInfoHud.h
cvfqtUtils.h
)

set(CEE_SOURCE_FILES
cvfqtBasicAboutDialog.cpp
cvfqtCvfBoundQGLContext.cpp
cvfqtMouseState.cpp
cvfqtOpenGLContext.cpp
cvfqtOpenGLWidget.cpp
cvfqtPerformanceInfoHud.cpp
cvfqtUtils.cpp
)

if (CEE_USE_QT5)
set(CEE_HEADER_FILES ${CEE_HEADER_FILES} cvfqtGLWidget.h)
set(CEE_SOURCE_FILES ${CEE_SOURCE_FILES} cvfqtGLWidget.cpp)
set(CEE_HEADER_FILES ${CEE_HEADER_FILES} cvfqtCvfBoundQGLContext_deprecated.h)
set(CEE_SOURCE_FILES ${CEE_SOURCE_FILES} cvfqtCvfBoundQGLContext_deprecated.cpp)
set(CEE_HEADER_FILES ${CEE_HEADER_FILES} cvfqtGLWidget_deprecated.h)
set(CEE_SOURCE_FILES ${CEE_SOURCE_FILES} cvfqtGLWidget_deprecated.cpp)
endif()

add_library(${PROJECT_NAME} ${CEE_HEADER_FILES} ${CEE_SOURCE_FILES})

target_include_directories(${PROJECT_NAME}
Expand All @@ -58,6 +77,5 @@ 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 (cvfqtOpenGLContext.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
set_source_files_properties (cvfqtGLWidget_deprecated.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
endif()
Loading

0 comments on commit 10a579f

Please sign in to comment.