Graphics/[SpriteChain|Submesh]Renderer: Fix material pass not breaking batching

This commit is contained in:
Jérôme Leclercq
2021-12-01 10:40:47 +01:00
parent b256ddd06b
commit e1a378e733
6 changed files with 59 additions and 18 deletions

View File

@@ -65,6 +65,7 @@ namespace Nz
UInt8* currentAllocationMemPtr = nullptr;
const VertexDeclaration* currentVertexDeclaration = nullptr;
AbstractBuffer* currentVertexBuffer = nullptr;
const MaterialPass* currentMaterialPass = nullptr;
const RenderPipeline* currentPipeline = nullptr;
const ShaderBinding* currentShaderBinding = nullptr;
const Texture* currentTextureOverlay = nullptr;
@@ -122,24 +123,30 @@ namespace Nz
currentVertexDeclaration = vertexDeclaration;
}
if (currentPipeline != &spriteChain.GetRenderPipeline())
if (const RenderPipeline* pipeline = &spriteChain.GetRenderPipeline(); currentPipeline != pipeline)
{
FlushDrawCall();
currentPipeline = &spriteChain.GetRenderPipeline();
currentPipeline = pipeline;
}
if (currentWorldInstance != &spriteChain.GetWorldInstance())
if (const MaterialPass* materialPass = &spriteChain.GetMaterialPass(); currentMaterialPass != materialPass)
{
FlushDrawData();
currentMaterialPass = materialPass;
}
if (const WorldInstance* worldInstance = &spriteChain.GetWorldInstance(); currentWorldInstance != worldInstance)
{
// TODO: Flushing draw calls on instance binding means we can have e.g. 1000 sprites rendered using a draw call for each one
// which is far from being efficient, using some bindless could help (or at least instancing?)
FlushDrawData();
currentWorldInstance = &spriteChain.GetWorldInstance();
currentWorldInstance = worldInstance;
}
if (currentTextureOverlay != spriteChain.GetTextureOverlay())
if (const Texture* textureOverlay = spriteChain.GetTextureOverlay(); currentTextureOverlay != textureOverlay)
{
FlushDrawData();
currentTextureOverlay = spriteChain.GetTextureOverlay();
currentTextureOverlay = textureOverlay;
}
std::size_t remainingQuads = spriteChain.GetSpriteCount();

View File

@@ -29,6 +29,7 @@ namespace Nz
const AbstractBuffer* currentIndexBuffer = nullptr;
const AbstractBuffer* currentVertexBuffer = nullptr;
const MaterialPass* currentMaterialPass = nullptr;
const RenderPipeline* currentPipeline = nullptr;
const ShaderBinding* currentShaderBinding = nullptr;
const WorldInstance* currentWorldInstance = nullptr;
@@ -59,6 +60,12 @@ namespace Nz
currentPipeline = pipeline;
}
if (const MaterialPass* materialPass = &submesh.GetMaterialPass(); currentMaterialPass != materialPass)
{
FlushDrawCall();
currentMaterialPass = materialPass;
}
if (const AbstractBuffer* indexBuffer = submesh.GetIndexBuffer(); currentIndexBuffer != indexBuffer)
{
FlushDrawCall();
@@ -71,12 +78,12 @@ namespace Nz
currentVertexBuffer = vertexBuffer;
}
if (currentWorldInstance != &submesh.GetWorldInstance())
if (const WorldInstance* worldInstance = &submesh.GetWorldInstance(); currentWorldInstance != worldInstance)
{
// TODO: Flushing draw calls on instance binding means we can have e.g. 1000 sprites rendered using a draw call for each one
// which is far from being efficient, using some bindless could help (or at least instancing?)
FlushDrawData();
currentWorldInstance = &submesh.GetWorldInstance();
currentWorldInstance = worldInstance;
}
if (!currentShaderBinding)