Graphics: Add support for draw call data (texture overlay)

This commit is contained in:
Jérôme Leclercq
2021-09-05 18:26:12 +02:00
parent 26e5a41dce
commit abdcd63058
16 changed files with 160 additions and 18 deletions

View File

@@ -29,12 +29,14 @@ namespace Nz
using Dependencies = TypeList<Renderer>;
struct Config;
struct DefaultTextures;
Graphics(Config config);
~Graphics();
inline const std::shared_ptr<RenderPipeline>& GetBlitPipeline() const;
inline const std::shared_ptr<RenderPipelineLayout>& GetBlitPipelineLayout() const;
inline const DefaultTextures& GetDefaultTextures() const;
inline const std::shared_ptr<AbstractBuffer>& GetFullscreenVertexBuffer() const;
inline const std::shared_ptr<VertexDeclaration>& GetFullscreenVertexDeclaration() const;
inline MaterialPassRegistry& GetMaterialPassRegistry();
@@ -51,15 +53,23 @@ namespace Nz
bool useDedicatedRenderDevice = true;
};
static constexpr UInt32 MaterialBindingSet = 2;
struct DefaultTextures
{
std::shared_ptr<Texture> whiteTexture2d;
};
static constexpr UInt32 DrawDataBindingSet = 2;
static constexpr UInt32 MaterialBindingSet = 3;
static constexpr UInt32 ViewerBindingSet = 0;
static constexpr UInt32 WorldBindingSet = 1;
static void FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set = DrawDataBindingSet);
static void FillViewerPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set = ViewerBindingSet);
static void FillWorldPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set = WorldBindingSet);
private:
void BuildBlitPipeline();
void BuildDefaultTextures();
void BuildFullscreenVertexBuffer();
void RegisterMaterialPasses();
void SelectDepthStencilFormats();
@@ -72,6 +82,7 @@ namespace Nz
std::shared_ptr<RenderPipelineLayout> m_blitPipelineLayout;
std::shared_ptr<RenderPipelineLayout> m_referencePipelineLayout;
std::shared_ptr<VertexDeclaration> m_fullscreenVertexDeclaration;
DefaultTextures m_defaultTextures;
MaterialPassRegistry m_materialPassRegistry;
PixelFormat m_preferredDepthStencilFormat;

View File

@@ -17,6 +17,11 @@ namespace Nz
return m_blitPipelineLayout;
}
inline auto Graphics::GetDefaultTextures() const -> const DefaultTextures&
{
return m_defaultTextures;
}
inline const std::shared_ptr<AbstractBuffer>& Graphics::GetFullscreenVertexBuffer() const
{
return m_fullscreenVertexBuffer;

View File

@@ -18,6 +18,7 @@ namespace Nz
m_data(std::move(data))
{
RenderPipelineLayoutInfo info;
Graphics::FillDrawDataPipelineLayout(info);
Graphics::FillViewerPipelineLayout(info);
Graphics::FillWorldPipelineLayout(info);

View File

@@ -23,7 +23,7 @@ namespace Nz
class RenderSpriteChain : public RenderElement
{
public:
inline RenderSpriteChain(int renderLayer, std::shared_ptr<RenderPipeline> renderPipeline, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::size_t spriteCount, const void* spriteData, const ShaderBinding& materialBinding, const ShaderBinding& instanceBinding);
inline RenderSpriteChain(int renderLayer, std::shared_ptr<RenderPipeline> renderPipeline, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::shared_ptr<Texture> textureOverlay, std::size_t spriteCount, const void* spriteData, const ShaderBinding& materialBinding, const ShaderBinding& instanceBinding);
~RenderSpriteChain() = default;
inline UInt64 ComputeSortingScore(const RenderQueueRegistry& registry) const override;
@@ -33,6 +33,7 @@ namespace Nz
inline const RenderPipeline* GetRenderPipeline() const;
inline std::size_t GetSpriteCount() const;
inline const void* GetSpriteData() const;
inline const Texture* GetTextureOverlay() const;
inline const VertexDeclaration* GetVertexDeclaration() const;
inline void Register(RenderQueueRegistry& registry) const override;
@@ -40,6 +41,7 @@ namespace Nz
private:
std::shared_ptr<RenderPipeline> m_renderPipeline;
std::shared_ptr<VertexDeclaration> m_vertexDeclaration;
std::shared_ptr<Texture> m_textureOverlay;
std::size_t m_spriteCount;
const void* m_spriteData;
const ShaderBinding& m_instanceBinding;

View File

@@ -7,10 +7,11 @@
namespace Nz
{
inline RenderSpriteChain::RenderSpriteChain(int renderLayer, std::shared_ptr<RenderPipeline> renderPipeline, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::size_t spriteCount, const void* spriteData, const ShaderBinding& materialBinding, const ShaderBinding& instanceBinding) :
inline RenderSpriteChain::RenderSpriteChain(int renderLayer, std::shared_ptr<RenderPipeline> renderPipeline, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::shared_ptr<Texture> textureOverlay, std::size_t spriteCount, const void* spriteData, const ShaderBinding& materialBinding, const ShaderBinding& instanceBinding) :
RenderElement(BasicRenderElement::SpriteChain),
m_renderPipeline(std::move(renderPipeline)),
m_vertexDeclaration(std::move(vertexDeclaration)),
m_textureOverlay(std::move(textureOverlay)),
m_spriteCount(spriteCount),
m_spriteData(spriteData),
m_instanceBinding(instanceBinding),
@@ -64,6 +65,11 @@ namespace Nz
return m_spriteData;
}
inline const Texture* RenderSpriteChain::GetTextureOverlay() const
{
return m_textureOverlay.get();
}
inline const VertexDeclaration* RenderSpriteChain::GetVertexDeclaration() const
{
return m_vertexDeclaration.get();

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/ElementRenderer.hpp>
#include <Nazara/Renderer/ShaderBinding.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#include <memory>
#include <unordered_map>
@@ -53,6 +54,7 @@ namespace Nz
{
const AbstractBuffer* vertexBuffer;
const RenderPipeline* renderPipeline;
const ShaderBinding* drawDataBinding;
const ShaderBinding* instanceBinding;
const ShaderBinding* materialBinding;
std::size_t firstIndex;
@@ -68,6 +70,7 @@ namespace Nz
std::unordered_map<const RenderSpriteChain*, DrawCallIndices> drawCallPerElement;
std::vector<DrawCall> drawCalls;
std::vector<std::shared_ptr<AbstractBuffer>> vertexBuffers;
std::vector<ShaderBindingPtr> shaderBindings;
};
}

View File

@@ -9,17 +9,21 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/ElementRenderer.hpp>
#include <Nazara/Renderer/ShaderBinding.hpp>
namespace Nz
{
class NAZARA_GRAPHICS_API SubmeshRenderer : public ElementRenderer
{
public:
SubmeshRenderer() = default;
SubmeshRenderer();
~SubmeshRenderer() = default;
std::unique_ptr<ElementRendererData> InstanciateData();
void Render(ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
private:
ShaderBindingPtr m_renderDataBinding;
};
}