From 7d5efa6c62bd162df060302298ecdbf32cf38700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Wed, 14 Feb 2024 15:09:47 +0100 Subject: [PATCH] draw: add TEXTURE_ANISOTROPY flag --- bind/v4k.lua | 1 + engine/joint/v4k.h | 12 +++++++++++- engine/split/v4k_render.c | 11 ++++++++++- engine/split/v4k_render.h | 1 + engine/v4k.c | 11 ++++++++++- engine/v4k.h | 1 + 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/bind/v4k.lua b/bind/v4k.lua index 2f8cc8c..4f85b8b 100644 --- a/bind/v4k.lua +++ b/bind/v4k.lua @@ -1062,6 +1062,7 @@ enum TEXTURE_FLAGS { TEXTURE_NEAREST = 0, TEXTURE_LINEAR = 64, TEXTURE_MIPMAPS = 128, + TEXTURE_ANISOTROPY = 1 << 30, TEXTURE_CLAMP = 0, TEXTURE_BORDER = 0x100, TEXTURE_REPEAT = 0x200, diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index a96b56b..8a9ede3 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -17110,6 +17110,7 @@ enum TEXTURE_FLAGS { TEXTURE_NEAREST = 0, TEXTURE_LINEAR = 64, TEXTURE_MIPMAPS = 128, + TEXTURE_ANISOTROPY = 1 << 30, TEXTURE_CLAMP = 0, TEXTURE_BORDER = 0x100, @@ -370744,6 +370745,15 @@ GLenum texture_type = t->flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTUR glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, wrap); glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, min_filter); glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, mag_filter); + + if (flags & TEXTURE_ANISOTROPY) { + GLfloat value, max_anisotropy = 16.0f; + glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &value); + + value = (value > max_anisotropy) ? max_anisotropy : value; + glTexParameterf(texture_type, GL_TEXTURE_MAX_ANISOTROPY, value); + } + #if 0 // only for sampler2DShadow if( flags & TEXTURE_DEPTH ) glTexParameteri(texture_type, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); if( flags & TEXTURE_DEPTH ) glTexParameteri(texture_type, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); @@ -373225,7 +373235,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model) if( reused ) continue; // decode texture+material - int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_LINEAR; // LINEAR, NEAREST + int flags = TEXTURE_MIPMAPS|TEXTURE_ANISOTROPY|TEXTURE_REPEAT|TEXTURE_LINEAR; // LINEAR, NEAREST int invalid = texture_checker().id; #if 1 diff --git a/engine/split/v4k_render.c b/engine/split/v4k_render.c index b585779..13910cb 100644 --- a/engine/split/v4k_render.c +++ b/engine/split/v4k_render.c @@ -730,6 +730,15 @@ GLenum texture_type = t->flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTUR glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, wrap); glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, min_filter); glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, mag_filter); + + if (flags & TEXTURE_ANISOTROPY) { + GLfloat value, max_anisotropy = 16.0f; + glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &value); + + value = (value > max_anisotropy) ? max_anisotropy : value; + glTexParameterf(texture_type, GL_TEXTURE_MAX_ANISOTROPY, value); + } + #if 0 // only for sampler2DShadow if( flags & TEXTURE_DEPTH ) glTexParameteri(texture_type, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); if( flags & TEXTURE_DEPTH ) glTexParameteri(texture_type, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); @@ -3211,7 +3220,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model) if( reused ) continue; // decode texture+material - int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_LINEAR; // LINEAR, NEAREST + int flags = TEXTURE_MIPMAPS|TEXTURE_ANISOTROPY|TEXTURE_REPEAT|TEXTURE_LINEAR; // LINEAR, NEAREST int invalid = texture_checker().id; #if 1 diff --git a/engine/split/v4k_render.h b/engine/split/v4k_render.h index e752d82..add244c 100644 --- a/engine/split/v4k_render.h +++ b/engine/split/v4k_render.h @@ -89,6 +89,7 @@ enum TEXTURE_FLAGS { TEXTURE_NEAREST = 0, TEXTURE_LINEAR = 64, TEXTURE_MIPMAPS = 128, + TEXTURE_ANISOTROPY = 1 << 30, TEXTURE_CLAMP = 0, TEXTURE_BORDER = 0x100, diff --git a/engine/v4k.c b/engine/v4k.c index aa8a5ff..643072f 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -17886,6 +17886,15 @@ GLenum texture_type = t->flags & TEXTURE_ARRAY ? GL_TEXTURE_2D_ARRAY : GL_TEXTUR glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, wrap); glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, min_filter); glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, mag_filter); + + if (flags & TEXTURE_ANISOTROPY) { + GLfloat value, max_anisotropy = 16.0f; + glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &value); + + value = (value > max_anisotropy) ? max_anisotropy : value; + glTexParameterf(texture_type, GL_TEXTURE_MAX_ANISOTROPY, value); + } + #if 0 // only for sampler2DShadow if( flags & TEXTURE_DEPTH ) glTexParameteri(texture_type, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); if( flags & TEXTURE_DEPTH ) glTexParameteri(texture_type, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); @@ -20367,7 +20376,7 @@ bool model_load_textures(iqm_t *q, const struct iqmheader *hdr, model_t *model) if( reused ) continue; // decode texture+material - int flags = TEXTURE_MIPMAPS|TEXTURE_REPEAT|TEXTURE_LINEAR; // LINEAR, NEAREST + int flags = TEXTURE_MIPMAPS|TEXTURE_ANISOTROPY|TEXTURE_REPEAT|TEXTURE_LINEAR; // LINEAR, NEAREST int invalid = texture_checker().id; #if 1 diff --git a/engine/v4k.h b/engine/v4k.h index 6392bc2..7321b18 100644 --- a/engine/v4k.h +++ b/engine/v4k.h @@ -3177,6 +3177,7 @@ enum TEXTURE_FLAGS { TEXTURE_NEAREST = 0, TEXTURE_LINEAR = 64, TEXTURE_MIPMAPS = 128, + TEXTURE_ANISOTROPY = 1 << 30, TEXTURE_CLAMP = 0, TEXTURE_BORDER = 0x100,