Sped up the lookup of the texture unit.
This commit is contained in:
parent
3680abfba4
commit
795801faa6
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user