Skip to content

Instantly share code, notes, and snippets.

@doug65536
Last active December 1, 2023 03:27
Show Gist options
  • Save doug65536/2c9f8a7b1b6b05349e7dbe833c878483 to your computer and use it in GitHub Desktop.
Save doug65536/2c9f8a7b1b6b05349e7dbe833c878483 to your computer and use it in GitHub Desktop.
uint32_t indexof_mipmap(int level)
{
int mask = ~((level - 1) >> 31);
uint32_t lvl0sz = texture->iw * texture->ih;
int kept = 2 * (level - 1) & mask;
uint32_t mul = (0x55555555 >> ((32 - kept) - 2)) & mask;
return (lvl0sz * mul) >> (kept & mask);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment