summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-12-15 21:08:36 -0600
committersanine-a <sanine.not@pm.me>2020-12-15 21:08:36 -0600
commit71dc88f9379f379ee0287b1ef2b62c57c6445099 (patch)
treefbc6288035740738f2c732b996e3f68830f13cf2
parent8f823ac7fc578e85415824220db3e06e01de0437 (diff)
fix bugs in texture parameter setting and add low-resolution to demo
-rw-r--r--demo/lowres.pngbin0 -> 210 bytes
-rw-r--r--demo/main.lua34
-rw-r--r--src/honey_lua.c14
-rw-r--r--src/texture.c57
-rw-r--r--src/texture.h2
5 files changed, 61 insertions, 46 deletions
diff --git a/demo/lowres.png b/demo/lowres.png
new file mode 100644
index 0000000..25abad2
--- /dev/null
+++ b/demo/lowres.png
Binary files differ
diff --git a/demo/main.lua b/demo/main.lua
index b956d04..34f9e6f 100644
--- a/demo/main.lua
+++ b/demo/main.lua
@@ -11,7 +11,7 @@ honey.input.key.bind(honey.input.key.escape, honey.exit)
local buffer = false
honey.input.key.bind(honey.input.key.f, function(action) if action == 1 then buffer = not buffer end end)
-local tex = honey.texture.load('checkerboard.png')
+ local tex = honey.texture.load('lowres.png', {minFilter='nearest', magFilter='nearest'})
local sceneRoot = Node.new()
@@ -28,18 +28,26 @@ local suzanne = MeshInstance.new(sceneRoot,
meshes[1],
shader)
print(suzanne.mesh)
-local plane = MeshInstance.new(suzanne,
- honey.glm.vec3{1,0,0},
- honey.glm.vec3{0,0,0},
- honey.glm.vec3{1,1,1},
- Primitives.plane(4,4),
- shader)
--- local plane2 = MeshInstance.new(suzanne,
--- honey.glm.vec3{5,0,0},
--- honey.glm.vec3{0,math.pi,0},
--- honey.glm.vec3{1,1,1},
--- honey.primitives.plane(4,4),
--- shader)
+--local plane = MeshInstance.new(suzanne,
+-- honey.glm.vec3{1,0,0},
+-- honey.glm.vec3{0,0,0},
+-- honey.glm.vec3{1,1,1},
+-- Primitives.plane(4,4),
+-- shader)
+
+MeshInstance.new(sceneRoot,
+ honey.glm.vec3{0,0,3},
+ honey.glm.vec3{0,0,0},
+ honey.glm.vec3{1,1,1},
+ Primitives.plane(4,4),
+ shader)
+
+MeshInstance.new(sceneRoot,
+ honey.glm.vec3{4,0,3},
+ honey.glm.vec3{0,math.pi,0},
+ honey.glm.vec3{1,1,1},
+ Primitives.plane(4,4),
+ shader)
suzanne.update = function(self, dt)
self:rotate('y', dt)
diff --git a/src/honey_lua.c b/src/honey_lua.c
index 1d199c2..50a9710 100644
--- a/src/honey_lua.c
+++ b/src/honey_lua.c
@@ -267,15 +267,15 @@ void honey_lua_parse_params(lua_State* L, int n, int m, ...)
if (n < m)
honey_lua_throw_error
(L, "required parameter '%s' was not found in param table!", param);
- continue;
}
-
- if (!check_argument(L, type, -1))
- honey_lua_throw_error
- (L, "parameter '%s' must be of type %s; got %s instead",
- param, type_to_string(type), lua_typename(L, lua_type(L, -1)));
+ else {
+ if (!check_argument(L, type, -1))
+ honey_lua_throw_error
+ (L, "parameter '%s' must be of type %s; got %s instead",
+ param, type_to_string(type), lua_typename(L, lua_type(L, -1)));
- function(L, data);
+ function(L, data);
+ }
lua_pop(L, 1);
}
diff --git a/src/texture.c b/src/texture.c
index fdd77be..2bcc1e2 100644
--- a/src/texture.c
+++ b/src/texture.c
@@ -21,16 +21,15 @@ static void configure_params(lua_State* L, honey_texture_params* params);
static void setup_texture(lua_State* L, honey_texture** tex, bool use_params)
{
+ honey_texture_params params;
+ setup_default_texture_params(&params);
+ if (use_params)
+ configure_params(L, &params);
+
honey_texture *texture = lua_newuserdata(L, sizeof(honey_texture));
+ texture->params = params;
*tex = texture;
- setup_default_texture_params(&(texture->params));
-
- if (use_params) {
- lua_pushvalue(L, -2);
- configure_params(L, &(texture->params));
- lua_pop(L, 1);
- }
-
+
lua_rawgeti(L, LUA_REGISTRYINDEX, honey_texture_mt_ref);
lua_setmetatable(L, -2);
}
@@ -129,10 +128,14 @@ void honey_setup_texture(lua_State* L)
honey_texture_mt_ref = luaL_ref(L, LUA_REGISTRYINDEX);
honey_lua_create_table
- (L, 2,
- HONEY_FUNCTION, "new", honey_lua_texture_new,
+ (L, 1,
HONEY_FUNCTION, "load", honey_lua_texture_load);
+ honey_lua_create_table
+ (L, 1,
+ HONEY_FUNCTION, "__call", honey_lua_texture_new);
+ lua_setmetatable(L, -2);
+
lua_setfield(L, -2, "texture");
}
@@ -357,17 +360,18 @@ static void configure_min_filter(lua_State* L, void* data)
{
honey_texture_params* params = (honey_texture_params*) data;
const char* str = lua_tostring(L, -1);
- if (strcmp(str, "nearest"))
+
+ if (strcmp(str, "nearest") == 0)
params->min_filter = GL_NEAREST;
- else if (strcmp(str, "linear"))
+ else if (strcmp(str, "linear") == 0)
params->min_filter = GL_LINEAR;
- else if (strcmp(str, "nearest-nearest"))
+ else if (strcmp(str, "nearest-nearest") == 0)
params->min_filter = GL_NEAREST_MIPMAP_NEAREST;
- else if (strcmp(str, "linear-nearest"))
+ else if (strcmp(str, "linear-nearest") == 0)
params->min_filter = GL_LINEAR_MIPMAP_NEAREST;
- else if (strcmp(str, "nearest-linear"))
+ else if (strcmp(str, "nearest-linear") == 0)
params->min_filter = GL_NEAREST_MIPMAP_LINEAR;
- else if (strcmp(str, "linear-linear"))
+ else if (strcmp(str, "linear-linear") == 0)
params->min_filter = GL_LINEAR_MIPMAP_LINEAR;
else
honey_lua_throw_error
@@ -380,10 +384,13 @@ static void configure_mag_filter(lua_State* L, void* data)
{
honey_texture_params* params = (honey_texture_params*) data;
const char* str = lua_tostring(L, -1);
- if (strcmp(str, "nearest"))
- params->min_filter = GL_NEAREST;
- else if (strcmp(str, "linear"))
- params->min_filter = GL_LINEAR;
+
+ if (strcmp(str, "nearest") == 0) {
+ printf("MAG FILTER NEAREST\n");
+ params->mag_filter = GL_NEAREST;
+ }
+ else if (strcmp(str, "linear") == 0)
+ params->mag_filter = GL_LINEAR;
else
honey_lua_throw_error
(L, "unknown magFilter type: '%s'", str);
@@ -393,13 +400,13 @@ static void configure_mag_filter(lua_State* L, void* data)
static void configure_wrap(lua_State* L, const char* string, int* wrap)
{
- if (strcmp(string, "clamp"))
+ if (strcmp(string, "clamp") == 0)
*wrap = GL_CLAMP_TO_EDGE;
- else if (strcmp(string, "clamp-border"))
+ else if (strcmp(string, "clamp-border") == 0)
*wrap = GL_CLAMP_TO_BORDER;
- else if (strcmp(string, "repeat"))
+ else if (strcmp(string, "repeat") == 0)
*wrap = GL_REPEAT;
- else if (strcmp(string, "repeat-mirror"))
+ else if (strcmp(string, "repeat-mirror") == 0)
*wrap = GL_MIRRORED_REPEAT;
else
honey_lua_throw_error
@@ -444,7 +451,7 @@ static void configure_params(lua_State* L, honey_texture_params* params)
HONEY_STRING, "type", configure_type, params,
HONEY_BOOLEAN, "mipmaps", configure_mipmaps, params,
HONEY_STRING, "minFilter", configure_min_filter, params,
- HONEY_STRING, "magFilter", configure_min_filter, params,
+ HONEY_STRING, "magFilter", configure_mag_filter, params,
HONEY_STRING, "sWrap", configure_wrap_s, params,
HONEY_STRING, "tWrap", configure_wrap_t, params,
HONEY_STRING, "rWrap", configure_wrap_r, params);
diff --git a/src/texture.h b/src/texture.h
index 6bbcc4d..e822a59 100644
--- a/src/texture.h
+++ b/src/texture.h
@@ -12,7 +12,7 @@
#define HONEY_TEXTURE_DEFAULT_HEIGHT 1024
#define HONEY_TEXTURE_DEFAULT_CHANNELS 4
#define HONEY_TEXTURE_DEFAULT_TYPE HONEY_TEXTURE_TYPE_RGBA
-#define HONEY_TEXTURE_DEFAULT_MIPMAPS true
+#define HONEY_TEXTURE_DEFAULT_MIPMAPS false
#define HONEY_TEXTURE_DEFAULT_MIN_FILTER GL_LINEAR
#define HONEY_TEXTURE_DEFAULT_MAG_FILTER GL_LINEAR
#define HONEY_TEXTURE_DEFAULT_WRAP_S GL_REPEAT