Graphics/Shader: Make texture units statics

Provides better performances and prevents the sampler type bug to happen
This commit is contained in:
Lynix
2016-12-18 01:13:46 +01:00
parent 1a8805aad1
commit 682dab32b3
10 changed files with 203 additions and 183 deletions

View File

@@ -249,13 +249,12 @@ namespace Nz
if (matEntry.enabled)
{
UInt8 overlayUnit;
material->Apply(pipelineInstance, 0, &overlayUnit);
overlayUnit++;
unsigned int overlayTextureUnit = Material::GetTextureUnit(TextureMap_Overlay);
material->Apply(pipelineInstance);
shader->SendInteger(shaderUniforms->textureOverlay, overlayUnit);
shader->SendInteger(shaderUniforms->textureOverlay, overlayTextureUnit);
Renderer::SetTextureSampler(overlayUnit, material->GetDiffuseSampler());
Renderer::SetTextureSampler(overlayTextureUnit, material->GetDiffuseSampler());
auto& overlayMap = matEntry.overlayMap;
for (auto& overlayIt : overlayMap)
@@ -266,7 +265,7 @@ namespace Nz
std::size_t spriteChainCount = spriteChainVector.size();
if (spriteChainCount > 0)
{
Renderer::SetTexture(overlayUnit, (overlay) ? overlay : &m_whiteTexture);
Renderer::SetTexture(overlayTextureUnit, (overlay) ? overlay : &m_whiteTexture);
std::size_t spriteChain = 0; // Which chain of sprites are we treating
std::size_t spriteChainOffset = 0; // Where was the last offset where we stopped in the last chain
@@ -525,8 +524,7 @@ namespace Nz
if (matEntry.enabled)
{
UInt8 freeTextureUnit;
material->Apply(pipelineInstance, 0, &freeTextureUnit);
material->Apply(pipelineInstance);
ForwardRenderQueue::MeshInstanceContainer& meshInstances = matEntry.meshMap;