GBA Video: Fix OpenGL rendering on M1 Macs

This commit is contained in:
Vicki Pfau 2022-01-19 23:06:19 -08:00
parent 506424286f
commit ddca55347e
3 changed files with 22 additions and 9 deletions

View File

@ -21,6 +21,7 @@ Emulation fixes:
- GBA I/O: Redo internal key input, enabling edge-based key IRQs - GBA I/O: Redo internal key input, enabling edge-based key IRQs
- GBA I/O: Disable open bus behavior on invalid register 06A - GBA I/O: Disable open bus behavior on invalid register 06A
- GBA Memory: Fix misaligned 32-bit I/O loads (fixes mgba.io/i/2307) - GBA Memory: Fix misaligned 32-bit I/O loads (fixes mgba.io/i/2307)
- GBA Video: Fix OpenGL rendering on M1 Macs
Other fixes: Other fixes:
- Core: Don't attempt to restore rewind diffs past start of rewind - Core: Don't attempt to restore rewind diffs past start of rewind
- FFmpeg: Fix crash when encoding audio with some containers - FFmpeg: Fix crash when encoding audio with some containers

View File

@ -166,6 +166,8 @@ struct GBAVideoGLRenderer {
struct GBAVideoGLShader windowShader; struct GBAVideoGLShader windowShader;
struct GBAVideoGLShader finalizeShader; struct GBAVideoGLShader finalizeShader;
bool useBindFragData;
GBARegisterDISPCNT dispcnt; GBARegisterDISPCNT dispcnt;
unsigned target1Obj; unsigned target1Obj;

View File

@ -67,11 +67,17 @@ static const GLchar* const _gles3Header =
"precision highp isampler2D;\n"; "precision highp isampler2D;\n";
static const GLchar* const _gl3Header = static const GLchar* const _gl3Header =
"#version 150 core\n" "#version 140 core\n"
"#define OUT(n)\n" "#define OUT(n)\n"
PALETTE_ENTRY PALETTE_ENTRY
"precision highp float;\n"; "precision highp float;\n";
static const GLchar* const _gl33Header =
"#version 330 core\n"
"#define OUT(n) layout(location = n)\n"
PALETTE_ENTRY
"precision highp float;\n";
static const char* const _vertexShader = static const char* const _vertexShader =
"in vec2 position;\n" "in vec2 position;\n"
"uniform ivec2 loc;\n" "uniform ivec2 loc;\n"
@ -698,13 +704,11 @@ static void _compileShader(struct GBAVideoGLRenderer* glRenderer, struct GBAVide
mLOG(GBA_VIDEO, ERROR, "Fragment shader compilation failure: %s", log); mLOG(GBA_VIDEO, ERROR, "Fragment shader compilation failure: %s", log);
} }
size_t i; size_t i;
#ifndef BUILD_GLES3 if (glRenderer->useBindFragData) {
for (i = 0; outFrags[i]; ++i) { for (i = 0; outFrags[i]; ++i) {
glBindFragDataLocation(program, i, outFrags[i]); glBindFragDataLocation(program, i, outFrags[i]);
} }
#else }
UNUSED(outFrags);
#endif
glLinkProgram(program); glLinkProgram(program);
glGetProgramInfoLog(program, 2048, 0, log); glGetProgramInfoLog(program, 2048, 0, log);
if (log[0]) { if (log[0]) {
@ -823,9 +827,15 @@ void GBAVideoGLRendererInit(struct GBAVideoRenderer* renderer) {
char log[2048]; char log[2048];
const GLchar* shaderBuffer[4]; const GLchar* shaderBuffer[4];
glRenderer->useBindFragData = false;
const GLubyte* version = glGetString(GL_VERSION); const GLubyte* version = glGetString(GL_VERSION);
if (strncmp((const char*) version, "OpenGL ES ", strlen("OpenGL ES "))) { if (strncmp((const char*) version, "OpenGL ES ", strlen("OpenGL ES ")) != 0) {
if (strncmp((const char*) version, "3.3 ", strlen("3.3 ")) == 0 || strncmp((const char*) version, "4.", strlen("4.")) == 0) {
shaderBuffer[0] = _gl33Header;
} else {
shaderBuffer[0] = _gl3Header; shaderBuffer[0] = _gl3Header;
glRenderer->useBindFragData = true;
}
} else { } else {
shaderBuffer[0] = _gles3Header; shaderBuffer[0] = _gles3Header;
} }