diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 805b6b6f..0b3f1751 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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; }