Skip to content

Instantly share code, notes, and snippets.

@pervognsen
pervognsen / array.inl.h
Last active March 24, 2024 06:15
somewhat palatable templates in c
struct A {
int size;
int capacity;
T *data;
};
typedef struct A A;
void A_(Create)(A *array, int capacity);
void A_(Destroy)(A *array);
enum { BMAX = 32, BCUT = BMAX / 2, BHEIGHT = 6 };
typedef uint8_t BIndex;
struct BNode {
BIndex length;
Key keys[BMAX];
union {
BNode *children[BMAX];
Value values[BMAX];
void DrawMesh(Gob_Mesh *mesh) {
glVertexPointer(3, GL_FLOAT, mesh->positions.stride, GOB_BUFFER(mesh->positions.buffer)->data + mesh->positions.start);
char *index_buffer = GOB_BUFFER(mesh->indices.buffer)->data;
uint8_t index_size = mesh->indices.index_size;
GLenum index_type = (index_size == 2) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
for (size_t i = 0; i < mesh->sections_count; i++) {
glDrawElements(GL_TRIANGLES, mesh->sections[i].index_count, index_type, index_buffer + index_size * mesh->sections[i].index_start);
}
}