Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Apr 4, 2016
1 parent 33e1231 commit 00d9988
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@

# Debug files
*.dSYM/
deps/
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## Project settings
PROJECT_NAME ?= GlisyVAO
PREFIX ?= /usr/local

## Project command dependencies
MKDIR ?= mkdir -p
RM ?= rm -f
CP ?= cp -f

## Source files
SRC += $(wildcard src/*.c)

## Source objects
OBJS := $(SRC:.c=.o)

## Compiler flags
CFLAGS += -Ideps
CFLAGS += -Iinclude
CFLAGS += -Wall
CFLAGS += -O2

## Target static library
TARGET_STATIC := lib$(PROJECT_NAME).a

## Builds everything
.PHONY: all
all: $(TARGET_STATIC)

## Builds static library
$(TARGET_STATIC): $(OBJS)
$(AR) crus $@ $^

## Compiles object files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@

## Cleans project directory
.PHONY: clean
clean: test/clean
clean:
$(RM) $(OBJS)
$(RM) $(TARGET_STATIC)

## Compiles and runs all test
.PHONY: test
test: $(TARGET_STATIC)
if test -d; then $(MAKE) -C $@; fi

## Installs library into system
.PHONY: install
install: $(TARGET_STATIC)
$(CP) -r include/* $(PREFIX)/include/
$(CP) $(TARGET_STATIC) $(PREFIX)/lib

## Uninstalls library from system
.PHONY: uninstall
uninstall:
$(RM) -r $(PREFIX)/include/$(PROJECT_NAME)
$(RM) $(PREFIX)/lib/$(TARGET_STATIC)

## Cleans test directory
.PHONY: test/clean
test/clean:
if test -d test; then $(MAKE) clean -C test; fi
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# vao
GlisyVAO
========

## Installation

```sh
$ clib install glisy/vao --save
```

## Usage

```c
#include <glisy/math.h>
#include <glisy/vao.h>

int
main (void) {
const vec3 vertices[] = {
vec3(-0.5, -0.5, +0.5),
vec3(+0.5, -0.5, +0.5),
vec3(-0.5, +0.5, +0.5),
vec3(+0.5, +0.5, +0.5),

vec3(-0.5, -0.5, -0.5),
vec3(+0.5, -0.5, -0.5),
vec3(-0.5, +0.5, -0.5),
vec3(+0.5, +0.5, -0.5),
};

GlisyVAOAttribute vPosition;
memset(&vPosition, 0, sizeof(vPosition));
vPosition.buffer.data = (void *) vertices;
vPosition.buffer.type = GL_FLOAT;
vPosition.buffer.size = size;
vPosition.buffer.usage = GL_STATIC_DRAW;
vPosition.buffer.dimension = 3;

GlisyVAO vao;
glisyVAOInit(&vao);
glisyVAOPush(&vao, &vPosition);
glisyVAOBind(&vao);
glisyVAOUpdate(&vao, 0);
return 0;
}
```
## License
MIT
180 changes: 180 additions & 0 deletions include/glisy/vao.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#ifndef GLISY_VAO_H
#define GLISY_VAO_H

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

#ifdef __cplusplus
extern "C" {
#endif

#ifndef GLISY_MAX_VAO_ATTRIBS
#define GLISY_MAX_VAO_ATTRIBS 0xff
#endif

/**
* Glisy VAO Attribute struct type.
*/

typedef struct GlisyVAOAttribute GlisyVAOAttribute;
struct GlisyVAOAttribute {
GLuint location;
const char *name;

struct {
GLvoid *data;
GLuint type;
GLuint size;
GLuint usage;
GLuint stride;
GLuint offset;
GLuint dimension;
GLboolean normalized;
} buffer;
};

/**
* Glisy VAO struct type.
*/

typedef struct GlisyVAO GlisyVAO;
struct GlisyVAO {
GLuint handle;
GLuint length;
GlisyVAOAttribute attributes[GLISY_MAX_VAO_ATTRIBS];
GLboolean useElements;
};

/**
* This function initializes a GlisyVAO struct with default values. Memory is
* allocated and initialized, and glGenVertexArrays() is called to generate a
* value for the handle member. The length member defaults to 0 and useElements
* defaults to false. If the vao param is NULL or undefined the function returns.
*
* @param vao - pointer to a GlisyVAO struct.
*/

void
glisyVAOInit(GlisyVAO *vao);

/**
* This function calls glBindVertexArray() to bind the verticies stored in the
* memory location of the vao handle member. If the vao param is NULL or
* undefined the function returns.
*
* @param vao - pointer to a GlisyVAO struct.
*/

void
glisyVAOBind(GlisyVAO *vao);

/**
* This function calls glBindVertexArray(0) to clear any bound verticies. If the
* vao param is NULL or undefined the function returns.
*
* @param vao - pointer to a GlisyVAO struct.
*/

void
glisyVAOUnbind(GlisyVAO *vao);

/**
* This function calls glDeleteVertexArrays() to destroy any verticies stored in
* the memory location of the vao handle member. If the vao param is NULL or
* undefined the function returns.
*
* @param vao - pointer to a GlisyVAO struct.
*/

void
glisyVAODispose(GlisyVAO *vao);

/**
* This function resets and reinitializes the vao and all of its attributes. The
* elements param is optional. If a properly initialized GlisyBuffer is passed
* in, it will be bound and the vao useElements member will be set to true. If
* elements are not being used, pass NULL to disable. If the vao param is NULL
* or undefined the function will return.
*
* @param vao - pointer to a GlisyVAO struct.
* @param elements - pointer to a GlisyBuffer struct.
*/

void
glisyVAOUpdate(GlisyVAO *vao, GlisyBuffer *elements);

/**
* This function pushes attr param onto the vao's internal attributes member
* list of attributes. If the vao or attr params are NULL or undefined the
* function returns false, otherwise it returns the new length of the vao.
*
* @param vao - pointer to a GlisyVAO struct.
* @param attr - pointer to a GlisyVAOAttribute struct.
*/

GLuint
glisyVAOPush(GlisyVAO *vao, GlisyVAOAttribute *attr);

/**
* @TODO(jwerle): implement glisyVAOPop
*
* @param vao - pointer to a GlisyVAO struct.
*/

GLuint
glisyVAOPop(GlisyVAO *vao);

/**
* @TODO(jwerle): implement glisyVAOSplice
*
* @param vao - pointer to a GlisyVAO struct.
* @param start - index at which to start slicing.
* @param count - length of the slice.
*/

GLuint
glisyVAOSplice(GlisyVAO *vao,
GLint start,
GLuint count);

/**
* This function places a vao attribute into vao at the index specified by
* location. If the location exceeds GLISY_MAX_VAO_ATTRIBS or if the vao's
* length is already at that maximum, nothing will be done. If the vao or attr
* params are NULL or undefined the function returns false, otherwise it returns
* the new vao length.
*
* @param vao - pointer to a GlisyVAO struct.
* @param location - index at which to set the new vao attribute.
* @param attr - pointer to a GlisyVAOAttribute struct.
*/

GLuint
glisyVAOSet(GlisyVAO *vao,
GLuint location,
GlisyVAOAttribute *attr);

/**
* @TODO(jwerle): implement glisyVAORemove
*
* @param vao - pointer to a GlisyVAO struct.
* @param location - index of the attr to be removed.
*/

GLuint
glisyVAORemove(GlisyVAO *vao, GLuint location);

/**
* This function initializes and binds a GlisyVAOAttribute struct. If the
* attribute param is NULL or undefined the function returns.
*
* @param attribute - pointer to a GlisyVAOAttribute struct.
*/

void
glisyVAOAttributeBind(GlisyVAOAttribute *attribute);

#ifdef __cplusplus
}
#endif
#endif
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "glisy",
"version": "0.0.1",
"repo": "glisy/vao",
"description": "GlisyVAO",
"keywords": [
"glisy",
"vao",
"vertex",
"array"
],
"src": [
"include/glisy/vao.h",
"src/vao.c"
],
"dependencies": {
"glisy/buffer": "master",
"glisy/gl": "master"
}
}
Loading

0 comments on commit 00d9988

Please sign in to comment.