all repos — mgba @ c9493932434558a4e49e2ab4e4dd643854540b26

mGBA Game Boy Advance Emulator

GBA Video: Start GLES cleanup
Vicki Pfau vi@endrift.com
Thu, 23 May 2019 14:19:15 -0700
commit

c9493932434558a4e49e2ab4e4dd643854540b26

parent

2506fd5330dbe920836ac442e1b0614a3efc8854

1 files changed, 34 insertions(+), 37 deletions(-)

jump to
M src/gba/renderers/gl.csrc/gba/renderers/gl.c

@@ -55,10 +55,13 @@ int type;

}; static const GLchar* const _gles3Header = - "#version 300\n"; + "#version 300 es\n" + "precision highp float;\n" + "precision highp int;\n"; static const GLchar* const _gl3Header = - "#version 130\n"; + "#version 130\n" + "precision highp float;\n"; static const char* const _vertexShader = "in vec2 position;\n"

@@ -67,9 +70,9 @@ "uniform ivec2 maxPos;\n"

"out vec2 texCoord;\n" "void main() {\n" - " vec2 local = vec2(position.x, float(position.y * loc.x + loc.y) / abs(maxPos.y));\n" - " gl_Position = vec4((local * 2. - 1.) * sign(maxPos), 0., 1.);\n" - " texCoord = local * abs(maxPos);\n" + " vec2 local = vec2(position.x, float(position.y * loc.x + loc.y) / float(maxPos.y));\n" + " gl_Position = vec4((local * 2. - 1.) * vec2(sign(maxPos)), 0., 1.);\n" + " texCoord = local * vec2(abs(maxPos));\n" "}"; static const char* const _renderTile16 =

@@ -132,10 +135,10 @@

"void main() {\n" " ivec2 coord = ivec2(texCoord);\n" " if (mosaic.x > 1) {\n" - " coord.x -= int(mod(coord.x, mosaic.x));\n" + " coord.x -= coord.x % mosaic.x;\n" " }\n" " if (mosaic.y > 1) {\n" - " coord.y -= int(mod(coord.y, mosaic.y));\n" + " coord.y -= coord.y % mosaic.y;\n" " }\n" " coord += offset;\n" " if ((size & 1) == 1) {\n"

@@ -153,7 +156,7 @@ " coord.y ^= 7;\n"

" }\n" " int tile = int(map.a * 15.9) + int(map.b * 15.9) * 16 + (tileFlags & 0x3) * 256;\n" " color = renderTile(tile, int(map.r * 15.9), coord & 7);\n" - " flags = inflags / flagCoeff;\n" + " flags = vec4(inflags) / flagCoeff;\n" "}"; static const char* const _fetchTileOverflow =

@@ -271,8 +274,6 @@ "uniform ivec2 mosaic;\n"

"out vec4 color;\n" "out vec4 flags;\n" FLAG_CONST - "precision highp float;\n" - "precision highp int;\n" "vec4 fetchTile(ivec2 coord);\n" "vec2 interpolate(ivec2 arr[4], float x);\n"

@@ -298,20 +299,20 @@

"void main() {\n" " ivec2 mat[4];\n" " ivec2 offset[4];\n" - " loadAffine(int(texCoord.y), mat, offset);\n" - " vec2 coord = texCoord;\n" + " vec2 incoord = texCoord;\n" " if (mosaic.x > 1) {\n" - " coord.x -= mod(coord.x, mosaic.x);\n" + " incoord.x = float(int(incoord.x) % mosaic.x);\n" " }\n" " if (mosaic.y > 1) {\n" - " coord.y -= mod(coord.y, mosaic.y);\n" + " incoord.y = float(int(incoord.y) % mosaic.y);\n" " }\n" - " float y = fract(coord.y);\n" + " loadAffine(int(incoord.y), mat, offset);\n" + " float y = fract(incoord.y);\n" " float lin = 0.75 + y * 0.25;\n" " vec2 mixedTransform = interpolate(mat, lin);\n" " vec2 mixedOffset = interpolate(offset, lin);\n" - " color = fetchTile(ivec2(mixedTransform * coord.x + mixedOffset));\n" - " flags = inflags / flagCoeff;\n" + " color = fetchTile(ivec2(mixedTransform * incoord.x + mixedOffset));\n" + " flags = vec4(inflags) / flagCoeff;\n" "}"; static const struct GBAVideoGLUniform _uniformsMode35[] = {

@@ -340,8 +341,6 @@ "uniform ivec2 mosaic;\n"

"out vec4 color;\n" "out vec4 flags;\n" FLAG_CONST - "precision highp float;\n" - "precision highp int;\n" "vec2 interpolate(ivec2 arr[4], float x);\n" "void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"

@@ -349,14 +348,14 @@

"void main() {\n" " ivec2 mat[4];\n" " ivec2 offset[4];\n" - " loadAffine(int(texCoord.y), mat, offset);\n" " vec2 incoord = texCoord;\n" " if (mosaic.x > 1) {\n" - " incoord.x -= mod(incoord.x, mosaic.x);\n" + " incoord.x = float(int(incoord.x) % mosaic.x);\n" " }\n" " if (mosaic.y > 1) {\n" - " incoord.y -= mod(incoord.y, mosaic.y);\n" + " incoord.y = float(int(incoord.y) % mosaic.y);\n" " }\n" + " loadAffine(int(incoord.y), mat, offset);\n" " float y = fract(incoord.y);\n" " float lin = 0.75 + y * 0.25;\n" " vec2 mixedTransform = interpolate(mat, lin);\n"

@@ -372,7 +371,7 @@ " int address = charBase + (coord.x >> 8) + (coord.y >> 8) * size.x;\n"

" ivec4 entry = ivec4(texelFetch(vram, ivec2(address & 255, address >> 8), 0) * 15.9);\n" " int sixteen = (entry.x << 12) | (entry.y << 8) | (entry.z << 4) | entry.w;\n" " color = vec4((sixteen & 0x1F) / 31., ((sixteen >> 5) & 0x1F) / 31., ((sixteen >> 10) & 0x1F) / 31., 1.);\n" - " flags = inflags / flagCoeff;\n" + " flags = vec4(inflags) / flagCoeff;\n" "}"; static const struct GBAVideoGLUniform _uniformsMode4[] = {

@@ -403,8 +402,6 @@ "uniform ivec2 mosaic;\n"

"out vec4 color;\n" "out vec4 flags;\n" FLAG_CONST - "precision highp float;\n" - "precision highp int;\n" "vec2 interpolate(ivec2 arr[4], float x);\n" "void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"

@@ -412,14 +409,14 @@

"void main() {\n" " ivec2 mat[4];\n" " ivec2 offset[4];\n" - " loadAffine(int(texCoord.y), mat, offset);\n" " vec2 incoord = texCoord;\n" " if (mosaic.x > 1) {\n" - " incoord.x -= mod(incoord.x, mosaic.x);\n" + " incoord.x = float(int(incoord.x) % mosaic.x);\n" " }\n" " if (mosaic.y > 1) {\n" - " incoord.y -= mod(incoord.y, mosaic.y);\n" + " incoord.y = float(int(incoord.y) % mosaic.y);\n" " }\n" + " loadAffine(int(incoord.y), mat, offset);\n" " float y = fract(incoord.y);\n" " float lin = 0.75 + y * 0.25;\n" " vec2 mixedTransform = interpolate(mat, lin);\n"

@@ -436,7 +433,7 @@ " vec4 twoEntries = texelFetch(vram, ivec2((address >> 1) & 255, address >> 9), 0);\n"

" ivec2 entry = ivec2(twoEntries[3 - 2 * (address & 1)] * 15.9, twoEntries[2 - 2 * (address & 1)] * 15.9);\n" " color = texelFetch(palette, entry, 0);\n" " color.a = 1;\n" - " flags = inflags / flagCoeff;\n" + " flags = vec4(inflags) / flagCoeff;\n" "}"; static const struct GBAVideoGLUniform _uniformsObj[] = {

@@ -478,14 +475,14 @@ "void main() {\n"

" vec2 incoord = texCoord;\n" " if (mosaic.x > 1) {\n" " int x = int(incoord.x);\n" - " incoord.x = clamp(x - int(mod(mosaic.z + x, mosaic.x)), 0, dims.z - 1);\n" + " incoord.x = clamp(x - (mosaic.z + x) % mosaic.x, 0, dims.z - 1);\n" " } else if (mosaic.x < -1) {\n" " int x = dims.z - int(incoord.x) - 1;\n" - " incoord.x = clamp(dims.z - x + int(mod(mosaic.z + x, -mosaic.x)) - 1, 0, dims.z - 1);\n" + " incoord.x = clamp(dims.z - x + (mosaic.z + x) % -mosaic.x - 1, 0, dims.z - 1);\n" " }\n" " if (mosaic.y > 1) {\n" " int y = int(incoord.y);\n" - " incoord.y = clamp(y - int(mod(mosaic.w + y, mosaic.y)), 0, dims.w - 1);\n" + " incoord.y = clamp(y - (mosaic.w + y) % mosaic.y, 0, dims.w - 1);\n" " }\n" " ivec2 coord = ivec2(transform * (incoord - dims.zw / 2) + dims.xy / 2);\n" " if ((coord & ~(dims.xy - 1)) != ivec2(0, 0)) {\n"

@@ -496,7 +493,7 @@ " if (objwin.x > 0) {\n"

" pix.a = 0;\n" " }\n" " color = pix;\n" - " flags = inflags / flagCoeff;\n" + " flags = vec4(inflags) / flagCoeff;\n" " window = objwin.yzw;\n" "}";

@@ -625,12 +622,12 @@ glAttachShader(program, vs);

glAttachShader(program, fs); glShaderSource(fs, shaderBufferLines, shaderBuffer, 0); glCompileShader(fs); - glGetShaderInfoLog(fs, 1024, 0, log); + glGetShaderInfoLog(fs, 2048, 0, log); if (log[0]) { mLOG(GBA_VIDEO, ERROR, "Fragment shader compilation failure: %s", log); } glLinkProgram(program); - glGetProgramInfoLog(program, 1024, 0, log); + glGetProgramInfoLog(program, 2048, 0, log); if (log[0]) { mLOG(GBA_VIDEO, ERROR, "Program link failure: %s", log); }

@@ -753,7 +750,7 @@ _initFramebufferTexture(bg->flags, GL_RGB, GL_COLOR_ATTACHMENT1, glRenderer->scale);

glBindFramebuffer(GL_FRAMEBUFFER, 0); } - char log[1024]; + char log[2048]; const GLchar* shaderBuffer[4]; const GLubyte* version = glGetString(GL_VERSION); if (strncmp((const char*) version, "OpenGL ES ", strlen("OpenGL ES "))) {

@@ -766,7 +763,7 @@ GLuint vs = glCreateShader(GL_VERTEX_SHADER);

shaderBuffer[1] = _vertexShader; glShaderSource(vs, 2, shaderBuffer, 0); glCompileShader(vs); - glGetShaderInfoLog(vs, 1024, 0, log); + glGetShaderInfoLog(vs, 2048, 0, log); if (log[0]) { mLOG(GBA_VIDEO, ERROR, "Vertex shader compilation failure: %s", log); }