Solved graphics resources not updated or corrupted when loaded in a thread (#411)

This commit is contained in:
Laurent Gomila 2013-07-01 21:59:46 +02:00
parent 4d55bbe4ff
commit 6b50691551
3 changed files with 18 additions and 0 deletions

View File

@ -26,6 +26,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/GLCheck.hpp>
#include <SFML/System/InputStream.hpp>
#include <SFML/System/Err.hpp>
#include <ft2build.h>
@ -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;
}

View File

@ -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;
}

View File

@ -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