2014-11-08 00:17:23 +00:00
|
|
|
#include "material.hh"
|
2014-10-22 21:17:18 +00:00
|
|
|
|
2015-03-18 15:26:20 +00:00
|
|
|
std::set<SharedTexture2D> Material::allTexturesSet = std::set<SharedTexture2D>();
|
|
|
|
std::vector<SharedTexture2D> Material::allTexturesVector = std::vector<SharedTexture2D>();
|
|
|
|
|
2014-11-08 00:44:24 +00:00
|
|
|
Material::Material(std::string filePath, float ambientFactor, float diffuseFactor,
|
2015-03-06 14:24:02 +00:00
|
|
|
float specularFactor, float shininess, bool movingTexture) {
|
2014-10-22 21:17:18 +00:00
|
|
|
reference = ACGL::OpenGL::Texture2DFileManager::the()->get(ACGL::OpenGL::Texture2DCreator(filePath));
|
2014-12-04 17:58:16 +00:00
|
|
|
reference->generateMipmaps();
|
2015-03-15 14:38:33 +00:00
|
|
|
reference->setMinFilter(GL_NEAREST_MIPMAP_LINEAR);
|
|
|
|
reference->setMagFilter(GL_LINEAR);
|
2014-11-08 00:44:24 +00:00
|
|
|
this->ambientFactor = ambientFactor;
|
|
|
|
this->diffuseFactor = diffuseFactor;
|
|
|
|
this->specularFactor = specularFactor;
|
|
|
|
this->shininess = shininess;
|
2015-03-06 14:24:02 +00:00
|
|
|
this->movingTexture = movingTexture;
|
2015-03-21 14:05:22 +00:00
|
|
|
unsigned int textureCount = allTexturesSet.size();
|
2015-03-18 15:26:20 +00:00
|
|
|
allTexturesSet.insert(reference);
|
2015-03-21 14:05:22 +00:00
|
|
|
if (allTexturesSet.size() != textureCount) {
|
2015-03-18 15:26:20 +00:00
|
|
|
allTexturesVector.push_back(reference);
|
|
|
|
}
|
2015-03-19 17:26:51 +00:00
|
|
|
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;
|
2014-10-22 21:17:18 +00:00
|
|
|
}
|
|
|
|
|
2014-11-08 00:17:23 +00:00
|
|
|
Material::Material() {
|
2014-10-24 08:48:45 +00:00
|
|
|
}
|
|
|
|
|
2014-11-08 00:17:23 +00:00
|
|
|
Material::~Material() {
|
2014-10-22 21:17:18 +00:00
|
|
|
}
|
|
|
|
|
2014-11-08 00:17:23 +00:00
|
|
|
ACGL::OpenGL::SharedTexture2D Material::getReference() {
|
2014-10-22 21:17:18 +00:00
|
|
|
return reference;
|
|
|
|
}
|
2014-11-08 00:44:24 +00:00
|
|
|
|
|
|
|
float Material::getAmbientFactor(){
|
|
|
|
return ambientFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Material::getDiffuseFactor(){
|
|
|
|
return diffuseFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Material::getSpecularFactor() {
|
|
|
|
return specularFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Material::getShininess() {
|
|
|
|
return shininess;
|
|
|
|
}
|
2015-03-06 14:24:02 +00:00
|
|
|
|
|
|
|
bool Material::isMoving(){
|
|
|
|
return movingTexture;
|
|
|
|
}
|
2015-03-18 15:26:20 +00:00
|
|
|
|
|
|
|
std::vector<SharedTexture2D>* Material::getAllTextures() {
|
|
|
|
return &allTexturesVector;
|
|
|
|
}
|
2015-03-19 17:26:51 +00:00
|
|
|
|
|
|
|
int Material::getTextureUnit() {
|
|
|
|
return textureUnit;
|
|
|
|
}
|