Material.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 isBumped() const;
  45. bool isLit() const;
  46. bool isSpecular() const;
  47. bool isTextureRepeat() const;
  48. bool isVertexColor() const;
  49. bool isSkinned() const;
  50. bool isModulateAlpha() const;
  51. void setLit(bool value);
  52. /**
  53. * Writes this material to the given file.
  54. */
  55. void writeMaterial(FILE* file);
  56. private:
  57. Material& operator=(const Material&); // Hidden copy assignment operator.
  58. void writeDefines(FILE* file, unsigned int& indent);
  59. void writeUniforms(FILE* file, unsigned int& indent);
  60. void writeSamplers(FILE* file, unsigned int& indent);
  61. void writeRenderStates(FILE* file, unsigned int& indent);
  62. void writeTechniqueAndPass(FILE* file, unsigned int& indent);
  63. void writeTechniqueOpening(FILE* file, unsigned int& indent);
  64. private:
  65. Material* _parent;
  66. std::string _id;
  67. std::string _vertexShader;
  68. std::string _fragmentShader;
  69. bool _lit;
  70. std::map<std::string, std::string> _defines;
  71. std::map<std::string, std::string> _uniforms;
  72. std::map<std::string, std::string> _renderStates;
  73. std::vector<Sampler*> _samplers;
  74. };
  75. }
  76. #endif