ParticleEmitterResource2.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Resource/ResourceObject.h>
  7. #include <AnKi/Math.h>
  8. namespace anki {
  9. class XmlElement;
  10. class ShaderProgramResourceVariantInitInfo;
  11. class ParticleEmitterResourceProperty
  12. {
  13. friend class ParticleEmitterResource2;
  14. public:
  15. ParticleEmitterResourceProperty()
  16. {
  17. zeroMemory(m_Mat4);
  18. }
  19. ParticleEmitterResourceProperty(const ParticleEmitterResourceProperty&) = delete; // Non-copyable
  20. ParticleEmitterResourceProperty& operator=(const ParticleEmitterResourceProperty&) = delete; // Non-copyable
  21. CString getName() const
  22. {
  23. return m_name;
  24. }
  25. template<typename T>
  26. const T& getValue() const;
  27. ShaderVariableDataType getDataType() const
  28. {
  29. ANKI_ASSERT(m_dataType != ShaderVariableDataType::kNone);
  30. return m_dataType;
  31. }
  32. private:
  33. ResourceString m_name;
  34. U32 m_offsetInAnKiParticleEmitterProperties = kMaxU32;
  35. ShaderVariableDataType m_dataType = ShaderVariableDataType::kNone;
  36. union
  37. {
  38. #define ANKI_SVDT_MACRO(type, baseType, rowCount, columnCount, isIntagralType) type ANKI_CONCATENATE(m_, type);
  39. #include <AnKi/Gr/ShaderVariableDataType.def.h>
  40. };
  41. };
  42. // Specialize the ParticleEmitterResourceProperty::getValue
  43. #define ANKI_SPECIALIZE_GET_VALUE(type, member) \
  44. template<> \
  45. inline const type& ParticleEmitterResourceProperty::getValue<type>() const \
  46. { \
  47. ANKI_ASSERT(m_dataType == ShaderVariableDataType::k##type); \
  48. return member; \
  49. }
  50. #define ANKI_SVDT_MACRO(type, baseType, rowCount, columnCount, isIntagralType) ANKI_SPECIALIZE_GET_VALUE(type, ANKI_CONCATENATE(m_, type))
  51. #include <AnKi/Gr/ShaderVariableDataType.def.h>
  52. #undef ANKI_SPECIALIZE_GET_VALUE
  53. // Common properties for each emitter. The rest of the properties are up to the user
  54. class ParticleEmitterResourceCommonProperties
  55. {
  56. public:
  57. U32 m_particleCount = 0;
  58. F32 m_emissionPeriod = 0.0;
  59. U32 m_particlesPerEmission = 0;
  60. };
  61. // This is the a particle emitter resource containing shader and properties.
  62. // XML format:
  63. // <particleEmitter>
  64. // <shaderProgram name="name of the shader">
  65. // [<mutation>
  66. // <mutator name="str" value="value"/>
  67. // </mutation>]
  68. // </shaderProgram>
  69. //
  70. // <!-- Common properties -->
  71. // <particleCount value="value" />
  72. // <emissionPeriod value="value" />
  73. // <particlesPerEmission value="value" />
  74. //
  75. // [<inputs>
  76. // <input name="name in AnKiParticleEmitterProperties struct" value="value(s)"/>
  77. // </inputs>]
  78. // </particleEmitter>
  79. class ParticleEmitterResource2 : public ResourceObject
  80. {
  81. public:
  82. ParticleEmitterResource2(CString fname, U32 uuid)
  83. : ResourceObject(fname, uuid)
  84. {
  85. }
  86. ~ParticleEmitterResource2() = default;
  87. /// Load it
  88. Error load(const ResourceFilename& filename, Bool async);
  89. const ParticleEmitterResourceCommonProperties& getCommonProperties() const
  90. {
  91. return m_commonProps;
  92. }
  93. ConstWeakArray<ParticleEmitterResourceProperty> getOtherProperties() const
  94. {
  95. return m_otherProps;
  96. }
  97. ConstWeakArray<U8> getPrefilledAnKiParticleEmitterProperties() const
  98. {
  99. return m_prefilledAnKiParticleEmitterProperties;
  100. }
  101. ShaderProgram& getShaderProgram() const
  102. {
  103. return *m_grProg;
  104. }
  105. const ShaderProgramResource& getShaderProgramResource() const
  106. {
  107. return *m_prog;
  108. }
  109. private:
  110. ResourceDynamicArray<U8> m_prefilledAnKiParticleEmitterProperties;
  111. ShaderProgramResourcePtr m_prog;
  112. ShaderProgramPtr m_grProg;
  113. ParticleEmitterResourceCommonProperties m_commonProps;
  114. ResourceDynamicArray<ParticleEmitterResourceProperty> m_otherProps;
  115. Error parseShaderProgram(XmlElement shaderProgramEl, Bool async);
  116. Error parseMutators(XmlElement mutatorsEl, ShaderProgramResourceVariantInitInfo& variantInitInfo);
  117. Error parseInput(XmlElement inputEl);
  118. };
  119. } // end namespace anki