From bb27fb0965754272bce6be40ba91e5e08c7fcd42 Mon Sep 17 00:00:00 2001 From: Anselme Date: Mon, 20 Jun 2016 17:26:04 +0200 Subject: [PATCH] added texture name to material --- src/phongmaterial.cpp | 30 +++++++++++++++--------------- src/phongmaterial.h | 35 +++++++++++++++++------------------ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/phongmaterial.cpp b/src/phongmaterial.cpp index a3044ce..c2cbbe6 100644 --- a/src/phongmaterial.cpp +++ b/src/phongmaterial.cpp @@ -11,39 +11,39 @@ void PhongMaterial::bindAttributes(Shader* myShader) // TODO store the attributes location myShader->bindFloat(myShader->getLocation("materialNs"), shininess); - if(normal_map != NULL) + if(textures[NORMALS_SLOT] != NULL) { - normal_map->bind(NORMALS_SLOT); + textures[NORMALS_SLOT]->bind(NORMALS_SLOT); myShader->bindInteger(myShader->getLocation("normalMap"), NORMALS_SLOT); } - if(emission_texture != NULL) + if(textures[EMISSION_SLOT] != NULL) { - emission_texture->bind(EMISSION_SLOT); + textures[EMISSION_SLOT]->bind(EMISSION_SLOT); myShader->bindInteger(myShader->getLocation("emissionTexture"), EMISSION_SLOT); } else myShader->bindVec3(myShader->getLocation("materialEmission"), emission); - if(diffuse_texture != NULL) + if(textures[DIFFUSE_SLOT] != NULL) { - diffuse_texture->bind(DIFFUSE_SLOT); + textures[DIFFUSE_SLOT]->bind(DIFFUSE_SLOT); myShader->bindInteger(myShader->getLocation("diffuseTexture"), DIFFUSE_SLOT); } else myShader->bindVec3(myShader->getLocation("materialKd"), diffuse); - if(specular_texture != NULL) + if(textures[SPECULAR_SLOT] != NULL) { - specular_texture->bind(SPECULAR_SLOT); + textures[SPECULAR_SLOT]->bind(SPECULAR_SLOT); myShader->bindInteger(myShader->getLocation("specularTexture"), SPECULAR_SLOT); } else myShader->bindVec3(myShader->getLocation("materialKs"), specular); - if(alpha_mask != NULL) + if(textures[ALPHA_SLOT] != NULL) { - alpha_mask->bind(ALPHA_SLOT); + textures[ALPHA_SLOT]->bind(ALPHA_SLOT); myShader->bindInteger(myShader->getLocation("alphaMask"), ALPHA_SLOT); } } @@ -51,15 +51,15 @@ void PhongMaterial::bindAttributes(Shader* myShader) unsigned int PhongMaterial::getFlags() { unsigned int flags = 1 << Mesh::MATERIAL_PHONG; - if(normal_map != NULL) + if(textures[NORMALS_SLOT] != NULL) flags |= 1 << Mesh::MATERIAL_PHONG_NORMAL_MAP; - if(emission_texture != NULL) + if(textures[EMISSION_SLOT] != NULL) flags |= 1 << Mesh::MATERIAL_PHONG_EMISSION_TEXTURE; - if(diffuse_texture != NULL) + if(textures[DIFFUSE_SLOT] != NULL) flags |= 1 << Mesh::MATERIAL_PHONG_DIFFUSE_TEXTURE; - if(specular_texture != NULL) + if(textures[SPECULAR_SLOT] != NULL) flags |= 1 << Mesh::MATERIAL_PHONG_SPECULAR_TEXTURE; - if(alpha_mask != NULL) + if(textures[ALPHA_SLOT] != NULL) flags |= 1 << Mesh::MATERIAL_ALPHA_MASK; return flags; } diff --git a/src/phongmaterial.h b/src/phongmaterial.h index d47acbf..28db003 100644 --- a/src/phongmaterial.h +++ b/src/phongmaterial.h @@ -3,21 +3,12 @@ #include "material.h" #include "glm/vec3.hpp" +#include class Texture; struct PhongMaterial : public Material { - glm::vec3 emission; - glm::vec3 diffuse; - glm::vec3 specular; - float shininess; - Texture* emission_texture; - Texture* diffuse_texture; - Texture* specular_texture; - Texture* normal_map; - Texture* alpha_mask; - enum TextureSlots { DIFFUSE_SLOT, @@ -28,22 +19,30 @@ struct PhongMaterial : public Material NB_PHONG_SLOTS }; + glm::vec3 emission; + glm::vec3 diffuse; + glm::vec3 specular; + float shininess; + Texture* textures[NB_PHONG_SLOTS]; + std::string textureNames[NB_PHONG_SLOTS]; + PhongMaterial() : emission(0), diffuse(0.5f), specular(0.5f), - shininess(10), - emission_texture(NULL), - diffuse_texture(NULL), - specular_texture(NULL), - normal_map(NULL), - alpha_mask(NULL) - {} + shininess(10) + { + for(int i=0; i