Refactor material system (#382)

This commit is contained in:
Jérôme Leclercq
2022-10-31 19:53:41 +01:00
committed by GitHub
parent 0a8048809c
commit dc6ce8427c
156 changed files with 3633 additions and 4569 deletions

View File

@@ -9,15 +9,16 @@
namespace Nz
{
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, const Recti& scissorBox) :
inline RenderSpriteChain::RenderSpriteChain(int renderLayer, std::shared_ptr<MaterialInstance> materialInstance, MaterialPassFlags materialFlags, 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, const Recti& scissorBox) :
RenderElement(BasicRenderElement::SpriteChain),
m_materialPass(std::move(materialPass)),
m_materialInstance(std::move(materialInstance)),
m_renderPipeline(std::move(renderPipeline)),
m_vertexDeclaration(std::move(vertexDeclaration)),
m_textureOverlay(std::move(textureOverlay)),
m_spriteCount(spriteCount),
m_spriteData(spriteData),
m_worldInstance(worldInstance),
m_materialFlags(materialFlags),
m_scissorBox(scissorBox),
m_renderLayer(renderLayer)
{
@@ -27,7 +28,7 @@ namespace Nz
{
UInt64 layerIndex = registry.FetchLayerIndex(m_renderLayer);
if (m_materialPass->IsFlagEnabled(MaterialPassFlag::SortByDistance))
if (m_materialFlags.Test(MaterialPassFlag::SortByDistance))
{
UInt64 matFlags = 1;
@@ -48,7 +49,7 @@ namespace Nz
else
{
UInt64 elementType = GetElementType();
UInt64 materialPassIndex = registry.FetchMaterialPassIndex(m_materialPass.get());
UInt64 materialInstanceIndex = registry.FetchMaterialInstanceIndex(m_materialInstance.get());
UInt64 pipelineIndex = registry.FetchPipelineIndex(m_renderPipeline.get());
UInt64 vertexDeclarationIndex = registry.FetchVertexDeclaration(m_vertexDeclaration.get());
@@ -63,18 +64,18 @@ namespace Nz
// - VertexDeclaration (8bits)
// - ?? (8bits) - Depth?
return (layerIndex & 0xFF) << 60 |
(matFlags) << 52 |
(elementType & 0xF) << 51 |
(pipelineIndex & 0xFFFF) << 35 |
(materialPassIndex & 0xFFFF) << 23 |
(vertexDeclarationIndex & 0xFF) << 7;
return (layerIndex & 0xFF) << 60 |
(matFlags) << 52 |
(elementType & 0xF) << 51 |
(pipelineIndex & 0xFFFF) << 35 |
(materialInstanceIndex & 0xFFFF) << 23 |
(vertexDeclarationIndex & 0xFF) << 7;
}
}
inline const MaterialPass& RenderSpriteChain::GetMaterialPass() const
inline const MaterialInstance& RenderSpriteChain::GetMaterialInstance() const
{
return *m_materialPass;
return *m_materialInstance;
}
inline const RenderPipeline& RenderSpriteChain::GetRenderPipeline() const
@@ -115,7 +116,7 @@ namespace Nz
inline void RenderSpriteChain::Register(RenderQueueRegistry& registry) const
{
registry.RegisterLayer(m_renderLayer);
registry.RegisterMaterialPass(m_materialPass.get());
registry.RegisterMaterialInstance(m_materialInstance.get());
registry.RegisterPipeline(m_renderPipeline.get());
registry.RegisterVertexDeclaration(m_vertexDeclaration.get());
}