2024-05-03 11:18:50 +12:00
|
|
|
#ifndef __BATCH_H__
|
|
|
|
#define __BATCH_H__
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <gearlib.h>
|
2024-05-03 22:52:53 +12:00
|
|
|
#include <slibs.h>
|
2024-05-03 11:18:50 +12:00
|
|
|
|
|
|
|
typedef struct BatchStats {
|
|
|
|
uint32_t draw_calls;
|
|
|
|
uint32_t total_verts;
|
|
|
|
} BatchStats;
|
|
|
|
|
|
|
|
typedef struct RenderBatch {
|
2024-05-03 22:52:53 +12:00
|
|
|
uint32_t vbo, vao;
|
|
|
|
|
2024-05-03 11:18:50 +12:00
|
|
|
uint32_t shader;
|
2024-05-03 22:52:53 +12:00
|
|
|
|
2024-05-03 11:18:50 +12:00
|
|
|
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;
|
|
|
|
|
2024-05-03 22:52:53 +12:00
|
|
|
typedef sl_vec(RenderBatch*) BatchList;
|
|
|
|
|
|
|
|
extern BatchList batches;
|
|
|
|
|
2024-05-03 11:18:50 +12:00
|
|
|
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
|