Graphics/FramePass: Replace render rect parameter of CommandCallback by FramePassEnvironment

This commit is contained in:
Jérôme Leclercq 2022-02-27 18:37:05 +01:00
parent 28531f5118
commit 8a097afb1b
7 changed files with 56 additions and 40 deletions

View File

@ -840,14 +840,14 @@ int main()
return Nz::FramePassExecution::Execute;
});
gbufferPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
gbufferPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetViewport(renderArea);
builder.SetViewport(env.renderRect);
std::vector<std::unique_ptr<Nz::RenderElement>> elements;
spaceshipModel.BuildElement(forwardPassIndex, modelInstance1, elements, renderArea);
spaceshipModel.BuildElement(forwardPassIndex, modelInstance2, elements, renderArea);
planeModel.BuildElement(forwardPassIndex, planeInstance, elements, renderArea);
spaceshipModel.BuildElement(forwardPassIndex, modelInstance1, elements, env.renderRect);
spaceshipModel.BuildElement(forwardPassIndex, modelInstance2, elements, env.renderRect);
planeModel.BuildElement(forwardPassIndex, planeInstance, elements, env.renderRect);
std::vector<Nz::Pointer<const Nz::RenderElement>> elementPointers;
std::vector<Nz::ElementRenderer::RenderStates> renderStates(elements.size());
@ -866,10 +866,10 @@ int main()
return (lightUpdate) ? Nz::FramePassExecution::UpdateAndExecute : Nz::FramePassExecution::Execute;
});
lightingPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
lightingPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderArea);
builder.SetViewport(renderArea);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
//builder.BindVertexBuffer(0, vertexBuffer.get());
builder.BindIndexBuffer(*coneMeshGfx->GetIndexBuffer(0).get());
@ -897,10 +897,10 @@ int main()
lightingPass.SetDepthStencilInput(depthBuffer1);
Nz::FramePass& forwardPass = graph.AddPass("Forward pass");
forwardPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
forwardPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderArea);
builder.SetViewport(renderArea);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
builder.BindShaderBinding(0, *skyboxShaderBinding);
@ -911,7 +911,7 @@ int main()
builder.DrawIndexed(Nz::SafeCast<Nz::UInt32>(cubeMeshGfx->GetIndexCount(0)));
std::vector<std::unique_ptr<Nz::RenderElement>> elements;
flareSprite.BuildElement(forwardPassIndex, flareInstance, elements, renderArea);
flareSprite.BuildElement(forwardPassIndex, flareInstance, elements, env.renderRect);
std::vector<Nz::Pointer<const Nz::RenderElement>> elementPointers;
std::vector<Nz::ElementRenderer::RenderStates> renderStates(elements.size());
@ -935,12 +935,12 @@ int main()
Nz::FramePass& occluderPass = graph.AddPass("Occluder pass");
occluderPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
occluderPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetViewport(renderArea);
builder.SetViewport(env.renderRect);
std::vector<std::unique_ptr<Nz::RenderElement>> elements;
flareSprite.BuildElement(forwardPassIndex, flareInstance, elements, renderArea);
flareSprite.BuildElement(forwardPassIndex, flareInstance, elements, env.renderRect);
std::vector<Nz::Pointer<const Nz::RenderElement>> elementPointers;
std::vector<Nz::ElementRenderer::RenderStates> renderStates(elements.size());
@ -959,10 +959,10 @@ int main()
occluderPass.SetDepthStencilInput(depthBuffer1);
Nz::FramePass& godraysPass = graph.AddPass("Light scattering pass");
godraysPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
godraysPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderArea);
builder.SetViewport(renderArea);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
builder.BindShaderBinding(0, *godRaysShaderBinding);
@ -976,10 +976,10 @@ int main()
godraysPass.AddOutput(godRaysTexture);
Nz::FramePass& bloomBrightPass = graph.AddPass("Bloom pass - extract bright pixels");
bloomBrightPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
bloomBrightPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderArea);
builder.SetViewport(renderArea);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
builder.BindShaderBinding(0, *bloomBrightShaderBinding);
@ -1000,10 +1000,10 @@ int main()
for (std::size_t i = 0; i < BloomSubdivisionCount; ++i)
{
Nz::FramePass& bloomBlurPassHorizontal = graph.AddPass("Bloom pass - gaussian blur #" + std::to_string(i) + " - horizontal");
bloomBlurPassHorizontal.SetCommandCallback([&, i](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
bloomBlurPassHorizontal.SetCommandCallback([&, i](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderArea);
builder.SetViewport(renderArea);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
builder.BindShaderBinding(0, *gaussianBlurShaderBinding[i * 2 + 0]);
builder.BindPipeline(*gaussianBlurPipeline);
@ -1021,10 +1021,10 @@ int main()
bloomBlurPassHorizontal.AddOutput(bloomTextures[bloomTextureIndex]);
Nz::FramePass& bloomBlurPassVertical = graph.AddPass("Bloom pass - gaussian blur #" + std::to_string(i) + " - vertical");
bloomBlurPassVertical.SetCommandCallback([&, i](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
bloomBlurPassVertical.SetCommandCallback([&, i](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderArea);
builder.SetViewport(renderArea);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
builder.BindShaderBinding(0, *gaussianBlurShaderBinding[i * 2 + 1]);
builder.BindPipeline(*gaussianBlurPipeline);
@ -1043,10 +1043,10 @@ int main()
}
Nz::FramePass& bloomBlendPass = graph.AddPass("Bloom pass - blend");
bloomBlendPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
bloomBlendPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderArea);
builder.SetViewport(renderArea);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
builder.BindVertexBuffer(0, *fullscreenVertexBuffer);
// Blend bloom
@ -1079,10 +1079,10 @@ int main()
Nz::FramePass& toneMappingPass = graph.AddPass("Tone mapping");
toneMappingPass.AddInput(bloomOutput);
toneMappingPass.AddOutput(toneMappingOutput);
toneMappingPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::Recti& renderArea)
toneMappingPass.SetCommandCallback([&](Nz::CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderArea);
builder.SetViewport(renderArea);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
builder.BindShaderBinding(0, *toneMappingShaderBinding);
builder.BindPipeline(*toneMappingPipeline);

View File

@ -19,8 +19,10 @@
namespace Nz
{
class BakedFrameGraph;
class CommandBufferBuilder;
class FrameGraph;
class RenderFrame;
enum class FramePassExecution
{
@ -29,10 +31,17 @@ namespace Nz
UpdateAndExecute
};
struct FramePassEnvironment
{
BakedFrameGraph& frameGraph;
Recti renderRect;
RenderFrame& renderFrame;
};
class NAZARA_GRAPHICS_API FramePass
{
public:
using CommandCallback = std::function<void(CommandBufferBuilder& builder, const Recti& renderRect)>;
using CommandCallback = std::function<void(CommandBufferBuilder& builder, const FramePassEnvironment& env)>;
using ExecutionCallback = std::function<FramePassExecution()>;
struct DepthStencilClear;
struct Input;

View File

@ -21,6 +21,7 @@ namespace Nz
case PixelFormat::BGRA8: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
case PixelFormat::BGRA8_SRGB: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
case PixelFormat::Depth16: return GLTextureFormat{ GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_RED, GL_ZERO, GL_ZERO, GL_ZERO };
case PixelFormat::Depth24: return GLTextureFormat{ GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_RED, GL_ZERO, GL_ZERO, GL_ZERO };
case PixelFormat::Depth24Stencil8: return GLTextureFormat{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_RED, GL_GREEN, GL_ZERO, GL_ZERO };
case PixelFormat::Depth32F: return GLTextureFormat{ GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT, GL_RED, GL_ZERO, GL_ZERO, GL_ZERO };
case PixelFormat::Depth32FStencil8: return GLTextureFormat{ GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_RED, GL_GREEN, GL_ZERO, GL_ZERO };

View File

@ -67,6 +67,12 @@ namespace Nz
if (!passData.name.empty())
builder.BeginDebugRegion(passData.name, Color::Green);
FramePassEnvironment env{
*this,
passData.renderRect,
renderFrame
};
bool first = true;
for (auto& subpass : passData.subpasses)
{
@ -75,7 +81,7 @@ namespace Nz
first = false;
subpass.commandCallback(builder, passData.renderRect);
subpass.commandCallback(builder, env);
}
if (!passData.name.empty())

View File

@ -137,7 +137,7 @@ namespace Nz
return (m_rebuildCommandBuffer) ? FramePassExecution::UpdateAndExecute : FramePassExecution::Execute;
});
depthPrepass.SetCommandCallback([this](CommandBufferBuilder& builder, const Recti& /*renderRect*/)
depthPrepass.SetCommandCallback([this](CommandBufferBuilder& builder, const FramePassEnvironment& /*env*/)
{
Recti viewport = m_viewer->GetViewport();

View File

@ -532,10 +532,10 @@ namespace Nz
mergePass.AddOutput(renderTargetData.finalAttachment);
mergePass.SetClearColor(0, Color::Black);
mergePass.SetCommandCallback([&targetViewers](CommandBufferBuilder& builder, const Recti& renderRect)
mergePass.SetCommandCallback([&targetViewers](CommandBufferBuilder& builder, const Nz::FramePassEnvironment& env)
{
builder.SetScissor(renderRect);
builder.SetViewport(renderRect);
builder.SetScissor(env.renderRect);
builder.SetViewport(env.renderRect);
Graphics* graphics = Graphics::Instance();
builder.BindPipeline(*graphics->GetBlitPipeline(false));

View File

@ -282,7 +282,7 @@ namespace Nz
return (m_rebuildCommandBuffer) ? FramePassExecution::UpdateAndExecute : FramePassExecution::Execute;
});
forwardPass.SetCommandCallback([this](CommandBufferBuilder& builder, const Recti& /*renderRect*/)
forwardPass.SetCommandCallback([this](CommandBufferBuilder& builder, const FramePassEnvironment& /*env*/)
{
Recti viewport = m_viewer->GetViewport();