From 2a8987481262378a1f577e07f76bdbeb51451a56 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sat, 19 Oct 2019 18:34:24 +0200 Subject: [PATCH] decouple imgui from gles renderer --- core/deps/imgui/imconfig.h | 4 +- core/hw/pvr/Renderer_if.cpp | 4 +- core/linux-dist/dispmanx.cpp | 2 +- core/linux-dist/x11.cpp | 2 +- core/rend/gl4/gles.cpp | 2 - core/rend/gles/glcache.h | 2 +- core/rend/gles/gldraw.cpp | 1 + core/rend/gles/gles.cpp | 18 ++------ core/rend/gles/gltex.cpp | 1 + core/rend/gles/imgui_impl_opengl3.cpp | 14 +++--- core/rend/gui.cpp | 18 ++++---- core/rend/vulkan/vulkan_context.cpp | 1 + core/sdl/sdl.cpp | 4 +- core/windows/winmain.cpp | 2 +- core/wsi/context.h | 3 +- core/wsi/egl.cpp | 3 ++ core/wsi/egl.h | 4 +- core/wsi/gl_context.cpp | 46 +++++++++++++++++++ core/wsi/gl_context.h | 16 +++++++ core/wsi/osx.h | 8 ++-- core/wsi/sdl.cpp | 11 +++-- core/wsi/sdl.h | 4 +- core/wsi/{swicher.cpp => switcher.cpp} | 12 +++-- core/wsi/wgl.cpp | 4 ++ core/wsi/wgl.h | 4 +- core/wsi/xgl.cpp | 8 +++- core/wsi/xgl.h | 4 +- .../reicast/src/main/jni/src/Android.cpp | 3 +- .../emulator-osx/emulator-osx/osx-main.mm | 2 + .../reicast-osx.xcodeproj/project.pbxproj | 12 +++-- 30 files changed, 155 insertions(+), 64 deletions(-) create mode 100644 core/wsi/gl_context.cpp rename core/wsi/{swicher.cpp => switcher.cpp} (88%) diff --git a/core/deps/imgui/imconfig.h b/core/deps/imgui/imconfig.h index 6430e66e9..fb30176ba 100644 --- a/core/deps/imgui/imconfig.h +++ b/core/deps/imgui/imconfig.h @@ -22,11 +22,11 @@ //#define IMGUI_API __declspec( dllimport ) //---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. -//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS +#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS //---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty) //---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp. -//#define IMGUI_DISABLE_DEMO_WINDOWS +#define IMGUI_DISABLE_DEMO_WINDOWS //---- Don't implement some functions to reduce linkage requirements. //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. diff --git a/core/hw/pvr/Renderer_if.cpp b/core/hw/pvr/Renderer_if.cpp index eff8b565b..0a5766216 100644 --- a/core/hw/pvr/Renderer_if.cpp +++ b/core/hw/pvr/Renderer_if.cpp @@ -280,8 +280,7 @@ bool rend_single_frame() if (renderer_changed != settings.pvr.rend) { rend_term_renderer(); - settings.pvr.rend = renderer_changed; - SwitchRenderApi(); + SwitchRenderApi(renderer_changed); rend_create_renderer(); rend_init_renderer(); } @@ -401,7 +400,6 @@ void rend_init_renderer() void rend_term_renderer() { - gui_term(); renderer->Term(); delete renderer; renderer = NULL; diff --git a/core/linux-dist/dispmanx.cpp b/core/linux-dist/dispmanx.cpp index f4f5452b8..d8cf75b67 100644 --- a/core/linux-dist/dispmanx.cpp +++ b/core/linux-dist/dispmanx.cpp @@ -78,6 +78,6 @@ void dispmanx_window_create() theGLContext.SetNativeWindow((EGLNativeWindowType)&native_window); theGLContext.SetNativeDisplay((EGLNativeDisplayType)dispman_display); - SwitchRenderApi(); + InitRenderApi(); } #endif diff --git a/core/linux-dist/x11.cpp b/core/linux-dist/x11.cpp index da0830af7..3246b1a6b 100644 --- a/core/linux-dist/x11.cpp +++ b/core/linux-dist/x11.cpp @@ -437,7 +437,7 @@ void x11_window_create() #ifdef USE_VULKAN theVulkanContext.SetWindow((void *)x11_win, (void *)x11_disp); #endif - SwitchRenderApi(); + InitRenderApi(); XFlush(x11_disp); diff --git a/core/rend/gl4/gles.cpp b/core/rend/gl4/gles.cpp index 2e9d23ed6..a933261a6 100644 --- a/core/rend/gl4/gles.cpp +++ b/core/rend/gl4/gles.cpp @@ -545,8 +545,6 @@ static bool gl_create_resources() gl_load_osd_resources(); - gui_init(); - // Create the buffer for Translucent poly params glGenBuffers(1, &gl4.vbo.tr_poly_params); // Bind it diff --git a/core/rend/gles/glcache.h b/core/rend/gles/glcache.h index 32c73c644..3029beea6 100644 --- a/core/rend/gles/glcache.h +++ b/core/rend/gles/glcache.h @@ -1,6 +1,6 @@ #pragma once #include -#include "gles.h" +#include "wsi/gl_context.h" #define TEXTURE_ID_CACHE_SIZE 32 diff --git a/core/rend/gles/gldraw.cpp b/core/rend/gles/gldraw.cpp index b35aa8548..4b7961ac6 100644 --- a/core/rend/gles/gldraw.cpp +++ b/core/rend/gles/gldraw.cpp @@ -1,4 +1,5 @@ #include "glcache.h" +#include "gles.h" #include "rend/rend.h" #include "rend/sorter.h" diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 971bb1bc2..2deb04823 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -1,5 +1,6 @@ #include #include "glcache.h" +#include "gles.h" #include "rend/TexCache.h" #include "rend/gui.h" #include "wsi/gl_context.h" @@ -500,18 +501,10 @@ static void gles_term() void findGLVersion() { gl.index_type = GL_UNSIGNED_INT; - - while (true) - if (glGetError() == GL_NO_ERROR) - break; - glGetIntegerv(GL_MAJOR_VERSION, &gl.gl_major); - if (glGetError() == GL_INVALID_ENUM) - gl.gl_major = 2; - const char *version = (const char *)glGetString(GL_VERSION); - INFO_LOG(RENDERER, "OpenGL version: %s", version); - if (!strncmp(version, "OpenGL ES", 9)) + gl.gl_major = theGLContext.GetMajorVersion(); + gl.is_gles = theGLContext.IsGLES(); + if (gl.is_gles) { - gl.is_gles = true; if (gl.gl_major >= 3) { gl.gl_version = "GLES3"; @@ -534,7 +527,6 @@ void findGLVersion() } else { - gl.is_gles = false; if (gl.gl_major >= 3) { gl.gl_version = "GL3"; @@ -830,8 +822,6 @@ bool gl_create_resources() gl_load_osd_resources(); - gui_init(); - return true; } diff --git a/core/rend/gles/gltex.cpp b/core/rend/gles/gltex.cpp index 11d64bd13..92526880a 100644 --- a/core/rend/gles/gltex.cpp +++ b/core/rend/gles/gltex.cpp @@ -1,5 +1,6 @@ #include #include "glcache.h" +#include "gles.h" #include "rend/TexCache.h" #include "hw/pvr/pvr_mem.h" #include "hw/mem/_vmem.h" diff --git a/core/rend/gles/imgui_impl_opengl3.cpp b/core/rend/gles/imgui_impl_opengl3.cpp index a0a0bdad2..9035c0bac 100644 --- a/core/rend/gles/imgui_impl_opengl3.cpp +++ b/core/rend/gles/imgui_impl_opengl3.cpp @@ -66,7 +66,7 @@ #include "TargetConditionals.h" #endif -#include "gles.h" +#include "wsi/gl_context.h" #include "glcache.h" // OpenGL Data @@ -87,7 +87,7 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) // Store GLSL version string so we can refer to it later in case we recreate shaders. Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure. if (glsl_version == NULL) { - if (gl.is_gles) + if (theGLContext.IsGLES()) glsl_version = "#version 100"; // OpenGL ES 2.0 else #if HOST_OS == OS_DARWIN @@ -131,7 +131,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr glActiveTexture(GL_TEXTURE0); bool clip_origin_lower_left = true; #ifdef GL_CLIP_ORIGIN - if (gl.gl_major >= 4 && glClipControl != NULL) + if (theGLContext.GetMajorVersion() >= 4 && glClipControl != NULL) { GLenum last_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)&last_clip_origin); // Support for GL 4.5's glClipControl(GL_UPPER_LEFT) if (last_clip_origin == GL_UPPER_LEFT) @@ -142,7 +142,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr if (save_background) { #ifndef GLES2 - if (!gl.is_gles && glReadBuffer != NULL) + if (!theGLContext.IsGLES() && glReadBuffer != NULL) glReadBuffer(GL_FRONT); // (Re-)create the background texture and reserve space for it @@ -192,12 +192,12 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data, bool save_backgr glUniform1i(g_AttribLocationTex, 0); glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); #ifndef GLES2 - if (gl.gl_major >= 3 && glBindSampler != NULL) + if (theGLContext.GetMajorVersion() >= 3 && glBindSampler != NULL) glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise. #endif GLuint vao_handle = 0; #ifndef GLES2 - if (gl.gl_major >= 3) + if (theGLContext.GetMajorVersion() >= 3) { // Recreate the VAO every time // (This is to easily allow multiple GL contexts. VAO are not shared among GL contexts, and we don't track creation/deletion of windows so we don't have an obvious key to use to cache them.) @@ -272,7 +272,7 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture() glcache.BindTexture(GL_TEXTURE_2D, g_FontTexture); glcache.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glcache.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - if (gl.gl_major >= 3) + if (theGLContext.GetMajorVersion() >= 3) glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index ceb0ede9e..fcb55283f 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -34,9 +34,6 @@ #include "linux-dist/main.h" // FIXME for kcode[] #include "gui_util.h" #include "gui_android.h" -#ifdef USE_VULKAN -#include "rend/vulkan/vulkan.h" -#endif #include "version.h" #include "oslib/audiostream.h" @@ -957,7 +954,7 @@ static void gui_display_settings() ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, normal_padding); int renderer = settings.pvr.rend == 3 ? 2 : settings.rend.PerStripSorting ? 1 : 0; #if HOST_OS != OS_DARWIN - bool has_per_pixel = !gl.is_gles && gl.gl_major >= 4 && !vulkan; + bool has_per_pixel = !theGLContext.IsGLES() && theGLContext.GetMajorVersion() >= 4 && !vulkan; #else bool has_per_pixel = false; #endif @@ -1672,11 +1669,14 @@ void gui_open_onboarding() void gui_term() { - inited = false; - term_vmus(); - if (settings.pvr.IsOpenGL()) - ImGui_ImplOpenGL3_Shutdown(); - ImGui::DestroyContext(); + if (inited) + { + inited = false; + term_vmus(); + if (settings.pvr.IsOpenGL()) + ImGui_ImplOpenGL3_Shutdown(); + ImGui::DestroyContext(); + } } int msgboxf(const wchar* text, unsigned int type, ...) { diff --git a/core/rend/vulkan/vulkan_context.cpp b/core/rend/vulkan/vulkan_context.cpp index 5e59f8cbd..5a936a008 100644 --- a/core/rend/vulkan/vulkan_context.cpp +++ b/core/rend/vulkan/vulkan_context.cpp @@ -682,6 +682,7 @@ void VulkanContext::Present() void VulkanContext::Term() { ImGui_ImplVulkan_Shutdown(); + gui_term(); if (device && pipelineCache) { std::vector cacheData = device->getPipelineCacheData(*pipelineCache); diff --git a/core/sdl/sdl.cpp b/core/sdl/sdl.cpp index 5ab48af4b..8998bcecc 100644 --- a/core/sdl/sdl.cpp +++ b/core/sdl/sdl.cpp @@ -107,7 +107,7 @@ void input_sdl_handle(u32 port) if (port == 0) // FIXME hack SDLGamepadDevice::UpdateRumble(); - #define SET_FLAG(field, mask, expr) field =((expr) ? (field & ~mask) : (field | mask)) + #define SET_FLAG(field, mask, expr) (field) = ((expr) ? ((field) & ~(mask)) : ((field) | (mask))) SDL_Event event; while (SDL_PollEvent(&event)) { @@ -238,7 +238,7 @@ void sdl_window_create() die("error initializing SDL Joystick subsystem"); } } - SwitchRenderApi(); + InitRenderApi(); } void sdl_window_destroy() diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index ae890026e..9cad816ee 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -717,7 +717,7 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi #endif theGLContext.SetWindow(hWnd); theGLContext.SetDeviceContext(GetDC(hWnd)); - SwitchRenderApi(); + InitRenderApi(); rend_thread(NULL); diff --git a/core/wsi/context.h b/core/wsi/context.h index 627d653f7..0ba7bf743 100644 --- a/core/wsi/context.h +++ b/core/wsi/context.h @@ -25,6 +25,7 @@ extern VulkanContext theVulkanContext; #endif -void SwitchRenderApi(); +void InitRenderApi(); +void SwitchRenderApi(int newApi); void TermRenderApi(); diff --git a/core/wsi/egl.cpp b/core/wsi/egl.cpp index 7599884e7..33f2e0b9b 100644 --- a/core/wsi/egl.cpp +++ b/core/wsi/egl.cpp @@ -193,12 +193,15 @@ bool EGLGraphicsContext::Init() eglSwapInterval(display, 1); #endif + PostInit(); + INFO_LOG(RENDERER, "EGL config: %p, %p, %p %dx%d", context, display, surface, w, h); return true; } void EGLGraphicsContext::Term() { + PreTerm(); eglMakeCurrent(display, NULL, NULL, EGL_NO_CONTEXT); if (context != EGL_NO_CONTEXT) eglDestroyContext(display, context); diff --git a/core/wsi/egl.h b/core/wsi/egl.h index 308ba3735..663357b82 100644 --- a/core/wsi/egl.h +++ b/core/wsi/egl.h @@ -18,17 +18,19 @@ You should have received a copy of the GNU General Public License along with Flycast. If not, see . */ +#pragma once #include #include #ifndef GLES2 #include "gl32funcs.h" #endif +#include "gl_context.h" #define USE_EGL #include #include -class EGLGraphicsContext +class EGLGraphicsContext : public GLGraphicsContext { public: ~EGLGraphicsContext() { Term(); } diff --git a/core/wsi/gl_context.cpp b/core/wsi/gl_context.cpp new file mode 100644 index 000000000..b36d31ae1 --- /dev/null +++ b/core/wsi/gl_context.cpp @@ -0,0 +1,46 @@ +/* + Created on: Oct 19, 2019 + + Copyright 2019 flyinghead + + This file is part of Flycast. + + Flycast is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + Flycast is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Flycast. If not, see . +*/ +#include "gl_context.h" +#include "rend/gui.h" + +void GLGraphicsContext::findGLVersion() +{ + while (true) + if (glGetError() == GL_NO_ERROR) + break; + glGetIntegerv(GL_MAJOR_VERSION, &majorVersion); + if (glGetError() == GL_INVALID_ENUM) + majorVersion = 2; + const char *version = (const char *)glGetString(GL_VERSION); + isGLES = !strncmp(version, "OpenGL ES", 9); + INFO_LOG(RENDERER, "OpenGL version: %s", version); +} + +void GLGraphicsContext::PostInit() +{ + findGLVersion(); + gui_init(); +} + +void GLGraphicsContext::PreTerm() +{ + gui_term(); +} diff --git a/core/wsi/gl_context.h b/core/wsi/gl_context.h index fa6d03fc8..eda891299 100644 --- a/core/wsi/gl_context.h +++ b/core/wsi/gl_context.h @@ -25,6 +25,22 @@ void do_swap_automation(); // FIXME extern int screen_width, screen_height; +class GLGraphicsContext +{ +public: + int GetMajorVersion() const { return majorVersion; } + bool IsGLES() const { return isGLES; } + +protected: + void PostInit(); + void PreTerm(); + void findGLVersion(); + +private: + int majorVersion = 0; + bool isGLES = false; +}; + #if HOST_OS == OS_DARWIN #include "osx.h" diff --git a/core/wsi/osx.h b/core/wsi/osx.h index e245db5e8..ad65e8c9d 100644 --- a/core/wsi/osx.h +++ b/core/wsi/osx.h @@ -18,18 +18,20 @@ You should have received a copy of the GNU General Public License along with Flycast. If not, see . */ +#pragma once #if defined(TARGET_IPHONE) //apple-specific ogles2 headers #include #include #else #include #endif +#include "gl_context.h" -class OSXGraphicsContext +class OSXGraphicsContext : public GLGraphicsContext { public: - bool Init() { return true; } - void Term() {} + bool Init() { PostInit(); return true; } + void Term() { PreTerm(); } void Swap(); bool IsSwapBufferPreserved() const { return true; } }; diff --git a/core/wsi/sdl.cpp b/core/wsi/sdl.cpp index ad149ca0a..c8a478df6 100644 --- a/core/wsi/sdl.cpp +++ b/core/wsi/sdl.cpp @@ -68,11 +68,13 @@ bool SDLGLGraphicsContext::Init() SDL_GL_MakeCurrent(window, glcontext); -#ifdef GLES - return true; -#else - return gl3wInit() != -1 && gl3wIsSupported(3, 1); +#ifndef GLES + if (gl3wInit() == -1 || !gl3wIsSupported(3, 1)) + return false; #endif + PostInit(); + + return true; } void SDLGLGraphicsContext::Swap() @@ -85,6 +87,7 @@ void SDLGLGraphicsContext::Swap() void SDLGLGraphicsContext::Term() { + PreTerm(); if (glcontext != nullptr) { SDL_GL_DeleteContext(glcontext); diff --git a/core/wsi/sdl.h b/core/wsi/sdl.h index 902828f65..7bb660d39 100644 --- a/core/wsi/sdl.h +++ b/core/wsi/sdl.h @@ -18,11 +18,13 @@ You should have received a copy of the GNU General Public License along with Flycast. If not, see . */ +#pragma once #include #include "types.h" #include +#include "gl_context.h" -class SDLGLGraphicsContext +class SDLGLGraphicsContext : public GLGraphicsContext { public: bool Init(); diff --git a/core/wsi/swicher.cpp b/core/wsi/switcher.cpp similarity index 88% rename from core/wsi/swicher.cpp rename to core/wsi/switcher.cpp index 67b783ae4..2fe332272 100644 --- a/core/wsi/swicher.cpp +++ b/core/wsi/switcher.cpp @@ -19,27 +19,33 @@ along with Flycast. If not, see . */ #include "context.h" +#include "rend/gui.h" #ifdef USE_VULKAN VulkanContext theVulkanContext; #endif -void SwitchRenderApi() +void InitRenderApi() { #ifdef USE_VULKAN if (settings.pvr.rend == 4) { - theGLContext.Term(); if (theVulkanContext.Init()) return; // Fall back to Open GL } - theVulkanContext.Term(); #endif if (!theGLContext.Init()) exit(1); } +void SwitchRenderApi(int newApi) +{ + TermRenderApi(); + settings.pvr.rend = newApi; + InitRenderApi(); +} + void TermRenderApi() { #ifdef USE_VULKAN diff --git a/core/wsi/wgl.cpp b/core/wsi/wgl.cpp index a85858926..e7649d331 100644 --- a/core/wsi/wgl.cpp +++ b/core/wsi/wgl.cpp @@ -112,6 +112,9 @@ bool WGLGraphicsContext::Init() screen_width = r.right - r.left; screen_height = r.bottom - r.top; + if (rv) + PostInit(); + return rv; } @@ -125,6 +128,7 @@ void WGLGraphicsContext::Swap() void WGLGraphicsContext::Term() { + PreTerm(); if (ourOpenGLRenderingContext != NULL) { wglDeleteContext(ourOpenGLRenderingContext); diff --git a/core/wsi/wgl.h b/core/wsi/wgl.h index b075a1610..0fdbc853f 100644 --- a/core/wsi/wgl.h +++ b/core/wsi/wgl.h @@ -18,8 +18,10 @@ You should have received a copy of the GNU General Public License along with Flycast. If not, see . */ +#pragma once #include #include +#include "gl_context.h" #define WGL_DRAW_TO_WINDOW_ARB 0x2001 #define WGL_ACCELERATION_ARB 0x2003 @@ -53,7 +55,7 @@ typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShar typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval); -class WGLGraphicsContext +class WGLGraphicsContext : public GLGraphicsContext { public: ~WGLGraphicsContext() { Term(); } diff --git a/core/wsi/xgl.cpp b/core/wsi/xgl.cpp index 5b4b68067..c29de3745 100644 --- a/core/wsi/xgl.cpp +++ b/core/wsi/xgl.cpp @@ -76,7 +76,12 @@ bool XGLGraphicsContext::Init() screen_width = 640; screen_height = 480; - return gl3wInit() != -1 && gl3wIsSupported(3, 1); + if (gl3wInit() == -1 || !gl3wIsSupported(3, 1)) + return false; + + PostInit(); + + return true; } bool XGLGraphicsContext::ChooseVisual(Display* x11Display, XVisualInfo** visual, int* depth) @@ -164,6 +169,7 @@ void XGLGraphicsContext::Swap() void XGLGraphicsContext::Term() { + PreTerm(); if (context) { glXMakeCurrent(display, None, NULL); diff --git a/core/wsi/xgl.h b/core/wsi/xgl.h index cc9e56dda..8bc09c4cf 100644 --- a/core/wsi/xgl.h +++ b/core/wsi/xgl.h @@ -18,12 +18,14 @@ You should have received a copy of the GNU General Public License along with Flycast. If not, see . */ +#pragma once #include #include #include #include +#include "gl_context.h" -class XGLGraphicsContext +class XGLGraphicsContext : public GLGraphicsContext { public: ~XGLGraphicsContext() { Term(); XFree(framebufferConfigs); } diff --git a/shell/android-studio/reicast/src/main/jni/src/Android.cpp b/shell/android-studio/reicast/src/main/jni/src/Android.cpp index 02aa472db..ddd0adca6 100644 --- a/shell/android-studio/reicast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/reicast/src/main/jni/src/Android.cpp @@ -397,10 +397,11 @@ static void *render_thread_func(void *) theVulkanContext.SetWindow((void *)g_window, nullptr); #endif theGLContext.SetNativeWindow((EGLNativeWindowType)g_window); - SwitchRenderApi(); + InitRenderApi(); rend_thread(NULL); + TermRenderApi(); ANativeWindow_release(g_window); g_window = NULL; diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index 712284f04..6ecdf5040 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -19,6 +19,7 @@ #if defined(USE_SDL) #include "sdl/sdl.h" #endif +#include "wsi/context.h" OSXKeyboardDevice keyboard(0); static std::shared_ptr kb_gamepad(0); @@ -138,6 +139,7 @@ extern "C" void emu_gles_init(int width, int height) { screen_width = width; screen_height = height; + InitRenderApi(); rend_init_renderer(); } diff --git a/shell/apple/emulator-osx/reicast-osx.xcodeproj/project.pbxproj b/shell/apple/emulator-osx/reicast-osx.xcodeproj/project.pbxproj index 1bcb5237e..9f6e844c7 100644 --- a/shell/apple/emulator-osx/reicast-osx.xcodeproj/project.pbxproj +++ b/shell/apple/emulator-osx/reicast-osx.xcodeproj/project.pbxproj @@ -248,7 +248,7 @@ AE7B904F23565B4200145C6A /* allocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE7B904D23565B4100145C6A /* allocator.cpp */; }; AE7B907C235A53D800145C6A /* gl4funcs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE7B906F235A53D800145C6A /* gl4funcs.cpp */; }; AE7B907D235A53D800145C6A /* osx.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE7B9071235A53D800145C6A /* osx.cpp */; }; - AE7B907F235A53D800145C6A /* swicher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE7B9075235A53D800145C6A /* swicher.cpp */; }; + AE7B907F235A53D800145C6A /* switcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE7B9075235A53D800145C6A /* switcher.cpp */; }; AE80EDB72157D4D500F7800F /* serialize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE80EDB62157D4D500F7800F /* serialize.cpp */; }; AE80EDBE2157D4E600F7800F /* naomi.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE80EDB92157D4E600F7800F /* naomi.cpp */; }; AE80EDBF2157D4E600F7800F /* naomi_cart.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE80EDBB2157D4E600F7800F /* naomi_cart.cpp */; }; @@ -257,6 +257,7 @@ AE8C274121122E2500D4D8F4 /* Changelog.txt in Resources */ = {isa = PBXBuildFile; fileRef = AE8C273B21122E2500D4D8F4 /* Changelog.txt */; }; AE8C274221122E2500D4D8F4 /* License.txt in Resources */ = {isa = PBXBuildFile; fileRef = AE8C273C21122E2500D4D8F4 /* License.txt */; }; AE8C274321122E2500D4D8F4 /* xbrz.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE8C273D21122E2500D4D8F4 /* xbrz.cpp */; }; + AE90679B235B6F6400CE473C /* gl_context.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AE90679A235B6F6400CE473C /* gl_context.cpp */; }; AED73BAE22FC0E9600ECDB64 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = AED73BAD22FC0E9600ECDB64 /* README.md */; }; AED73DC42303E19200ECDB64 /* sdl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AED73DC02303E19100ECDB64 /* sdl.cpp */; }; AED73DC72303E57C00ECDB64 /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AED73DC62303E57C00ECDB64 /* libSDL2.a */; }; @@ -833,7 +834,7 @@ AE7B9070235A53D800145C6A /* gl_context.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gl_context.h; sourceTree = ""; }; AE7B9071235A53D800145C6A /* osx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = osx.cpp; sourceTree = ""; }; AE7B9072235A53D800145C6A /* osx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = osx.h; sourceTree = ""; }; - AE7B9075235A53D800145C6A /* swicher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = swicher.cpp; sourceTree = ""; }; + AE7B9075235A53D800145C6A /* switcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = switcher.cpp; sourceTree = ""; }; AE80EDB62157D4D500F7800F /* serialize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = serialize.cpp; path = ../../../core/serialize.cpp; sourceTree = ""; }; AE80EDB92157D4E600F7800F /* naomi.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = naomi.cpp; sourceTree = ""; }; AE80EDBA2157D4E600F7800F /* naomi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = naomi.h; sourceTree = ""; }; @@ -848,6 +849,7 @@ AE8C273E21122E2500D4D8F4 /* xbrz.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xbrz.h; sourceTree = ""; }; AE8C273F21122E2500D4D8F4 /* xbrz_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xbrz_config.h; sourceTree = ""; }; AE8C274021122E2500D4D8F4 /* xbrz_tools.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xbrz_tools.h; sourceTree = ""; }; + AE90679A235B6F6400CE473C /* gl_context.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gl_context.cpp; sourceTree = ""; }; AED73BAD22FC0E9600ECDB64 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../../../core/README.md; sourceTree = ""; }; AED73DC02303E19100ECDB64 /* sdl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sdl.cpp; sourceTree = ""; }; AED73DC12303E19100ECDB64 /* sdl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sdl.h; sourceTree = ""; }; @@ -2117,9 +2119,10 @@ AE7B906A235A53D800145C6A /* context.h */, AE7B906F235A53D800145C6A /* gl4funcs.cpp */, AE7B9070235A53D800145C6A /* gl_context.h */, + AE90679A235B6F6400CE473C /* gl_context.cpp */, AE7B9071235A53D800145C6A /* osx.cpp */, AE7B9072235A53D800145C6A /* osx.h */, - AE7B9075235A53D800145C6A /* swicher.cpp */, + AE7B9075235A53D800145C6A /* switcher.cpp */, ); name = wsi; path = ../../../core/wsi; @@ -2720,7 +2723,7 @@ 84B7BEB31B72720200F9733F /* coreio.cpp in Sources */, AED73ECA234E827400ECDB64 /* drawer.cpp in Sources */, 84B7BF281B72720200F9733F /* dsp.cpp in Sources */, - AE7B907F235A53D800145C6A /* swicher.cpp in Sources */, + AE7B907F235A53D800145C6A /* switcher.cpp in Sources */, 84B7BF3D1B72720200F9733F /* Renderer_if.cpp in Sources */, AED73E6F2348E45000ECDB64 /* PpAtom.cpp in Sources */, 84B7BF191B72720200F9733F /* deflate.c in Sources */, @@ -2809,6 +2812,7 @@ 84B7BEB91B72720200F9733F /* elf.cpp in Sources */, 84B7BF2B1B72720200F9733F /* arm_mem.cpp in Sources */, 84B7BF4F1B72720200F9733F /* rtc.cpp in Sources */, + AE90679B235B6F6400CE473C /* gl_context.cpp in Sources */, AED73EC12348E49900ECDB64 /* imgui_impl_vulkan.cpp in Sources */, AED73E612348E45000ECDB64 /* InfoSink.cpp in Sources */, 84B7BF361B72720200F9733F /* maple_helper.cpp in Sources */,