Viewport controls
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
#include "BasePass.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Window/Window.h"
|
||||
#include "Scene/Component/Camera.h"
|
||||
#include "Scene/Actor/CameraActor.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "Material/MaterialAsset.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
BasePassMeshProcessor::BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass)
|
||||
BasePassMeshProcessor::BasePassMeshProcessor(Gfx::PGraphics graphics, uint8 translucentBasePass)
|
||||
: MeshProcessor(graphics)
|
||||
, target(viewport)
|
||||
, translucentBasePass(translucentBasePass)
|
||||
//, cachedPrimitiveIndex(0)
|
||||
{
|
||||
@@ -23,8 +22,8 @@ BasePassMeshProcessor::~BasePassMeshProcessor()
|
||||
|
||||
void BasePassMeshProcessor::processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout baseLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
@@ -70,11 +69,10 @@ void BasePassMeshProcessor::processMeshBatch(
|
||||
//co_return;
|
||||
}
|
||||
|
||||
BasePass::BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
|
||||
: RenderPass(graphics, viewport)
|
||||
, processor(new BasePassMeshProcessor(viewport, graphics, false))
|
||||
BasePass::BasePass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
, processor(new BasePassMeshProcessor(graphics, false))
|
||||
, descriptorSets(4)
|
||||
, source(source)
|
||||
{
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
basePassLayout = graphics->createPipelineLayout();
|
||||
@@ -115,16 +113,15 @@ BasePass::~BasePass()
|
||||
{
|
||||
}
|
||||
|
||||
void BasePass::beginFrame()
|
||||
void BasePass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
processor->clearCommands();
|
||||
primitiveLayout->reset();
|
||||
BulkResourceData uniformUpdate;
|
||||
|
||||
viewParams.viewMatrix = source->getCameraComponent().getViewMatrix();
|
||||
viewParams.projectionMatrix = source->getCameraComponent().getProjectionMatrix();
|
||||
viewParams.cameraPosition = Math::Vector4(source->getCameraComponent().getCameraPosition(), 0);
|
||||
viewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix);
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
viewParams.projectionMatrix = cam.getProjectionMatrix();
|
||||
viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
|
||||
uniformUpdate.size = sizeof(ViewParameter);
|
||||
uniformUpdate.data = (uint8*)&viewParams;
|
||||
@@ -158,7 +155,7 @@ void BasePass::render()
|
||||
graphics->beginRenderPass(renderPass);
|
||||
for (auto &&meshBatch : passData.staticDrawList)
|
||||
{
|
||||
processor->processMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets);
|
||||
processor->processMeshBatch(meshBatch, viewport, renderPass, basePassLayout, primitiveLayout, descriptorSets);
|
||||
}
|
||||
graphics->executeCommands(processor->getRenderCommands());
|
||||
graphics->endRenderPass();
|
||||
@@ -186,6 +183,8 @@ void BasePass::createRenderPass()
|
||||
numPointLightBuffer = resources->requestUniform("NUM_POINT_LIGHTS");
|
||||
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
|
||||
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
|
||||
colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colorAttachment->storeOp = Gfx::SE_ATTACHMENT_STORE_OP_STORE;
|
||||
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
|
||||
renderPass = graphics->createRenderPass(layout, viewport);
|
||||
oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST");
|
||||
|
||||
@@ -8,13 +8,13 @@ namespace Seele
|
||||
class BasePassMeshProcessor : public MeshProcessor
|
||||
{
|
||||
public:
|
||||
BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass);
|
||||
BasePassMeshProcessor(Gfx::PGraphics graphics, uint8 translucentBasePass);
|
||||
virtual ~BasePassMeshProcessor();
|
||||
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
@@ -34,9 +34,11 @@ struct BasePassData
|
||||
class BasePass : public RenderPass<BasePassData>
|
||||
{
|
||||
public:
|
||||
BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
|
||||
BasePass(Gfx::PGraphics graphics);
|
||||
BasePass(BasePass&& other) = default;
|
||||
virtual ~BasePass();
|
||||
virtual void beginFrame() override;
|
||||
BasePass& operator=(BasePass&& other) = default;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
BasePass.h
|
||||
BasePass.cpp
|
||||
DepthPrepass.h
|
||||
@@ -9,7 +9,8 @@ target_sources(Engine
|
||||
MeshProcessor.h
|
||||
MeshProcessor.cpp
|
||||
RenderGraph.h
|
||||
RenderGraph.cpp
|
||||
RenderGraphResources.h
|
||||
RenderGraphResources.cpp
|
||||
RenderPass.h
|
||||
TextPass.h
|
||||
TextPass.cpp
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
#include "DepthPrepass.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Window/Window.h"
|
||||
#include "Scene/Component/Camera.h"
|
||||
#include "Scene/Actor/CameraActor.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Math/Vector.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "Material/MaterialAsset.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics)
|
||||
DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(Gfx::PGraphics graphics)
|
||||
: MeshProcessor(graphics)
|
||||
, target(viewport)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -21,8 +20,8 @@ DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor()
|
||||
|
||||
void DepthPrepassMeshProcessor::processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout baseLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
@@ -69,11 +68,10 @@ void DepthPrepassMeshProcessor::processMeshBatch(
|
||||
//co_return;
|
||||
}
|
||||
|
||||
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
|
||||
: RenderPass(graphics, viewport)
|
||||
, processor(new DepthPrepassMeshProcessor(viewport, graphics))
|
||||
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
, processor(new DepthPrepassMeshProcessor(graphics))
|
||||
, descriptorSets(3)
|
||||
, source(source)
|
||||
{
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
|
||||
@@ -98,16 +96,15 @@ DepthPrepass::~DepthPrepass()
|
||||
{
|
||||
}
|
||||
|
||||
void DepthPrepass::beginFrame()
|
||||
void DepthPrepass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
processor->clearCommands();
|
||||
primitiveLayout->reset();
|
||||
BulkResourceData uniformUpdate;
|
||||
|
||||
viewParams.viewMatrix = source->getCameraComponent().getViewMatrix();
|
||||
viewParams.projectionMatrix = source->getCameraComponent().getProjectionMatrix();
|
||||
viewParams.cameraPosition = Math::Vector4(source->getCameraComponent().getCameraPosition(), 0);
|
||||
viewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix);
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
viewParams.projectionMatrix = cam.getProjectionMatrix();
|
||||
viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
|
||||
uniformUpdate.size = sizeof(ViewParameter);
|
||||
uniformUpdate.data = (uint8*)&viewParams;
|
||||
@@ -129,7 +126,7 @@ void DepthPrepass::render()
|
||||
graphics->beginRenderPass(renderPass);
|
||||
for (auto &&meshBatch : passData.staticDrawList)
|
||||
{
|
||||
processor->processMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
|
||||
processor->processMeshBatch(meshBatch, viewport, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
|
||||
}
|
||||
graphics->executeCommands(processor->getRenderCommands());
|
||||
graphics->endRenderPass();
|
||||
|
||||
@@ -8,22 +8,21 @@ namespace Seele
|
||||
class DepthPrepassMeshProcessor : public MeshProcessor
|
||||
{
|
||||
public:
|
||||
DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics);
|
||||
DepthPrepassMeshProcessor(Gfx::PGraphics graphics);
|
||||
virtual ~DepthPrepassMeshProcessor();
|
||||
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 staticMeshId = -1) override;
|
||||
|
||||
private:
|
||||
Gfx::PViewport target;
|
||||
};
|
||||
DEFINE_REF(DepthPrepassMeshProcessor)
|
||||
DECLARE_REF(CameraActor)
|
||||
struct DepthPrepassData
|
||||
{
|
||||
Array<StaticMeshBatch> staticDrawList;
|
||||
@@ -31,9 +30,11 @@ struct DepthPrepassData
|
||||
class DepthPrepass : public RenderPass<DepthPrepassData>
|
||||
{
|
||||
public:
|
||||
DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
|
||||
DepthPrepass(Gfx::PGraphics graphics);
|
||||
DepthPrepass(DepthPrepass&& other) = default;
|
||||
~DepthPrepass();
|
||||
virtual void beginFrame() override;
|
||||
DepthPrepass& operator=(DepthPrepass& other) = default;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
@@ -45,7 +46,6 @@ private:
|
||||
UPDepthPrepassMeshProcessor processor;
|
||||
|
||||
Array<Gfx::PDescriptorSet> descriptorSets;
|
||||
PCameraActor source;
|
||||
Gfx::PPipelineLayout depthPrepassLayout;
|
||||
// Set 0: viewParameter
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
#include "LightCullingPass.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Scene/Actor/CameraActor.h"
|
||||
#include "Scene/Component/Camera.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "RenderGraph.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
LightCullingPass::LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera)
|
||||
: RenderPass(graphics, viewport)
|
||||
, source(camera)
|
||||
LightCullingPass::LightCullingPass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -18,16 +17,15 @@ LightCullingPass::~LightCullingPass()
|
||||
|
||||
}
|
||||
|
||||
void LightCullingPass::beginFrame()
|
||||
void LightCullingPass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
uint32_t viewportWidth = viewport->getSizeX();
|
||||
uint32_t viewportHeight = viewport->getSizeY();
|
||||
|
||||
BulkResourceData uniformUpdate;
|
||||
viewParams.viewMatrix = source->getCameraComponent().getViewMatrix();
|
||||
viewParams.projectionMatrix = source->getCameraComponent().getProjectionMatrix();
|
||||
viewParams.cameraPosition = Math::Vector4(source->getCameraComponent().getCameraPosition(), 0);
|
||||
viewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix);
|
||||
viewParams.viewMatrix = cam.getViewMatrix();
|
||||
viewParams.projectionMatrix = cam.getProjectionMatrix();
|
||||
viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0);
|
||||
viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewportWidth), static_cast<float>(viewportHeight));
|
||||
uniformUpdate.size = sizeof(ViewParameter);
|
||||
uniformUpdate.data = (uint8*)&viewParams;
|
||||
@@ -263,10 +261,9 @@ void LightCullingPass::setupFrustums()
|
||||
glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1));
|
||||
|
||||
viewParams = {
|
||||
.viewMatrix = source->getCameraComponent().getViewMatrix(),
|
||||
.projectionMatrix = source->getCameraComponent().getProjectionMatrix(),
|
||||
.inverseProjectionMatrix = glm::inverse(source->getCameraComponent().getProjectionMatrix()),
|
||||
.cameraPosition = Math::Vector4(source->getTransform().getPosition(), 0),
|
||||
.viewMatrix = Math::Matrix4(),
|
||||
.projectionMatrix = Math::Matrix4(),
|
||||
.cameraPosition = Math::Vector4(),
|
||||
.screenDimensions = glm::vec2(viewportWidth, viewportHeight),
|
||||
};
|
||||
dispatchParams.numThreads = numThreads;
|
||||
|
||||
@@ -15,9 +15,9 @@ struct LightCullingPassData
|
||||
class LightCullingPass : public RenderPass<LightCullingPassData>
|
||||
{
|
||||
public:
|
||||
LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera);
|
||||
LightCullingPass(Gfx::PGraphics graphics);
|
||||
virtual ~LightCullingPass();
|
||||
virtual void beginFrame() override;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
@@ -71,7 +71,6 @@ private:
|
||||
Gfx::PComputeShader cullingShader;
|
||||
Gfx::PPipelineLayout cullingLayout;
|
||||
Gfx::PComputePipeline cullingPipeline;
|
||||
PCameraActor source;
|
||||
};
|
||||
DEFINE_REF(LightCullingPass)
|
||||
} // namespace Seele
|
||||
|
||||
@@ -18,8 +18,8 @@ protected:
|
||||
Gfx::PGraphics graphics;
|
||||
virtual void processMeshBatch(
|
||||
const MeshBatch& batch,
|
||||
// const PPrimitiveComponent primitiveComponent,
|
||||
const Gfx::PRenderPass& renderPass,
|
||||
Gfx::PViewport target,
|
||||
Gfx::PRenderPass renderPass,
|
||||
Gfx::PPipelineLayout pipelineLayout,
|
||||
Gfx::PDescriptorLayout primitiveLayout,
|
||||
Array<Gfx::PDescriptorSet> descriptorSets,
|
||||
|
||||
@@ -1,29 +1,95 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(ViewFrame)
|
||||
template<typename... RenderPasses>
|
||||
class RenderGraph;
|
||||
|
||||
class RenderGraphResources
|
||||
template<>
|
||||
class RenderGraph<>
|
||||
{
|
||||
public:
|
||||
RenderGraphResources();
|
||||
~RenderGraphResources();
|
||||
Gfx::PRenderTargetAttachment requestRenderTarget(const std::string& outputName);
|
||||
Gfx::PTexture requestTexture(const std::string& outputName);
|
||||
Gfx::PStructuredBuffer requestBuffer(const std::string& outputName);
|
||||
Gfx::PUniformBuffer requestUniform(const std::string& outputName);
|
||||
void registerRenderPassOutput(const std::string& outputName, Gfx::PRenderTargetAttachment attachment);
|
||||
void registerTextureOutput(const std::string& outputName, Gfx::PTexture buffer);
|
||||
void registerBufferOutput(const std::string& outputName, Gfx::PStructuredBuffer buffer);
|
||||
void registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer);
|
||||
RenderGraph(PRenderGraphResources) {}
|
||||
void updatePassData() {}
|
||||
protected:
|
||||
Map<std::string, Gfx::PRenderTargetAttachment> registeredAttachments;
|
||||
Map<std::string, Gfx::PTexture> registeredTextures;
|
||||
Map<std::string, Gfx::PStructuredBuffer> registeredBuffers;
|
||||
Map<std::string, Gfx::PUniformBuffer> registeredUniforms;
|
||||
void setViewport(Gfx::PViewport) {}
|
||||
void createRenderPass() {}
|
||||
void beginFrame(const Component::Camera&) {}
|
||||
void render() {}
|
||||
void endFrame() {}
|
||||
};
|
||||
DEFINE_REF(RenderGraphResources)
|
||||
|
||||
template<typename This, typename... Rest>
|
||||
class RenderGraph<This, Rest...> : private RenderGraph<Rest...>
|
||||
{
|
||||
public:
|
||||
RenderGraph(PRenderGraphResources resources, This&& pass, Rest&&... rest)
|
||||
: RenderGraph<Rest...>(resources, std::move(rest)...)
|
||||
, resources(resources)
|
||||
, rp(std::move(pass))
|
||||
{
|
||||
rp.setResources(resources);
|
||||
}
|
||||
template<typename PassData, typename... OtherData>
|
||||
void updatePassData(PassData passData, OtherData... otherData)
|
||||
{
|
||||
rp.updateViewFrame(std::move(passData));
|
||||
RenderGraph<Rest...>::updatePassData(otherData...);
|
||||
}
|
||||
void updateViewport(Gfx::PViewport viewport)
|
||||
{
|
||||
setViewport(viewport);
|
||||
createRenderPass();
|
||||
}
|
||||
void render(const Component::Camera& cam)
|
||||
{
|
||||
beginFrame(cam);
|
||||
render();
|
||||
endFrame();
|
||||
}
|
||||
protected:
|
||||
void setViewport(Gfx::PViewport viewport)
|
||||
{
|
||||
rp.setViewport(viewport);
|
||||
RenderGraph<Rest...>::setViewport(viewport);
|
||||
}
|
||||
void createRenderPass()
|
||||
{
|
||||
rp.createRenderPass();
|
||||
RenderGraph<Rest...>::createRenderPass();
|
||||
}
|
||||
void beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
rp.beginFrame(cam);
|
||||
RenderGraph<Rest...>::beginFrame(cam);
|
||||
}
|
||||
void render()
|
||||
{
|
||||
rp.render();
|
||||
RenderGraph<Rest...>::render();
|
||||
}
|
||||
void endFrame()
|
||||
{
|
||||
rp.endFrame();
|
||||
RenderGraph<Rest...>::endFrame();
|
||||
}
|
||||
private:
|
||||
PRenderGraphResources resources;
|
||||
This rp;
|
||||
};
|
||||
|
||||
class RenderGraphBuilder
|
||||
{
|
||||
public:
|
||||
template<typename... RenderPasses>
|
||||
static RenderGraph<RenderPasses...> build(RenderPasses&&... renderPasses)
|
||||
{
|
||||
PRenderGraphResources resources = new RenderGraphResources();
|
||||
return RenderGraph<RenderPasses...>(resources, std::move(renderPasses)...);
|
||||
}
|
||||
private:
|
||||
RenderGraphBuilder() = delete;
|
||||
};
|
||||
|
||||
} // namespace Seele
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "RenderGraph.h"
|
||||
#include "RenderGraphResources.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(ViewFrame)
|
||||
|
||||
class RenderGraphResources
|
||||
{
|
||||
public:
|
||||
RenderGraphResources();
|
||||
~RenderGraphResources();
|
||||
Gfx::PRenderTargetAttachment requestRenderTarget(const std::string& outputName);
|
||||
Gfx::PTexture requestTexture(const std::string& outputName);
|
||||
Gfx::PStructuredBuffer requestBuffer(const std::string& outputName);
|
||||
Gfx::PUniformBuffer requestUniform(const std::string& outputName);
|
||||
void registerRenderPassOutput(const std::string& outputName, Gfx::PRenderTargetAttachment attachment);
|
||||
void registerTextureOutput(const std::string& outputName, Gfx::PTexture buffer);
|
||||
void registerBufferOutput(const std::string& outputName, Gfx::PStructuredBuffer buffer);
|
||||
void registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer);
|
||||
protected:
|
||||
Map<std::string, Gfx::PRenderTargetAttachment> registeredAttachments;
|
||||
Map<std::string, Gfx::PTexture> registeredTextures;
|
||||
Map<std::string, Gfx::PStructuredBuffer> registeredBuffers;
|
||||
Map<std::string, Gfx::PUniformBuffer> registeredUniforms;
|
||||
};
|
||||
DEFINE_REF(RenderGraphResources)
|
||||
} // namespace Seele
|
||||
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Math/Math.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "RenderGraphResources.h"
|
||||
#include "Component/Camera.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -12,27 +13,30 @@ template<typename RenderPassDataType>
|
||||
class RenderPass
|
||||
{
|
||||
public:
|
||||
RenderPass(Gfx::PGraphics graphics, Gfx::PViewport viewport)
|
||||
RenderPass(Gfx::PGraphics graphics)
|
||||
: graphics(graphics)
|
||||
, viewport(viewport)
|
||||
{}
|
||||
virtual ~RenderPass()
|
||||
{}
|
||||
void updateViewFrame(RenderPassDataType viewFrame) {
|
||||
passData = std::move(viewFrame);
|
||||
}
|
||||
virtual void beginFrame() = 0;
|
||||
virtual void beginFrame(const Component::Camera& cam) = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void endFrame() = 0;
|
||||
virtual void publishOutputs() = 0;
|
||||
virtual void createRenderPass() = 0;
|
||||
void setResources(PRenderGraphResources _resources) { resources = _resources; }
|
||||
void setViewport(Gfx::PViewport _viewport)
|
||||
{
|
||||
viewport = _viewport;
|
||||
publishOutputs();
|
||||
}
|
||||
protected:
|
||||
struct ViewParameter
|
||||
{
|
||||
Math::Matrix4 viewMatrix;
|
||||
Math::Matrix4 projectionMatrix;
|
||||
Math::Matrix4 inverseProjectionMatrix;
|
||||
Math::Vector4 cameraPosition;
|
||||
Math::Vector2 screenDimensions;
|
||||
Math::Vector2 pad0;
|
||||
@@ -43,7 +47,7 @@ protected:
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::PViewport viewport;
|
||||
};
|
||||
template<typename T>
|
||||
concept RenderPassType = true;
|
||||
template<typename RP, typename T>
|
||||
concept RenderPassType = std::derived_from<RP, RenderPass<T>>;
|
||||
|
||||
} // namespace Seele
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
TextPass::TextPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment)
|
||||
: RenderPass(graphics, viewport)
|
||||
, renderTarget(attachment)
|
||||
TextPass::TextPass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -16,7 +15,7 @@ TextPass::~TextPass()
|
||||
|
||||
}
|
||||
|
||||
void TextPass::beginFrame()
|
||||
void TextPass::beginFrame(const Component::Camera& cam)
|
||||
{
|
||||
for(TextRender& render : passData.texts)
|
||||
{
|
||||
@@ -60,6 +59,13 @@ void TextPass::beginFrame()
|
||||
.scale = render.scale,
|
||||
};
|
||||
}
|
||||
BulkResourceData projectionUpdate = {
|
||||
.size = sizeof(Math::Matrix4),
|
||||
.data = (uint8*)&cam.projectionMatrix,
|
||||
};
|
||||
projectionBuffer->updateContents(projectionUpdate);
|
||||
generalSet->updateBuffer(1, projectionBuffer);
|
||||
generalSet->writeChanges();
|
||||
//co_return;
|
||||
}
|
||||
|
||||
@@ -99,7 +105,9 @@ void TextPass::publishOutputs()
|
||||
|
||||
void TextPass::createRenderPass()
|
||||
{
|
||||
renderTarget = resources->requestRenderTarget("UIPASS_COLOR");
|
||||
depthAttachment = resources->requestRenderTarget("UIPASS_DEPTH");
|
||||
|
||||
ShaderCreateInfo createInfo;
|
||||
createInfo.mainModule = "TextPass";
|
||||
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
|
||||
@@ -146,13 +154,12 @@ void TextPass::createRenderPass()
|
||||
textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
|
||||
textureArrayLayout->create();
|
||||
|
||||
Math::Matrix4 projectionMatrix = glm::ortho(0.f, (float)viewport->getSizeX(), 0.f, (float)viewport->getSizeY());
|
||||
projectionBuffer = graphics->createUniformBuffer({
|
||||
.resourceData = {
|
||||
.size = sizeof(Math::Matrix4),
|
||||
.data = (uint8*)&projectionMatrix,
|
||||
.data = nullptr,
|
||||
},
|
||||
.bDynamic = false,
|
||||
.bDynamic = true,
|
||||
});
|
||||
|
||||
glyphSampler = graphics->createSamplerState({
|
||||
|
||||
@@ -25,9 +25,9 @@ struct TextPassData
|
||||
class TextPass : public RenderPass<TextPassData>
|
||||
{
|
||||
public:
|
||||
TextPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget);
|
||||
TextPass(Gfx::PGraphics graphics);
|
||||
virtual ~TextPass();
|
||||
virtual void beginFrame() override;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
@@ -69,7 +69,6 @@ private:
|
||||
|
||||
Gfx::PRenderTargetAttachment renderTarget;
|
||||
Gfx::PRenderTargetAttachment depthAttachment;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
|
||||
Gfx::PDescriptorLayout generalLayout;
|
||||
Gfx::PDescriptorLayout textureArrayLayout;
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
UIPass::UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment)
|
||||
: RenderPass(graphics, viewport)
|
||||
, renderTarget(attachment)
|
||||
UIPass::UIPass(Gfx::PGraphics graphics)
|
||||
: RenderPass(graphics)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -15,7 +14,7 @@ UIPass::~UIPass()
|
||||
|
||||
}
|
||||
|
||||
void UIPass::beginFrame()
|
||||
void UIPass::beginFrame(const Component::Camera&)
|
||||
{
|
||||
VertexBufferCreateInfo info = {
|
||||
.resourceData = {
|
||||
@@ -58,20 +57,30 @@ void UIPass::endFrame()
|
||||
|
||||
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;
|
||||
TextureCreateInfo depthBufferInfo = {
|
||||
.width = viewport->getSizeX(),
|
||||
.height = viewport->getSizeY(),
|
||||
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
||||
.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;
|
||||
depthAttachment->clear.depthStencil.depth = 1.0f;
|
||||
resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
|
||||
|
||||
TextureCreateInfo colorBufferInfo = {
|
||||
.width = viewport->getSizeX(),
|
||||
.height = viewport->getSizeY(),
|
||||
.format = Gfx::SE_FORMAT_R16G16B16A16_SFLOAT,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
||||
};
|
||||
colorBuffer = graphics->createTexture2D(colorBufferInfo);
|
||||
renderTarget =
|
||||
new Gfx::RenderTargetAttachment(colorBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
||||
renderTarget->clear.color = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
resources->registerRenderPassOutput("UIPASS_COLOR", renderTarget);
|
||||
}
|
||||
|
||||
void UIPass::createRenderPass()
|
||||
|
||||
@@ -15,15 +15,16 @@ struct UIPassData
|
||||
class UIPass : public RenderPass<UIPassData>
|
||||
{
|
||||
public:
|
||||
UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget);
|
||||
UIPass(Gfx::PGraphics graphics);
|
||||
virtual ~UIPass();
|
||||
virtual void beginFrame() override;
|
||||
virtual void beginFrame(const Component::Camera& cam) override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void publishOutputs() override;
|
||||
virtual void createRenderPass() override;
|
||||
private:
|
||||
Gfx::PRenderTargetAttachment renderTarget;
|
||||
Gfx::PTexture2D colorBuffer;
|
||||
Gfx::PRenderTargetAttachment depthAttachment;
|
||||
Gfx::PTexture2D depthBuffer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user