From 36062905855378cef662c6002c0e71f4c985ae4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 24 Dec 2017 13:35:54 -0300 Subject: [PATCH] Make shared gl context optional. --HG-- branch : dev --- bin/assets/ee.ini | 1 + include/eepp/window/window.hpp | 9 ++++++--- src/eepp/window/backend/SDL2/windowsdl2.cpp | 14 +++++++++----- src/eepp/window/engine.cpp | 5 +++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/bin/assets/ee.ini b/bin/assets/ee.ini index cc577477b..5c170f4c9 100755 --- a/bin/assets/ee.ini +++ b/bin/assets/ee.ini @@ -8,6 +8,7 @@ Resizeable = 1 WinIcon = assets/icon/ee.png VSync = 1 GLVersion = Default +SharedGLContext = 0 Backend = Default JoystickEnabled = 0 ParticlesNum = 1000 diff --git a/include/eepp/window/window.hpp b/include/eepp/window/window.hpp index 55a2a2bde..6914b54df 100644 --- a/include/eepp/window/window.hpp +++ b/include/eepp/window/window.hpp @@ -79,13 +79,14 @@ class WindowSettings { class ContextSettings { public: - inline ContextSettings( bool vsync, EEGL_version version = GLv_default, bool doubleBuffering = true, Uint32 depthBufferSize = 24, Uint32 stencilBufferSize = 1, Uint32 multisamples = 0 ) : + inline ContextSettings( bool vsync, EEGL_version version = GLv_default, bool doubleBuffering = true, Uint32 depthBufferSize = 24, Uint32 stencilBufferSize = 1, Uint32 multisamples = 0, bool sharedGLContext = true ) : Version( version ), DepthBufferSize( depthBufferSize ), StencilBufferSize( stencilBufferSize ), Multisamples( multisamples ), VSync( vsync ), - DoubleBuffering( doubleBuffering ) + DoubleBuffering( doubleBuffering ), + SharedGLContext( sharedGLContext ) {} inline ContextSettings() : @@ -94,7 +95,8 @@ class ContextSettings { StencilBufferSize( 1 ), Multisamples( 0 ), VSync( false ), - DoubleBuffering( true ) + DoubleBuffering( true ), + SharedGLContext( true ) {} EEGL_version Version; @@ -103,6 +105,7 @@ class ContextSettings { Uint32 Multisamples; bool VSync; bool DoubleBuffering; + bool SharedGLContext; }; /** @brief WindowInfo Contains the window state information */ diff --git a/src/eepp/window/backend/SDL2/windowsdl2.cpp b/src/eepp/window/backend/SDL2/windowsdl2.cpp index ed055ecf9..bcc910bf8 100644 --- a/src/eepp/window/backend/SDL2/windowsdl2.cpp +++ b/src/eepp/window/backend/SDL2/windowsdl2.cpp @@ -220,17 +220,21 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) { #endif #ifdef SDL2_THREADED_GLCONTEXT - SDL_GL_SetAttribute( SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1 ); + if ( mWindow.ContextConfig.SharedGLContext ) { + SDL_GL_SetAttribute( SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1 ); - mGLContext = SDL_GL_CreateContext( mSDLWindow ); - mGLContextThread = SDL_GL_CreateContext( mSDLWindow ); + mGLContext = SDL_GL_CreateContext( mSDLWindow ); + mGLContextThread = SDL_GL_CreateContext( mSDLWindow ); + } else { + mGLContext = SDL_GL_CreateContext( mSDLWindow ); + } #else mGLContext = SDL_GL_CreateContext( mSDLWindow ); #endif if ( NULL == mGLContext #ifdef SDL2_THREADED_GLCONTEXT - || NULL == mGLContextThread + || ( mWindow.ContextConfig.SharedGLContext && NULL == mGLContextThread ) #endif ) { @@ -281,7 +285,7 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) { bool WindowSDL::isThreadedGLContext() { #ifdef SDL2_THREADED_GLCONTEXT - return true; + return mWindow.ContextConfig.SharedGLContext; #else return false; #endif diff --git a/src/eepp/window/engine.cpp b/src/eepp/window/engine.cpp index 356e92161..96a0ff139 100755 --- a/src/eepp/window/engine.cpp +++ b/src/eepp/window/engine.cpp @@ -307,8 +307,9 @@ ContextSettings Engine::createContextSettings( IniFile * ini, std::string iniKey int depthBufferSize = ini->getValueI( iniKeyName, "DepthBufferSize", 24 ); int stencilBufferSize = ini->getValueI( iniKeyName, "StencilBufferSize", 1 ); int multisamples = ini->getValueI( iniKeyName, "Multisamples", 0 ); + bool sharedGLContext = ini->getValueB( iniKeyName, "SharedGLContext", false ); - return ContextSettings( VSync, GLVer, doubleBuffering, depthBufferSize, stencilBufferSize, multisamples ); + return ContextSettings( VSync, GLVer, doubleBuffering, depthBufferSize, stencilBufferSize, multisamples, sharedGLContext ); } ContextSettings Engine::createContextSettings( std::string iniPath, std::string iniKeyName ) { @@ -326,7 +327,7 @@ void Engine::disableSharedGLContext() { } bool Engine::isSharedGLContextEnabled() { - return mSharedGLContext; + return mSharedGLContext && mWindow->isThreadedGLContext(); } Uint32 Engine::getMainThreadId() {