Formatted EVERYTHING

This commit is contained in:
Dynamitos
2024-06-09 12:20:53 +02:00
parent f18bf8acbe
commit d95dab850c
265 changed files with 8002 additions and 12310 deletions
+62 -69
View File
@@ -1,40 +1,32 @@
#include "TextPass.h"
#include "Graphics/Command.h"
#include "Graphics/Enums.h"
#include "RenderGraph.h"
#include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h"
#include "Graphics/Command.h"
#include "RenderGraph.h"
using namespace Seele;
TextPass::TextPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
}
TextPass::TextPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {}
TextPass::~TextPass()
{
}
TextPass::~TextPass() {}
void TextPass::beginFrame(const Component::Camera& cam)
{
void TextPass::beginFrame(const Component::Camera& cam) {
RenderPass::beginFrame(cam);
for(TextRender& render : texts)
{
for (TextRender& render : texts) {
FontData& fd = getFontData(render.font);
TextResources& res = textResources[render.font].add();
Array<GlyphInstanceData> instanceData;
float x = render.position.x;
float y = render.position.y;
for(uint32 c : render.text)
{
for (uint32 c : render.text) {
const GlyphData& glyph = fd.glyphDataSet[fd.characterToGlyphIndex[c]];
Vector2 bearing = glyph.bearing;
Vector2 size = glyph.size;
float xpos = x + bearing.x * render.scale;
float ypos = y - (size.y - bearing.y) * render.scale;
float w = size.x * render.scale;
float h = size.y * render.scale;
@@ -46,10 +38,11 @@ void TextPass::beginFrame(const Component::Camera& cam)
x += (glyph.advance >> 6) * render.scale;
}
res.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = static_cast<uint32>(instanceData.size() * sizeof(GlyphInstanceData)),
.data = reinterpret_cast<uint8*>(instanceData.data()),
},
.sourceData =
{
.size = static_cast<uint32>(instanceData.size() * sizeof(GlyphInstanceData)),
.data = reinterpret_cast<uint8*>(instanceData.data()),
},
.numElements = instanceData.size(),
});
@@ -68,48 +61,42 @@ void TextPass::beginFrame(const Component::Camera& cam)
projectionBuffer->updateContents(projectionUpdate);
generalSet->updateBuffer(1, projectionBuffer);
generalSet->writeChanges();
//co_return;
// co_return;
}
void TextPass::render()
{
void TextPass::render() {
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
for(const auto& [fontAsset, res] : textResources)
{
for (const auto& [fontAsset, res] : textResources) {
Gfx::ORenderCommand command = graphics->createRenderCommand("TextPassCommand");
command->setViewport(viewport);
command->bindPipeline(pipeline);
for(const auto& resource : res)
{
for (const auto& resource : res) {
command->bindDescriptor({generalSet, resource.textureArraySet});
//command->bindVertexBuffer({resource.vertexBuffer});
command->pushConstants(Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(TextData), &resource.textData);
//command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0);
// command->bindVertexBuffer({resource.vertexBuffer});
command->pushConstants(Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(TextData),
&resource.textData);
// command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0);
}
commands.add(std::move(command));
}
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
textResources.clear();
//co_return;
// co_return;
}
void TextPass::endFrame()
{
//co_return;
void TextPass::endFrame() {
// co_return;
}
void TextPass::publishOutputs()
{
}
void TextPass::publishOutputs() {}
void TextPass::createRenderPass()
{
void TextPass::createRenderPass() {
renderTarget = resources->requestRenderTarget("UIPASS_COLOR");
depthAttachment = resources->requestRenderTarget("UIPASS_DEPTH");
ShaderCreateInfo createInfo = {
.name = "TextVertex",
.mainModule = "TextPass",
@@ -118,22 +105,35 @@ void TextPass::createRenderPass()
vertexShader = graphics->createVertexShader(createInfo);
createInfo.name = "TextFragment";
createInfo.entryPoint = "fragmentMain";
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
generalLayout = graphics->createDescriptorLayout("pRender");
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,});
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,});
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
generalLayout->create();
textureArrayLayout = graphics->createDescriptorLayout("pGlyphTextures");
textureArrayLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, .textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY, .descriptorCount = 256, .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT,});
textureArrayLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY,
.descriptorCount = 256,
.bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT,
});
textureArrayLayout->create();
projectionBuffer = graphics->createUniformBuffer({
.sourceData = {
.size = sizeof(Matrix4),
.data = nullptr,
},
.sourceData =
{
.size = sizeof(Matrix4),
.data = nullptr,
},
.dynamic = true,
});
@@ -148,22 +148,17 @@ void TextPass::createRenderPass()
generalSet->updateBuffer(0, projectionBuffer);
generalSet->updateSampler(1, glyphSampler);
generalSet->writeChanges();
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(generalLayout);
pipelineLayout->addDescriptorLayout(textureArrayLayout);
pipelineLayout->addPushConstants({
.stageFlags = Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
.offset = 0,
.size = sizeof(TextData)});
pipelineLayout->addPushConstants(
{.stageFlags = Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, .offset = 0, .size = sizeof(TextData)});
pipelineLayout->create();
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = {renderTarget},
.depthAttachment = depthAttachment
};
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{.colorAttachments = {renderTarget}, .depthAttachment = depthAttachment};
renderPass = graphics->createRenderPass(std::move(layout), {}, viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader;
@@ -172,7 +167,8 @@ void TextPass::createRenderPass()
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
pipelineInfo.colorBlend.attachmentCount = 1;
pipelineInfo.colorBlend.blendAttachments[0].blendEnable = true;
pipelineInfo.colorBlend.blendAttachments[0].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;
pipelineInfo.colorBlend.blendAttachments[0].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;
pipelineInfo.colorBlend.blendAttachments[0].srcColorBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA;
pipelineInfo.colorBlend.blendAttachments[0].dstColorBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
pipelineInfo.colorBlend.blendAttachments[0].alphaBlendOp = Gfx::SE_BLEND_OP_ADD;
@@ -183,19 +179,16 @@ void TextPass::createRenderPass()
pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
}
TextPass::FontData& TextPass::getFontData(PFontAsset font)
{
if(fontData.exists(font))
{
TextPass::FontData& TextPass::getFontData(PFontAsset font) {
if (fontData.exists(font)) {
return fontData[font];
}
}
const auto& fontGlyphs = font->getGlyphData();
FontData& fd = fontData[font];
Array<GlyphData> glyphData;
Array<Gfx::PTexture> textures;
glyphData.reserve(fontGlyphs.size());
for(const auto& [key, value] : fontGlyphs)
{
for (const auto& [key, value] : fontGlyphs) {
fd.characterToGlyphIndex[key] = static_cast<uint32>(glyphData.size());
GlyphData& gd = glyphData.add();
gd.bearing = value.bearing;
@@ -204,7 +197,7 @@ TextPass::FontData& TextPass::getFontData(PFontAsset font)
textures.add(font->getTexture(value.textureIndex));
}
fd.glyphDataSet = glyphData;
textureArrayLayout->reset();
fd.textureArraySet = textureArrayLayout->allocateDescriptorSet();
fd.textureArraySet->updateTextureArray(0, textures);