Techneck/code/source-c/world/chunk.c

50 lines
1.3 KiB
C

#include <world/chunk.h>
#include <glad/glad.h>
#include <stddef.h>
void tc_upload_chunk(tc_chunk_s *chunk)
{
// If the chunk has no mesh, it's probably only air.
if(chunk->num_vertices == 0)
{
return;
}
if(chunk->vao != 0) glDeleteVertexArrays(1, &chunk->vao);
if(chunk->vbo != 0) glDeleteBuffers(1, &chunk->vbo);
glGenVertexArrays(1, &chunk->vao);
glBindVertexArray(chunk->vao);
glGenBuffers(1, &chunk->vbo);
glBindBuffer(GL_ARRAY_BUFFER, chunk->vbo);
glBufferData(GL_ARRAY_BUFFER, chunk->num_vertices * 5 * sizeof(float), NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0,
chunk->num_vertices * 3 * sizeof(float),
chunk->vertex_positions
);
glBufferSubData(GL_ARRAY_BUFFER,
chunk->num_vertices * 3 * sizeof(float),
chunk->num_vertices * 2 * sizeof(float),
chunk->vertex_uvs
);
glBindVertexArray(0);
}
void tc_draw_chunkloader_zone(tc_chunkloader_s *loader)
{
tc_chunklist_s *list = &loader->chunklist;
for(tc_chunklist_entry_s *current = list->first; current != NULL; current = current->next)
{
if(current->entity == NULL)
{
return;
}
tc_send_pointer_to_entity(current->entity, "draw", 0);
}
}