all repos — mgba @ bbf06b5f1312c7f5d8dcf3a4e6f8c9ddbf76e6d8

mGBA Game Boy Advance Emulator

GBA Video: Simplify GL sprite flipping
Vicki Pfau vi@endrift.com
Thu, 23 May 2019 13:09:13 -0700
commit

bbf06b5f1312c7f5d8dcf3a4e6f8c9ddbf76e6d8

parent

13ffd13cdd841571b5c2c0547611b7a3ea4467e8

1 files changed, 10 insertions(+), 6 deletions(-)

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

@@ -1443,10 +1443,6 @@ if (spriteY + height >= 256) {

spriteY -= 256; } - if (!GBAObjAttributesAIsTransformed(sprite->a) && GBAObjAttributesBIsVFlip(sprite->b)) { - spriteY = (renderer->firstY - height) + (renderer->firstY - spriteY) + 1; - } - int totalWidth = width; int totalHeight = height; if (GBAObjAttributesAIsTransformed(sprite->a) && GBAObjAttributesAIsDoubleSize(sprite->a)) {

@@ -1466,7 +1462,7 @@ glBindTexture(GL_TEXTURE_2D, renderer->vramTex);

glActiveTexture(GL_TEXTURE0 + 1); glBindTexture(GL_TEXTURE_2D, renderer->paletteTex); glUniform2i(uniforms[GBA_GL_VS_LOC], totalHeight, 0); - glUniform2i(uniforms[GBA_GL_VS_MAXPOS], (GBAObjAttributesBIsHFlip(sprite->b) && !GBAObjAttributesAIsTransformed(sprite->a)) ? -totalWidth : totalWidth, totalHeight); + glUniform2i(uniforms[GBA_GL_VS_MAXPOS], totalWidth, totalHeight); glUniform1i(uniforms[GBA_GL_OBJ_VRAM], 0); glUniform1i(uniforms[GBA_GL_OBJ_PALETTE], 1); glUniform1i(uniforms[GBA_GL_OBJ_CHARBASE], charBase);

@@ -1484,7 +1480,15 @@ LOAD_16(mat.d, 0, &renderer->d.oam->mat[GBAObjAttributesBGetMatIndex(sprite->b)].d);

glUniformMatrix2fv(uniforms[GBA_GL_OBJ_TRANSFORM], 1, GL_FALSE, (GLfloat[]) { mat.a / 256.f, mat.c / 256.f, mat.b / 256.f, mat.d / 256.f }); } else { - glUniformMatrix2fv(uniforms[GBA_GL_OBJ_TRANSFORM], 1, GL_FALSE, (GLfloat[]) { 1.f, 0, 0, 1.f }); + int flipX = 1; + int flipY = 1; + if (GBAObjAttributesBIsHFlip(sprite->b)) { + flipX = -1; + } + if (GBAObjAttributesBIsVFlip(sprite->b)) { + flipY = -1; + } + glUniformMatrix2fv(uniforms[GBA_GL_OBJ_TRANSFORM], 1, GL_FALSE, (GLfloat[]) { flipX, 0, 0, flipY }); } glUniform4i(uniforms[GBA_GL_OBJ_DIMS], width, height, totalWidth, totalHeight); if (GBAObjAttributesAGetMode(sprite->a) == OBJ_MODE_OBJWIN) {