summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-08-22 15:55:44 -0500
committersanine <sanine.not@pm.me>2022-08-22 15:55:44 -0500
commit1f47b685f35455afcc7441389cdc60018f66d159 (patch)
tree640f1ae52966ad0b6621a0cd4b4f810f9186e803 /src
parentd69f711275675d4b5da88117b14c1d15be232cf5 (diff)
add textures
Diffstat (limited to 'src')
-rw-r--r--src/gl/CMakeLists.txt1
-rw-r--r--src/gl/gl.c2
-rw-r--r--src/gl/gl.h1
-rw-r--r--src/gl/shader.c11
-rw-r--r--src/gl/texture.c93
-rw-r--r--src/main.c2
6 files changed, 110 insertions, 0 deletions
diff --git a/src/gl/CMakeLists.txt b/src/gl/CMakeLists.txt
index f995ef5..d4bc770 100644
--- a/src/gl/CMakeLists.txt
+++ b/src/gl/CMakeLists.txt
@@ -7,6 +7,7 @@ target_sources(honey PUBLIC
${GL}/drawing.c
${GL}/shader.c
${GL}/window.c
+ ${GL}/texture.c
${GL}/gl.c
${GL}/glad/glad.c
)
diff --git a/src/gl/gl.c b/src/gl/gl.c
index 8f56d33..c4502dc 100644
--- a/src/gl/gl.c
+++ b/src/gl/gl.c
@@ -21,6 +21,7 @@ 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),
@@ -48,6 +49,7 @@ void setup_gl(lua_State *L, int honey_index)
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/gl.h b/src/gl/gl.h
index 766fe63..8aa1ef7 100644
--- a/src/gl/gl.h
+++ b/src/gl/gl.h
@@ -7,6 +7,7 @@ void setup_gl(lua_State *L, int honey_index);
void setup_shader(lua_State *L, int gl_index);
void setup_drawing(lua_State *L, int gl_index);
void setup_data(lua_State *L, int gl_index);
+void setup_texture(lua_State *L, int gl_index);
void setup_window(lua_State *L, int honey_index);
diff --git a/src/gl/shader.c b/src/gl/shader.c
index fb64bc0..c3b409c 100644
--- a/src/gl/shader.c
+++ b/src/gl/shader.c
@@ -14,6 +14,7 @@ int gl_program_link(lua_State *L);
int gl_program_use(lua_State *L);
int gl_uniform_get_location(lua_State *L);
+int gl_uniform_1i(lua_State *L);
int gl_uniform_4f(lua_State *L);
@@ -36,6 +37,7 @@ void setup_shader(lua_State *L, int gl_index)
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),
@@ -141,6 +143,15 @@ int gl_uniform_get_location(lua_State *L)
}
+int gl_uniform_1i(lua_State *L)
+{
+ lua_Integer location, v0;
+ hs_parse_args(L, hs_int(location), hs_int(v0));
+ glUniform1i(location, v0);
+ return 0;
+}
+
+
int gl_uniform_4f(lua_State *L)
{
lua_Integer location;
diff --git a/src/gl/texture.c b/src/gl/texture.c
new file mode 100644
index 0000000..d0c3a0a
--- /dev/null
+++ b/src/gl/texture.c
@@ -0,0 +1,93 @@
+#include "gl/glad/glad.h"
+#include <GLFW/glfw3.h>
+#include <lua.h>
+#include <honeysuckle.h>
+
+
+int gl_texture_create(lua_State *L);
+int gl_texture_bind(lua_State *L);
+int gl_texture_image_2d(lua_State *L);
+int gl_texture_generate_mipmaps(lua_State *L);
+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 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");
+}
+
+
+int gl_texture_create(lua_State *L)
+{
+ unsigned int texture;
+ glGenTextures(1, &texture);
+ lua_pushinteger(L, texture);
+ return 1;
+}
+
+
+int gl_texture_bind(lua_State *L)
+{
+ lua_Integer target, texture;
+ hs_parse_args(L, hs_int(target), hs_int(texture));
+ glBindTexture(target, texture);
+ return 0;
+}
+
+
+int gl_texture_image_2d(lua_State *L)
+{
+ lua_Integer target, mipmap_level,
+ internal_format,
+ width, height,
+ format, type;
+ void *data;
+ hs_parse_args(L,
+ hs_int(target), hs_int(mipmap_level),
+ hs_int(internal_format),
+ hs_int(width), hs_int(height),
+ hs_int(format), hs_int(type),
+ hs_light(data)
+ );
+
+ glTexImage2D(target, mipmap_level, internal_format, width, height, 0, format, type, data);
+ return 0;
+}
+
+
+int gl_texture_generate_mipmaps(lua_State *L)
+{
+ lua_Integer target;
+ hs_parse_args(L, hs_int(target));
+ glGenerateMipmap(target);
+ return 0;
+}
+
+
+int gl_texture_set_active(lua_State *L)
+{
+ lua_Integer unit;
+ hs_parse_args(L, hs_int(unit));
+ glActiveTexture(GL_TEXTURE0 + unit);
+ return 0;
+}
diff --git a/src/main.c b/src/main.c
index c989dbd..66b1f11 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,6 +3,7 @@
#include <lualib.h>
#include <honeysuckle.h>
#include "gl/gl.h"
+#include "image/image.h"
int main(int argc, char **argv)
@@ -14,6 +15,7 @@ int main(int argc, char **argv)
int honey_index = lua_gettop(L);
setup_gl(L, honey_index);
setup_window(L, honey_index);
+ setup_image(L, honey_index);
lua_setglobal(L, "honey");
int err = luaL_loadfile(L, "honey.lua");