GBA Video: Remove redundant flags layers

This commit is contained in:
Vicki Pfau 2020-01-29 18:02:36 -08:00
parent 241e67da62
commit e9cab735cd
2 changed files with 29 additions and 51 deletions

View File

@ -44,7 +44,6 @@ struct GBAVideoGLAffine {
struct GBAVideoGLBackground {
GLuint fbo;
GLuint tex;
GLuint flags;
unsigned index;
int enabled;
@ -96,7 +95,6 @@ enum {
GBA_GL_BG_CHARBASE,
GBA_GL_BG_SIZE,
GBA_GL_BG_OFFSET,
GBA_GL_BG_INFLAGS,
GBA_GL_BG_TRANSFORM,
GBA_GL_BG_RANGE,
GBA_GL_BG_MOSAIC,

View File

@ -117,7 +117,6 @@ static const struct GBAVideoGLUniform _uniformsMode0[] = {
{ "charBase", GBA_GL_BG_CHARBASE, },
{ "size", GBA_GL_BG_SIZE, },
{ "offset", GBA_GL_BG_OFFSET, },
{ "inflags", GBA_GL_BG_INFLAGS, },
{ "mosaic", GBA_GL_BG_MOSAIC, },
{ 0 }
};
@ -130,10 +129,8 @@ static const char* const _renderMode0 =
"uniform int charBase;\n"
"uniform int size;\n"
"uniform int offset[160];\n"
"uniform ivec4 inflags;\n"
"uniform ivec2 mosaic;\n"
"OUT(0) out vec4 color;\n"
"OUT(1) out ivec4 flags;\n"
"vec4 renderTile(int tile, int paletteId, ivec2 localCoord);\n"
@ -171,7 +168,6 @@ static const char* const _renderMode0 =
" }\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;\n"
"}";
static const char* const _fetchTileOverflow =
@ -199,7 +195,6 @@ static const struct GBAVideoGLUniform _uniformsMode2[] = {
{ "screenBase", GBA_GL_BG_SCREENBASE, },
{ "charBase", GBA_GL_BG_CHARBASE, },
{ "size", GBA_GL_BG_SIZE, },
{ "inflags", GBA_GL_BG_INFLAGS, },
{ "offset", GBA_GL_BG_OFFSET, },
{ "transform", GBA_GL_BG_TRANSFORM, },
{ "range", GBA_GL_BG_RANGE, },
@ -235,12 +230,10 @@ static const char* const _renderMode2 =
"uniform int screenBase;\n"
"uniform int charBase;\n"
"uniform int size;\n"
"uniform ivec4 inflags;\n"
"uniform ivec4 transform[160];\n"
"uniform ivec2 range;\n"
"uniform ivec2 mosaic;\n"
"OUT(0) out vec4 color;\n"
"OUT(1) out ivec4 flags;\n"
"vec4 fetchTile(ivec2 coord);\n"
"vec2 interpolate(ivec2 arr[4], float x);\n"
@ -284,7 +277,6 @@ static const char* const _renderMode2 =
" vec2 mixedTransform = interpolate(mat, lin);\n"
" vec2 mixedOffset = interpolate(offset, lin);\n"
" color = fetchTile(ivec2(mixedTransform * incoord.x + mixedOffset));\n"
" flags = inflags;\n"
"}";
static const struct GBAVideoGLUniform _uniformsMode35[] = {
@ -293,7 +285,6 @@ static const struct GBAVideoGLUniform _uniformsMode35[] = {
{ "vram", GBA_GL_BG_VRAM, },
{ "charBase", GBA_GL_BG_CHARBASE, },
{ "size", GBA_GL_BG_SIZE, },
{ "inflags", GBA_GL_BG_INFLAGS, },
{ "offset", GBA_GL_BG_OFFSET, },
{ "transform", GBA_GL_BG_TRANSFORM, },
{ "range", GBA_GL_BG_RANGE, },
@ -306,12 +297,10 @@ static const char* const _renderMode35 =
"uniform sampler2D vram;\n"
"uniform int charBase;\n"
"uniform ivec2 size;\n"
"uniform ivec4 inflags;\n"
"uniform ivec4 transform[160];\n"
"uniform ivec2 range;\n"
"uniform ivec2 mosaic;\n"
"OUT(0) out vec4 color;\n"
"OUT(1) out ivec4 flags;\n"
"vec2 interpolate(ivec2 arr[4], float x);\n"
"void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"
@ -347,7 +336,6 @@ static const char* const _renderMode35 =
" 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(float(sixteen & 0x1F) / 31., float((sixteen >> 5) & 0x1F) / 31., float((sixteen >> 10) & 0x1F) / 31., 1.);\n"
" flags = inflags;\n"
"}";
static const struct GBAVideoGLUniform _uniformsMode4[] = {
@ -357,7 +345,6 @@ static const struct GBAVideoGLUniform _uniformsMode4[] = {
{ "palette", GBA_GL_BG_PALETTE, },
{ "charBase", GBA_GL_BG_CHARBASE, },
{ "size", GBA_GL_BG_SIZE, },
{ "inflags", GBA_GL_BG_INFLAGS, },
{ "offset", GBA_GL_BG_OFFSET, },
{ "transform", GBA_GL_BG_TRANSFORM, },
{ "range", GBA_GL_BG_RANGE, },
@ -371,12 +358,10 @@ static const char* const _renderMode4 =
"uniform int palette[256];\n"
"uniform int charBase;\n"
"uniform ivec2 size;\n"
"uniform ivec4 inflags;\n"
"uniform ivec4 transform[160];\n"
"uniform ivec2 range;\n"
"uniform ivec2 mosaic;\n"
"OUT(0) out vec4 color;\n"
"OUT(1) out ivec4 flags;\n"
"vec2 interpolate(ivec2 arr[4], float x);\n"
"void loadAffine(int y, out ivec2 mat[4], out ivec2 aff[4]);\n"
@ -413,7 +398,6 @@ static const char* const _renderMode4 =
" ivec2 entry = ivec2(twoEntries[3 - 2 * (address & 1)] * 15.9, twoEntries[2 - 2 * (address & 1)] * 15.9);\n"
" int paletteEntry = palette[entry.y * 16 + entry.x];\n"
" color = vec4(PALETTE_ENTRY(paletteEntry), 1.);\n"
" flags = inflags;\n"
"}";
static const struct GBAVideoGLUniform _uniformsObj[] = {
@ -567,7 +551,7 @@ static const struct GBAVideoGLUniform _uniformsFinalize[] = {
{ "maxPos", GBA_GL_VS_MAXPOS, },
{ "scale", GBA_GL_FINALIZE_SCALE, },
{ "layers", GBA_GL_FINALIZE_LAYERS, },
{ "flags", GBA_GL_FINALIZE_FLAGS, },
{ "objFlags", GBA_GL_FINALIZE_FLAGS, },
{ "window", GBA_GL_FINALIZE_WINDOW, },
{ "backdrop", GBA_GL_FINALIZE_BACKDROP, },
{ "backdropFlags", GBA_GL_FINALIZE_BACKDROPFLAGS, },
@ -578,7 +562,7 @@ static const char* const _finalize =
"in vec2 texCoord;\n"
"uniform int scale;\n"
"uniform sampler2D layers[5];\n"
"uniform isampler2D flags[5];\n"
"uniform isampler2D objFlags;\n"
"uniform isampler2D window;\n"
"uniform sampler2D backdrop;\n"
"uniform isampler2D backdropFlags;\n"
@ -610,35 +594,35 @@ static const char* const _finalize =
" if ((layerWindow & 16) != 0) {\n"
" vec4 pix = texelFetch(layers[4], coord, 0);\n"
" if (pix.a != 0.) {\n"
" ivec4 inflags = ivec4(texelFetch(flags[4], coord, 0));\n"
" ivec4 inflags = ivec4(texelFetch(objFlags, coord, 0));\n"
" composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n"
" }\n"
" }\n"
" if ((layerWindow & 1) != 0) {\n"
" vec4 pix = texelFetch(layers[0], coord, 0);\n"
" if (pix.a != 0.) {\n"
" ivec4 inflags = ivec4(texelFetch(flags[0], coord, 0).xyz, 0);\n"
" ivec4 inflags = ivec4(texelFetch(backdropFlags, ivec2(1, texCoord.y), 0));\n"
" composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n"
" }\n"
" }\n"
" if ((layerWindow & 2) != 0) {\n"
" vec4 pix = texelFetch(layers[1], coord, 0);\n"
" if (pix.a != 0.) {\n"
" ivec4 inflags = ivec4(texelFetch(flags[1], coord, 0).xyz, 0);\n"
" ivec4 inflags = ivec4(texelFetch(backdropFlags, ivec2(2, texCoord.y), 0));\n"
" composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n"
" }\n"
" }\n"
" if ((layerWindow & 4) != 0) {\n"
" vec4 pix = texelFetch(layers[2], coord, 0);\n"
" if (pix.a != 0.) {\n"
" ivec4 inflags = ivec4(texelFetch(flags[2], coord, 0).xyz, 0);\n"
" ivec4 inflags = ivec4(texelFetch(backdropFlags, ivec2(3, texCoord.y), 0));\n"
" composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n"
" }\n"
" }\n"
" if ((layerWindow & 8) != 0) {\n"
" vec4 pix = texelFetch(layers[3], coord, 0);\n"
" if (pix.a != 0.) {\n"
" ivec4 inflags = ivec4(texelFetch(flags[3], coord, 0).xyz, 0);\n"
" ivec4 inflags = ivec4(texelFetch(backdropFlags, ivec2(4, texCoord.y), 0));\n"
" composite(pix, inflags, topPixel, topFlags, bottomPixel, bottomFlags);\n"
" }\n"
" }\n"
@ -747,7 +731,7 @@ static void _initFramebufferTextureEx(GLuint tex, GLenum internalFormat, GLenum
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, scale > 0 ? GBA_VIDEO_HORIZONTAL_PIXELS * scale : 1, GBA_VIDEO_VERTICAL_PIXELS * (scale > 0 ? scale : 1), 0, format, type, 0);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, scale > 0 ? GBA_VIDEO_HORIZONTAL_PIXELS * scale : 8, GBA_VIDEO_VERTICAL_PIXELS * (scale > 0 ? scale : 1), 0, format, type, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, tex, 0);
}
@ -764,7 +748,7 @@ static void _initFramebuffers(struct GBAVideoGLRenderer* glRenderer) {
glBindFramebuffer(GL_FRAMEBUFFER, glRenderer->fbo[GBA_GL_FBO_BACKDROP]);
_initFramebufferTexture(glRenderer->layers[GBA_GL_TEX_BACKDROP_COLOR], GL_RGB, GL_COLOR_ATTACHMENT0, 0);
_initFramebufferTextureEx(glRenderer->layers[GBA_GL_TEX_BACKDROP_FLAGS], GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE, GL_COLOR_ATTACHMENT1, glRenderer->scale);
_initFramebufferTextureEx(glRenderer->layers[GBA_GL_TEX_BACKDROP_FLAGS], GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE, GL_COLOR_ATTACHMENT1, 0);
glBindFramebuffer(GL_FRAMEBUFFER, glRenderer->fbo[GBA_GL_FBO_WINDOW]);
_initFramebufferTextureEx(glRenderer->layers[GBA_GL_TEX_WINDOW], GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE, GL_COLOR_ATTACHMENT0, glRenderer->scale);
@ -777,7 +761,6 @@ static void _initFramebuffers(struct GBAVideoGLRenderer* glRenderer) {
struct GBAVideoGLBackground* bg = &glRenderer->bg[i];
glBindFramebuffer(GL_FRAMEBUFFER, bg->fbo);
_initFramebufferTexture(bg->tex, GL_RGBA, GL_COLOR_ATTACHMENT0, glRenderer->scale);
_initFramebufferTextureEx(bg->flags, GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE, GL_COLOR_ATTACHMENT1, glRenderer->scale);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
@ -825,7 +808,6 @@ void GBAVideoGLRendererInit(struct GBAVideoRenderer* renderer) {
bg->affine.sy = 0;
glGenFramebuffers(1, &bg->fbo);
glGenTextures(1, &bg->tex);
glGenTextures(1, &bg->flags);
}
_initFramebuffers(glRenderer);
@ -924,7 +906,6 @@ void GBAVideoGLRendererDeinit(struct GBAVideoRenderer* renderer) {
struct GBAVideoGLBackground* bg = &glRenderer->bg[i];
glDeleteFramebuffers(1, &bg->fbo);
glDeleteTextures(1, &bg->tex);
glDeleteTextures(1, &bg->flags);
}
}
@ -1422,11 +1403,21 @@ void _drawScanlines(struct GBAVideoGLRenderer* glRenderer, int y) {
glDrawBuffers(2, (GLenum[]) { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 });
glClearBufferfv(GL_COLOR, 0, (GLfloat[]) { ((backdrop >> 16) & 0xF8) / 248., ((backdrop >> 8) & 0xF8) / 248., (backdrop & 0xF8) / 248., 1.f });
glClearBufferiv(GL_COLOR, 1, (GLint[]) { 32, glRenderer->target1Bd | (glRenderer->target2Bd * 2) | (glRenderer->blendEffect * 4), glRenderer->blda, 0 });
glDrawBuffers(2, (GLenum[]) { GL_NONE, GL_COLOR_ATTACHMENT1 });
int i;
for (i = 0; i < 4; ++i) {
glScissor(i + 1, glRenderer->firstY, i + 2, y - glRenderer->firstY + 1);
glClearBufferiv(GL_COLOR, 1, (GLint[]) { glRenderer->bg[i].priority,
glRenderer->bg[i].target1 | (glRenderer->bg[i].target2 << 1) | (glRenderer->blendEffect << 2),
glRenderer->blda, 0 });
}
glDrawBuffers(1, (GLenum[]) { GL_COLOR_ATTACHMENT0 });
GBAVideoGLRendererDrawWindow(glRenderer, y);
if (GBARegisterDISPCNTIsObjEnable(glRenderer->dispcnt) && !glRenderer->d.disableOBJ) {
int i;
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glEnable(GL_STENCIL_TEST);
glDepthFunc(GL_LESS);
@ -1609,33 +1600,25 @@ void _finalizeLayers(struct GBAVideoGLRenderer* renderer) {
glActiveTexture(GL_TEXTURE0 + 3);
glBindTexture(GL_TEXTURE_2D, renderer->bg[0].tex);
glActiveTexture(GL_TEXTURE0 + 4);
glBindTexture(GL_TEXTURE_2D, renderer->bg[0].flags);
glActiveTexture(GL_TEXTURE0 + 5);
glBindTexture(GL_TEXTURE_2D, renderer->bg[1].tex);
glActiveTexture(GL_TEXTURE0 + 6);
glBindTexture(GL_TEXTURE_2D, renderer->bg[1].flags);
glActiveTexture(GL_TEXTURE0 + 7);
glActiveTexture(GL_TEXTURE0 + 5);
glBindTexture(GL_TEXTURE_2D, renderer->bg[2].tex);
glActiveTexture(GL_TEXTURE0 + 8);
glBindTexture(GL_TEXTURE_2D, renderer->bg[2].flags);
glActiveTexture(GL_TEXTURE0 + 9);
glActiveTexture(GL_TEXTURE0 + 6);
glBindTexture(GL_TEXTURE_2D, renderer->bg[3].tex);
glActiveTexture(GL_TEXTURE0 + 10);
glBindTexture(GL_TEXTURE_2D, renderer->bg[3].flags);
glActiveTexture(GL_TEXTURE0 + 11);
glActiveTexture(GL_TEXTURE0 + 7);
glBindTexture(GL_TEXTURE_2D, renderer->layers[GBA_GL_TEX_BACKDROP_COLOR]);
glActiveTexture(GL_TEXTURE0 + 12);
glActiveTexture(GL_TEXTURE0 + 8);
glBindTexture(GL_TEXTURE_2D, renderer->layers[GBA_GL_TEX_BACKDROP_FLAGS]);
glUniform2i(uniforms[GBA_GL_VS_LOC], GBA_VIDEO_VERTICAL_PIXELS, 0);
glUniform2i(uniforms[GBA_GL_VS_MAXPOS], GBA_VIDEO_HORIZONTAL_PIXELS, GBA_VIDEO_VERTICAL_PIXELS);
glUniform1i(uniforms[GBA_GL_FINALIZE_SCALE], renderer->scale);
glUniform1iv(uniforms[GBA_GL_FINALIZE_LAYERS], 5, (GLint[]) { 3, 5, 7, 9, 1 });
glUniform1iv(uniforms[GBA_GL_FINALIZE_FLAGS], 5, (GLint[]) { 4, 6, 8, 10, 2 });
glUniform1iv(uniforms[GBA_GL_FINALIZE_LAYERS], 5, (GLint[]) { 3, 4, 5, 6, 1 });
glUniform1i(uniforms[GBA_GL_FINALIZE_FLAGS], 2);
glUniform1i(uniforms[GBA_GL_FINALIZE_WINDOW], 0);
glUniform1i(uniforms[GBA_GL_FINALIZE_WINDOW], 0);
glUniform1i(uniforms[GBA_GL_FINALIZE_BACKDROP], 11);
glUniform1i(uniforms[GBA_GL_FINALIZE_BACKDROPFLAGS], 12);
glUniform1i(uniforms[GBA_GL_FINALIZE_BACKDROP], 7);
glUniform1i(uniforms[GBA_GL_FINALIZE_BACKDROPFLAGS], 8);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -1752,10 +1735,7 @@ void _prepareBackground(struct GBAVideoGLRenderer* renderer, struct GBAVideoGLBa
} else {
glUniform2i(uniforms[GBA_GL_BG_MOSAIC], 0, 0);
}
glUniform4i(uniforms[GBA_GL_BG_INFLAGS], background->priority,
background->target1 | (background->target2 * 2) | (renderer->blendEffect * 4),
renderer->blda, 0);
glDrawBuffers(2, (GLenum[]) { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 });
glDrawBuffers(1, (GLenum[]) { GL_COLOR_ATTACHMENT0 });
}
void GBAVideoGLRendererDrawBackgroundMode0(struct GBAVideoGLRenderer* renderer, struct GBAVideoGLBackground* background, int y) {