#include <Model/Model.hpp>
#include <Log/Log.hpp>
#include <Utilities/Utilities.hpp>
#include <Vk/DescriptorSet/DescriptorSet.hpp>
#include <Vk/ShaderConst.hpp>
#include <Display/WidgetDisplay/WorldDisplay/WorldDisplay.hpp>
#include <VoxelSpriteRenderer/VoxelSpriteRenderer.hpp>

#define DECL_VOXEL_SPRITE(name) std::shared_ptr<Model> Model::name;
#include <VoxelSprite/VoxelSpriteList.hpp>

Model::Model(std::shared_ptr<Vk::Buffer> buffer, std::shared_ptr<Vk::DescriptorSet> descSet) : buffer(buffer), descSet(descSet) {}

void Model::draw(GraphicsContext &context, WorldDisplay &worldDisplay)
{
    worldDisplay.getFrameDrawer().modelStage->drawModel(*descSet);
}

void Model::renderModel(std::shared_ptr<Model> &outModel, VoxelSprite &sprite, std::atomic<unsigned int> &tasksDone)
{
    GraphicsContext::onNextFrame([&outModel, &sprite, &tasksDone](GraphicsContext &)
    {
        VoxelSpriteRenderer renderer(sprite);
        outModel = renderer.makeModel();
        tasksDone++;
    });
}