Skip to content

Commit

Permalink
[glf] Portion of Autodesk PR PixarAnimationStudios#3391. Relevant PR …
Browse files Browse the repository at this point in the history
…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 PixarAnimationStudios#3391

(Internal change: 2349272)
  • Loading branch information
clach authored and pixar-oss committed Nov 26, 2024
1 parent f598bc2 commit 20acbba
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmake/defaults/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions pxr/imaging/glf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +34,7 @@ pxr_library(glf
simpleLightingContext
simpleMaterial
simpleShadowArray
testGLContext
texture
uniformBlock
utils
Expand Down
76 changes: 74 additions & 2 deletions pxr/imaging/glf/testGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

#include "pxr/base/tf/diagnostic.h"

#ifdef PXR_X11_SUPPORT_ENABLED
#include <GL/glx.h>
#endif

#include <stdio.h>

PXR_NAMESPACE_OPEN_SCOPE

#ifdef PXR_X11_SUPPORT_ENABLED

class Glf_TestGLContextPrivate {
public:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -217,4 +290,3 @@ GlfTestGLContext::_IsEqual(GlfGLContextSharedPtr const &rhs) const
}

PXR_NAMESPACE_CLOSE_SCOPE

0 comments on commit 20acbba

Please sign in to comment.