From 20acbba03655b65f79e4b03694ee0a790d091923 Mon Sep 17 00:00:00 2001 From: clach Date: Fri, 22 Nov 2024 13:44:44 -0800 Subject: [PATCH] [glf] Portion of Autodesk PR #3391. Relevant PR description: Autodesk: Enable experimental Vulkan testing on macOS - Create a null GL context when X11 isn't available, so tests can still run (but without HgiGL support). Pixar note: The original PR had both the X11 GL context and the null GL context in new separate files, but I put them both in testGLContext.cpp to simplify the build scripts and hide the details. See #3391 (Internal change: 2349272) --- cmake/defaults/Packages.cmake | 1 + pxr/imaging/glf/CMakeLists.txt | 4 +- pxr/imaging/glf/testGLContext.cpp | 76 ++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/cmake/defaults/Packages.cmake b/cmake/defaults/Packages.cmake index 8ac373aa8f..5746dfc912 100644 --- a/cmake/defaults/Packages.cmake +++ b/cmake/defaults/Packages.cmake @@ -266,6 +266,7 @@ if (PXR_BUILD_IMAGING) # --X11 if (CMAKE_SYSTEM_NAME STREQUAL "Linux") find_package(X11) + add_definitions(-DPXR_X11_SUPPORT_ENABLED) endif() # --Embree if (PXR_BUILD_EMBREE_PLUGIN) diff --git a/pxr/imaging/glf/CMakeLists.txt b/pxr/imaging/glf/CMakeLists.txt index a273e001b8..0e6ad8415c 100644 --- a/pxr/imaging/glf/CMakeLists.txt +++ b/pxr/imaging/glf/CMakeLists.txt @@ -8,9 +8,6 @@ if (NOT ${PXR_ENABLE_GL_SUPPORT}) endif() set(optionalPublicClasses "") -if (X11_FOUND) - list(APPEND optionalPublicClasses testGLContext) -endif() pxr_library(glf LIBRARIES @@ -37,6 +34,7 @@ pxr_library(glf simpleLightingContext simpleMaterial simpleShadowArray + testGLContext texture uniformBlock utils diff --git a/pxr/imaging/glf/testGLContext.cpp b/pxr/imaging/glf/testGLContext.cpp index ac21a9c14e..3f8d7a03fe 100644 --- a/pxr/imaging/glf/testGLContext.cpp +++ b/pxr/imaging/glf/testGLContext.cpp @@ -8,12 +8,14 @@ #include "pxr/base/tf/diagnostic.h" +#ifdef PXR_X11_SUPPORT_ENABLED #include +#endif -#include PXR_NAMESPACE_OPEN_SCOPE +#ifdef PXR_X11_SUPPORT_ENABLED class Glf_TestGLContextPrivate { public: @@ -113,6 +115,77 @@ Glf_TestGLContextPrivate::areSharing( const Glf_TestGLContextPrivate * context1, return context1->_sharedContext==context2->_sharedContext; } +#else // PXR_X11_SUPPORT_ENABLED + +class Glf_TestGLContextPrivate +{ +public: + Glf_TestGLContextPrivate(Glf_TestGLContextPrivate const * other = nullptr); + + void makeCurrent() const; + + bool isValid(); + + bool operator==(const Glf_TestGLContextPrivate& rhs) const; + + static const Glf_TestGLContextPrivate * currentContext(); + + static bool areSharing(const Glf_TestGLContextPrivate * context1, + const Glf_TestGLContextPrivate * context2); + +private: + Glf_TestGLContextPrivate const * _sharedContext; + + static Glf_TestGLContextPrivate const * _currenGLContext; +}; + +Glf_TestGLContextPrivate const * Glf_TestGLContextPrivate::_currenGLContext = + nullptr; + +Glf_TestGLContextPrivate::Glf_TestGLContextPrivate( + Glf_TestGLContextPrivate const * other) +{ + _sharedContext = other ? other : this; +} + +void +Glf_TestGLContextPrivate::makeCurrent() const +{ + _currenGLContext = this; +} + +bool +Glf_TestGLContextPrivate::isValid() +{ + return true; +} + +bool +Glf_TestGLContextPrivate::operator==(const Glf_TestGLContextPrivate& rhs) const +{ + return true; +} + +const Glf_TestGLContextPrivate * +Glf_TestGLContextPrivate::currentContext() +{ + return _currenGLContext; +} + +bool +Glf_TestGLContextPrivate::areSharing( + const Glf_TestGLContextPrivate * context1, + const Glf_TestGLContextPrivate * context2) +{ + if (!context1 || !context2) { + return false; + } + + return context1->_sharedContext == context2->_sharedContext; +} + +#endif // PXR_X11_SUPPORT_ENABLED + Glf_TestGLContextPrivate * _GetSharedContext() @@ -217,4 +290,3 @@ GlfTestGLContext::_IsEqual(GlfGLContextSharedPtr const &rhs) const } PXR_NAMESPACE_CLOSE_SCOPE -