rendering.c: batching for sprites (blended vs unblended), separation of rendering submodules; textures.c: textures_get_atlas_id()
This commit is contained in:
@@ -307,12 +307,12 @@ static t_texture_key textures_load(struct texture_cache *cache, const char *path
|
||||
upload_texture_from_surface(new_texture.loner_texture, surface);
|
||||
new_texture.srcrect = (t_rect) { .w = surface->w, .h = surface->h };
|
||||
shput(cache->hash, path, new_texture);
|
||||
return (t_texture_key){ (int)shgeti(cache->hash, path) };
|
||||
return (t_texture_key){ shgeti(cache->hash, path) };
|
||||
} else {
|
||||
new_texture.atlas_index = cache->atlas_index;
|
||||
shput(cache->hash, path, new_texture);
|
||||
cache->is_dirty = true;
|
||||
return (t_texture_key){ (int)shgeti(cache->hash, path) };
|
||||
return (t_texture_key){ shgeti(cache->hash, path) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ void textures_update_atlas(struct texture_cache *cache) {
|
||||
recreate_current_atlas_texture(cache);
|
||||
|
||||
cache->is_dirty = false;
|
||||
|
||||
|
||||
arrfree(rects);
|
||||
}
|
||||
|
||||
@@ -371,24 +371,27 @@ extern const char stop_rodata_heuristic[];
|
||||
asm(".set start_rodata_address, .rodata");
|
||||
asm(".set stop_rodata_heuristic, .data"); /* there's nothing in default linker script to know the size of .rodata */
|
||||
|
||||
/* TODO: it might be better to contruct a new table that hashes pointers, not strings, to texture keys */
|
||||
/* this way every used texture will benefit, no matter the order of commission */
|
||||
t_texture_key textures_get_key(struct texture_cache *cache, const char *path) {
|
||||
static const char *last_path = NULL;
|
||||
static t_texture_key last_texture;
|
||||
|
||||
/* fast path */
|
||||
if (path == last_path && path >= start_rodata_address && path < stop_rodata_heuristic)
|
||||
if (path == last_path)
|
||||
return last_texture;
|
||||
|
||||
/* hash tables are assumed to be stable, so we just return indices */
|
||||
int texture = (int)shgeti(cache->hash, path);
|
||||
ptrdiff_t texture = shgeti(cache->hash, path);
|
||||
|
||||
/* load it if it isn't */
|
||||
if (texture == -1) {
|
||||
last_texture = textures_load(cache, path);
|
||||
} else
|
||||
last_texture = (t_texture_key){ texture };
|
||||
last_texture = (t_texture_key){ (uint16_t)texture };
|
||||
|
||||
last_path = path;
|
||||
if (path >= start_rodata_address && path < stop_rodata_heuristic)
|
||||
last_path = path;
|
||||
|
||||
return last_texture;
|
||||
}
|
||||
@@ -402,11 +405,24 @@ t_texture_key textures_get_key(struct texture_cache *cache, const char *path) {
|
||||
if (texture == -1) {
|
||||
return textures_load(cache, path);
|
||||
} else
|
||||
return (t_texture_key){ (int)texture };
|
||||
return (t_texture_key){ (uint16_t)texture };
|
||||
}
|
||||
|
||||
#endif /* generic implementation of textures_get_key() */
|
||||
|
||||
int32_t textures_get_atlas_id(const struct texture_cache *cache, t_texture_key key) {
|
||||
if (m_texture_key_is_valid(key)) {
|
||||
if (cache->hash[key.id].value.loner_texture != 0)
|
||||
return -cache->hash[key.id].value.loner_texture;
|
||||
else
|
||||
return cache->hash[key.id].value.atlas_index;
|
||||
} else {
|
||||
CRY("Texture lookup failed.",
|
||||
"Tried to get atlas id that isn't loaded.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
t_rect textures_get_srcrect(const struct texture_cache *cache, t_texture_key key) {
|
||||
if (m_texture_key_is_valid(key)) {
|
||||
return cache->hash[key.id].value.srcrect;
|
||||
|
Reference in New Issue
Block a user