townengine/src/textures.h

52 lines
1.9 KiB
C
Raw Normal View History

2024-07-08 00:44:20 +00:00
#ifndef TEXTURES_H
#define TEXTURES_H
#include "private/textures.h"
#include "util.h"
2024-07-08 00:44:20 +00:00
#include <SDL2/SDL.h>
#include <glad/glad.h>
2024-07-08 00:44:20 +00:00
/* type safe structure for persistent texture handles */
typedef struct { int id; } t_texture_key;
/* tests whether given key structure corresponds to any texture */
#define m_texture_key_is_valid(p_key) ((p_key).id != 0)
/* tests whether given key corresponds to atlas texture or a loner */
#define m_texture_is_atlas(p_key) ((p_key).id > 0)
2024-07-08 00:44:20 +00:00
void textures_cache_init(struct texture_cache *cache, SDL_Window *window);
void textures_cache_deinit(struct texture_cache *cache);
/* for debugging */
void textures_dump_atlases(struct texture_cache *cache);
/* loads an image if it isn't in the cache, otherwise a no-op. */
/* can be called from anywhere at any time after init, useful if you want to */
/* preload textures you know will definitely be used */
// void textures_load(struct texture_cache *cache, const char *path);
2024-07-08 00:44:20 +00:00
/* repacks the current texture atlas based on the texture cache if needed */
/* any previously returned srcrect results are invalidated after that */
/* call it every time before rendering */
void textures_update_atlas(struct texture_cache *cache);
2024-07-08 00:44:20 +00:00
/* returns a persistent handle to some texture in cache, loading it if needed */
/* check the result with m_texture_key_is_valid() */
t_texture_key textures_get_key(struct texture_cache *cache, const char *path);
2024-07-08 00:44:20 +00:00
/* returns a rect in a texture cache of the given key */
t_rect textures_get_srcrect(const struct texture_cache *cache, t_texture_key key);
2024-07-08 00:44:20 +00:00
/* returns a rect of dimensions of the whole texture (whole atlas) */
t_rect textures_get_dims(const struct texture_cache *cache, t_texture_key key);
2024-07-08 00:44:20 +00:00
/* binds atlas texture in opengl state */
void textures_bind(const struct texture_cache *cache, t_texture_key key, GLenum target);
2024-07-08 00:44:20 +00:00
/* returns the number of atlases in the cache */
size_t textures_get_num_atlases(const struct texture_cache *cache);
2024-07-08 00:44:20 +00:00
#endif