Browse Source

add data size parameter to GLBuffer

main
cinnaboot 4 years ago
parent
commit
2919e2bcb6
  1. 10
      src/shader.cpp
  2. 1
      src/shader.h
  3. 1
      src/tangerine.cpp

10
src/shader.cpp

@ -259,9 +259,11 @@ initTransforms(MemoryArena* arena,
xform_ubo->target = GL_UNIFORM_BUFFER; xform_ubo->target = GL_UNIFORM_BUFFER;
xform_ubo->data_type = GL_FLOAT; xform_ubo->data_type = GL_FLOAT;
xform_ubo->name = arenaCopyCStr(arena, "matrices"); xform_ubo->name = arenaCopyCStr(arena, "matrices");
xform_ubo->data_size = sizeof(*xforms);
glBindBuffer(xform_ubo->target, xform_ubo->id); 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 // NOTE: bindbufferbase
xform_ubo->binding_idx = gl_ctx->binding_count++; xform_ubo->binding_idx = gl_ctx->binding_count++;
@ -330,13 +332,14 @@ loadGLMesh(const Mesh& m,
attrib->buf_type = mappings[i].buf_type; attrib->buf_type = mappings[i].buf_type;
u32 type_size = getGLTypeSize(attrib->data_type); u32 type_size = getGLTypeSize(attrib->data_type);
assert(type_size > 0); assert(type_size > 0);
buf.data_size = m.num_vertices * type_size;
void* mesh_buf_data = getMeshData(m, mappings[i]); void* mesh_buf_data = getMeshData(m, mappings[i]);
assert(mesh_buf_data); assert(mesh_buf_data);
initGLAttribBuffer(&buf, GL_ARRAY_BUFFER, attrib); initGLAttribBuffer(&buf, GL_ARRAY_BUFFER, attrib);
glBindBuffer(buf.target, buf.id); glBindBuffer(buf.target, buf.id);
glBufferData(buf.target, glBufferData(buf.target,
m.num_vertices * type_size, buf.data_size,
mesh_buf_data, mesh_buf_data,
glm.usage); glm.usage);
glVertexAttribPointer(attrib->location, attrib->num_components, glVertexAttribPointer(attrib->location, attrib->num_components,
@ -347,9 +350,10 @@ loadGLMesh(const Mesh& m,
glGenBuffers(1, &glm.element_buf->id); glGenBuffers(1, &glm.element_buf->id);
glm.element_buf->target = GL_ELEMENT_ARRAY_BUFFER; glm.element_buf->target = GL_ELEMENT_ARRAY_BUFFER;
glm.element_buf->data_type = GL_UNSIGNED_SHORT; 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); glBindBuffer(glm.element_buf->target, glm.element_buf->id);
glBufferData(glm.element_buf->target, glBufferData(glm.element_buf->target,
m.num_indices * sizeof(u16), glm.element_buf->data_size,
m.indices, m.indices,
glm.usage); glm.usage);

1
src/shader.h

@ -94,6 +94,7 @@ struct GLBuffer
GLuint id; GLuint id;
GLenum target; GLenum target;
GLenum data_type; 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 // FIXME: we should initialize both of these to UINT_MAX because '0' is a
// valid location and index // valid location and index
GLuint location; // NOTE: if used as backing for vertex attribute GLuint location; // NOTE: if used as backing for vertex attribute

1
src/tangerine.cpp

@ -355,6 +355,7 @@ initLights(MemoryArena* arena, GLContext* gl_ctx, u32 max_lights)
lights_ubo->target = GL_UNIFORM_BUFFER; lights_ubo->target = GL_UNIFORM_BUFFER;
lights_ubo->data_type = GL_BYTE; // NOTE: mixed types in structure lights_ubo->data_type = GL_BYTE; // NOTE: mixed types in structure
lights_ubo->data_size = lb->buf_size;
lights_ubo->name = arenaCopyCStr(arena, "lights"); lights_ubo->name = arenaCopyCStr(arena, "lights");
assert((GLint) gl_ctx->binding_count < gl_ctx->max_binding_points); assert((GLint) gl_ctx->binding_count < gl_ctx->max_binding_points);
lights_ubo->binding_idx = gl_ctx->binding_count++; lights_ubo->binding_idx = gl_ctx->binding_count++;

Loading…
Cancel
Save