From ccff34b431797b0594742dd09eab7ec75ab4c0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 26 Jul 2026 18:29:32 +0200 Subject: [PATCH 1/2] Reuse the AndroidJavaGLContext as the new generic OpenGLGraphicsContext --- CMakeLists.txt | 2 -- Common/CMakeLists.txt | 2 ++ Common/Common.vcxproj | 2 ++ Common/Common.vcxproj.filters | 6 ++++++ .../GPU/OpenGL/OpenGLGraphicsContext.cpp | 16 ++++++++-------- .../GPU/OpenGL/OpenGLGraphicsContext.h | 6 +++--- Windows/PPSSPP.vcxproj | 16 ---------------- Windows/PPSSPP.vcxproj.filters | 6 ------ android/jni/Android.mk | 4 ++-- android/jni/app-android.cpp | 5 ++--- 10 files changed, 25 insertions(+), 40 deletions(-) rename android/jni/AndroidJavaGLContext.cpp => Common/GPU/OpenGL/OpenGLGraphicsContext.cpp (71%) rename android/jni/AndroidJavaGLContext.h => Common/GPU/OpenGL/OpenGLGraphicsContext.h (84%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 108c4e5570..ce693a0ae7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -909,8 +909,6 @@ endif() if(ANDROID) list(APPEND AndroidJniSource android/jni/app-android.cpp - android/jni/AndroidJavaGLContext.cpp - android/jni/AndroidJavaGLContext.h android/jni/AndroidAudio.cpp android/jni/AndroidAudio.h android/jni/OpenSLContext.cpp diff --git a/Common/CMakeLists.txt b/Common/CMakeLists.txt index 806c379841..5e1872ac30 100644 --- a/Common/CMakeLists.txt +++ b/Common/CMakeLists.txt @@ -170,6 +170,8 @@ add_library(Common STATIC GPU/OpenGL/GLProfiler.h GPU/OpenGL/DataFormatGL.cpp GPU/OpenGL/DataFormatGL.h + GPU/OpenGL/OpenGLGraphicsContext.cpp + GPU/OpenGL/OpenGLGraphicsContext.h GPU/Vulkan/VulkanBarrier.cpp GPU/Vulkan/VulkanBarrier.h GPU/Vulkan/VulkanDebug.cpp diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 7586f14964..af5fee50f9 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -442,6 +442,7 @@ + @@ -924,6 +925,7 @@ + diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index d5fd69f5bb..326a9bcf80 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -792,6 +792,9 @@ GPU\Vulkan + + GPU\OpenGL + @@ -1463,6 +1466,9 @@ GPU\Vulkan + + GPU\OpenGL + diff --git a/android/jni/AndroidJavaGLContext.cpp b/Common/GPU/OpenGL/OpenGLGraphicsContext.cpp similarity index 71% rename from android/jni/AndroidJavaGLContext.cpp rename to Common/GPU/OpenGL/OpenGLGraphicsContext.cpp index 25a4110bf1..9ae1f1471a 100644 --- a/android/jni/AndroidJavaGLContext.cpp +++ b/Common/GPU/OpenGL/OpenGLGraphicsContext.cpp @@ -1,26 +1,26 @@ -#include "AndroidJavaGLContext.h" +#include "OpenGLGraphicsContext.h" #include "Common/System/Display.h" #include "Common/GPU/OpenGL/GLFeatures.h" #include "Common/Log.h" -#include "Core/Config.h" #include "Core/ConfigValues.h" #include "Core/System.h" +#include "Core/Config.h" -AndroidJavaEGLGraphicsContext::AndroidJavaEGLGraphicsContext() { +OpenGLGraphicsContext::OpenGLGraphicsContext() { SetGPUBackend(GPUBackend::OPENGL); + // OpenGL handles rotated rendering in the driver. g_display.rotation = DisplayRotation::ROTATE_0; g_display.rot_matrix.setIdentity(); } -bool AndroidJavaEGLGraphicsContext::InitSurface(WindowSystem winsys, void *data1, void *data2, std::string *errorMessage) { - INFO_LOG(Log::G3D, "AndroidJavaEGLGraphicsContext::InitFromRenderThread"); +bool OpenGLGraphicsContext::InitSurface(WindowSystem winsys, void *data1, void *data2, std::string *errorMessage) { + INFO_LOG(Log::G3D, "OpenGLGraphicsContext::InitSurface"); if (!CheckGLExtensions()) { *errorMessage = "CheckExtensions failed"; ERROR_LOG(Log::G3D, "CheckGLExtensions failed - not gonna attempt starting up."); return false; } - draw_ = Draw::T3DCreateGLContext(false); // Can't fail renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); renderManager_->SetInflightFrames(g_Config.iInflightFrames); @@ -33,8 +33,8 @@ bool AndroidJavaEGLGraphicsContext::InitSurface(WindowSystem winsys, void *data1 return true; } -void AndroidJavaEGLGraphicsContext::ShutdownSurface() { - INFO_LOG(Log::G3D, "AndroidJavaEGLGraphicsContext::Shutdown"); +void OpenGLGraphicsContext::ShutdownSurface() { + INFO_LOG(Log::G3D, "OpenGLGraphicsContext::Shutdown"); renderManager_ = nullptr; // owned by draw_. delete draw_; draw_ = nullptr; diff --git a/android/jni/AndroidJavaGLContext.h b/Common/GPU/OpenGL/OpenGLGraphicsContext.h similarity index 84% rename from android/jni/AndroidJavaGLContext.h rename to Common/GPU/OpenGL/OpenGLGraphicsContext.h index 2caa142bbc..015514a6eb 100644 --- a/android/jni/AndroidJavaGLContext.h +++ b/Common/GPU/OpenGL/OpenGLGraphicsContext.h @@ -4,10 +4,10 @@ #include "Common/GPU/OpenGL/GLRenderManager.h" #include "Common/GPU/thin3d_create.h" -class AndroidJavaEGLGraphicsContext : public GraphicsContext { +class OpenGLGraphicsContext : public GraphicsContext { public: - AndroidJavaEGLGraphicsContext(); - ~AndroidJavaEGLGraphicsContext() override { delete draw_; } + OpenGLGraphicsContext(); + ~OpenGLGraphicsContext() override { delete draw_; } bool NeedsSeparateEmuThread() const override { return true; } diff --git a/Windows/PPSSPP.vcxproj b/Windows/PPSSPP.vcxproj index 656dcb3d86..595d2af092 100644 --- a/Windows/PPSSPP.vcxproj +++ b/Windows/PPSSPP.vcxproj @@ -411,14 +411,6 @@ - - true - true - true - true - true - true - true true @@ -711,14 +703,6 @@ - - true - true - true - true - true - true - true diff --git a/Windows/PPSSPP.vcxproj.filters b/Windows/PPSSPP.vcxproj.filters index e10e94dd61..faa765ee1a 100644 --- a/Windows/PPSSPP.vcxproj.filters +++ b/Windows/PPSSPP.vcxproj.filters @@ -187,9 +187,6 @@ Windows\Input - - Other Platforms\Android - Other Platforms\Android @@ -397,9 +394,6 @@ Windows\Input - - Other Platforms\Android - Other Platforms\Android diff --git a/android/jni/Android.mk b/android/jni/Android.mk index de4820b749..c7bcc03370 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -127,7 +127,8 @@ NATIVE_FILES :=\ $(SRC)/Common/GPU/OpenGL/GLRenderManager.cpp \ $(SRC)/Common/GPU/OpenGL/GLQueueRunner.cpp \ $(SRC)/Common/GPU/OpenGL/GLProfiler.cpp \ - $(SRC)/Common/GPU/OpenGL/DataFormatGL.cpp + $(SRC)/Common/GPU/OpenGL/DataFormatGL.cpp \ + $(SRC)/Common/GPU/OpenGL/OpenGLGraphicsContext.cpp VULKAN_FILES := \ $(SRC)/Common/GPU/Vulkan/thin3d_vulkan.cpp \ @@ -916,7 +917,6 @@ LOCAL_STATIC_LIBRARIES += ppsspp_common ppsspp_core libarmips libzstd LOCAL_MODULE := ppsspp_jni LOCAL_SRC_FILES := \ $(SRC)/android/jni/app-android.cpp \ - $(SRC)/android/jni/AndroidJavaGLContext.cpp \ $(SRC)/android/jni/AndroidAudio.cpp \ $(SRC)/android/jni/OpenSLContext.cpp \ $(SRC)/UI/ImDebugger/ImDebugger.cpp \ diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 9e576f5ca2..2e014b7e36 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -88,11 +88,10 @@ struct JNIEnv {}; #include "Common/GPU/Vulkan/VulkanLoader.h" #include "Common/GPU/GraphicsContext.h" #include "Common/GPU/Vulkan/VulkanGraphicsContext.h" +#include "Common/GPU/OpenGL/OpenGLGraphicsContext.h" #include "Common/StringUtils.h" #include "Common/TimeUtil.h" -#include "AndroidJavaGLContext.h" - #include "Core/CmdLine.h" #include "Core/Config.h" #include "Core/ConfigValues.h" @@ -779,7 +778,7 @@ retry: switch (g_Config.iGPUBackend) { case (int)GPUBackend::OPENGL: INFO_LOG(Log::System, "NativeApp.init() -- creating OpenGL context (JavaGL)"); - graphicsContext = new AndroidJavaEGLGraphicsContext(); + graphicsContext = new OpenGLGraphicsContext(); INFO_LOG(Log::System, "NativeApp.init() - not yet launching emuthread, waiting to displayInit"); break; case (int)GPUBackend::VULKAN: From 1649d2fcae9260b02bace1cbf9e0f9df9697c5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 26 Jul 2026 20:11:12 +0200 Subject: [PATCH 2/2] Also merge away the iOS GL graphics context --- Common/GPU/OpenGL/OpenGLGraphicsContext.cpp | 15 +---- Common/GPU/OpenGL/OpenGLGraphicsContext.h | 2 + ios/ViewController.mm | 72 ++------------------- 3 files changed, 9 insertions(+), 80 deletions(-) diff --git a/Common/GPU/OpenGL/OpenGLGraphicsContext.cpp b/Common/GPU/OpenGL/OpenGLGraphicsContext.cpp index 9ae1f1471a..6ae331c739 100644 --- a/Common/GPU/OpenGL/OpenGLGraphicsContext.cpp +++ b/Common/GPU/OpenGL/OpenGLGraphicsContext.cpp @@ -8,7 +8,7 @@ OpenGLGraphicsContext::OpenGLGraphicsContext() { SetGPUBackend(GPUBackend::OPENGL); - + CheckGLExtensions(); // OpenGL handles rotated rendering in the driver. g_display.rotation = DisplayRotation::ROTATE_0; g_display.rot_matrix.setIdentity(); @@ -16,20 +16,11 @@ OpenGLGraphicsContext::OpenGLGraphicsContext() { bool OpenGLGraphicsContext::InitSurface(WindowSystem winsys, void *data1, void *data2, std::string *errorMessage) { INFO_LOG(Log::G3D, "OpenGLGraphicsContext::InitSurface"); - if (!CheckGLExtensions()) { - *errorMessage = "CheckExtensions failed"; - ERROR_LOG(Log::G3D, "CheckGLExtensions failed - not gonna attempt starting up."); - return false; - } draw_ = Draw::T3DCreateGLContext(false); // Can't fail renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); renderManager_->SetInflightFrames(g_Config.iInflightFrames); - - if (!draw_->CreatePresets()) { - // This can't really happen now that compilation is async - they're only really queued for compile here. - _assert_msg_(false, "Failed to compile preset shaders"); - return false; - } + const bool result = draw_->CreatePresets(); + _dbg_assert_(result); return true; } diff --git a/Common/GPU/OpenGL/OpenGLGraphicsContext.h b/Common/GPU/OpenGL/OpenGLGraphicsContext.h index 015514a6eb..972e1a9c0c 100644 --- a/Common/GPU/OpenGL/OpenGLGraphicsContext.h +++ b/Common/GPU/OpenGL/OpenGLGraphicsContext.h @@ -4,6 +4,8 @@ #include "Common/GPU/OpenGL/GLRenderManager.h" #include "Common/GPU/thin3d_create.h" +// This one is mainly useful for the backends that already initialize GL in platform-specific code. +// It doesn't have the real initialization that we need to do on some platforms. class OpenGLGraphicsContext : public GraphicsContext { public: OpenGLGraphicsContext(); diff --git a/ios/ViewController.mm b/ios/ViewController.mm index db9dde0913..488b446a52 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -18,7 +18,7 @@ #include "Common/GPU/thin3d.h" #include "Common/GPU/thin3d_create.h" #include "Common/GPU/OpenGL/GLRenderManager.h" -#include "Common/GPU/OpenGL/GLFeatures.h" +#include "Common/GPU/OpenGL/OpenGLGraphicsContext.h" #include "Common/System/Display.h" #include "Common/System/System.h" #include "Common/System/OSD.h" @@ -42,77 +42,13 @@ #error Must be built with ARC, please revise the flags for ViewController.mm to include -fobjc-arc. #endif -class IOSGLESContext : public GraphicsContext { -public: - IOSGLESContext() { - CheckGLExtensions(); - SetGPUBackend(GPUBackend::OPENGL); - } - ~IOSGLESContext() { - delete draw_; - } - - bool InitAPI(void *wnd, std::string *deviceNameSetting, std::string *error_message) override { - // Nothing to do here, we already initialized in the constructor. - return true; - } - bool InitSurface(WindowSystem winsys, void *data1, void *data2, std::string *error_message) override { - draw_ = Draw::T3DCreateGLContext(false); - renderManager_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); - renderManager_->SetInflightFrames(g_Config.iInflightFrames); - bool success = draw_->CreatePresets(); - _assert_msg_(success, "Failed to compile preset shaders"); - return true; - } - - void ShutdownSurface() override { - // Nothing to do here, we already initialized in the constructor. - if (draw_) { - delete draw_; - draw_ = nullptr; - } - renderManager_ = nullptr; - } - void ShutdownAPI() override { - // Nothing to do here. - } - - bool NeedsSeparateEmuThread() const override { return true; } - Draw::DrawContext *GetDrawContext() override { - return draw_; - } - - void Resize() override {} - - void ThreadStart() override { - renderManager_->ThreadStart(draw_); - } - - bool ThreadFrame(bool waitIfEmpty) override { - return renderManager_->ThreadFrame(waitIfEmpty); - } - - void ThreadEnd() override { - renderManager_->ThreadEnd(); - } - -protected: - void BeginShutdown() { - renderManager_->SetSkipGLCalls(); - } - -private: - Draw::DrawContext *draw_; - GLRenderManager *renderManager_; -}; - static std::atomic renderLoopRunning; static std::thread g_emuThread; PPSSPPBaseViewController *sharedViewController; @interface PPSSPPViewControllerGL () { - IOSGLESContext *graphicsContext; + GraphicsContext *graphicsContext; int imageRequestId; NSString *imageFilename; @@ -202,7 +138,7 @@ PPSSPPBaseViewController *sharedViewController; self.view.frame = [screen bounds]; self.view.multipleTouchEnabled = YES; - graphicsContext = new IOSGLESContext(); + graphicsContext = new OpenGLGraphicsContext(); std::string errorMessage; if (!graphicsContext->InitAPI(nullptr, nullptr, &errorMessage)) { @@ -210,7 +146,7 @@ PPSSPPBaseViewController *sharedViewController; } if (!graphicsContext->InitSurface(WINDOWSYSTEM_NONE, nullptr, nullptr, &errorMessage)) { - ERROR_LOG(Log::G3D, "InitAPI failed: %s", errorMessage.c_str()); + ERROR_LOG(Log::G3D, "InitSurface failed: %s", errorMessage.c_str()); } /*self.iCadeView = [[iCadeReaderView alloc] init];