From b156770bbdd159d1c86e83ca49fc1471e8e6e74e Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 14 Jul 2026 10:00:41 -0700 Subject: [PATCH] Configure the runtime OpenGL 3.3 core context Co-authored-by: douglasjv --- .../upstream/douglas-pr15-macos-gl-context.md | 9 ++++++++ runtime/src/main.cpp | 21 ++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 docs/internal/upstream/douglas-pr15-macos-gl-context.md diff --git a/docs/internal/upstream/douglas-pr15-macos-gl-context.md b/docs/internal/upstream/douglas-pr15-macos-gl-context.md new file mode 100644 index 00000000..bb05ad5e --- /dev/null +++ b/docs/internal/upstream/douglas-pr15-macos-gl-context.md @@ -0,0 +1,9 @@ +# macOS OpenGL context setup + +Source: [PSXRecomp PR #15](https://github.com/mstan/psxrecomp/pull/15), +commit [`df7d1faa5f27be0ba357463a763c77efc43e1f91`](https://github.com/douglasjv/psxrecomp-tweaks/commit/df7d1faa5f27be0ba357463a763c77efc43e1f91). + +This branch isolates the reusable OpenGL 3.3 core-context setup and applies it +to both launcher and direct game windows. CPU-copied overlay discovery, debug +input additions, and title-specific material from the source commit are not +included. diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 994cb69b..5963e2a7 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp @@ -374,6 +374,17 @@ static void clamp_window_aspect(int* w, int* h, int num, int den) { *h = width * den / num; } +/* SDL GL attributes are global inputs to the next context creation. Set the + * runtime requirements immediately before every GL window, because launcher + * teardown resets them and macOS otherwise supplies a legacy 2.1 context. */ +static void configure_core_gl_context_attributes() { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); +} + /* Live native-wide vs squash toggle (ws_nw TCP command) for A/B comparison. * Re-engages with the chosen mode in place if widescreen is already running. */ extern "C" void psx_ws_set_native_wide(int on) { @@ -3243,10 +3254,7 @@ int main(int argc, char** argv) { seed.has_deadzone = true; seed.window_width = g_video_win_w; seed.has_window_width = true; - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + configure_core_gl_context_attributes(); /* Launcher opens at the same 4:3 size the game will, so there's no * jarring resize on LAUNCH. The dense dashboard needs a usable @@ -3569,7 +3577,10 @@ int main(int argc, char** argv) { #endif Uint32 win_flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE; - if (g_video_renderer == 1) win_flags |= SDL_WINDOW_OPENGL; + if (g_video_renderer == 1) { + configure_core_gl_context_attributes(); + win_flags |= SDL_WINDOW_OPENGL; + } if (g_video_renderer == 2) win_flags |= SDL_WINDOW_VULKAN; /* Fullscreen on launch (launcher "Fullscreen on launch" toggle). DESKTOP * fullscreen keeps the desktop resolution and letterboxes the image, matching