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

83 lines
3.6 KiB
C++
Raw Normal View History

2021-09-23 10:10:39 +02:00
#pragma once
2024-06-09 12:20:04 +02:00
#include "Graphics/Shader.h"
2021-09-23 10:10:39 +02:00
#include "RenderPass.h"
2025-01-08 19:15:12 +01:00
#include "UI/System.h"
2024-06-09 12:20:04 +02:00
namespace Seele {
2021-09-23 10:10:39 +02:00
DECLARE_NAME_REF(Gfx, Texture2D)
DECLARE_NAME_REF(Gfx, RenderTargetAttachment)
2024-06-09 12:20:04 +02:00
class UIPass : public RenderPass {
public:
2025-01-08 19:15:12 +01:00
UIPass(Gfx::PGraphics graphics, UI::PSystem system);
2023-11-05 10:36:01 +01:00
UIPass(UIPass&&) = default;
UIPass& operator=(UIPass&&) = default;
2021-09-23 10:10:39 +02:00
virtual ~UIPass();
2025-04-11 23:13:19 +02:00
virtual void beginFrame(const Component::Camera& cam, const Component::Transform& transform) override;
2022-04-15 23:45:44 +02:00
virtual void render() override;
virtual void endFrame() override;
2021-09-23 10:10:39 +02:00
virtual void publishOutputs() override;
virtual void createRenderPass() override;
2024-06-09 12:20:04 +02:00
2026-10-13 21:49:28 +02:00
// input: the owning view forwards its window callbacks here (window-relative coords)
void mouseMove(Vector2 position) { system->mouseMove(position); }
void mouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier, Vector2 position) {
system->mouseButton(button, action, (KeyModifier)modifier, position);
}
void scroll(Vector2 delta) { system->scroll(delta); }
void key(KeyCode code, InputAction action, KeyModifierFlags modifier, char text = 0) { system->key(code, action, (KeyModifier)modifier, text); }
2024-06-09 12:20:04 +02:00
private:
2025-01-12 11:26:52 +01:00
struct RenderElementStyle {
float x;
float y;
float w;
float h;
2026-11-05 22:31:04 +01:00
// Layout is locked 1:1 to the Slang std430 struct (UIPass.slang::RenderElementStyle).
// Offsets (both sides): x/y/w/h @0/4/8/12, color @16 (12B, 16B-aligned in std430),
// opacity @28, z @32, textureIndex @36, uvOffset @40, uvSize @48, pad @56, sizeof=64.
//
// The trailing `pad` (Vector2) is LOAD-BEARING: the Slang std430 struct is 16B-aligned
// (because of the float3), so its stride is sizeof=64. On platforms where the C++ side
// aligns to 4 (alignof(glm::vec3)==4), the natural sizeof would be 56 and the CPU would
// pack elements at 56B — desyncing element 1's data against the GPU's 64B stride and
// corrupting every field from uvSize onward. `pad` forces sizeof==64 on ALL platforms.
//
// Do NOT reorder, remove, or shrink `pad`, and do NOT insert fields between existing ones
// without updating BOTH this struct AND the Slang struct AND re-verifying the offsets
// (slangc + spirv-dis, and a static_assert on the C++ side if available).
Vector color; // glm::vec3 (12B; std430 aligns it to 16B, C++ aligns per ABI)
2025-01-12 11:26:52 +01:00
float opacity = 1;
float z = 0;
2025-03-20 20:15:38 +01:00
uint32 textureIndex = std::numeric_limits<uint32>::max();
2026-10-21 21:21:49 +02:00
// UV rect for textured quads (glyphs: their rect in the font atlas); unused for untextured quads
Vector2 uvOffset = Vector2(0);
Vector2 uvSize = Vector2(1);
2026-11-05 22:31:04 +01:00
Vector2 pad; // do not remove — see layout comment above
2025-01-08 19:15:12 +01:00
};
Gfx::RenderTargetAttachment colorAttachment;
2024-02-01 10:21:36 +01:00
Gfx::RenderTargetAttachment depthAttachment;
2023-11-01 23:12:30 +01:00
Gfx::OTexture2D depthBuffer;
2021-09-23 10:10:39 +02:00
2025-01-08 19:15:12 +01:00
Gfx::ODescriptorLayout uiDescriptorLayout;
2025-08-10 19:16:55 +02:00
Gfx::ODescriptorSet uiDescriptorSet;
2023-10-26 18:37:29 +02:00
2025-08-10 19:16:55 +02:00
Gfx::ODescriptorSet viewParamsSet;
2025-05-06 19:36:43 +02:00
2025-01-08 19:15:12 +01:00
Gfx::OVertexShader uiVertexShader;
Gfx::OFragmentShader uiFragmentShader;
Gfx::OPipelineLayout uiPipelineLayout;
Gfx::PGraphicsPipeline uiPipeline;
2025-01-12 11:26:52 +01:00
UI::PSystem system;
Array<UI::UIRender> renderElements;
Array<RenderElementStyle> elements;
Gfx::OShaderBuffer elementBuffer;
2025-03-07 21:48:27 +01:00
constexpr static const char* ELEMENT_NAME = "elements";
2026-10-20 22:01:51 +02:00
Gfx::OSampler uiSampler;
2025-03-07 21:48:27 +01:00
constexpr static const char* GLYPHSAMPLER_NAME = "glyphSampler";
2024-06-20 21:57:26 +02:00
Array<Gfx::PTexture2D> usedTextures;
2025-03-07 21:48:27 +01:00
constexpr static const char* TEXTURES_NAME = "textures";
2021-09-23 10:10:39 +02:00
};
DEFINE_REF(UIPass);
} // namespace Seele