Rename GuiView to ImguiBridge.
PiperOrigin-RevId: 900186368 Change-Id: Ie8f08d081dbc9a2b5638b5e799788e81891c908a
This commit is contained in:
committed by
Copybara-Service
parent
a2d0e33c0f
commit
e047f1101a
@@ -39,7 +39,7 @@
|
||||
#include <mujoco/mjvisualize.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "experimental/filament/filament/filament_platform_factory.h"
|
||||
#include "experimental/filament/filament/gui_view.h"
|
||||
#include "experimental/filament/filament/imgui_bridge.h"
|
||||
#include "experimental/filament/filament/imgui_editor.h"
|
||||
#include "experimental/filament/filament/model_util.h"
|
||||
#include "experimental/filament/filament/object_manager.h"
|
||||
@@ -82,7 +82,7 @@ FilamentContext::FilamentContext(const mjrFilamentConfig* config)
|
||||
|
||||
FilamentContext::~FilamentContext() {
|
||||
DestroyRenderTargets();
|
||||
gui_view_.reset();
|
||||
imgui_bridge_.reset();
|
||||
scene_bridge_.reset();
|
||||
scene_view_.reset();
|
||||
object_manager_.reset();
|
||||
@@ -96,7 +96,7 @@ void FilamentContext::Init(const mjModel* model) {
|
||||
scene_view_ = std::make_unique<SceneView>(engine_);
|
||||
scene_bridge_ = std::make_unique<SceneBridge>(object_manager_.get(), model,
|
||||
scene_view_.get());
|
||||
gui_view_ = std::make_unique<GuiView>(
|
||||
imgui_bridge_ = std::make_unique<ImguiBridge>(
|
||||
scene_view_.get(), object_manager_->GetMaterial(ObjectManager::kUnlitUi));
|
||||
|
||||
// Set clear options.
|
||||
@@ -127,11 +127,11 @@ void FilamentContext::Render(const mjrRect& viewport, const mjvScene* scene) {
|
||||
scene_bridge_->Update(viewport, scene);
|
||||
// Update the UX renderable entity after processing the scene in case there
|
||||
// are any elements in the scene which generate UX draw calls (e.g. labels).
|
||||
if (gui_view_ && gui_swap_chain_target_ == scene_swap_chain_target_) {
|
||||
if (imgui_bridge_ && gui_swap_chain_target_ == scene_swap_chain_target_) {
|
||||
// Prepare the filament Renderable that contains the GUI draw commands. We
|
||||
// must call this function even if we do not plan on rendering the GUI to
|
||||
// ensure the ImGui state is updated.
|
||||
gui_view_->Update();
|
||||
imgui_bridge_->Update();
|
||||
}
|
||||
|
||||
last_render_mode_ = SceneView::DrawMode::kNormal;
|
||||
@@ -155,7 +155,7 @@ void FilamentContext::Render(const mjrRect& viewport, const mjvScene* scene) {
|
||||
request.viewport = viewport;
|
||||
request.camera = last_camera_;
|
||||
request.enable_ux = (gui_swap_chain_target_ == kWindowSwapChain);
|
||||
request.gui_scale = gui_view_ ? gui_view_->GetScale() : 1.0f;
|
||||
request.gui_scale = imgui_bridge_ ? imgui_bridge_->GetScale() : 1.0f;
|
||||
scene_view_->Render(renderer_, request);
|
||||
renderer_->endFrame();
|
||||
}
|
||||
@@ -229,7 +229,7 @@ void FilamentContext::ReadPixels(mjrRect viewport, unsigned char* rgb,
|
||||
request.target = color_target_.get();
|
||||
request.camera = last_camera_;
|
||||
request.enable_ux = (gui_swap_chain_target_ == kOffscreenSwapChain);
|
||||
request.gui_scale = gui_view_ ? gui_view_->GetScale() : 1.0f;
|
||||
request.gui_scale = imgui_bridge_ ? imgui_bridge_->GetScale() : 1.0f;
|
||||
scene_view_->Render(renderer_, request);
|
||||
|
||||
const size_t num_bytes = viewport.width * viewport.height * 3;
|
||||
@@ -288,8 +288,8 @@ void FilamentContext::UploadHeightField(const mjModel* model, int id) {
|
||||
uintptr_t FilamentContext::UploadGuiImage(uintptr_t tex_id,
|
||||
const uint8_t* pixels, int width,
|
||||
int height, int bpp) {
|
||||
if (gui_view_) {
|
||||
return gui_view_->UploadImage(tex_id, pixels, width, height, bpp);
|
||||
if (imgui_bridge_) {
|
||||
return imgui_bridge_->UploadImage(tex_id, pixels, width, height, bpp);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <mujoco/mjmodel.h>
|
||||
#include <mujoco/mjrender.h>
|
||||
#include <mujoco/mjvisualize.h>
|
||||
#include "experimental/filament/filament/gui_view.h"
|
||||
#include "experimental/filament/filament/imgui_bridge.h"
|
||||
#include "experimental/filament/filament/object_manager.h"
|
||||
#include "experimental/filament/filament/render_target.h"
|
||||
#include "experimental/filament/filament/scene_bridge.h"
|
||||
@@ -89,7 +89,7 @@ class FilamentContext {
|
||||
std::unique_ptr<ObjectManager> object_manager_;
|
||||
std::unique_ptr<SceneView> scene_view_;
|
||||
std::unique_ptr<SceneBridge> scene_bridge_;
|
||||
std::unique_ptr<GuiView> gui_view_;
|
||||
std::unique_ptr<ImguiBridge> imgui_bridge_;
|
||||
int window_width_ = 0;
|
||||
int window_height_ = 0;
|
||||
};
|
||||
|
||||
+15
-20
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "experimental/filament/filament/gui_view.h"
|
||||
#include "experimental/filament/filament/imgui_bridge.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -32,16 +32,13 @@
|
||||
|
||||
namespace mujoco {
|
||||
|
||||
GuiView::GuiView(SceneView* scene_view, filament::Material* ui_material)
|
||||
: scene_view_(scene_view), material_(ui_material) {
|
||||
}
|
||||
ImguiBridge::ImguiBridge(SceneView* scene_view, filament::Material* ui_material)
|
||||
: scene_view_(scene_view), material_(ui_material) {}
|
||||
|
||||
GuiView::~GuiView() {
|
||||
PrepareRenderables(0);
|
||||
}
|
||||
ImguiBridge::~ImguiBridge() { PrepareRenderables(0); }
|
||||
|
||||
uintptr_t GuiView::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
|
||||
int width, int height, int bpp) {
|
||||
uintptr_t ImguiBridge::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
|
||||
int width, int height, int bpp) {
|
||||
if (bpp != 4 && bpp != 3) {
|
||||
mju_error("Unsupported image bpp. Got %d, wanted 3 or 4", bpp);
|
||||
}
|
||||
@@ -79,9 +76,8 @@ uintptr_t GuiView::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
|
||||
// lifetime of the data.
|
||||
const size_t num_bytes = width * height * bpp;
|
||||
std::byte* bytes = new std::byte[num_bytes];
|
||||
const auto callback = +[](void* user) {
|
||||
delete[] reinterpret_cast<std::byte*>(user);
|
||||
};
|
||||
const auto callback =
|
||||
+[](void* user) { delete[] reinterpret_cast<std::byte*>(user); };
|
||||
|
||||
TextureData texture_data;
|
||||
DefaultTextureData(&texture_data);
|
||||
@@ -95,7 +91,7 @@ uintptr_t GuiView::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
|
||||
return tex_id;
|
||||
}
|
||||
|
||||
void GuiView::CreateTexture(ImTextureData* data) {
|
||||
void ImguiBridge::CreateTexture(ImTextureData* data) {
|
||||
if (data->Format != ImTextureFormat_RGBA32) {
|
||||
mju_error("Unsupported texture format.");
|
||||
}
|
||||
@@ -115,7 +111,7 @@ void GuiView::CreateTexture(ImTextureData* data) {
|
||||
UpdateTexture(data);
|
||||
}
|
||||
|
||||
void GuiView::UpdateTexture(ImTextureData* data) {
|
||||
void ImguiBridge::UpdateTexture(ImTextureData* data) {
|
||||
auto iter = textures_.find(data->TexID);
|
||||
if (iter == textures_.end()) {
|
||||
mju_error("Texture not found: %llu", data->TexID);
|
||||
@@ -131,7 +127,7 @@ void GuiView::UpdateTexture(ImTextureData* data) {
|
||||
data->SetStatus(ImTextureStatus_OK);
|
||||
}
|
||||
|
||||
void GuiView::DestroyTexture(ImTextureData* data) {
|
||||
void ImguiBridge::DestroyTexture(ImTextureData* data) {
|
||||
auto iter = textures_.find(data->TexID);
|
||||
if (iter != textures_.end()) {
|
||||
textures_.erase(data->TexID);
|
||||
@@ -140,7 +136,7 @@ void GuiView::DestroyTexture(ImTextureData* data) {
|
||||
}
|
||||
}
|
||||
|
||||
void GuiView::Update() {
|
||||
void ImguiBridge::Update() {
|
||||
if (!ImGui::GetCurrentContext()) {
|
||||
PrepareRenderables(0);
|
||||
return;
|
||||
@@ -271,7 +267,7 @@ void GuiView::Update() {
|
||||
}
|
||||
}
|
||||
|
||||
void GuiView::PrepareRenderables(int count) {
|
||||
void ImguiBridge::PrepareRenderables(int count) {
|
||||
while (renderables_.size() < count) {
|
||||
auto& r = renderables_.emplace_back(
|
||||
std::make_unique<Renderable>(scene_view_->GetEngine()));
|
||||
@@ -291,7 +287,7 @@ void GuiView::PrepareRenderables(int count) {
|
||||
}
|
||||
}
|
||||
|
||||
float GuiView::GetScale() const {
|
||||
float ImguiBridge::GetScale() const {
|
||||
return ImGui::GetIO().DisplayFramebufferScale.x;
|
||||
}
|
||||
|
||||
@@ -315,8 +311,7 @@ void DrawTextAt(const char* text, float x, float y, float z) {
|
||||
const int flags = ImGuiWindowFlags_NoBringToFrontOnFocus |
|
||||
ImGuiWindowFlags_NoFocusOnAppearing |
|
||||
ImGuiWindowFlags_NoBackground |
|
||||
ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoInputs |
|
||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs |
|
||||
ImGuiWindowFlags_NoNav;
|
||||
|
||||
ImGui::Begin("labels", nullptr, flags);
|
||||
+8
-8
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_GUI_VIEW_H_
|
||||
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_GUI_VIEW_H_
|
||||
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_IMGUI_BRIDGE_H_
|
||||
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_IMGUI_BRIDGE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
@@ -30,10 +30,10 @@
|
||||
namespace mujoco {
|
||||
|
||||
// Manages Renderables that will be added a SceneView's UX scene.
|
||||
class GuiView {
|
||||
class ImguiBridge {
|
||||
public:
|
||||
GuiView(SceneView* scene_view, filament::Material* ui_material);
|
||||
~GuiView();
|
||||
ImguiBridge(SceneView* scene_view, filament::Material* ui_material);
|
||||
~ImguiBridge();
|
||||
|
||||
// Prepares the Renderables using data from the current ImGui state. This
|
||||
// function must be called once per frame to ensure ImGui state is correctly
|
||||
@@ -47,8 +47,8 @@ class GuiView {
|
||||
uintptr_t UploadImage(uintptr_t tex_id, const uint8_t* pixels, int width,
|
||||
int height, int bpp);
|
||||
|
||||
GuiView(const GuiView&) = delete;
|
||||
GuiView& operator=(const GuiView&) = delete;
|
||||
ImguiBridge(const ImguiBridge&) = delete;
|
||||
ImguiBridge& operator=(const ImguiBridge&) = delete;
|
||||
|
||||
private:
|
||||
// Ensures exactly `count` Renderables exist, creating or destroying them as
|
||||
@@ -72,4 +72,4 @@ void DrawTextAt(const char* text, float x, float y, float z);
|
||||
|
||||
} // namespace mujoco
|
||||
|
||||
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_GUI_VIEW_H_
|
||||
#endif // MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_IMGUI_BRIDGE_H_
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <math/TVecHelpers.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "experimental/filament/filament/color_grading_options.h"
|
||||
#include "experimental/filament/filament/gui_view.h"
|
||||
#include "experimental/filament/filament/imgui_bridge.h"
|
||||
#include "experimental/filament/filament/light.h"
|
||||
#include "experimental/filament/filament/material.h"
|
||||
#include "experimental/filament/filament/math_util.h"
|
||||
|
||||
Reference in New Issue
Block a user