Files
WoWee/include/rendering/overlay_system.hpp
Kelsi ac02a87ad4 perf(render): skip redundant mega-bone uploads and cache selection circle floor
prepareRender() re-uploaded every animated M2 instance's bone matrices
into the mega bone SSBO every frame — including the majority whose
bones were never recomputed because they are distance, frustum, or
frame-skip culled and keep their previous matrices. The bonesDirty
flag computeBoneMatrices() sets was never consumed. Track the slot
each instance last uploaded to per frame index and memcpy only when
the bones changed or the slot moved, cutting megabytes of redundant
host-visible writes per frame in doodad-dense scenes.

The selection circle also re-ran terrain/WMO/M2 floor raycasts every
frame; reuse the result while the target's position is unchanged,
refreshing every 30 frames so streamed-in geometry still snaps.
2026-07-12 08:30:15 -07:00

81 lines
2.8 KiB
C++

#pragma once
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <vulkan/vulkan.h>
#include <vk_mem_alloc.h>
#include <functional>
#include <optional>
namespace wowee {
namespace rendering {
class VkContext;
/// Manages selection circle and fullscreen overlay Vulkan pipelines.
/// Extracted from Renderer to isolate overlay rendering resources.
class OverlaySystem {
public:
/// Height query callable: returns floor height at (x, y) or (x, y, probeZ).
using HeightQuery2D = std::function<std::optional<float>(float x, float y)>;
using HeightQuery3D = std::function<std::optional<float>(float x, float y, float probeZ)>;
explicit OverlaySystem(VkContext* ctx);
~OverlaySystem();
OverlaySystem(const OverlaySystem&) = delete;
OverlaySystem& operator=(const OverlaySystem&) = delete;
// Selection circle
void setSelectionCircle(const glm::vec3& pos, float radius, const glm::vec3& color);
void clearSelectionCircle();
void renderSelectionCircle(const glm::mat4& view, const glm::mat4& projection,
VkCommandBuffer cmd,
HeightQuery2D terrainHeight,
HeightQuery3D wmoHeight,
HeightQuery3D m2Height);
// Fullscreen color overlay (underwater tint, etc.)
void renderOverlay(const glm::vec4& color, VkCommandBuffer cmd);
/// Destroy all Vulkan resources (called before VkContext teardown).
void cleanup();
/// Recreate pipelines after swapchain resize / MSAA change.
void recreatePipelines();
private:
void initSelectionCircle();
void initOverlayPipeline();
VkContext* vkCtx_ = nullptr;
// Selection circle resources
VkPipeline selCirclePipeline_ = VK_NULL_HANDLE;
VkPipelineLayout selCirclePipelineLayout_ = VK_NULL_HANDLE;
::VkBuffer selCircleVertBuf_ = VK_NULL_HANDLE;
VmaAllocation selCircleVertAlloc_ = VK_NULL_HANDLE;
::VkBuffer selCircleIdxBuf_ = VK_NULL_HANDLE;
VmaAllocation selCircleIdxAlloc_ = VK_NULL_HANDLE;
int selCircleVertCount_ = 0;
glm::vec3 selCirclePos_{0.0f};
glm::vec3 selCircleColor_{1.0f, 0.0f, 0.0f};
float selCircleRadius_ = 1.5f;
bool selCircleVisible_ = false;
// Floor-snap cache: the terrain/WMO/M2 floor queries are collision
// raycasts, so reuse the result while the target stands still. Refreshed
// periodically in case world geometry streams in around the target.
glm::vec3 selCircleFloorCachePos_{0.0f};
float selCircleFloorCacheZ_ = 0.0f;
int selCircleFloorCacheAge_ = -1; // -1 = invalid; counts frames since query
// Fullscreen overlay resources
VkPipeline overlayPipeline_ = VK_NULL_HANDLE;
VkPipelineLayout overlayPipelineLayout_ = VK_NULL_HANDLE;
};
} // namespace rendering
} // namespace wowee