Skip to content

Commit

Permalink
Refactored cvf::OpenGLContext and cvf::OpenGLContextGroup, and added …
Browse files Browse the repository at this point in the history
…first cut impl of cvfqt::GLWidget and cvfqt::OpenGLWidget
  • Loading branch information
sigurdp committed Jan 12, 2024
1 parent 4bd1be3 commit 9b553d6
Show file tree
Hide file tree
Showing 19 changed files with 1,192 additions and 139 deletions.
28 changes: 21 additions & 7 deletions Fwk/AppFwk/cafViewer/cafOpenGLWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,33 @@ OpenGLWidget::OpenGLWidget( cvf::OpenGLContextGroup* contextGroup,
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 Down Expand Up @@ -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 Down Expand Up @@ -161,7 +168,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: 5 additions & 1 deletion Fwk/VizFwk/LibGuiQt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::Widgets Qt5::OpenGL)

set(CEE_HEADER_FILES
cvfqtBasicAboutDialog.h
cvfqtGLWidget.h
cvfqtMouseState.h
cvfqtOpenGLWidget.h
cvfqtPerformanceInfoHud.h
cvfqtUtils.h
cvfqtCvfBoundQGLContext_deprecated.h
Expand All @@ -29,13 +31,16 @@ cvfqtGLWidget_deprecated.h

set(CEE_SOURCE_FILES
cvfqtBasicAboutDialog.cpp
cvfqtGLWidget.cpp
cvfqtMouseState.cpp
cvfqtOpenGLWidget.cpp
cvfqtPerformanceInfoHud.cpp
cvfqtUtils.cpp
cvfqtCvfBoundQGLContext_deprecated.cpp
cvfqtGLWidget_deprecated.cpp
)


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

target_include_directories(${PROJECT_NAME}
Expand All @@ -57,5 +62,4 @@ source_group("" FILES ${PROJECT_FILES})
# Unity Build
if (CMAKE_UNITY_BUILD)
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()
31 changes: 1 addition & 30 deletions Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext_deprecated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,9 @@ namespace cvfqt {
///
//--------------------------------------------------------------------------------------------------
OpenGLContext_QGLContextAdapter_deprecated::OpenGLContext_QGLContextAdapter_deprecated(cvf::OpenGLContextGroup* contextGroup, QGLContext* backingQGLContext)
: cvf::OpenGLContext(contextGroup),
m_isCoreOpenGLProfile(false),
m_majorVersion(0),
m_minorVersion(0)
: cvf::OpenGLContext(contextGroup)
{
m_qtGLContext = backingQGLContext;

CVF_ASSERT(m_qtGLContext);
QGLFormat glFormat = m_qtGLContext->format();
m_majorVersion = glFormat.majorVersion();
m_minorVersion = glFormat.minorVersion();
m_isCoreOpenGLProfile = (glFormat.profile() == QGLFormat::CoreProfile) ? true : false;
}


Expand All @@ -80,26 +71,6 @@ OpenGLContext_QGLContextAdapter_deprecated::~OpenGLContext_QGLContextAdapter_dep
}


//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool OpenGLContext_QGLContextAdapter_deprecated::initializeContext()
{
if (!cvf::OpenGLContext::initializeContext())
{
return false;
}

// Possibly override setting for fixed function support
if (m_isCoreOpenGLProfile)
{
group()->capabilities()->setSupportsFixedFunction(false);
}

return true;
}


//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
5 changes: 0 additions & 5 deletions Fwk/VizFwk/LibGuiQt/cvfqtCvfBoundQGLContext_deprecated.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,11 @@ class OpenGLContext_QGLContextAdapter_deprecated : public cvf::OpenGLContext
OpenGLContext_QGLContextAdapter_deprecated(cvf::OpenGLContextGroup* contextGroup, QGLContext* backingQGLContext);
virtual ~OpenGLContext_QGLContextAdapter_deprecated();

virtual bool initializeContext();

virtual void makeCurrent();
virtual bool isCurrent() const;

private:
QGLContext* m_qtGLContext;
bool m_isCoreOpenGLProfile; // This is a Core OpenGL profile. Implies OpenGL version of 3.2 or more
int m_majorVersion; // OpenGL version as reported by Qt
int m_minorVersion;
};


Expand Down
Loading

0 comments on commit 9b553d6

Please sign in to comment.