diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 000000000..5304a78f9 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,142 @@ +load( + "@gz//bazel/skylark:build_defs.bzl", + "GZ_FEATURES", + "GZ_ROOT", + "GZ_VISIBILITY", + "gz_configure_header", + "gz_export_header", + "gz_include_header", +) + +package( + default_visibility = GZ_VISIBILITY, + features = GZ_FEATURES, +) + +licenses(["notice"]) # Apache-2.0 + +exports_files(["LICENSE"]) + +gz_configure_header( + name = "rendering_config_hh", + src = "include/gz/rendering/config.hh.in", + cmakelists = ["CMakeLists.txt"], + defines = { + # These definitions are deprecated, this is merely to suppress generator warnings + "GZ_RENDERING_RESOURCE_PATH": "unused", + "GZ_RENDERING_ENGINE_INSTALL_DIR": "unused", + }, + package = "rendering", + undefines = [ + "HAVE_OGRE", + "HAVE_OPTIX", + ], +) + +gz_export_header( + name = "include/gz/rendering/Export.hh", + export_base = "GZ_RENDERING", + lib_name = "gz-rendering", + visibility = ["//visibility:private"], +) + +public_headers_no_gen = glob([ + "include/gz/rendering/*.hh", + "include/gz/rendering/base/*.hh", +]) + +sources = glob( + [ + "src/*.cc", + "src/base/*.cc", + ], + exclude = [ + "src/*_TEST.cc", + ], +) + +gz_include_header( + name = "rendering_hh_genrule", + out = "include/gz/rendering.hh", + hdrs = public_headers_no_gen + [ + "include/gz/rendering/config.hh", + "include/gz/rendering/Export.hh", + ], +) + +public_headers = public_headers_no_gen + [ + "include/gz/rendering/config.hh", + "include/gz/rendering/Export.hh", + "include/gz/rendering.hh", +] + +cc_library( + name = "rendering", + srcs = sources, + hdrs = public_headers, + includes = ["include"], + local_defines = [ + "GZ_RENDERING_BAZEL_BUILD", + 'GZ_RENDERING_PLUGIN_PATH=\\"\\"', + 'GZ_RENDERING_RELATIVE_RESOURCE_PATH=\\"\\"', + 'GZ_RENDERING_ENGINE_RELATIVE_INSTALL_DIR=\\"ogre2\\"', + ], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "common/events", + GZ_ROOT + "common/geospatial", + GZ_ROOT + "common/graphics", + GZ_ROOT + "math", + GZ_ROOT + "plugin:core", + GZ_ROOT + "plugin:loader", + GZ_ROOT + "utils", + ], +) + +test_sources = glob( + include = ["src/*_TEST.cc"], +) + +[cc_test( + name = src.replace("/", "_").replace(".cc", "").replace("src_", ""), + srcs = [src], + env = { + "GZ_BAZEL": "1", + "GZ_BAZEL_PATH": "rendering", + }, + deps = [ + ":rendering", + "@gtest", + "@gtest//:gtest_main", + ], +) for src in test_sources] + +common_test_sources = glob( + include = ["test/common_test/*_TEST.cc"], +) + +[cc_test( + name = src.replace("/", "_").replace(".cc", "").replace("src_", ""), + srcs = [ + src, + "test/common_test/CommonRenderingTest.hh", + ], + data = [ + "test/media", + GZ_ROOT + "rendering/ogre2:libgz-rendering-ogre2.so", + ], + env = { + "GZ_BAZEL": "1", + "GZ_BAZEL_PATH": "rendering", + "GZ_ENGINE_TO_TEST": "ogre2", + "GZ_ENGINE_BACKEND": "opengl", + "GZ_ENGINE_HEADLESS": "true", + }, + includes = ["test/common_test"], + deps = [ + ":rendering", + GZ_ROOT + "common/testing", + "@gtest", + "@gtest//:gtest_main", + ], +) for src in common_test_sources] diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel new file mode 100644 index 000000000..e847762e1 --- /dev/null +++ b/examples/BUILD.bazel @@ -0,0 +1,20 @@ +load( + "@gz//bazel/skylark:build_defs.bzl", + "GZ_FEATURES", + "GZ_ROOT", + "GZ_VISIBILITY", + "gz_configure_header", + "gz_export_header", + "gz_include_header", +) + +cc_binary( + name = "simple_demo_sdl2", + srcs = ["simple_demo_sdl2/Main.cc"], + deps = [ + GZ_ROOT + "common", + GZ_ROOT + "rendering", + "@sdl2", + "@vulkan", + ], +) diff --git a/examples/simple_demo_sdl2/CMakeLists.txt b/examples/simple_demo_sdl2/CMakeLists.txt new file mode 100644 index 000000000..86e0a0f81 --- /dev/null +++ b/examples/simple_demo_sdl2/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) +project(gz-rendering-simple-demo) + +find_package(gz-rendering7) + +find_package(GLUT REQUIRED) +include_directories(SYSTEM ${GLUT_INCLUDE_DIRS}) +link_directories(${GLUT_LIBRARY_DIRS}) + +find_package(OpenGL REQUIRED) +include_directories(SYSTEM ${OpenGL_INCLUDE_DIRS}) +link_directories(${OpenGL_LIBRARY_DIRS}) + +if (NOT APPLE) + find_package(GLEW REQUIRED) + include_directories(SYSTEM ${GLEW_INCLUDE_DIRS}) + link_directories(${GLEW_LIBRARY_DIRS}) +endif() + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") + +add_executable(simple_demo Main.cc GlutWindow.cc) + +target_link_libraries(simple_demo + ${GLUT_LIBRARIES} + ${OPENGL_LIBRARIES} + ${GLEW_LIBRARIES} + ${GZ-RENDERING_LIBRARIES} + ) diff --git a/examples/simple_demo_sdl2/GlutWindow.cc b/examples/simple_demo_sdl2/GlutWindow.cc new file mode 100644 index 000000000..964d7014e --- /dev/null +++ b/examples/simple_demo_sdl2/GlutWindow.cc @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2015 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#if __APPLE__ + #include + #include + #include +#else + #include + #include + #include +#endif + +#if !defined(__APPLE__) && !defined(_WIN32) + #include +#endif + +#include + +#include +#include +#include +#include + +#include "GlutWindow.hh" + +#define KEY_ESC 27 +#define KEY_TAB 9 + +////////////////////////////////////////////////// +unsigned int imgw = 0; +unsigned int imgh = 0; + +std::vector g_cameras; +ir::CameraPtr g_camera; +ir::CameraPtr g_currCamera; +unsigned int g_cameraIndex = 0; +ir::ImagePtr g_image; + +bool g_initContext = false; + +#if __APPLE__ + CGLContextObj g_context; + CGLContextObj g_glutContext; +#elif _WIN32 +#else + GLXContext g_context; + Display *g_display; + GLXDrawable g_drawable; + GLXContext g_glutContext; + Display *g_glutDisplay; + GLXDrawable g_glutDrawable; +#endif + +double g_offset = 0.0; + +////////////////////////////////////////////////// +//! [update camera] +void updateCameras() + +{ + double angle = g_offset / 2 * M_PI; + double x = sin(angle) * 3.0 + 3.0; + double y = cos(angle) * 3.0; + for (ir::CameraPtr camera : g_cameras) + { + camera->SetLocalPosition(x, y, 0.0); + } + + g_offset += 0.0005; +} +//! [update camera] + +////////////////////////////////////////////////// +void displayCB() +{ +#if __APPLE__ + CGLSetCurrentContext(g_context); +#elif _WIN32 +#else + if (g_display) + { + glXMakeCurrent(g_display, g_drawable, g_context); + } +#endif + + g_cameras[g_cameraIndex]->Capture(*g_image); + +#if __APPLE__ + CGLSetCurrentContext(g_glutContext); +#elif _WIN32 +#else + glXMakeCurrent(g_glutDisplay, g_glutDrawable, g_glutContext); +#endif + + unsigned char *data = g_image->Data(); + + glClearColor(0.5, 0.5, 0.5, 1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPixelZoom(1, -1); + glRasterPos2f(-1, 1); + glDrawPixels(imgw, imgh, GL_RGB, GL_UNSIGNED_BYTE, data); + + glutSwapBuffers(); + updateCameras(); +} + +////////////////////////////////////////////////// +void idleCB() +{ + glutPostRedisplay(); +} + +////////////////////////////////////////////////// +void keyboardCB(unsigned char _key, int, int) +{ + if (_key == KEY_ESC || _key == 'q' || _key == 'Q') + { + exit(0); + } + else if (_key == KEY_TAB) + { + g_cameraIndex = (g_cameraIndex + 1) % g_cameras.size(); + } +} + +////////////////////////////////////////////////// +void initCamera(ir::CameraPtr _camera) +{ + g_camera = _camera; + imgw = g_camera->ImageWidth(); + imgh = g_camera->ImageHeight(); + ir::Image image = g_camera->CreateImage(); + g_image = std::make_shared(image); + g_camera->Capture(*g_image); +} + +////////////////////////////////////////////////// +void initContext() +{ + glutInitDisplayMode(GLUT_DOUBLE); + glutInitWindowPosition(0, 0); + glutInitWindowSize(imgw, imgh); + glutCreateWindow("Simple Demo"); + glutDisplayFunc(displayCB); + glutIdleFunc(idleCB); + glutKeyboardFunc(keyboardCB); +} + +////////////////////////////////////////////////// +void printUsage() +{ + std::cout << "===============================" << std::endl; + std::cout << " TAB - Switch render engines " << std::endl; + std::cout << " ESC - Exit " << std::endl; + std::cout << "===============================" << std::endl; +} + +////////////////////////////////////////////////// +void run(std::vector _cameras) +{ + if (_cameras.empty()) + { + gzerr << "No cameras found. Scene will not be rendered" << std::endl; + return; + } + +#if __APPLE__ + g_context = CGLGetCurrentContext(); +#elif _WIN32 +#else + g_context = glXGetCurrentContext(); + g_display = glXGetCurrentDisplay(); + g_drawable = glXGetCurrentDrawable(); +#endif + + g_cameras = _cameras; + initCamera(_cameras[0]); + initContext(); + printUsage(); + +#if __APPLE__ + g_glutContext = CGLGetCurrentContext(); +#elif _WIN32 +#else + g_glutDisplay = glXGetCurrentDisplay(); + g_glutDrawable = glXGetCurrentDrawable(); + g_glutContext = glXGetCurrentContext(); +#endif + + glutMainLoop(); +} diff --git a/examples/simple_demo_sdl2/GlutWindow.hh b/examples/simple_demo_sdl2/GlutWindow.hh new file mode 100644 index 000000000..3b757b280 --- /dev/null +++ b/examples/simple_demo_sdl2/GlutWindow.hh @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2015 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef GZ_RENDERING_EXAMPLES_SIMPLE_DEMO_GLUTWINDOW_HH_ +#define GZ_RENDERING_EXAMPLES_SIMPLE_DEMO_GLUTWINDOW_HH_ + +#include +#include "gz/rendering/RenderTypes.hh" + +namespace ir = gz::rendering; + +/// \brief Run the demo and render the scene from the cameras +/// \param[in] _cameras Cameras in the scene +void run(std::vector _cameras); + +#endif diff --git a/examples/simple_demo_sdl2/Main.cc b/examples/simple_demo_sdl2/Main.cc new file mode 100644 index 000000000..021354117 --- /dev/null +++ b/examples/simple_demo_sdl2/Main.cc @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2015 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include +#include + +#include +#include + +#include + +using namespace gz; +using namespace rendering; + +////////////////////////////////////////////////// +void buildScene(ScenePtr _scene) +{ + // initialize _scene + _scene->SetAmbientLight(0.3, 0.3, 0.3); + VisualPtr root = _scene->RootVisual(); + + // create directional light + DirectionalLightPtr light0 = _scene->CreateDirectionalLight(); + light0->SetDirection(-0.5, 0.5, -1); + light0->SetDiffuseColor(0.5, 0.5, 0.5); + light0->SetSpecularColor(0.5, 0.5, 0.5); + root->AddChild(light0); + + // // create point light + // PointLightPtr light1 = _scene->CreatePointLight(); + // light1->SetDiffuseColor(0.5, 0.5, 0.5); + // light1->SetSpecularColor(0.5, 0.5, 0.5); + // light1->SetLocalPosition(5, -5, 10); + // root->AddChild(light1); + + // create point light + PointLightPtr light2 = _scene->CreatePointLight(); + light2->SetDiffuseColor(0.5, 0.5, 0.5); + light2->SetSpecularColor(0.5, 0.5, 0.5); + light2->SetLocalPosition(3, 5, 5); + root->AddChild(light2); + + // create green material + MaterialPtr green = _scene->CreateMaterial(); + green->SetAmbient(0.0, 0.5, 0.0); + green->SetDiffuse(0.0, 0.7, 0.0); + green->SetSpecular(0.5, 0.5, 0.5); + green->SetShininess(50); + green->SetReflectivity(0); + + // create center visual + VisualPtr center = _scene->CreateVisual(); + center->AddGeometry(_scene->CreateSphere()); + center->SetLocalPosition(3, 0, 0); + center->SetLocalScale(0.1, 0.1, 0.1); + center->SetMaterial(green); + root->AddChild(center); + +//! [red material] + // create red material + MaterialPtr red = _scene->CreateMaterial(); + red->SetAmbient(0.5, 0.0, 0.0); + red->SetDiffuse(1.0, 0.0, 0.0); + red->SetSpecular(0.5, 0.5, 0.5); + red->SetShininess(50); + red->SetReflectivity(0); + red->SetRenderOrder(3); +//! [red material] + + // create sphere visual + VisualPtr sphere = _scene->CreateVisual(); + sphere->AddGeometry(_scene->CreateSphere()); + sphere->SetOrigin(0.0, -0.5, 0.0); + sphere->SetLocalPosition(3, 0, 0); + sphere->SetLocalRotation(0, 0, 0); + sphere->SetLocalScale(1, 1, 1); + sphere->SetMaterial(red); + root->AddChild(sphere); + + // create blue material + MaterialPtr blue = _scene->CreateMaterial(); + blue->SetAmbient(0.0, 0.0, 0.3); + blue->SetDiffuse(0.0, 0.0, 0.8); + blue->SetSpecular(0.5, 0.5, 0.5); + blue->SetShininess(50); + blue->SetReflectivity(0); + + // create box visual + VisualPtr box = _scene->CreateVisual(); + box->AddGeometry(_scene->CreateBox()); + box->SetOrigin(0.0, 0.5, 0.0); + box->SetLocalPosition(3, 0, 0); + box->SetLocalRotation(GZ_PI / 4, 0, GZ_PI / 3); + box->SetLocalScale(1, 2.5, 1); + box->SetMaterial(blue); + root->AddChild(box); + + // create ellipsoid visual + VisualPtr ellipsoidVisual = _scene->CreateVisual(); + auto ellipsoid = _scene->CreateSphere(); + ellipsoidVisual->SetLocalScale(1.2, 0.7, 0.5); + ellipsoidVisual->AddGeometry(ellipsoid); + ellipsoidVisual->SetLocalPosition(3, -1, 0); + ellipsoidVisual->SetMaterial(green); + root->AddChild(ellipsoidVisual); + +//! [white material] + // create white material + MaterialPtr white = _scene->CreateMaterial(); + white->SetAmbient(0.5, 0.5, 0.5); + white->SetDiffuse(0.8, 0.8, 0.8); + white->SetReceiveShadows(true); + white->SetReflectivity(0); + white->SetRenderOrder(0); +//! [white material] + + VisualPtr capsuleVisual = _scene->CreateVisual(); + CapsulePtr capsule = _scene->CreateCapsule(); + capsule->SetLength(0.2); + capsule->SetRadius(0.2); + capsuleVisual->AddGeometry(capsule); + capsuleVisual->SetOrigin(0.0, 0.0, 0.0); + capsuleVisual->SetLocalPosition(4, 2, 0); + capsuleVisual->SetLocalScale(1, 1, 1); + capsuleVisual->SetMaterial(red); + root->AddChild(capsuleVisual); + + // create plane visual + VisualPtr plane = _scene->CreateVisual(); + plane->AddGeometry(_scene->CreatePlane()); + plane->SetLocalScale(5, 8, 1); + plane->SetLocalPosition(3, 0, -0.5); + plane->SetMaterial(white); + root->AddChild(plane); + + // create plane visual + VisualPtr plane2 = _scene->CreateVisual(); + plane2->AddGeometry(_scene->CreatePlane()); + plane2->SetLocalScale(5, 8, 1); + plane2->SetLocalPosition(4, 0.5, -0.5); + plane2->Scale(0.1, 0.1, 1); + plane2->SetMaterial(red); + root->AddChild(plane2); + + // create axis visual + VisualPtr axis = _scene->CreateAxisVisual(); + axis->SetLocalPosition(4.0, 0.5, -0.4); + root->AddChild(axis); + + // create camera + CameraPtr camera = _scene->CreateCamera("camera"); + camera->SetLocalPosition(0.0, 0.0, 0.0); + camera->SetLocalRotation(0.0, 0.0, 0.0); + camera->SetImageWidth(800); + camera->SetImageHeight(600); + camera->SetAntiAliasing(2); + camera->SetAspectRatio(1.333); + camera->SetHFOV(GZ_PI / 2); + root->AddChild(camera); + + // track target + camera->SetTrackTarget(box); +} + +////////////////////////////////////////////////// +CameraPtr createCamera(const std::string &_engineName, + const std::map& _params) +{ + // create and populate scene + RenderEngine *engine = rendering::engine(_engineName, _params); + if (!engine) + { + std::cout << "Engine '" << _engineName + << "' is not supported" << std::endl; + return CameraPtr(); + } + ScenePtr scene = engine->CreateScene("scene"); + buildScene(scene); + + // return camera sensor + SensorPtr sensor = scene->SensorByName("camera"); + return std::dynamic_pointer_cast(sensor); +} + +void SetupVulkan(std::vector _instance_extensions) +{ + VkResult err; + VkInstanceCreateInfo create_info = {}; + create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + + std::vector properties; + uint32_t properties_count; + vkEnumerateInstanceExtensionProperties(nullptr, &properties_count, nullptr); + properties.resize(properties_count); + err = vkEnumerateInstanceExtensionProperties(nullptr, &properties_count, properties.data()); + + for (auto property: properties) + { + std::cout << "Extension property found: " << property.extensionName << std::endl; + } +} + +////////////////////////////////////////////////// +int main(int _argc, char** _argv) +{ + common::Console::SetVerbosity(4); + + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) + { + std::cerr << "could not init sdl" << std::endl; + return -1; + } + + auto window_flags = static_cast(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + SDL_Window* window = SDL_CreateWindow("simple_demo_sdl2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags); +} diff --git a/include/gz/rendering/RenderPassSystem.hh b/include/gz/rendering/RenderPassSystem.hh index 14242839d..8fc9d1cb3 100644 --- a/include/gz/rendering/RenderPassSystem.hh +++ b/include/gz/rendering/RenderPassSystem.hh @@ -17,6 +17,7 @@ #ifndef GZ_RENDERING_RENDERPASSSYSTEM_HH_ #define GZ_RENDERING_RENDERPASSSYSTEM_HH_ +#include #include #include #include @@ -49,23 +50,46 @@ namespace gz public: virtual RenderPass *New() const = 0; }; + class GZ_RENDERING_VISIBLE BaseRenderPassSystem + { + public: using RenderPassFactoryFn = std::function; + + public: BaseRenderPassSystem(); + + public: virtual ~BaseRenderPassSystem(); + + /// \brief Register a render pass factory to the system + /// \param[in] _type Render pass type, i.e. type id of render pass class + /// \param[in] _factory Factory function used to create the render pass + public: void Register(const std::string &_type, + RenderPassFactoryFn _factoryFn); + + /// \brief Implementation for creating render passes + /// \param[in] _type Render pass type, i.e. type id of render pass class + /// \return Pointer to the render pass created + public: RenderPassPtr Create(const std::string &_type); + + public: template RenderPassPtr Create() + { + return this->Create(typeid(T).name()); + } + + GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr); + }; + /* \class RenderPassSystem RenderPassSystem.hh \ * gz/rendering/RenderPassSystem.hh */ /// \brief A class for creating and managing render passes class GZ_RENDERING_VISIBLE RenderPassSystem { - /// \brief Constructor - public: RenderPassSystem(); - - /// \brief Destructor - public: virtual ~RenderPassSystem(); + private: static BaseRenderPassSystem& Implementation(); /// \brief Templated function for creating render passes /// \return Pointer to the render pass created public: template RenderPassPtr Create() { - return this->CreateImpl(typeid(T).name()); + return this->Implementation().Create(typeid(T).name()); } /// \brief Register a render pass factory to the system @@ -73,20 +97,6 @@ namespace gz /// \param[in] _factory Factory used to create the render pass public: static void Register(const std::string &_type, RenderPassFactory *_factory); - - /// \brief Implementation for creating render passes - /// \param[in] _type Render pass type, i.e. type id of render pass class - /// \return Pointer to the render pass created - private: RenderPassPtr CreateImpl(const std::string &_type); - - /// \brief A map of render pass type id name to its factory class - GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING - private: static std::map renderPassMap; - - /// \internal - /// \brief Pointer to private data class - private: std::unique_ptr dataPtr; - GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING }; /// \brief Render pass registration macro diff --git a/ogre2/BUILD.bazel b/ogre2/BUILD.bazel new file mode 100644 index 000000000..e264c8340 --- /dev/null +++ b/ogre2/BUILD.bazel @@ -0,0 +1,81 @@ +load( + "@gz//bazel/skylark:build_defs.bzl", + "GZ_FEATURES", + "GZ_ROOT", + "GZ_VISIBILITY", + "gz_configure_header", + "gz_export_header", + "gz_include_header", +) + +public_headers_no_gen = glob(["include/gz/rendering/ogre2/*.hh"]) + +gz_export_header( + name = "include/gz/rendering/ogre2/Export.hh", + export_base = "GZ_RENDERING_OGRE2", + lib_name = "gz-rendering-ogre2", + visibility = ["//visibility:private"], +) + +public_headers = public_headers_no_gen + [ + "include/gz/rendering/ogre2/Export.hh", +] + +sources = glob([ + "src/*.cc", + "src/*.hh", + "src/terrain/Terra/include/Terra/*.h", + "src/terrain/Terra/include/Terra/Hlms/*.h", + "src/terrain/Terra/include/Terra/Hlms/PbsListener/*.h", + "src/terrain/Terra/src/*.cpp", + "src/terrain/Terra/src/Hlms/*.cpp", + "src/terrain/Terra/src/Hlms/*.cpp.inc", + "src/terrain/Terra/src/Hlms/PbsListener/*.cpp", +]) + +cc_library( + name = "rendering_ogre2", + srcs = sources, + hdrs = public_headers, + copts = [ + # Both in terrain/Terra + "-Wno-sign-compare", + "-Wno-strict-aliasing", + ], + includes = [ + "include", + "src/terrain/Terra/include", + ], + local_defines = [ + "OGRE2_RESOURCE_PATH='\"./ogre2\"'", + "OGRE2_VERSION='\"TODO: replace with correct string\"'", + ], + deps = [ + GZ_ROOT + "math/eigen3", + GZ_ROOT + "rendering", + GZ_ROOT + "third_party/ogre-next:OgreMain", + GZ_ROOT + "third_party/ogre-next:ComponentHlmsUnlit", + GZ_ROOT + "third_party/ogre-next:ComponentHlmsPbs", + GZ_ROOT + "third_party/ogre-next:ComponentOverlay", + GZ_ROOT + "plugin:register", + GZ_ROOT + "third_party/ogre-next:RenderSystemVulkan_null", + #GZ_ROOT + "third_party/ogre-next:RenderSystemVulkan_xcb" + #GZ_ROOT + "third_party/ogre-next:RenderSystemGL3Plus_egl", + GZ_ROOT + "third_party/ogre-next:Plugin_ParticleFX", + "@spdlog", + ], +) + +cc_binary( + name = "libgz-rendering-ogre2.so", + srcs = [ + ":rendering_ogre2", + ], + data = ["src/media"], + linkshared = True, + visibility = GZ_VISIBILITY, + deps = [ + ":rendering_ogre2", + GZ_ROOT + "plugin:register", + ], +) diff --git a/ogre2/src/Ogre2GaussianNoisePass.cc b/ogre2/src/Ogre2GaussianNoisePass.cc index df37ced8b..2ba22661b 100644 --- a/ogre2/src/Ogre2GaussianNoisePass.cc +++ b/ogre2/src/Ogre2GaussianNoisePass.cc @@ -22,6 +22,8 @@ #include "gz/rendering/ogre2/Ogre2GaussianNoisePass.hh" #include "gz/rendering/ogre2/Ogre2RenderEngine.hh" +#include "spdlog/spdlog.h" + #ifdef _MSC_VER #pragma warning(push, 0) #endif @@ -183,4 +185,6 @@ void Ogre2GaussianNoisePass::CreateRenderPass() nodeDef->mapOutputChannel(1, "rt_input"); } +#ifndef OGRE2_STATIC_LIB GZ_RENDERING_REGISTER_RENDER_PASS(Ogre2GaussianNoisePass, GaussianNoisePass) +#endif diff --git a/ogre2/src/Ogre2LidarVisual.cc b/ogre2/src/Ogre2LidarVisual.cc index 348ce020b..f19f853bb 100644 --- a/ogre2/src/Ogre2LidarVisual.cc +++ b/ogre2/src/Ogre2LidarVisual.cc @@ -15,6 +15,7 @@ * */ +#if OGRE_GLSUPPORT #ifdef __APPLE__ #define GL_SILENCE_DEPRECATION #include @@ -24,6 +25,7 @@ #include #endif #endif +#endif #include @@ -160,12 +162,14 @@ void Ogre2LidarVisual::Create() engine->OgreRoot()->getRenderSystem()->getFriendlyName(); if (renderSystemName.find("OpenGL") != std::string::npos) { +#if OGRE_GLSUPPORT #ifdef __APPLE__ glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); #else #ifndef _WIN32 glEnable(GL_PROGRAM_POINT_SIZE); #endif +#endif #endif } this->dataPtr->pointsMat = diff --git a/ogre2/src/Ogre2Marker.cc b/ogre2/src/Ogre2Marker.cc index 4aaf6af27..97f248c2f 100644 --- a/ogre2/src/Ogre2Marker.cc +++ b/ogre2/src/Ogre2Marker.cc @@ -101,6 +101,7 @@ void Ogre2Marker::PreRender() engine->OgreRoot()->getRenderSystem()->getFriendlyName(); if (renderSystemName.find("OpenGL") != std::string::npos) { + #if OGRE_GLSUPPORT #ifdef __APPLE__ glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); #else @@ -108,6 +109,7 @@ void Ogre2Marker::PreRender() glEnable(GL_PROGRAM_POINT_SIZE); #endif #endif + #endif } Ogre::MaterialPtr pointsMat = Ogre::MaterialManager::getSingleton().getByName( diff --git a/ogre2/src/Ogre2RenderEngine.cc b/ogre2/src/Ogre2RenderEngine.cc index 049781b48..b5bb7e20c 100644 --- a/ogre2/src/Ogre2RenderEngine.cc +++ b/ogre2/src/Ogre2RenderEngine.cc @@ -34,6 +34,7 @@ #include "gz/rendering/ogre2/Ogre2RenderTypes.hh" #include "gz/rendering/ogre2/Ogre2Scene.hh" #include "gz/rendering/ogre2/Ogre2Storage.hh" +#include "Ogre2StaticPluginLoader.hh" #include "Ogre2GzHlmsPbsPrivate.hh" #include "Ogre2GzHlmsTerraPrivate.hh" @@ -55,11 +56,16 @@ #include #endif + class GZ_RENDERING_OGRE2_HIDDEN gz::rendering::Ogre2RenderEnginePrivate { #if HAVE_GLX - public: GLXFBConfig* dummyFBConfigs = nullptr; + public: GLXFBConfig* dummyFBConfigs{nullptr}; +#endif + +#if OGRE2_STATIC_LIB + public: Ogre2StaticPluginLoader* staticPluginLoader{nullptr}; #endif /// \brief The graphics API to use @@ -134,6 +140,11 @@ Ogre::Window * Ogre2RenderEngine::OgreWindow() const ////////////////////////////////////////////////// Ogre2RenderEngine::~Ogre2RenderEngine() { + if (this->dataPtr->staticPluginLoader) + { + delete this->dataPtr->staticPluginLoader; + this->dataPtr->staticPluginLoader = nullptr; + } } ////////////////////////////////////////////////// @@ -176,6 +187,12 @@ void Ogre2RenderEngine::Destroy() this->ogreRoot = nullptr; } + if (this->dataPtr->staticPluginLoader) + { + delete this->dataPtr->staticPluginLoader; + this->dataPtr->staticPluginLoader = nullptr; + } + delete this->ogreLogManager; this->ogreLogManager = nullptr; @@ -543,6 +560,14 @@ void Ogre2RenderEngine::CreateOverlay() ////////////////////////////////////////////////// void Ogre2RenderEngine::LoadPlugins() { +#if OGRE2_STATIC_LIB + if (!this->dataPtr->staticPluginLoader) { + this->dataPtr->staticPluginLoader = new Ogre2StaticPluginLoader; + } + this->dataPtr->staticPluginLoader->Install(this->ogreRoot); + return; +#endif + for (auto iter = this->ogrePaths.begin(); iter != this->ogrePaths.end(); ++iter) { @@ -642,6 +667,7 @@ void Ogre2RenderEngine::CreateRenderSystem() const Ogre::RenderSystemList *rsList; rsList = &(this->ogreRoot->getAvailableRenderers()); + std::string targetRenderSysName("OpenGL 3+ Rendering Subsystem"); if (this->dataPtr->graphicsAPI == GraphicsAPI::VULKAN) { @@ -672,6 +698,7 @@ void Ogre2RenderEngine::CreateRenderSystem() // doesn't complain about the line being too long bContinue = renderSys && renderSys->getName().compare(targetRenderSysName) != 0; + std::cout << "Found: " << renderSys->getName() << std::endl; } while (bContinue); } @@ -684,9 +711,11 @@ void Ogre2RenderEngine::CreateRenderSystem() if (!this->Headless()) { - - // We operate in windowed mode - renderSys->setConfigOption("Full Screen", "No"); + if (this->dataPtr->graphicsAPI != GraphicsAPI::VULKAN) + { + // We operate in windowed mode + renderSys->setConfigOption("Full Screen", "No"); + } if (this->dataPtr->graphicsAPI == GraphicsAPI::OPENGL) { @@ -697,19 +726,25 @@ void Ogre2RenderEngine::CreateRenderSystem() /// size of the first window created. /// FBO is the only good option renderSys->setConfigOption("RTT Preferred Mode", "FBO"); + } } else { - try + if (this->dataPtr->graphicsAPI == GraphicsAPI::OPENGL) { - // This may fail if Ogre was *only* build with EGL support, but in that - // case we can ignore the error + // This may fail if Ogre was *only* build with EGL support, but in that + // case we can ignore the error + try { renderSys->setConfigOption( "Interface", "Headless EGL / PBuffer" ); + } + catch ( Ogre::Exception & e) { + std::cout << "Couldn't set Interface: " << e.what() << std::endl; + } } - catch( Ogre::Exception & ) + else if (this->dataPtr->graphicsAPI == GraphicsAPI::VULKAN) { - std::cerr << "Unable to setup EGL (headless mode)" << '\n'; + renderSys->setConfigOption( "Interface", "null" ); } } diff --git a/ogre2/src/Ogre2StaticPluginLoader.cc b/ogre2/src/Ogre2StaticPluginLoader.cc new file mode 100644 index 000000000..cca0126a0 --- /dev/null +++ b/ogre2/src/Ogre2StaticPluginLoader.cc @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2023 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include "Ogre2StaticPluginLoader.hh" + +#include "gz/rendering/RenderPassSystem.hh" +#include "gz/rendering/ogre2/Ogre2GaussianNoisePass.hh" + +#include "OgreRoot.h" + +#if OGRE2_STATIC_LIB + #ifdef OGRE2_HAVE_OPENGL + #include "OgreGL3PlusPlugin.h" + #endif + #ifdef OGRE2_HAVE_VULKAN + #include "OgreVulkanPlugin.h" + #endif + #include "OgreParticleFXPlugin.h" +#endif + +#if OGRE2_STATIC_LIB +class GaussianNoiseFactory: public gz::rendering::RenderPassFactory +{ + public: GaussianNoiseFactory() { + gz::rendering::RenderPassSystem::Register(typeid(gz::rendering::GaussianNoisePass).name(), this); + } + + public: gz::rendering::RenderPass *New() const override { + return new gz::rendering::Ogre2GaussianNoisePass(); + } +}; +#endif // OGRE2_STATIC_LIB + +namespace gz::rendering +{ + +class Ogre2StaticPluginLoader::Implementation +{ +#ifdef OGRE2_STATIC_LIB +#ifdef OGRE2_HAVE_OPENGL + public: Ogre::GL3PlusPlugin* gl3_plugin = {nullptr}; +#endif +#ifdef OGRE2_HAVE_VULKAN + public: Ogre::VulkanPlugin * vulkan_plugin = {nullptr}; +#endif + + public: Ogre::ParticleFXPlugin * particle_plugin = {nullptr}; + + public: GaussianNoiseFactory gaussian_noise_factory; + +#endif + + public: ~Implementation() + { +#ifdef OGRE2_STATIC_LIB +#ifdef OGRE2_HAVE_OPENGL + delete this->gl3_plugin; +#endif +#ifdef OGRE2_HAVE_VULKAN + delete this->vulkan_plugin; +#endif + delete this->particle_plugin; +#endif + } +}; + +Ogre2StaticPluginLoader::Ogre2StaticPluginLoader() + : dataPtr(gz::utils::MakeUniqueImpl()) +{ +} + +void Ogre2StaticPluginLoader::Install(Ogre::Root *_root) +{ +#ifdef OGRE2_STATIC_LIB +#ifdef OGRE2_HAVE_OPENGL + if (!this->dataPtr->gl3_plugin) + { + this->dataPtr->gl3_plugin = new Ogre::GL3PlusPlugin(); + } + _root->installPlugin(this->dataPtr->gl3_plugin, nullptr); +#endif +#ifdef OGRE2_HAVE_VULKAN + if (!this->dataPtr->vulkan_plugin) + { + this->dataPtr->vulkan_plugin = new Ogre::VulkanPlugin(); + } + _root->installPlugin(this->dataPtr->vulkan_plugin, nullptr); +#endif + if (!this->dataPtr->particle_plugin) + { + this->dataPtr->particle_plugin = new Ogre::ParticleFXPlugin(); + } + _root->installPlugin(this->dataPtr->particle_plugin, nullptr); +#endif +} + +} // namespace gz::rendering diff --git a/ogre2/src/Ogre2StaticPluginLoader.hh b/ogre2/src/Ogre2StaticPluginLoader.hh new file mode 100644 index 000000000..06d952d1a --- /dev/null +++ b/ogre2/src/Ogre2StaticPluginLoader.hh @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2023 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef GZ_RENDERING_OGRE2_OGRE2STATICPLUGINLOADER_HH_ +#define GZ_RENDERING_OGRE2_OGRE2STATICPLUGINLOADER_HH_ + +#include "gz/rendering/ogre2/Export.hh" + +#include + +#include + +namespace Ogre +{ +class Root; +} // namespace Ogre + +namespace gz::rendering +{ + +class GZ_RENDERING_OGRE2_VISIBLE Ogre2StaticPluginLoader +{ +public: Ogre2StaticPluginLoader(); + +public: void Install(Ogre::Root *_root); + +GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr); +}; +} // namespace gz::rendering + +#endif // GZ_RENDERING_OGRE2_OGRE2STATICPLUGINLOADER_HH_ diff --git a/src/InstallationDirectories.cc b/src/InstallationDirectories.cc index c0e32a8b0..c68217aa9 100644 --- a/src/InstallationDirectories.cc +++ b/src/InstallationDirectories.cc @@ -15,6 +15,8 @@ * */ +#include + #include #include @@ -26,16 +28,20 @@ namespace rendering { inline namespace GZ_RENDERING_VERSION_NAMESPACE { +#ifdef GZ_RENDERING_BAZEL_BUILD +std::string getInstallPrefix() { return gz::common::joinPaths(gz::common::cwd(), "rendering"); } +#endif + std::string getResourcePath() { return gz::common::joinPaths( - getInstallPrefix(), GZ_RENDERING_RELATIVE_RESOURCE_PATH); + getInstallPrefix(), GZ_RENDERING_RELATIVE_RESOURCE_PATH); } std::string getEngineInstallDir() { return gz::common::joinPaths( - getInstallPrefix(), GZ_RENDERING_ENGINE_RELATIVE_INSTALL_DIR); + getInstallPrefix(), GZ_RENDERING_ENGINE_RELATIVE_INSTALL_DIR); } } diff --git a/src/RenderEngineManager.cc b/src/RenderEngineManager.cc index f9e657792..0565f7975 100644 --- a/src/RenderEngineManager.cc +++ b/src/RenderEngineManager.cc @@ -456,18 +456,21 @@ void RenderEngineManagerPrivate::RegisterDefaultEngines() std::lock_guard lock(this->enginesMutex); #if HAVE_OGRE + std::cout << "HAVE_OGRE" << std::endl; engineName = "ogre"; this->defaultEngines[engineName] = libName + engineName; if (this->engines.find(libName + engineName) == this->engines.end()) this->engines[libName + engineName] = nullptr; #endif #if HAVE_OGRE2 + std::cout << "HAVE_OGRE2" << std::endl; engineName = "ogre2"; this->defaultEngines[engineName] = libName + engineName; if (this->engines.find(libName + engineName) == this->engines.end()) this->engines[libName + engineName] = nullptr; #endif #if HAVE_OPTIX + std::cout << "HAVE_OPTIX" << std::endl; engineName = "optix"; this->defaultEngines[engineName] = libName + engineName; if (this->engines.find(libName + engineName) == this->engines.end()) diff --git a/src/RenderPassSystem.cc b/src/RenderPassSystem.cc index 6c24a1c86..b690e09ef 100644 --- a/src/RenderPassSystem.cc +++ b/src/RenderPassSystem.cc @@ -17,37 +17,36 @@ #include +#include + #include "gz/rendering/RenderPassSystem.hh" using namespace gz; using namespace rendering; /// \brief Private implementation of the RenderPassSystem class -class gz::rendering::RenderPassSystemPrivate +class gz::rendering::BaseRenderPassSystem::Implementation { + public: std::map factoryFns; }; -std::map RenderPassSystem::renderPassMap; - -////////////////////////////////////////////////// -// RenderPassSystem ////////////////////////////////////////////////// -RenderPassSystem::RenderPassSystem() : - dataPtr(new RenderPassSystemPrivate) +BaseRenderPassSystem::BaseRenderPassSystem() + : dataPtr(gz::utils::MakeUniqueImpl()) { } ////////////////////////////////////////////////// -RenderPassSystem::~RenderPassSystem() = default; +BaseRenderPassSystem::~BaseRenderPassSystem() = default; ////////////////////////////////////////////////// -RenderPassPtr RenderPassSystem::CreateImpl(const std::string &_type) +RenderPassPtr BaseRenderPassSystem::Create(const std::string &_type) { RenderPassPtr pass; - auto it = renderPassMap.find(_type); - if (it != renderPassMap.end()) + auto itFn = this->dataPtr->factoryFns.find(_type); + if (itFn != this->dataPtr->factoryFns.end()) { - pass.reset(it->second->New()); + pass.reset(itFn->second()); } else { @@ -58,8 +57,21 @@ RenderPassPtr RenderPassSystem::CreateImpl(const std::string &_type) } ////////////////////////////////////////////////// -void RenderPassSystem::Register(const std::string &_name, - RenderPassFactory *_factory) +void BaseRenderPassSystem::Register(const std::string &_name, + RenderPassFactoryFn _factoryFn) +{ + this->dataPtr->factoryFns[_name] = _factoryFn; +} + +////////////////////////////////////////////////// +BaseRenderPassSystem& RenderPassSystem::Implementation() +{ + static gz::utils::NeverDestroyed instance; + return instance.Access(); +} + +////////////////////////////////////////////////// +void RenderPassSystem::Register(const std::string &_type, RenderPassFactory *_factory) { - renderPassMap[_name] = _factory; + Implementation().Register(_type, [_factory](){return _factory->New();}); } diff --git a/test/common_test/Heightmap_TEST.cc b/test/common_test/Heightmap_TEST.cc index 7408ce1f3..f582fad28 100644 --- a/test/common_test/Heightmap_TEST.cc +++ b/test/common_test/Heightmap_TEST.cc @@ -20,21 +20,22 @@ #include "CommonRenderingTest.hh" #include +#include #include "gz/rendering/Heightmap.hh" #include "gz/rendering/Scene.hh" #include + using namespace gz; using namespace rendering; -class HeightmapTest : public CommonRenderingTest +class HeightmapTest : public CommonRenderingTest { /// \brief Path to test media files. - public: const std::string TEST_MEDIA_PATH{ - common::joinPaths(std::string(PROJECT_SOURCE_PATH), - "test", "media")}; + public: const std::string TEST_MEDIA_PATH = + gz::common::testing::TestFile("media"); }; ///////////////////////////////////////////////// diff --git a/test/common_test/Material_TEST.cc b/test/common_test/Material_TEST.cc index 9bc1f0bb0..a0c832872 100644 --- a/test/common_test/Material_TEST.cc +++ b/test/common_test/Material_TEST.cc @@ -20,6 +20,7 @@ #include "CommonRenderingTest.hh" +#include #include #include "gz/rendering/Camera.hh" @@ -34,9 +35,8 @@ using namespace rendering; class MaterialTest : public CommonRenderingTest { - public: const std::string TEST_MEDIA_PATH = - common::joinPaths(std::string(PROJECT_SOURCE_PATH), - "test", "media", "materials", "textures"); + protected: const std::string TEST_MEDIA_PATH = + gz::common::testing::TestFile("media", "materials", "textures"); }; ///////////////////////////////////////////////// diff --git a/test/common_test/Mesh_TEST.cc b/test/common_test/Mesh_TEST.cc index d4008e734..b06b5ce50 100644 --- a/test/common_test/Mesh_TEST.cc +++ b/test/common_test/Mesh_TEST.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include "gz/rendering/Camera.hh" #include "gz/rendering/Mesh.hh" @@ -35,8 +36,7 @@ using namespace rendering; class MeshTest : public CommonRenderingTest { public: const std::string TEST_MEDIA_PATH = - common::joinPaths(std::string(PROJECT_SOURCE_PATH), - "test", "media", "meshes"); + gz::common::testing::TestFile("media", "meshes"); }; ///////////////////////////////////////////////// diff --git a/test/common_test/ParticleEmitter_TEST.cc b/test/common_test/ParticleEmitter_TEST.cc index 909fe44d3..bb91233c2 100644 --- a/test/common_test/ParticleEmitter_TEST.cc +++ b/test/common_test/ParticleEmitter_TEST.cc @@ -25,16 +25,17 @@ #include "gz/rendering/ParticleEmitter.hh" #include "gz/rendering/Scene.hh" +#include + using namespace gz; using namespace rendering; /// \brief The test fixture. -class ParticleEmitterTest : public CommonRenderingTest +class ParticleEmitterTest : public CommonRenderingTest { /// \brief A directory under test/ with some textures. protected: const std::string TEST_MEDIA_PATH = - common::joinPaths(std::string(PROJECT_SOURCE_PATH), - "test", "media", "materials", "textures"); + gz::common::testing::TestFile("media", "materials", "textures"); }; ///////////////////////////////////////////////// diff --git a/test/common_test/Projector_TEST.cc b/test/common_test/Projector_TEST.cc index 596a7d2a5..dc2bd9172 100644 --- a/test/common_test/Projector_TEST.cc +++ b/test/common_test/Projector_TEST.cc @@ -25,6 +25,8 @@ #include "gz/rendering/Projector.hh" #include "gz/rendering/Scene.hh" +#include + using namespace gz; using namespace rendering; @@ -32,9 +34,8 @@ using namespace rendering; class ProjectorTest : public CommonRenderingTest { /// \brief A directory under test/ with some textures. - protected: const std::string TEST_MEDIA_PATH = - common::joinPaths(std::string(PROJECT_SOURCE_PATH), - "test", "media", "materials", "textures"); + public: const std::string TEST_MEDIA_PATH = + gz::common::testing::TestFile("media", "materials", "textures"); }; ///////////////////////////////////////////////// diff --git a/test/common_test/RenderingIface_TEST.cc b/test/common_test/RenderingIface_TEST.cc index c65472c92..d60772c61 100644 --- a/test/common_test/RenderingIface_TEST.cc +++ b/test/common_test/RenderingIface_TEST.cc @@ -84,7 +84,8 @@ TEST(RenderingIfaceTest, GetEngine) EXPECT_FALSE(isEngineLoaded("no_such_engine")); EXPECT_EQ(nullptr, sceneFromFirstRenderEngine()); - RenderEngine *eng = engine(envEngine, std::map()); + auto engineParams = GetEngineParams(envEngine, envBackend, envHeadless); + RenderEngine *eng = engine(envEngine, engineParams); ASSERT_NE(nullptr, eng); auto engineName = eng->Name(); ASSERT_FALSE(engineName.empty()); diff --git a/test/common_test/Scene_TEST.cc b/test/common_test/Scene_TEST.cc index 4cdddf41a..c564bc917 100644 --- a/test/common_test/Scene_TEST.cc +++ b/test/common_test/Scene_TEST.cc @@ -22,14 +22,15 @@ #include "gz/rendering/RenderTarget.hh" #include "gz/rendering/Scene.hh" +#include + using namespace gz; using namespace rendering; class SceneTest : public CommonRenderingTest { public: const std::string TEST_MEDIA_PATH = - common::joinPaths(std::string(PROJECT_SOURCE_PATH), - "test", "media", "skeleton"); + gz::common::testing::TestFile("media", "skeleton"); }; ///////////////////////////////////////////////// diff --git a/test/common_test/Utils_TEST.cc b/test/common_test/Utils_TEST.cc index fef785cb9..940228272 100644 --- a/test/common_test/Utils_TEST.cc +++ b/test/common_test/Utils_TEST.cc @@ -18,6 +18,7 @@ #include "CommonRenderingTest.hh" #include +#include #include #include "gz/rendering/Camera.hh" @@ -33,9 +34,8 @@ using namespace rendering; class UtilTest : public CommonRenderingTest { /// \brief Path to test media files. - public: const std::string TEST_MEDIA_PATH{ - common::joinPaths(std::string(PROJECT_SOURCE_PATH), - "test", "media")}; + public: const std::string TEST_MEDIA_PATH = + gz::common::testing::TestFile("media"); }; /////////////////////////////////////////////////