full removal of SDL_Renderer usage, working spatial triangle rendering, temporary(?) regression of HDPI

This commit is contained in:
2024-07-12 21:10:25 +03:00
parent 34cf504b2b
commit 55d85399e9
12 changed files with 348 additions and 224 deletions

View File

@@ -1,46 +1,10 @@
#ifndef TEXTURES_H
#define TEXTURES_H
#include "private/textures.h"
#include <SDL2/SDL.h>
#include <stb_rect_pack.h>
#include <stdbool.h>
struct texture {
SDL_Rect srcrect; /* position in atlas */
SDL_Surface *data; /* original image data */
SDL_Texture *loner_data; /* loner textures store their data directly */
int atlas_index; /* which atlas the texture is in */
int8_t layer;
};
struct texture_cache_item {
char *key;
struct texture value;
};
/* use the public API to create and manipulate instances of this structure */
struct texture_cache {
/* from context */
SDL_Window *window;
SDL_Renderer *renderer;
struct texture_cache_item *hash;
struct texture_cache_item *loner_hash;
stbrp_node *node_buffer; /* used internally by stb_rect_pack */
SDL_Surface **atlas_surfaces;
SDL_Texture **atlas_textures;
int atlas_index;
bool is_dirty; /* current atlas needs to be recreated */
};
#include <glad/glad.h>
void textures_cache_init(struct texture_cache *cache, SDL_Window *window);
void textures_cache_deinit(struct texture_cache *cache);
@@ -64,15 +28,12 @@ SDL_Rect textures_get_srcrect(struct texture_cache *cache, const char *path);
/* if the texture is not found, returns INT_MIN */
int textures_get_atlas_index(struct texture_cache *cache, const char *path);
/* returns a pointer to the atlas at `index` */
/* if the index is out of bounds, returns NULL. */
/* you can get the index via texture_get_atlas_index */
SDL_Texture *textures_get_atlas(struct texture_cache *cache, int index);
/* binds atlas texture in opengl state */
void textures_bind_atlas(struct texture_cache *cache, int index, GLenum target);
SDL_Texture *textures_get_loner(struct texture_cache *cache, const char *path);
void textures_bind_loner(struct texture_cache *cache, const char *path, GLenum target);
/* returns the number of atlases in the cache */
size_t textures_get_num_atlases(struct texture_cache *cache);
#endif