diff --git a/game/material.cc b/game/material.cc index e70df5c..63cbc21 100644 --- a/game/material.cc +++ b/game/material.cc @@ -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* Material::getAllTextures() { return &allTexturesVector; } + +int Material::getTextureUnit() { + return textureUnit; +} diff --git a/game/material.hh b/game/material.hh index 40f224a..cc9fc5d 100644 --- a/game/material.hh +++ b/game/material.hh @@ -22,8 +22,10 @@ class Material{ float getShininess(); bool isMoving(); static std::vector* getAllTextures(); + int getTextureUnit(); private: + int textureUnit; ACGL::OpenGL::SharedTexture2D reference; float ambientFactor; float diffuseFactor; diff --git a/game/object.cc b/game/object.cc index da834a2..2d32020 100644 --- a/game/object.cc +++ b/game/object.cc @@ -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) {