Skip to content

Commit

Permalink
[Metal] Add Metal support to Minimal Scene
Browse files Browse the repository at this point in the history
- Set ogre2 render engine as default and ensure the Qt surface format supports OpenGL 4.1
- Default ogre render engine to version to ogre2 in CMakeLists.txt, scene3d.config and Scene3D.
- Set default QSurfaceFormat to OpenGL 4.1 in applications
- cherry-pick 066d276
- Experimental support for Metal in Scene3D and MinimalScene plugins (OpenGL is disabled)
- Modify examples/standalone/window to use Metal backend in the Qt scene graph and force render loop to be single threaded
- Modify ign.cc commandlets to use Metal backend in the Qt scene graph and force render loop to be single threaded
- Use CFBridgingRetain / CFBridgingRelease to manage access to Metal texture objects.
- Force render engine to initialise on the main thread.
- Fix build after interface changes
- Fix build after changes in gazebosim/gz-rendering#477
- Reverse changes to isolate issues in transform control
- Add cross-platform support to MinimalScene TextureNode
- Introduce abstract delegate class for the TextureNode
- Add implementations for OpenGL and Metal
- Add cross-platform support to MinimalScene RenderThread
- Introduce abstract delegate class for the RenderThread
- Add implementations for OpenGL and Metal
- Update CMakeLists.txt for cross-platform
- Only include objective-c and Apple frameworks for macOS
- Add render interface for a camera texture
- Change name of render interface files
- Refactor file names to use `Rhi` suffix
- Refactor names of render interface classes
- Replace Delegate with Rhi (render hardware interface - from Qt)
- Add render hardware interface for the ignition renderer
- Update MinimalScene to use a render hardware interface to retrieve the camera texture
- Convert MinimalScene back to c++
- All Metal specific code moved out of MinimalScene to render interface classes
- Rename MinimalScene and compile as c++
- Allow render system to be switched between Metal and OpenGL
  - Add method SetRenderSystem
  - Update classes in MinimalScene to allow the render system to be set in the plugin XML
  - Move all scene graph backend config to Application
- Set textureDirty flag true on initialisation
- Fix an issue where the initial texture is not sized correctly on initialisation leading to aliasing artefacts
- Fix after rebasing onto ign-gui6

[QML] update function call syntax in Connections blocks
- Change syntax to address warning: QML Connections: Implicitly defined onFoo properties in Connections are deprecated
- Qt 5.15, see: https://doc.qt.io/qt-5/qml-qtqml-connections.html
- Add missing properties for tooltopDelay
- cherry-pick ac51e07

Signed-off-by: Rhys Mainwaring <[email protected]>
  • Loading branch information
srmainwaring committed Nov 30, 2021
1 parent f8af480 commit 12262ce
Show file tree
Hide file tree
Showing 19 changed files with 3,239 additions and 146 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ ign_find_package(TINYXML2 REQUIRED PRIVATE PRETTY tinyxml2)

#--------------------------------------
# Find ignition-math
ign_find_package(ignition-math6 REQUIRED VERSION 6.5)
ign_find_package(ignition-math6 REQUIRED VERSION 6.9)
set(IGN_MATH_VER ${ignition-math6_VERSION_MAJOR})

#--------------------------------------
# Find ignition-common
ign_find_package(ignition-common4 REQUIRED COMPONENTS profiler VERSION 4.1)
ign_find_package(ignition-common4 REQUIRED COMPONENTS profiler VERSION 4.4)
set(IGN_COMMON_VER ${ignition-common4_VERSION_MAJOR})

#--------------------------------------
Expand All @@ -59,8 +59,8 @@ set(IGN_TRANSPORT_VER ${ignition-transport11_VERSION_MAJOR})

#--------------------------------------
# Find ignition-rendering
ign_find_package(ignition-rendering6 REQUIRED COMPONENTS ogre)
set(IGN_RENDERING_VER ${ignition-rendering6_VERSION_MAJOR})
ign_find_package(ignition-rendering7 REQUIRED COMPONENTS ogre2)
set(IGN_RENDERING_VER ${ignition-rendering7_VERSION_MAJOR})

#--------------------------------------
# Find ignition-msgs
Expand Down
42 changes: 41 additions & 1 deletion examples/standalone/window/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,66 @@
*/

#include <iostream>
#include <sstream>

#ifndef Q_MOC_RUN
#include <ignition/gui/qt.h>
#include <ignition/gui/Application.hh>
#include <ignition/gui/MainWindow.hh>
#endif

#include <tinyxml2.h>

//////////////////////////////////////////////////
int main(int _argc, char **_argv)
{
std::cout << "Hello, GUI!" << std::endl;

// must be called before the widget or its parent window gets 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);

// TODO: OpenGL/Metal
// Use single-threaded scene graph rendering
qputenv("QSG_RENDER_LOOP", "basic");

// TODO: OpenGL/Metal
// Use Metal backend
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);

// Increase verboosity so we see all messages
ignition::common::Console::SetVerbosity(4);

// Create app
ignition::gui::Application app(_argc, _argv);

// Create plugin XML
std::string _filename("");
std::ostringstream ss;
ss << "<plugin filename=\"MinimalScene\">"
<< " <ignition-gui>"
<< " <title>View 1</title>"
<< " <property type=\"string\" key=\"state\">docked</property>"
<< " </ignition-gui>"
<< " <engine>ogre2</engine>"
<< " <scene>scene</scene>"
<< " <skybox></skybox>"
<< " <ambient_light>1 1 1</ambient_light>"
<< " <background_color>0.8 0.8 0.8</background_color>"
<< " <camera_pose>-6 0 6 0 0.5 0</camera_pose>"
<< "</plugin>\n";

tinyxml2::XMLDocument pluginDoc;
pluginDoc.Parse(ss.str().c_str());
tinyxml2::XMLElement *pluginElem{pluginDoc.FirstChildElement("plugin")};

// Load plugins / config
if (!app.LoadPlugin("Publisher"))
if (!app.LoadPlugin("MinimalScene", pluginElem))
{
return 1;
}
Expand Down
5 changes: 4 additions & 1 deletion include/ignition/gui/qml/PluginMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ Popup {
id: searchSortBar
color: searchColor
height: 50
width: parent.width
// incorrect: https://stackoverflow.com/questions/63767669/parent-is-null-in-listview-delegate-after-upgrade-to-qt-5-15
// width: parent.width
width: pluginMenuListView.width

RowLayout {
id: rowLayout
anchors.fill: parent
Expand Down
29 changes: 29 additions & 0 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@ Application::Application(int &_argc, char **_argv, const WindowType _type)
{
igndbg << "Initializing application." << std::endl;

// TODO(srmainwaring): OpenGL/Metal
std::string renderSystem = "metal";
if (renderSystem.compare("opengl") == 0)
{
// Must be called before the widget or its parent window gets 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);
}
#if __APPLE__
else if (renderSystem.compare("metal") == 0)
{
igndbg << "Qt using Metal rendering interface" << std::endl;
qputenv("QSG_RENDER_LOOP", "basic");
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);
}
#endif
else
{
ignerr << "Invalid render system: " << renderSystem << std::endl;
}

// Increase verbosity so we see all messages
ignition::common::Console::SetVerbosity(4);

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

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/grid_3d/Grid3D_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST(Grid3DTest, WithoutScene)
EXPECT_TRUE(createMainWindow());

// Check there is no scene
auto engine = rendering::engine("ogre");
auto engine = rendering::engine("ogre2");
ASSERT_NE(nullptr, engine);

EXPECT_EQ(0u, engine->SceneCount());
Expand All @@ -65,7 +65,7 @@ TEST(Grid3DTest, CRUD)
// Load plugin
const char *pluginStr =
"<plugin filename=\"Grid3D\">"
"<engine>ogre</engine>"
"<engine>ogre2</engine>"
"<scene>scene</scene>"
"<insert>"
"<cell_count>5</cell_count>"
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 12262ce

Please sign in to comment.