Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Metal support to MinimalScene and Qt Application #323

Merged
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;

srmainwaring marked this conversation as resolved.
Show resolved Hide resolved
#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