Merge branch 'master' into automatic-file-fix

This commit is contained in:
Jérôme Leclercq
2021-10-28 09:57:59 +02:00
committed by GitHub
55 changed files with 780 additions and 517 deletions

View File

@@ -36,6 +36,16 @@ namespace Nz
template<typename T> void HashCombine(std::size_t& seed, const T& v);
template<typename T> bool IsPowerOfTwo(T value);
template<typename T> T ReverseBits(T integer);
#ifdef NAZARA_DEBUG
template<typename To, typename From, std::enable_if_t<std::is_integral_v<To> && std::is_integral_v<From>, int> = 0> To SafeCast(From value);
template<typename To, typename From, std::enable_if_t<std::is_floating_point_v<To> && std::is_floating_point_v<From>, int> = 0> To SafeCast(From value);
template<typename To, typename From, std::enable_if_t<std::is_integral_v<To> && std::is_floating_point_v<From>, int> = 0> To SafeCast(From value);
template<typename To, typename From, std::enable_if_t<std::is_floating_point_v<To> && std::is_integral_v<From>, int> = 0> To SafeCast(From value);
template<typename To, typename From, std::enable_if_t<std::is_enum_v<To>&& std::is_integral_v<From>, int> = 0> To SafeCast(From value);
template<typename To, typename From, std::enable_if_t<std::is_integral_v<To>&& std::is_enum_v<From>, int> = 0> To SafeCast(From value);
#else
template<typename To, typename From> To SafeCast(From value);
#endif
template<typename T> constexpr auto UnderlyingCast(T value) -> std::underlying_type_t<T>;
template<typename T>

View File

@@ -13,6 +13,7 @@
#include <Nazara/Core/Stream.hpp>
#include <cassert>
#include <climits>
#include <limits>
#include <utility>
#include <Nazara/Core/Debug.hpp>
@@ -291,6 +292,75 @@ namespace Nz
return reversed;
}
#ifdef NAZARA_DEBUG
template<typename To, typename From, std::enable_if_t<std::is_integral_v<To> && std::is_integral_v<From>, int>>
To SafeCast(From value)
{
// Type capable of storing the biggest value between the two types
using MaxValueType = std::conditional_t<(sizeof(From) > sizeof(To) || (sizeof(From) == sizeof(To) && std::is_signed_v<To>)), From, To>;
// Type capable of storing the smallest value between the two types
using MinValueType = std::conditional_t<(sizeof(From) > sizeof(To) || (sizeof(From) == sizeof(To) && std::is_signed_v<From>)), From, To>;
if constexpr (!std::is_signed_v<To>)
assert(value >= 0);
assert(static_cast<MaxValueType>(value) <= static_cast<MaxValueType>(std::numeric_limits<To>::max()));
assert(static_cast<MinValueType>(value) >= static_cast<MinValueType>(std::numeric_limits<To>::lowest()));
return static_cast<To>(value);
}
template<typename To, typename From, std::enable_if_t<std::is_floating_point_v<To> && std::is_floating_point_v<From>, int>>
To SafeCast(From value)
{
// Type capable of storing the biggest value between the two types
using MaxValueType = std::conditional_t<(sizeof(From) > sizeof(To)), From, To>;
// Type capable of storing the smallest value between the two types
using MinValueType = std::conditional_t<(sizeof(From) > sizeof(To)), From, To>;
assert(static_cast<MaxValueType>(value) <= static_cast<MaxValueType>(std::numeric_limits<To>::max()));
assert(static_cast<MinValueType>(value) >= static_cast<MinValueType>(std::numeric_limits<To>::lowest()));
return static_cast<To>(value);
}
template<typename To, typename From, std::enable_if_t<std::is_integral_v<To> && std::is_floating_point_v<From>, int>>
To SafeCast(From value)
{
assert(floor(value) == value);
assert(value <= static_cast<From>(std::numeric_limits<To>::max()));
assert(value >= static_cast<From>(std::numeric_limits<To>::lowest()));
return static_cast<To>(value);
}
template<typename To, typename From, std::enable_if_t<std::is_floating_point_v<To> && std::is_integral_v<From>, int>>
To SafeCast(From value)
{
return static_cast<To>(value);
}
template<typename To, typename From, std::enable_if_t<std::is_enum_v<To> && std::is_integral_v<From>, int>>
To SafeCast(From value)
{
return static_cast<To>(SafeCast<std::underlying_type_t<To>>(value));
}
template<typename To, typename From, std::enable_if_t<std::is_integral_v<To> && std::is_enum_v<From>, int>>
To SafeCast(From value)
{
return SafeCast<To>(static_cast<std::underlying_type_t<From>>(value));
}
#else
template<typename To, typename From>
To SafeCast(From value)
{
return static_cast<To>(value);
}
#endif
template<typename T>
constexpr auto UnderlyingCast(T value) -> std::underlying_type_t<T>
{

View File

@@ -19,6 +19,7 @@ namespace Nz
class CommandBufferBuilder;
class RenderElement;
class RenderFrame;
class ViewerInstance;
struct ElementRendererData;
class NAZARA_GRAPHICS_API ElementRenderer
@@ -28,8 +29,8 @@ namespace Nz
virtual ~ElementRenderer();
virtual std::unique_ptr<ElementRendererData> InstanciateData() = 0;
virtual void Prepare(ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer<const RenderElement>* elements, std::size_t elementCount);
virtual void Render(ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) = 0;
virtual void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer<const RenderElement>* elements, std::size_t elementCount);
virtual void Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) = 0;
virtual void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame);
};

View File

@@ -50,6 +50,17 @@ namespace Nz
Orthographic,
Perspective
};
enum class PredefinedShaderBinding
{
InstanceDataUbo,
OverlayTexture,
ViewerDataUbo,
Max = ViewerDataUbo
};
constexpr std::size_t PredefinedShaderBindingCount = static_cast<std::size_t>(PredefinedShaderBinding::Max) + 1;
}
#endif // NAZARA_GRAPHICS_ENUMS_HPP

View File

@@ -87,6 +87,7 @@ namespace Nz
RenderQueue<RenderElement*> depthPrepassRenderQueue;
RenderQueue<RenderElement*> forwardRenderQueue;
ShaderBindingPtr blitShaderBinding;
bool prepare = true;
bool rebuildDepthPrepass = true;
bool rebuildForwardPass = true;
};

View File

@@ -42,7 +42,6 @@ namespace Nz
inline MaterialPassRegistry& GetMaterialPassRegistry();
inline const MaterialPassRegistry& GetMaterialPassRegistry() const;
inline PixelFormat GetPreferredDepthStencilFormat() const;
inline const std::shared_ptr<RenderPipelineLayout>& GetReferencePipelineLayout() const;
inline const std::shared_ptr<RenderDevice>& GetRenderDevice() const;
inline const RenderPassCache& GetRenderPassCache() const;
inline TextureSamplerCache& GetSamplerCache();
@@ -55,17 +54,12 @@ namespace Nz
struct DefaultTextures
{
std::shared_ptr<Texture> whiteTexture2d;
std::array<std::shared_ptr<Texture>, ImageTypeCount> whiteTextures;
};
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);
static void FillDrawDataPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set);
static void FillViewerPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set);
static void FillWorldPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set);
private:
void BuildBlitPipeline();
@@ -80,7 +74,6 @@ namespace Nz
std::shared_ptr<RenderDevice> m_renderDevice;
std::shared_ptr<RenderPipeline> m_blitPipeline;
std::shared_ptr<RenderPipelineLayout> m_blitPipelineLayout;
std::shared_ptr<RenderPipelineLayout> m_referencePipelineLayout;
std::shared_ptr<VertexDeclaration> m_fullscreenVertexDeclaration;
DefaultTextures m_defaultTextures;
MaterialPassRegistry m_materialPassRegistry;

View File

@@ -47,11 +47,6 @@ namespace Nz
return m_preferredDepthStencilFormat;
}
inline const std::shared_ptr<RenderPipelineLayout>& Graphics::GetReferencePipelineLayout() const
{
return m_referencePipelineLayout;
}
inline const std::shared_ptr<RenderDevice>& Graphics::GetRenderDevice() const
{
return m_renderDevice;

View File

@@ -22,7 +22,7 @@ namespace Nz
inline void AddPass(std::size_t passIndex, std::shared_ptr<MaterialPass> pass);
inline void AddPass(std::string passName, std::shared_ptr<MaterialPass> pass);
inline MaterialPass* GetPass(std::size_t passIndex) const;
inline const std::shared_ptr<MaterialPass>& GetPass(std::size_t passIndex) const;
inline bool HasPass(std::size_t passIndex) const;

View File

@@ -21,17 +21,23 @@ namespace Nz
return AddPass(registry.GetPassIndex(passName), std::move(pass));
}
inline MaterialPass* Material::GetPass(std::size_t passIndex) const
inline const std::shared_ptr<MaterialPass>& Material::GetPass(std::size_t passIndex) const
{
if (passIndex >= m_passes.size())
return nullptr;
{
static std::shared_ptr<MaterialPass> dummy;
return dummy;
}
return m_passes[passIndex].get();
return m_passes[passIndex];
}
inline bool Material::HasPass(std::size_t passIndex) const
{
return GetPass(passIndex) != nullptr;
if (passIndex >= m_passes.size())
return false;
return m_passes[passIndex] != nullptr;
}
inline void Material::RemovePass(std::size_t passIndex)

View File

@@ -52,6 +52,8 @@ namespace Nz
inline void EnsurePipelineUpdate() const;
void FillShaderBinding(std::vector<ShaderBinding::Binding>& bindings) const;
inline RendererComparison GetDepthCompareFunc() const;
inline BlendEquation GetBlendAlphaModeEquation() const;
inline BlendEquation GetBlendColorModeEquation() const;
@@ -70,7 +72,6 @@ namespace Nz
inline PrimitiveMode GetPrimitiveMode() const;
inline const std::shared_ptr<const MaterialSettings>& GetSettings() const;
inline const std::shared_ptr<UberShader>& GetShader(ShaderStageType shaderStage) const;
inline ShaderBinding& GetShaderBinding();
inline const std::shared_ptr<Texture>& GetTexture(std::size_t textureIndex) const;
inline const TextureSamplerInfo& GetTextureSampler(std::size_t textureIndex) const;
inline const std::shared_ptr<AbstractBuffer>& GetUniformBuffer(std::size_t bufferIndex) const;
@@ -109,12 +110,11 @@ namespace Nz
NazaraSignal(OnMaterialRelease, const MaterialPass* /*material*/);
private:
inline void InvalidateCommandBuffer();
inline void InvalidatePipeline();
inline void InvalidateShaderBinding();
inline void InvalidateTextureSampler(std::size_t textureIndex);
inline void InvalidateUniformData(std::size_t uniformBufferIndex);
void UpdatePipeline() const;
void UpdateShaderBinding();
struct MaterialTexture
{
@@ -137,10 +137,8 @@ namespace Nz
mutable std::shared_ptr<MaterialPipeline> m_pipeline;
mutable MaterialPipelineInfo m_pipelineInfo;
MaterialPassFlags m_flags;
ShaderBindingPtr m_shaderBinding;
bool m_forceCommandBufferRegeneration;
mutable bool m_pipelineUpdated;
bool m_shaderBindingUpdated;
};
}

View File

@@ -373,12 +373,6 @@ namespace Nz
return m_pipelineInfo.shaders[UnderlyingCast(shaderStage)].uberShader;
}
inline ShaderBinding& MaterialPass::GetShaderBinding()
{
assert(m_shaderBinding);
return *m_shaderBinding;
}
inline const std::shared_ptr<Texture>& MaterialPass::GetTexture(std::size_t textureIndex) const
{
NazaraAssert(textureIndex < m_textures.size(), "Invalid texture index");
@@ -614,7 +608,8 @@ namespace Nz
if (m_textures[textureIndex].texture != texture)
{
m_textures[textureIndex].texture = std::move(texture);
InvalidateShaderBinding();
InvalidateCommandBuffer();
}
}
@@ -624,6 +619,7 @@ namespace Nz
if (m_textures[textureIndex].samplerInfo != samplerInfo)
{
m_textures[textureIndex].samplerInfo = std::move(samplerInfo);
InvalidateTextureSampler(textureIndex);
}
}
@@ -635,10 +631,17 @@ namespace Nz
{
m_uniformBuffers[bufferIndex].buffer = std::move(uniformBuffer);
m_uniformBuffers[bufferIndex].dataInvalidated = true;
InvalidateShaderBinding();
InvalidateCommandBuffer();
}
}
inline void MaterialPass::InvalidateCommandBuffer()
{
m_forceCommandBufferRegeneration = true;
OnMaterialInvalidated(this);
}
inline void MaterialPass::InvalidatePipeline()
{
m_forceCommandBufferRegeneration = true;
@@ -647,20 +650,12 @@ namespace Nz
OnMaterialInvalidated(this);
}
inline void MaterialPass::InvalidateShaderBinding()
{
m_forceCommandBufferRegeneration = true;
m_shaderBindingUpdated = false;
OnMaterialInvalidated(this);
}
inline void MaterialPass::InvalidateTextureSampler(std::size_t textureIndex)
{
assert(textureIndex < m_textures.size());
m_textures[textureIndex].sampler.reset();
InvalidateShaderBinding();
InvalidateCommandBuffer();
}
inline void MaterialPass::InvalidateUniformData(std::size_t uniformBufferIndex)
@@ -674,4 +669,3 @@ namespace Nz
}
#include <Nazara/Graphics/DebugOff.hpp>
#include "MaterialPass.hpp"

View File

@@ -28,6 +28,7 @@ namespace Nz
struct SharedUniformBlock;
struct Texture;
struct UniformBlock;
using PredefinedBinding = std::array<std::size_t, PredefinedShaderBindingCount>;
inline MaterialSettings();
inline MaterialSettings(Builder builder);
@@ -38,6 +39,7 @@ namespace Nz
inline const Builder& GetBuilderData() const;
inline const std::vector<Option>& GetOptions() const;
inline std::size_t GetOptionIndex(const std::string_view& name) const;
inline std::size_t GetPredefinedBinding(PredefinedShaderBinding shaderBinding) const;
inline const std::shared_ptr<RenderPipelineLayout>& GetRenderPipelineLayout() const;
inline const std::shared_ptr<UberShader>& GetShader(ShaderStageType stage) const;
inline const std::vector<std::shared_ptr<UberShader>>& GetShaders() const;
@@ -59,11 +61,14 @@ namespace Nz
struct Builder
{
inline Builder();
std::vector<std::shared_ptr<UberShader>> shaders;
std::vector<Option> options;
std::vector<Texture> textures;
std::vector<UniformBlock> uniformBlocks;
std::vector<SharedUniformBlock> sharedUniformBlocks;
PredefinedBinding predefinedBindings;
};
struct Option

View File

@@ -18,14 +18,11 @@ namespace Nz
m_data(std::move(data))
{
RenderPipelineLayoutInfo info;
Graphics::FillDrawDataPipelineLayout(info);
Graphics::FillViewerPipelineLayout(info);
Graphics::FillWorldPipelineLayout(info);
for (const Texture& textureInfo : m_data.textures)
{
info.bindings.push_back({
Graphics::MaterialBindingSet,
0,
textureInfo.bindingIndex,
ShaderBindingType::Texture,
textureInfo.shaderStages
@@ -35,7 +32,7 @@ namespace Nz
for (const UniformBlock& ubo : m_data.uniformBlocks)
{
info.bindings.push_back({
Graphics::MaterialBindingSet,
0,
ubo.bindingIndex,
ShaderBindingType::UniformBuffer,
ubo.shaderStages
@@ -45,7 +42,7 @@ namespace Nz
for (const SharedUniformBlock& ubo : m_data.sharedUniformBlocks)
{
info.bindings.push_back({
Graphics::MaterialBindingSet,
0,
ubo.bindingIndex,
ShaderBindingType::UniformBuffer,
ubo.shaderStages
@@ -76,6 +73,11 @@ namespace Nz
return InvalidIndex;
}
inline std::size_t MaterialSettings::GetPredefinedBinding(PredefinedShaderBinding shaderBinding) const
{
return m_data.predefinedBindings[UnderlyingCast(shaderBinding)];
}
inline const std::shared_ptr<RenderPipelineLayout>& MaterialSettings::GetRenderPipelineLayout() const
{
return m_pipelineLayout;
@@ -193,6 +195,11 @@ namespace Nz
});
}
}
inline MaterialSettings::Builder::Builder()
{
predefinedBindings.fill(InvalidIndex);
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -31,7 +31,7 @@ namespace Nz
std::array<std::size_t, 3> lightArray;
std::size_t lightArraySize;
static PredefinedLightData GetOffset();
static PredefinedLightData GetOffsets();
static MaterialSettings::SharedUniformBlock GetUniformBlock();
};
@@ -42,6 +42,7 @@ namespace Nz
std::size_t worldMatrixOffset;
static PredefinedInstanceData GetOffsets();
static MaterialSettings::SharedUniformBlock GetUniformBlock(UInt32 bindingIndex, ShaderStageTypeFlags shaderStages);
};
struct NAZARA_GRAPHICS_API PredefinedViewerData
@@ -58,6 +59,7 @@ namespace Nz
std::size_t viewProjMatrixOffset;
static PredefinedViewerData GetOffsets();
static MaterialSettings::SharedUniformBlock GetUniformBlock(UInt32 bindingIndex, ShaderStageTypeFlags shaderStages);
};
}

View File

@@ -3,13 +3,14 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/RenderElement.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline RenderElement::RenderElement(BasicRenderElement elementType) :
RenderElement(static_cast<UInt8>(elementType))
RenderElement(SafeCast<UInt8>(elementType))
{
}

View File

@@ -8,6 +8,7 @@
#define NAZARA_GRAPHICS_RENDERSPRITECHAIN_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/MaterialPass.hpp>
#include <Nazara/Graphics/RenderElement.hpp>
#include <Nazara/Graphics/RenderQueueRegistry.hpp>
#include <Nazara/Graphics/WorldInstance.hpp>
@@ -17,36 +18,35 @@
namespace Nz
{
class AbstractBuffer;
class RenderPipeline;
class ShaderBinding;
class MaterialPass;
class VertexDeclaration;
class ViewerInstance;
class RenderSpriteChain : public RenderElement
{
public:
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 WorldInstance& worldInstance, const MaterialPassFlags& matFlags);
inline RenderSpriteChain(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::shared_ptr<Texture> textureOverlay, std::size_t spriteCount, const void* spriteData);
~RenderSpriteChain() = default;
inline UInt64 ComputeSortingScore(const Nz::Frustumf& frustum, const RenderQueueRegistry& registry) const override;
inline UInt64 ComputeSortingScore(const Frustumf& frustum, const RenderQueueRegistry& registry) const override;
inline const ShaderBinding& GetInstanceBinding() const;
inline const ShaderBinding& GetMaterialBinding() const;
inline const RenderPipeline* GetRenderPipeline() const;
inline const MaterialPass& GetMaterialPass() const;
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 const WorldInstance& GetWorldInstance() const;
inline void Register(RenderQueueRegistry& registry) const override;
private:
std::shared_ptr<MaterialPass> m_materialPass;
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;
MaterialPassFlags m_matFlags;
const ShaderBinding& m_materialBinding;
const WorldInstance& m_worldInstance;
int m_renderLayer;
};

View File

@@ -8,28 +8,27 @@
namespace Nz
{
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 WorldInstance& worldInstance, const MaterialPassFlags& matFlags) :
inline RenderSpriteChain::RenderSpriteChain(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::shared_ptr<Texture> textureOverlay, std::size_t spriteCount, const void* spriteData) :
RenderElement(BasicRenderElement::SpriteChain),
m_materialPass(std::move(materialPass)),
m_renderPipeline(std::move(renderPipeline)),
m_vertexDeclaration(std::move(vertexDeclaration)),
m_textureOverlay(std::move(textureOverlay)),
m_spriteCount(spriteCount),
m_spriteData(spriteData),
m_matFlags(matFlags),
m_materialBinding(materialBinding),
m_worldInstance(worldInstance),
m_renderLayer(renderLayer)
{
}
inline UInt64 RenderSpriteChain::ComputeSortingScore(const Nz::Frustumf& frustum, const RenderQueueRegistry& registry) const
inline UInt64 RenderSpriteChain::ComputeSortingScore(const Frustumf& frustum, const RenderQueueRegistry& registry) const
{
UInt64 layerIndex = registry.FetchLayerIndex(m_renderLayer);
UInt64 elementType = GetElementType();
UInt64 pipelineIndex = registry.FetchPipelineIndex(m_renderPipeline.get());
UInt64 vertexDeclarationIndex = registry.FetchVertexDeclaration(m_vertexDeclaration.get());
if (m_matFlags.Test(MaterialPassFlag::Transparent))
if (m_materialPass->IsFlagEnabled(MaterialPassFlag::Transparent))
{
UInt64 matFlags = 1;
@@ -66,19 +65,14 @@ namespace Nz
}
}
inline const ShaderBinding& RenderSpriteChain::GetInstanceBinding() const
inline const MaterialPass& RenderSpriteChain::GetMaterialPass() const
{
return m_worldInstance.GetShaderBinding();
return *m_materialPass;
}
inline const ShaderBinding& RenderSpriteChain::GetMaterialBinding() const
inline const RenderPipeline& RenderSpriteChain::GetRenderPipeline() const
{
return m_materialBinding;
}
inline const RenderPipeline* RenderSpriteChain::GetRenderPipeline() const
{
return m_renderPipeline.get();
return *m_renderPipeline;
}
inline std::size_t RenderSpriteChain::GetSpriteCount() const
@@ -101,6 +95,11 @@ namespace Nz
return m_vertexDeclaration.get();
}
inline const WorldInstance& RenderSpriteChain::GetWorldInstance() const
{
return m_worldInstance;
}
inline void RenderSpriteChain::Register(RenderQueueRegistry& registry) const
{
registry.RegisterLayer(m_renderLayer);

View File

@@ -17,33 +17,33 @@
namespace Nz
{
class AbstractBuffer;
class MaterialPass;
class RenderPipeline;
class ShaderBinding;
class RenderSubmesh : public RenderElement
{
public:
inline RenderSubmesh(int renderLayer, std::shared_ptr<RenderPipeline> renderPipeline, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> vertexBuffer, const WorldInstance& worldInstance, const ShaderBinding& materialBinding, const MaterialPassFlags& matFlags);
inline RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> vertexBuffer);
~RenderSubmesh() = default;
inline UInt64 ComputeSortingScore(const Nz::Frustumf& frustum, const RenderQueueRegistry& registry) const override;
inline UInt64 ComputeSortingScore(const Frustumf& frustum, const RenderQueueRegistry& registry) const override;
inline const AbstractBuffer* GetIndexBuffer() const;
inline std::size_t GetIndexCount() const;
inline const MaterialPass& GetMaterialPass() const;
inline const RenderPipeline* GetRenderPipeline() const;
inline const ShaderBinding& GetInstanceBinding() const;
inline const ShaderBinding& GetMaterialBinding() const;
inline const AbstractBuffer* GetVertexBuffer() const;
inline const WorldInstance& GetWorldInstance() const;
inline void Register(RenderQueueRegistry& registry) const override;
private:
std::shared_ptr<AbstractBuffer> m_indexBuffer;
std::shared_ptr<AbstractBuffer> m_vertexBuffer;
std::shared_ptr<MaterialPass> m_materialPass;
std::shared_ptr<RenderPipeline> m_renderPipeline;
std::size_t m_indexCount;
MaterialPassFlags m_matFlags;
const ShaderBinding& m_materialBinding;
const WorldInstance& m_worldInstance;
int m_renderLayer;
};

View File

@@ -4,31 +4,31 @@
#include <Nazara/Graphics/RenderSubmesh.hpp>
#include <Nazara/Graphics/Algorithm.hpp>
#include <Nazara/Graphics/MaterialPass.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr<RenderPipeline> renderPipeline, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> vertexBuffer, const WorldInstance& worldInstance, const ShaderBinding& materialBinding, const MaterialPassFlags& matFlags) :
inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> vertexBuffer) :
RenderElement(BasicRenderElement::Submesh),
m_indexBuffer(std::move(indexBuffer)),
m_vertexBuffer(std::move(vertexBuffer)),
m_materialPass(std::move(materialPass)),
m_renderPipeline(std::move(renderPipeline)),
m_indexCount(indexCount),
m_matFlags(matFlags),
m_materialBinding(materialBinding),
m_worldInstance(worldInstance),
m_renderLayer(renderLayer)
{
}
inline UInt64 RenderSubmesh::ComputeSortingScore(const Nz::Frustumf& frustum, const RenderQueueRegistry& registry) const
inline UInt64 RenderSubmesh::ComputeSortingScore(const Frustumf& frustum, const RenderQueueRegistry& registry) const
{
UInt64 layerIndex = registry.FetchLayerIndex(m_renderLayer);
UInt64 elementType = GetElementType();
UInt64 pipelineIndex = registry.FetchPipelineIndex(m_renderPipeline.get());
UInt64 vertexBufferIndex = registry.FetchVertexBuffer(m_vertexBuffer.get());
if (m_matFlags.Test(MaterialPassFlag::Transparent))
if (m_materialPass->IsFlagEnabled(MaterialPassFlag::Transparent))
{
UInt64 matFlags = 1;
@@ -74,26 +74,26 @@ namespace Nz
return m_indexCount;
}
inline const MaterialPass& RenderSubmesh::GetMaterialPass() const
{
return *m_materialPass;
}
inline const RenderPipeline* RenderSubmesh::GetRenderPipeline() const
{
return m_renderPipeline.get();
}
inline const ShaderBinding& RenderSubmesh::GetInstanceBinding() const
{
return m_worldInstance.GetShaderBinding();
}
inline const ShaderBinding& RenderSubmesh::GetMaterialBinding() const
{
return m_materialBinding;
}
inline const AbstractBuffer* RenderSubmesh::GetVertexBuffer() const
{
return m_vertexBuffer.get();
}
inline const WorldInstance& RenderSubmesh::GetWorldInstance() const
{
return m_worldInstance;
}
inline void RenderSubmesh::Register(RenderQueueRegistry& registry) const
{
registry.RegisterLayer(m_renderLayer);

View File

@@ -30,8 +30,8 @@ namespace Nz
~SpriteChainRenderer() = default;
std::unique_ptr<ElementRendererData> InstanciateData();
void Prepare(ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer<const RenderElement>* elements, std::size_t elementCount);
void Render(ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer<const RenderElement>* elements, std::size_t elementCount);
void Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame);
private:
@@ -52,6 +52,7 @@ namespace Nz
std::size_t m_maxVertexBufferSize;
std::size_t m_maxVertexCount;
std::vector<BufferCopy> m_pendingCopies;
std::vector<ShaderBinding::Binding> m_bindingCache;
RenderDevice& m_device;
};
@@ -61,9 +62,7 @@ namespace Nz
{
const AbstractBuffer* vertexBuffer;
const RenderPipeline* renderPipeline;
const ShaderBinding* drawDataBinding;
const ShaderBinding* instanceBinding;
const ShaderBinding* materialBinding;
const ShaderBinding* shaderBinding;
std::size_t firstIndex;
std::size_t quadCount;
};

View File

@@ -13,6 +13,10 @@
namespace Nz
{
class AbstractBuffer;
class RenderPipeline;
class ShaderBinding;
class NAZARA_GRAPHICS_API SubmeshRenderer : public ElementRenderer
{
public:
@@ -20,10 +24,27 @@ namespace Nz
~SubmeshRenderer() = default;
std::unique_ptr<ElementRendererData> InstanciateData();
void Render(ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
void Prepare(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, RenderFrame& currentFrame, const Pointer<const RenderElement>* elements, std::size_t elementCount);
void Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer<const RenderElement>* elements, std::size_t elementCount) override;
void Reset(ElementRendererData& rendererData, RenderFrame& currentFrame);
private:
ShaderBindingPtr m_renderDataBinding;
std::vector<ShaderBinding::Binding> m_bindingCache;
};
struct SubmeshRendererData : public ElementRendererData
{
struct DrawCall
{
const AbstractBuffer* indexBuffer;
const AbstractBuffer* vertexBuffer;
const RenderPipeline* renderPipeline;
const ShaderBinding* shaderBinding;
std::size_t indexCount;
};
std::vector<DrawCall> drawCalls;
std::vector<ShaderBindingPtr> shaderBindings;
};
}

View File

@@ -34,9 +34,8 @@ namespace Nz
inline const Matrix4f& GetProjectionMatrix() const;
inline const Matrix4f& GetViewMatrix() const;
inline const Matrix4f& GetViewProjMatrix() const;
inline std::shared_ptr<AbstractBuffer>& GetInstanceBuffer();
inline const std::shared_ptr<AbstractBuffer>& GetInstanceBuffer() const;
inline ShaderBinding& GetShaderBinding();
inline std::shared_ptr<AbstractBuffer>& GetViewerBuffer();
inline const std::shared_ptr<AbstractBuffer>& GetViewerBuffer() const;
void UpdateBuffers(UploadPool& uploadPool, CommandBufferBuilder& builder);
inline void UpdateProjectionMatrix(const Matrix4f& projectionMatrix);
@@ -59,7 +58,6 @@ namespace Nz
Matrix4f m_projectionMatrix;
Matrix4f m_viewProjMatrix;
Matrix4f m_viewMatrix;
ShaderBindingPtr m_shaderBinding;
Vector2f m_targetSize;
bool m_dataInvalided;
};

View File

@@ -38,21 +38,16 @@ namespace Nz
return m_viewProjMatrix;
}
inline std::shared_ptr<AbstractBuffer>& ViewerInstance::GetInstanceBuffer()
inline std::shared_ptr<AbstractBuffer>& ViewerInstance::GetViewerBuffer()
{
return m_viewerDataBuffer;
}
inline const std::shared_ptr<AbstractBuffer>& ViewerInstance::GetInstanceBuffer() const
inline const std::shared_ptr<AbstractBuffer>& ViewerInstance::GetViewerBuffer() const
{
return m_viewerDataBuffer;
}
inline ShaderBinding& ViewerInstance::GetShaderBinding()
{
return *m_shaderBinding;
}
inline void ViewerInstance::UpdateProjectionMatrix(const Matrix4f& projectionMatrix)
{
m_projectionMatrix = projectionMatrix;

View File

@@ -34,8 +34,6 @@ namespace Nz
inline std::shared_ptr<AbstractBuffer>& GetInstanceBuffer();
inline const std::shared_ptr<AbstractBuffer>& GetInstanceBuffer() const;
inline const Matrix4f& GetInvWorldMatrix() const;
inline ShaderBinding& GetShaderBinding();
inline const ShaderBinding& GetShaderBinding() const;
inline const Matrix4f& GetWorldMatrix() const;
void UpdateBuffers(UploadPool& uploadPool, CommandBufferBuilder& builder);
@@ -49,7 +47,6 @@ namespace Nz
std::shared_ptr<AbstractBuffer> m_instanceDataBuffer;
Matrix4f m_invWorldMatrix;
Matrix4f m_worldMatrix;
ShaderBindingPtr m_shaderBinding;
bool m_dataInvalided;
};
}

View File

@@ -23,16 +23,6 @@ namespace Nz
return m_invWorldMatrix;
}
inline ShaderBinding& WorldInstance::GetShaderBinding()
{
return *m_shaderBinding;
}
inline const ShaderBinding& WorldInstance::GetShaderBinding() const
{
return *m_shaderBinding;
}
inline const Matrix4f& WorldInstance::GetWorldMatrix() const
{
return m_worldMatrix;

View File

@@ -259,6 +259,18 @@ namespace Nz
//Resize(m_preferredSize);
}
inline entt::registry& BaseWidget::GetRegistry()
{
assert(m_registry);
return *m_registry;
}
inline const entt::registry& BaseWidget::GetRegistry() const
{
assert(m_registry);
return *m_registry;
}
inline bool BaseWidget::IsRegisteredToCanvas() const
{
return m_canvas && m_canvasIndex != InvalidCanvasIndex;