Add the ability to auto discard unused texture layer based on the compiled shader

This commit is contained in:
Benau 2018-01-22 09:55:17 +08:00
parent 0aa61ec746
commit 0ed74ac3e9
5 changed files with 20 additions and 17 deletions

View File

@ -353,17 +353,6 @@ Material::Material(const XMLNode *node, bool deprecated)
m_sampler_path[i] = ""; m_sampler_path[i] = "";
} }
} }
#ifndef SERVER_ONLY
if (ProfileWorld::isNoGraphics() || !CVS->isDefferedEnabled())
{
for (int i = 2; i < 6; i++)
{
// When advanced pipeline is off only .spm uv textures are used
m_sampler_path[i] = "";
}
}
#endif
loadContainerId(); loadContainerId();
core::stringc texfname(m_texname.c_str()); core::stringc texfname(m_texname.c_str());

View File

@ -39,8 +39,9 @@ SPDynamicDrawCall::SPDynamicDrawCall(scene::E_PRIMITIVE_TYPE pt,
m_textures.resize(m_stk_material.size()); m_textures.resize(m_stk_material.size());
for (unsigned j = 0; j < 6; j++) for (unsigned j = 0; j < 6; j++)
{ {
m_textures[0][j] = SPTextureManager::get()->getTexture m_textures[0][j] = SPTextureManager::get()->getTexture(
(std::get<2>(m_stk_material[0])->getSamplerPath(j), m_shaders[0] && m_shaders[0]->hasTextureLayer(j) ?
std::get<2>(m_stk_material[0])->getSamplerPath(j) : "",
j == 0 ? std::get<2>(m_stk_material[0]) : NULL, j == 0 ? std::get<2>(m_stk_material[0]) : NULL,
m_shaders[0] && m_shaders[0]->isSrgbForTextureLayer(j), m_shaders[0] && m_shaders[0]->isSrgbForTextureLayer(j),
std::get<2>(m_stk_material[0])->getContainerId()); std::get<2>(m_stk_material[0])->getContainerId());

View File

@ -126,7 +126,8 @@ void SPMeshBuffer::uploadGLMesh()
for (unsigned j = 0; j < 6; j++) for (unsigned j = 0; j < 6; j++)
{ {
m_textures[i][j] = SPTextureManager::get()->getTexture m_textures[i][j] = SPTextureManager::get()->getTexture
(std::get<2>(m_stk_material[i])->getSamplerPath(j), (m_shaders[0]->hasTextureLayer(j) ?
std::get<2>(m_stk_material[i])->getSamplerPath(j) : "",
j == 0 ? std::get<2>(m_stk_material[i]) : NULL, j == 0 ? std::get<2>(m_stk_material[i]) : NULL,
m_shaders[0]->isSrgbForTextureLayer(j), m_shaders[0]->isSrgbForTextureLayer(j),
std::get<2>(m_stk_material[i])->getContainerId()); std::get<2>(m_stk_material[i])->getContainerId());

View File

@ -127,7 +127,7 @@ void SPShader::addAllTextures(RenderPass rp)
const unsigned idx = const unsigned idx =
unsigned(m_prefilled_samplers[rp].size() + m_samplers[rp].size()); unsigned(m_prefilled_samplers[rp].size() + m_samplers[rp].size());
glUniform1i(loc, idx); glUniform1i(loc, idx);
m_samplers[rp].emplace_back(i, idx); m_samplers[rp][i] = idx;
} }
#endif #endif
} // addPrefilledTextures } // addPrefilledTextures

View File

@ -27,6 +27,7 @@
#include <cstring> #include <cstring>
#include <functional> #include <functional>
#include <ostream> #include <ostream>
#include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
@ -85,7 +86,7 @@ private:
GLuint m_program[RP_COUNT]; GLuint m_program[RP_COUNT];
std::vector<std::pair<unsigned, unsigned> > m_samplers[RP_COUNT]; std::map<unsigned, unsigned> m_samplers[RP_COUNT];
std::vector<std::tuple<unsigned, std::string, SamplerType, std::vector<std::tuple<unsigned, std::string, SamplerType,
GLuint> >m_prefilled_samplers[RP_COUNT]; GLuint> >m_prefilled_samplers[RP_COUNT];
@ -229,7 +230,18 @@ public:
bool isSrgbForTextureLayer(unsigned layer) const; bool isSrgbForTextureLayer(unsigned layer) const;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
bool useTangents() const { return m_use_tangents; } bool useTangents() const { return m_use_tangents; }
// ------------------------------------------------------------------------
bool hasTextureLayer(unsigned layer)
{
for (unsigned rp = RP_1ST; rp < RP_COUNT; rp++)
{
if (m_samplers[rp].find(layer) != m_samplers[rp].end())
{
return true;
}
}
return false;
}
}; };
} }