diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-12-11 10:49:50 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-12-11 10:51:40 -0500 |
| commit | fa8fa6784559ed0fc8d780e36880273f77e272c4 (patch) | |
| tree | 7456a4e9148d47e409ba837bafdc6238b6c757db /src/gl.h | |
| parent | add ubos (diff) | |
| download | voxel-fa8fa6784559ed0fc8d780e36880273f77e272c4.tar.gz voxel-fa8fa6784559ed0fc8d780e36880273f77e272c4.tar.bz2 voxel-fa8fa6784559ed0fc8d780e36880273f77e272c4.zip | |
i did a lot
Diffstat (limited to 'src/gl.h')
| -rw-r--r-- | src/gl.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/gl.h b/src/gl.h new file mode 100644 index 0000000..58809c9 --- /dev/null +++ b/src/gl.h @@ -0,0 +1,73 @@ +#pragma once + +#include <GL/gl.h> +#include <cglm/cglm.h> + +#include "list.h" + +#define GL_OK 0 +#define GL_ERROR 1 +#define GL_RESULT int + +#define MAX_VBOS 4 + +typedef struct { + u32 vao; + u32 vbos[MAX_VBOS]; + i32 vbos_count; + i32 vertex_count; +} Mesh; + +void mesh_init(Mesh *mesh, u32 vertex_count); +void mesh_store_float(Mesh *mesh, float *data, u32 count, u32 dimensions); +void mesh_store_i32(Mesh *mesh, i32 *data, u32 count, u32 dimensions); +void mesh_store_u8(Mesh *mesh, u8 *data, u32 count, u32 dimensions); +void mesh_store_u32(Mesh *mesh, u32 *data, u32 count, u32 dimensions); +void mesh_finish(void); +void mesh_bind(Mesh *mesh); +void mesh_unbind(Mesh *mesh); +void mesh_draw(Mesh *mesh); +void mesh_draw_instanced(Mesh *mesh, u32 count); +void mesh_free(Mesh *mesh); + +typedef struct { + u32 id; + u32 len; +} Uniform; + +void uniform_init(Uniform *uniform, u32 len); +void uniform_store(Uniform *uniform, u32 offset, u32 len, void *data); +void uniform_bind(Uniform *uniform, u32 binding); +void uniform_unbind(u32 binding); +void uniform_free(Uniform *uniform); + +typedef struct { + u32 program_id; + u32 vertex_id; + u32 fragment_id; + /* vertex attributes */ + List attribute_names; + List attribute_locations; + /* uniforms */ + List uniform_names; + List uniform_locations; + /* uniform blocks */ + List uniform_block_names; + List uniform_block_indicies; +} Shader; + +GL_RESULT shader_init(Shader *shader, const char *vertexFile, const char *fragmentFile); +void shader_bind(Shader *shader); +void shader_unbind(void); +void shader_free(Shader *shader); + +i32 shader_attribute_location(Shader *shader, const char *name); +i32 shader_uniform_location(Shader *shader, const char *name); +i32 shader_uniform_block_index(Shader *shader, const char *name); + +void shader_load_float(Shader *shader, const char *name, float value); +void shader_load_int(Shader *shader, const char *name, int value); +void shader_load_vec3(Shader *shader, const char *name, vec3 value); +void shader_load_ivec3(Shader *shader, const char *name, ivec3 value); +void shader_load_mat4(Shader *shader, const char *name, mat4 value); +void shader_load_ubo(Shader *shader, const char *name, u32 binding); |