Skip to content

Commit

Permalink
Add Metal support to MinimalScene and Qt Application (#323)
Browse files Browse the repository at this point in the history
* [Metal] Add Metal support to MinimalScene and Qt Application

Allow MinimalScene to use either OpenGL or Metal render systems

Add classes to abstract out render hardware interfaces:
- IgnCameraTextureRhi
- RenderThreadRhi
- TextureNodeRhi

Add implementations for OpenGL and Metal in:
- MinimalSceneRhiOpenGL
- MinimalSceneRhiMetal
- Modify the existing MinimalScene class to forward rendering calls to the (virtual) render hardware interface functions.
- Modify plugin CMakeLists.txt to conditionally compile Metal support if the platform is macOS
- Update Application.cc to support either OpenGL or Metal

Refactor MinimalScene to use GraphicAPI
- Use the GraphicsAPI enum to set the choice of graphics interface (OpenGL or Metal).
- Change the MinimalScene plugin element to <graphics_api>...</graphics_api>

Add documentation and confirm to code style
- Document the OpenGL and Metal render interface classes
- Revert default engine to ogre

Set graphics API to Metal for macOS, otherwise use OpenGL
- Update Application.cc to only use Metal for macOS
- Fix issues with code check

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Co-authored-by: Ian Chen <ichen@osrfoundation.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
  • Loading branch information
3 people authored Mar 4, 2022
1 parent e099634 commit 63b3599
Show file tree
Hide file tree
Showing 10 changed files with 1,305 additions and 120 deletions.
23 changes: 23 additions & 0 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ Application::Application(int &_argc, char **_argv, const WindowType _type)
{
igndbg << "Initializing application." << std::endl;

#if __APPLE__
// Use the Metal graphics API on macOS.
igndbg << "Qt using Metal graphics interface" << std::endl;
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);

// TODO(srmainwaring): implement facility for overriding the default
// graphics API in macOS, in which case there are restrictions on
// the version of OpenGL used.
//
// macOS only supports OpenGL <= 4.1.
// This must be called before the main window is shown.
// QSurfaceFormat format(QSurfaceFormat::DeprecatedFunctions);
// format.setDepthBufferSize(24);
// format.setStencilBufferSize(8);
// format.setVersion(4, 1);
// format.setProfile(QSurfaceFormat::CoreProfile);
// format.setRenderableType(QSurfaceFormat::OpenGL);
// QSurfaceFormat::setDefaultFormat(format);
#else
// Otherwise use OpenGL
igndbg << "Qt using OpenGL graphics interface" << std::endl;
#endif

// Configure console
common::Console::SetPrefix("[GUI] ");

Expand Down
33 changes: 32 additions & 1 deletion src/plugins/minimal_scene/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
set(SOURCES
MinimalScene.cc
MinimalSceneRhi.cc
MinimalSceneRhiOpenGL.cc
)

set(PROJECT_LINK_LIBS "")

# Objective-C sources for macOS
if (APPLE)
set(SOURCES
${SOURCES}
MinimalSceneRhiMetal.mm
)

set(PROJECT_LINK_LIBS
"-framework AppKit"
"-framework Metal"
)
endif()

ign_gui_add_plugin(MinimalScene
SOURCES
MinimalScene.cc
${SOURCES}
QT_HEADERS
MinimalScene.hh
PUBLIC_LINK_LIBS
ignition-rendering${IGN_RENDERING_VER}::ignition-rendering${IGN_RENDERING_VER}
${PROJECT_LINK_LIBS}
)

# Enable ARC on selected source files
if (APPLE)
set_source_files_properties(
MinimalSceneRhiMetal.mm
PROPERTIES
COMPILE_FLAGS
"-fobjc-arc"
)
endif()
Loading

0 comments on commit 63b3599

Please sign in to comment.