optimize texture sampling
This commit is contained in:
parent
736af38518
commit
b2682a2d40
3 changed files with 26 additions and 21 deletions
|
|
@ -810,8 +810,9 @@ void pxl8_3d_clear_zbuffer(pxl8_gfx* gfx) {
|
|||
i32 count = gfx->zbuffer_width * gfx->zbuffer_height;
|
||||
const f32 far_z = 1e30f;
|
||||
|
||||
f32* ptr = gfx->zbuffer;
|
||||
for (i32 i = 0; i < count; i++) {
|
||||
gfx->zbuffer[i] = far_z;
|
||||
ptr[i] = far_z;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1002,11 +1003,13 @@ static inline u32 pxl8_sample_texture(pxl8_gfx* gfx, u32 texture_id, f32 u, f32
|
|||
return 0;
|
||||
}
|
||||
|
||||
u = u - floorf(u);
|
||||
v = v - floorf(v);
|
||||
i32 tex_u = (i32)(u * entry->w);
|
||||
i32 tex_v = (i32)(v * entry->h);
|
||||
|
||||
i32 tx = (i32)(u * entry->w) % entry->w;
|
||||
i32 ty = (i32)(v * entry->h) % entry->h;
|
||||
i32 tx = tex_u % entry->w;
|
||||
if (tx < 0) tx += entry->w;
|
||||
i32 ty = tex_v % entry->h;
|
||||
if (ty < 0) ty += entry->h;
|
||||
|
||||
i32 atlas_x = entry->x + tx;
|
||||
i32 atlas_y = entry->y + ty;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue