65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
#ifndef PHONGMATERIAL_H
|
|
#define PHONGMATERIAL_H
|
|
|
|
#include "material.h"
|
|
#include "glm/vec3.hpp"
|
|
#include <string>
|
|
|
|
class Texture;
|
|
|
|
struct PhongMaterial : public Material
|
|
{
|
|
enum TextureSlots
|
|
{
|
|
DIFFUSE_SLOT,
|
|
EMISSION_SLOT,
|
|
NORMALS_SLOT,
|
|
SPECULAR_SLOT,
|
|
ALPHA_SLOT,
|
|
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)
|
|
{
|
|
for(int i=0; i<NB_PHONG_SLOTS; ++i)
|
|
textures[i] = NULL;
|
|
}
|
|
|
|
void setTexture(TextureSlots slot, Texture* texture = NULL, const std::string &name = "")
|
|
{ textures[slot] = texture; textureNames[slot] = name; }
|
|
|
|
virtual ~PhongMaterial() {}
|
|
|
|
virtual void bindAttributes(Shader* myShader);
|
|
|
|
virtual unsigned int getFlags();
|
|
|
|
/**
|
|
* @brief serializeMaterial saves a material to a file
|
|
* @return true if the save succeeded
|
|
*/
|
|
static bool serialize(PhongMaterial* mat, FILE *file);
|
|
bool serialize(FILE *file) { return serialize(this, file); }
|
|
|
|
/**
|
|
* @brief deserializeMaterial creates a material from reading a file,
|
|
* be careful, this method has no way to load the attached textures, so you must do it manually,
|
|
* however, you can use the texture names stored in the textureNames array to find which textures are requested.
|
|
* @return the material or NULL if the loading failed
|
|
*/
|
|
static PhongMaterial* deserialize(FILE *file);
|
|
};
|
|
|
|
#endif // PHONGMATERIAL_H
|