Skip to content

Commit 20acbba

Browse files
clachpixar-oss
authored andcommitted
[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)
1 parent f598bc2 commit 20acbba

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

cmake/defaults/Packages.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ if (PXR_BUILD_IMAGING)
266266
# --X11
267267
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
268268
find_package(X11)
269+
add_definitions(-DPXR_X11_SUPPORT_ENABLED)
269270
endif()
270271
# --Embree
271272
if (PXR_BUILD_EMBREE_PLUGIN)

pxr/imaging/glf/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ if (NOT ${PXR_ENABLE_GL_SUPPORT})
88
endif()
99

1010
set(optionalPublicClasses "")
11-
if (X11_FOUND)
12-
list(APPEND optionalPublicClasses testGLContext)
13-
endif()
1411

1512
pxr_library(glf
1613
LIBRARIES
@@ -37,6 +34,7 @@ pxr_library(glf
3734
simpleLightingContext
3835
simpleMaterial
3936
simpleShadowArray
37+
testGLContext
4038
texture
4139
uniformBlock
4240
utils

pxr/imaging/glf/testGLContext.cpp

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

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

11+
#ifdef PXR_X11_SUPPORT_ENABLED
1112
#include <GL/glx.h>
13+
#endif
1214

13-
#include <stdio.h>
1415

1516
PXR_NAMESPACE_OPEN_SCOPE
1617

18+
#ifdef PXR_X11_SUPPORT_ENABLED
1719

1820
class Glf_TestGLContextPrivate {
1921
public:
@@ -113,6 +115,77 @@ Glf_TestGLContextPrivate::areSharing( const Glf_TestGLContextPrivate * context1,
113115

114116
return context1->_sharedContext==context2->_sharedContext;
115117
}
118+
#else // PXR_X11_SUPPORT_ENABLED
119+
120+
class Glf_TestGLContextPrivate
121+
{
122+
public:
123+
Glf_TestGLContextPrivate(Glf_TestGLContextPrivate const * other = nullptr);
124+
125+
void makeCurrent() const;
126+
127+
bool isValid();
128+
129+
bool operator==(const Glf_TestGLContextPrivate& rhs) const;
130+
131+
static const Glf_TestGLContextPrivate * currentContext();
132+
133+
static bool areSharing(const Glf_TestGLContextPrivate * context1,
134+
const Glf_TestGLContextPrivate * context2);
135+
136+
private:
137+
Glf_TestGLContextPrivate const * _sharedContext;
138+
139+
static Glf_TestGLContextPrivate const * _currenGLContext;
140+
};
141+
142+
Glf_TestGLContextPrivate const * Glf_TestGLContextPrivate::_currenGLContext =
143+
nullptr;
144+
145+
Glf_TestGLContextPrivate::Glf_TestGLContextPrivate(
146+
Glf_TestGLContextPrivate const * other)
147+
{
148+
_sharedContext = other ? other : this;
149+
}
150+
151+
void
152+
Glf_TestGLContextPrivate::makeCurrent() const
153+
{
154+
_currenGLContext = this;
155+
}
156+
157+
bool
158+
Glf_TestGLContextPrivate::isValid()
159+
{
160+
return true;
161+
}
162+
163+
bool
164+
Glf_TestGLContextPrivate::operator==(const Glf_TestGLContextPrivate& rhs) const
165+
{
166+
return true;
167+
}
168+
169+
const Glf_TestGLContextPrivate *
170+
Glf_TestGLContextPrivate::currentContext()
171+
{
172+
return _currenGLContext;
173+
}
174+
175+
bool
176+
Glf_TestGLContextPrivate::areSharing(
177+
const Glf_TestGLContextPrivate * context1,
178+
const Glf_TestGLContextPrivate * context2)
179+
{
180+
if (!context1 || !context2) {
181+
return false;
182+
}
183+
184+
return context1->_sharedContext == context2->_sharedContext;
185+
}
186+
187+
#endif // PXR_X11_SUPPORT_ENABLED
188+
116189

117190
Glf_TestGLContextPrivate *
118191
_GetSharedContext()
@@ -217,4 +290,3 @@ GlfTestGLContext::_IsEqual(GlfGLContextSharedPtr const &rhs) const
217290
}
218291

219292
PXR_NAMESPACE_CLOSE_SCOPE
220-

0 commit comments

Comments
 (0)