Graphics: Add RenderTextureBlit
This commit is contained in:
parent
f3aacc0cd2
commit
80cab34088
|
|
@ -82,6 +82,7 @@
|
|||
#include <Nazara/Graphics/RenderSubmesh.hpp>
|
||||
#include <Nazara/Graphics/RenderTarget.hpp>
|
||||
#include <Nazara/Graphics/RenderTexture.hpp>
|
||||
#include <Nazara/Graphics/RenderTextureBlit.hpp>
|
||||
#include <Nazara/Graphics/RenderWindow.hpp>
|
||||
#include <Nazara/Graphics/ShaderReflection.hpp>
|
||||
#include <Nazara/Graphics/ShadowViewer.hpp>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GRAPHICS_RENDERTEXTUREBLIT_HPP
|
||||
#define NAZARA_GRAPHICS_RENDERTEXTUREBLIT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Texture;
|
||||
|
||||
class NAZARA_GRAPHICS_API RenderTextureBlit : public RenderTarget
|
||||
{
|
||||
public:
|
||||
inline RenderTextureBlit(const Vector2ui& textureSize, std::shared_ptr<Texture> targetTexture, SamplerFilter filter = SamplerFilter::Linear);
|
||||
inline RenderTextureBlit(const Vector2ui& textureSize, std::shared_ptr<Texture> targetTexture, SamplerFilter filter, PipelineStage targetPipelineStage, MemoryAccessFlags targetMemoryFlags, TextureLayout targetLayout);
|
||||
RenderTextureBlit(const RenderTextureBlit&) = delete;
|
||||
RenderTextureBlit(RenderTextureBlit&&) = delete;
|
||||
~RenderTextureBlit() = default;
|
||||
|
||||
void OnBuildGraph(FrameGraph& graph, std::size_t attachmentIndex) const override;
|
||||
void OnRenderEnd(RenderFrame& renderFrame, const BakedFrameGraph& frameGraph, std::size_t finalAttachment) const override;
|
||||
|
||||
const Vector2ui& GetSize() const override;
|
||||
|
||||
RenderTextureBlit& operator=(const RenderTextureBlit&) = delete;
|
||||
RenderTextureBlit& operator=(RenderTextureBlit&&) = delete;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Texture> m_targetTexture;
|
||||
MemoryAccessFlags m_targetMemoryFlags;
|
||||
PipelineStage m_targetPipelineStage;
|
||||
SamplerFilter m_samplerFilter;
|
||||
TextureLayout m_targetLayout;
|
||||
Vector2ui m_textureSize;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/RenderTextureBlit.inl>
|
||||
|
||||
#endif // NAZARA_GRAPHICS_RENDERTEXTUREBLIT_HPP
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline RenderTextureBlit::RenderTextureBlit(const Vector2ui& textureSize, std::shared_ptr<Texture> targetTexture, SamplerFilter filter) :
|
||||
RenderTextureBlit(textureSize, std::move(targetTexture), filter, PipelineStage::FragmentShader, MemoryAccess::ColorRead, TextureLayout::ColorInput)
|
||||
{
|
||||
}
|
||||
|
||||
RenderTextureBlit::RenderTextureBlit(const Vector2ui& textureSize, std::shared_ptr<Texture> texture, SamplerFilter filter, PipelineStage targetPipelineStage, MemoryAccessFlags targetMemoryFlags, TextureLayout targetLayout) :
|
||||
m_targetTexture(std::move(texture)),
|
||||
m_targetMemoryFlags(targetMemoryFlags),
|
||||
m_targetPipelineStage(targetPipelineStage),
|
||||
m_samplerFilter(filter),
|
||||
m_targetLayout(targetLayout),
|
||||
m_textureSize(textureSize)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/RenderTextureBlit.hpp>
|
||||
#include <Nazara/Graphics/BakedFrameGraph.hpp>
|
||||
#include <Nazara/Graphics/FrameGraph.hpp>
|
||||
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
void RenderTextureBlit::OnBuildGraph(FrameGraph& graph, std::size_t attachmentIndex) const
|
||||
{
|
||||
graph.AddOutput(attachmentIndex);
|
||||
}
|
||||
|
||||
void RenderTextureBlit::OnRenderEnd(RenderFrame& renderFrame, const BakedFrameGraph& frameGraph, std::size_t finalAttachment) const
|
||||
{
|
||||
const std::shared_ptr<Texture>& sourceTexture = frameGraph.GetAttachmentTexture(finalAttachment);
|
||||
|
||||
Vector2ui sourceTextureSize = Vector2ui(sourceTexture->GetSize());
|
||||
Vector2ui targetTextureSize = Vector2ui(m_targetTexture->GetSize());
|
||||
|
||||
renderFrame.Execute([&](CommandBufferBuilder& builder)
|
||||
{
|
||||
builder.BeginDebugRegion("Blit to texture", Color::Blue());
|
||||
{
|
||||
builder.TextureBarrier(PipelineStage::ColorOutput, PipelineStage::Transfer, MemoryAccess::ColorWrite, MemoryAccess::TransferRead, TextureLayout::ColorOutput, TextureLayout::TransferSource, *sourceTexture);
|
||||
builder.TextureBarrier(PipelineStage::TopOfPipe, PipelineStage::Transfer, {}, MemoryAccess::TransferWrite, TextureLayout::Undefined, TextureLayout::TransferDestination, *m_targetTexture);
|
||||
|
||||
Boxui fromBox(0, 0, 0, sourceTextureSize.x, sourceTextureSize.y, 1);
|
||||
Boxui toBox(0, 0, 0, targetTextureSize.x, targetTextureSize.y, 1);
|
||||
|
||||
builder.BlitTexture(*sourceTexture, fromBox, TextureLayout::TransferSource, *m_targetTexture, toBox, TextureLayout::TransferDestination, m_samplerFilter);
|
||||
builder.TextureBarrier(PipelineStage::Transfer, m_targetPipelineStage, MemoryAccess::TransferWrite, m_targetMemoryFlags, TextureLayout::TransferDestination, m_targetLayout, *m_targetTexture);
|
||||
}
|
||||
builder.EndDebugRegion();
|
||||
}, QueueType::Graphics);
|
||||
}
|
||||
|
||||
const Vector2ui& RenderTextureBlit::GetSize() const
|
||||
{
|
||||
return m_textureSize;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue