From 12923669214ba73a809f4e221a634244888b0146 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Thu, 15 Dec 2022 15:53:56 +0500 Subject: Added liquid rendering pass --- src/RendererSection.cpp | 54 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 16 deletions(-) (limited to 'src/RendererSection.cpp') diff --git a/src/RendererSection.cpp b/src/RendererSection.cpp index 429a8bd..7ea74df 100644 --- a/src/RendererSection.cpp +++ b/src/RendererSection.cpp @@ -9,16 +9,26 @@ #include "RendererSectionData.hpp" -RendererSection::RendererSection(const RendererSectionData& data, std::shared_ptr pipeline, std::shared_ptr bufferBinding) { +RendererSection::RendererSection(const RendererSectionData& data, + std::shared_ptr solidPipeline, + std::shared_ptr solidBufferBinding, + std::shared_ptr liquidPipeline, + std::shared_ptr liquidBufferBinding) { OPTICK_EVENT(); auto gal = Gal::GetImplementation(); - buffer = gal->CreateBuffer(); - pipelineInstance = pipeline->CreateInstance({ - {bufferBinding, buffer} + solidBuffer = gal->CreateBuffer(); + solidPipelineInstance = solidPipeline->CreateInstance({ + {solidBufferBinding, solidBuffer} }); - pipelineInstance->SetInstancesCount(4); + solidPipelineInstance->SetInstancesCount(4); + + liquidBuffer = gal->CreateBuffer(); + liquidPipelineInstance = liquidPipeline->CreateInstance({ + {liquidBufferBinding, liquidBuffer} + }); + liquidPipelineInstance->SetInstancesCount(4); UpdateData(data); } @@ -32,18 +42,27 @@ RendererSection::~RendererSection() { } -void swap(RendererSection & lhs, RendererSection & rhs) { - std::swap(lhs.pipelineInstance, rhs.pipelineInstance); - std::swap(lhs.buffer, rhs.buffer); - std::swap(lhs.hash, rhs.hash); - std::swap(lhs.numOfFaces, rhs.numOfFaces); - std::swap(lhs.sectionPos, rhs.sectionPos); +void RendererSection::RenderSolid() { + OPTICK_EVENT(); + solidPipelineInstance->Activate(); + solidPipelineInstance->Render(0, solidFacesCount); } -void RendererSection::Render() { +void RendererSection::RenderLiquid() { OPTICK_EVENT(); - pipelineInstance->Activate(); - pipelineInstance->Render(0, numOfFaces); + liquidPipelineInstance->Activate(); + liquidPipelineInstance->Render(0, liquidFacesCount); +} + +void swap(RendererSection & lhs, RendererSection & rhs) { + std::swap(lhs.solidPipelineInstance, rhs.solidPipelineInstance); + std::swap(lhs.solidBuffer, rhs.solidBuffer); + std::swap(lhs.liquidPipelineInstance, rhs.liquidPipelineInstance); + std::swap(lhs.liquidBuffer, rhs.liquidBuffer); + std::swap(lhs.hash, rhs.hash); + std::swap(lhs.solidFacesCount, rhs.solidFacesCount); + std::swap(lhs.liquidFacesCount, rhs.liquidFacesCount); + std::swap(lhs.sectionPos, rhs.sectionPos); } Vector RendererSection::GetPosition() { @@ -57,9 +76,12 @@ size_t RendererSection::GetHash() { void RendererSection::UpdateData(const RendererSectionData & data) { OPTICK_EVENT(); - buffer->SetData({ reinterpret_cast(data.vertices.data()), reinterpret_cast(data.vertices.data() + data.vertices.size())}); + solidBuffer->SetData({ reinterpret_cast(data.solidVertices.data()), reinterpret_cast(data.solidVertices.data() + data.solidVertices.size())}); + solidFacesCount = data.solidVertices.size(); + + liquidBuffer->SetData({ reinterpret_cast(data.liquidVertices.data()), reinterpret_cast(data.liquidVertices.data() + data.liquidVertices.size()) }); + liquidFacesCount = data.liquidVertices.size(); - numOfFaces = data.vertices.size(); sectionPos = data.sectionPos; hash = data.hash; } -- cgit v1.2.3