Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Feb 12, 2016
1 parent c85a138 commit d6211c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
9 changes: 8 additions & 1 deletion include/glisy/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ struct glisy_geometry {
// length of vertices needed to draw faces
GLuint faceslen;

// length of indices
GLuint indiceslen;

// index buffer
glisy_buffer index;

Expand All @@ -35,6 +38,9 @@ struct glisy_geometry {
// GL element type (GL_INT, GL_UNSIGNED_SHORT, etc)
GLenum elementsType;

// element array buffer indices
GLushort indices[BUFSIZ];

// predicate to indicate that the geometry should
// tell the underlying VAO to use elements for the
// ELEMENT_ARRAY_BUFFER
Expand Down Expand Up @@ -83,7 +89,8 @@ glisy_geometry_attr(glisy_geometry *geometry,

void
glisy_geometry_faces(glisy_geometry *geometry,
glisy_vao_attribute *attr);
GLuint count,
GLushort *indices);

/**
*/
Expand Down
21 changes: 13 additions & 8 deletions src/geometry.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ glisy_geometry_init(glisy_geometry *geometry) {

void
glisy_geometry_update(glisy_geometry *geometry) {
// index buffer object (GL_ELEMENT_ARRAY_BUFFER)
GLuint ibo;
if (geometry == NULL) return;
if (!geometry->dirty) return;

Expand Down Expand Up @@ -82,6 +84,12 @@ glisy_geometry_update(glisy_geometry *geometry) {
// update VAO
if (geometry->useElements) {
glisy_vao_update(&geometry->vao, &geometry->index);
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
geometry->indiceslen * sizeof(GLushort),
geometry->indices,
GL_STATIC_DRAW);
} else {
glisy_vao_update(&geometry->vao, 0);
}
Expand All @@ -103,14 +111,11 @@ glisy_geometry_attr(glisy_geometry *geometry,

void
glisy_geometry_faces(glisy_geometry *geometry,
glisy_vao_attribute *attr) {
GLuint count,
GLushort *indices) {

glisy_buffer_dispose(&geometry->index);
glisy_buffer_init(&geometry->index, GL_ELEMENT_ARRAY_BUFFER);
glisy_buffer_source(&geometry->index,
attr->buffer.size,
attr->buffer.data);
glisy_buffer_update(&geometry->index, GL_DYNAMIC_DRAW);
geometry->indiceslen = count;
memcpy(geometry->indices, indices, sizeof(GLushort) * count);
geometry->useElements = GL_TRUE;
}

Expand Down Expand Up @@ -179,7 +184,7 @@ glisy_geometry_draw(glisy_geometry *geometry,
glDrawElements(mode,
stop - start,
geometry->elementsType,
&offset);
0);

} else {
glDrawArrays(mode, start, stop - start);
Expand Down

0 comments on commit d6211c5

Please sign in to comment.