From 047b15c2102d40d2cfe561b333f13b7f28082ae5 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Wed, 6 Mar 2024 01:06:17 -0600 Subject: [PATCH 1/2] fix 2d shaders on OSX --- Src/Graphics/Shaders2D.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Src/Graphics/Shaders2D.h b/Src/Graphics/Shaders2D.h index f0fc3f4..9f012d7 100644 --- a/Src/Graphics/Shaders2D.h +++ b/Src/Graphics/Shaders2D.h @@ -188,12 +188,12 @@ static const char s_fragmentShaderTileGen[] = R"glsl( } // register data - bool LineScrollMode (int layerNum) { return (regs[0x60/4 + layerNum] & 0x8000) != 0; } - int GetHorizontalScroll(int layerNum) { return int(regs[0x60 / 4 + layerNum] &0x3FFu); } + bool LineScrollMode (int layerNum) { return (regs[0x60/4 + layerNum] & 0x8000u) != 0; } + int GetHorizontalScroll(int layerNum) { return int(regs[0x60/4 + layerNum] & 0x3FFu); } int GetVerticalScroll (int layerNum) { return int((regs[0x60/4 + layerNum] >> 16) & 0x1FFu); } int LayerPriority () { return int((regs[0x20/4] >> 8) & 0xFu); } - bool LayerIs4Bit (int layerNum) { return (regs[0x20/4] & (1 << (12 + layerNum))) != 0; } - bool LayerEnabled (int layerNum) { return (regs[0x60/4 + layerNum] & 0x80000000) != 0; } + bool LayerIs4Bit (int layerNum) { return (regs[0x20/4] & uint(1 << (12 + layerNum))) != 0; } + bool LayerEnabled (int layerNum) { return (regs[0x60/4 + layerNum] & 0x80000000u) != 0; } bool LayerSelected (int layerNum) { return (LayerPriority() & (1 << layerNum)) == 0; } float Int8ToFloat(uint c) @@ -225,11 +225,12 @@ static const char s_fragmentShaderTileGen[] = R"glsl( uint alpha = (colour>>15); // top bit is alpha. 1 means clear, 0 opaque alpha = ~alpha; // invert alpha = alpha & 0x1u; // mask bit + const uint mask = 0x1F; vec4 c; - c.r = float((colour >> 0 ) & 0x1F) / 31.0; - c.g = float((colour >> 5 ) & 0x1F) / 31.0; - c.b = float((colour >> 10) & 0x1F) / 31.0; + c.r = float((colour >> 0 ) & mask) / 31.0; + c.g = float((colour >> 5 ) & mask) / 31.0; + c.b = float((colour >> 10) & mask) / 31.0; c.a = float(alpha) / 1.0; c.rgb *= c.a; // multiply by alpha value, this will push transparent to black, no branch needed From 93f622ee25a221ffb6948c06e096114cc7932ad7 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Wed, 6 Mar 2024 01:07:56 -0600 Subject: [PATCH 2/2] cleanup code format --- Src/Graphics/Shaders2D.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Src/Graphics/Shaders2D.h b/Src/Graphics/Shaders2D.h index 9f012d7..329db61 100644 --- a/Src/Graphics/Shaders2D.h +++ b/Src/Graphics/Shaders2D.h @@ -189,12 +189,12 @@ static const char s_fragmentShaderTileGen[] = R"glsl( // register data bool LineScrollMode (int layerNum) { return (regs[0x60/4 + layerNum] & 0x8000u) != 0; } - int GetHorizontalScroll(int layerNum) { return int(regs[0x60/4 + layerNum] & 0x3FFu); } - int GetVerticalScroll (int layerNum) { return int((regs[0x60/4 + layerNum] >> 16) & 0x1FFu); } - int LayerPriority () { return int((regs[0x20/4] >> 8) & 0xFu); } - bool LayerIs4Bit (int layerNum) { return (regs[0x20/4] & uint(1 << (12 + layerNum))) != 0; } - bool LayerEnabled (int layerNum) { return (regs[0x60/4 + layerNum] & 0x80000000u) != 0; } - bool LayerSelected (int layerNum) { return (LayerPriority() & (1 << layerNum)) == 0; } + int GetHorizontalScroll (int layerNum) { return int(regs[0x60/4 + layerNum] & 0x3FFu); } + int GetVerticalScroll (int layerNum) { return int((regs[0x60/4 + layerNum] >> 16) & 0x1FFu); } + int LayerPriority () { return int((regs[0x20/4] >> 8) & 0xFu); } + bool LayerIs4Bit (int layerNum) { return (regs[0x20/4] & uint(1 << (12 + layerNum))) != 0; } + bool LayerEnabled (int layerNum) { return (regs[0x60/4 + layerNum] & 0x80000000u) != 0; } + bool LayerSelected (int layerNum) { return (LayerPriority() & (1 << layerNum)) == 0; } float Int8ToFloat(uint c) {