diff --git a/res/shaders/Debug.slang b/res/shaders/Debug.slang new file mode 100644 index 0000000..e69de29 diff --git a/res/shaders/lib/DebugVertexData.slang b/res/shaders/lib/DebugVertexData.slang new file mode 100644 index 0000000..cba4e8e --- /dev/null +++ b/res/shaders/lib/DebugVertexData.slang @@ -0,0 +1,16 @@ +import Common; +import VertexData; +import MaterialParameter; + +struct StaticMeshVertexData : IVertexData +{ + VertexAttributes getAttributes(uint index) + { + VertexAttributes attributes; + attributes.position_MS = float3(positions[3 * index + 0], positions[3 * index + 1], positions[3 * index + 2]); + attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]); + return attributes; + } + StructuredBuffer positions; + StructuredBuffer color; +}; diff --git a/src/Engine/Graphics/RenderPass/DebugPass.cpp b/src/Engine/Graphics/RenderPass/DebugPass.cpp index e0dc0bf..f50fa65 100644 --- a/src/Engine/Graphics/RenderPass/DebugPass.cpp +++ b/src/Engine/Graphics/RenderPass/DebugPass.cpp @@ -16,129 +16,119 @@ void Seele::addDebugVertices(Array verts) gDebugVertices.addAll(verts); } -//DebugPass::DebugPass(Gfx::PGraphics graphics, PScene scene) -// : RenderPass(graphics, scene) -//{ -// -//} -//DebugPass::~DebugPass() -//{ -// -//} -// -//void DebugPass::beginFrame(const Component::Camera& cam) -//{ -// RenderPass::beginFrame(cam); -// DataSource uniformUpdate; -// -// viewParams.viewMatrix = cam.getViewMatrix(); -// viewParams.projectionMatrix = viewport->getProjectionMatrix(); -// viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 1); -// viewParams.screenDimensions = Vector2(static_cast(viewport->getSizeX()), static_cast(viewport->getSizeY())); -// uniformUpdate.size = sizeof(ViewParameter); -// uniformUpdate.data = (uint8*)&viewParams; -// viewParamsBuffer->updateContents(uniformUpdate); -// descriptorLayout->reset(); -// descriptorSet = descriptorLayout->allocateDescriptorSet(); -// descriptorSet->updateBuffer(0, viewParamsBuffer); -// descriptorSet->writeChanges(); -// -// VertexBufferCreateInfo vertexBufferInfo = { -// .sourceData = { -// .size = sizeof(DebugVertex) * passData.vertices.size(), -// .data = (uint8*)passData.vertices.data(), -// }, -// .vertexSize = sizeof(DebugVertex), -// .numVertices = (uint32)passData.vertices.size(), -// }; -// debugVertices = graphics->createVertexBuffer(vertexBufferInfo); -// -//} -// -//void DebugPass::render() -//{ -// graphics->beginRenderPass(renderPass); -// Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("DebugRender"); -// renderCommand->setViewport(viewport); -// renderCommand->bindPipeline(pipeline); -// renderCommand->bindDescriptor(descriptorSet); -// renderCommand->bindVertexBuffer({VertexInputStream(0, 0, debugVertices)}); -// renderCommand->draw((uint32)passData.vertices.size(), 1, 0, 0); -// graphics->executeCommands(Array{renderCommand}); -// graphics->endRenderPass(); -//} -// -//void DebugPass::endFrame() -//{ -// -//} -// -//void DebugPass::publishOutputs() -//{ -// UniformBufferCreateInfo viewCreateInfo = { -// .sourceData = DataSource { -// .size = sizeof(ViewParameter), -// .data = nullptr, -// }, -// .dynamic = true -// }; -// viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo); -// -// descriptorLayout = graphics->createDescriptorLayout("DebugDescLayout"); -// descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); -// descriptorLayout->create(); -// -// pipelineLayout = graphics->createPipelineLayout(); -// pipelineLayout->addDescriptorLayout(0, descriptorLayout); -// pipelineLayout->create(); -//} -// -//void DebugPass::createRenderPass() -//{ -// Gfx::PRenderTargetAttachment baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR"); -// baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; -// Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); -// depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; -// Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(baseColorAttachment, depthAttachment); -// renderPass = graphics->createRenderPass(layout, viewport); -// -// ShaderCreateInfo createInfo; -// createInfo.name = "DebugVertex"; -// createInfo.mainModule = "Debug"; -// createInfo.entryPoint = "vertexMain"; -// createInfo.defines["INDEX_VIEW_PARAMS"] = "0"; -// Gfx::PVertexShader vertexShader = graphics->createVertexShader(createInfo); -// -// createInfo.name = "DebugFragment"; -// -// createInfo.entryPoint = "fragmentMain"; -// Gfx::PFragmentShader fragmentShader = graphics->createFragmentShader(createInfo); -// -// Gfx::PVertexDeclaration vertexDecl = graphics->createVertexDeclaration({ -// Gfx::VertexElement { -// .streamIndex = 0, -// .offset = offsetof(DebugVertex, position), -// .vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT, -// .attributeIndex = 0, -// .stride = sizeof(DebugVertex), -// }, -// Gfx::VertexElement { -// .streamIndex = 0, -// .offset = offsetof(DebugVertex, color), -// .vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT, -// .attributeIndex = 1, -// .stride = sizeof(DebugVertex), -// } -// }); -// -// GraphicsPipelineCreateInfo gfxInfo; -// gfxInfo.vertexDeclaration = vertexDecl; -// gfxInfo.vertexShader = vertexShader; -// gfxInfo.fragmentShader = fragmentShader; -// gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_LINE; -// gfxInfo.rasterizationState.lineWidth = 5.f; -// gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST; -// gfxInfo.pipelineLayout = pipelineLayout; -// gfxInfo.renderPass = renderPass; -// pipeline = graphics->createGraphicsPipeline(gfxInfo); -//} +DebugPass::DebugPass(Gfx::PGraphics graphics, PScene scene) + : RenderPass(graphics, scene) +{ + +} +DebugPass::~DebugPass() +{ + +} + +void DebugPass::beginFrame(const Component::Camera& cam) +{ + RenderPass::beginFrame(cam); + + VertexBufferCreateInfo vertexBufferInfo = { + .sourceData = { + .size = sizeof(DebugVertex) * gDebugVertices.size(), + .data = (uint8*)gDebugVertices.data(), + }, + .vertexSize = sizeof(DebugVertex), + .numVertices = (uint32)gDebugVertices.size(), + }; + debugVertices = graphics->createVertexBuffer(vertexBufferInfo); + +} + +void DebugPass::render() +{ + graphics->beginRenderPass(renderPass); + Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("DebugRender"); + renderCommand->setViewport(viewport); + renderCommand->bindPipeline(pipeline); + renderCommand->bindDescriptor(descriptorSet); + renderCommand->bindVertexBuffer({ debugVertices }); + renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0); + graphics->executeCommands(Array{renderCommand}); + graphics->endRenderPass(); +} + +void DebugPass::endFrame() +{ + +} + +void DebugPass::publishOutputs() +{ + UniformBufferCreateInfo viewCreateInfo = { + .sourceData = DataSource { + .size = sizeof(ViewParameter), + .data = nullptr, + }, + .dynamic = true + }; + viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo); + + descriptorLayout = graphics->createDescriptorLayout("DebugDescLayout"); + descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER); + descriptorLayout->create(); + + pipelineLayout = graphics->createPipelineLayout(); + pipelineLayout->addDescriptorLayout(0, descriptorLayout); + pipelineLayout->create(); +} + +void DebugPass::createRenderPass() +{ + Gfx::PRenderTargetAttachment baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR"); + baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; + Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); + depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; + Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{ + .colorAttachments = {baseColorAttachment}, + .depthAttachment = depthAttachment, + }; + renderPass = graphics->createRenderPass(std::move(layout), viewport); + + ShaderCreateInfo createInfo; + createInfo.name = "DebugVertex"; + createInfo.mainModule = "Debug"; + createInfo.entryPoint = "vertexMain"; + createInfo.defines["INDEX_VIEW_PARAMS"] = "0"; + Gfx::PVertexShader vertexShader = graphics->createVertexShader(createInfo); + + createInfo.name = "DebugFragment"; + + createInfo.entryPoint = "fragmentMain"; + Gfx::PFragmentShader fragmentShader = graphics->createFragmentShader(createInfo); + + Gfx::OVertexDeclaration vertexDecl = graphics->createVertexDeclaration({ + Gfx::VertexElement { + .streamIndex = 0, + .offset = offsetof(DebugVertex, position), + .vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT, + .attributeIndex = 0, + .stride = sizeof(DebugVertex), + }, + Gfx::VertexElement { + .streamIndex = 0, + .offset = offsetof(DebugVertex, color), + .vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT, + .attributeIndex = 1, + .stride = sizeof(DebugVertex), + } + }); + + GraphicsPipelineCreateInfo gfxInfo; + gfxInfo.vertexDeclaration = vertexDecl; + gfxInfo.vertexShader = vertexShader; + gfxInfo.fragmentShader = fragmentShader; + gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_LINE; + gfxInfo.rasterizationState.lineWidth = 5.f; + gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST; + gfxInfo.pipelineLayout = pipelineLayout; + gfxInfo.renderPass = renderPass; + pipeline = graphics->createGraphicsPipeline(gfxInfo); +} diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index 47faa29..8d0b103 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -81,7 +81,7 @@ void GameView::applyArea(URect rect) void GameView::reloadGame() { - gameInterface.reload(AssetRegistry::getInstance()); + gameInterface.reload(); systemGraph = new SystemGraph(); gameInterface.getGame()->setupScene(scene, systemGraph);