From 008fa23d5ff6bc652028774e496fba8e11f0577c Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 10 Apr 2022 14:54:21 +0200 Subject: [PATCH] Added a setting to define the OpenGL version to use. --- es-core/src/Settings.cpp | 1 + es-core/src/renderers/RendererOpenGL.cpp | 64 ++++++++++++++++++++---- es-core/src/renderers/RendererOpenGL.h | 3 ++ 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 656dff342..480cbbebd 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -279,6 +279,7 @@ void Settings::setDefaults() // mBoolMap["DebugSkipInputLogging"] = {false, false}; + mStringMap["OpenGLVersion"] = {"", ""}; mStringMap["ROMDirectory"] = {"", ""}; mStringMap["UIMode_passkey"] = {"uuddlrlrba", "uuddlrlrba"}; mIntMap["LottieMaxFileCache"] = {150, 150}; diff --git a/es-core/src/renderers/RendererOpenGL.cpp b/es-core/src/renderers/RendererOpenGL.cpp index 97c3845f9..2093adc30 100644 --- a/es-core/src/renderers/RendererOpenGL.cpp +++ b/es-core/src/renderers/RendererOpenGL.cpp @@ -28,6 +28,8 @@ RendererOpenGL::RendererOpenGL() noexcept , mBlurVerticalShader {nullptr} , mScanlinelShader {nullptr} , mLastShader {nullptr} + , mMajorGLVersion {0} + , mMinorGLVersion {0} { } @@ -128,16 +130,55 @@ GLenum RendererOpenGL::convertTextureType(const TextureType type) void RendererOpenGL::setup() { + std::string glVersion {Settings::getInstance()->getString("OpenGLVersion")}; + #if defined(USE_OPENGLES) + if (glVersion == "" || glVersion == "3.0") { + mMajorGLVersion = 3; + mMinorGLVersion = 0; + } + else if (glVersion == "3.1") { + mMajorGLVersion = 3; + mMinorGLVersion = 1; + } + else if (glVersion == "3.2") { + mMajorGLVersion = 3; + mMinorGLVersion = 2; + } + else { + LOG(LogWarning) << "Unsupported OpenGL ES version \"" << glVersion + << "\" requested, defaulting to 3.0 (valid versions are 3.0, 3.1 and 3.2)"; + mMajorGLVersion = 3; + mMinorGLVersion = 0; + } + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); #else + if (glVersion == "" || glVersion == "3.3") { + mMajorGLVersion = 3; + mMinorGLVersion = 3; + } + else if (glVersion == "4.2") { + mMajorGLVersion = 4; + mMinorGLVersion = 2; + } + else if (glVersion == "4.6") { + mMajorGLVersion = 4; + mMinorGLVersion = 6; + } + else { + LOG(LogWarning) << "Unsupported OpenGL version \"" << glVersion + << "\" requested, defaulting to 3.3 (valid versions are 3.3, 4.2 and 4.6)"; + mMajorGLVersion = 3; + mMinorGLVersion = 3; + } + 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); #endif + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, mMajorGLVersion); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, mMinorGLVersion); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); @@ -170,12 +211,17 @@ bool RendererOpenGL::createContext() LOG(LogInfo) << "GL vendor: " << vendor; LOG(LogInfo) << "GL renderer: " << renderer; LOG(LogInfo) << "GL version: " << version; -#if defined(_WIN64) - LOG(LogInfo) << "EmulationStation renderer: OpenGL 3.3 with GLEW"; -#elif defined(USE_OPENGLES) - LOG(LogInfo) << "EmulationStation renderer: OpenGL ES 3.0"; +#if defined(USE_OPENGLES) + LOG(LogInfo) << "EmulationStation renderer: OpenGL ES " << mMajorGLVersion << "." + << mMinorGLVersion; #else - LOG(LogInfo) << "EmulationStation renderer: OpenGL 3.3"; +#if defined(_WIN64) + LOG(LogInfo) << "EmulationStation renderer: OpenGL " << mMajorGLVersion << "." + << mMinorGLVersion << " with GLEW"; +#else + LOG(LogInfo) << "EmulationStation renderer: OpenGL " << mMajorGLVersion << "." + << mMinorGLVersion; +#endif #endif GL_CHECK_ERROR(glClearColor(0.0f, 0.0f, 0.0f, 1.0f)); diff --git a/es-core/src/renderers/RendererOpenGL.h b/es-core/src/renderers/RendererOpenGL.h index ecaf6f7e4..ec3a4d7ed 100644 --- a/es-core/src/renderers/RendererOpenGL.h +++ b/es-core/src/renderers/RendererOpenGL.h @@ -87,6 +87,9 @@ private: ShaderOpenGL* mBlurVerticalShader; ShaderOpenGL* mScanlinelShader; ShaderOpenGL* mLastShader; + + int mMajorGLVersion; + int mMinorGLVersion; }; #endif // ES_CORE_RENDERER_RENDERER_OPENGL_H