feat: add 2D rendering pipeline

This commit is contained in:
2026-09-03 00:58:46 +02:00
parent d515a36403
commit c9fb6e991a
11 changed files with 557 additions and 3 deletions
@@ -0,0 +1,45 @@
#ifndef DESTRUM_QUADRENDERINGMANAGER_H
#define DESTRUM_QUADRENDERINGMANAGER_H
#include <vector>
#include <glm/glm.hpp>
#include <destrum/Graphics/ids.h>
#include <destrum/Singleton.h>
struct QuadSubmission {
glm::vec2 position;
glm::vec2 size;
float rotation;
glm::vec4 color;
ImageID textureId;
};
class QuadRenderingManager final : public Singleton<QuadRenderingManager> {
public:
friend class Singleton<QuadRenderingManager>;
void SubmitQuad(
const glm::vec2& position,
const glm::vec2& size,
const glm::vec4& color = glm::vec4{1.0f},
ImageID textureId = NULL_IMAGE_ID);
void SubmitQuad(
const glm::vec2& position,
const glm::vec2& size,
float rotation,
const glm::vec4& color = glm::vec4{1.0f},
ImageID textureId = NULL_IMAGE_ID);
[[nodiscard]] const std::vector<QuadSubmission>& GetQuads() const { return quads; }
void ClearQuads();
private:
QuadRenderingManager() = default;
std::vector<QuadSubmission> quads;
};
#endif // DESTRUM_QUADRENDERINGMANAGER_H
@@ -0,0 +1,47 @@
#ifndef DESTRUM_QUADRENDERERPASS_H
#define DESTRUM_QUADRENDERERPASS_H
#include <cstddef>
#include <memory>
#include <glm/glm.hpp>
#include <vulkan/vulkan.h>
#include <destrum/Graphics/Resources/Buffer.h>
class GfxDevice;
class Pipeline;
struct GPUImage;
class RenderResources;
class QuadRendererPass final {
public:
void init(GfxDevice& gfxDevice, RenderResources& resources, VkFormat drawImageFormat);
void draw(
VkCommandBuffer cmd,
GfxDevice& gfxDevice,
RenderResources& resources,
const GPUImage& target,
const glm::mat4& projection);
void cleanup(GfxDevice& gfxDevice);
private:
struct QuadVertex {
glm::vec2 position;
glm::vec2 uv;
glm::vec4 color;
std::uint32_t textureId;
};
void ensureCapacity(GfxDevice& gfxDevice, std::size_t requiredQuads);
VkPipelineLayout pipelineLayout{VK_NULL_HANDLE};
std::unique_ptr<Pipeline> pipeline;
GPUBuffer vertexBuffer{};
GPUBuffer indexBuffer{};
std::size_t quadCapacity{0};
};
#endif // DESTRUM_QUADRENDERERPASS_H
@@ -1,11 +1,13 @@
#ifndef RENDERER_H
#define RENDERER_H
#include <glm/mat4x4.hpp>
#include <glm/vec3.hpp>
#include <destrum/Graphics/Camera.h>
#include <destrum/Graphics/Pipelines/LineRenderingPass.h>
#include <destrum/Graphics/Pipelines/MeshPipeline.h>
#include <destrum/Graphics/Pipelines/QuadRendererPass.h>
#include <destrum/Graphics/ids.h>
#include <destrum/Graphics/MeshDrawCommand.h>
#include <destrum/Graphics/Resources/NBuffer.h>
@@ -69,6 +71,11 @@ public:
return resources;
}
void drawQuads(
VkCommandBuffer cmd,
GfxDevice& gfxDevice,
const glm::mat4& projection);
private:
void createDrawImage(GfxDevice& gfxDevice, const glm::ivec2& drawImageSize, bool firstCreate);
@@ -113,6 +120,7 @@ private:
std::unique_ptr<MeshPipeline> meshPipeline;
std::unique_ptr<SkyboxPipeline> skyboxPipeline;
std::unique_ptr<LineRenderingPass> lineRenderingPass;
std::unique_ptr<QuadRendererPass> quadRendererPass;
std::unique_ptr<SkinningPipeline> skinningPipeline;
bool initialized{false};