From ad88561245fee7f50bc760a6f6ba5bf91fff691a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sat, 31 Oct 2020 16:29:02 +0100 Subject: [PATCH] Graphics: Fix MaterialPipeline::GetRenderPipeline --- examples/GraphicsTest/main.cpp | 51 +++++------------------- src/Nazara/Graphics/MaterialPipeline.cpp | 2 + 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/examples/GraphicsTest/main.cpp b/examples/GraphicsTest/main.cpp index 23f7ca17d..946d6bc28 100644 --- a/examples/GraphicsTest/main.cpp +++ b/examples/GraphicsTest/main.cpp @@ -94,6 +94,7 @@ int main() Nz::Material material(Nz::BasicMaterial::GetSettings()); //material.SetShader(Nz::ShaderStageType::Fragment, fragmentShader); //material.SetShader(Nz::ShaderStageType::Vertex, vertexShader); + material.EnableDepthBuffer(true); material.SetTexture(0, texture); material.SetTextureSampler(0, textureSampler); @@ -109,33 +110,8 @@ int main() Nz::AccessByOffset(viewerDataBuffer.data(), viewerUboOffsets.viewMatrixOffset) = Nz::Matrix4f::Translate(Nz::Vector3f::Backward() * 1); Nz::AccessByOffset(viewerDataBuffer.data(), viewerUboOffsets.projMatrixOffset) = Nz::Matrix4f::Perspective(70.f, float(windowSize.x) / windowSize.y, 0.1f, 1000.f); - Nz::RenderPipelineLayoutInfo pipelineLayoutInfo; - { - auto& uboBinding = pipelineLayoutInfo.bindings.emplace_back(); - uboBinding.index = 0; - uboBinding.shaderStageFlags = Nz::ShaderStageType::Vertex; - uboBinding.type = Nz::ShaderBindingType::UniformBuffer; - } - - { - auto& uboBinding = pipelineLayoutInfo.bindings.emplace_back(); - uboBinding.index = 1; - uboBinding.shaderStageFlags = Nz::ShaderStageType::Vertex; - uboBinding.type = Nz::ShaderBindingType::UniformBuffer; - } - - { - auto& textureBinding = pipelineLayoutInfo.bindings.emplace_back(); - textureBinding.index = 2; - textureBinding.shaderStageFlags = Nz::ShaderStageType::Fragment; - textureBinding.type = Nz::ShaderBindingType::Texture; - } - - //std::shared_ptr renderPipelineLayout = device->InstantiateRenderPipelineLayout(std::move(pipelineLayoutInfo)); std::shared_ptr renderPipelineLayout = material.GetSettings()->GetRenderPipelineLayout(); - Nz::ShaderBindingPtr shaderBinding = renderPipelineLayout->AllocateShaderBinding(); - std::shared_ptr instanceDataUbo = device->InstantiateBuffer(Nz::BufferType_Uniform); if (!instanceDataUbo->Initialize(instanceDataBuffer.size(), Nz::BufferUsage_DeviceLocal | Nz::BufferUsage_Dynamic)) { @@ -152,15 +128,16 @@ int main() return __LINE__; } + Nz::ShaderBindingPtr shaderBinding = renderPipelineLayout->AllocateShaderBinding(); shaderBinding->Update({ { - 5, + material.GetSettings()->GetPredefinedBindingIndex(Nz::PredefinedShaderBinding::UboViewerData), Nz::ShaderBinding::UniformBufferBinding { viewerDataUbo.get(), 0, viewerDataBuffer.size() } }, { - 4, + material.GetSettings()->GetPredefinedBindingIndex(Nz::PredefinedShaderBinding::UboInstanceData), Nz::ShaderBinding::UniformBufferBinding { instanceDataUbo.get(), 0, instanceDataBuffer.size() } @@ -173,20 +150,14 @@ int main() } }); - Nz::RenderPipelineInfo pipelineInfo; - pipelineInfo.pipelineLayout = renderPipelineLayout; + std::vector vertexBuffers = { + { + 0, + drfreakVB->GetVertexDeclaration() + } + }; - pipelineInfo.depthBuffer = true; - pipelineInfo.shaderStages.emplace_back(material.GetShader(Nz::ShaderStageType::Fragment)); - pipelineInfo.shaderStages.emplace_back(material.GetShader(Nz::ShaderStageType::Vertex)); - - auto& vertexBuffer = pipelineInfo.vertexBuffers.emplace_back(); - vertexBuffer.binding = 0; - vertexBuffer.declaration = drfreakVB->GetVertexDeclaration(); - - //std::shared_ptr pipeline = material.GetPipeline()->GetRenderPipeline(pipelineInfo.vertexBuffers); - - std::shared_ptr pipeline = device->InstantiateRenderPipeline(pipelineInfo); + std::shared_ptr pipeline = material.GetPipeline()->GetRenderPipeline(vertexBuffers); Nz::RenderDevice* renderDevice = window.GetRenderDevice().get(); diff --git a/src/Nazara/Graphics/MaterialPipeline.cpp b/src/Nazara/Graphics/MaterialPipeline.cpp index c22e21d1e..5996f64b0 100644 --- a/src/Nazara/Graphics/MaterialPipeline.cpp +++ b/src/Nazara/Graphics/MaterialPipeline.cpp @@ -53,6 +53,8 @@ namespace Nz renderPipelineInfo.shaderStages.push_back(shaderStage); } + renderPipelineInfo.vertexBuffers = vertexBuffers; + return m_renderPipelines.emplace_back(Graphics::Instance()->GetRenderDevice().InstantiateRenderPipeline(std::move(renderPipelineInfo))); } /*!