diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index 3c5b4ef9a..b1803576d 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -102,7 +102,7 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -void GlContext::Initialize() +void GlContext::GlobalInit() { // Create the shared context sharedContext = new ContextType(NULL); @@ -115,7 +115,7 @@ void GlContext::Initialize() //////////////////////////////////////////////////////////// -void GlContext::Cleanup() +void GlContext::GlobalCleanup() { // Destroy the shared context delete sharedContext; @@ -141,7 +141,10 @@ void GlContext::EnsureContext() //////////////////////////////////////////////////////////// GlContext* GlContext::New() { - return new ContextType(sharedContext); + GlContext* context = new ContextType(sharedContext); + context->Initialize(); + + return context; } @@ -153,10 +156,7 @@ GlContext* GlContext::New(const ContextSettings& settings, const WindowImpl* own // Create the context GlContext* context = new ContextType(sharedContext, settings, owner, bitsPerPixel); - - // Enable antialiasing if needed - if (context->GetSettings().AntialiasingLevel > 0) - glEnable(GL_MULTISAMPLE_ARB); + context->Initialize(); return context; } @@ -170,10 +170,7 @@ GlContext* GlContext::New(const ContextSettings& settings, unsigned int width, u // Create the context GlContext* context = new ContextType(sharedContext, settings, width, height); - - // Enable antialiasing if needed - if (context->GetSettings().AntialiasingLevel > 0) - glEnable(GL_MULTISAMPLE_ARB); + context->Initialize(); return context; } @@ -253,6 +250,33 @@ int GlContext::EvaluateFormat(unsigned int bitsPerPixel, const ContextSettings& std::abs(static_cast(settings.AntialiasingLevel - antialiasing)); } + +//////////////////////////////////////////////////////////// +void GlContext::Initialize() +{ + // Activate the context + SetActive(true); + + // Retrieve the context version number + const GLubyte* version = glGetString(GL_VERSION); + if (version) + { + // The beginning of the returned string is "major.minor" (this is standard) + mySettings.MajorVersion = version[0] - '0'; + mySettings.MinorVersion = version[2] - '0'; + } + else + { + // Can't get the version number, assume 2.0 + mySettings.MajorVersion = 2; + mySettings.MinorVersion = 0; + } + + // Enable antialiasing if needed + if (mySettings.AntialiasingLevel > 0) + glEnable(GL_MULTISAMPLE_ARB); +} + } // namespace priv } // namespace sf diff --git a/src/SFML/Window/GlContext.hpp b/src/SFML/Window/GlContext.hpp index dab762f30..f6eb193a0 100644 --- a/src/SFML/Window/GlContext.hpp +++ b/src/SFML/Window/GlContext.hpp @@ -57,7 +57,7 @@ public : /// can be called only once. /// //////////////////////////////////////////////////////////// - static void Initialize(); + static void GlobalInit(); //////////////////////////////////////////////////////////// /// \brief Perform the global cleanup @@ -69,7 +69,7 @@ public : /// can be called only once. /// //////////////////////////////////////////////////////////// - static void Cleanup(); + static void GlobalCleanup(); //////////////////////////////////////////////////////////// /// \brief Ensures that an OpenGL context is active in the current thread @@ -217,6 +217,14 @@ protected : // Member data //////////////////////////////////////////////////////////// ContextSettings mySettings; ///< Creation settings of the context + +private: + + //////////////////////////////////////////////////////////// + /// \brief Perform various initializations after the context construction + /// + //////////////////////////////////////////////////////////// + void Initialize(); }; } // namespace priv diff --git a/src/SFML/Window/GlResource.cpp b/src/SFML/Window/GlResource.cpp index d06a8fc98..a0fa41aa4 100644 --- a/src/SFML/Window/GlResource.cpp +++ b/src/SFML/Window/GlResource.cpp @@ -54,7 +54,7 @@ GlResource::GlResource() // If this is the very first resource, trigger the global context initialization if (count == 0) - priv::GlContext::Initialize(); + priv::GlContext::GlobalInit(); // Increment the resources counter count++; @@ -76,7 +76,7 @@ GlResource::~GlResource() // If there's no more resource alive, we can trigger the global context cleanup if (count == 0) - priv::GlContext::Cleanup(); + priv::GlContext::GlobalCleanup(); } diff --git a/src/SFML/Window/Linux/GlxContext.cpp b/src/SFML/Window/Linux/GlxContext.cpp index 36ee48abc..08c62aca4 100644 --- a/src/SFML/Window/Linux/GlxContext.cpp +++ b/src/SFML/Window/Linux/GlxContext.cpp @@ -60,9 +60,6 @@ myOwnsWindow(true) // Create the context CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings()); - - // Activate the context - SetActive(true); } @@ -81,9 +78,6 @@ myOwnsWindow(false) // Create the context if (myWindow) CreateContext(shared, bitsPerPixel, settings); - - // Activate the context - SetActive(true); } @@ -110,9 +104,6 @@ myOwnsWindow(true) // Create the context CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, settings); - - // Activate the context - SetActive(true); } diff --git a/src/SFML/Window/OSX/SFContext.hpp b/src/SFML/Window/OSX/SFContext.hpp index dcc38ebdb..c49e482fa 100644 --- a/src/SFML/Window/OSX/SFContext.hpp +++ b/src/SFML/Window/OSX/SFContext.hpp @@ -150,13 +150,6 @@ private: unsigned int bitsPerPixel, const ContextSettings& settings); - //////////////////////////////////////////////////////////// - /// \brief Finish updating our settings - /// \note The context must be active in order to get the OpenGL version. - /// - //////////////////////////////////////////////////////////// - void UpdateOpenGLVersion(); - //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/OSX/SFContext.mm b/src/SFML/Window/OSX/SFContext.mm index dc35f87d3..4f05b0df9 100644 --- a/src/SFML/Window/OSX/SFContext.mm +++ b/src/SFML/Window/OSX/SFContext.mm @@ -57,12 +57,6 @@ SFContext::SFContext(SFContext* shared) // Create the context CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings(0, 0, 0)); - - // Activate the context - SetActive(true); - - // Finish updating settings. - UpdateOpenGLVersion(); } @@ -79,12 +73,6 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings, // Apply context. WindowImplCocoa const * ownerCocoa = static_cast(owner); ownerCocoa->ApplyContext(myContext); - - // Activate the context - SetActive(true); - - // Finish updating settings. - UpdateOpenGLVersion(); } @@ -109,12 +97,6 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings, [myWindow setContentView:myView]; [myView setOpenGLContext:myContext]; [myContext setView:myView]; - - // Activate the context - SetActive(true); - - // Finish updating settings. - UpdateOpenGLVersion(); } @@ -224,33 +206,6 @@ void SFContext::CreateContext(SFContext* shared, mySettings = settings; } - -//////////////////////////////////////////////////////////// -void SFContext::UpdateOpenGLVersion() -{ - // Update the OpenGL version in the settings. - // NB : the context muste be active to get its version. - - GLubyte const* versionString = glGetString(GL_VERSION); - - if (versionString == 0) { - - // (Warning) Couldn't get the OpenGL version of the context. - // This happens sometimes (but not always) when creating the first - // context for no apparent reason. - - // We assume we can get at least a 2.0 valid context. - mySettings.MajorVersion = 2; - mySettings.MinorVersion = 0; - - } else { - - // versionString looks like "2.1 NVIDIA-1.6.26". - mySettings.MajorVersion = versionString[0]; - mySettings.MinorVersion = versionString[2]; - } -} - } // namespace priv } // namespace sf diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index ad8b3dc8b..295ca2d19 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -56,9 +56,6 @@ myOwnsWindow (true) // Create the context if (myDeviceContext) CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, ContextSettings()); - - // Activate the context - SetActive(true); } @@ -76,9 +73,6 @@ myOwnsWindow (false) // Create the context if (myDeviceContext) CreateContext(shared, bitsPerPixel, settings); - - // Activate the context - SetActive(true); } @@ -102,9 +96,6 @@ myOwnsWindow (true) // Create the context if (myDeviceContext) CreateContext(shared, VideoMode::GetDesktopMode().BitsPerPixel, settings); - - // Activate the context - SetActive(true); }