#include "pipeline.h"

#include "core/renderer/renderer.h"

bool pipeline::init() {
    vertex_buffer = aorii::get_renderer_raw()->create_vertex_buffer();
    index_buffer = aorii::get_renderer_raw()->create_index_buffer();
    return true;
}

void pipeline::destroy() {
    aorii::get_renderer_raw()->destroy_buffer(vertex_buffer);
    aorii::get_renderer_raw()->destroy_buffer(index_buffer);
}

void pipeline::set_triangle(const std::span<const aorii_vertex>& in_vertexes,
    const std::span<const aorii_triangle>& in_triangles) {
    if (vertex_buffer->get_size() < in_vertexes.size()) { vertex_buffer->resize(static_cast<int>(in_vertexes.size())); }
    const auto v_buffer = static_cast<aorii_vertex*>(vertex_buffer->lock());
    std::ranges::copy(in_vertexes, v_buffer);
    vertex_buffer->unlock();

    if (index_buffer->get_size() < in_triangles.size()) { index_buffer->resize(static_cast<int>(in_triangles.size())); }
    const auto i_buffer = static_cast<aorii_triangle*>(index_buffer->lock());
    std::ranges::copy(in_triangles, i_buffer);
    index_buffer->unlock();
}
