Graphics/Camera: Add clear color per viewer

This commit is contained in:
Jérôme Leclercq 2021-11-13 20:06:34 +01:00
parent a812c69e69
commit 342c053faa
7 changed files with 22 additions and 2 deletions

View File

@ -8,6 +8,7 @@
#define NAZARA_GRAPHICS_ABSTRACTVIEWER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Math/Rect.hpp>
@ -22,6 +23,7 @@ namespace Nz
AbstractViewer() = default;
~AbstractViewer() = default;
virtual const Color& GetClearColor() const = 0;
virtual UInt32 GetRenderMask() const = 0;
virtual const RenderTarget& GetRenderTarget() = 0;
virtual ViewerInstance& GetViewerInstance() = 0;

View File

@ -11,6 +11,7 @@
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/FramePass.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
#include <Nazara/Renderer/CommandPool.hpp>
#include <Nazara/Renderer/Framebuffer.hpp>
#include <Nazara/Renderer/RenderPass.hpp>
@ -72,6 +73,7 @@ namespace Nz
std::shared_ptr<RenderPass> renderPass;
std::string name;
std::vector<std::size_t> outputTextureIndices;
std::vector<CommandBufferBuilder::ClearValues> outputClearValues;
std::vector<SubpassData> subpasses;
std::vector<TextureTransition> transitions;
FramePass::ExecutionCallback executionCallback;

View File

@ -28,6 +28,7 @@ namespace Nz
~Camera() = default;
inline float GetAspectRatio() const;
const Color& GetClearColor() const override;
inline DegreeAnglef GetFOV() const;
UInt32 GetRenderMask() const override;
const RenderTarget& GetRenderTarget() override;
@ -39,6 +40,7 @@ namespace Nz
inline float GetZFar() const;
inline float GetZNear() const;
inline void UpdateClearColor(Color color);
inline void UpdateFOV(DegreeAnglef fov);
inline void UpdateProjectionType(ProjectionType projectionType);
inline void UpdateRenderMask(UInt32 renderMask);
@ -61,6 +63,7 @@ namespace Nz
NazaraSlot(RenderTarget, OnRenderTargetSizeChange, m_onRenderTargetSizeChange);
const RenderTarget* m_renderTarget;
Color m_clearColor;
DegreeAnglef m_fov;
ProjectionType m_projectionType;
Rectf m_targetRegion;

View File

@ -10,6 +10,7 @@ namespace Nz
{
inline Camera::Camera(const RenderTarget* renderTarget, ProjectionType projectionType) :
m_renderTarget(nullptr),
m_clearColor(Color::Black),
m_fov(70.f),
m_projectionType(projectionType),
m_targetRegion(0.f, 0.f, 1.f, 1.f),
@ -24,6 +25,7 @@ namespace Nz
inline Camera::Camera(const Camera& camera) :
m_renderTarget(nullptr),
m_clearColor(camera.m_clearColor),
m_fov(camera.m_fov),
m_projectionType(camera.m_projectionType),
m_targetRegion(camera.m_targetRegion),
@ -39,6 +41,7 @@ namespace Nz
inline Camera::Camera(Camera&& camera) noexcept :
m_renderTarget(nullptr),
m_clearColor(camera.m_clearColor),
m_fov(camera.m_fov),
m_projectionType(camera.m_projectionType),
m_targetRegion(camera.m_targetRegion),
@ -82,6 +85,11 @@ namespace Nz
return m_zNear;
}
inline void Camera::UpdateClearColor(Color color)
{
m_clearColor = color;
}
inline void Camera::UpdateFOV(DegreeAnglef fov)
{
m_fov = fov;

View File

@ -62,7 +62,7 @@ namespace Nz
builder.TextureBarrier(textureTransition.srcStageMask, textureTransition.dstStageMask, textureTransition.srcAccessMask, textureTransition.dstAccessMask, textureTransition.oldLayout, textureTransition.newLayout, *texture);
}
builder.BeginRenderPass(*passData.framebuffer, *passData.renderPass, passData.renderRect);
builder.BeginRenderPass(*passData.framebuffer, *passData.renderPass, passData.renderRect, passData.outputClearValues.data(), passData.outputClearValues.size());
if (!passData.name.empty())
builder.BeginDebugRegion(passData.name, Color::Green);

View File

@ -8,6 +8,11 @@
namespace Nz
{
const Color& Camera::GetClearColor() const
{
return m_clearColor;
}
UInt32 Camera::GetRenderMask() const
{
return m_renderMask;

View File

@ -475,7 +475,7 @@ namespace Nz
forwardPass.SetDepthStencilInput(viewerData.depthStencilAttachment);
//forwardPass.SetDepthStencilOutput(viewerData.depthStencilAttachment);
forwardPass.SetClearColor(0, Color::Black);
forwardPass.SetClearColor(0, viewer->GetClearColor());
forwardPass.SetDepthStencilClear(1.f, 0);
forwardPass.SetExecutionCallback([&]()