mirror of https://github.com/mgba-emu/mgba.git
GBA Video: Don't repeat yourself
This commit is contained in:
parent
e15cca9623
commit
cbe87be222
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue