From aff5c1a47c4cc81c496c008ffbdc34e583ac3408 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Fri, 4 Dec 2009 13:55:16 +0000 Subject: [PATCH] Renamed Image::GetValidTextureSize to Image::GetValidSize Added Image::GetMaximumSize git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1306 4e206d99-4929-0410-ac5d-dfc041789085 --- include/SFML/Graphics/Image.hpp | 12 ++++++++++-- src/SFML/Graphics/FontLoader.cpp | 14 ++++++-------- src/SFML/Graphics/Image.cpp | 30 ++++++++++++++++++++++-------- src/SFML/Graphics/Text.cpp | 2 +- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index ae650031..9f203245 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -260,14 +260,22 @@ public : FloatRect GetTexCoords(const IntRect& rectangle) const; //////////////////////////////////////////////////////////// - /// Get a valid texture size according to hardware support + /// Get the maximum image size according to hardware support + /// + /// \return Maximum size allowed for images, in pixels + /// + //////////////////////////////////////////////////////////// + static unsigned int GetMaximumSize(); + + //////////////////////////////////////////////////////////// + /// Get a valid image size according to hardware support /// /// \param Size : size to convert /// /// \return Valid nearest size (greater than or equal to specified size) /// //////////////////////////////////////////////////////////// - static unsigned int GetValidTextureSize(unsigned int size); + static unsigned int GetValidSize(unsigned int size); //////////////////////////////////////////////////////////// /// Assignment operator diff --git a/src/SFML/Graphics/FontLoader.cpp b/src/SFML/Graphics/FontLoader.cpp index 9a6244d2..97802e18 100644 --- a/src/SFML/Graphics/FontLoader.cpp +++ b/src/SFML/Graphics/FontLoader.cpp @@ -167,18 +167,17 @@ bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, u FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const String& charset, Font& font) { // Let's find how many characters to put in each row to make them fit into a squared texture - GLint maxSize; - GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize)); + unsigned int maxSize = Image::GetMaximumSize(); int nbChars = static_cast(sqrt(static_cast(charset.GetSize())) * 0.75); // Clamp the character size to make sure we won't create a texture too big - if (nbChars * charSize >= static_cast(maxSize)) + if (nbChars * charSize >= maxSize) charSize = maxSize / nbChars; // Initialize the dimensions unsigned int left = 0; unsigned int top = 0; - unsigned int texWidth = Image::GetValidTextureSize(charSize * nbChars); + unsigned int texWidth = Image::GetValidSize(charSize * nbChars); unsigned int texHeight = charSize * nbChars; std::vector tops(texWidth, 0); @@ -514,18 +513,17 @@ bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int char bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const String& charset, Font& font) { // Let's find how many characters to put in each row to make them fit into a squared texture - GLint maxSize; - GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize)); + unsigned int maxSize = Image::GetMaximumSize(); int nbChars = static_cast(sqrt(static_cast(charset.GetSize())) * 0.75); // Clamp the character size to make sure we won't create a texture too big - if (nbChars * charSize >= static_cast(maxSize)) + if (nbChars * charSize >= maxSize) charSize = maxSize / nbChars; // Initialize the dimensions unsigned int left = 0; unsigned int top = 0; - unsigned int texWidth = Image::GetValidTextureSize(charSize * nbChars); + unsigned int texWidth = Image::GetValidSize(charSize * nbChars); unsigned int texHeight = charSize * nbChars; std::vector tops(texWidth, 0); diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 83e81679..f9045d98 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -577,9 +577,21 @@ FloatRect Image::GetTexCoords(const IntRect& rect) const //////////////////////////////////////////////////////////// -/// Get a valid texture size according to hardware support +/// Get the maximum image size according to hardware support //////////////////////////////////////////////////////////// -unsigned int Image::GetValidTextureSize(unsigned int size) +unsigned int Image::GetMaximumSize() +{ + GLint size; + GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size)); + + return static_cast(size); +} + + +//////////////////////////////////////////////////////////// +/// Get a valid image size according to hardware support +//////////////////////////////////////////////////////////// +unsigned int Image::GetValidSize(unsigned int size) { // Make sure that GLEW is initialized priv::EnsureGlewInit(); @@ -633,15 +645,17 @@ bool Image::CreateTexture() return false; // Adjust internal texture dimensions depending on NPOT textures support - unsigned int textureWidth = GetValidTextureSize(myWidth); - unsigned int textureHeight = GetValidTextureSize(myHeight); + unsigned int textureWidth = GetValidSize(myWidth); + unsigned int textureHeight = GetValidSize(myHeight); // Check the maximum texture size - GLint maxSize; - GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize)); - if ((textureWidth > static_cast(maxSize)) || (textureHeight > static_cast(maxSize))) + unsigned int maxSize = GetMaximumSize(); + if ((textureWidth > maxSize) || (textureHeight > maxSize)) { - std::cerr << "Failed to create image, its internal size is too high (" << textureWidth << "x" << textureHeight << ")" << std::endl; + std::cerr << "Failed to create image, its internal size is too high " + << "(" << textureWidth << "x" << textureHeight << ", " + << "maximum is " << maxSize << "x" << maxSize << ")" + << std::endl; return false; } diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index 6dd0fa17..567b5bdd 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -213,7 +213,7 @@ void Text::Render(RenderTarget&, RenderQueue& queue) const return; // Set the scaling factor to get the actual size - float charSize = static_cast(myFont->GetCharacterSize()); + float charSize = static_cast(myFont->GetCharacterSize()); float factor = mySize / charSize; // Bind the font texture