Skip to content

Commit 794ce0d

Browse files
Consuming Arena Allocator for our Rendering (#459)
* upgrade vma to v3.3.0 * rendering with Arena allocator support * fixed bracket * fixed hashmap test * fixed logger UI * improved log msg type * reordered log type defaut and selection * clang format * added Write API to Graphic Buffer
1 parent c12afed commit 794ce0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2099
-1593
lines changed

Resources/Shaders/infinite_grid.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Camera;
1313

1414
void main()
1515
{
16-
scaleFactor = 80.0;
16+
scaleFactor = 50.0;
1717

1818
vec3 posScale = pos * scaleFactor;
1919
uv = posScale.xz;

Resources/Shaders/vertex_common.glsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ struct DrawVertex
77

88
struct DrawData
99
{
10-
uint TransformIndex;
11-
uint MaterialIndex;
1210
uint VertexOffset;
13-
uint IndexOffset;
1411
uint VertexCount;
12+
uint IndexOffset;
1513
uint IndexCount;
14+
uint AllocationCount;
15+
uint InstanceCount;
16+
uint TransformIndex;
17+
uint MaterialIndex;
1618
};
1719

1820
struct DrawDataView

Tetragrama/Components/HierarchyViewUIComponent.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44
#include <ImGuizmo/ImGuizmo.h>
55
#include <Inputs/Keyboard.h>
66
#include <Inputs/Mouse.h>
7-
#include <MessageToken.h>
8-
#include <Messenger.h>
97
#include <ZEngine/Engine.h>
108
#include <ZEngine/Rendering/Scenes/GraphicScene.h>
11-
#include <ZEngine/Windows/Inputs/IDevice.h>
129
#include <ZEngine/Windows/Inputs/KeyCodeDefinition.h>
1310
#include <glm/glm.hpp>
1411
#include <gtc/type_ptr.hpp>
15-
#include <imgui.h>
16-
#include <stack>
1712

1813
using namespace ZEngine;
1914
using namespace ZEngine::Helpers;
@@ -81,6 +76,9 @@ namespace Tetragrama::Components
8176
int node_id = -1;
8277
};
8378

79+
Importers::AssetMesh* mesh = ctx->AssetManagerPtr->GetMeshAsset(mesh_node_hierarchy->MeshUUID);
80+
const auto& mesh_alloc = current_scene->CreateOrGetMeshAllocation(mesh);
81+
8482
for (int i = 0; i < mesh_node_hierarchy->Hierarchies.size(); ++i)
8583
{
8684
if (mesh_node_hierarchy->Hierarchies[i].Parent == -1)
@@ -98,17 +96,33 @@ namespace Tetragrama::Components
9896
continue;
9997
}
10098

101-
auto node_ref = Importers::AssetNodeRef{.AssetNodeHandle = handle, .NodeHierarchyIndex = entry.node_id};
99+
auto node_ref = Importers::AssetNodeRef{.NodeHierarchyIndex = entry.node_id, .AssetNodeHandle = handle, .AssetMeshUUID = mesh_node_hierarchy->MeshUUID};
102100
if (mesh_node_hierarchy->NodeNames.contains(entry.node_id))
103101
{
104102
auto name_idx = mesh_node_hierarchy->NodeNames[entry.node_id];
105103
node_ref.Name = mesh_node_hierarchy->Names[name_idx].c_str();
106104
}
107105

108-
int scene_node_id = current_scene->CreateSceneNode(entry.Parent, entry.Depth, node_ref);
106+
int scene_node_id = current_scene->CreateSceneNode(entry.Parent, entry.Depth, node_ref);
107+
108+
if (mesh_node_hierarchy->NodeMeshes.contains(entry.node_id))
109+
{
110+
const auto& submesh_id = mesh_node_hierarchy->NodeMeshes.at(entry.node_id);
111+
const auto& sub_mesh = mesh->SubMeshes[submesh_id];
112+
auto material_handle = ctx->AssetManagerPtr->GetMaterialHandleFromUUID(sub_mesh.MaterialUUID);
113+
auto material_index = Managers::AssetManager::ReadAssetHandleIndex(material_handle);
114+
115+
current_scene->NodeSubMeshesAllocations[scene_node_id].TransformId = scene_node_id;
116+
current_scene->NodeSubMeshesAllocations[scene_node_id].MaterialId = material_index;
117+
current_scene->NodeSubMeshesAllocations[scene_node_id].IndexOffset = mesh_alloc.IndexOffset + sub_mesh.IndexOffset;
118+
current_scene->NodeSubMeshesAllocations[scene_node_id].VertexOffset = mesh_alloc.VertexOffset + sub_mesh.VertexOffset;
119+
current_scene->NodeSubMeshesAllocations[scene_node_id].VertexCount = sub_mesh.VertexCount;
120+
current_scene->NodeSubMeshesAllocations[scene_node_id].IndexCount = sub_mesh.IndexCount;
121+
current_scene->NodeSubMeshesAllocations[scene_node_id].InstanceCount = mesh_alloc.InstanceCount;
122+
}
109123

110-
const auto& node = mesh_node_hierarchy->Hierarchies[entry.node_id];
111-
bool has_children = (node.FirstChild != -1);
124+
const auto& node = mesh_node_hierarchy->Hierarchies[entry.node_id];
125+
bool has_children = (node.FirstChild != -1);
112126

113127
if (has_children)
114128
{
@@ -276,18 +290,22 @@ namespace Tetragrama::Components
276290
{
277291
continue;
278292
}
279-
const auto& node = scene->Hierarchies[entry.node_id];
280-
281-
auto name_id = scene->NodeNames[entry.node_id];
282293

294+
const auto& node = scene->Hierarchies[entry.node_id];
295+
auto name_id = scene->NodeNames.at(entry.node_id);
283296
bool is_selected = (selected_node == entry.node_id);
284297
bool has_children = (node.FirstChild != -1);
285298

286299
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth;
287300
if (!has_children)
301+
{
288302
flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen;
303+
}
304+
289305
if (is_selected)
306+
{
290307
flags |= ImGuiTreeNodeFlags_Selected;
308+
}
291309

292310
auto node_id = fmt::format("SceneNode_{0}", entry.node_id);
293311
bool open = ImGui::TreeNodeEx(node_id.c_str(), flags, "%s", scene->Names[name_id].c_str());

Tetragrama/Components/HierarchyViewUIComponent.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
#pragma once
2-
#include <EditorCameraController.h>
3-
#include <Message.h>
42
#include <UIComponent.h>
53
#include <imgui.h>
6-
#include <future>
7-
#include <mutex>
8-
#include <string>
94

105
namespace Tetragrama::Components
116
{

Tetragrama/Components/InspectorViewUIComponent.cpp

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <ZEngine/Rendering/Textures/Texture2D.h>
1010

1111
#define GLM_ENABLE_EXPERIMENTAL
12+
#include <Editor.h>
1213
#include <glm/gtx/matrix_decompose.hpp>
1314

1415
using namespace ZEngine::Rendering::Materials;
@@ -29,69 +30,52 @@ namespace Tetragrama::Components
2930
m_node_flag = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding;
3031
}
3132

32-
void InspectorViewUIComponent::Update(ZEngine::Core::TimeStep dt) {}
33-
34-
std::future<void> InspectorViewUIComponent::SceneEntitySelectedMessageHandlerAsync(Messengers::GenericMessage<ZEngine::Rendering::Scenes::SceneEntity>& message)
35-
{
36-
{
37-
std::lock_guard lock(m_mutex);
38-
m_scene_entity = std::move(message.GetValue());
39-
}
40-
co_return;
41-
}
42-
43-
std::future<void> InspectorViewUIComponent::SceneEntityUnSelectedMessageHandlerAsync(Messengers::EmptyMessage& message)
44-
{
45-
{
46-
std::lock_guard lock(m_mutex);
47-
m_recieved_unselected_request = true;
48-
}
49-
co_return;
50-
}
51-
52-
std::future<void> InspectorViewUIComponent::SceneEntityDeletedMessageHandlerAsync(Messengers::EmptyMessage&)
53-
{
54-
{
55-
std::lock_guard lock(m_mutex);
56-
m_recieved_deleted_request = true;
57-
}
58-
co_return;
59-
}
33+
void InspectorViewUIComponent::Update(ZEngine::Core::TimeStep dt) {}
6034

6135
void InspectorViewUIComponent::Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer)
6236
{
63-
if (m_recieved_deleted_request || m_recieved_unselected_request)
37+
ImGui::Begin(Name, (CanBeClosed ? &CanBeClosed : NULL), ImGuiWindowFlags_NoCollapse);
38+
39+
if (ParentLayer && ParentLayer->ParentContext)
6440
{
65-
m_scene_entity = {};
66-
m_recieved_deleted_request = false;
67-
m_recieved_unselected_request = false;
41+
auto ctx = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
42+
auto idx = ctx->SelectedSceneNode.load(std::memory_order_acquire);
43+
if (idx != -1)
44+
{
45+
auto name_idx = ctx->CurrentScenePtr->NodeNames[idx];
46+
auto& name = ctx->CurrentScenePtr->Names[name_idx];
47+
48+
ImGui::Dummy(ImVec2(0, 3));
49+
Helpers::DrawInputTextControl("Name", name.c_str(), [&](std::string_view value) {
50+
name.clear();
51+
name.append(value.data());
52+
});
53+
}
6854
}
6955

70-
ImGui::Begin(Name, (CanBeClosed ? &CanBeClosed : NULL), ImGuiWindowFlags_NoCollapse);
56+
// Helpers::DrawEntityControl("Name", m_scene_entity, m_node_flag, [this] {
57+
// ImGui::Dummy(ImVec2(0, 3));
58+
// Helpers::DrawInputTextControl("Entity name", m_scene_entity.GetName(), [this](std::string_view value) { m_scene_entity.SetName(value); });
59+
// });
7160

72-
Helpers::DrawEntityControl("Name", m_scene_entity, m_node_flag, [this] {
73-
ImGui::Dummy(ImVec2(0, 3));
74-
Helpers::DrawInputTextControl("Entity name", m_scene_entity.GetName(), [this](std::string_view value) { m_scene_entity.SetName(value); });
75-
});
76-
77-
Helpers::DrawEntityControl("Transform", m_scene_entity, m_node_flag, [this] {
78-
auto transform = m_scene_entity.GetTransform();
61+
// Helpers::DrawEntityControl("Transform", m_scene_entity, m_node_flag, [this] {
62+
// auto transform = m_scene_entity.GetTransform();
7963

80-
glm::vec3 translation, scale, skew;
81-
glm::qua<float> rot_quat;
82-
glm::vec4 perspective;
83-
glm::decompose(transform, scale, rot_quat, translation, skew, perspective);
64+
// glm::vec3 translation, scale, skew;
65+
// glm::qua<float> rot_quat;
66+
// glm::vec4 perspective;
67+
// glm::decompose(transform, scale, rot_quat, translation, skew, perspective);
8468

85-
ImGui::Dummy(ImVec2(0, 3));
86-
Helpers::DrawVec3Control("Position", translation, [&translation](glm::vec3& value) { translation = value; });
69+
// ImGui::Dummy(ImVec2(0, 3));
70+
// Helpers::DrawVec3Control("Position", translation, [&translation](glm::vec3& value) { translation = value; });
8771

88-
glm::vec3 rotation = glm::eulerAngles(rot_quat);
89-
ImGui::Dummy(ImVec2(0, 0.5));
90-
Helpers::DrawVec3Control("Rotation", rotation, [&rotation](glm::vec3& value) { rotation = value; });
72+
// glm::vec3 rotation = glm::eulerAngles(rot_quat);
73+
// ImGui::Dummy(ImVec2(0, 0.5));
74+
// Helpers::DrawVec3Control("Rotation", rotation, [&rotation](glm::vec3& value) { rotation = value; });
9175

92-
ImGui::Dummy(ImVec2(0, 0.5));
93-
Helpers::DrawVec3Control("Scale", scale, [&scale](glm::vec3& value) { scale = value; }, 1.0f);
94-
});
76+
// ImGui::Dummy(ImVec2(0, 0.5));
77+
// Helpers::DrawVec3Control("Scale", scale, [&scale](glm::vec3& value) { scale = value; }, 1.0f);
78+
//});
9579

9680
// Mesh Renderer
9781
// Helpers::DrawEntityComponentControl<MeshComponent>("Mesh Geometry", m_scene_entity, m_node_flag, true,
@@ -354,7 +338,7 @@ namespace Tetragrama::Components
354338
ImGui::OpenPopup("PopupAddComponent");
355339
}
356340

357-
if (ImGui::BeginPopup("PopupAddComponent"))
341+
/*if (ImGui::BeginPopup("PopupAddComponent"))
358342
{
359343
if (ImGui::BeginMenu("Lights"))
360344
{
@@ -379,7 +363,7 @@ namespace Tetragrama::Components
379363
ImGui::EndMenu();
380364
}
381365
ImGui::EndPopup();
382-
}
366+
}*/
383367

384368
ImGui::End();
385369
}

Tetragrama/Components/InspectorViewUIComponent.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,13 @@ namespace Tetragrama::Components
1515
InspectorViewUIComponent();
1616
virtual ~InspectorViewUIComponent();
1717

18-
void Initialize(Layers::ImguiLayer* parent = nullptr, const char* name = "Inspector", bool visibility = true, bool closed = false) override;
18+
void Initialize(Layers::ImguiLayer* parent = nullptr, const char* name = "Inspector", bool visibility = true, bool closed = false) override;
1919

20-
void Update(ZEngine::Core::TimeStep dt) override;
20+
void Update(ZEngine::Core::TimeStep dt) override;
2121

22-
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer) override;
23-
std::future<void> SceneEntitySelectedMessageHandlerAsync(Messengers::GenericMessage<ZEngine::Rendering::Scenes::SceneEntity>&);
24-
std::future<void> SceneEntityUnSelectedMessageHandlerAsync(Messengers::EmptyMessage&);
25-
std::future<void> SceneEntityDeletedMessageHandlerAsync(Messengers::EmptyMessage&);
22+
virtual void Render(ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer) override;
2623

2724
private:
28-
ImGuiTreeNodeFlags m_node_flag;
29-
bool m_recieved_unselected_request{false};
30-
bool m_recieved_deleted_request{false};
31-
ZEngine::Rendering::Scenes::SceneEntity m_scene_entity;
32-
std::mutex m_mutex;
25+
ImGuiTreeNodeFlags m_node_flag;
3326
};
3427
} // namespace Tetragrama::Components

0 commit comments

Comments
 (0)