basic flow layout

This commit is contained in:
Dynamitos
2025-01-12 11:26:52 +01:00
parent e487867f96
commit 2915db8898
18 changed files with 415 additions and 172 deletions
+99 -32
View File
@@ -8,8 +8,9 @@
using namespace Seele;
UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphics) {
UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphics), system(system) {
glyphInstanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "GlyphInstanceBuffer"});
elementBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "RenderStyleElements"});
textDescriptorLayout = graphics->createDescriptorLayout("pText");
textDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
@@ -28,15 +29,24 @@ UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphic
textPipelineLayout->addDescriptorLayout(viewParamsLayout);
textPipelineLayout->addDescriptorLayout(textDescriptorLayout);
uiDescriptorLayout = graphics->createDescriptorLayout("pParams");
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
uiDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.descriptorCount = 1024,
});
uiPipelineLayout = graphics->createPipelineLayout("UIPipeline");
uiPipelineLayout->addDescriptorLayout(viewParamsLayout);
uiPipelineLayout->addDescriptorLayout(uiDescriptorLayout);
// todo:
texts.add(TextRender{
.text = "TestText123",
.font = AssetRegistry::findFont("", "arial"),
.fontSize = 12,
.position = Vector2(0, 100),
});
}
UIPass::~UIPass() {}
@@ -45,35 +55,49 @@ void UIPass::beginFrame(const Component::Camera& cam) {
RenderPass::beginFrame(cam);
glyphs.clear();
usedTextures.clear();
for (TextRender& render : texts) {
TextResources& res = textResources[render.font].add();
float x = render.position.x * viewport->getContentScaleX();
float y = (viewport->getHeight() - render.position.y) * viewport->getContentScaleY();
for (uint32 c : render.text) {
const FontAsset::Glyph& glyph = render.font->getGlyphData(c);
Vector2 bearing = Vector2(glyph.bearing) * viewport->getContentScaleX();
Vector2 size = Vector2(glyph.size) * viewport->getContentScaleY();
float xpos = x + glyph.bearing.x;
float ypos = y + (size.y - bearing.y);
float w = size.x;
float h = size.y;
glyphs.add(GlyphInstanceData{
.x = xpos,
.y = ypos,
.width = w,
.height = h,
.glyphIndex = (uint32)usedTextures.size(),
for (const auto& render : renderElements) {
float x = render.position.x;
float y = render.position.y;
if (render.text.empty()) {
//todo: convert using actual tree depth
elements.add(RenderElementStyle{
.x = x,
.y = y,
.w = render.dimensions.x,
.h = render.dimensions.y,
.color = render.backgroundColor,
.z = render.level / 100.f,
});
usedTextures.add(glyph.texture);
x += glyph.advance >> 6;
} else {
y = y + render.fontSize;
for (uint32 c : render.text) {
const FontAsset::Glyph& glyph = render.font->getGlyphData(c);
Vector2 bearing = Vector2(glyph.bearing);
Vector2 size = Vector2(glyph.size);
float xpos = x + glyph.bearing.x;
float ypos = y - bearing.y;
float w = size.x;
float h = size.y;
glyphs.add(GlyphInstanceData{
.x = xpos,
.y = ypos,
.z = render.level / 100.0f,
.width = w,
.height = h,
.glyphIndex = (uint32)usedTextures.size(),
});
usedTextures.add(glyph.texture);
x += glyph.advance / 64.0f;
}
}
}
glyphInstanceBuffer->rotateBuffer(sizeof(GlyphInstanceData) * glyphs.size());
glyphInstanceBuffer->updateContents(0, sizeof(GlyphInstanceData) * glyphs.size(), glyphs.data());
glyphInstanceBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT);
textDescriptorLayout->reset();
textDescriptorSet = textDescriptorLayout->allocateDescriptorSet();
textDescriptorSet->updateBuffer(0, 0, glyphInstanceBuffer);
@@ -82,6 +106,16 @@ void UIPass::beginFrame(const Component::Camera& cam) {
textDescriptorSet->updateTexture(2, i, usedTextures[i]);
}
textDescriptorSet->writeChanges();
elementBuffer->rotateBuffer(sizeof(RenderElementStyle) * elements.size());
elementBuffer->updateContents(0, sizeof(RenderElementStyle) * elements.size(), elements.data());
elementBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT);
uiDescriptorLayout->reset();
uiDescriptorSet = uiDescriptorLayout->allocateDescriptorSet();
uiDescriptorSet->updateBuffer(0, 0, elementBuffer);
uiDescriptorSet->updateSampler(1, 0, glyphSampler);
uiDescriptorSet->writeChanges();
}
void UIPass::render() {
@@ -89,6 +123,9 @@ void UIPass::render() {
Array<Gfx::ORenderCommand> commands;
Gfx::ORenderCommand command = graphics->createRenderCommand("TextPassCommand");
command->setViewport(viewport);
command->bindPipeline(uiPipeline);
command->bindDescriptor({viewParamsSet, uiDescriptorSet});
command->draw(4, elements.size(), 0, 0);
command->bindPipeline(textPipeline);
command->bindDescriptor({viewParamsSet, textDescriptorSet});
command->draw(4, glyphs.size(), 0, 0);
@@ -142,7 +179,7 @@ void UIPass::createRenderPass() {
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
});
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
textPipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
.vertexShader = textVertexShader,
.fragmentShader = textFragmentShader,
@@ -167,15 +204,45 @@ void UIPass::createRenderPass() {
Gfx::SE_COLOR_COMPONENT_A_BIT,
}},
},
};
});
textPipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
graphics->beginShaderCompilation(ShaderCompilationInfo{
.name = "UIVertex",
.modules = {"UIPass"},
.entryPoints = {{"vertexMain", "UIPass"}, {"fragmentMain", "UIPass"}},
.rootSignature = uiPipelineLayout,
});
uiPipelineLayout->create();
uiVertexShader = graphics->createVertexShader({0});
uiFragmentShader = graphics->createFragmentShader({1});
uiPipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
.vertexShader = uiVertexShader,
.fragmentShader = uiFragmentShader,
.renderPass = renderPass,
.pipelineLayout = uiPipelineLayout,
.rasterizationState =
{
.cullMode = Gfx::SE_CULL_MODE_NONE,
},
.colorBlend =
{
.attachmentCount = 1,
.blendAttachments = {{
.blendEnable = true,
.srcColorBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA,
.dstColorBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.srcAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
.dstAlphaBlendFactor = Gfx::SE_BLEND_FACTOR_ZERO,
.alphaBlendOp = Gfx::SE_BLEND_OP_ADD,
.colorWriteMask = Gfx::SE_COLOR_COMPONENT_R_BIT | Gfx::SE_COLOR_COMPONENT_G_BIT | Gfx::SE_COLOR_COMPONENT_B_BIT |
Gfx::SE_COLOR_COMPONENT_A_BIT,
}},
},
});
system->style();
system->layout(UVector2(viewport->getWidth(), viewport->getHeight()));
renderElements = system->render();
}