Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tetragrama/Components/HierarchyViewUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace Tetragrama::Components
{
auto* mc = actor->GetComponent<MeshComponent>();
if (mc && mc->RenderInstanceId != UINT32_MAX)
current_scene->RemoveMeshInstance(mc->RenderInstanceId);
current_scene->RemoveMeshInstance(mc->RenderInstanceId, ctx->RenderResourceManager);
if (selected)
current_scene->SelectedActorHandle = {};
pending_delete = h;
Expand Down
3 changes: 0 additions & 3 deletions Tetragrama/Components/ProjectViewUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ namespace Tetragrama::Components
char name[MAX_FILE_PATH_COUNT];
entry.Path.CopyFilename(name, sizeof(name));

// --- UE thumbnail-first card layout ---
// Icon fills the top portion, name overlaid on a semi-transparent footer strip.
const float sz = m_thumbnail_size;
const float pad = 6.0f;
Expand Down Expand Up @@ -324,7 +323,6 @@ namespace Tetragrama::Components
ImGui::EndPopup();
}

// ---- DrawList rendering ----
ImDrawList* dl = ImGui::GetWindowDrawList();
ImVec2 icon_end = {origin.x + card_w, origin.y + sz};

Expand All @@ -344,7 +342,6 @@ namespace Tetragrama::Components
if (!dark_theme)
dl->AddRect(origin, card_end, card_border, rounding, 0, 1.0f);

// --- Icon (vector, centered in the thumbnail area) ---
// When a per-asset thumbnail is ready, call
// dl->AddImage((ImTextureID)(intptr_t)thumb.Index, ixo, {ixo.x + ic, ixo.y + ic * 0.92f})
// instead of DrawContentIcon().
Expand Down
2 changes: 0 additions & 2 deletions ZEngine/ZEngine/Core/VFS/Meta/MetaFileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ namespace ZEngine::Core::VFS
}
} // namespace

// -------------------------------------------------------------------------
// MetaFileIO
// -------------------------------------------------------------------------

VFSPath MetaFileIO::MetaPathFor(const VFSPath& asset_path)
{
Expand Down
4 changes: 0 additions & 4 deletions ZEngine/ZEngine/Core/VFS/Registry/DependencyGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace ZEngine::Core::VFS
{
// -------------------------------------------------------------------------
// AdjacencyList
// -------------------------------------------------------------------------

bool AdjacencyList::Contains(const uuids::uuid& uuid) const
{
Expand Down Expand Up @@ -70,9 +68,7 @@ namespace ZEngine::Core::VFS
return false;
}

// -------------------------------------------------------------------------
// DependencyGraph
// -------------------------------------------------------------------------

void DependencyGraph::Initialize(Core::Memory::ArenaAllocator* arena)
{
Expand Down
14 changes: 0 additions & 14 deletions ZEngine/ZEngine/Rendering/Cameras/FlyCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ namespace ZEngine::Rendering::Cameras
UpdateMatrices();
}

// ---------------------------------------------------------------------------
// Public accessors
// ---------------------------------------------------------------------------

Quaternion<float> FlyCamera::GetOrientation() const
{
Expand All @@ -73,9 +71,7 @@ namespace ZEngine::Rendering::Cameras
return rotate(GetOrientation(), Vec3f(0.0f, 1.0f, 0.0f));
}

// ---------------------------------------------------------------------------
// Configuration
// ---------------------------------------------------------------------------

void FlyCamera::SetViewportSize(float logicalW, float logicalH)
{
Expand All @@ -98,9 +94,7 @@ namespace ZEngine::Rendering::Cameras
m_viewDirty = true;
}

// ---------------------------------------------------------------------------
// OnUpdate — main entry point called once per frame by the controller
// ---------------------------------------------------------------------------

void FlyCamera::OnUpdate(float dt)
{
Expand Down Expand Up @@ -191,9 +185,7 @@ namespace ZEngine::Rendering::Cameras
Input.FlushDeltas();
}

// ---------------------------------------------------------------------------
// Private update methods
// ---------------------------------------------------------------------------

void FlyCamera::UpdateFree(float dt)
{
Expand Down Expand Up @@ -305,9 +297,7 @@ namespace ZEngine::Rendering::Cameras
}
}

// ---------------------------------------------------------------------------
// Focus / bookmarks
// ---------------------------------------------------------------------------

void FlyCamera::FocusOn(Vec3f center, float radius)
{
Expand Down Expand Up @@ -376,9 +366,7 @@ namespace ZEngine::Rendering::Cameras
State = FlyCameraState::Animating;
}

// ---------------------------------------------------------------------------
// Ray unprojection
// ---------------------------------------------------------------------------

FlyCamera::Ray FlyCamera::GetRayFromViewport(float viewportX, float viewportY) const
{
Expand All @@ -400,9 +388,7 @@ namespace ZEngine::Rendering::Cameras
return {Position, mag > 0.0001f ? dir / mag : f};
}

// ---------------------------------------------------------------------------
// Private helpers
// ---------------------------------------------------------------------------

Vec3f FlyCamera::KeyboardMoveDir() const
{
Expand Down
23 changes: 23 additions & 0 deletions ZEngine/ZEngine/Rendering/RenderResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,29 @@ namespace ZEngine::Rendering
return {};
}

void RenderResourceManager::ReleaseMeshGeometry(const uuids::uuid& uuid)
{
std::lock_guard lock(m_uuid_map_mutex);

// Find and invalidate the slot
for (uint32_t i = 0; i < m_uuid_to_buffer_count; ++i)
{
if (m_uuid_to_buffer[i].UUID == uuid)
{
BufferHandle h = m_uuid_to_buffer[i].Handle;

// Free the mesh slot (geometry bytes stay in VB/IB — append-only)
if (h.IsValid() && !(h.Generation & GBUF_GEN_TAG) && h.Index < m_mesh_slot_count)
m_mesh_slots[h.Index].Generation = 0;

// Remove from UUID map (swap with last entry)
m_uuid_to_buffer[i] = m_uuid_to_buffer[--m_uuid_to_buffer_count];
ZENGINE_CORE_INFO("[RRM] Released mesh geometry slot for UUID {}", uuids::to_string(uuid))
return;
}
}
}

void RenderResourceManager::Release(BufferHandle handle)
{
if (!handle.IsValid())
Expand Down
12 changes: 8 additions & 4 deletions ZEngine/ZEngine/Rendering/RenderResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,16 @@ namespace ZEngine::Rendering
void ResetGeometryBuffers();

/// @brief Find the BufferHandle registered for a mesh asset by UUID.
/// @details Returns an invalid handle if the mesh has not been uploaded yet or
/// the UUID is not in the uuid-to-buffer map.
/// @param uuid Asset UUID from the meta file.
/// @return Valid BufferHandle if found; invalid otherwise.
BufferHandle FindMeshBuffer(const uuids::uuid& uuid) const;

/// @brief Release the geometry slot for a mesh and unregister its UUID.
/// @details Frees the MeshSlot so it can be reused by a future upload.
/// The VB/IB bytes are not reclaimed (append-only buffer) but the
/// slot index becomes available for the next UploadMesh call.
/// No-op if the UUID is not registered.
/// @param uuid Asset UUID of the mesh to release.
void ReleaseMeshGeometry(const uuids::uuid& uuid);

/// @brief Write CPU data into an existing HOST_VISIBLE BufferView.
/// @details Uses the ring allocator for staging; falls back to a one-shot staging
/// buffer and RecordAndSubmit. Render-thread only.
Expand Down
23 changes: 22 additions & 1 deletion ZEngine/ZEngine/Rendering/Scenes/RenderScene.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <ZEngine/Rendering/RenderResourceManager.h>
#include <ZEngine/Rendering/Scenes/RenderScene.h>
#include <cstring>

Expand Down Expand Up @@ -35,20 +36,40 @@ namespace ZEngine::Rendering::Scenes
return id;
}

void RenderScene::RemoveMeshInstance(uint32_t id)
void RenderScene::RemoveMeshInstance(uint32_t id, Rendering::RenderResourceManager* rrm)
{
uuids::uuid freed_uuid;

SeqBeginWrite();

for (uint32_t i = 0; i < Instances.size(); ++i)
{
if (Instances[i].Id == id)
{
freed_uuid = Instances[i].MeshUUID;
Instances.erase(i);
break;
}
}

SeqEndWrite();

// Release geometry if no other instance references the same mesh UUID.
if (rrm && !freed_uuid.is_nil())
{
bool still_used = false;
for (uint32_t i = 0; i < Instances.size(); ++i)
{
if (Instances[i].MeshUUID == freed_uuid)
{
still_used = true;
break;
}
}
if (!still_used)
rrm->ReleaseMeshGeometry(freed_uuid);
}

MarkInstancesDirty();
}

Expand Down
9 changes: 6 additions & 3 deletions ZEngine/ZEngine/Rendering/Scenes/RenderScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include <ZEngine/ZEngineDef.h>
#include <uuid.h>

namespace ZEngine::Rendering
{
class RenderResourceManager;
}

namespace ZEngine::Rendering::Scenes
{
struct GridConfig
Expand Down Expand Up @@ -108,13 +113,11 @@ namespace ZEngine::Rendering::Scenes
PaddedAtomic<bool> GridDirty[3] = {};
GridConfig Grid = {};

// --- Main-thread-only write operations ---
uint32_t AddMeshInstance(const uuids::uuid& uuid, const char* name);
void RemoveMeshInstance(uint32_t id);
void RemoveMeshInstance(uint32_t id, ZEngine::Rendering::RenderResourceManager* rrm = nullptr);
void SetInstanceTransform(uint32_t id, const Core::Maths::Mat4f& t);
void MarkInstancesDirty();

// --- Render-thread read (seqlock snapshot) ---
// Fills `out` with a consistent copy; retries if a write was in progress.
void GetInstancesSnapshot(Core::Memory::ArenaAllocator* scratch, Core::Containers::Array<MeshInstance>& out) const;

Expand Down
Loading