Refactoring basic text rendering

This commit is contained in:
Dynamitos
2025-01-08 19:15:12 +01:00
parent eef78e8aa5
commit e487867f96
70 changed files with 608 additions and 1133 deletions
+52 -14
View File
@@ -1,15 +1,22 @@
#pragma once
#include "Graphics/Shader.h"
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
#include "Asset/FontAsset.h"
#include "UI/System.h"
namespace Seele {
DECLARE_NAME_REF(Gfx, Texture2D)
DECLARE_NAME_REF(Gfx, RenderTargetAttachment)
struct TextRender {
std::string text;
PFontAsset font;
uint32 fontSize;
Vector4 textColor;
Vector2 position;
};
class UIPass : public RenderPass {
public:
UIPass(Gfx::PGraphics graphics, PScene scene);
UIPass(Gfx::PGraphics graphics, UI::PSystem system);
UIPass(UIPass&&) = default;
UIPass& operator=(UIPass&&) = default;
virtual ~UIPass();
@@ -20,23 +27,54 @@ class UIPass : public RenderPass {
virtual void createRenderPass() override;
private:
Gfx::RenderTargetAttachment renderTarget;
Gfx::OTexture2D colorBuffer;
struct GlyphData {
Vector2 bearing;
Vector2 size;
uint32 advance;
};
struct GlyphInstanceData {
float x;
float y;
float width;
float height;
uint32 glyphIndex;
};
struct TextData {
Vector4 textColor;
float scale;
};
struct TextResources {
Gfx::PShaderBuffer instanceBuffer;
Gfx::PDescriptorSet textureArraySet;
TextData textData;
};
Map<PFontAsset, Array<TextResources>> textResources;
Gfx::RenderTargetAttachment colorAttachment;
Gfx::RenderTargetAttachment depthAttachment;
Gfx::OTexture2D depthBuffer;
Gfx::ODescriptorLayout descriptorLayout;
Gfx::PDescriptorSet descriptorSet;
Gfx::ODescriptorLayout textDescriptorLayout;
Gfx::PDescriptorSet textDescriptorSet;
Gfx::OUniformBuffer numTexturesBuffer;
Gfx::OVertexBuffer elementBuffer;
Gfx::OVertexShader textVertexShader;
Gfx::OFragmentShader textFragmentShader;
Gfx::OPipelineLayout textPipelineLayout;
Gfx::PGraphicsPipeline textPipeline;
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::PGraphicsPipeline pipeline;
Gfx::OPipelineLayout pipelineLayout;
Gfx::ODescriptorLayout uiDescriptorLayout;
Gfx::PDescriptorSet uiDescriptorSet;
Array<UI::RenderElementStyle> renderElements;
Gfx::OVertexShader uiVertexShader;
Gfx::OFragmentShader uiFragmentShader;
Gfx::OPipelineLayout uiPipelineLayout;
Gfx::PGraphicsPipeline uiPipeline;
Array<TextRender> texts;
Array<GlyphInstanceData> glyphs;
Gfx::OShaderBuffer glyphInstanceBuffer;
Gfx::OSampler glyphSampler;
Array<Gfx::PTexture2D> usedTextures;
};
DEFINE_REF(UIPass);