Skip to content

Commit

Permalink
initial geometry WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Feb 11, 2016
1 parent a17cd52 commit 59dbb3a
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 122 deletions.
76 changes: 68 additions & 8 deletions include/glisy/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

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

/**
* Glisy Geometry struct type.
* Geometry structure to abstract interaction
* with the VAO (vertex array object) and OpenGL
* buffer objects (ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, etc)
*/

typedef struct glisy_geometry glisy_geometry;
Expand All @@ -15,30 +18,51 @@ struct glisy_geometry {
glisy_vao vao;

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

// length os vao attributes array
// length of vao attributes array
GLuint attrlen;

// length of vertices needed to draw faces
GLuint faceslen;

// index buffer
glisy_buffer index;

// does the geometry need an update
GLboolean dirty;

// GL element type (GL_INT, GL_UNSIGNED_SHORT, etc)
GLenum elementsType;

// predicate to indicate that the geometry should
// tell the underlying VAO to use elements for the
// ELEMENT_ARRAY_BUFFER
GLboolean useElements;

// Bound pointer a glisy_program
glisy_program *program;
};

/**
* Glisy Geometry initializer.
* @param geometry - pointer to a Glisy Geometry struct
* Initializes a pointer to a glisy_geometry structure. This function
* sets the default element type to GL_UNSIGNED_SHORT. The faces vertices
* length and attribute length is reset to 0. An existing attributes
* bound to the geometry are cleared and the internal VAO is reinitialized.
*
* @param glisy_geometry * - A pointer to a glisy_geometry struct.
*/

void
glisy_geometry_init(glisy_geometry *geometry);

/**
* Glisy Geometry update.
* @param geometry - pointer to a Glisy Geometry struct
* Updates geometry VAO. The internal VAO is disposed and all bound attributes
* to the geometry are bound to the VAO again. If the the geometry should use
* elements then the geometry index buffer is given to the internal VAO when
* it is updated.
*
* @param glisy_geometry * - A pointer to a glisy_geometry struct.
*/

void
Expand All @@ -50,6 +74,42 @@ glisy_geometry_update(glisy_geometry *geometry);
*/

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

/**
*/

void
glisy_geometry_faces(glisy_geometry *geometry,
glisy_vao_attribute *attr);

/**
*/

void
glisy_geometry_dispose(glisy_geometry *geometry);

/**
*/

void
glisy_geometry_bind(glisy_geometry *geometry, glisy_program *program);

/**
*/

void
glisy_geometry_unbind(glisy_geometry *geometry);

/**
*/

void
glisy_geometry_draw(glisy_geometry *geometry,
GLuint mode,
GLuint start,
GLuint stop);

#endif
24 changes: 1 addition & 23 deletions include/glisy/glisy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern "C" {
#include <glisy/shader.h>
#include <glisy/buffer.h>
#include <glisy/program.h>
#include <glisy/geometry.h>
#include <glisy/renderer.h>

/**
Expand All @@ -24,29 +25,6 @@ extern "C" {

#include <glisy/camera/perspective.h>

/**
* Initialize Glisy.
*/

GLboolean
glisy_init(void);

/**
* Terminate Glisy.
*/

GLboolean
glisy_terminate(void);

/**
* Renders a Glisy Scene with a Glisy Camera.
*/

void
glisy_render(const glisy_renderer renderer,
const glisy_scene scene,
const glisy_perspective_camera camera);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/glisy/math/mat2.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ struct mat2 {
#define mat2_string(a) (const char *) ({ \
char str[BUFSIZ]; \
memset(str, 0, BUFSIZ); \
sprintf(str, "mat2(%f, %f, %f, %f)", \
sprintf(str, "mat2(%f, %f, \n%f, %f)", \
a.m11, a.m12, a.m21, a.m22); \
(strdup(str)); \
})
Expand Down
22 changes: 12 additions & 10 deletions include/glisy/math/mat3.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,18 @@ struct mat3 {
* Returns a string representation of mat3 a.
*/

#define mat3_string(a) (const char *) ({ \
char str[BUFSIZ]; \
mat3 b; \
mat3_copy(b, a); \
memset(str, 0, BUFSIZ); \
sprintf(str, "mat3(%f, %f, %f, %f, %f, %f, %f, %f, %f)", \
b.m11, b.m12, b.m13, \
b.m21, b.m22, b.m23, \
b.m31, b.m32, b.m33); \
(strdup(str)); \
#define mat3_string(a) (const char *) ({ \
char str[BUFSIZ]; \
mat3 b; \
mat3_copy(b, a); \
memset(str, 0, BUFSIZ); \
sprintf(str, "mat3(%f, %f, %f,\n" \
" %f, %f, %f,\n" \
" %f, %f, %f)", \
b.m11, b.m12, b.m13, \
b.m21, b.m22, b.m23, \
b.m31, b.m32, b.m33); \
(strdup(str)); \
})

#endif
9 changes: 5 additions & 4 deletions include/glisy/vao.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
typedef struct glisy_vao_attribute glisy_vao_attribute;
struct glisy_vao_attribute {
GLuint location;
GLchar *name;
char *name;

struct {
GLfloat data[BUFSIZ];
Expand All @@ -35,6 +35,7 @@ struct glisy_vao {
GLuint handle;
GLuint length;
glisy_vao_attribute attributes[GLISY_MAX_VAO_ATTRIBS];
GLboolean useElements;
};

/**
Expand Down Expand Up @@ -65,10 +66,10 @@ glisy_vao_dispose(glisy_vao *vao);
*/

void
glisy_vao_update(glisy_vao *vao);
glisy_vao_update(glisy_vao *vao, glisy_buffer *elements);

GLuint
glisy_vao_push(glisy_vao *vao, glisy_vao_attribute attr);
glisy_vao_push(glisy_vao *vao, glisy_vao_attribute *attr);

GLuint
glisy_vao_pop(glisy_vao *vao);
Expand All @@ -77,7 +78,7 @@ GLuint
glisy_vao_splice(glisy_vao *vao, GLint start, GLuint count);

GLuint
glisy_vao_set(glisy_vao *vao, GLuint location, glisy_vao_attribute attr);
glisy_vao_set(glisy_vao *vao, GLuint location, glisy_vao_attribute *attr);

GLuint
glisy_vao_remove(glisy_vao *vao, GLuint location);
Expand Down
Loading

0 comments on commit 59dbb3a

Please sign in to comment.