fix that using mipmap filtering did not generate the necessary mipmaps

Sat, 02 Aug 2025 15:45:43 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 02 Aug 2025 15:45:43 +0200
changeset 243
b06168253818
parent 242
6eeb987f1681
child 244
ceab8a9f0366

fix that using mipmap filtering did not generate the necessary mipmaps

src/ascension/texture.h file | annotate | diff | comparison | revisions
src/texture.c file | annotate | diff | comparison | revisions
--- a/src/ascension/texture.h	Sat Aug 02 15:19:06 2025 +0200
+++ b/src/ascension/texture.h	Sat Aug 02 15:45:43 2025 +0200
@@ -42,6 +42,7 @@
     unsigned width;
     unsigned height;
     unsigned refcount;
+    bool use_mipmaps;
     // TODO: add support for texture atlas - idea: rects are defined in AscTexture and can be indexed
 } AscTexture;
 
--- a/src/texture.c	Sat Aug 02 15:19:06 2025 +0200
+++ b/src/texture.c	Sat Aug 02 15:45:43 2025 +0200
@@ -90,6 +90,10 @@
                  0, format,
                  GL_UNSIGNED_BYTE, surface->pixels);
     asc_error_catch_gl("Writing texture data");
+    if (tex->use_mipmaps) {
+        glGenerateTextureMipmap(tex->tex_id);
+        asc_error_catch_gl("Generating texture mipmaps");
+    }
 }
 
 void asc_texture_from_file(AscTexture *tex, const char *name) {
@@ -137,6 +141,7 @@
         memset(&tex[i], 0, sizeof(AscTexture));
         tex[i].tex_id = textures[i];
         tex[i].target = texture_targets[target];
+        tex[i].use_mipmaps = min_filter > 1;
         glBindTexture(tex[i].target, tex[i].tex_id);
         glTexParameteri(tex[i].target, GL_TEXTURE_MIN_FILTER,
                         texture_filters[min_filter]);

mercurial