diff options
author | sanine-a <sanine.not@pm.me> | 2020-12-15 21:08:36 -0600 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-12-15 21:08:36 -0600 |
commit | 71dc88f9379f379ee0287b1ef2b62c57c6445099 (patch) | |
tree | fbc6288035740738f2c732b996e3f68830f13cf2 /src | |
parent | 8f823ac7fc578e85415824220db3e06e01de0437 (diff) |
fix bugs in texture parameter setting and add low-resolution to demo
Diffstat (limited to 'src')
-rw-r--r-- | src/honey_lua.c | 14 | ||||
-rw-r--r-- | src/texture.c | 57 | ||||
-rw-r--r-- | src/texture.h | 2 |
3 files changed, 40 insertions, 33 deletions
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(¶ms); + if (use_params) + configure_params(L, ¶ms); + 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 |