From 1fe22e24d020d9d933a4ed7bfd618e634830023c Mon Sep 17 00:00:00 2001 From: binary1248 Date: Mon, 19 May 2014 08:42:42 +0200 Subject: [PATCH] Fix the case where not having created a GlResource prior to calling Shader::isAvailable() would break context management. (#211) --- src/SFML/Graphics/Shader.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) 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; }