// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Common.h" #include "Engine/Graphics/GPUBuffer.h" /// /// Data storage for the skinned meshes rendering /// class FLAXENGINE_API SkinnedMeshDrawData { private: bool _hasValidData = false; bool _isDirty = false; public: /// /// The bones count. /// int32 BonesCount = 0; /// /// The bone matrices buffer. Contains prepared skeletal bones transformations (stored as 4x3, 3 Vector4 behind each other). /// GPUBuffer* BoneMatrices = nullptr; /// /// The bone matrices buffer used during the previous update. Used by per-bone motion blur. /// GPUBuffer* PrevBoneMatrices = nullptr; /// /// The CPU data buffer with the bones transformations (ready to be flushed with the GPU). /// Array Data; public: /// /// Initializes a new instance of the class. /// SkinnedMeshDrawData(); /// /// Finalizes an instance of the class. /// ~SkinnedMeshDrawData(); public: /// /// Determines whether this instance is ready for rendering. /// FORCE_INLINE bool IsReady() const { return BoneMatrices != nullptr && BoneMatrices->IsAllocated(); } /// /// Setups the data container for the specified bones amount. /// /// The bones count. void Setup(int32 bonesCount); /// /// Sets the bone matrices data for the GPU buffer. Ensure to call Flush before rendering. /// /// The bones data. /// True if drop previous update bones used for motion blur, otherwise will keep them and do the update. void SetData(const Matrix* bones, bool dropHistory); /// /// After bones Data has been modified externally. Updates the bone matrices data for the GPU buffer. Ensure to call Flush before rendering. /// /// True if drop previous update bones used for motion blur, otherwise will keep them and do the update. void OnDataChanged(bool dropHistory); /// /// Flushes the bones data buffer with the GPU by sending the data fro the CPU. /// /// The GPU context. void Flush(class GPUContext* context); };