Material.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # ifndef MATERIAL_H_
  2. # define MATERIAL_H_
  3. #include "RenderState.h"
  4. #include "Technique.h"
  5. #include "Properties.h"
  6. namespace gameplay
  7. {
  8. class NodeCloneContext;
  9. /**
  10. * Defines a material for an object to be rendered.
  11. *
  12. * This class encapsulates a set of rendering techniques that can be used to render an
  13. * object. This class facilitates loading of techniques using specified shaders or
  14. * material files (.material). When multiple techniques are loaded using a material file,
  15. * the current technique for an object can be set at runtime.
  16. */
  17. class Material : public RenderState
  18. {
  19. friend class Technique;
  20. friend class Pass;
  21. friend class RenderState;
  22. friend class Node;
  23. friend class Model;
  24. public:
  25. /**
  26. * Creates a material using the data from the Properties object defined at the specified URL,
  27. * where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
  28. * (and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
  29. *
  30. * @param url The URL pointing to the Properties object defining the material.
  31. *
  32. * @return A new Material.
  33. * @script{create}
  34. */
  35. static Material* create(const char* url);
  36. /**
  37. * Creates a material from the specified properties object.
  38. *
  39. * @param materialProperties The properties object defining the
  40. * material (must have namespace equal to 'material').
  41. * @return A new Material.
  42. * @script{create}
  43. */
  44. static Material* create(Properties* materialProperties);
  45. /**
  46. * Creates a material from the specified effect.
  47. *
  48. * The returned material has a single technique and a single pass for the
  49. * given effect.
  50. *
  51. * @param effect Effect for the new material.
  52. *
  53. * @return A new Material.
  54. * @script{create}
  55. */
  56. static Material* create(Effect* effect);
  57. /**
  58. * Creates a material using the specified vertex and fragment shader.
  59. *
  60. * The returned material has a single technique and a single pass for the
  61. * given effect.
  62. *
  63. * @param vshPath Path to the vertex shader file.
  64. * @param fshPath Path to the fragment shader file.
  65. * @param defines New-line delimited list of preprocessor defines.
  66. *
  67. * @return A new Material.
  68. * @script{create}
  69. */
  70. static Material* create(const char* vshPath, const char* fshPath, const char* defines = NULL);
  71. /**
  72. * Returns the number of techniques in the material.
  73. *
  74. * @return The technique count.
  75. */
  76. unsigned int getTechniqueCount() const;
  77. /**
  78. * Returns the technique at the specified index in this material.
  79. *
  80. * @param index The index of the technique to return.
  81. *
  82. * @return The specified technique.
  83. */
  84. Technique* getTechniqueByIndex(unsigned int index) const;
  85. /**
  86. * Returns the technique with the specified ID in this material.
  87. *
  88. * @param id The ID of the technique to return.
  89. *
  90. * @return The specified technique.
  91. */
  92. Technique* getTechnique(const char* id) const;
  93. /**
  94. * Returns this material's current technique.
  95. *
  96. * @return The current technique.
  97. */
  98. Technique* getTechnique() const;
  99. /**
  100. * Sets the current material technique.
  101. *
  102. * @param id ID of the technique to set.
  103. */
  104. void setTechnique(const char* id);
  105. private:
  106. /**
  107. * Constructor.
  108. */
  109. Material();
  110. /**
  111. * Constructor.
  112. */
  113. Material(const Material& m);
  114. /**
  115. * Destructor.
  116. */
  117. ~Material();
  118. /**
  119. * Clones this material.
  120. *
  121. * @param context The clone context.
  122. *
  123. * @return The newly created material.
  124. * @script{create}
  125. */
  126. Material* clone(NodeCloneContext &context) const;
  127. /**
  128. * Loads a technique from the given properties object into the specified material.
  129. */
  130. static bool loadTechnique(Material* material, Properties* techniqueProperties);
  131. /**
  132. * Load a pass from the given properties object into the specified technique.
  133. */
  134. static bool loadPass(Technique* technique, Properties* passProperites);
  135. /**
  136. * Loads render state from the specified properties object.
  137. */
  138. static void loadRenderState(RenderState* renderState, Properties* properties);
  139. Technique* _currentTechnique;
  140. std::vector<Technique*> _techniques;
  141. };
  142. }
  143. #endif