From 66678a27cf697e80c89dcf730e84eba9cb3b96df Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Mon, 23 Sep 2024 09:34:27 +0300 Subject: [PATCH] twn_textures.c: add debug hints about unportable texture dimensions --- include/twn_util.h | 5 +++++ src/twn_textures.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/include/twn_util.h b/include/twn_util.h index eb3ff4a..57cc577 100644 --- a/include/twn_util.h +++ b/include/twn_util.h @@ -170,4 +170,9 @@ static inline t_fvec2 fast_cossine(float a) { }; } +static inline bool is_power_of_two(int x) +{ + return (x != 0) && ((x & (x - 1)) == 0); +} + #endif diff --git a/src/twn_textures.c b/src/twn_textures.c index 48fbe5c..270bf77 100644 --- a/src/twn_textures.c +++ b/src/twn_textures.c @@ -1,6 +1,7 @@ #include "twn_textures_c.h" #include "twn_config.h" #include "twn_util.h" +#include "twn_engine_context_c.h" #include #include @@ -342,6 +343,12 @@ static t_texture_key textures_load(struct texture_cache *cache, const char *path /* it's a "loner texture," it doesn't fit in an atlas so it's not in one */ if (surface->w >= TEXTURE_ATLAS_SIZE || surface->h >= TEXTURE_ATLAS_SIZE) { + if (ctx.game.debug) { + if (surface->w > TEXTURE_ATLAS_SIZE || surface->h > TEXTURE_ATLAS_SIZE) + log_warn("Unportable texture dimensions for %s, use 2048x2048 at max", path); + if (!is_power_of_two(surface->w) || !is_power_of_two(surface->h)) + log_warn("Unportable texture dimensions for %s, should be powers of 2", path); + } new_texture.loner_texture = create_gpu_texture(TEXTURE_FILTER_NEAREAST, true); upload_texture_from_surface(new_texture.loner_texture, surface); new_texture.srcrect = (t_frect) { .w = (float)surface->w, .h = (float)surface->h };