// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #pragma once #include #include namespace anki { class XmlElement; class ShaderProgramResourceVariantInitInfo; class ParticleEmitterResourceProperty { friend class ParticleEmitterResource2; public: ParticleEmitterResourceProperty() { zeroMemory(m_Mat4); } ParticleEmitterResourceProperty(const ParticleEmitterResourceProperty&) = delete; // Non-copyable ParticleEmitterResourceProperty& operator=(const ParticleEmitterResourceProperty&) = delete; // Non-copyable CString getName() const { return m_name; } template const T& getValue() const; ShaderVariableDataType getDataType() const { ANKI_ASSERT(m_dataType != ShaderVariableDataType::kNone); return m_dataType; } private: ResourceString m_name; U32 m_offsetInAnKiParticleEmitterProperties = kMaxU32; ShaderVariableDataType m_dataType = ShaderVariableDataType::kNone; union { #define ANKI_SVDT_MACRO(type, baseType, rowCount, columnCount, isIntagralType) type ANKI_CONCATENATE(m_, type); #include }; }; // Specialize the ParticleEmitterResourceProperty::getValue #define ANKI_SPECIALIZE_GET_VALUE(type, member) \ template<> \ inline const type& ParticleEmitterResourceProperty::getValue() const \ { \ ANKI_ASSERT(m_dataType == ShaderVariableDataType::k##type); \ return member; \ } #define ANKI_SVDT_MACRO(type, baseType, rowCount, columnCount, isIntagralType) ANKI_SPECIALIZE_GET_VALUE(type, ANKI_CONCATENATE(m_, type)) #include #undef ANKI_SPECIALIZE_GET_VALUE // Common properties for each emitter. The rest of the properties are up to the user class ParticleEmitterResourceCommonProperties { public: U32 m_particleCount = 0; F32 m_emissionPeriod = 0.0; U32 m_particlesPerEmission = 0; }; // This is the a particle emitter resource containing shader and properties. // XML format: // // // [ // // ] // // // // // // // // [ // // ] // class ParticleEmitterResource2 : public ResourceObject { public: ParticleEmitterResource2(CString fname, U32 uuid) : ResourceObject(fname, uuid) { } ~ParticleEmitterResource2() = default; /// Load it Error load(const ResourceFilename& filename, Bool async); const ParticleEmitterResourceCommonProperties& getCommonProperties() const { return m_commonProps; } ConstWeakArray getOtherProperties() const { return m_otherProps; } ConstWeakArray getPrefilledAnKiParticleEmitterProperties() const { return m_prefilledAnKiParticleEmitterProperties; } ShaderProgram& getShaderProgram() const { return *m_grProg; } const ShaderProgramResource& getShaderProgramResource() const { return *m_prog; } private: ResourceDynamicArray m_prefilledAnKiParticleEmitterProperties; ShaderProgramResourcePtr m_prog; ShaderProgramPtr m_grProg; ParticleEmitterResourceCommonProperties m_commonProps; ResourceDynamicArray m_otherProps; Error parseShaderProgram(XmlElement shaderProgramEl, Bool async); Error parseMutators(XmlElement mutatorsEl, ShaderProgramResourceVariantInitInfo& variantInitInfo); Error parseInput(XmlElement inputEl); }; } // end namespace anki