summaryrefslogtreecommitdiff
path: root/prge_mesh.c
diff options
context:
space:
mode:
Diffstat (limited to 'prge_mesh.c')
-rw-r--r--prge_mesh.c65
1 files changed, 0 insertions, 65 deletions
diff --git a/prge_mesh.c b/prge_mesh.c
deleted file mode 100644
index dc2c2da..0000000
--- a/prge_mesh.c
+++ /dev/null
@@ -1,65 +0,0 @@
-Vertex vertex(V3 pos)
-{
- Vertex v = { pos };
- return v;
-}
-
-void mesh_init_buffers(Mesh *mesh)
-{
- Assert(mesh->verts);
- Assert(mesh->nverts > 0);
-
- glGenVertexArrays(1, &mesh->vao);
- glBindVertexArray(mesh->vao);
-
- glGenBuffers(1, &mesh->vbo);
- glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo);
- glBufferData(GL_ARRAY_BUFFER, mesh->nverts*sizeof(Vertex), mesh->verts, GL_STATIC_DRAW);
-
- if (mesh->indices && (mesh->nindices > 0)) {
- glGenBuffers(1, &mesh->ebo);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh->ebo);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, mesh->nindices*sizeof(U32), mesh->indices, GL_STATIC_DRAW);
- }
-
- glEnableVertexAttribArray(PRGE_SHADER_POS_LOC);
- glVertexAttribPointer(PRGE_SHADER_POS_LOC, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
- glBindVertexArray(0);
-}
-
-Mesh *mesh(Arena *arena, Vertex *verts, U32 nverts, U32 *indices, U32 nindices)
-{
- Mesh *mesh = arena_push(arena, sizeof(Mesh));
- mesh->verts = verts;
- mesh->nverts = nverts;
- mesh->indices = indices;
- mesh->nindices = nindices;
- mesh_init_buffers(mesh);
- return mesh;
-}
-
-void mesh_clear(Mesh *mesh)
-{
- glBindVertexArray(mesh->vao);
- glDisableVertexAttribArray(PRGE_SHADER_POS_LOC);
-
- glBindVertexArray(0);
- glDeleteVertexArrays(1, &mesh->vao);
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glDeleteBuffers(1, &mesh->vbo);
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- glDeleteBuffers(1, &mesh->ebo);
-}
-
-void mesh_draw(Mesh mesh)
-{
- Assert(mesh.vao);
- glBindVertexArray(mesh.vao);
- if (mesh.ebo)
- glDrawElements(GL_TRIANGLES, mesh.nindices, GL_UNSIGNED_INT, 0);
- else
- glDrawArrays(GL_TRIANGLES, 0, mesh.nverts);
- glBindVertexArray(0);
-}