From 13d164063cf10f9728dd0b175dc333fcb852f4dd Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Wed, 4 Mar 2026 04:55:22 -0800 Subject: [PATCH] Remove separate targets for classic and filament renderer. The platform::Renderer now supports both implementations at runtime. PiperOrigin-RevId: 878427862 Change-Id: I2997c197c6eddbe177c77b435cc5848fd80f1839 --- .github/workflows/build.yml | 12 ++--------- .github/workflows/build_steps.sh | 26 ++++-------------------- CMakeLists.txt | 17 +++++++--------- src/experimental/filament/CMakeLists.txt | 8 +++++++- src/experimental/platform/CMakeLists.txt | 19 ++--------------- src/experimental/studio/CMakeLists.txt | 1 + src/experimental/studio/README.md | 12 ----------- src/experimental/studio/build.sh | 1 - src/experimental/studio/main.cc | 2 ++ 9 files changed, 25 insertions(+), 73 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe4ee3cb..f8a592a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -381,20 +381,12 @@ jobs: if: ${{ runner.os == 'Linux' }} run: bash ./.github/workflows/build_steps.sh prepare_linux - - name: Configure Studio with legacy OpenGL rendering - env: - CMAKE_ARGS: ${{ matrix.cmake_args }} - run: bash ./.github/workflows/build_steps.sh configure_studio_legacy_opengl - - - name: Build Studio with legacy OpenGL rendering - run: bash ./.github/workflows/build_steps.sh build_studio - - - name: Configure Studio with Filament rendering + - name: Configure Studio env: CMAKE_ARGS: ${{ matrix.cmake_args }} run: bash ./.github/workflows/build_steps.sh configure_studio - - name: Build Studio with Filament rendering + - name: Build Studio run: bash ./.github/workflows/build_steps.sh build_studio - name: Notify team chat diff --git a/.github/workflows/build_steps.sh b/.github/workflows/build_steps.sh index c99a2774..bf75fd35 100755 --- a/.github/workflows/build_steps.sh +++ b/.github/workflows/build_steps.sh @@ -147,9 +147,8 @@ build_simulate() { } -_configure_studio() { - # Invoke cmake will all options OFF assuming that the caller will enable - # needed options by running `export _CONFIGURE_STUDIO_CMAKE_ARGS=...` first +configure_studio() { + echo "Configuring Studio..." cmake -B build \ -DCMAKE_BUILD_TYPE:STRING=Release \ -DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF \ @@ -157,28 +156,11 @@ _configure_studio() { -DBUILD_SHARED_LIBS=OFF \ -DMUJOCO_BUILD_EXAMPLES=OFF \ -DMUJOCO_BUILD_SIMULATE=OFF \ - -DMUJOCO_BUILD_STUDIO=OFF \ + -DMUJOCO_BUILD_STUDIO=ON \ -DMUJOCO_BUILD_TESTS=OFF \ -DMUJOCO_TEST_PYTHON_UTIL=OFF \ -DMUJOCO_WITH_USD=OFF \ - -DMUJOCO_USE_FILAMENT=OFF \ - -DMUJOCO_USE_FILAMENT_VULKAN=OFF \ - ${_CONFIGURE_STUDIO_CMAKE_ARGS} -} - - -configure_studio_legacy_opengl() { - echo "Configuring Studio (legacy OpenGL)..." - export _CONFIGURE_STUDIO_CMAKE_ARGS="-DMUJOCO_BUILD_STUDIO=ON ${CMAKE_ARGS}" - _configure_studio - echo "Configuring Studio (legacy OpenGL)... DONE" -} - - -configure_studio() { - echo "Configuring Studio..." - export _CONFIGURE_STUDIO_CMAKE_ARGS="-DMUJOCO_BUILD_STUDIO=ON -DMUJOCO_USE_FILAMENT=ON ${CMAKE_ARGS}" - _configure_studio + -DMUJOCO_USE_FILAMENT=ON echo "Configuring Studio... DONE" } diff --git a/CMakeLists.txt b/CMakeLists.txt index f0838f48..0ee7f6b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,8 @@ if(NOT EMSCRIPTEN) option(MUJOCO_TEST_PYTHON_UTIL "Build and test utility libraries for Python bindings" ON) option(MUJOCO_WITH_USD "Build with OpenUSD" OFF) option(MUJOCO_USE_FILAMENT "Use filament rendering" OFF) - option(MUJOCO_USE_FILAMENT_VULKAN "Use vulkan backend for filament rendering" OFF) + # Allows filament renderer to be used with mjr API; disables src/render to prevent conflicts. + option(MUJOCO_USE_FILAMENT_MJR_COMPAT "Use filament mjr compatibility layer" OFF) endif() if(EMSCRIPTEN) @@ -114,19 +115,15 @@ add_subdirectory(src/engine) add_subdirectory(src/user) add_subdirectory(src/xml) add_subdirectory(src/thread) - -if(MUJOCO_USE_FILAMENT AND NOT EMSCRIPTEN) - # Note that, by default, the "src/render" and "src/ui" code is added directly - # into the "mujoco" target. However, "mujoco::filament" is a separate, - # explicit target. Therefore, if you want to use MuJoCo with Filament, you - # will need to explicitly add the "mujoco::filament" target as a link - # dependency in your project. - add_subdirectory(src/experimental/filament) -elseif(NOT EMSCRIPTEN) +if(NOT EMSCRIPTEN AND NOT MUJOCO_USE_FILAMENT_MJR_COMPAT) add_subdirectory(src/render) add_subdirectory(src/ui) endif() +if(MUJOCO_USE_FILAMENT AND NOT EMSCRIPTEN) + add_subdirectory(src/experimental/filament) +endif() + if(EMSCRIPTEN) add_subdirectory(wasm) if(MUJOCO_BUILD_TESTS_WASM) diff --git a/src/experimental/filament/CMakeLists.txt b/src/experimental/filament/CMakeLists.txt index 17ebec93..4d792c67 100644 --- a/src/experimental/filament/CMakeLists.txt +++ b/src/experimental/filament/CMakeLists.txt @@ -21,7 +21,6 @@ target_compile_definitions(${MUJOCO_FILAMENT_TARGET_NAME} PRIVATE MJ_STATIC) target_sources(${MUJOCO_FILAMENT_TARGET_NAME} PUBLIC - mjr_compat.cc render_context_filament.h render_context_filament.cc filament/buffer_util.cc @@ -58,6 +57,13 @@ target_sources(${MUJOCO_FILAMENT_TARGET_NAME} filament/vertex_util.cc filament/vertex_util.h ) +if(MUJOCO_USE_FILAMENT_MJR_COMPAT) + target_sources(${MUJOCO_FILAMENT_TARGET_NAME} + PUBLIC + mjr_compat.cc + ) +endif() + target_include_directories(${MUJOCO_FILAMENT_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include diff --git a/src/experimental/platform/CMakeLists.txt b/src/experimental/platform/CMakeLists.txt index c3fc3b38..fa0561ad 100644 --- a/src/experimental/platform/CMakeLists.txt +++ b/src/experimental/platform/CMakeLists.txt @@ -16,25 +16,8 @@ cmake_minimum_required(VERSION 3.16) set(MUJOCO_PLATFORM_TARGET_NAME mujoco_platform) -# Determine the render configuration and dependencies based options. -if(MUJOCO_USE_FILAMENT AND MUJOCO_USE_FILAMENT_VULKAN) - set(MUJOCO_PLATFORM_RENDER_CONFIG "MUJOCO_RENDERER_FILAMENT_VULKAN") - set(MUJOCO_PLATFORM_RENDER_DEPS "mujoco::filament") -elseif(MUJOCO_USE_FILAMENT) - set(MUJOCO_PLATFORM_RENDER_CONFIG "MUJOCO_RENDERER_FILAMENT_OPENGL") - set(MUJOCO_PLATFORM_RENDER_DEPS "mujoco::filament") -else() - set(MUJOCO_PLATFORM_RENDER_CONFIG "MUJOCO_RENDERER_CLASSIC_OPENGL") - set(MUJOCO_PLATFORM_RENDER_DEPS "dear_imgui_OpenGL3") -endif() - add_library(${MUJOCO_PLATFORM_TARGET_NAME} STATIC) -target_compile_definitions(${MUJOCO_PLATFORM_TARGET_NAME} - PUBLIC - -D${MUJOCO_PLATFORM_RENDER_CONFIG} -) - target_sources(${MUJOCO_PLATFORM_TARGET_NAME} PUBLIC egl_utils.cc @@ -113,8 +96,10 @@ include(third_party_deps/libwebp) target_link_libraries(${MUJOCO_PLATFORM_TARGET_NAME} dear_imgui dear_imgui_SDL2 + dear_imgui_OpenGL3 dear_imgui_stdlib implot + mujoco::filament webp SDL2::SDL2-static ${MUJOCO_PLATFORM_RENDER_DEPS} diff --git a/src/experimental/studio/CMakeLists.txt b/src/experimental/studio/CMakeLists.txt index 1bf9d048..cafa6a66 100644 --- a/src/experimental/studio/CMakeLists.txt +++ b/src/experimental/studio/CMakeLists.txt @@ -50,6 +50,7 @@ include(third_party_deps/font_awesome) target_link_libraries(${MUJOCO_STUDIO_TARGET_NAME} PRIVATE absl::flags + absl::flags_parse dear_imgui implot mujoco::mujoco diff --git a/src/experimental/studio/README.md b/src/experimental/studio/README.md index 5828876e..a71d9819 100644 --- a/src/experimental/studio/README.md +++ b/src/experimental/studio/README.md @@ -32,18 +32,6 @@ If you intend to develop the application you may prefer to work from an IDE: * [Visual Studio](https://visualstudio.microsoft.com/). Follow these [instructions](https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=msvc-170). -## Filament Rendering - -Studio uses legacy OpenGL rendering by default but there is an option to use -Physically Based Rendering via [Filament](https://google.github.io/filament/Filament.md.html). -To enable Filament you need to `-DMUJOCO_USE_FILAMENT=ON` during the cmake -configuration step. The Filament renderer has multiple rendering backends, -on Linux OpenGL is the default but Vulkan can be used by also providing -the `-DMUJOCO_USE_FILAMENT_VULKAN=ON` option. - -Also note that you will need to run the application from the folder containing -the executable so that the expected materials/assets can be found. - ## Known Bugs * MuJoCo Studio does not yet work using Wayland on Linux, use X11 instead. diff --git a/src/experimental/studio/build.sh b/src/experimental/studio/build.sh index 63043c33..8b8b116b 100755 --- a/src/experimental/studio/build.sh +++ b/src/experimental/studio/build.sh @@ -62,7 +62,6 @@ if [[ "$do_configure" == true ]]; then "-DUSE_STATIC_LIBCXX=OFF" "-DBUILD_SHARED_LIB=OFF" "-DMUJOCO_USE_FILAMENT=ON" - "-DMUJOCO_USE_FILAMENT_VULKAN=OFF" "-DMUJOCO_BUILD_EXAMPLES=OFF" "-DMUJOCO_BUILD_SIMULATE=OFF" "-DMUJOCO_BUILD_TESTS=OFF" diff --git a/src/experimental/studio/main.cc b/src/experimental/studio/main.cc index 2b7bf227..312883e6 100644 --- a/src/experimental/studio/main.cc +++ b/src/experimental/studio/main.cc @@ -25,6 +25,7 @@ #include #include +#include #include #include "experimental/platform/graphics_mode.h" #include "experimental/studio/app.h" @@ -73,6 +74,7 @@ class FileResource { }; int main(int argc, char** argv, char** envp) { + absl::ParseCommandLine(argc, argv); const char* home = getenv("HOME"); const std::string ini_path = std::string(home ? home : ".") + "/.mujoco.ini";