summaryrefslogtreecommitdiff
path: root/src/gl/gl.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-08-20 15:37:04 -0500
committersanine <sanine.not@pm.me>2022-08-20 15:37:04 -0500
commit8b9b325b092b7157996cfbcdd7ce38f9e876fff8 (patch)
tree4c878f4a887d435d8c464112c2ad0cef1a6db2c8 /src/gl/gl.c
parentb6ccd8b31a78ef99f8c346d9b60f123c7ac813ec (diff)
fix bug in gl.bufferData and add error checking
Diffstat (limited to 'src/gl/gl.c')
-rw-r--r--src/gl/gl.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/gl/gl.c b/src/gl/gl.c
index 485d412..581cf39 100644
--- a/src/gl/gl.c
+++ b/src/gl/gl.c
@@ -15,6 +15,7 @@
int gl_init(lua_State *L);
int glad_init(lua_State *L);
int gl_terminate(lua_State *L);
+int gl_get_error(lua_State *L);
/* buffers */
int gl_create_buffer(lua_State *L);
@@ -38,6 +39,7 @@ int gl_program_link(lua_State *L);
int gl_program_use(lua_State *L);
/* drawing */
+int gl_set_viewport(lua_State *L);
int gl_draw_arrays(lua_State *L);
int gl_set_clear_color(lua_State *L);
int gl_clear(lua_State *L);
@@ -45,6 +47,15 @@ int gl_clear(lua_State *L);
void setup_gl(lua_State *L, int honey_index)
{
+ 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 buffer_binding_targets = hs_create_table(L,
hs_str_int("arrayBuffer", GL_ARRAY_BUFFER),
);
@@ -76,6 +87,9 @@ void setup_gl(lua_State *L, int honey_index)
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("errorType", error_types),
/* buffer */
hs_str_cfunc("createBuffer", gl_create_buffer),
@@ -107,6 +121,7 @@ void setup_gl(lua_State *L, int honey_index)
hs_str_cfunc("drawArrays", gl_draw_arrays),
hs_str_cfunc("setClearColor", gl_set_clear_color),
hs_str_cfunc("clear", gl_clear),
+ hs_str_cfunc("setViewport", gl_set_viewport),
hs_str_tbl("primitiveType", primitive_types),
hs_str_tbl("bufferMask", buffer_masks),
@@ -139,6 +154,13 @@ int gl_terminate(lua_State *L)
}
+int gl_get_error(lua_State *L)
+{
+ lua_pushinteger(L, glGetError());
+ return 1;
+}
+
+
int gl_create_buffer(lua_State *L)
{
int buf;
@@ -150,9 +172,9 @@ int gl_create_buffer(lua_State *L)
int gl_bind_buffer(lua_State *L)
{
- lua_Integer buf, target;
- hs_parse_args(L, hs_int(buf), hs_int(target));
- glBindBuffer(buf, target);
+ lua_Integer target, buf;
+ hs_parse_args(L, hs_int(target), hs_int(buf));
+ glBindBuffer(target, buf);
return 0;
}
@@ -174,9 +196,13 @@ int gl_buffer_data(lua_State *L)
hs_throw_error(L, "all table items must be numbers (failed at index %d)", i);
}
buf[i] = lua_tonumber(L, -1);
+ printf(" [%d] %f\n", i, buf[i]);
lua_pop(L, 1);
}
+ printf("target: %d\n", target);
+ printf("GL_ARRAY_BUFFER: %d\n", GL_ARRAY_BUFFER);
+
/* call */
glBufferData(target, len*sizeof(float), buf, usage);
free(buf);
@@ -292,9 +318,11 @@ int gl_vertex_attrib_pointer(lua_State *L)
lua_Integer index, size, stride, offset;
bool normalized;
hs_parse_args(L, hs_int(index), hs_int(size), hs_bool(normalized), hs_int(stride), hs_int(offset));
- glVertexAttribPointer(index, size, GL_FLOAT,
+ printf("normalized: %d\n", normalized);
+ /*glVertexAttribPointer(index, size, GL_FLOAT,
normalized, stride*sizeof(float),
- (void*) (offset*sizeof(float)));
+ (void*) (offset*sizeof(float)));*/
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void*)0);
return 0;
}
@@ -333,3 +361,12 @@ int gl_draw_arrays(lua_State *L)
glDrawArrays(mode, first, count);
return 0;
}
+
+
+int gl_set_viewport(lua_State *L)
+{
+ lua_Integer x, y, w, h;
+ hs_parse_args(L, hs_int(x), hs_int(y), hs_int(w), hs_int(h));
+ glViewport(x, y, w, h);
+ return 0;
+}