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) {
|
if (allTexturesSet.size() != count) {
|
||||||
allTexturesVector.push_back(reference);
|
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() {
|
Material::Material() {
|
||||||
@ -54,3 +58,7 @@ bool Material::isMoving(){
|
|||||||
std::vector<SharedTexture2D>* Material::getAllTextures() {
|
std::vector<SharedTexture2D>* Material::getAllTextures() {
|
||||||
return &allTexturesVector;
|
return &allTexturesVector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Material::getTextureUnit() {
|
||||||
|
return textureUnit;
|
||||||
|
}
|
||||||
|
@ -22,8 +22,10 @@ class Material{
|
|||||||
float getShininess();
|
float getShininess();
|
||||||
bool isMoving();
|
bool isMoving();
|
||||||
static std::vector<SharedTexture2D>* getAllTextures();
|
static std::vector<SharedTexture2D>* getAllTextures();
|
||||||
|
int getTextureUnit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int textureUnit;
|
||||||
ACGL::OpenGL::SharedTexture2D reference;
|
ACGL::OpenGL::SharedTexture2D reference;
|
||||||
float ambientFactor;
|
float ambientFactor;
|
||||||
float diffuseFactor;
|
float diffuseFactor;
|
||||||
|
@ -29,8 +29,7 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
|||||||
else {
|
else {
|
||||||
shader->setUniform("movingTexture", false);
|
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", material.getTextureUnit());
|
||||||
shader->setUniform("uTexture", (int)textureUnit + 2);
|
|
||||||
shader->setUniform("modelMatrix", modelMatrix);
|
shader->setUniform("modelMatrix", modelMatrix);
|
||||||
}
|
}
|
||||||
if (lightingPass) {
|
if (lightingPass) {
|
||||||
|
Loading…
Reference in New Issue
Block a user