From 97bdf72ce1408d1c2841784667185bd0eccb38c6 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Mon, 12 Jan 2015 18:00:44 +0100 Subject: [PATCH] Adjusted OpenGL and Window example to request a 24-bit instead of a 32-bit depth buffer since it might not be supported on all systems. --- examples/opengl/OpenGL.cpp | 4 ++-- examples/window/Window.cpp | 4 ++-- src/SFML/Window/GlContext.cpp | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index c90080140..c02b9c2c4 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -14,9 +14,9 @@ //////////////////////////////////////////////////////////// int main() { - // Request a 32-bits depth buffer when creating the window + // Request a 24-bits depth buffer when creating the window sf::ContextSettings contextSettings; - contextSettings.depthBits = 32; + contextSettings.depthBits = 24; // Create the main window sf::RenderWindow window(sf::VideoMode(800, 600), "SFML graphics with OpenGL", sf::Style::Default, contextSettings); diff --git a/examples/window/Window.cpp b/examples/window/Window.cpp index 46adf0d3a..3fcea52c6 100644 --- a/examples/window/Window.cpp +++ b/examples/window/Window.cpp @@ -13,9 +13,9 @@ //////////////////////////////////////////////////////////// int main() { - // Request a 32-bits depth buffer when creating the window + // Request a 24-bits depth buffer when creating the window sf::ContextSettings contextSettings; - contextSettings.depthBits = 32; + contextSettings.depthBits = 24; // Create the main window sf::Window window(sf::VideoMode(640, 480), "SFML window with OpenGL", sf::Style::Default, contextSettings); diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index c4110ad9f..d35aaa4b0 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -96,6 +96,11 @@ namespace { + // AMD drivers have issues with internal synchronization + // We need to make sure that no operating system context + // or pixel format operations are performed simultaneously + sf::Mutex mutex; + // This per-thread variable holds the current context for each thread sf::ThreadLocalPtr currentContext(NULL); @@ -141,6 +146,8 @@ namespace priv //////////////////////////////////////////////////////////// void GlContext::globalInit() { + Lock lock(mutex); + // Create the shared context sharedContext = new ContextType(NULL); sharedContext->initialize(); @@ -155,6 +162,8 @@ void GlContext::globalInit() //////////////////////////////////////////////////////////// void GlContext::globalCleanup() { + Lock lock(mutex); + // Destroy the shared context delete sharedContext; sharedContext = NULL; @@ -179,6 +188,9 @@ void GlContext::ensureContext() //////////////////////////////////////////////////////////// GlContext* GlContext::create() { + Lock lock(mutex); + + // Create the context GlContext* context = new ContextType(sharedContext); context->initialize(); @@ -192,6 +204,8 @@ GlContext* GlContext::create(const ContextSettings& settings, const WindowImpl* // Make sure that there's an active context (context creation may need extensions, and thus a valid context) ensureContext(); + Lock lock(mutex); + // Create the context GlContext* context = new ContextType(sharedContext, settings, owner, bitsPerPixel); context->initialize(); @@ -207,6 +221,8 @@ GlContext* GlContext::create(const ContextSettings& settings, unsigned int width // Make sure that there's an active context (context creation may need extensions, and thus a valid context) ensureContext(); + Lock lock(mutex); + // Create the context GlContext* context = new ContextType(sharedContext, settings, width, height); context->initialize(); @@ -221,6 +237,8 @@ GlFunctionPointer GlContext::getFunction(const char* name) { #if !defined(SFML_OPENGL_ES) + Lock lock(mutex); + return ContextType::getFunction(name); #else @@ -254,6 +272,8 @@ bool GlContext::setActive(bool active) { if (this != currentContext) { + Lock lock(mutex); + // Activate the context if (makeCurrent()) {