#include <gear/graphics/renderer.h>
#include <gear/graphics/pipeline.h>
#include <sokol/sokol_glue.h>

void g_renderer_begin(g_renderer* renderer) {
    sg_begin_pass(&(sg_pass){ .action = renderer->pass_action, .swapchain = sglue_swapchain() });
}

void g_renderer_draw(g_renderer* renderer, g_renderer_object object, u32 elements) {
    if(renderer->bound_pipeline_id != object.pipeline.id) {
        g_pipeline_bind(renderer, object.pipeline);
        sg_apply_bindings(&object.bind);
    }

    sg_draw(0, elements, 1);
};

void g_renderer_end(g_renderer* renderer) {
    sg_end_pass();
    sg_commit();
    renderer->bound_pipeline_id = 0;
}
