From 4220f69c06539b338317301abfef3f28117ea6bd Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:52:47 -0700 Subject: [PATCH] renderer/opengl: Deduce GLES from actual driver in use. (#7056) --- src/video_core/renderer_opengl/gl_driver.cpp | 13 +++++++++++-- src/video_core/renderer_opengl/gl_driver.h | 1 + src/video_core/renderer_opengl/renderer_opengl.cpp | 5 ++--- src/video_core/video_core.cpp | 3 --- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_driver.cpp b/src/video_core/renderer_opengl/gl_driver.cpp index 1894d44ef..cddd915aa 100644 --- a/src/video_core/renderer_opengl/gl_driver.cpp +++ b/src/video_core/renderer_opengl/gl_driver.cpp @@ -8,6 +8,7 @@ #include "core/telemetry_session.h" #include "video_core/custom_textures/custom_format.h" #include "video_core/renderer_opengl/gl_driver.h" +#include "video_core/renderer_opengl/gl_vars.h" namespace OpenGL { @@ -74,8 +75,7 @@ static void APIENTRY DebugHandler(GLenum source, GLenum type, GLuint id, GLenum GetType(type), id, message); } -Driver::Driver(Core::TelemetrySession& telemetry_session_) - : telemetry_session{telemetry_session_}, is_gles{Settings::values.use_gles.GetValue()} { +Driver::Driver(Core::TelemetrySession& telemetry_session_) : telemetry_session{telemetry_session_} { const bool enable_debug = Settings::values.renderer_debug.GetValue(); if (enable_debug) { glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); @@ -83,6 +83,7 @@ Driver::Driver(Core::TelemetrySession& telemetry_session_) } ReportDriverInfo(); + DeduceGLES(); DeduceVendor(); CheckExtensionSupport(); FindBugs(); @@ -142,6 +143,14 @@ void Driver::ReportDriverInfo() { telemetry_session.AddField(user_system, "GPU_OpenGL_Version", std::string{gl_version}); } +void Driver::DeduceGLES() { + // According to the spec, all GLES version strings must start with "OpenGL ES". + is_gles = gl_version.starts_with("OpenGL ES"); + + // TODO: Eliminate this global state and replace with driver references. + OpenGL::GLES = is_gles; +} + void Driver::DeduceVendor() { if (gpu_vendor.find("NVIDIA") != gpu_vendor.npos) { vendor = Vendor::Nvidia; diff --git a/src/video_core/renderer_opengl/gl_driver.h b/src/video_core/renderer_opengl/gl_driver.h index 0a82b0af5..62c6ee2ce 100644 --- a/src/video_core/renderer_opengl/gl_driver.h +++ b/src/video_core/renderer_opengl/gl_driver.h @@ -117,6 +117,7 @@ public: private: void ReportDriverInfo(); + void DeduceGLES(); void DeduceVendor(); void CheckExtensionSupport(); void FindBugs(); diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index a4736c4cf..f94109378 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -13,7 +13,6 @@ #include "core/memory.h" #include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_texture_mailbox.h" -#include "video_core/renderer_opengl/gl_vars.h" #include "video_core/renderer_opengl/post_processing_opengl.h" #include "video_core/renderer_opengl/renderer_opengl.h" #include "video_core/shader/generator/glsl_shader_gen.h" @@ -459,7 +458,7 @@ void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture, case GPU::Regs::PixelFormat::RGBA8: internal_format = GL_RGBA; texture.gl_format = GL_RGBA; - texture.gl_type = GLES ? GL_UNSIGNED_BYTE : GL_UNSIGNED_INT_8_8_8_8; + texture.gl_type = driver.IsOpenGLES() ? GL_UNSIGNED_BYTE : GL_UNSIGNED_INT_8_8_8_8; break; case GPU::Regs::PixelFormat::RGB8: @@ -470,7 +469,7 @@ void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture, internal_format = GL_RGB; // GLES Dosen't support BGR , Use RGB instead - texture.gl_format = GLES ? GL_RGB : GL_BGR; + texture.gl_format = driver.IsOpenGLES() ? GL_RGB : GL_BGR; texture.gl_type = GL_UNSIGNED_BYTE; break; diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index c836e7372..e8f090a0f 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -11,7 +11,6 @@ #include "video_core/pica.h" #include "video_core/pica_state.h" #include "video_core/renderer_base.h" -#include "video_core/renderer_opengl/gl_vars.h" #include "video_core/renderer_opengl/renderer_opengl.h" #include "video_core/renderer_software/renderer_software.h" #include "video_core/renderer_vulkan/renderer_vulkan.h" @@ -34,8 +33,6 @@ void Init(Frontend::EmuWindow& emu_window, Frontend::EmuWindow* secondary_window Pica::Init(); const Settings::GraphicsAPI graphics_api = Settings::values.graphics_api.GetValue(); - OpenGL::GLES = Settings::values.use_gles.GetValue(); - switch (graphics_api) { case Settings::GraphicsAPI::Software: g_renderer = std::make_unique(system, emu_window);