#ifndef __BATCH_H__
#define __BATCH_H__

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

#include <gearlib.h>
#include <slibs.h>

typedef struct BatchStats {
    uint32_t draw_calls;
    uint32_t total_verts;
} BatchStats;

typedef struct RenderBatch {
    uint32_t vbo, vao;

    uint32_t shader;

    void* vertices;
    void* vertex_ptr;
    size_t vertex_size;
    uint32_t vertex_count;
    uint32_t max_vertices;
    VertexLayout layout;

    BatchStats stats;

    void* data;
    void (*flush_callback)(struct RenderBatch*);
} RenderBatch;

typedef sl_vec(RenderBatch*) BatchList;

extern BatchList batches;

RenderBatch* create_batch(size_t vert_size, uint32_t max_verts);
void flush();
void flush_batch(RenderBatch* batch);
void batch_add_attrib(RenderBatch* batch, VertexAttrib attr);
void batch_bind_attribs(RenderBatch* batch);
bool batch_needs_flush(RenderBatch* batch, uint32_t vertex_add);

#endif
