Program Listing for File Mesh.hpp

Return to documentation for file (engine/include/Cacao/Mesh.hpp)

#pragma once

#include "DllHelper.hpp"
#include "Asset.hpp"

#include <memory>
#include <vector>

#include "glm/glm.hpp"

namespace Cacao {
    struct CACAO_API Vertex {
        const glm::vec3 position;
        const glm::vec2 texCoords;
        const glm::vec3 tangent;
        const glm::vec3 bitangent;
        const glm::vec3 normal;

        Vertex(glm::vec3 position, glm::vec2 texCoords = glm::vec2(0.0f), glm::vec3 tangent = glm::vec3(0.0f), glm::vec3 bitangent = glm::vec3(0.0f), glm::vec3 normal = glm::vec3(0.0f))
          : position(position), texCoords(texCoords), tangent(tangent), bitangent(bitangent), normal(normal) {}
    };

    class CACAO_API Mesh final : public Asset {
      public:
        static std::shared_ptr<Mesh> Create(std::vector<Vertex>&& vtx, std::vector<glm::uvec3>&& idx, const std::string& addr) {
            return std::shared_ptr<Mesh>(new Mesh(std::move(vtx), std::move(idx), addr));
        }

        Mesh(const Mesh&) = delete;
        Mesh(Mesh&&);
        Mesh& operator=(const Mesh&) = delete;
        Mesh& operator=(Mesh&&);

        void Realize();

        std::shared_future<void> RealizeAsync();

        void DropRealized();

        class Impl;

        ~Mesh();

      private:
        Mesh(std::vector<Vertex>&& vtx, std::vector<glm::uvec3>&& idx, const std::string& addr);
        friend class ResourceManager;
        friend class PAL;

        std::unique_ptr<Impl> impl;
        friend class ImplAccessor;
    };
}