Files
Seele/src/Engine/Graphics/RenderPass/TextPass.h
T

79 lines
2.0 KiB
C++
Raw Normal View History

2022-04-15 11:19:30 +02:00
#pragma once
#include "Asset/FontAsset.h"
2023-11-15 17:42:57 +01:00
#include "Graphics/Shader.h"
2024-06-09 12:20:04 +02:00
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
2022-04-15 11:19:30 +02:00
2024-06-09 12:20:04 +02:00
namespace Seele {
2022-04-15 11:19:30 +02:00
DECLARE_NAME_REF(Gfx, Texture2D)
2023-08-28 21:23:13 +02:00
DECLARE_NAME_REF(Gfx, ShaderBuffer)
2024-06-09 12:20:04 +02:00
struct TextRender {
2022-04-15 11:19:30 +02:00
std::string text;
PFontAsset font;
2023-01-21 18:43:21 +01:00
Vector4 textColor;
Vector2 position;
2022-04-15 11:19:30 +02:00
float scale;
};
2024-06-09 12:20:04 +02:00
class TextPass : public RenderPass {
public:
2023-10-26 18:37:29 +02:00
TextPass(Gfx::PGraphics graphics, PScene scene);
2023-11-05 10:36:01 +01:00
TextPass(TextPass&&) = default;
TextPass& operator=(TextPass&&) = default;
2022-04-15 11:19:30 +02:00
virtual ~TextPass();
2022-11-17 16:47:42 +01:00
virtual void beginFrame(const Component::Camera& cam) override;
2022-04-15 23:45:44 +02:00
virtual void render() override;
virtual void endFrame() override;
2022-04-15 11:19:30 +02:00
virtual void publishOutputs() override;
virtual void createRenderPass() override;
2024-06-09 12:20:04 +02:00
private:
struct GlyphData {
2023-01-21 18:43:21 +01:00
Vector2 bearing;
Vector2 size;
2022-04-17 09:10:20 +02:00
uint32 advance;
2022-04-15 11:19:30 +02:00
};
2024-06-09 12:20:04 +02:00
struct GlyphInstanceData {
2023-01-21 18:43:21 +01:00
Vector2 position;
Vector2 widthHeight;
2022-04-17 09:10:20 +02:00
uint32 glyphIndex;
};
2024-06-09 12:20:04 +02:00
struct TextData {
2023-01-21 18:43:21 +01:00
Vector4 textColor;
2022-04-17 09:10:20 +02:00
float scale;
2022-04-15 11:19:30 +02:00
};
2024-06-09 12:20:04 +02:00
struct FontData {
2022-04-15 23:45:44 +02:00
Gfx::PDescriptorSet textureArraySet;
2022-04-17 09:10:20 +02:00
Array<GlyphData> glyphDataSet;
2022-04-15 11:19:30 +02:00
Map<uint32, uint32> characterToGlyphIndex;
};
FontData& getFontData(PFontAsset font);
Map<PFontAsset, FontData> fontData;
2024-06-09 12:20:04 +02:00
struct TextResources {
2023-11-15 17:42:57 +01:00
Gfx::PShaderBuffer instanceBuffer;
2022-04-15 23:45:44 +02:00
Gfx::PDescriptorSet textureArraySet;
2022-04-17 09:10:20 +02:00
TextData textData;
2022-04-15 11:19:30 +02:00
};
2023-10-26 18:37:29 +02:00
Map<PFontAsset, Array<TextResources>> textResources;
2022-04-15 11:19:30 +02:00
2024-02-01 10:21:36 +01:00
Gfx::RenderTargetAttachment renderTarget;
Gfx::RenderTargetAttachment depthAttachment;
2022-04-15 11:19:30 +02:00
2023-11-05 10:36:01 +01:00
Gfx::ODescriptorLayout generalLayout;
Gfx::ODescriptorLayout textureArrayLayout;
2022-04-15 11:19:30 +02:00
2022-04-15 23:45:44 +02:00
Gfx::PDescriptorSet generalSet;
2023-11-05 10:36:01 +01:00
Gfx::OUniformBuffer projectionBuffer;
2023-11-15 17:42:57 +01:00
Gfx::OSampler glyphSampler;
2022-04-15 11:19:30 +02:00
2023-11-05 10:36:01 +01:00
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
2024-04-19 18:23:36 +02:00
Gfx::OPipelineLayout pipelineLayout;
2023-11-09 22:15:51 +01:00
Gfx::PGraphicsPipeline pipeline;
2023-10-26 18:37:29 +02:00
Array<TextRender> texts;
2022-04-15 11:19:30 +02:00
};
DEFINE_REF(TextPass);
} // namespace Seele