Skip to content

Commit

Permalink
[Metal] Add Metal support for macOS
Browse files Browse the repository at this point in the history
Update ign command script
- Remove server only setting for macOS

Enable the sensors server plugin to run on macOS
- Initialise the render engine for sensors on the main thread
- Platform specific OpenGL context code must be moved elsewhere.
- Ensure the active OpenGL context is associated with the render thread post initialisation

Enable the Gazebo GUI to run on macOS
- Move the RenderThread object to the render thread at the same time as a the OpenGL context

Reinstate render synchronisation
- Reinstate Ignition / QML serial rendering IgnRenderer::Render.
- Allow IgnRenderer::Render to accept a nullptr so it can be called without render sync from the main thread before the render thread is started.

Update QML
- Add missing properties for tooltopDelay

Configure the Qt scene graph to use the Metal backend
- Force the gazebo application to use the Metal backend for the Qt scene graph
- Move Metal scene graph backend to ign::gui::Application

Modify sensors to use Metal
- Set the render system parameter to use Metal

Default to Metal on macOS, otherwise use OpenGL
- Add preprocessor checks to use the Metal graphics API for __APPLE__

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
  • Loading branch information
srmainwaring committed Dec 5, 2021
1 parent cddc011 commit 5e39eee
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
13 changes: 0 additions & 13 deletions src/cmd/cmdgazebo.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,6 @@ has properly set the DYLD_LIBRARY_PATH environment variables."
# Neither the -s nor -g options were used, so run both the server
# and gui.
if options['server'] == 0 && options['gui'] == 0

if plugin.end_with? ".dylib"
puts "`ign gazebo` currently only works with the -s argument on macOS.
See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info."
exit(-1)
end

serverPid = Process.fork do
ENV['RMT_PORT'] = '1500'
Process.setpgid(0, 0)
Expand Down Expand Up @@ -504,12 +497,6 @@ See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info."
options['headless-rendering'])
# Otherwise run the gui
else options['gui']
if plugin.end_with? ".dylib"
puts "`ign gazebo` currently only works with the -s argument on macOS.
See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info."
exit(-1)
end

ENV['RMT_PORT'] = '1501'
Importer.runGui(options['gui_config'], options['render_engine_gui'])
end
Expand Down
2 changes: 2 additions & 0 deletions src/gui/plugins/component_inspector/Boolean.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Rectangle {
// Horizontal margins
property int margin: 5

property int tooltipDelay: 500

RowLayout {
anchors.fill: parent

Expand Down
2 changes: 2 additions & 0 deletions src/gui/plugins/modules/TypeIcon.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Image {
*/
property string entityType: ''

property int tooltipDelay: 500

/**
* Image address according to type
*/
Expand Down
3 changes: 3 additions & 0 deletions src/gui/plugins/visualize_lidar/VisualizeLidar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ GridLayout {
anchors.leftMargin: 10
anchors.rightMargin: 10

property int tooltipDelay: 500
property int tooltipTimeout: 1000

CheckBox {
Layout.alignment: Qt.AlignHCenter
id: displayVisual
Expand Down
9 changes: 9 additions & 0 deletions src/rendering/RenderUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2536,11 +2536,20 @@ void RenderUtil::Init()
rendering::setPluginPaths(pluginPath.PluginPaths());

std::map<std::string, std::string> params;
#ifdef __APPLE__
// TODO(srmainwaring): implement facility for overriding the default
// graphics API in macOS, in which case there are restrictions on
// the version of OpenGL used.
params["metal"] = "1";
#else
if (this->dataPtr->useCurrentGLContext)
params["useCurrentGLContext"] = "1";
#endif

if (this->dataPtr->isHeadlessRendering)
params["headless"] = "1";
params["winID"] = this->dataPtr->winID;

this->dataPtr->engine = rendering::engine(this->dataPtr->engineName, params);
if (!this->dataPtr->engine)
{
Expand Down
18 changes: 16 additions & 2 deletions src/systems/sensors/Sensors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void SensorsPrivate::WaitForInit()
this->renderUtil.SetBackgroundColor(*this->backgroundColor);
if (this->ambientLight)
this->renderUtil.SetAmbientLight(*this->ambientLight);
this->renderUtil.Init();

this->scene = this->renderUtil.Scene();
this->scene->SetCameraPassCountPerGpuFlush(6u);
this->initialized = true;
Expand Down Expand Up @@ -461,7 +461,21 @@ void Sensors::Update(const UpdateInfo &_info,
EntityComponentManager &_ecm)
{
IGN_PROFILE("Sensors::Update");
std::unique_lock<std::mutex> lock(this->dataPtr->renderMutex);

if (!this->dataPtr->initialized &&
(_ecm.HasComponentType(components::Camera::typeId) ||
_ecm.HasComponentType(components::DepthCamera::typeId) ||
_ecm.HasComponentType(components::GpuLidar::typeId) ||
_ecm.HasComponentType(components::RgbdCamera::typeId) ||
_ecm.HasComponentType(components::ThermalCamera::typeId)))
{
igndbg << "Initialization needed" << std::endl;
std::unique_lock<std::mutex> lock(this->dataPtr->renderMutex);

// Initialise render engine on main thread
this->dataPtr->renderUtil.Init();
}

if (this->dataPtr->running && this->dataPtr->initialized)
{
this->dataPtr->renderUtil.UpdateECM(_info, _ecm);
Expand Down

0 comments on commit 5e39eee

Please sign in to comment.