2021-09-23 10:10:39 +02:00
|
|
|
#include "UIPass.h"
|
|
|
|
|
#include "RenderGraph.h"
|
|
|
|
|
#include "Graphics/Graphics.h"
|
|
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2021-10-01 19:55:04 +02:00
|
|
|
UIPass::UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment)
|
|
|
|
|
: RenderPass(graphics, viewport)
|
2021-09-23 10:10:39 +02:00
|
|
|
, renderTarget(attachment)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIPass::~UIPass()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-09 12:38:02 +01:00
|
|
|
MainJob UIPass::beginFrame()
|
2021-09-23 10:10:39 +02:00
|
|
|
{
|
2021-12-09 12:38:02 +01:00
|
|
|
co_return;
|
2021-09-23 10:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-02 13:00:03 +01:00
|
|
|
MainJob UIPass::render()
|
2021-09-23 10:10:39 +02:00
|
|
|
{
|
|
|
|
|
graphics->beginRenderPass(renderPass);
|
|
|
|
|
Gfx::PRenderCommand command = graphics->createRenderCommand("UIPassCommand");
|
|
|
|
|
command->setViewport(viewport);
|
|
|
|
|
command->bindPipeline(pipeline);
|
|
|
|
|
command->draw(4, 1, 0, 0);
|
|
|
|
|
graphics->executeCommands(Array<Gfx::PRenderCommand>({command}));
|
|
|
|
|
graphics->endRenderPass();
|
2021-11-24 12:10:23 +01:00
|
|
|
co_return;
|
2021-09-23 10:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-09 12:38:02 +01:00
|
|
|
MainJob UIPass::endFrame()
|
2021-09-23 10:10:39 +02:00
|
|
|
{
|
2021-12-09 12:38:02 +01:00
|
|
|
co_return;
|
2021-09-23 10:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UIPass::publishOutputs()
|
|
|
|
|
{
|
|
|
|
|
TextureCreateInfo depthBufferInfo;
|
|
|
|
|
// Even if we only render to part of an image, we need to make sure
|
|
|
|
|
// that the depthbuffer is the same size or they can't be used in the same
|
|
|
|
|
// framebuffer
|
|
|
|
|
depthBufferInfo.width = viewport->getOwner()->getSizeX();
|
|
|
|
|
depthBufferInfo.height = viewport->getOwner()->getSizeY();
|
|
|
|
|
depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT;
|
|
|
|
|
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
|
|
|
|
|
|
|
|
|
depthBuffer = graphics->createTexture2D(depthBufferInfo);
|
|
|
|
|
depthAttachment =
|
|
|
|
|
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
|
|
|
|
depthAttachment->clear.depthStencil.depth = 1.0f;
|
2021-10-01 19:55:04 +02:00
|
|
|
resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
|
2021-09-23 10:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UIPass::createRenderPass()
|
|
|
|
|
{
|
|
|
|
|
std::ifstream codeStream("./shaders/UIPass.slang", std::ios::ate);
|
|
|
|
|
auto fileSize = codeStream.tellg();
|
|
|
|
|
codeStream.seekg(0);
|
|
|
|
|
Array<char> buffer(static_cast<uint32>(fileSize));
|
|
|
|
|
codeStream.read(buffer.data(), fileSize);
|
|
|
|
|
|
|
|
|
|
ShaderCreateInfo createInfo;
|
|
|
|
|
createInfo.shaderCode.add(std::string(buffer.data()));
|
|
|
|
|
createInfo.name = "UIVertex";
|
|
|
|
|
createInfo.entryPoint = "vertexMain";
|
|
|
|
|
vertexShader = graphics->createVertexShader(createInfo);
|
|
|
|
|
|
|
|
|
|
createInfo.name = "UIFragment";
|
|
|
|
|
createInfo.entryPoint = "fragmentMain";
|
|
|
|
|
fragmentShader = graphics->createFragmentShader(createInfo);
|
|
|
|
|
declaration = graphics->createVertexDeclaration({});
|
|
|
|
|
pipelineLayout = graphics->createPipelineLayout();
|
|
|
|
|
pipelineLayout->create();
|
|
|
|
|
|
|
|
|
|
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(renderTarget, depthAttachment);
|
|
|
|
|
renderPass = graphics->createRenderPass(layout, viewport);
|
|
|
|
|
|
|
|
|
|
GraphicsPipelineCreateInfo pipelineInfo;
|
|
|
|
|
pipelineInfo.vertexDeclaration = declaration;
|
|
|
|
|
pipelineInfo.vertexShader = vertexShader;
|
|
|
|
|
pipelineInfo.fragmentShader = fragmentShader;
|
|
|
|
|
pipelineInfo.renderPass = renderPass;
|
|
|
|
|
pipelineInfo.pipelineLayout = pipelineLayout;
|
|
|
|
|
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
|
|
|
|
|
pipelineInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
|
|
|
|
|
|
|
|
|
|
pipeline = graphics->createGraphicsPipeline(pipelineInfo);
|
|
|
|
|
}
|