From 4c976cab99d977ca2a638aff8a685301dfcf962b Mon Sep 17 00:00:00 2001 From: David Klein Date: Thu, 11 Apr 2024 15:23:44 +0200 Subject: [PATCH 1/3] overridable g1 texture filters --- Sources/kinc/graphics1/graphics.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/kinc/graphics1/graphics.c b/Sources/kinc/graphics1/graphics.c index 809593d41..45a5305d9 100644 --- a/Sources/kinc/graphics1/graphics.c +++ b/Sources/kinc/graphics1/graphics.c @@ -17,6 +17,9 @@ static kinc_g4_shader_t vertexShader; static kinc_g4_shader_t fragmentShader; static kinc_g4_pipeline_t pipeline; static kinc_g4_texture_unit_t tex; +kinc_g4_texture_filter_t kinc_internal_g1_texture_minf = KINC_G4_TEXTURE_FILTER_LINEAR; +kinc_g4_texture_filter_t kinc_internal_g1_texture_magf = KINC_G4_TEXTURE_FILTER_LINEAR; +kinc_g4_mipmap_filter_t kinc_internal_g1_texture_mipf = KINC_G4_MIPMAP_FILTER_NONE; #endif static kinc_g4_vertex_buffer_t vb; static kinc_g4_index_buffer_t ib; @@ -44,6 +47,9 @@ void kinc_g1_end(void) { #ifndef KINC_KONG kinc_g4_set_texture(tex, &texture); + kinc_g4_set_texture_minification_filter(tex, kinc_internal_g1_texture_minf); + kinc_g4_set_texture_magnification_filter(tex, kinc_internal_g1_texture_magf); + kinc_g4_set_texture_mipmap_filter(tex, kinc_internal_g1_texture_mipf); #endif kinc_g4_set_vertex_buffer(&vb); kinc_g4_set_index_buffer(&ib); From 39d82991f25e0d859cc1852e8558dc4047947302 Mon Sep 17 00:00:00 2001 From: David Klein Date: Thu, 18 Apr 2024 08:48:43 +0200 Subject: [PATCH 2/3] add a public api for overriding g1 filter settings --- Sources/kinc/graphics1/graphics.c | 47 ++++++++++++++++++++++++++---- Sources/kinc/graphics1/graphics.h | 48 +++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 6 deletions(-) diff --git a/Sources/kinc/graphics1/graphics.c b/Sources/kinc/graphics1/graphics.c index 45a5305d9..f95a256c0 100644 --- a/Sources/kinc/graphics1/graphics.c +++ b/Sources/kinc/graphics1/graphics.c @@ -7,6 +7,7 @@ #include #include #include +#include #ifdef KINC_KONG #include @@ -17,9 +18,9 @@ static kinc_g4_shader_t vertexShader; static kinc_g4_shader_t fragmentShader; static kinc_g4_pipeline_t pipeline; static kinc_g4_texture_unit_t tex; -kinc_g4_texture_filter_t kinc_internal_g1_texture_minf = KINC_G4_TEXTURE_FILTER_LINEAR; -kinc_g4_texture_filter_t kinc_internal_g1_texture_magf = KINC_G4_TEXTURE_FILTER_LINEAR; -kinc_g4_mipmap_filter_t kinc_internal_g1_texture_mipf = KINC_G4_MIPMAP_FILTER_NONE; +kinc_g1_texture_filter_t kinc_internal_g1_texture_filter_min = KINC_G1_TEXTURE_FILTER_LINEAR; +kinc_g1_texture_filter_t kinc_internal_g1_texture_filter_mag = KINC_G1_TEXTURE_FILTER_LINEAR; +kinc_g1_mipmap_filter_t kinc_internal_g1_mipmap_filter = KINC_G1_MIPMAP_FILTER_NONE; #endif static kinc_g4_vertex_buffer_t vb; static kinc_g4_index_buffer_t ib; @@ -33,6 +34,28 @@ void kinc_g1_begin(void) { kinc_internal_g1_image = (uint32_t *)kinc_g4_texture_lock(&texture); } +static inline kinc_g4_texture_filter_t map_texture_filter(kinc_g1_texture_filter_t filter) { + switch (filter) { + case KINC_G1_TEXTURE_FILTER_POINT: return KINC_G4_TEXTURE_FILTER_POINT; + case KINC_G1_TEXTURE_FILTER_LINEAR: return KINC_G4_TEXTURE_FILTER_LINEAR; + case KINC_G1_TEXTURE_FILTER_ANISOTROPIC: return KINC_G4_TEXTURE_FILTER_ANISOTROPIC; + } + + kinc_log(KINC_LOG_LEVEL_WARNING, "unhandled kinc_g1_texture_filter_t (%i)", filter); + return KINC_G1_TEXTURE_FILTER_LINEAR; +} + +static inline kinc_g4_texture_filter_t map_mipmap_filter(kinc_g1_texture_filter_t filter) { + switch (filter) { + case KINC_G1_MIPMAP_FILTER_NONE: return KINC_G4_MIPMAP_FILTER_NONE; + case KINC_G1_MIPMAP_FILTER_POINT: return KINC_G4_MIPMAP_FILTER_POINT; + case KINC_G1_MIPMAP_FILTER_LINEAR: return KINC_G4_MIPMAP_FILTER_LINEAR; + } + + kinc_log(KINC_LOG_LEVEL_WARNING, "unhandled kinc_g1_mipmap_filter_t (%i)", filter); + return KINC_G4_MIPMAP_FILTER_NONE; +} + void kinc_g1_end(void) { kinc_internal_g1_image = NULL; kinc_g4_texture_unlock(&texture); @@ -47,9 +70,9 @@ void kinc_g1_end(void) { #ifndef KINC_KONG kinc_g4_set_texture(tex, &texture); - kinc_g4_set_texture_minification_filter(tex, kinc_internal_g1_texture_minf); - kinc_g4_set_texture_magnification_filter(tex, kinc_internal_g1_texture_magf); - kinc_g4_set_texture_mipmap_filter(tex, kinc_internal_g1_texture_mipf); + kinc_g4_set_texture_minification_filter(tex, map_texture_filter(kinc_internal_g1_texture_filter_min)); + kinc_g4_set_texture_magnification_filter(tex, map_texture_filter(kinc_internal_g1_texture_filter_mag)); + kinc_g4_set_texture_mipmap_filter(tex, map_mipmap_filter(kinc_internal_g1_mipmap_filter)); #endif kinc_g4_set_vertex_buffer(&vb); kinc_g4_set_index_buffer(&ib); @@ -178,4 +201,16 @@ int kinc_g1_height() { return kinc_internal_g1_h; } +void kinc_g1_set_texture_magnification_filter(kinc_g1_texture_filter_t filter) { + kinc_internal_g1_texture_filter_min = filter; +} + +void kinc_g1_set_texture_minification_filter(kinc_g1_texture_filter_t filter) { + kinc_internal_g1_texture_filter_mag = filter; +} + +void kinc_g1_set_texture_mipmap_filter(kinc_g1_mipmap_filter_t filter) { + kinc_internal_g1_mipmap_filter = filter; +} + #endif diff --git a/Sources/kinc/graphics1/graphics.h b/Sources/kinc/graphics1/graphics.h index d171f5073..52376d877 100644 --- a/Sources/kinc/graphics1/graphics.h +++ b/Sources/kinc/graphics1/graphics.h @@ -14,6 +14,18 @@ extern "C" { #endif +typedef enum { + KINC_G1_TEXTURE_FILTER_POINT, + KINC_G1_TEXTURE_FILTER_LINEAR, + KINC_G1_TEXTURE_FILTER_ANISOTROPIC, +} kinc_g1_texture_filter_t; + +typedef enum { + KINC_G1_MIPMAP_FILTER_NONE, + KINC_G1_MIPMAP_FILTER_POINT, + KINC_G1_MIPMAP_FILTER_LINEAR, +} kinc_g1_mipmap_filter_t; + /// /// Initializes the G1-API. /// @@ -34,6 +46,9 @@ KINC_FUNC void kinc_g1_end(void); extern uint32_t *kinc_internal_g1_image; extern int kinc_internal_g1_w, kinc_internal_g1_h, kinc_internal_g1_tex_width; +extern kinc_g1_texture_filter_t kinc_internal_g1_texture_filter_min; +extern kinc_g1_texture_filter_t kinc_internal_g1_texture_filter_mag; +extern kinc_g1_mipmap_filter_t kinc_internal_g1_mipmap_filter; #if defined(KINC_DYNAMIC_COMPILE) || defined(KINC_DYNAMIC) || defined(KINC_DOCS) @@ -59,6 +74,27 @@ KINC_FUNC int kinc_g1_width(void); /// The height KINC_FUNC int kinc_g1_height(void); +/// +/// Set the texture-sampling-mode for upscaled textures. +/// +/// The texture-unit to set the texture-sampling-mode for +/// The mode to set +KINC_FUNC void kinc_g1_set_texture_magnification_filter(kinc_g1_texture_filter_t filter); + +/// +/// Set the texture-sampling-mode for downscaled textures. +/// +/// The texture-unit to set the texture-sampling-mode for +/// The mode to set +KINC_FUNC void kinc_g1_set_texture_minification_filter(kinc_g1_texture_filter_t filter); + +/// +/// Sets the mipmap-sampling-mode which defines whether mipmaps are used at all and if so whether the two neighbouring mipmaps are linearly interpolated. +/// +/// The texture-unit to set the mipmap-sampling-mode for +/// The mode to set +KINC_FUNC void kinc_g1_set_texture_mipmap_filter(kinc_g1_mipmap_filter_t filter); + #else // implementation moved to the header to allow easy inlining @@ -79,6 +115,18 @@ static inline int kinc_g1_height(void) { return kinc_internal_g1_h; } +static inline void kinc_g1_set_texture_magnification_filter(kinc_g1_texture_filter_t filter) { + kinc_internal_g1_texture_filter_min = filter; +} + +static inline void kinc_g1_set_texture_minification_filter(kinc_g1_texture_filter_t filter) { + kinc_internal_g1_texture_filter_mag = filter; +} + +static inline void kinc_g1_set_texture_mipmap_filter(kinc_g1_mipmap_filter_t filter) { + kinc_internal_g1_mipmap_filter = filter; +} + #endif #ifdef __cplusplus From 8f3599187efcbf8318b1180e1d3887faa24092e6 Mon Sep 17 00:00:00 2001 From: David Klein Date: Thu, 18 Apr 2024 08:52:51 +0200 Subject: [PATCH 3/3] fix swapped names --- Sources/kinc/graphics1/graphics.c | 4 ++-- Sources/kinc/graphics1/graphics.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/kinc/graphics1/graphics.c b/Sources/kinc/graphics1/graphics.c index f95a256c0..e316f91e4 100644 --- a/Sources/kinc/graphics1/graphics.c +++ b/Sources/kinc/graphics1/graphics.c @@ -202,11 +202,11 @@ int kinc_g1_height() { } void kinc_g1_set_texture_magnification_filter(kinc_g1_texture_filter_t filter) { - kinc_internal_g1_texture_filter_min = filter; + kinc_internal_g1_texture_filter_mag = filter; } void kinc_g1_set_texture_minification_filter(kinc_g1_texture_filter_t filter) { - kinc_internal_g1_texture_filter_mag = filter; + kinc_internal_g1_texture_filter_min = filter; } void kinc_g1_set_texture_mipmap_filter(kinc_g1_mipmap_filter_t filter) { diff --git a/Sources/kinc/graphics1/graphics.h b/Sources/kinc/graphics1/graphics.h index 52376d877..7a4ba186c 100644 --- a/Sources/kinc/graphics1/graphics.h +++ b/Sources/kinc/graphics1/graphics.h @@ -116,11 +116,11 @@ static inline int kinc_g1_height(void) { } static inline void kinc_g1_set_texture_magnification_filter(kinc_g1_texture_filter_t filter) { - kinc_internal_g1_texture_filter_min = filter; + kinc_internal_g1_texture_filter_mag = filter; } static inline void kinc_g1_set_texture_minification_filter(kinc_g1_texture_filter_t filter) { - kinc_internal_g1_texture_filter_mag = filter; + kinc_internal_g1_texture_filter_min = filter; } static inline void kinc_g1_set_texture_mipmap_filter(kinc_g1_mipmap_filter_t filter) {