Skip to content

Commit

Permalink
Add Metal support for the Ogre2 Render Engine (#463)
Browse files Browse the repository at this point in the history
* [Metal] enable loading of the Metal render system for ogre2

- Add parameter "metal" and a member variable useMetalRenderSystem to Ogre2RenderEngine
- Modify LoadPlugins to load the Metal render system if enabled
- Modify CreateRenderSystem to select the Metal render system
- Modify RegisterHlms to load the Metal resources
- Add missing Metal shaders for the Terra (from Ogre2)

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] enable metal render system for some examples

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] add Metal shader for skybox and update material

- Add Metal shader for skybox
- Update skybox material to support universal shaders
- Create subdirectories for GLSL and Metal in media/materials/programs and update Ogre2RenderEngine with new resource locations

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] add Metal and unified shaders to each material (wip)

- Add Metal and unified shaders to each material
- Add placeholders for a number of shaders to prevent compile errors when running examples

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] enable metal render system for remaining examples [do not merge]

- Note: these changes will need to be modified / reverted before merging

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] update examples to accept optional command line option "metal"

- Examples accept an additional command line option metal when specifying the ogre2 render engine.
- Pass parameters to the createCamera function.

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] fix formatting on example ogre2_demo

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] revert changes to example text_geom

- This example is for ogre only (not ogre2)

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] update formatting of shaders

- Minor formatting changes to plain_color, point and skybox Metal shaders.

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] port depth_camera and selection_buffer shaders

- Port depth_camera_vs and selection_buffer_fs to Metal
- The mouse_picker, ogre2_demo and transform_control demos now work correctly.

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] shader formatting - replace tabs with whitespace

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] port gaussian_noise shaders

- Port gaussian_noise vertex and pixel shaders from the GLSL counterparts
- The ogre2_demo and render_pass examples now work correctly.

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] port thermal_camera pixel shader

- Correct error in thermal material script
- Port thermal_camera pixel shaders from the GLSL counterparts
- The thermal_camera examples now runs but further requires testing

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] add placeholders for remaining shaders

- Add stubs for the remaining vertex and pixel shaders to port from GLSL

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] port heat_signature pixel shader

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] port depth_camera and gpu_rays shaders [wip]

- Initial ports of depth_camera and gpu_rays shaders
- This is work in progress:
	- On Metal the compositor in Ogre2GpuRay has a pixel format exception
	- Texture sampling for depth_camera_final_fs.metal is not using the equivalent of OpenGL's texelFetch

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] update custom_scene_viewer example to accept optional command line option "metal"

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] fix fragment program specifier in gaussian noise material

- Unified shader had incorrect specifier

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] fix depth camera vertex shader not found in selection buffer material

- This is the same issue as fixed in #456

Signed-off-by: Rhys Mainwaring <[email protected]>

* switch to user RGBA format for internal textures in gpu ray sensor

Signed-off-by: Ian Chen <[email protected]>

* [Metal] complete port of gpu rays 1st pass shader

- Complete port of the GPU Rays shader
- This depends upon the pixel format fix in #468

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] update shaders to fix lidar near plane clipping

- Update Metal shaders to match changes made in PR #356
- Update CrossPlatformSettings_piece to #define outVs_gl_ClipDistance
- Update Ign_piece_vs_any to use cross platform version of gl_ClipDistance

Signed-off-by: Rhys Mainwaring <[email protected]>

* Fix style for code check

- Remove line end whitespace causing CI to fail.

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] incorporate review feedback

- Revert debug output in Ogre2RenderEngine
- Fix codecheck issue with variable declaration shadows previous local
- Revert changes to simple_demo_qml
- Move useMetalRenderSystem to Ogre2RenderEnginePrivate

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] introduce enum for graphics interface

- Add enum class GraphicsAPI to RenderEngine.hh
- Add utils class GraphicsAPIUtils for setting enum from string
- Update Ogre2RenderEngine to use GraphicsAPI enum
- Update examples to use GraphicsAPI enum

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] refactor enum for graphics interface

- Move GraphicsAPI to own file

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] fix examples

- Fix custom_scene_viewer

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] fix class description

- Fix code check
- Change GraphicsAPIUtils class documentation
- Improve graphics API check in Ogre2RenderEngine

Signed-off-by: Rhys Mainwaring <[email protected]>

* [Metal] fix codecheck

- Fix code check - uninitialised variable warning

Signed-off-by: Rhys Mainwaring <[email protected]>

Co-authored-by: Ian Chen <[email protected]>
  • Loading branch information
srmainwaring and iche033 authored Nov 25, 2021
1 parent 04a50f8 commit 8e7b7fb
Show file tree
Hide file tree
Showing 74 changed files with 2,595 additions and 84 deletions.
18 changes: 16 additions & 2 deletions examples/actor_animation/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ void buildScene(ScenePtr _scene, std::vector<VisualPtr> &_visuals,

//////////////////////////////////////////////////
CameraPtr createCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params,
std::vector<VisualPtr> &_visuals, common::SkeletonPtr &_skel)
{
// create and populate scene
RenderEngine *engine = rendering::engine(_engineName);
RenderEngine *engine = rendering::engine(_engineName, _params);
if (!engine)
{
ignwarn << "Engine '" << _engineName
Expand Down Expand Up @@ -187,6 +188,12 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

common::Console::SetVerbosity(4);
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;
Expand All @@ -201,7 +208,14 @@ int main(int _argc, char** _argv)
std::cout << "Starting engine [" << engineName << "]" << std::endl;
try
{
CameraPtr camera = createCamera(engineName, visuals, skel);
std::map<std::string, std::string> params;
if (engineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}

CameraPtr camera = createCamera(engineName, params, visuals, skel);
if (camera)
{
cameras.push_back(camera);
Expand Down
20 changes: 17 additions & 3 deletions examples/camera_tracking/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ NodePtr createMainNode(ScenePtr _scene)
}

//////////////////////////////////////////////////
CameraPtr createCamera(const std::string &_engineName)
CameraPtr createCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params)
{
// create and populate scene
RenderEngine *engine = rendering::engine(_engineName);
RenderEngine *engine = rendering::engine(_engineName, _params);
if (!engine)
{
std::cout << "Engine '" << _engineName
Expand Down Expand Up @@ -126,6 +127,12 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

common::Console::SetVerbosity(4);
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;
Expand All @@ -138,7 +145,14 @@ int main(int _argc, char** _argv)
{
try
{
CameraPtr camera = createCamera(engineName);
std::map<std::string, std::string> params;
if (engineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}

CameraPtr camera = createCamera(engineName, params);
if (camera)
{
cameras.push_back(camera);
Expand Down
20 changes: 17 additions & 3 deletions examples/custom_scene_viewer/ManualSceneDemo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ unsigned int ManualSceneDemo::CameraCount() const
}

//////////////////////////////////////////////////
void ManualSceneDemo::AddCamera(const std::string &_engineName)
void ManualSceneDemo::AddCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params)
{
RenderEngine *engine = rendering::engine(_engineName);
RenderEngine *engine = rendering::engine(_engineName, _params);
if (!engine)
{
std::cout << "Engine '" << _engineName
Expand Down Expand Up @@ -191,6 +192,19 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

std::map<std::string, std::string> params;
if (ogreEngineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}

common::Console::SetVerbosity(4);
//! [add scenes]
ManualSceneDemoPtr sceneDemo(new ManualSceneDemo);
Expand All @@ -208,7 +222,7 @@ int main(int _argc, char** _argv)
sceneDemo->AddScene(SceneBuilderPtr(new ShadowSceneBuilder(4)));
sceneDemo->AddScene(SceneBuilderPtr(new ShadowSceneBuilder(5)));
//! [add scenes]
sceneDemo->AddCamera(ogreEngineName);
sceneDemo->AddCamera(ogreEngineName, params);
sceneDemo->AddCamera("optix");
sceneDemo->Run();
return 0;
Expand Down
4 changes: 3 additions & 1 deletion examples/custom_scene_viewer/ManualSceneDemo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef IGNITION_RENDERING_EXAMPLES_CUSTOM_SCENE_VIEWER_MANUALSCENEDEMO_HH_
#define IGNITION_RENDERING_EXAMPLES_CUSTOM_SCENE_VIEWER_MANUALSCENEDEMO_HH_

#include <map>
#include <string>
#include <ignition/rendering.hh>
#include "TestTypes.hh"
Expand Down Expand Up @@ -46,7 +47,8 @@ namespace ignition

public: virtual unsigned int CameraCount() const;

public: virtual void AddCamera(const std::string &_engineName);
public: virtual void AddCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params = {});

public: virtual void PrevCamera();

Expand Down
9 changes: 5 additions & 4 deletions examples/depth_camera/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,18 @@ int main(int _argc, char** _argv)
engineName = _argv[1];
}

bool useMetalRenderSystem{false};
if (_argc > 2 && std::string(_argv[2]).compare("metal") == 0)
GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
{
useMetalRenderSystem = true;
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

common::Console::SetVerbosity(4);
try
{
std::map<std::string, std::string> params;
if (engineName.compare("ogre2") == 0 && useMetalRenderSystem)
if (engineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}
Expand Down
20 changes: 17 additions & 3 deletions examples/heightmap/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ void buildScene(ScenePtr _scene)
}

//////////////////////////////////////////////////
CameraPtr createCamera(const std::string &_engineName)
CameraPtr createCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params)
{
// create and populate scene
RenderEngine *engine = rendering::engine(_engineName);
RenderEngine *engine = rendering::engine(_engineName, _params);
if (!engine)
{
ignwarn << "Engine '" << _engineName
Expand Down Expand Up @@ -227,13 +228,26 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

engineNames.push_back(ogreEngineName);

for (auto engineName : engineNames)
{
try
{
CameraPtr camera = createCamera(engineName);
std::map<std::string, std::string> params;
if (engineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}

CameraPtr camera = createCamera(engineName, params);
if (camera)
{
cameras.push_back(camera);
Expand Down
20 changes: 17 additions & 3 deletions examples/lidar_visual/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@ LidarVisualPtr createLidar(ScenePtr _scene)
}

//////////////////////////////////////////////////
CameraPtr createCamera(const std::string &_engineName)
CameraPtr createCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params)
{
// create and populate scene
RenderEngine *engine = rendering::engine(_engineName);
RenderEngine *engine = rendering::engine(_engineName, _params);
if (!engine)
{
ignwarn << "Engine '" << _engineName
Expand Down Expand Up @@ -271,6 +272,12 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

common::Console::SetVerbosity(4);
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;
Expand All @@ -284,7 +291,14 @@ int main(int _argc, char** _argv)
std::cout << "Starting engine [" << engineName << "]" << std::endl;
try
{
CameraPtr camera = createCamera(engineName);
std::map<std::string, std::string> params;
if (engineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}

CameraPtr camera = createCamera(engineName, params);
if (camera)
{
cameras.push_back(camera);
Expand Down
20 changes: 17 additions & 3 deletions examples/mesh_viewer/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ void buildScene(ScenePtr _scene)
}

//////////////////////////////////////////////////
CameraPtr createCamera(const std::string &_engineName)
CameraPtr createCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params)
{
// create and populate scene
RenderEngine *engine = rendering::engine(_engineName);
RenderEngine *engine = rendering::engine(_engineName, _params);
if (!engine)
{
ignwarn << "Engine '" << _engineName
Expand Down Expand Up @@ -131,6 +132,12 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

common::Console::SetVerbosity(4);
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;
Expand All @@ -142,7 +149,14 @@ int main(int _argc, char** _argv)
{
try
{
CameraPtr camera = createCamera(engineName);
std::map<std::string, std::string> params;
if (engineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}

CameraPtr camera = createCamera(engineName, params);
if (camera)
{
cameras.push_back(camera);
Expand Down
20 changes: 17 additions & 3 deletions examples/mouse_picking/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ void buildScene(ScenePtr _scene)
root->AddChild(camera);
}

CameraPtr createCamera(const std::string &_engineName)
CameraPtr createCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params)
{
// create and populate scene
RenderEngine *engine = rendering::engine(_engineName);
RenderEngine *engine = rendering::engine(_engineName, _params);
if (!engine)
{
std::cout << "Engine '" << _engineName
Expand All @@ -134,6 +135,12 @@ int main(int _argc, char** _argv)
ogreEngineName = _argv[1];
}

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

common::Console::SetVerbosity(4);
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;
Expand All @@ -145,7 +152,14 @@ int main(int _argc, char** _argv)
{
try
{
CameraPtr camera = createCamera(engineName);
std::map<std::string, std::string> params;
if (engineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}

CameraPtr camera = createCamera(engineName, params);
if (camera)
{
cameras.push_back(camera);
Expand Down
20 changes: 17 additions & 3 deletions examples/ogre2_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,11 @@ void buildScene(ScenePtr _scene)
}

//////////////////////////////////////////////////
CameraPtr createCamera(const std::string &_engineName)
CameraPtr createCamera(const std::string &_engineName,
const std::map<std::string, std::string>& _params)
{
// create and populate scene
RenderEngine *engine = rendering::engine(_engineName);
RenderEngine *engine = rendering::engine(_engineName, _params);
if (!engine)
{
std::cout << "Engine '" << _engineName
Expand Down Expand Up @@ -316,12 +317,25 @@ int main(int _argc, char** _argv)
std::vector<std::string> engineNames;
std::vector<CameraPtr> cameras;

GraphicsAPI graphicsApi = GraphicsAPI::OPENGL;
if (_argc > 2)
{
graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2]));
}

engineNames.push_back("ogre2");
for (auto engineName : engineNames)
{
try
{
CameraPtr camera = createCamera(engineName);
std::map<std::string, std::string> params;
if (engineName.compare("ogre2") == 0
&& graphicsApi == GraphicsAPI::METAL)
{
params["metal"] = "1";
}

CameraPtr camera = createCamera(engineName, params);
if (camera)
{
cameras.push_back(camera);
Expand Down
Loading

0 comments on commit 8e7b7fb

Please sign in to comment.