MaterialShaderProgramCreator.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef ANKI_RESOURCE_MATERIAL_SHADER_PROGRAM_CREATOR_H
  2. #define ANKI_RESOURCE_MATERIAL_SHADER_PROGRAM_CREATOR_H
  3. #include "anki/util/StringList.h"
  4. namespace anki {
  5. class XmlElement;
  6. /// Creator of shader programs. This class parses between
  7. /// <shaderProgam></shaderProgram> located inside a <material></material>
  8. /// and creates the source of a custom program.
  9. ///
  10. /// @note Be carefull when you change the methods. Some change may create more
  11. //// unique shaders and this is never good.
  12. class MaterialShaderProgramCreator
  13. {
  14. public:
  15. struct Input
  16. {
  17. std::string name;
  18. std::string type;
  19. StringList value;
  20. Bool constant;
  21. U32 arraySize;
  22. std::string line;
  23. U32 shaders = 0; ///< Shader mask
  24. Bool putInBlock = false;
  25. Bool instanced = false;
  26. };
  27. explicit MaterialShaderProgramCreator(const XmlElement& pt,
  28. Bool enableUniformBlocks = false);
  29. ~MaterialShaderProgramCreator();
  30. /// Get the shader program source code. This is the one and only public
  31. /// member
  32. const std::string& getShaderProgramSource() const
  33. {
  34. return source;
  35. }
  36. const PtrVector<Input>& getInputVariables() const
  37. {
  38. return inputs;
  39. }
  40. private:
  41. /// The lines of the shader program source
  42. StringList srcLines;
  43. std::string source; ///< Shader program final source
  44. PtrVector<Input> inputs;
  45. Bool enableUniformBlocks;
  46. /// Parse what is within the
  47. /// @code <shaderProgram></shaderProgram> @endcode
  48. void parseShaderProgramTag(const XmlElement& el);
  49. /// Parse what is within the
  50. /// @code <shader></shader> @endcode
  51. void parseShaderTag(const XmlElement& el);
  52. /// Parse what is within the @code <inputs></inputs> @endcode
  53. void parseInputsTag(const XmlElement& programEl);
  54. /// Parse what is within the @code <operation></operation> @endcode
  55. void parseOperationTag(const XmlElement& el, U32 shader, std::string& out);
  56. };
  57. } // end namespace anki
  58. #endif