Fixed a bug where calling Texture::getMaximumSize() before any GlResource is created would break context management.

This commit is contained in:
Maximilian Wagenbach 2014-07-19 01:10:27 +02:00 committed by binary1248
parent 6ad7b21203
commit 713407e159
3 changed files with 23 additions and 10 deletions

View File

@ -28,7 +28,6 @@
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include <cassert>
namespace sf

View File

@ -29,6 +29,7 @@
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/GLCheck.hpp>
#include <SFML/Graphics/TextureSaver.hpp>
#include <SFML/Window/Context.hpp>
#include <SFML/Window/Window.hpp>
#include <SFML/System/Mutex.hpp>
#include <SFML/System/Lock.hpp>
@ -522,12 +523,26 @@ void Texture::bind(const Texture* texture, CoordinateType coordinateType)
////////////////////////////////////////////////////////////
unsigned int Texture::getMaximumSize()
{
ensureGlContext();
static unsigned int size = 0;
static bool checked = false;
GLint size;
glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size));
// Make sure we only have to check once
if (!checked)
{
// Create a temporary context in case the user queries
// the size before a GlResource is created, thus
// initializing the shared context
Context context;
return static_cast<unsigned int>(size);
GLint glSize;
glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glSize));
size = static_cast<unsigned int>(glSize);
checked = true;
}
return size;
}

View File

@ -32,7 +32,6 @@
#include <SFML/OpenGL.hpp>
#include <set>
#include <cstdlib>
#include <cassert>
#ifdef SFML_SYSTEM_IOS
#include <OpenGLES/ES1/gl.h>
#else