From eb45b6f04f5979a286dee0e8bc4dc5fb8ad31c0d Mon Sep 17 00:00:00 2001 From: bjorn Date: Sun, 22 Jul 2018 19:46:45 -0700 Subject: [PATCH] Add the ability to set Texture LOD bias; --- src/api/types/texture.c | 11 +++++++---- src/graphics/opengl.c | 1 + src/graphics/texture.h | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api/types/texture.c b/src/api/types/texture.c index fb382cb5..eeec136a 100644 --- a/src/api/types/texture.c +++ b/src/api/types/texture.c @@ -28,11 +28,12 @@ int l_lovrTextureGetFilter(lua_State* L) { Texture* texture = luax_checktypeof(L, 1, Texture); TextureFilter filter = lovrTextureGetFilter(texture); lua_pushstring(L, FilterModes[filter.mode]); + lua_pushnumber(L, filter.sharpness); if (filter.mode == FILTER_ANISOTROPIC) { lua_pushnumber(L, filter.anisotropy); - return 2; + return 3; } - return 1; + return 2; } int l_lovrTextureGetHeight(lua_State* L) { @@ -85,8 +86,10 @@ int l_lovrTextureReplacePixels(lua_State* L) { int l_lovrTextureSetFilter(lua_State* L) { Texture* texture = luax_checktypeof(L, 1, Texture); FilterMode mode = luaL_checkoption(L, 2, NULL, FilterModes); - float anisotropy = luaL_optnumber(L, 3, 1.); - lovrTextureSetFilter(texture, (TextureFilter) { .mode = mode, .anisotropy = anisotropy }); + float sharpness = luaL_optnumber(L, 3, 0.); + float anisotropy = luaL_optnumber(L, 4, 1.); + TextureFilter filter = { .mode = mode, .sharpness = sharpness, .anisotropy = anisotropy }; + lovrTextureSetFilter(texture, filter); return 0; } diff --git a/src/graphics/opengl.c b/src/graphics/opengl.c index f72d258e..614624e2 100644 --- a/src/graphics/opengl.c +++ b/src/graphics/opengl.c @@ -1025,6 +1025,7 @@ void lovrTextureSetFilter(Texture* texture, TextureFilter filter) { break; } + glTexParameteri(texture->glType, GL_TEXTURE_LOD_BIAS, -filter.sharpness); glTexParameteri(texture->glType, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); } diff --git a/src/graphics/texture.h b/src/graphics/texture.h index 6ebb892b..a551ee6e 100644 --- a/src/graphics/texture.h +++ b/src/graphics/texture.h @@ -20,6 +20,7 @@ typedef enum { typedef struct { FilterMode mode; float anisotropy; + float sharpness; } TextureFilter; typedef enum {