From 6007cebe8ac49ca4f3d09b6bed5e3d41a197221a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 3 Sep 2016 02:31:07 +0300 Subject: Add option for create custom OpenGL context. By default this option disabled, because may create issues. --- src/defaults.cpp | 1 + src/graphicsmanager.cpp | 2 +- src/gui/widgets/tabs/setup_perfomance.cpp | 4 ++++ src/render/graphics.cpp | 6 +++--- src/render/graphics.h | 4 ++-- src/render/mobileopengl2graphics.cpp | 4 ++-- src/render/mobileopengl2graphics.h | 2 +- src/render/modernopenglgraphics.cpp | 15 +++++++++++---- src/render/modernopenglgraphics.h | 2 +- 9 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/defaults.cpp b/src/defaults.cpp index 2a6d96cb5..bd4ea9224 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -387,6 +387,7 @@ DefaultsData* getConfigDefaults() AddDEF("enableTradeFilter", true); AddDEF("enableIdCollecting", false); AddDEF("checkOpenGLVersion", true); + AddDEF("openglContext", false); return configData; } diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index 4b0bae9a5..28a7bd9fa 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -184,7 +184,7 @@ int GraphicsManager::detectGraphics() SDL_Window *const window = createWindow(100, 100, 0, SDL_ANYFORMAT | SDL_OPENGL); mainGraphics->setWindow(window, 100, 100); - mainGraphics->createGLContext(); + mainGraphics->createGLContext(false); initOpenGL(); logVersion(); diff --git a/src/gui/widgets/tabs/setup_perfomance.cpp b/src/gui/widgets/tabs/setup_perfomance.cpp index c62346f8f..25f25a4c7 100644 --- a/src/gui/widgets/tabs/setup_perfomance.cpp +++ b/src/gui/widgets/tabs/setup_perfomance.cpp @@ -92,6 +92,10 @@ Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) : new SetupItemCheckBox(_("Enable texture sampler (OpenGL)"), "", "useTextureSampler", this, "useTextureSamplerEvent"); + // TRANSLATORS: settings option + new SetupItemCheckBox(_("Enable OpenGL context creation"), + "", "openglContext", this, "openglContextEvent"); + // TRANSLATORS: settings option new SetupItemLabel(_("Better quality (disable for better performance)"), diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp index bc08ecfd3..59524d300 100644 --- a/src/render/graphics.cpp +++ b/src/render/graphics.cpp @@ -288,10 +288,10 @@ bool Graphics::setOpenGLMode() restrict2 mRect.w = CAST_S32(w1 / mScale); mRect.h = CAST_S32(h1 / mScale); - createGLContext(); + createGLContext(config.getBoolValue("openglContext")); #else // USE_SDL2 - createGLContext(); + createGLContext(config.getBoolValue("openglContext")); mRect.w = CAST_U16(mWindow->w / mScale); mRect.h = CAST_U16(mWindow->h / mScale); @@ -389,7 +389,7 @@ int Graphics::getSoftwareFlags() const restrict2 } #ifdef USE_OPENGL -void Graphics::createGLContext() restrict2 +void Graphics::createGLContext(const bool custom A_UNUSED) restrict2 { #ifdef USE_SDL2 mGLContext = SDL_GL_CreateContext(mWindow); diff --git a/src/render/graphics.h b/src/render/graphics.h index 016f2c4ab..997ed2196 100644 --- a/src/render/graphics.h +++ b/src/render/graphics.h @@ -404,9 +404,9 @@ class Graphics notfinal #ifdef USE_OPENGL #ifdef USE_SDL2 - virtual void createGLContext() restrict2; + virtual void createGLContext(const bool custom) restrict2; #else - virtual void createGLContext() restrict2 A_CONST; + virtual void createGLContext(const bool custom) restrict2 A_CONST; #endif #endif diff --git a/src/render/mobileopengl2graphics.cpp b/src/render/mobileopengl2graphics.cpp index 163185bb6..576bc67ab 100644 --- a/src/render/mobileopengl2graphics.cpp +++ b/src/render/mobileopengl2graphics.cpp @@ -1227,9 +1227,9 @@ void MobileOpenGL2Graphics::clearScreen() const restrict2 GL_STENCIL_BUFFER_BIT); } -void MobileOpenGL2Graphics::createGLContext() restrict2 +void MobileOpenGL2Graphics::createGLContext(const bool custom) restrict2 { - Graphics::createGLContext(); + Graphics::createGLContext(custom); /* if (mGLContext) SDL::makeCurrentContext(mGLContext); diff --git a/src/render/mobileopengl2graphics.h b/src/render/mobileopengl2graphics.h index 9b171becb..2efa367c4 100644 --- a/src/render/mobileopengl2graphics.h +++ b/src/render/mobileopengl2graphics.h @@ -77,7 +77,7 @@ class MobileOpenGL2Graphics final : public Graphics uint32_t *restrict const arr) restrict2 override final A_NONNULL(3); - void createGLContext() restrict2 override final; + void createGLContext(const bool custom) restrict2 override final; #include "render/graphicsdef.hpp" RENDER_GRAPHICSDEF_HPP diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp index 458a9a9f7..1629dbea5 100644 --- a/src/render/modernopenglgraphics.cpp +++ b/src/render/modernopenglgraphics.cpp @@ -1221,12 +1221,19 @@ void ModernOpenGLGraphics::clearScreen() const restrict2 GL_STENCIL_BUFFER_BIT); } -void ModernOpenGLGraphics::createGLContext() restrict2 +void ModernOpenGLGraphics::createGLContext(const bool custom) restrict2 { - if (mGLContext) - SDL::makeCurrentContext(mGLContext); + if (custom) + { + if (mGLContext) + SDL::makeCurrentContext(mGLContext); + else + mGLContext = SDL::createGLContext(mWindow, 3, 3, 0x01); + } else - mGLContext = SDL::createGLContext(mWindow, 3, 3, 0x01); + { + Graphics::createGLContext(false); + } } void ModernOpenGLGraphics::finalize(ImageCollection *restrict const col) diff --git a/src/render/modernopenglgraphics.h b/src/render/modernopenglgraphics.h index f7eecd0c4..53d6966c2 100644 --- a/src/render/modernopenglgraphics.h +++ b/src/render/modernopenglgraphics.h @@ -77,7 +77,7 @@ class ModernOpenGLGraphics final : public Graphics uint32_t *restrict const arr) restrict2 override final A_NONNULL(3); - void createGLContext() restrict2 override final; + void createGLContext(const bool custom) restrict2 override final; #include "render/graphicsdef.hpp" RENDER_GRAPHICSDEF_HPP -- cgit v1.2.3-60-g2f50