Recreate swap chain when the window size changes.

PiperOrigin-RevId: 882521107
Change-Id: I0d29d2e323e7830256c24eead439b3f2eb55de40
This commit is contained in:
Haroon Qureshi
2026-03-12 04:56:10 -07:00
committed by Copybara-Service
parent 4d0c4666db
commit b62aed86f9
2 changed files with 15 additions and 0 deletions
@@ -140,6 +140,19 @@ void FilamentContext::Render(const mjrRect& viewport, const mjvScene* scene,
mju_error("Unexpected context.");
}
// If we're rendering to the window, and the window size has changed, we need
// to reacquire the swap chain.
if (scene_swap_chain_target_ == kWindowSwapChain &&
(viewport.width != window_width_ || viewport.height != window_height_)) {
if (window_width_ != 0 && window_height_ != 0) {
engine_->flushAndWait();
engine_->destroy(window_swap_chain_);
window_swap_chain_ = engine_->createSwapChain(config_.native_window);
}
window_width_ = viewport.width;
window_height_ = viewport.height;
}
scene_view_->SetViewport(viewport);
scene_view_->UpdateScene(con, scene);
// Update the UX renderable entity after processing the scene in case there
@@ -89,6 +89,8 @@ class FilamentContext {
std::unique_ptr<ObjectManager> object_manager_;
std::unique_ptr<SceneView> scene_view_;
std::unique_ptr<GuiView> gui_view_;
int window_width_ = 0;
int window_height_ = 0;
};
} // namespace mujoco