From ef9dd3a728234f04c7aa81dfb44b0a3129f79987 Mon Sep 17 00:00:00 2001 From: Tobias Frisch <tfrisch@uni-koblenz.de> Date: Thu, 16 Sep 2021 13:13:03 +0200 Subject: [PATCH] [#96] Completed docs for scene module Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de> --- modules/scene/include/vkcv/scene/Bounds.hpp | 30 ++++- modules/scene/include/vkcv/scene/Mesh.hpp | 95 ++++++++++++++-- modules/scene/include/vkcv/scene/MeshPart.hpp | 107 ++++++++++++++++-- modules/scene/include/vkcv/scene/Node.hpp | 6 +- .../include/vkcv/shader/Compiler.hpp | 2 +- 5 files changed, 215 insertions(+), 25 deletions(-) diff --git a/modules/scene/include/vkcv/scene/Bounds.hpp b/modules/scene/include/vkcv/scene/Bounds.hpp index 56d9e6b8..2ab081c1 100644 --- a/modules/scene/include/vkcv/scene/Bounds.hpp +++ b/modules/scene/include/vkcv/scene/Bounds.hpp @@ -40,12 +40,36 @@ namespace vkcv::scene { * @param[in] max Maximum values of the box as 3D vector */ Bounds(const glm::vec3& min, const glm::vec3& max); + + /** + * Destructor of an axis aligned bounding box. + */ ~Bounds() = default; - + + /** + * Copy-constructor of an axis aligned bounding box. + * @param[in] other Other box as Bounds + */ Bounds(const Bounds& other) = default; - Bounds(Bounds&& other) = default; - + + /** + * Move-constructor of an axis aligned bounding box. + * @param[in,out] other Other box as Bounds + */ + Bounds(Bounds&& other) = default; + + /** + * Copy-operator of an axis aligned bounding box. + * @param[in] other Other box as Bounds + * @return Reference to this box + */ Bounds& operator=(const Bounds& other) = default; + + /** + * Move-operator of an axis aligned bounding box. + * @param[in,out] other Other box as Bounds + * @return Reference to this box + */ Bounds& operator=(Bounds&& other) = default; /** diff --git a/modules/scene/include/vkcv/scene/Mesh.hpp b/modules/scene/include/vkcv/scene/Mesh.hpp index fc89cd02..3118696b 100644 --- a/modules/scene/include/vkcv/scene/Mesh.hpp +++ b/modules/scene/include/vkcv/scene/Mesh.hpp @@ -12,43 +12,118 @@ namespace vkcv::scene { * @addtogroup vkcv_scene * @{ */ - + + /** + * An event function type to be called on per drawcall recording level to adjust data + * like push constants with provided matrices. + */ typedef typename event_function<const glm::mat4&, const glm::mat4&, PushConstants&, vkcv::DrawcallInfo&>::type RecordMeshDrawcallFunction; class Node; - + + /** + * A class to represent a whole mesh to render. + */ class Mesh { friend class Node; private: + /** + * Parent scene of the mesh. + */ Scene& m_scene; + + /** + * List of the meshes parts. + */ std::vector<MeshPart> m_parts; + + /** + * List of the meshes drawcalls to render. + */ std::vector<DrawcallInfo> m_drawcalls; + + /** + * Local transformation matrix of the mesh. + */ glm::mat4 m_transform; + + /** + * Axis aligned bounding box of the mesh. + */ Bounds m_bounds; - + + /** + * Constructor of a new mesh with a given scene as parent. + * @param[in,out] scene Scene + */ explicit Mesh(Scene& scene); - + + /** + * Load mesh data from a scene structure from the asset loader + * creating and loading all mesh parts being required. + * @param[in] scene Scene structure from asset loader + * @param[in] mesh Mesh structure from asset loader + */ void load(const asset::Scene& scene, const asset::Mesh& mesh); - + + /** + * Record drawcalls of the mesh, equally to all its visible parts. + * @param[in] viewProjection View-transformation and projection as 4x4 matrix + * @param[out] pushConstants Structure to store push constants per drawcall + * @param[out] drawcalls List of drawcall structures + * @param[in] record Drawcall recording event function + */ void recordDrawcalls(const glm::mat4& viewProjection, PushConstants& pushConstants, std::vector<DrawcallInfo>& drawcalls, const RecordMeshDrawcallFunction& record); - + + /** + * Return the amount of drawcalls of the mesh + * as sum of all its parts. + * @return Amount of drawcalls + */ [[nodiscard]] size_t getDrawcallCount() const; public: + /** + * Destructor of a mesh. + */ ~Mesh(); - + + /** + * Copy-constructor of a mesh. + * @param[in] other Other mesh instance + */ Mesh(const Mesh& other) = default; - Mesh(Mesh&& other) = default; - + + /** + * Move-constructor of a mesh. + * @param[in,out] other Other mesh instance + */ + Mesh(Mesh&& other) = default; + + /** + * Copy-operator of a mesh. + * @param[in] other Other mesh instance + * @return Reference to this mesh instance + */ Mesh& operator=(const Mesh& other); + + /** + * Move-operator of a mesh. + * @param[in,out] other Other mesh instance + * @return Reference to this mesh instance + */ Mesh& operator=(Mesh&& other) noexcept; - + + /** + * Return the axis aligned bounding box of the mesh. + * @return Axis aligned bounding box of this mesh + */ [[nodiscard]] const Bounds& getBounds() const; diff --git a/modules/scene/include/vkcv/scene/MeshPart.hpp b/modules/scene/include/vkcv/scene/MeshPart.hpp index ec1e6c7d..8d77efd7 100644 --- a/modules/scene/include/vkcv/scene/MeshPart.hpp +++ b/modules/scene/include/vkcv/scene/MeshPart.hpp @@ -17,41 +17,128 @@ namespace vkcv::scene { class Scene; class Mesh; - + + /** + * A class to represent a group of vertices to render + * a part of a mesh. + */ class MeshPart { friend class Mesh; private: + /** + * Parent scene of the mesh part. + */ Scene& m_scene; + + /** + * The buffer handle of its vertex buffer. + */ BufferHandle m_vertices; + + /** + * The list of the used vertex buffer bindings. + */ std::vector<VertexBufferBinding> m_vertexBindings; + + /** + * The buffer handle of its index buffer. + */ BufferHandle m_indices; + + /** + * The amount of indices in its index buffer. + */ size_t m_indexCount; + + /** + * Axis aligned bounding box of the mesh part. + */ Bounds m_bounds; + + /** + * The index of the material used to render + * this part of the mesh. + */ size_t m_materialIndex; - + + /** + * Constructor of a new mesh part with a given scene as parent. + * @param[in,out] scene Scene + */ explicit MeshPart(Scene& scene); - + + /** + * Load vertex and index data from structures provided by the asset loader + * and add a matching drawcall to the list if the loaded mesh part is valid. + * @param[in] scene Scene structure from asset loader + * @param[in] vertexGroup Vertex group structure from asset loader + * @param[out] drawcalls List of drawcalls + */ void load(const asset::Scene& scene, const asset::VertexGroup& vertexGroup, std::vector<DrawcallInfo>& drawcalls); public: + /** + * Destructor of a mesh part. + */ ~MeshPart(); - + + /** + * Copy-constructor of a mesh part. + * @param[in] other Other mesh part + */ MeshPart(const MeshPart& other); - MeshPart(MeshPart&& other); - + + /** + * Move-constructor of a mesh part. + * @param[in,out] other Other mesh part + */ + MeshPart(MeshPart&& other) noexcept; + + /** + * Copy-operator of a mesh part. + * @param[in] other Other mesh part + * @return Reference to this mesh part + */ MeshPart& operator=(const MeshPart& other); - MeshPart& operator=(MeshPart&& other) noexcept; - + + /** + * Move-operator of a mesh part. + * @param[in,out] other Other mesh part + * @return Reference to this mesh part + */ + MeshPart& operator=(MeshPart&& other) noexcept; + + /** + * Get the material used by this specific part of + * the mesh for rendering. + * @return Material + */ [[nodiscard]] const material::Material& getMaterial() const; - + + /** + * Return the axis aligned bounding box of this + * specific part of the mesh. + * @return Axis aligned bounding box of this mesh part + */ [[nodiscard]] const Bounds& getBounds() const; - + + /** + * Return the status if this part of the mesh is valid + * as boolean value. + * @return true if the mesh part is valid, otherwise false + */ explicit operator bool() const; + + /** + * Return the status if this part of the mesh is invalid + * as boolean value. + * @return true if the mesh part is invalid, otherwise false + */ bool operator!() const; }; diff --git a/modules/scene/include/vkcv/scene/Node.hpp b/modules/scene/include/vkcv/scene/Node.hpp index 85305dd2..51088f25 100644 --- a/modules/scene/include/vkcv/scene/Node.hpp +++ b/modules/scene/include/vkcv/scene/Node.hpp @@ -81,7 +81,11 @@ namespace vkcv::scene { * @param[in] maxMeshesPerNode Maximum amount of meshes per node */ void splitMeshesToSubNodes(size_t maxMeshesPerNode); - + + /** + * Return the sum of drawcalls in the graph of this node. + * @return Amount of drawcalls + */ [[nodiscard]] size_t getDrawcallCount() const; diff --git a/modules/shader_compiler/include/vkcv/shader/Compiler.hpp b/modules/shader_compiler/include/vkcv/shader/Compiler.hpp index 3ffa2516..ddaaf3d9 100644 --- a/modules/shader_compiler/include/vkcv/shader/Compiler.hpp +++ b/modules/shader_compiler/include/vkcv/shader/Compiler.hpp @@ -16,7 +16,7 @@ namespace vkcv::shader { */ /** - * An event function type to react on shader compilation. + * An event function type to be called on compilation completion. */ typedef typename event_function<ShaderStage, const std::filesystem::path&>::type ShaderCompiledFunction; -- GitLab