summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gl/data.c47
-rw-r--r--src/gl/drawing.c39
-rw-r--r--src/gl/gl.c44
-rw-r--r--src/gl/shader.c45
-rw-r--r--src/gl/texture.c37
5 files changed, 104 insertions, 108 deletions
diff --git a/src/gl/data.c b/src/gl/data.c
index 777689a..a9d0324 100644
--- a/src/gl/data.c
+++ b/src/gl/data.c
@@ -4,6 +4,7 @@
#include <GLFW/glfw3.h>
#include <lua.h>
#include <honeysuckle.h>
+#include "util/util.h"
#include "gl.h"
int gl_create_buffer(lua_State *L);
@@ -18,32 +19,30 @@ int gl_vertex_array_enable_attrib(lua_State *L);
void setup_data(lua_State *L, int gl_index)
{
- int buffer_binding_targets = hs_create_table(L,
- hs_str_int("arrayBuffer", GL_ARRAY_BUFFER),
- hs_str_int("elementArrayBuffer", GL_ELEMENT_ARRAY_BUFFER),
- );
-
- int buffer_usage_patterns = hs_create_table(L,
- hs_str_int("streamDraw", GL_STREAM_DRAW),
- hs_str_int("staticDraw", GL_STATIC_DRAW),
- hs_str_int("dynamicDraw", GL_DYNAMIC_DRAW),
- );
-
- hs_create_table(L,
- hs_str_cfunc("createBuffer", gl_create_buffer),
- hs_str_cfunc("bindBuffer", gl_bind_buffer),
- hs_str_cfunc("bufferData", gl_buffer_data),
-
- hs_str_cfunc("createVertexArray", gl_vertex_array_create),
- hs_str_cfunc("bindVertexArray", gl_vertex_array_bind),
- hs_str_cfunc("vertexAttribPointer", gl_vertex_attrib_pointer),
- hs_str_cfunc("vertexArrayEnableAttrib", gl_vertex_array_enable_attrib),
-
- hs_str_tbl("bufferTarget", buffer_binding_targets),
- hs_str_tbl("bufferUsage", buffer_usage_patterns),
+ int tbl = hs_create_table(L,
+ /* functions */
+ hs_str_cfunc("GenBuffers", gl_create_buffer),
+ hs_str_cfunc("BindBuffer", gl_bind_buffer),
+ hs_str_cfunc("BufferData", gl_buffer_data),
+
+ hs_str_cfunc("GenVertexArrays", gl_vertex_array_create),
+ hs_str_cfunc("BindVertexArray", gl_vertex_array_bind),
+ hs_str_cfunc("VertexAttribPointer", gl_vertex_attrib_pointer),
+ hs_str_cfunc("EnableVertexAttribArray", gl_vertex_array_enable_attrib),
+
+ /******** enums ********/
+ /* buffer bind targets */
+ hs_str_int("ARRAY_BUFFER", GL_ARRAY_BUFFER),
+ hs_str_int("ELEMENT_ARRAY_BUFFER", GL_ELEMENT_ARRAY_BUFFER),
+
+ /* buffer usage patters */
+ hs_str_int("STREAM_DRAW", GL_STREAM_DRAW),
+ hs_str_int("STATIC_DRAW", GL_STATIC_DRAW),
+ hs_str_int("DYNAMIC_DRAW", GL_DYNAMIC_DRAW),
);
- lua_setfield(L, gl_index, "data");
+ append_table(L, gl_index, tbl);
+ lua_pop(L, 1);
}
diff --git a/src/gl/drawing.c b/src/gl/drawing.c
index ca914e0..e6b1e13 100644
--- a/src/gl/drawing.c
+++ b/src/gl/drawing.c
@@ -2,6 +2,7 @@
#include <GLFW/glfw3.h>
#include <lua.h>
#include <honeysuckle.h>
+#include "util/util.h"
int gl_set_viewport(lua_State *L);
int gl_draw_arrays(lua_State *L);
@@ -11,30 +12,28 @@ int gl_clear(lua_State *L);
void setup_drawing(lua_State *L, int gl_index)
{
- int primitive_types = hs_create_table(L,
- hs_str_int("points", GL_POINTS),
- hs_str_int("lines", GL_LINES),
- hs_str_int("triangles", GL_TRIANGLES),
- );
-
- int buffer_masks = hs_create_table(L,
- hs_str_int("colorBuffer", GL_COLOR_BUFFER_BIT),
- hs_str_int("depthBuffer", GL_DEPTH_BUFFER_BIT),
- hs_str_int("stencilBuffer", GL_STENCIL_BUFFER_BIT),
- );
+ int tbl = hs_create_table(L,
+ /* functions */
+ hs_str_cfunc("DrawArrays", gl_draw_arrays),
+ hs_str_cfunc("DrawElements", gl_draw_elements),
+ hs_str_cfunc("ClearColor", gl_set_clear_color),
+ hs_str_cfunc("Clear", gl_clear),
+ hs_str_cfunc("Viewport", gl_set_viewport),
- hs_create_table(L,
- hs_str_cfunc("drawArrays", gl_draw_arrays),
- hs_str_cfunc("drawElements", gl_draw_elements),
- hs_str_cfunc("setClearColor", gl_set_clear_color),
- hs_str_cfunc("clear", gl_clear),
- hs_str_cfunc("setViewport", gl_set_viewport),
+ /******** enums ********/
+ /* rendering primitives */
+ hs_str_int("POINTS", GL_POINTS),
+ hs_str_int("LINES", GL_LINES),
+ hs_str_int("TRIANGLES", GL_TRIANGLES),
- hs_str_tbl("primitiveType", primitive_types),
- hs_str_tbl("bufferMask", buffer_masks),
+ /* clear bitmasks */
+ hs_str_int("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT),
+ hs_str_int("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT),
+ hs_str_int("STENCIL_BUFFER_BIT", GL_STENCIL_BUFFER_BIT),
);
- lua_setfield(L, gl_index, "draw");
+ append_table(L, gl_index, tbl);
+ lua_pop(L, 1);
}
int gl_set_clear_color(lua_State *L)
diff --git a/src/gl/gl.c b/src/gl/gl.c
index c4502dc..4639d48 100644
--- a/src/gl/gl.c
+++ b/src/gl/gl.c
@@ -20,36 +20,34 @@ int gl_get_error(lua_State *L);
void setup_gl(lua_State *L, int honey_index)
{
- int data_types = hs_create_table(L,
- hs_str_int("uchar", GL_UNSIGNED_BYTE),
- hs_str_int("uint", GL_UNSIGNED_INT),
- hs_str_int("int", GL_INT),
- hs_str_int("float", GL_FLOAT),
- );
-
- int error_types = hs_create_table(L,
- hs_str_int("noError", GL_NO_ERROR),
- hs_str_int("invalidEnum", GL_INVALID_ENUM),
- hs_str_int("invalidValue", GL_INVALID_VALUE),
- hs_str_int("invalidOperation", GL_INVALID_OPERATION),
- hs_str_int("invalidFramebufferOperation", GL_INVALID_FRAMEBUFFER_OPERATION),
- hs_str_int("outOfMemory", GL_OUT_OF_MEMORY),
- );
-
int gl_index = hs_create_table(L,
- hs_str_cfunc("init", gl_init),
- hs_str_cfunc("initGlad", glad_init),
- hs_str_cfunc("terminate", gl_terminate),
- hs_str_cfunc("getError", gl_get_error),
-
- hs_str_tbl("dataType", data_types),
- hs_str_tbl("errorType", error_types),
+ /* functions */
+ hs_str_cfunc("Init", gl_init),
+ hs_str_cfunc("InitGlad", glad_init),
+ hs_str_cfunc("Terminate", gl_terminate),
+ hs_str_cfunc("GetError", gl_get_error),
+
+ /******** enums ********/
+ /* data types */
+ hs_str_int("UNSIGNED_BYTE", GL_UNSIGNED_BYTE),
+ hs_str_int("UNSIGNED_INT", GL_UNSIGNED_INT),
+ hs_str_int("INT", GL_INT),
+ hs_str_int("FLOAT", GL_FLOAT),
+
+ /* error types */
+ hs_str_int("NO_ERROR", GL_NO_ERROR),
+ hs_str_int("INVALID_ENUM", GL_INVALID_ENUM),
+ hs_str_int("INVALID_VALUE", GL_INVALID_VALUE),
+ hs_str_int("INVALID_OPERATION", GL_INVALID_OPERATION),
+ hs_str_int("INVALID_FRAMEBUFFER_OPERATION", GL_INVALID_FRAMEBUFFER_OPERATION),
+ hs_str_int("OUT_OF_MEMORY", GL_OUT_OF_MEMORY),
);
setup_shader(L, gl_index);
setup_drawing(L, gl_index);
setup_data(L, gl_index);
setup_texture(L, gl_index);
+
lua_setfield(L, honey_index, "gl");
}
diff --git a/src/gl/shader.c b/src/gl/shader.c
index c3b409c..b4d03e6 100644
--- a/src/gl/shader.c
+++ b/src/gl/shader.c
@@ -2,6 +2,7 @@
#include <GLFW/glfw3.h>
#include <lua.h>
#include <honeysuckle.h>
+#include "util/util.h"
int gl_create_shader(lua_State *L);
int gl_shader_set_source(lua_State *L);
@@ -20,30 +21,30 @@ int gl_uniform_4f(lua_State *L);
void setup_shader(lua_State *L, int gl_index)
{
- int shader_types = hs_create_table(L,
- hs_str_int("vertexShader", GL_VERTEX_SHADER),
- hs_str_int("fragmentShader", GL_FRAGMENT_SHADER),
+ int tbl = hs_create_table(L,
+ /* functions */
+ hs_str_cfunc("CreateShader", gl_create_shader),
+ hs_str_cfunc("ShaderSource", gl_shader_set_source),
+ hs_str_cfunc("CompileShader", gl_shader_compile),
+ hs_str_cfunc("DeleteShader", gl_shader_delete),
+
+ hs_str_cfunc("CreateProgram", gl_program_create),
+ hs_str_cfunc("AttachShader", gl_program_attach_shader),
+ hs_str_cfunc("LinkProgram", gl_program_link),
+ hs_str_cfunc("UseProgram", gl_program_use),
+
+ hs_str_cfunc("GetUniformLocation", gl_uniform_get_location),
+ hs_str_cfunc("Uniform1i", gl_uniform_1i),
+ hs_str_cfunc("Uniform4f", gl_uniform_4f),
+
+ /******** enums ********/
+ /* shader types */
+ hs_str_int("VERTEX_SHADER", GL_VERTEX_SHADER),
+ hs_str_int("FRAGMENT_SHADER", GL_FRAGMENT_SHADER),
);
- hs_create_table(L,
- hs_str_cfunc("create", gl_create_shader),
- hs_str_cfunc("setSource", gl_shader_set_source),
- hs_str_cfunc("compile", gl_shader_compile),
- hs_str_cfunc("delete", gl_shader_delete),
-
- hs_str_cfunc("createProgram", gl_program_create),
- hs_str_cfunc("attachShader", gl_program_attach_shader),
- hs_str_cfunc("link", gl_program_link),
- hs_str_cfunc("use", gl_program_use),
-
- hs_str_cfunc("getUniformLocation", gl_uniform_get_location),
- hs_str_cfunc("uniform1i", gl_uniform_1i),
- hs_str_cfunc("uniform4f", gl_uniform_4f),
-
- hs_str_tbl("type", shader_types),
- );
-
- lua_setfield(L, gl_index, "shader");
+ append_table(L, gl_index, tbl);
+ lua_pop(L, 1);
}
diff --git a/src/gl/texture.c b/src/gl/texture.c
index d0c3a0a..739dd13 100644
--- a/src/gl/texture.c
+++ b/src/gl/texture.c
@@ -2,6 +2,7 @@
#include <GLFW/glfw3.h>
#include <lua.h>
#include <honeysuckle.h>
+#include "util/util.h"
int gl_texture_create(lua_State *L);
@@ -13,27 +14,25 @@ int gl_texture_set_active(lua_State *L);
void setup_texture(lua_State *L, int gl_index)
{
- int bind_targets = hs_create_table(L,
- hs_str_int("texture2d", GL_TEXTURE_2D),
+ int tbl = hs_create_table(L,
+ /* functions */
+ hs_str_cfunc("GenTextures", gl_texture_create),
+ hs_str_cfunc("BindTexture", gl_texture_bind),
+ hs_str_cfunc("TexImage2D", gl_texture_image_2d),
+ hs_str_cfunc("GenerateMipmap", gl_texture_generate_mipmaps),
+ hs_str_cfunc("ActiveTexture", gl_texture_set_active),
+
+ /******** enums ********/
+ /* texture binding targets */
+ hs_str_int("TEXTURE_2D", GL_TEXTURE_2D),
+
+ /* texture data formats */
+ hs_str_int("RGB", GL_RGB),
+ hs_str_int("RGBA", GL_RGBA),
);
- int formats = hs_create_table(L,
- hs_str_int("rgb", GL_RGB),
- hs_str_int("rgba", GL_RGBA),
- );
-
- hs_create_table(L,
- hs_str_cfunc("create", gl_texture_create),
- hs_str_cfunc("bind", gl_texture_bind),
- hs_str_cfunc("bufferImage2d", gl_texture_image_2d),
- hs_str_cfunc("generateMipmaps", gl_texture_generate_mipmaps),
- hs_str_cfunc("setActiveUnit", gl_texture_set_active),
-
- hs_str_tbl("bindTarget", bind_targets),
- hs_str_tbl("format", formats),
- );
-
- lua_setfield(L, gl_index, "texture");
+ append_table(L, gl_index, tbl);
+ lua_pop(L, 1);
}