typedef & PascalCase for ALL structs and enums
This commit is contained in:
@ -11,47 +11,47 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
struct texture {
|
||||
t_frect srcrect; /* position in atlas */
|
||||
typedef struct Texture {
|
||||
Rect srcrect; /* position in atlas */
|
||||
SDL_Surface *data; /* original image data */
|
||||
int atlas_index;
|
||||
gpu_texture loner_texture; /* stored directly for loners, == 0 means atlas_index should be used */
|
||||
gpu_texture repeating_texture; /* separately allocated texture, for loners == loner_texture */
|
||||
enum texture_mode mode;
|
||||
};
|
||||
GPUTexture loner_texture; /* stored directly for loners, == 0 means atlas_index should be used */
|
||||
GPUTexture repeating_texture; /* separately allocated Texture, for loners == loner_texture */
|
||||
enum TextureMode mode;
|
||||
} Texture;
|
||||
|
||||
|
||||
struct texture_cache_item {
|
||||
typedef struct TextureCacheItem {
|
||||
char *key;
|
||||
struct texture value;
|
||||
};
|
||||
struct Texture value;
|
||||
} TextureCacheItem;
|
||||
|
||||
|
||||
struct texture_cache {
|
||||
typedef struct TextureCache {
|
||||
SDL_Window *window; /* from context */
|
||||
|
||||
struct texture_cache_item *hash;
|
||||
struct TextureCacheItem *hash;
|
||||
|
||||
stbrp_node *node_buffer; /* used internally by stb_rect_pack */
|
||||
|
||||
SDL_Surface **atlas_surfaces;
|
||||
gpu_texture *atlas_textures; /* shared by atlas textures */
|
||||
GPUTexture *atlas_textures; /* shared by atlas textures */
|
||||
int atlas_index; /* atlas that is currently being built */
|
||||
|
||||
bool is_dirty; /* current atlas needs to be recreated */
|
||||
};
|
||||
} TextureCache;
|
||||
|
||||
/* type safe structure for persistent texture handles */
|
||||
typedef struct { uint16_t id; } t_texture_key;
|
||||
typedef struct TextureKey { uint16_t id; } TextureKey;
|
||||
|
||||
/* tests whether given key structure corresponds to any texture */
|
||||
#define m_texture_key_is_valid(p_key) ((p_key).id != (uint16_t)-1)
|
||||
|
||||
void textures_cache_init(struct texture_cache *cache, SDL_Window *window);
|
||||
void textures_cache_deinit(struct texture_cache *cache);
|
||||
void textures_cache_init(struct TextureCache *cache, SDL_Window *window);
|
||||
void textures_cache_deinit(struct TextureCache *cache);
|
||||
|
||||
/* for debugging */
|
||||
void textures_dump_atlases(struct texture_cache *cache);
|
||||
void textures_dump_atlases(struct TextureCache *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 */
|
||||
@ -61,30 +61,30 @@ void textures_dump_atlases(struct texture_cache *cache);
|
||||
/* 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);
|
||||
void textures_update_atlas(TextureCache *cache);
|
||||
|
||||
/* 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);
|
||||
TextureKey textures_get_key(TextureCache *cache, const char *path);
|
||||
|
||||
/* returns a rect in a texture cache of the given key */
|
||||
t_frect textures_get_srcrect(const struct texture_cache *cache, t_texture_key key);
|
||||
Rect textures_get_srcrect(const TextureCache *cache, TextureKey key);
|
||||
|
||||
/* returns a rect of dimensions of the whole texture (whole atlas) */
|
||||
t_frect textures_get_dims(const struct texture_cache *cache, t_texture_key key);
|
||||
Rect textures_get_dims(const TextureCache *cache, TextureKey key);
|
||||
|
||||
/* returns an identifier that is equal for all textures placed in the same atlas */
|
||||
int32_t textures_get_atlas_id(const struct texture_cache *cache, t_texture_key key);
|
||||
int32_t textures_get_atlas_id(const TextureCache *cache, TextureKey key);
|
||||
|
||||
void textures_bind(const struct texture_cache *cache, t_texture_key key);
|
||||
void textures_bind(const TextureCache *cache, TextureKey key);
|
||||
|
||||
void textures_bind_repeating(const struct texture_cache *cache, t_texture_key key);
|
||||
void textures_bind_repeating(const TextureCache *cache, TextureKey key);
|
||||
|
||||
/* returns helpful information about contents of alpha channel in given texture */
|
||||
enum texture_mode textures_get_mode(const struct texture_cache *cache, t_texture_key key);
|
||||
TextureMode textures_get_mode(const TextureCache *cache, TextureKey key);
|
||||
|
||||
/* returns the number of atlases in the cache */
|
||||
size_t textures_get_num_atlases(const struct texture_cache *cache);
|
||||
size_t textures_get_num_atlases(const TextureCache *cache);
|
||||
|
||||
/* TODO: should recieve texture_cache, get_key optimization cache should be cleared some other way */
|
||||
void textures_reset_state(void);
|
||||
|
Reference in New Issue
Block a user