Repository navigation
Expand file tree
/
Copy pathRendererEditor.cpp
More file actions
199 lines (178 loc) · 8.83 KB
/
Copy pathRendererEditor.cpp
File metadata and controls
199 lines (178 loc) · 8.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include <random>
#include "Log.h"
#include "Renderer.h"
#include "ThirdParty/imgui/imgui.h"
#define IMGUI_IMPL_VULKAN_USE_VOLK
#include "ThirdParty/imgui/imgui_impl_vulkan.h"
#include "Editor/Editor.h"
#include "World.h"
#include "../GameCode/Game.h"
#include "Camera.h"
#include "GPUStats.h"
#include "Entity.h"
#include "MeshCache.h"
namespace Magic
{
void Renderer::DoUIWork(int frameNumber, RenderingInfo& renderingInfo)
{
const auto world = renderingInfo.pWorld;
const auto pGame = renderingInfo.pGame;
ImGui::NewFrame();
ImVec2 displaySize = ImGui::GetIO().DisplaySize;
ImGuiWindowFlags flags = ImGuiWindowFlags_NoMove;
const float halfDisplayHeight = displaySize.y * 0.5f;
const float maximumPanelWidth = displaySize.x * 0.75f;
ImGui::SetNextWindowPos(ImVec2(0, 0)); // Top left
ImGui::SetNextWindowSize(ImVec2(450, halfDisplayHeight), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints(ImVec2(300.0f, halfDisplayHeight), ImVec2(maximumPanelWidth, halfDisplayHeight));
ImGui::Begin("Engine Info", nullptr, flags);
ImGui::Text("Game::Update() (us):"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%lld", renderingInfo.updateLoopTimingUS.count());
ImGui::Text("Frame #:"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%d", frameNumber);
ImGui::Text("Entity Count:"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%zu", renderingInfo.gameStats.entityCount);
ImGui::Text("Mesh Count:"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%zu", renderingInfo.gameStats.meshCount);
ImGui::Text("SubMesh Count:"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%zu", renderingInfo.gameStats.subMeshCount);
ImGui::Text("Texture Count:"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%zu", renderingInfo.gameStats.textureCount);
ImGui::Text("Cached Mesh Count:"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%zu", static_cast<std::size_t>(GMeshCache->GetCachedMeshCount()));
#if MAGIC_TRACK_GPU_STATS
auto bytesToMB = [](std::size_t bytes) -> double { return static_cast<double>(bytes) / (1024.0 * 1024.0); };\
ImGui::Text("Buffer MB Uploaded:"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%lf", bytesToMB(renderingInfo.gameStats.bufferBytesUploaded));
ImGui::Text("Image MB Uploaded:"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%lf", bytesToMB(renderingInfo.gameStats.imageBytesUploaded));
#endif
ImGui::Text("Camera Axes:");
constexpr float cameraValueColumnX = 105.0f;
constexpr const char* cameraComponentFormat = "% 5.3f";
const Vector3f cameraPosition = pGame->m_camera->GetPosition();
ImGui::Text("Position:");
ImGui::SameLine(cameraValueColumnX);
ImGui::Text("[");
ImGui::SameLine(0.0f, 0.0f);
ImGui::TextColored(ImVec4(1,0.3,0.3,1), cameraComponentFormat, cameraPosition.x);
ImGui::SameLine(0.0f, 0.0f);
ImGui::Text(" ");
ImGui::SameLine(0.0f, 0.0f);
ImGui::TextColored(ImVec4(0.3,1,0.3,1), cameraComponentFormat, cameraPosition.y);
ImGui::SameLine(0.0f, 0.0f);
ImGui::Text(" ");
ImGui::SameLine(0.0f, 0.0f);
ImGui::TextColored(ImVec4(0.3,0.3,1,1), cameraComponentFormat, cameraPosition.z);
ImGui::SameLine(0.0f, 0.0f);
ImGui::Text("]");
ImGui::TextColored(ImVec4(1,0.3,0.3,1), "X (right):");
ImGui::SameLine(cameraValueColumnX);
ImGui::TextColored(ImVec4(1,0.3,0.3,1), "[% 5.3f % 5.3f % 5.3f]", pGame->m_camera->GetRight().x, pGame->m_camera->GetRight().y, pGame->m_camera->GetRight().z);
ImGui::TextColored(ImVec4(0.3,1,0.3,1), "Y (forward):");
ImGui::SameLine(cameraValueColumnX);
ImGui::TextColored(ImVec4(0.3,1,0.3,1), "[% 5.3f % 5.3f % 5.3f]", pGame->m_camera->GetForward().x, pGame->m_camera->GetForward().y, pGame->m_camera->GetForward().z);
ImGui::TextColored(ImVec4(0.3,0.3,1,1), "Z (up):");
ImGui::SameLine(cameraValueColumnX);
ImGui::TextColored(ImVec4(0.3,0.3,1,1), "[% 5.3f % 5.3f % 5.3f]", pGame->m_camera->GetUp().x, pGame->m_camera->GetUp().y, pGame->m_camera->GetUp().z);
ImGui::Checkbox("Show Bounding Boxes", &m_renderBoundingBoxes);
if (!GEditor->isWorldLoaded)
{
ImGui::InputText("##WorldNameTextBox", GEditor->loadWorldTextBoxNameBuffer, IM_ARRAYSIZE(GEditor->loadWorldTextBoxNameBuffer));
if (ImGui::Button("Load World", ImVec2(150, 30)))
{
if (!GEditor->isWorldLoaded)
{
if (pGame->LoadContent(GEditor->loadWorldTextBoxNameBuffer))
{
auto entities = world->GetAllEntities();
if (!entities.empty())
{
GEditor->sceneOutlineSelectedEntity = entities[0];
}
GEditor->isWorldLoaded = true;
#if PLATFORM_WINDOWS
strncpy_s(GEditor->loadedWorldNameBuffer, GEditor->loadWorldTextBoxNameBuffer, GEditor->defaultMaxTextLength);
#elif PLATFORM_MACOS
strlcpy(GEditor->loadedWorldNameBuffer, GEditor->loadWorldTextBoxNameBuffer, GEditor->defaultMaxTextLength);
#endif
}
else
{
Logger::Warn("World not found!");
}
}
else
{
Logger::Warn("World already loaded! Please unload the current world first before loading another!");
}
}
}
else
{
if (ImGui::Button("Unload World", ImVec2(150, 30)))
{
if (GEditor->isWorldLoaded)
{
pGame->UnloadContent();
renderingInfo.meshesToRender.clear(); // Invalidate all queued up items
GEditor->isWorldLoaded = false;
GEditor->sceneOutlineSelectedEntity = nullptr;
#if PLATFORM_WINDOWS
strncpy_s(GEditor->loadedWorldNameBuffer, "NULL", 5);
#elif PLATFORM_MACOS
strlcpy(GEditor->loadedWorldNameBuffer, "NULL", 5);
#endif
}
}
}
ImGui::Text("World Loaded:"); ImGui::SameLine(); ImGui::TextColored(ImVec4(0,1,0,1), "%s", GEditor->loadedWorldNameBuffer);
ImGui::End();
ImGui::SetNextWindowPos(ImVec2(0, halfDisplayHeight));
ImGui::SetNextWindowSize(ImVec2(300.0f, halfDisplayHeight), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints(ImVec2(200.0f, halfDisplayHeight), ImVec2(maximumPanelWidth, halfDisplayHeight));
if (ImGui::Begin("Scene Outline", nullptr, flags))
{
// Make a scrollable region that fills the window's content area
ImVec2 avail = ImGui::GetContentRegionAvail();
ImGui::BeginChild("SceneOutlineList", avail, ImGuiChildFlags_None, ImGuiWindowFlags_AlwaysVerticalScrollbar);
auto DrawEntityNode = [](this auto& self, IEntity* e) -> void {
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth;
if (e == GEditor->sceneOutlineSelectedEntity) flags |= ImGuiTreeNodeFlags_Selected;
if (!e->HasChildren()) flags |= ImGuiTreeNodeFlags_Leaf; // No collapsing/arrow
// Use the pointer for identity so duplicate names are safe.
const bool open = ImGui::TreeNodeEx(static_cast<const void*>(e), flags, "%s", e->GetName()); // Are we trying to inspect this entity's children?
// Check immediately after TreeNodeEx, before drawing children.
// Clicking the arrow expands/collapses without changing selection.
if (ImGui::IsItemClicked(ImGuiMouseButton_Left) && !ImGui::IsItemToggledOpen())
{
GEditor->sceneOutlineSelectedEntity = e;
}
if (open)
{
for (IEntity* child : e->GetChildren())
{
self(child);
}
ImGui::TreePop();
}
};
// int i = 0;
for (auto entity : world->GetAllEntities())
{
if (entity->GetParent() == nullptr)
{
DrawEntityNode(entity);
}
}
ImGui::EndChild();
}
ImGui::End();
ImGui::SetNextWindowPos(ImVec2(displaySize.x, 0.0f), ImGuiCond_Always, ImVec2(1.0f, 0.0f));
ImGui::SetNextWindowSize(ImVec2(400.0f, displaySize.y), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints(ImVec2(300.0f, displaySize.y), ImVec2(maximumPanelWidth, displaySize.y));
if (ImGui::Begin("Inspector", nullptr, flags))
{
// Entity: Display transform
if (GEditor->sceneOutlineSelectedEntity)
{
EntityType selectedEntityType = GEditor->sceneOutlineSelectedEntity->GetEntityType();
ImGui::TextWrapped("%s", Entity::TypeToStr(selectedEntityType));
ImGui::Separator();
GEditor->sceneOutlineSelectedEntity->DrawInspectorElements();
}
}
ImGui::End();
}
}