mirror of https://github.com/mgba-emu/mgba.git
GBA Video: Don't repeat yourself
This commit is contained in:
parent
2c84689345
commit
133ed11cab
|
@ -233,6 +233,29 @@ static const char* const _interpolate =
|
||||||
" aff[2] = transform[start + 2].zw;\n"
|
" aff[2] = transform[start + 2].zw;\n"
|
||||||
" mat[3] = transform[start + 3].xy;\n"
|
" mat[3] = transform[start + 3].xy;\n"
|
||||||
" aff[3] = transform[start + 3].zw;\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";
|
"}\n";
|
||||||
|
|
||||||
static const char* const _renderMode2 =
|
static const char* const _renderMode2 =
|
||||||
|
@ -250,8 +273,7 @@ static const char* const _renderMode2 =
|
||||||
"OUT(0) out vec4 color;\n"
|
"OUT(0) out vec4 color;\n"
|
||||||
|
|
||||||
"int fetchTile(ivec2 coord);\n"
|
"int fetchTile(ivec2 coord);\n"
|
||||||
"vec2 interpolate(ivec2 arr[4], float x);\n"
|
"ivec2 affineInterpolate();\n"
|
||||||
"void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"
|
|
||||||
|
|
||||||
"int renderTile(ivec2 coord) {\n"
|
"int renderTile(ivec2 coord) {\n"
|
||||||
" int map = (coord.x >> 11) + (((coord.y >> 7) & 0x7F0) << size);\n"
|
" int map = (coord.x >> 11) + (((coord.y >> 7) & 0x7F0) << size);\n"
|
||||||
|
@ -278,26 +300,7 @@ static const char* const _renderMode2 =
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" ivec2 mat[4];\n"
|
" int paletteEntry = fetchTile(affineInterpolate());\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"
|
|
||||||
" color = texelFetch(palette, ivec2(paletteEntry, int(texCoord.y)), 0);\n"
|
" color = texelFetch(palette, ivec2(paletteEntry, int(texCoord.y)), 0);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
@ -325,30 +328,10 @@ static const char* const _renderMode35 =
|
||||||
"uniform ivec2 mosaic;\n"
|
"uniform ivec2 mosaic;\n"
|
||||||
"OUT(0) out vec4 color;\n"
|
"OUT(0) out vec4 color;\n"
|
||||||
|
|
||||||
"vec2 interpolate(ivec2 arr[4], float x);\n"
|
"ivec2 affineInterpolate();\n"
|
||||||
"void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"
|
|
||||||
|
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" ivec2 mat[4];\n"
|
" ivec2 coord = affineInterpolate();\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"
|
|
||||||
" if (coord.x < 0 || coord.x >= (size.x << 8)) {\n"
|
" if (coord.x < 0 || coord.x >= (size.x << 8)) {\n"
|
||||||
" discard;\n"
|
" discard;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
|
@ -386,30 +369,10 @@ static const char* const _renderMode4 =
|
||||||
"uniform ivec2 mosaic;\n"
|
"uniform ivec2 mosaic;\n"
|
||||||
"OUT(0) out vec4 color;\n"
|
"OUT(0) out vec4 color;\n"
|
||||||
|
|
||||||
"vec2 interpolate(ivec2 arr[4], float x);\n"
|
"ivec2 affineInterpolate();\n"
|
||||||
"void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"
|
|
||||||
|
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" ivec2 mat[4];\n"
|
" ivec2 coord = affineInterpolate();\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"
|
|
||||||
" if (coord.x < 0 || coord.x >= (size.x << 8)) {\n"
|
" if (coord.x < 0 || coord.x >= (size.x << 8)) {\n"
|
||||||
" discard;\n"
|
" discard;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
|
|
Loading…
Reference in New Issue