Getting tile data from overworld

This commit is contained in:
2025-03-03 00:57:36 -06:00
parent d81775054d
commit d53b5eab49
10 changed files with 176 additions and 23 deletions

View File

@ -4,13 +4,33 @@
// https://opensource.org/licenses/MIT
#define PACKED_U8_PER_UI 4
#define PACKED_U8_PER_UVEC4 PACKED_U8_PER_UI / 4
#define PACKED_U8_PER_UVEC4 PACKED_U8_PER_UI * 4
uint packedGetU8(uint position, uint data) {
return (data >> (position * 8u)) & 0xFFu;
}
uint packedGetU8FromVEC4(uint position, vec4 data) {
return packedGetU8(position, uint(data[position / 4u]));
}
int packedGetI8(uint position, uint data) {
int shift = int(position * 8u);
return int(data << (24 - shift)) >> 24;
}
uint packedArrayGetU8IndexFromUVEC4Array(uint u8ArrayIndex) {
// Given a uint8_t array is uploaded, this will return the index to get the
// appropriate uvec4 from a uvec4 array that will be at the right index.
return u8ArrayIndex / uint(PACKED_U8_PER_UVEC4);
}
uint packedArrayGetU8FromUVEC4ArrayValue(uint u8ArrayIndex, uvec4 data) {
// Given a value from a uint8_t array, this will return the value at the
// appropriate index. You must first get the uvec4 from the array using
// packedArrayGetU8IndexFromUVEC4Array.
uint subIndex = (u8ArrayIndex % uint(PACKED_U8_PER_UVEC4)) / uint(PACKED_U8_PER_UI);
uint shiftAmount = (u8ArrayIndex % uint(PACKED_U8_PER_UI)) * 8u;
uint value = (data[subIndex] >> shiftAmount) & 0xFFu;
return value;
}