Skip to content

Commit

Permalink
updated buffer header and source
Browse files Browse the repository at this point in the history
  • Loading branch information
humanshell committed Feb 16, 2016
1 parent d7795d5 commit 7328e41
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
50 changes: 45 additions & 5 deletions include/glisy/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <glisy/gl.h>

/**
* Glisy Buffer struct type.
*/

typedef struct glisy_buffer glisy_buffer;
Expand All @@ -17,39 +18,78 @@ struct glisy_buffer {
};

/**
* Glisy Buffer initializer.
* This function initializes a glisy_buffer struct. The buffer's handle is set
* to 0 and the target is set to the value of the target param. If the
* target param is 0, the buffer will point to the global GL_ARRAY_BUFFER
* memory location. If the buffer param is NULL or undefined the function fails.
*
* @param buffer * - pointer to a glisy_buffer struct.
* @param target - unsigned int referencing the buffer's target.
*/

void
glisy_buffer_init(glisy_buffer *buffer, GLuint target);

/**
* Glisy Buffer bind.
* This function uses glGenBuffers() to tell OpenGL to allocate space for this
* buffer and glBindBuffer() to bind the buffer's handle to its target. If the
* buffer param is NULL or undefined the function fails.
*
* @param buffer * - pointer to a glisy_buffer struct.
*/

void
glisy_buffer_bind(glisy_buffer *buffer);

/**
*/
* Glisy Buffer unbind.
* This function uses glBindBuffer() to reset the buffer's target to 0. If the
* buffer param is NULL or undefined the function fails.
*
* @param buffer * - pointer to a glisy_buffer struct.
*/

void
glisy_buffer_unbind(glisy_buffer *buffer);

/**
*/
* Glisy Buffer dispose.
* This function uses glDeleteBuffers() to deallocate the buffer's memory and
* resets its handle to 0. If the buffer param is NULL or undefined the function
* fails.
*
* @param buffer * - pointer to a glisy_buffer struct.
*/

void
glisy_buffer_dispose(glisy_buffer *buffer);

/**
* Glisy Buffer update.
* This function uses glBufferData() to create the buffer's data in memory. If
* the buffer param is NULL or undefined the function fails.
*
* @param buffer * - pointer to a glisy_buffer struct.
* @param usage - unsigned int referencing the buffer's usage.
*/

void
glisy_buffer_source(glisy_buffer *buffer, GLsizei size, GLvoid *data);
glisy_buffer_update(glisy_buffer *buffer, GLuint usage);

/**
*/
* Glisy Buffer source.
* This function prepares the buffer's data so it is ready to be created by
* glisy_buffer_update(). If the buffer or data params are NULL or undefined the
* function fails.
*
* @param buffer * - pointer to a glisy_buffer struct.
* @param size - the size of the data stored in the buffer.
* @param data * - the actual buffer data to be rendered.
*/

void
glisy_buffer_update(glisy_buffer *buffer, GLuint usage);
glisy_buffer_source(glisy_buffer *buffer, GLsizei size, GLvoid *data);

#endif
5 changes: 5 additions & 0 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@ glisy_buffer_init(glisy_buffer *buffer, GLuint target) {

void
glisy_buffer_bind(glisy_buffer *buffer) {
if (!buffer) return;
glGenBuffers(1, &buffer->handle);
glBindBuffer(buffer->target, buffer->handle);
}

void
glisy_buffer_unbind(glisy_buffer *buffer) {
if (!buffer) return;
glBindBuffer(buffer->target, 0);
}

void
glisy_buffer_dispose(glisy_buffer *buffer) {
if (!buffer) return;
glDeleteBuffers(1, &buffer->handle);
buffer->handle = 0;
}

void
glisy_buffer_update(glisy_buffer *buffer, GLuint usage) {
if (!buffer) return;
glBufferData(buffer->target,
buffer->size,
buffer->data,
Expand All @@ -39,6 +43,7 @@ glisy_buffer_update(glisy_buffer *buffer, GLuint usage) {
void
glisy_buffer_source(glisy_buffer *buffer, GLsizei size, GLvoid *data) {
if (!buffer) return;
if (!data) return;
buffer->size = size;
memset(buffer->data, 0, BUFSIZ);
memcpy(buffer->data, data, size);
Expand Down

0 comments on commit 7328e41

Please sign in to comment.