diff --git a/src/shader.cpp b/src/shader.cpp index 949e81c..1cce201 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -259,9 +259,11 @@ initTransforms(MemoryArena* arena, xform_ubo->target = GL_UNIFORM_BUFFER; xform_ubo->data_type = GL_FLOAT; xform_ubo->name = arenaCopyCStr(arena, "matrices"); + xform_ubo->data_size = sizeof(*xforms); glBindBuffer(xform_ubo->target, xform_ubo->id); - glBufferData(xform_ubo->target, sizeof(*xforms), xforms, GL_DYNAMIC_DRAW); + glBufferData(xform_ubo->target, xform_ubo->data_size, xforms, + GL_DYNAMIC_DRAW); // NOTE: bindbufferbase xform_ubo->binding_idx = gl_ctx->binding_count++; @@ -330,13 +332,14 @@ loadGLMesh(const Mesh& m, attrib->buf_type = mappings[i].buf_type; u32 type_size = getGLTypeSize(attrib->data_type); assert(type_size > 0); + buf.data_size = m.num_vertices * type_size; void* mesh_buf_data = getMeshData(m, mappings[i]); assert(mesh_buf_data); initGLAttribBuffer(&buf, GL_ARRAY_BUFFER, attrib); glBindBuffer(buf.target, buf.id); glBufferData(buf.target, - m.num_vertices * type_size, + buf.data_size, mesh_buf_data, glm.usage); glVertexAttribPointer(attrib->location, attrib->num_components, @@ -347,9 +350,10 @@ loadGLMesh(const Mesh& m, glGenBuffers(1, &glm.element_buf->id); glm.element_buf->target = GL_ELEMENT_ARRAY_BUFFER; glm.element_buf->data_type = GL_UNSIGNED_SHORT; + glm.element_buf->data_size = m.num_indices * sizeof(u16); glBindBuffer(glm.element_buf->target, glm.element_buf->id); glBufferData(glm.element_buf->target, - m.num_indices * sizeof(u16), + glm.element_buf->data_size, m.indices, glm.usage); diff --git a/src/shader.h b/src/shader.h index 62758b0..ed3ff7f 100644 --- a/src/shader.h +++ b/src/shader.h @@ -94,6 +94,7 @@ struct GLBuffer GLuint id; GLenum target; GLenum data_type; + GLuint data_size; // NOTE: size of buffer in bytes // FIXME: we should initialize both of these to UINT_MAX because '0' is a // valid location and index GLuint location; // NOTE: if used as backing for vertex attribute diff --git a/src/tangerine.cpp b/src/tangerine.cpp index 5ed870f..e1c1d07 100644 --- a/src/tangerine.cpp +++ b/src/tangerine.cpp @@ -355,6 +355,7 @@ initLights(MemoryArena* arena, GLContext* gl_ctx, u32 max_lights) lights_ubo->target = GL_UNIFORM_BUFFER; lights_ubo->data_type = GL_BYTE; // NOTE: mixed types in structure + lights_ubo->data_size = lb->buf_size; lights_ubo->name = arenaCopyCStr(arena, "lights"); assert((GLint) gl_ctx->binding_count < gl_ctx->max_binding_points); lights_ubo->binding_idx = gl_ctx->binding_count++;