--- a/src/ascension/texture.h Sun May 11 14:51:00 2025 +0200 +++ b/src/ascension/texture.h Mon May 12 20:51:57 2025 +0200 @@ -28,6 +28,8 @@ #ifndef ASCENSION_TEXTURE_H #define ASCENSION_TEXTURE_H +#include "datatypes.h" + #include <SDL2/SDL_surface.h> typedef struct AscTexture AscTexture; @@ -38,6 +40,7 @@ unsigned width; unsigned height; unsigned refcount; + // TODO: add support for texture atlas - idea: rects are defined in AscTexture and can be indexed }; enum asc_texture_target { @@ -59,6 +62,11 @@ ASC_TEXTURE_MAG_FILTER_LINEAR }; +enum asc_texture_scale_mode { + ASC_TEXTURE_SCALE_FIT, + ASC_TEXTURE_SCALE_REPEAT +}; + __attribute__((__nonnull__)) void asc_texture_init( AscTexture *tex, @@ -88,4 +96,15 @@ __attribute__((__nonnull__)) void asc_texture_from_file(AscTexture *tex, const char *name); + +/** + * Calculates UV scaling factors depending on texture and surface dimensions. + * + * @param tex the texture + * @param surface_dimension the dimensions of the surface the texture is applied to + * @param factors additional scaling factors + * @return the calculated UV scaling factors + */ +asc_vec2f asc_texture_calculate_uv_scale(const AscTexture *tex, asc_vec2u surface_dimension, asc_vec2f factors); + #endif //ASCENSION_TEXTURE_H