MaterialShaderProgramCreator.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /// At least one variable is instanced
  41. Bool usesInstancing() const
  42. {
  43. return instanced;
  44. }
  45. /// It has tessellation shaders
  46. Bool hasTessellation() const
  47. {
  48. return tessellation;
  49. }
  50. /// The fragment shader needs the vInstanceId
  51. Bool usesInstanceIdInFragmentShader() const
  52. {
  53. return instanceIdInFragmentShader;
  54. }
  55. private:
  56. /// The lines of the shader program source
  57. StringList srcLines;
  58. std::string source; ///< Shader program final source
  59. PtrVector<Input> inputs;
  60. Bool enableUniformBlocks;
  61. Bool instanced = false;
  62. Bool tessellation = false;
  63. Bool instanceIdInFragmentShader = false;
  64. /// Parse what is within the
  65. /// @code <shaderProgram></shaderProgram> @endcode
  66. void parseShaderProgramTag(const XmlElement& el);
  67. /// Parse what is within the
  68. /// @code <shader></shader> @endcode
  69. void parseShaderTag(const XmlElement& el);
  70. /// Parse what is within the @code <inputs></inputs> @endcode
  71. void parseInputsTag(const XmlElement& programEl);
  72. /// Parse what is within the @code <operation></operation> @endcode
  73. void parseOperationTag(const XmlElement& el, U32 shader, std::string& out);
  74. };
  75. } // end namespace anki
  76. #endif