From fbe8d5144aec537b430515e3ea76adf24bc950e2 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Sat, 6 Jun 2026 14:01:16 -0700 Subject: [PATCH] gates OpenGL calls for ARM --- src/pc/gfx/gfx_dummy.c | 4 +--- src/pc/gfx/gfx_opengl.c | 6 +++++- src/pc/gfx/gfx_sdl.c | 7 +++++++ src/pc/pc_main.c | 17 ++++++++++++++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/pc/gfx/gfx_dummy.c b/src/pc/gfx/gfx_dummy.c index 88654ff04..5419a11bd 100644 --- a/src/pc/gfx/gfx_dummy.c +++ b/src/pc/gfx/gfx_dummy.c @@ -55,9 +55,7 @@ UNUSED static void gfx_dummy_wm_set_fullscreen(UNUSED bool enable) { } static void gfx_dummy_wm_main_loop(void (*run_one_game_iter)(void)) { - while (1) { - run_one_game_iter(); - } + run_one_game_iter(); } static void gfx_dummy_wm_get_dimensions(uint32_t *width, uint32_t *height) { diff --git a/src/pc/gfx/gfx_opengl.c b/src/pc/gfx/gfx_opengl.c index ff35d0333..60af383a0 100644 --- a/src/pc/gfx/gfx_opengl.c +++ b/src/pc/gfx/gfx_opengl.c @@ -59,7 +59,9 @@ static struct ShaderProgram shader_program_pool[CC_MAX_SHADERS]; static uint8_t shader_program_pool_size = 0; static uint8_t shader_program_pool_index = 0; static GLuint opengl_vbo; +#ifndef USE_GLES static GLuint opengl_vao; +#endif static int tex_cache_size = 0; static int num_textures = 0; @@ -835,10 +837,12 @@ static void gfx_opengl_init(void) { glBindBuffer(GL_ARRAY_BUFFER, opengl_vbo); - if (vmajor >= 3 && !is_es) { +#ifndef USE_GLES + if (vmajor >= 3) { glGenVertexArrays(1, &opengl_vao); glBindVertexArray(opengl_vao); } +#endif glDepthFunc(GL_LEQUAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/pc/gfx/gfx_sdl.c b/src/pc/gfx/gfx_sdl.c index be965e821..2d1b87bb3 100644 --- a/src/pc/gfx/gfx_sdl.c +++ b/src/pc/gfx/gfx_sdl.c @@ -36,6 +36,7 @@ #include "../configfile.h" #include "../cliopts.h" +#include "../platform.h" #include "pc/controller/controller_keyboard.h" #include "pc/controller/controller_sdl.h" #include "pc/controller/controller_bind_mapping.h" @@ -143,7 +144,13 @@ static void gfx_sdl_init(const char *window_title) { xpos, ypos, configWindow.w, configWindow.h, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ); + if (!wnd) { + sys_fatal("Failed to create SDL window: %s", SDL_GetError()); + } ctx = SDL_GL_CreateContext(wnd); + if (!ctx) { + sys_fatal("Failed to create OpenGL context: %s", SDL_GetError()); + } gfx_sdl_set_vsync(configWindow.vsync); diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 0d4f9f7fb..b80d6f0e8 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "sm64.h" @@ -96,6 +97,12 @@ static u32 sDrawnFrames = 0; bool gGameInited = false; bool gGfxInited = false; +static volatile bool gQuitSignal = false; + +static void handle_signal(int sig) { + (void)sig; + gQuitSignal = true; +} f32 gMasterVolume; @@ -504,6 +511,13 @@ int main(int argc, char *argv[]) { // handle terminal arguments if (!parse_cli_opts(argc, argv)) { return 0; } + struct sigaction sa; + sa.sa_handler = handle_signal; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + #ifdef _WIN32 // handle Windows console if (gCLIOpts.console || gCLIOpts.headless) { @@ -542,7 +556,7 @@ int main(int argc, char *argv[]) { // render the rom setup screen if (!main_rom_handler()) { - if (!gCLIOpts.hideLoadingScreen) { + if (!gCLIOpts.hideLoadingScreen && !gCLIOpts.headless) { render_rom_setup_screen(); // holds the game load until a valid rom is provided } else { printf("ERROR: could not find valid vanilla us sm64 rom in game's user folder\n"); @@ -612,6 +626,7 @@ int main(int argc, char *argv[]) { // main loop while (true) { + if (gQuitSignal) { game_exit(); } debug_context_reset(); CTX_BEGIN(CTX_TOTAL); gWindowApi->main_loop(produce_one_frame);