From 6959c1a826693017a26336fc1814593f6199ed3d Mon Sep 17 00:00:00 2001 From: binary1248 Date: Fri, 15 Aug 2014 13:39:06 +0200 Subject: [PATCH] Added notes to documentation and adjusted OpenGL example as a workaround for the side effects of making static functions that require a context work. If the user wants to make use of both sfml-graphics and OpenGL, they should make sure sf::Texture::getMaximumSize() and/or sf::Shader::isAvailable() are called at least once before setting their final context active as those functions will cause a context switch the first time they are called. --- examples/opengl/OpenGL.cpp | 10 +++++++--- include/SFML/Graphics/Shader.hpp | 3 +++ include/SFML/Graphics/Texture.hpp | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index 639254bc0..ccb1d34da 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -22,9 +22,6 @@ int main() sf::RenderWindow window(sf::VideoMode(800, 600), "SFML graphics with OpenGL", sf::Style::Default, contextSettings); window.setVerticalSyncEnabled(true); - // Make it the active window for OpenGL calls - window.setActive(); - // Create a sprite for the background sf::Texture backgroundTexture; if (!backgroundTexture.loadFromFile("resources/background.jpg")) @@ -39,6 +36,13 @@ int main() text.setColor(sf::Color(255, 255, 255, 170)); text.setPosition(250.f, 450.f); + // Make the window the active target for OpenGL calls + // Note: If using sf::Texture or sf::Shader with OpenGL, + // be sure to call sf::Texture::getMaximumSize() and/or + // sf::Shader::isAvailable() at least once before calling + // setActive(), as those functions will cause a context switch + window.setActive(); + // Load an OpenGL texture. // We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function), // but here we want more control on it (generate mipmaps, ...) so we create a new one from an image diff --git a/include/SFML/Graphics/Shader.hpp b/include/SFML/Graphics/Shader.hpp index 99f86dbb1..028dd7270 100644 --- a/include/SFML/Graphics/Shader.hpp +++ b/include/SFML/Graphics/Shader.hpp @@ -486,6 +486,9 @@ public : /// the shader features. If it returns false, then /// any attempt to use sf::Shader will fail. /// + /// Note: The first call to this function, whether by your + /// code or SFML will result in a context switch. + /// /// \return True if shaders are supported, false otherwise /// //////////////////////////////////////////////////////////// diff --git a/include/SFML/Graphics/Texture.hpp b/include/SFML/Graphics/Texture.hpp index 83a016dfe..8fde8ec0a 100644 --- a/include/SFML/Graphics/Texture.hpp +++ b/include/SFML/Graphics/Texture.hpp @@ -460,6 +460,9 @@ public : /// You can expect a value of 512 pixels for low-end graphics /// card, and up to 8192 pixels or more for newer hardware. /// + /// Note: The first call to this function, whether by your + /// code or SFML will result in a context switch. + /// /// \return Maximum size allowed for textures, in pixels /// ////////////////////////////////////////////////////////////