all repos — mgba @ 12e681392db2b8218eb28806960d501a9e98092f

mGBA Game Boy Advance Emulator

Fragment shader now no longer requires extensions
Jeffrey Pfau jeffrey@endrift.com
Wed, 08 May 2013 15:19:54 -0700
commit

12e681392db2b8218eb28806960d501a9e98092f

parent

8047ce11d006ba4a51d055ce78f03807f66e5329

1 files changed, 48 insertions(+), 44 deletions(-)

jump to
M src/gba/renderers/video-glsl.csrc/gba/renderers/video-glsl.c

@@ -12,7 +12,6 @@ 1, 0

}; static const GLchar* _fragmentShader = - "#extension GL_EXT_gpu_shader4 : enable\n" "varying float x;\n" "uniform float y;\n" "uniform sampler2D vram;\n"

@@ -31,57 +30,62 @@ "uniform int bg3hofs;\n"

"uniform int bg3vofs;\n" "#define VRAM_INDEX(i) (vec2(mod(float(i + 1), 512.0) / 512.0 - 1.0 / 1024.0, (160.0 + floor(float(i) / 512.0)) / 255.0))\n" "#define DESERIALIZE(vec) int(dot(vec4(63488.0, 1984.0, 62.0, 1.0), vec))\n" + "#define IMOD(a, b) int(mod(float(a), float(b)))\n" + "#define BIT_CHECK(a, b) (IMOD(a / b, 2) == 1)\n" "vec4 backgroundMode0(int bgcnt, int hofs, int vofs) {\n" - " int charBase = ((bgcnt / 4) & 3) * 8192;\n" - " int screenBase = ((bgcnt / 256) & 0x1F) * 1024;\n" - " int size = bgcnt >> 14;\n" - " int localX = hofs + int(x);\n" - " int localY = vofs + int(y);\n" - " int xBase = localX & 0xF8;\n" - " int yBase = localY & 0xF8;\n" - " if (size == 1) {\n" - " xBase += (localX & 0x100) << 5;\n" - " } else if (size == 2) {\n" - " yBase += localY & 0x100;\n" - " } else if (size == 3) {\n" - " xBase += (localX & 0x100) << 5;\n" - " yBase += (localY & 0x100) << 1;\n" - " }\n" - " screenBase = screenBase + (xBase / 8) + (yBase * 4);\n" - " int mapData = DESERIALIZE(texture2D(vram, VRAM_INDEX(screenBase)));\n" - " charBase = charBase + ((mapData & 0x3FF) * 16) + (localX & 0x4) / 4 + (localY & 0x7) * 2;\n" - " int tileData = DESERIALIZE(texture2D(vram, VRAM_INDEX(charBase)));\n" - " tileData = ((tileData >> ((localX & 3) * 4)) & 0xF);\n" - " if (tileData == 0) {\n" - " return vec4(0, 0, 0, 0);\n" + " int charBase = IMOD(bgcnt / 4, 4) * 8192;\n" + " int screenBase = IMOD(bgcnt / 256, 32) * 1024;\n" + " int size = IMOD(bgcnt/ 0x4000, 4);\n" + " int localX = hofs + int(x);\n" + " int localY = vofs + int(y);\n" + " int xBase = IMOD(localX, 256);\n" + " int yBase = IMOD(localY, 256);\n" + " xBase -= IMOD(localX, 8);\n" + " yBase -= IMOD(localY, 8);\n" + " if (size == 1) {\n" + " xBase += IMOD(localX / 0x100, 2) * 0x2000;\n" + " } else if (size == 2) {\n" + " yBase += IMOD(localY / 0x100, 2) * 0x100;\n" + " } else if (size == 3) {\n" + " xBase += IMOD(localX / 0x100, 2) * 0x2000;\n" + " yBase += IMOD(localY / 0x100, 2) * 0x200;\n" " }\n" - " return texture2D(vram, vec2(float(tileData + (mapData / 4096) * 16) / 512.0, y / 256.0));\n" + " screenBase = screenBase + (xBase / 8) + (yBase * 4);\n" + " int mapData = DESERIALIZE(texture2D(vram, VRAM_INDEX(screenBase)));\n" + " charBase = charBase + (IMOD(mapData, 0x400) * 16) + IMOD(localX, 8) / 4 + IMOD(localY, 8) * 2;\n" + " int tileData = DESERIALIZE(texture2D(vram, VRAM_INDEX(charBase)));\n" + " tileData /= int(pow(2.0, mod(float(localX), 4.0) * 4.0));\n" + " tileData = IMOD(tileData, 0x10);\n" + " if (tileData == 0) {\n" + " return vec4(0, 0, 0, 0);\n" + " }\n" + " return texture2D(vram, vec2(float(tileData + (mapData / 4096) * 16) / 512.0, y / 256.0));\n" "}\n" "void runPriority(int priority, inout vec4 color) {\n" - " if (color.a > 0.0) {\n" - " return;\n" - " }\n" - " if ((dispcnt & 0x100) != 0 && (bg0cnt & 0x3) == priority) {\n" - " color = backgroundMode0(bg0cnt, bg0hofs, bg0vofs);\n" - " }\n" - " if (color.a > 0.0) {\n" - " return;\n" - " }\n" - " if ((dispcnt & 0x200) != 0 && (bg1cnt & 0x3) == priority) {\n" - " color = backgroundMode0(bg1cnt, bg1hofs, bg1vofs);\n" - " }\n" - " if (color.a > 0.0) {\n" - " return;\n" - " }\n" - " if ((dispcnt & 0x400) != 0 && (bg2cnt & 0x3) == priority) {\n" - " color = backgroundMode0(bg2cnt, bg2hofs, bg2vofs);\n" - " }\n" - " if (color.a > 0.0) {\n" + " if (color.a > 0.0) {\n" + " return;\n" + " }\n" + " if (BIT_CHECK(dispcnt, 0x100) && IMOD(bg0cnt, 4) == priority) {\n" + " color = backgroundMode0(bg0cnt, bg0hofs, bg0vofs);\n" + " }\n" + " if (color.a > 0.0) {\n" + " return;\n" + " }\n" + " if (BIT_CHECK(dispcnt, 0x200) && IMOD(bg1cnt, 4) == priority) {\n" + " color = backgroundMode0(bg1cnt, bg1hofs, bg1vofs);\n" + " }\n" + " if (color.a > 0.0) {\n" + " return;\n" + " }\n" + " if (BIT_CHECK(dispcnt, 0x400) && IMOD(bg2cnt, 4) == priority) {\n" + " color = backgroundMode0(bg2cnt, bg2hofs, bg2vofs);\n" + " }\n" + " if (color.a > 0.0) {\n" " return;\n" " }\n" - " if ((dispcnt & 0x800) != 0 && (bg3cnt & 0x3) == priority) {\n" + " if (BIT_CHECK(dispcnt, 0x800) && IMOD(bg3cnt, 4) == priority) {\n" " color = backgroundMode0(bg3cnt, bg3hofs, bg3vofs);\n" " }\n" "}\n"