some refactoring needed by the editor

This commit is contained in:
Anselme 2015-08-07 23:48:18 +02:00
parent 6499ffd9dd
commit b9dc55d0cf
6 changed files with 34 additions and 4 deletions

View File

@ -8,12 +8,12 @@ class Material
{
public:
Material(Shader* myShader = NULL) : shader(myShader) {}
Shader* getShader() {return shader;}
Shader* getShader() {return shader;}
virtual void bindAttributes() = 0;
protected:
Shader* shader;
Shader* shader;
};
#endif // MATERIAL_H

View File

@ -9,11 +9,12 @@ class Texture;
class PhongMaterial : public Material
{
public:
glm::vec3 kd;
glm::vec3 ks;
float ns;
Texture* tex;
public:
PhongMaterial() : kd(0.5f), ks(0.5f), ns(10), tex(NULL)
{
shader = ResourceBase::getShader("phong");

View File

@ -17,7 +17,12 @@ PhongModule::PhongModule(Lights::Light* myDirLight, Lights* myPointLights) :
void PhongModule::addEntity(PhongEntity* myEntity)
{
entities.push_back(myEntity);
entities.push_back(myEntity);
}
void PhongModule::clearEntities()
{
entities.clear();
}
void PhongModule::renderGL(Camera* myCamera)

View File

@ -26,6 +26,7 @@ public:
PhongModule(Lights::Light* myDirLight, Lights* myPointLights);
void addEntity(PhongEntity* myEntity);
void clearEntities();
void virtual renderGL(Camera* myCamera);
};

View File

@ -68,3 +68,13 @@ Lights* ResourceBase::getLights(const std::string &lightsName)
return lights.get(lightsName);
}
std::string ResourceBase::getMaterialName(Material* myMat)
{
return materials.getName(myMat);
}
std::string ResourceBase::getTextureName(Texture* myTex)
{
return textures.getName(myTex);
}

View File

@ -32,6 +32,9 @@ public:
static PhongEntity* getEntity(const std::string &entityName);
static Lights* getLights(const std::string &lightsName);
static std::string getMaterialName(Material* myMat);
static std::string getTextureName(Texture* myTex);
protected:
template <typename T>
class DataBase
@ -56,6 +59,16 @@ protected:
return NULL;
}
}
std::string getName(T* ptr)
{
for(const std::string &n : names)
{
if(ptr == get(n))
return n;
}
return "";
}
};
static DataBase<Texture> textures;