diff --git a/examples/actor_animation/Main.cc b/examples/actor_animation/Main.cc index 565af7c95..42d54a658 100644 --- a/examples/actor_animation/Main.cc +++ b/examples/actor_animation/Main.cc @@ -188,11 +188,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/boundingbox_camera/Main.cc b/examples/boundingbox_camera/Main.cc index 734ccd622..1cf00c590 100644 --- a/examples/boundingbox_camera/Main.cc +++ b/examples/boundingbox_camera/Main.cc @@ -272,11 +272,7 @@ int main(int _argc, char** _argv) } } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/camera_tracking/Main.cc b/examples/camera_tracking/Main.cc index f8d7e4e93..03279a92e 100644 --- a/examples/camera_tracking/Main.cc +++ b/examples/camera_tracking/Main.cc @@ -127,11 +127,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/custom_scene_viewer/ManualSceneDemo.cc b/examples/custom_scene_viewer/ManualSceneDemo.cc index 551b37ff1..5af164988 100644 --- a/examples/custom_scene_viewer/ManualSceneDemo.cc +++ b/examples/custom_scene_viewer/ManualSceneDemo.cc @@ -192,11 +192,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/custom_shaders_uniforms/Main.cc b/examples/custom_shaders_uniforms/Main.cc index fc46fdd75..093de95b2 100644 --- a/examples/custom_shaders_uniforms/Main.cc +++ b/examples/custom_shaders_uniforms/Main.cc @@ -167,11 +167,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/depth_camera/Main.cc b/examples/depth_camera/Main.cc index ffaf64f8c..ff90e5f87 100644 --- a/examples/depth_camera/Main.cc +++ b/examples/depth_camera/Main.cc @@ -154,11 +154,7 @@ int main(int _argc, char** _argv) engineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/heightmap/Main.cc b/examples/heightmap/Main.cc index 9fff45d43..82db73326 100644 --- a/examples/heightmap/Main.cc +++ b/examples/heightmap/Main.cc @@ -324,11 +324,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2 && buildDemScene != 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/lidar_visual/Main.cc b/examples/lidar_visual/Main.cc index 868d9776b..af5aebeb7 100644 --- a/examples/lidar_visual/Main.cc +++ b/examples/lidar_visual/Main.cc @@ -272,11 +272,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/mesh_viewer/Main.cc b/examples/mesh_viewer/Main.cc index 311ccee93..a0c32a156 100644 --- a/examples/mesh_viewer/Main.cc +++ b/examples/mesh_viewer/Main.cc @@ -142,11 +142,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/mouse_picking/Main.cc b/examples/mouse_picking/Main.cc index 0e62cd2d0..d94bc4d1e 100644 --- a/examples/mouse_picking/Main.cc +++ b/examples/mouse_picking/Main.cc @@ -135,11 +135,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/ogre2_demo/Main.cc b/examples/ogre2_demo/Main.cc index 8d3183d3a..999b00252 100644 --- a/examples/ogre2_demo/Main.cc +++ b/examples/ogre2_demo/Main.cc @@ -317,11 +317,7 @@ int main(int _argc, char** _argv) std::vector engineNames; std::vector cameras; -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/particles_demo/Main.cc b/examples/particles_demo/Main.cc index a35da5845..9ed66c568 100644 --- a/examples/particles_demo/Main.cc +++ b/examples/particles_demo/Main.cc @@ -168,11 +168,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/projector/Main.cc b/examples/projector/Main.cc index 19b7fba85..f78224b16 100644 --- a/examples/projector/Main.cc +++ b/examples/projector/Main.cc @@ -180,11 +180,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/render_pass/Main.cc b/examples/render_pass/Main.cc index 6001add7c..21863d807 100644 --- a/examples/render_pass/Main.cc +++ b/examples/render_pass/Main.cc @@ -198,11 +198,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/segmentation_camera/Main.cc b/examples/segmentation_camera/Main.cc index 1a580732f..0dda4ecd7 100644 --- a/examples/segmentation_camera/Main.cc +++ b/examples/segmentation_camera/Main.cc @@ -150,11 +150,7 @@ int main(int _argc, char** _argv) engineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/simple_demo/Main.cc b/examples/simple_demo/Main.cc index ef9c8030d..1ea6e0f67 100644 --- a/examples/simple_demo/Main.cc +++ b/examples/simple_demo/Main.cc @@ -218,11 +218,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/thermal_camera/Main.cc b/examples/thermal_camera/Main.cc index eb37088cb..68157a0c9 100644 --- a/examples/thermal_camera/Main.cc +++ b/examples/thermal_camera/Main.cc @@ -138,11 +138,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/transform_control/Main.cc b/examples/transform_control/Main.cc index d0feef3aa..22dec4d3b 100644 --- a/examples/transform_control/Main.cc +++ b/examples/transform_control/Main.cc @@ -121,11 +121,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/view_control/Main.cc b/examples/view_control/Main.cc index 25fd38944..5d12fc365 100644 --- a/examples/view_control/Main.cc +++ b/examples/view_control/Main.cc @@ -167,11 +167,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/visualization_demo/Main.cc b/examples/visualization_demo/Main.cc index 04ce442f1..104ef4250 100644 --- a/examples/visualization_demo/Main.cc +++ b/examples/visualization_demo/Main.cc @@ -248,11 +248,7 @@ int main(int _argc, char** _argv) engine = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/waves/Main.cc b/examples/waves/Main.cc index b273e59fb..44889751e 100644 --- a/examples/waves/Main.cc +++ b/examples/waves/Main.cc @@ -164,11 +164,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/examples/wide_angle_camera/Main.cc b/examples/wide_angle_camera/Main.cc index d200246b5..63d6d7073 100644 --- a/examples/wide_angle_camera/Main.cc +++ b/examples/wide_angle_camera/Main.cc @@ -169,11 +169,7 @@ int main(int _argc, char** _argv) ogreEngineName = _argv[1]; } -#ifdef __APPLE__ - GraphicsAPI graphicsApi = GraphicsAPI::METAL; -#else - GraphicsAPI graphicsApi = GraphicsAPI::OPENGL; -#endif + GraphicsAPI graphicsApi = defaultGraphicsAPI(); if (_argc > 2) { graphicsApi = GraphicsAPIUtils::Set(std::string(_argv[2])); diff --git a/include/gz/rendering/Utils.hh b/include/gz/rendering/Utils.hh index 4d53fe2c9..65a50b820 100644 --- a/include/gz/rendering/Utils.hh +++ b/include/gz/rendering/Utils.hh @@ -29,6 +29,7 @@ #include "gz/rendering/Camera.hh" #include "gz/rendering/config.hh" #include "gz/rendering/Export.hh" +#include "gz/rendering/GraphicsAPI.hh" #include "gz/rendering/RayQuery.hh" #include "gz/rendering/Image.hh" @@ -120,6 +121,12 @@ namespace gz /// \return Image in bayer format GZ_RENDERING_VISIBLE Image convertRGBToBayer(const Image &_image, PixelFormat _bayerFormat); + + /// \brief Convenience function to get the default graphics API based on + /// current platform + /// \return Graphics API, i.e. METAL, OPENGL, VULKAN + GZ_RENDERING_VISIBLE + GraphicsAPI defaultGraphicsAPI(); } } } diff --git a/src/Utils.cc b/src/Utils.cc index f6ddcf396..a5ff03ea8 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -25,8 +25,9 @@ #include "gz/math/Vector3.hh" #include "gz/rendering/Camera.hh" -#include "gz/rendering/RayQuery.hh" +#include "gz/rendering/GraphicsAPI.hh" #include "gz/rendering/PixelFormat.hh" +#include "gz/rendering/RayQuery.hh" #include "gz/rendering/Utils.hh" @@ -393,6 +394,16 @@ Image convertRGBToBayer(const Image &_image, PixelFormat _bayerFormat) return destImage; } +///////////////////////////////////////////////// +GraphicsAPI defaultGraphicsAPI() +{ +#ifdef __APPLE__ + return GraphicsAPI::METAL; +#else + return GraphicsAPI::OPENGL; +#endif +} + } } }