Material.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef MATERIAL_H_
  2. #define MATERIAL_H_
  3. #include "Sampler.h"
  4. #include "Light.h"
  5. #include "Constants.h"
  6. namespace gameplay
  7. {
  8. class Material
  9. {
  10. public:
  11. /**
  12. * Constructor.
  13. */
  14. Material(const std::string& id);
  15. Material(const Material&);
  16. /**
  17. * Destructor.
  18. */
  19. virtual ~Material(void);
  20. /**
  21. * Returns this material's id string.
  22. */
  23. const std::string& getId() const;
  24. /**
  25. * Sets this material's id string.
  26. */
  27. void setId(const char* id);
  28. Material* getParent() const;
  29. void setParent(Material* material);
  30. void addDefine(const std::string& name);
  31. bool isDefined(const std::string& name) const;
  32. const char* getUniform(const char* name) const;
  33. void setUniform(const std::string& name, const std::string& value);
  34. const char* getRenderState(const char* name) const;
  35. void setRenderState(const std::string& name, const std::string& value);
  36. void setVertexShader(const char* path);
  37. void setFragmentShader(const char* path);
  38. /**
  39. * Creates a sampler and adds it to this material.
  40. */
  41. Sampler* createSampler(const std::string& id);
  42. Sampler* getSampler(const std::string& id) const;
  43. bool isTextured() const;
  44. bool isLit() const;
  45. bool isSpecular() const;
  46. bool isTextureRepeat() const;
  47. bool isVertexColor() const;
  48. bool isSkinned() const;
  49. bool isModulateAlpha() const;
  50. void setLit(bool value);
  51. /**
  52. * Writes this material to the given file.
  53. */
  54. void writeMaterial(FILE* file);
  55. private:
  56. Material& operator=(const Material&); // Hidden copy assignment operator.
  57. void writeDefines(FILE* file, unsigned int& indent);
  58. void writeUniforms(FILE* file, unsigned int& indent);
  59. void writeSamplers(FILE* file, unsigned int& indent);
  60. void writeRenderStates(FILE* file, unsigned int& indent);
  61. void writeTechniqueAndPass(FILE* file, unsigned int& indent);
  62. void writeTechniqueOpening(FILE* file, unsigned int& indent);
  63. private:
  64. Material* _parent;
  65. std::string _id;
  66. std::string _vertexShader;
  67. std::string _fragmentShader;
  68. bool _lit;
  69. std::map<std::string, std::string> _defines;
  70. std::map<std::string, std::string> _uniforms;
  71. std::map<std::string, std::string> _renderStates;
  72. std::vector<Sampler*> _samplers;
  73. };
  74. }
  75. #endif