From 6b50691551da7c76b69f626b86056bb40a1fbf9a Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Mon, 1 Jul 2013 21:59:46 +0200 Subject: [PATCH] Solved graphics resources not updated or corrupted when loaded in a thread (#411) --- src/SFML/Graphics/Font.cpp | 5 +++++ src/SFML/Graphics/Shader.cpp | 4 ++++ src/SFML/Graphics/Texture.cpp | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 1ad882dac..8afe57e73 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -26,6 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -480,6 +481,10 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c // Delete the FT glyph FT_Done_Glyph(glyphDesc); + // Force an OpenGL flush, so that the font's texture will appear updated + // in all contexts immediately (solves problems in multi-threaded apps) + glCheck(glFlush()); + // Done :) return glyph; } diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 072bc6e31..eb292b729 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -535,6 +535,10 @@ bool Shader::compile(const char* vertexShaderCode, const char* fragmentShaderCod return false; } + // Force an OpenGL flush, so that the shader will appear updated + // in all contexts immediately (solves problems in multi-threaded apps) + glCheck(glFlush()); + return true; } diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index a0e57e19e..7b5fdb27a 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -192,6 +192,11 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area) if (create(image.getSize().x, image.getSize().y)) { update(image); + + // Force an OpenGL flush, so that the texture will appear updated + // in all contexts immediately (solves problems in multi-threaded apps) + glCheck(glFlush()); + return true; } else @@ -225,6 +230,10 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area) pixels += 4 * width; } + // Force an OpenGL flush, so that the texture will appear updated + // in all contexts immediately (solves problems in multi-threaded apps) + glCheck(glFlush()); + return true; } else