Skip to content

Commit

Permalink
started geometry type and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
humanshell committed Feb 10, 2016
1 parent 2fb2caf commit a17cd52
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
55 changes: 55 additions & 0 deletions include/glisy/geometry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef GLISY_GEOMETRY_H
#define GLISY_GEOMETRY_H

#include <glisy/vao.h>
#include <glisy/buffer.h>

/**
* Glisy Geometry struct type.
*/

typedef struct glisy_geometry glisy_geometry;
struct glisy_geometry {

// vertext array object
glisy_vao vao;

// array of vao attributes
glisy_vao_attribute *attributes[GLISY_MAX_VAO_ATTRIBS];

// length os vao attributes array
GLuint attrlen;

// index buffer
glisy_buffer index;

// does the geometry need an update
GLboolean dirty;

};

/**
* Glisy Geometry initializer.
* @param geometry - pointer to a Glisy Geometry struct
*/

void
glisy_geometry_init(glisy_geometry *geometry);

/**
* Glisy Geometry update.
* @param geometry - pointer to a Glisy Geometry struct
*/

void
glisy_geometry_update(glisy_geometry *geometry);

/**
* Glisy Geometry attributes.
* @param geometry - pointer to a Glisy Geometry struct
*/

void
glisy_geometry_attr(glisy_geometry *geometry, GLchar *name, glisy_vao_attribute *attr);

#endif
56 changes: 56 additions & 0 deletions src/geometry.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <strings.h>
#include <glisy/geometry.h>

// push a vao attribute onto the geometry attributes array
static void
push_attr(glisy_geometry *geometry, glisy_vao_attribute *attribute) {
if (geometry == NULL) return;
if (attribute == NULL) return;

if (geometry->attrlen < GLISY_MAX_VAO_ATTRIBS) {
geometry->attributes[geometry->attrlen++] = attribute;
}
}

/**
* Glisy Geometry initializer.
*/

void
glisy_geometry_init(glisy_geometry *geometry) {
if (geometry == NULL) return;

geometry->attrlen = 0;
geometry->dirty = GL_FALSE;

memset(&geometry->attributes, 0, sizeof(glisy_vao_attribute *) * GLISY_MAX_VAO_ATTRIBS);
glisy_vao_init(&geometry->vao);
}

/**
* Glisy Geometry update.
*/

void
glisy_geometry_update(glisy_geometry *geometry) {
if (geometry == NULL) return;
if (!geometry->dirty) return;

glisy_vao_dispose(&geometry->vao);
glisy_vao_init(&geometry->vao);
//@TODO(jwerle): complete me
}

/**
* Glisy Geometry attributes.
*/

void
glisy_geometry_attr(glisy_geometry *geometry, GLchar *name, glisy_vao_attribute *attr) {
if (geometry == NULL) return;
if (name == NULL) return;

geometry->dirty = GL_TRUE;
attr->name = name;
push_attr(geometry, attr);
}

0 comments on commit a17cd52

Please sign in to comment.