Fix the case where not having created a GlResource prior to calling Shader::isAvailable() would break context management. (#211)

This commit is contained in:
binary1248 2014-05-19 08:42:42 +02:00 committed by Lukas Dürrenberger
parent 749cbb2ff8
commit 1fe22e24d0

View File

@ -29,6 +29,7 @@
#include <SFML/Graphics/Shader.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/GLCheck.hpp>
#include <SFML/Window/Context.hpp>
#include <SFML/System/InputStream.hpp>
#include <SFML/System/Err.hpp>
#include <fstream>
@ -437,15 +438,29 @@ void Shader::bind(const Shader* shader)
////////////////////////////////////////////////////////////
bool Shader::isAvailable()
{
ensureGlContext();
static bool available = false;
static bool checked = false;
// Make sure that extensions are initialized
priv::ensureExtensionsInit();
// Make sure we only have to check once
if (!checked)
{
// Create a temporary context in case the user checks
// before a GlResource is created, thus initializing
// the shared context
Context context;
return GLEW_ARB_shading_language_100 &&
GLEW_ARB_shader_objects &&
GLEW_ARB_vertex_shader &&
GLEW_ARB_fragment_shader;
// Make sure that extensions are initialized
priv::ensureExtensionsInit();
available = GLEW_ARB_shading_language_100 &&
GLEW_ARB_shader_objects &&
GLEW_ARB_vertex_shader &&
GLEW_ARB_fragment_shader;
checked = true;
}
return available;
}