Sped up the lookup of the texture unit.

This commit is contained in:
Faerbit 2015-03-19 18:26:51 +01:00
parent 3680abfba4
commit 795801faa6
3 changed files with 11 additions and 2 deletions

View File

@ -19,6 +19,10 @@ Material::Material(std::string filePath, float ambientFactor, float diffuseFacto
if (allTexturesSet.size() != count) {
allTexturesVector.push_back(reference);
}
textureUnit = std::distance(Material::getAllTextures()->begin(),
std::find(std::begin(*Material::getAllTextures()),
// first two texture units are used by the loading screen
std::end(*Material::getAllTextures()), reference)) + 2;
}
Material::Material() {
@ -54,3 +58,7 @@ bool Material::isMoving(){
std::vector<SharedTexture2D>* Material::getAllTextures() {
return &allTexturesVector;
}
int Material::getTextureUnit() {
return textureUnit;
}

View File

@ -22,8 +22,10 @@ class Material{
float getShininess();
bool isMoving();
static std::vector<SharedTexture2D>* getAllTextures();
int getTextureUnit();
private:
int textureUnit;
ACGL::OpenGL::SharedTexture2D reference;
float ambientFactor;
float diffuseFactor;

View File

@ -29,8 +29,7 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
else {
shader->setUniform("movingTexture", false);
}
auto textureUnit = std::distance(Material::getAllTextures()->begin(), std::find(std::begin(*Material::getAllTextures()), std::end(*Material::getAllTextures()), material.getReference()));
shader->setUniform("uTexture", (int)textureUnit + 2);
shader->setUniform("uTexture", material.getTextureUnit());
shader->setUniform("modelMatrix", modelMatrix);
}
if (lightingPass) {