From 116cfe9c708ab7ce1e36b7f9e3ce836411e72e4c Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Mon, 8 Jun 2026 06:33:53 -0700 Subject: [PATCH] Remove initial width/height arguments. The ValidateSwapChains function will correctly set up swap chains before any render calls, negating the need to have something done in the constructor. PiperOrigin-RevId: 928529339 Change-Id: Ie584d57f649730adc092f8683f18697892a5a14f --- .../filament/filament/filament_context.cc | 15 +++++---------- .../filament/filament/filament_context.h | 2 ++ src/experimental/filament/mjr_compat.cc | 4 +--- .../filament/render_context_filament.h | 4 ---- src/experimental/platform/hal/renderer.cc | 2 -- 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/experimental/filament/filament/filament_context.cc b/src/experimental/filament/filament/filament_context.cc index f0c4a450..5789c5c5 100644 --- a/src/experimental/filament/filament/filament_context.cc +++ b/src/experimental/filament/filament/filament_context.cc @@ -64,13 +64,8 @@ FilamentContext::FilamentContext(const mjrFilamentConfig* config) #else if (config_.native_window) { window_swap_chain_ = engine_->createSwapChain(config_.native_window); - } else { - window_swap_chain_ = - engine_->createSwapChain(config_.width, config_.height); } #endif - offscreen_swap_chain_ = - engine_->createSwapChain(config_.width, config_.height); object_manager_ = std::make_unique(engine_); material_manager_ = std::make_unique(object_manager_.get()); @@ -240,13 +235,13 @@ void FilamentContext::ValidateSwapChains( } if (max_offscreen_width && max_offscreen_height) { - if (max_offscreen_width != config_.width || - max_offscreen_height != config_.height) { + if (max_offscreen_width != offscreen_width_ || + max_offscreen_height != offscreen_height_) { engine_->destroy(offscreen_swap_chain_); - config_.width = max_offscreen_width; - config_.height = max_offscreen_height; + offscreen_width_ = max_offscreen_width; + offscreen_height_ = max_offscreen_height; offscreen_swap_chain_ = - engine_->createSwapChain(config_.width, config_.height); + engine_->createSwapChain(offscreen_width_, offscreen_height_); } } } diff --git a/src/experimental/filament/filament/filament_context.h b/src/experimental/filament/filament/filament_context.h index 9d258220..14927ca3 100644 --- a/src/experimental/filament/filament/filament_context.h +++ b/src/experimental/filament/filament/filament_context.h @@ -83,6 +83,8 @@ class FilamentContext : public mjrfContext { std::unique_ptr material_manager_; int window_width_ = 0; int window_height_ = 0; + int offscreen_width_ = 0; + int offscreen_height_ = 0; std::uint64_t frame_counter_ = 0; }; diff --git a/src/experimental/filament/mjr_compat.cc b/src/experimental/filament/mjr_compat.cc index b2e6573f..e5d53004 100644 --- a/src/experimental/filament/mjr_compat.cc +++ b/src/experimental/filament/mjr_compat.cc @@ -190,9 +190,7 @@ void mjr_makeContext(const mjModel* m, mjrContext* con, int fontscale) { mjr_freeContext(con); mjrFilamentConfig cfg; - memset(&cfg, 0, sizeof(mjrFilamentConfig)); - cfg.width = m->vis.global.offwidth; - cfg.height = m->vis.global.offheight; + mjrf_defaultFilamentConfig(&cfg); mjr_makeFilamentContext(m, &cfg, con); } diff --git a/src/experimental/filament/render_context_filament.h b/src/experimental/filament/render_context_filament.h index 0dff0a1f..ba112dae 100644 --- a/src/experimental/filament/render_context_filament.h +++ b/src/experimental/filament/render_context_filament.h @@ -105,10 +105,6 @@ struct mjrFilamentConfig { // rendering will be done to an offscreen framebuffer. void* native_window; - // The initial width and height of the offscreen framebuffer. - int width; - int height; - // The backend graphics API to use. mjrGraphicsApi graphics_api; diff --git a/src/experimental/platform/hal/renderer.cc b/src/experimental/platform/hal/renderer.cc index a01c4489..727ecf89 100644 --- a/src/experimental/platform/hal/renderer.cc +++ b/src/experimental/platform/hal/renderer.cc @@ -97,8 +97,6 @@ void Renderer::Init(const mjModel* model) { mjrFilamentConfig cfg; mjrf_defaultFilamentConfig(&cfg); cfg.native_window = native_window_; - cfg.width = model->vis.global.offwidth; - cfg.height = model->vis.global.offheight; cfg.force_software_rendering = IsSoftware(gfx_); cfg.graphics_api = IsOpenGl(gfx_) || IsWebGl(gfx_) ? mjGRAPHICS_API_OPENGL