Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Shader::isAvailable() breaking context management if called too early #603

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/SFML/Graphics/Shader.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -437,15 +438,29 @@ void Shader::bind(const Shader* shader)
////////////////////////////////////////////////////////////
bool Shader::isAvailable()
{
ensureGlContext();
static bool available = false;
static bool checked = false;

// 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;

// Make sure that extensions are initialized
priv::ensureExtensionsInit();
// 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 GLEW_ARB_shading_language_100 &&
GLEW_ARB_shader_objects &&
GLEW_ARB_vertex_shader &&
GLEW_ARB_fragment_shader;
return available;
}


Expand Down