GBA Video: Don't repeat yourself

This commit is contained in:
Vicki Pfau 2023-04-18 02:18:49 -07:00
parent 2c84689345
commit 133ed11cab
1 changed files with 29 additions and 66 deletions

View File

@ -233,6 +233,29 @@ static const char* const _interpolate =
" aff[2] = transform[start + 2].zw;\n"
" mat[3] = transform[start + 3].xy;\n"
" aff[3] = transform[start + 3].zw;\n"
"}\n"
"ivec2 affineInterpolate() {\n"
" ivec2 mat[4];\n"
" ivec2 offset[4];\n"
" vec2 incoord = texCoord;\n"
" if (mosaic.x > 1) {\n"
" incoord.x = float(MOSAIC(incoord.x, mosaic.x));\n"
" }\n"
" if (mosaic.y > 1) {\n"
" incoord.y = float(MOSAIC(incoord.y, mosaic.y));\n"
" }\n"
" loadAffine(int(incoord.y), mat, offset);\n"
" float y = fract(incoord.y);\n"
" float start = 2. / 3.;\n"
" if (int(incoord.y) - range.x < 4) {\n"
" y = incoord.y - float(range.x);\n"
" start -= 1.;\n"
" }\n"
" float lin = start + y / 3.;\n"
" vec2 mixedTransform = interpolate(mat, lin);\n"
" vec2 mixedOffset = interpolate(offset, lin);\n"
" return ivec2(mixedTransform * incoord.x + mixedOffset);\n"
"}\n";
static const char* const _renderMode2 =
@ -250,8 +273,7 @@ static const char* const _renderMode2 =
"OUT(0) out vec4 color;\n"
"int fetchTile(ivec2 coord);\n"
"vec2 interpolate(ivec2 arr[4], float x);\n"
"void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"
"ivec2 affineInterpolate();\n"
"int renderTile(ivec2 coord) {\n"
" int map = (coord.x >> 11) + (((coord.y >> 7) & 0x7F0) << size);\n"
@ -278,26 +300,7 @@ static const char* const _renderMode2 =
"}\n"
"void main() {\n"
" ivec2 mat[4];\n"
" ivec2 offset[4];\n"
" vec2 incoord = texCoord;\n"
" if (mosaic.x > 1) {\n"
" incoord.x = float(MOSAIC(incoord.x, mosaic.x));\n"
" }\n"
" if (mosaic.y > 1) {\n"
" incoord.y = float(MOSAIC(incoord.y, mosaic.y));\n"
" }\n"
" loadAffine(int(incoord.y), mat, offset);\n"
" float y = fract(incoord.y);\n"
" float start = 2. / 3.;\n"
" if (int(incoord.y) - range.x < 4) {\n"
" y = incoord.y - float(range.x);\n"
" start -= 1.;\n"
" }\n"
" float lin = start + y / 3.;\n"
" vec2 mixedTransform = interpolate(mat, lin);\n"
" vec2 mixedOffset = interpolate(offset, lin);\n"
" int paletteEntry = fetchTile(ivec2(mixedTransform * incoord.x + mixedOffset));\n"
" int paletteEntry = fetchTile(affineInterpolate());\n"
" color = texelFetch(palette, ivec2(paletteEntry, int(texCoord.y)), 0);\n"
"}";
@ -325,30 +328,10 @@ static const char* const _renderMode35 =
"uniform ivec2 mosaic;\n"
"OUT(0) out vec4 color;\n"
"vec2 interpolate(ivec2 arr[4], float x);\n"
"void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"
"ivec2 affineInterpolate();\n"
"void main() {\n"
" ivec2 mat[4];\n"
" ivec2 offset[4];\n"
" vec2 incoord = texCoord;\n"
" if (mosaic.x > 1) {\n"
" incoord.x = float(MOSAIC(incoord.x, mosaic.x));\n"
" }\n"
" if (mosaic.y > 1) {\n"
" incoord.y = float(MOSAIC(incoord.y, mosaic.y));\n"
" }\n"
" loadAffine(int(incoord.y), mat, offset);\n"
" float y = fract(incoord.y);\n"
" float start = 2. / 3.;\n"
" if (int(incoord.y) - range.x < 4) {\n"
" y = incoord.y - float(range.x);\n"
" start -= 1.;\n"
" }\n"
" float lin = start + y / 3.;\n"
" vec2 mixedTransform = interpolate(mat, lin);\n"
" vec2 mixedOffset = interpolate(offset, lin);\n"
" ivec2 coord = ivec2(mixedTransform * incoord.x + mixedOffset);\n"
" ivec2 coord = affineInterpolate();\n"
" if (coord.x < 0 || coord.x >= (size.x << 8)) {\n"
" discard;\n"
" }\n"
@ -386,30 +369,10 @@ static const char* const _renderMode4 =
"uniform ivec2 mosaic;\n"
"OUT(0) out vec4 color;\n"
"vec2 interpolate(ivec2 arr[4], float x);\n"
"void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"
"ivec2 affineInterpolate();\n"
"void main() {\n"
" ivec2 mat[4];\n"
" ivec2 offset[4];\n"
" vec2 incoord = texCoord;\n"
" if (mosaic.x > 1) {\n"
" incoord.x = float(MOSAIC(incoord.x, mosaic.x));\n"
" }\n"
" if (mosaic.y > 1) {\n"
" incoord.y = float(MOSAIC(incoord.y, mosaic.y));\n"
" }\n"
" loadAffine(int(incoord.y), mat, offset);\n"
" float y = fract(incoord.y);\n"
" float start = 2. / 3.;\n"
" if (int(incoord.y) - range.x < 4) {\n"
" y = incoord.y - float(range.x);\n"
" start -= 1.;\n"
" }\n"
" float lin = start + y / 3.;\n"
" vec2 mixedTransform = interpolate(mat, lin);\n"
" vec2 mixedOffset = interpolate(offset, lin);\n"
" ivec2 coord = ivec2(mixedTransform * incoord.x + mixedOffset);\n"
" ivec2 coord = affineInterpolate();\n"
" if (coord.x < 0 || coord.x >= (size.x << 8)) {\n"
" discard;\n"
" }\n"