mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Work on character rendering and frustrum culling etc
This commit is contained in:
parent
fc5294eb0f
commit
7dd1dada5f
16 changed files with 559 additions and 138 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "game/character.hpp"
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vk_mem_alloc.h>
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
|
@ -15,6 +16,7 @@ class CharacterRenderer;
|
|||
class Camera;
|
||||
class VkContext;
|
||||
class VkTexture;
|
||||
class VkRenderTarget;
|
||||
|
||||
class CharacterPreview {
|
||||
public:
|
||||
|
|
@ -36,8 +38,15 @@ public:
|
|||
void render();
|
||||
void rotate(float yawDelta);
|
||||
|
||||
// TODO: Vulkan offscreen render target for preview
|
||||
VkTexture* getTextureId() const { return nullptr; }
|
||||
// Off-screen composite pass — call from Renderer::beginFrame() before main render pass
|
||||
void compositePass(VkCommandBuffer cmd, uint32_t frameIndex);
|
||||
|
||||
// Mark that the preview needs compositing this frame (call from UI each frame)
|
||||
void requestComposite() { compositeRequested_ = true; }
|
||||
|
||||
// Returns the ImGui texture handle. Returns VK_NULL_HANDLE until the first
|
||||
// compositePass has run (image is in UNDEFINED layout before that).
|
||||
VkDescriptorSet getTextureId() const { return compositeRendered_ ? imguiTextureId_ : VK_NULL_HANDLE; }
|
||||
int getWidth() const { return fboWidth_; }
|
||||
int getHeight() const { return fboHeight_; }
|
||||
|
||||
|
|
@ -51,17 +60,35 @@ private:
|
|||
void destroyFBO();
|
||||
|
||||
pipeline::AssetManager* assetManager_ = nullptr;
|
||||
VkContext* vkCtx_ = nullptr;
|
||||
std::unique_ptr<CharacterRenderer> charRenderer_;
|
||||
std::unique_ptr<Camera> camera_;
|
||||
|
||||
// TODO: Vulkan offscreen render target
|
||||
// VkRenderTarget* renderTarget_ = nullptr;
|
||||
// Off-screen render target (color + depth)
|
||||
std::unique_ptr<VkRenderTarget> renderTarget_;
|
||||
|
||||
// Per-frame UBO for preview camera/lighting (double-buffered)
|
||||
static constexpr uint32_t MAX_FRAMES = 2;
|
||||
VkDescriptorPool previewDescPool_ = VK_NULL_HANDLE;
|
||||
VkBuffer previewUBO_[MAX_FRAMES] = {};
|
||||
VmaAllocation previewUBOAlloc_[MAX_FRAMES] = {};
|
||||
void* previewUBOMapped_[MAX_FRAMES] = {};
|
||||
VkDescriptorSet previewPerFrameSet_[MAX_FRAMES] = {};
|
||||
|
||||
// Dummy 1x1 white texture for shadow map placeholder
|
||||
std::unique_ptr<VkTexture> dummyWhiteTex_;
|
||||
|
||||
// ImGui texture handle for displaying the preview (VkDescriptorSet in Vulkan backend)
|
||||
VkDescriptorSet imguiTextureId_ = VK_NULL_HANDLE;
|
||||
|
||||
static constexpr int fboWidth_ = 400;
|
||||
static constexpr int fboHeight_ = 500;
|
||||
|
||||
static constexpr uint32_t PREVIEW_MODEL_ID = 9999;
|
||||
uint32_t instanceId_ = 0;
|
||||
bool modelLoaded_ = false;
|
||||
bool compositeRequested_ = false;
|
||||
bool compositeRendered_ = false; // True after first successful compositePass
|
||||
float modelYaw_ = 180.0f;
|
||||
|
||||
// Cached info from loadCharacter() for later recompositing.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ public:
|
|||
CharacterRenderer();
|
||||
~CharacterRenderer();
|
||||
|
||||
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout, pipeline::AssetManager* am);
|
||||
bool initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayout, pipeline::AssetManager* am,
|
||||
VkRenderPass renderPassOverride = VK_NULL_HANDLE);
|
||||
void shutdown();
|
||||
|
||||
void setAssetManager(pipeline::AssetManager* am) { assetManager = am; }
|
||||
|
|
@ -219,7 +220,9 @@ public:
|
|||
|
||||
private:
|
||||
VkContext* vkCtx_ = nullptr;
|
||||
VkRenderPass renderPassOverride_ = VK_NULL_HANDLE;
|
||||
pipeline::AssetManager* assetManager = nullptr;
|
||||
int renderLogCounter_ = 0; // per-instance debug counter
|
||||
|
||||
// Vulkan pipelines (one per blend mode)
|
||||
VkPipeline opaquePipeline_ = VK_NULL_HANDLE;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ class M2Renderer;
|
|||
class Minimap;
|
||||
class WorldMap;
|
||||
class QuestMarkerRenderer;
|
||||
class CharacterPreview;
|
||||
class Shader;
|
||||
|
||||
class Renderer {
|
||||
|
|
@ -239,6 +240,10 @@ private:
|
|||
int shadowPostMoveFrames_ = 0; // transition marker for movement->idle shadow recenter
|
||||
|
||||
public:
|
||||
// Character preview registration (for off-screen composite pass)
|
||||
void registerPreview(CharacterPreview* preview);
|
||||
void unregisterPreview(CharacterPreview* preview);
|
||||
|
||||
void setShadowsEnabled(bool enabled) { shadowsEnabled = enabled; }
|
||||
bool areShadowsEnabled() const { return shadowsEnabled; }
|
||||
void setMsaaSamples(VkSampleCountFlagBits samples);
|
||||
|
|
@ -384,6 +389,9 @@ private:
|
|||
void destroyPerFrameResources();
|
||||
void updatePerFrameUBO();
|
||||
|
||||
// Active character previews for off-screen rendering
|
||||
std::vector<CharacterPreview*> activePreviews_;
|
||||
|
||||
bool terrainEnabled = true;
|
||||
bool terrainLoaded = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,9 +25,10 @@ public:
|
|||
/**
|
||||
* Create the render target with given dimensions and format.
|
||||
* Creates: color image, image view, sampler, render pass, framebuffer.
|
||||
* When withDepth is true, also creates a D32_SFLOAT depth attachment.
|
||||
*/
|
||||
bool create(VkContext& ctx, uint32_t width, uint32_t height,
|
||||
VkFormat format = VK_FORMAT_R8G8B8A8_UNORM);
|
||||
VkFormat format = VK_FORMAT_R8G8B8A8_UNORM, bool withDepth = false);
|
||||
|
||||
/**
|
||||
* Destroy all Vulkan resources.
|
||||
|
|
@ -48,6 +49,7 @@ public:
|
|||
void endPass(VkCommandBuffer cmd);
|
||||
|
||||
// Accessors
|
||||
VkImage getColorImage() const { return colorImage_.image; }
|
||||
VkImageView getColorImageView() const { return colorImage_.imageView; }
|
||||
VkSampler getSampler() const { return sampler_; }
|
||||
VkRenderPass getRenderPass() const { return renderPass_; }
|
||||
|
|
@ -62,6 +64,8 @@ public:
|
|||
|
||||
private:
|
||||
AllocatedImage colorImage_{};
|
||||
AllocatedImage depthImage_{};
|
||||
bool hasDepth_ = false;
|
||||
VkSampler sampler_ = VK_NULL_HANDLE;
|
||||
VkRenderPass renderPass_ = VK_NULL_HANDLE;
|
||||
VkFramebuffer framebuffer_ = VK_NULL_HANDLE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue