use t_frect for texture dimentions

This commit is contained in:
2024-07-30 18:09:21 +03:00
parent ea29f2c5f0
commit 0b215acbdf
5 changed files with 36 additions and 36 deletions

View File

@ -168,7 +168,7 @@ static void render_sprites(const struct primitive_2d primitives[],
NULL,
GL_STREAM_DRAW);
const t_rect dims =
const t_frect dims =
textures_get_dims(&ctx.texture_cache, primitives->sprite.texture_key);
/* vertex population over a mapped buffer */
@ -181,13 +181,13 @@ static void render_sprites(const struct primitive_2d primitives[],
const size_t cur = batch.mode == TEXTURE_MODE_GHOSTLY ? i : batch.size - i - 1;
const struct sprite_primitive sprite = primitives[cur].sprite;
const t_rect srcrect =
const t_frect srcrect =
textures_get_srcrect(&ctx.texture_cache, primitives[cur].sprite.texture_key);
const float wr = (float)srcrect.w / (float)dims.w;
const float hr = (float)srcrect.h / (float)dims.h;
const float xr = (float)srcrect.x / (float)dims.w;
const float yr = (float)srcrect.y / (float)dims.h;
const float wr = srcrect.w / dims.w;
const float hr = srcrect.h / dims.h;
const float xr = srcrect.x / dims.w;
const float yr = srcrect.y / dims.h;
t_fvec2 uv0 = { xr + wr * sprite.flip_x, yr + hr * sprite.flip_y };
t_fvec2 uv1 = { xr + wr * sprite.flip_x, yr + hr * !sprite.flip_y };

View File

@ -64,22 +64,22 @@ static void draw_uncolored_space_traingle_batch(struct mesh_batch *batch,
struct uncolored_space_triangle_payload *payload =
&((union uncolored_space_triangle *)batch->primitives)[i].payload;
t_rect srcrect = textures_get_srcrect(&ctx.texture_cache, texture_key);
t_rect dims = textures_get_dims(&ctx.texture_cache, texture_key);
t_frect srcrect = textures_get_srcrect(&ctx.texture_cache, texture_key);
t_frect dims = textures_get_dims(&ctx.texture_cache, texture_key);
/* TODO: fast path for uvs mapped directly on srcrect corners? */
const float wr = (float)srcrect.w / (float)dims.w;
const float hr = (float)srcrect.h / (float)dims.h;
const float xr = (float)srcrect.x / (float)dims.w;
const float yr = (float)srcrect.y / (float)dims.h;
const float wr = srcrect.w / dims.w;
const float hr = srcrect.h / dims.h;
const float xr = srcrect.x / dims.w;
const float yr = srcrect.y / dims.h;
payload->uv0.x = xr + ((float)payload->uv0.x / (float)srcrect.w) * wr;
payload->uv0.y = yr + ((float)payload->uv0.y / (float)srcrect.h) * hr;
payload->uv1.x = xr + ((float)payload->uv1.x / (float)srcrect.w) * wr;
payload->uv1.y = yr + ((float)payload->uv1.y / (float)srcrect.h) * hr;
payload->uv2.x = xr + ((float)payload->uv2.x / (float)srcrect.w) * wr;
payload->uv2.y = yr + ((float)payload->uv2.y / (float)srcrect.h) * hr;
payload->uv0.x = xr + ((float)payload->uv0.x / srcrect.w) * wr;
payload->uv0.y = yr + ((float)payload->uv0.y / srcrect.h) * hr;
payload->uv1.x = xr + ((float)payload->uv1.x / srcrect.w) * wr;
payload->uv1.y = yr + ((float)payload->uv1.y / srcrect.h) * hr;
payload->uv2.x = xr + ((float)payload->uv2.x / srcrect.w) * wr;
payload->uv2.y = yr + ((float)payload->uv2.y / srcrect.h) * hr;
}
textures_bind(&ctx.texture_cache, texture_key, GL_TEXTURE_2D);