Skip to content

Commit 0900db8

Browse files
committed
Merge pull request #3215 from dgovil/ios-imaging
Apple: Enable Imaging support for Embedded Platforms (Internal change: 2343224)
2 parents edbde59 + bb98ff8 commit 0900db8

26 files changed

Lines changed: 212 additions & 66 deletions

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ to use a monolithic build when embedding USD
160160

161161
These builds do not support Python bindings or command line tools.
162162

163-
Currently, these builds also do not support Imaging or USD Imaging.
164-
165163
For example, the following will download, build, and install USD's dependencies,
166164
then build and install USD for iOS into `/path/to/my_usd_install_dir`.
167165

build_scripts/build_usd.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,10 +1534,23 @@ def InstallMaterialX(context, force, buildArgs):
15341534
]
15351535

15361536
if MacOSTargetEmbedded(context):
1537+
# The materialXShaderGen in hdSt assumes the GLSL shadergen is
1538+
# available but MaterialX intertwines GLSL shadergen support with
1539+
# also requiring rendering support.
15371540
cmakeOptions.extend([
15381541
'-DMATERIALX_BUILD_GEN_MSL=ON',
1539-
'-DMATERIALX_BUILD_GEN_GLSL=OFF',
1542+
'-DMATERIALX_BUILD_GEN_GLSL=ON',
15401543
'-DMATERIALX_BUILD_IOS=ON'])
1544+
PatchFile("CMakeLists.txt",
1545+
[(' set(MATERIALX_BUILD_GEN_GLSL OFF)',
1546+
' set(MATERIALX_BUILD_GEN_GLSL ON)'),
1547+
(' if (MATERIALX_BUILD_GEN_GLSL)\n' +
1548+
' add_subdirectory(source/MaterialXRenderGlsl)\n' +
1549+
' endif()',
1550+
' if (MATERIALX_BUILD_GEN_GLSL AND NOT MATERIALX_BUILD_IOS)\n' +
1551+
' add_subdirectory(source/MaterialXRenderGlsl)\n' +
1552+
' endif()')
1553+
], multiLineMatches=True)
15411554

15421555
cmakeOptions += buildArgs
15431556
RunCMake(context, force, cmakeOptions)
@@ -1830,8 +1843,8 @@ def InstallUSD(context, force, buildArgs):
18301843
18311844
- Embedded Build Targets
18321845
When cross compiling for an embedded target operating system, e.g. iOS, the
1833-
following components are disabled: python, tools, imaging, tests, examples,
1834-
tutorials.
1846+
following components are disabled: python, tools, tests, examples, tutorials,
1847+
opencolorio, openimageio, openvdb.
18351848
18361849
- Python Versions and DCC Plugins:
18371850
Some DCCs may ship with and run using their own version of Python. In that case,
@@ -2265,9 +2278,11 @@ def __init__(self, args):
22652278

22662279
# - Imaging
22672280
self.buildImaging = (args.build_imaging == IMAGING or
2268-
args.build_imaging == USD_IMAGING) and not embedded
2281+
args.build_imaging == USD_IMAGING)
22692282
self.enablePtex = self.buildImaging and args.enable_ptex
2270-
self.enableOpenVDB = self.buildImaging and args.enable_openvdb
2283+
self.enableOpenVDB = (self.buildImaging
2284+
and args.enable_openvdb
2285+
and not embedded)
22712286

22722287
# - USD Imaging
22732288
self.buildUsdImaging = (args.build_imaging == USD_IMAGING)
@@ -2282,9 +2297,10 @@ def __init__(self, args):
22822297
self.buildPrman = self.buildImaging and args.build_prman
22832298
self.prmanLocation = (os.path.abspath(args.prman_location)
22842299
if args.prman_location else None)
2285-
self.buildOIIO = args.build_oiio or (self.buildUsdImaging
2286-
and self.buildTests)
2287-
self.buildOCIO = args.build_ocio
2300+
self.buildOIIO = ((args.build_oiio or (self.buildUsdImaging
2301+
and self.buildTests))
2302+
and not embedded)
2303+
self.buildOCIO = args.build_ocio and not embedded
22882304

22892305
# - Alembic Plugin
22902306
self.buildAlembic = args.build_alembic
@@ -2421,8 +2437,14 @@ def ForceBuildDependency(self, dep):
24212437
if "--tools" in sys.argv:
24222438
PrintError("Cannot build tools for embedded build targets")
24232439
sys.exit(1)
2424-
if "--imaging" in sys.argv:
2425-
PrintError("Cannot build imaging for embedded build targets")
2440+
if "--openimageio" in sys.argv:
2441+
PrintError("Cannot build openimageio for embedded build targets")
2442+
sys.exit(1)
2443+
if "--opencolorio" in sys.argv:
2444+
PrintError("Cannot build opencolorio for embedded build targets")
2445+
sys.exit(1)
2446+
if "--openvdb" in sys.argv:
2447+
PrintError("Cannot build openvdb for embedded build targets")
24262448
sys.exit(1)
24272449

24282450
# Error out if user explicitly specified building usdview without required

cmake/defaults/Options.cmake

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,18 @@ if(APPLE)
5353
MESSAGE(STATUS "Setting PXR_BUILD_USD_TOOLS=OFF because they are not supported on Apple embedded platforms")
5454
set(PXR_BUILD_USD_TOOLS OFF)
5555
endif()
56-
if (${PXR_BUILD_IMAGING})
57-
MESSAGE(STATUS "Setting PXR_BUILD_USD_IMAGING=OFF because it is not supported on Apple embedded platforms")
58-
set(PXR_BUILD_IMAGING OFF)
59-
endif ()
56+
if(${PXR_BUILD_OPENCOLORIO_PLUGIN})
57+
MESSAGE(STATUS "Setting PXR_BUILD_OPENCOLORIO_PLUGIN=OFF because it is not supported on Apple embedded platforms")
58+
set(PXR_BUILD_OPENCOLORIO_PLUGIN OFF)
59+
endif()
60+
if(${PXR_BUILD_OPENIMAGEIO_PLUGIN})
61+
MESSAGE(STATUS "Setting PXR_BUILD_OPENIMAGEIO_PLUGIN=OFF because it is not supported on Apple embedded platforms")
62+
set(PXR_BUILD_OPENIMAGEIO_PLUGIN OFF)
63+
endif()
64+
if(${PXR_ENABLE_OPENVDB_SUPPORT})
65+
MESSAGE(STATUS "Setting PXR_ENABLE_OPENVDB_SUPPORT=OFF because it is not supported on Apple embedded platforms")
66+
set(PXR_ENABLE_OPENVDB_SUPPORT OFF)
67+
endif()
6068
endif ()
6169
endif()
6270

cmake/defaults/Packages.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ if (PXR_BUILD_IMAGING)
201201
add_definitions(-DPXR_OCIO_PLUGIN_ENABLED)
202202
endif()
203203
# --OpenGL
204-
if (PXR_ENABLE_GL_SUPPORT)
204+
if (PXR_ENABLE_GL_SUPPORT AND NOT PXR_APPLE_EMBEDDED)
205205
# Prefer legacy GL library over GLVND libraries if both
206206
# are installed.
207207
if (POLICY CMP0072)
@@ -250,7 +250,7 @@ if (PXR_BUILD_IMAGING)
250250
endif()
251251
endif()
252252
# --Opensubdiv
253-
set(OPENSUBDIV_USE_GPU ${PXR_ENABLE_GL_SUPPORT})
253+
set(OPENSUBDIV_USE_GPU ${PXR_BUILD_GPU_SUPPORT})
254254
find_package(OpenSubdiv 3 REQUIRED)
255255
# --Ptex
256256
if (PXR_ENABLE_PTEX_SUPPORT)

pxr/imaging/garch/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,29 @@ if(APPLE)
1111
set(GARCH_GLPLATFORMCONTEXT glPlatformContextDarwin)
1212
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowDarwin)
1313
set(GARCH_SOURCE_EXTENSION mm)
14-
set(GARCH_PLATFORM_LIBRARIES "-framework AppKit")
14+
set(GARCH_PLATFORM_LIBRARIES "-framework Foundation")
15+
if (PXR_APPLE_EMBEDDED)
16+
list(APPEND GARCH_PLATFORM_LIBRARIES "-framework UIKit")
17+
else()
18+
list(APPEND GARCH_PLATFORM_LIBRARIES "-framework AppKit")
19+
list(APPEND GARCH_PLATFORM_LIBRARIES OpenGL::GL)
20+
endif()
1521
elseif(X11_FOUND)
1622
set(GARCH_GLPLATFORMCONTEXT glPlatformContextGLX)
1723
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowGLX)
1824
set(GARCH_SOURCE_EXTENSION cpp)
25+
set(GARCH_PLATFORM_LIBRARIES ${X11_LIBRARIES} OpenGL::GL)
1926
elseif(WIN32)
2027
set(GARCH_GLPLATFORMCONTEXT glPlatformContextWindows)
2128
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowWindows)
2229
set(GARCH_SOURCE_EXTENSION cpp)
30+
set(GARCH_PLATFORM_LIBRARIES OpenGL::GL)
2331
endif()
2432

2533
pxr_library(garch
2634
LIBRARIES
2735
arch
2836
tf
29-
${X11_LIBRARIES}
30-
OpenGL::GL
3137
${GARCH_PLATFORM_LIBRARIES}
3238

3339
PUBLIC_CLASSES

pxr/imaging/garch/glPlatformContextDarwin.mm

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
// Licensed under the terms set forth in the LICENSE.txt file available at
55
// https://openusd.org/license.
66
//
7-
#import <Foundation/Foundation.h>
8-
#import <AppKit/NSOpenGL.h>
7+
#include "pxr/imaging/garch/glPlatformContextDarwin.h"
98

10-
#include "pxr/pxr.h"
11-
#include "glPlatformContextDarwin.h"
9+
#include "pxr/base/arch/defines.h"
1210

13-
#ifdef ARCH_OS_IPHONE
14-
typedef EAGLContext NSGLContext;
11+
#import <Foundation/Foundation.h>
12+
#if defined(ARCH_OS_OSX)
13+
#import <AppKit/NSOpenGL.h>
14+
using NSGLContext = NSOpenGLContext;
1515
#else
16-
typedef NSOpenGLContext NSGLContext;
16+
using NSGLContext = void;
1717
#endif
1818

1919
PXR_NAMESPACE_OPEN_SCOPE
@@ -22,7 +22,11 @@
2222
{
2323
public:
2424
Detail() {
25+
#if defined(ARCH_OS_OSX)
2526
context = [NSGLContext currentContext];
27+
#else
28+
context = nil;
29+
#endif
2630
}
2731
Detail(NullState) {
2832
context = nil;
@@ -73,9 +77,7 @@
7377
void
7478
GarchNSGLContextState::MakeCurrent()
7579
{
76-
#if ARCH_OS_IPHONE
77-
[EAGLContext setCurrentContext:_detail->context];
78-
#else
80+
#if defined(ARCH_OS_OSX)
7981
[_detail->context makeCurrentContext];
8082
#endif
8183
}
@@ -84,7 +86,9 @@
8486
void
8587
GarchNSGLContextState::DoneCurrent()
8688
{
89+
#if defined(ARCH_OS_OSX)
8790
[NSGLContext clearCurrentContext];
91+
#endif
8892
}
8993

9094
GarchGLPlatformContextState
@@ -96,6 +100,7 @@
96100
void *
97101
GarchSelectCoreProfileMacVisual()
98102
{
103+
#if defined(ARCH_OS_OSX)
99104
NSOpenGLPixelFormatAttribute attribs[10];
100105
int c = 0;
101106

@@ -105,6 +110,9 @@
105110
attribs[c++] = 0;
106111

107112
return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
113+
#else // ARCH_OS_MACOS
114+
return nullptr;
115+
#endif
108116
}
109117

110118
PXR_NAMESPACE_CLOSE_SCOPE

pxr/imaging/garch/glPlatformDebugWindowDarwin.mm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
#include "pxr/imaging/garch/glDebugWindow.h"
1010
#include "pxr/imaging/garch/glPlatformDebugWindowDarwin.h"
1111

12+
#if defined(ARCH_OS_OSX)
1213
#import <Cocoa/Cocoa.h>
1314
#import <OpenGL/OpenGL.h>
1415
#import <OpenGL/gl.h>
16+
#endif
1517

1618
PXR_NAMESPACE_USING_DIRECTIVE
1719

20+
#if defined(ARCH_OS_OSX)
21+
1822
static int
1923
Garch_GetModifierKeys(NSUInteger flags)
2024
{
@@ -223,3 +227,29 @@ - (void)keyDown:(NSEvent *)event
223227
}
224228

225229
PXR_NAMESPACE_CLOSE_SCOPE
230+
231+
#else // IPHONE Derivatives
232+
233+
PXR_NAMESPACE_OPEN_SCOPE
234+
235+
Garch_GLPlatformDebugWindow::Garch_GLPlatformDebugWindow(GarchGLDebugWindow *w)
236+
{
237+
}
238+
239+
void Garch_GLPlatformDebugWindow::Init(const char *title, int width, int height, int nSamples)
240+
{
241+
}
242+
243+
void
244+
Garch_GLPlatformDebugWindow::Run()
245+
{
246+
}
247+
248+
void
249+
Garch_GLPlatformDebugWindow::ExitApp()
250+
{
251+
}
252+
253+
PXR_NAMESPACE_CLOSE_SCOPE
254+
255+
#endif

pxr/imaging/glf/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ pxr_library(glf
2424
tf
2525
trace
2626
sdf
27-
OpenGL::GL
28-
${X11_LIBRARIES}
2927

3028
PUBLIC_CLASSES
3129
bindingMap

pxr/imaging/hdSt/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
set(PXR_PREFIX pxr/imaging)
22
set(PXR_PACKAGE hdSt)
33

4-
# XXX We tmp check for PXR_ENABLE_GL_SUPPORT since Storm currently still only
5-
# runs on OpenGL. Once Storm uses only Hgi, remove GL_SUPPORT check.
4+
# XXX We check for PXR_ENABLE_GL_SUPPORT since Storm currently still uses
5+
# GL via GarchGLApi. Once Storm uses only Hgi, remove GL_SUPPORT check.
66
if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT})
77
message(STATUS
88
"Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF")

pxr/imaging/hdx/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
set(PXR_PREFIX pxr/imaging)
22
set(PXR_PACKAGE hdx)
33

4-
# XXX We tmp check for PXR_ENABLE_GL_SUPPORT since Hdx currently still uses
5-
# OpenGL directly. Once Hdx uses only Hgi, remove GL_SUPPORT check.
4+
# XXX We check for PXR_ENABLE_GL_SUPPORT since Hdx currently still uses
5+
# GL via GarchGLApi. Once Hdx uses only Hgi, remove GL_SUPPORT check.
66
if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT})
77
message(STATUS
88
"Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF")

0 commit comments

Comments
 (0)