branchless sprite blit and zbuffer updates
This commit is contained in:
parent
349fa8bc81
commit
a33d4c0068
2 changed files with 137 additions and 41 deletions
|
|
@ -9,10 +9,29 @@ void pxl8_blit_hicolor(u16* fb, u32 fb_width, const u16* sprite, u32 atlas_width
|
|||
u16* dest_row = dest_base + row * fb_width;
|
||||
const u16* src_row = src_base + row * atlas_width;
|
||||
|
||||
for (u32 col = 0; col < w; col++) {
|
||||
if (src_row[col] != 0) {
|
||||
dest_row[col] = src_row[col];
|
||||
u32 col = 0;
|
||||
u32 count2 = w / 2;
|
||||
for (u32 i = 0; i < count2; i++) {
|
||||
u32 pixels = ((const u32*)src_row)[i];
|
||||
if (pixels == 0) {
|
||||
col += 2;
|
||||
continue;
|
||||
}
|
||||
u16 s0 = (u16)(pixels);
|
||||
u16 s1 = (u16)(pixels >> 16);
|
||||
u16 d0 = dest_row[col];
|
||||
u16 d1 = dest_row[col + 1];
|
||||
u16 m0 = (u16)(-(s0 != 0));
|
||||
u16 m1 = (u16)(-(s1 != 0));
|
||||
dest_row[col] = (s0 & m0) | (d0 & ~m0);
|
||||
dest_row[col + 1] = (s1 & m1) | (d1 & ~m1);
|
||||
col += 2;
|
||||
}
|
||||
if (w & 1) {
|
||||
u16 s = src_row[col];
|
||||
u16 d = dest_row[col];
|
||||
u16 m = (u16)(-(s != 0));
|
||||
dest_row[col] = (s & m) | (d & ~m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,10 +45,37 @@ void pxl8_blit_indexed(u8* fb, u32 fb_width, const u8* sprite, u32 atlas_width,
|
|||
u8* dest_row = dest_base + row * fb_width;
|
||||
const u8* src_row = src_base + row * atlas_width;
|
||||
|
||||
for (u32 col = 0; col < w; col++) {
|
||||
if (src_row[col] != 0) {
|
||||
dest_row[col] = src_row[col];
|
||||
u32 col = 0;
|
||||
u32 count4 = w / 4;
|
||||
for (u32 i = 0; i < count4; i++) {
|
||||
u32 pixels = ((const u32*)src_row)[i];
|
||||
if (pixels == 0) {
|
||||
col += 4;
|
||||
continue;
|
||||
}
|
||||
u8 s0 = (u8)(pixels);
|
||||
u8 s1 = (u8)(pixels >> 8);
|
||||
u8 s2 = (u8)(pixels >> 16);
|
||||
u8 s3 = (u8)(pixels >> 24);
|
||||
u8 d0 = dest_row[col];
|
||||
u8 d1 = dest_row[col + 1];
|
||||
u8 d2 = dest_row[col + 2];
|
||||
u8 d3 = dest_row[col + 3];
|
||||
u8 m0 = (u8)(-(s0 != 0));
|
||||
u8 m1 = (u8)(-(s1 != 0));
|
||||
u8 m2 = (u8)(-(s2 != 0));
|
||||
u8 m3 = (u8)(-(s3 != 0));
|
||||
dest_row[col] = (s0 & m0) | (d0 & ~m0);
|
||||
dest_row[col + 1] = (s1 & m1) | (d1 & ~m1);
|
||||
dest_row[col + 2] = (s2 & m2) | (d2 & ~m2);
|
||||
dest_row[col + 3] = (s3 & m3) | (d3 & ~m3);
|
||||
col += 4;
|
||||
}
|
||||
for (; col < w; col++) {
|
||||
u8 s = src_row[col];
|
||||
u8 d = dest_row[col];
|
||||
u8 m = (u8)(-(s != 0));
|
||||
dest_row[col] = (s & m) | (d & ~m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue