private the texture.c/.h, remove vestigial circle hash table from ctx
This commit is contained in:
parent
2a8f4b1bdc
commit
a4cb50687e
@ -44,10 +44,10 @@ set(TOWNENGINE_SOURCE_FILES
|
||||
src/audio.c src/audio.h
|
||||
src/util.c src/util.h
|
||||
src/rendering.c src/rendering.h
|
||||
src/textures.c src/textures.h
|
||||
src/input.c src/input.h
|
||||
src/text.c src/text.h
|
||||
src/camera.c src/camera.h
|
||||
src/textures/textures.c
|
||||
|
||||
${SYSTEM_SOURCE_FILES}
|
||||
)
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define CONTEXT_H
|
||||
|
||||
|
||||
#include "textures.h"
|
||||
#include "textures/internal_api.h"
|
||||
#include "input.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
@ -2,9 +2,10 @@
|
||||
#include "rendering.h"
|
||||
#include "input.h"
|
||||
#include "util.h"
|
||||
#include "textures.h"
|
||||
#include "game_api.h"
|
||||
#include "audio/internal_api.h"
|
||||
#include "textures/internal_api.h"
|
||||
#include "rendering/internal_api.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
@ -299,7 +300,6 @@ static bool initialize(void) {
|
||||
/* rendering */
|
||||
/* these are dynamic arrays and will be allocated lazily by stb_ds */
|
||||
ctx.render_queue_2d = NULL;
|
||||
ctx.circle_radius_hash = NULL;
|
||||
|
||||
textures_cache_init(&ctx.texture_cache, ctx.window);
|
||||
if (TTF_Init() < 0) {
|
||||
|
@ -2,8 +2,8 @@
|
||||
#include "rendering/sprites.h"
|
||||
#include "rendering/triangles.h"
|
||||
#include "rendering/circles.h"
|
||||
#include "textures/internal_api.h"
|
||||
#include "context.h"
|
||||
#include "textures.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <glad/glad.h>
|
||||
|
@ -20,9 +20,6 @@ typedef struct push_sprite_args {
|
||||
bool, flip_y )
|
||||
} t_push_sprite_args;
|
||||
|
||||
/* clears all render queues */
|
||||
void render_queue_clear(void);
|
||||
|
||||
/* pushes a sprite onto the sprite render queue */
|
||||
/* this is a simplified version of push_sprite_ex for the most common case. */
|
||||
/* it assumes you want no color modulation, no rotation, no flip */
|
||||
@ -68,7 +65,4 @@ void unfurl_triangle(const char *path,
|
||||
/* pushes a camera state to be used for all future unfurl_* commands */
|
||||
void set_camera(const t_camera *camera);
|
||||
|
||||
/* renders the background, then the primitives in all render queues */
|
||||
void render(void);
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,8 @@
|
||||
#ifndef RENDERING_INTERNAL_API_H
|
||||
#define RENDERING_INTERNAL_API_H
|
||||
#include "../textures.h"
|
||||
|
||||
#include "../util.h"
|
||||
#include "../textures/internal_api.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <glad/glad.h>
|
||||
@ -78,4 +79,10 @@ struct mesh_batch_item {
|
||||
struct mesh_batch value;
|
||||
};
|
||||
|
||||
/* renders the background, then the primitives in all render queues */
|
||||
void render(void);
|
||||
|
||||
/* clears all render queues */
|
||||
void render_queue_clear(void);
|
||||
|
||||
#endif
|
||||
|
@ -2,10 +2,10 @@
|
||||
#ifndef SPRITES_H
|
||||
#define SPRITES_H
|
||||
|
||||
#include "../textures.h"
|
||||
#include "../rendering.h"
|
||||
#include "../context.h"
|
||||
#include "../util.h"
|
||||
#include "../textures/internal_api.h"
|
||||
#include "quad_element_buffer.h"
|
||||
#include "internal_api.h"
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
#ifndef TRIANGLES_H
|
||||
#define TRIANGLES_H
|
||||
|
||||
#include "../textures.h"
|
||||
#include "../context.h"
|
||||
#include "internal_api.h"
|
||||
#include "../textures/internal_api.h"
|
||||
|
||||
#include <stb_ds.h>
|
||||
|
||||
|
@ -1,55 +0,0 @@
|
||||
#ifndef TEXTURES_H
|
||||
#define TEXTURES_H
|
||||
|
||||
#include "textures/internal_api.h"
|
||||
#include "textures/modes.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <glad/glad.h>
|
||||
|
||||
/* type safe structure for persistent texture handles */
|
||||
typedef struct { uint16_t id; } t_texture_key;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* binds atlas texture in opengl state */
|
||||
void textures_bind(const struct texture_cache *cache, t_texture_key key, GLenum target);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* returns the number of atlases in the cache */
|
||||
size_t textures_get_num_atlases(const struct texture_cache *cache);
|
||||
|
||||
#endif
|
@ -39,4 +39,48 @@ struct texture_cache {
|
||||
bool is_dirty; /* current atlas needs to be recreated */
|
||||
};
|
||||
|
||||
/* type safe structure for persistent texture handles */
|
||||
typedef struct { uint16_t id; } t_texture_key;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* binds atlas texture in opengl state */
|
||||
void textures_bind(const struct texture_cache *cache, t_texture_key key, GLenum target);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* returns the number of atlases in the cache */
|
||||
size_t textures_get_num_atlases(const struct texture_cache *cache);
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "textures/internal_api.h"
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
#include "textures.h"
|
||||
#include "internal_api.h"
|
||||
#include "../config.h"
|
||||
#include "../util.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
@ -396,7 +395,7 @@ void textures_update_atlas(struct texture_cache *cache) {
|
||||
/* EXPERIMANTAL: LIKELY TO BE REMOVED! */
|
||||
#ifdef __linux__ /* use rodata elf section for fast lookups of repeating textures */
|
||||
|
||||
#include "system/linux/elf.h"
|
||||
#include "../system/linux/elf.h"
|
||||
|
||||
static const char *rodata_start;
|
||||
static const char *rodata_stop;
|
Loading…
Reference in New Issue
Block a user