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
This commit is contained in:
parent
cacd150569
commit
aff5c1a47c
@ -260,14 +260,22 @@ public :
|
|||||||
FloatRect GetTexCoords(const IntRect& rectangle) const;
|
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
|
/// \param Size : size to convert
|
||||||
///
|
///
|
||||||
/// \return Valid nearest size (greater than or equal to specified size)
|
/// \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
|
/// Assignment operator
|
||||||
|
@ -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)
|
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
|
// Let's find how many characters to put in each row to make them fit into a squared texture
|
||||||
GLint maxSize;
|
unsigned int maxSize = Image::GetMaximumSize();
|
||||||
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize));
|
|
||||||
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
|
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
|
||||||
|
|
||||||
// Clamp the character size to make sure we won't create a texture too big
|
// Clamp the character size to make sure we won't create a texture too big
|
||||||
if (nbChars * charSize >= static_cast<unsigned int>(maxSize))
|
if (nbChars * charSize >= maxSize)
|
||||||
charSize = maxSize / nbChars;
|
charSize = maxSize / nbChars;
|
||||||
|
|
||||||
// Initialize the dimensions
|
// Initialize the dimensions
|
||||||
unsigned int left = 0;
|
unsigned int left = 0;
|
||||||
unsigned int top = 0;
|
unsigned int top = 0;
|
||||||
unsigned int texWidth = Image::GetValidTextureSize(charSize * nbChars);
|
unsigned int texWidth = Image::GetValidSize(charSize * nbChars);
|
||||||
unsigned int texHeight = charSize * nbChars;
|
unsigned int texHeight = charSize * nbChars;
|
||||||
std::vector<unsigned int> tops(texWidth, 0);
|
std::vector<unsigned int> 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)
|
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
|
// Let's find how many characters to put in each row to make them fit into a squared texture
|
||||||
GLint maxSize;
|
unsigned int maxSize = Image::GetMaximumSize();
|
||||||
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize));
|
|
||||||
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
|
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
|
||||||
|
|
||||||
// Clamp the character size to make sure we won't create a texture too big
|
// Clamp the character size to make sure we won't create a texture too big
|
||||||
if (nbChars * charSize >= static_cast<unsigned int>(maxSize))
|
if (nbChars * charSize >= maxSize)
|
||||||
charSize = maxSize / nbChars;
|
charSize = maxSize / nbChars;
|
||||||
|
|
||||||
// Initialize the dimensions
|
// Initialize the dimensions
|
||||||
unsigned int left = 0;
|
unsigned int left = 0;
|
||||||
unsigned int top = 0;
|
unsigned int top = 0;
|
||||||
unsigned int texWidth = Image::GetValidTextureSize(charSize * nbChars);
|
unsigned int texWidth = Image::GetValidSize(charSize * nbChars);
|
||||||
unsigned int texHeight = charSize * nbChars;
|
unsigned int texHeight = charSize * nbChars;
|
||||||
std::vector<unsigned int> tops(texWidth, 0);
|
std::vector<unsigned int> tops(texWidth, 0);
|
||||||
|
|
||||||
|
@ -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<unsigned int>(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// Get a valid image size according to hardware support
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
unsigned int Image::GetValidSize(unsigned int size)
|
||||||
{
|
{
|
||||||
// Make sure that GLEW is initialized
|
// Make sure that GLEW is initialized
|
||||||
priv::EnsureGlewInit();
|
priv::EnsureGlewInit();
|
||||||
@ -633,15 +645,17 @@ bool Image::CreateTexture()
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Adjust internal texture dimensions depending on NPOT textures support
|
// Adjust internal texture dimensions depending on NPOT textures support
|
||||||
unsigned int textureWidth = GetValidTextureSize(myWidth);
|
unsigned int textureWidth = GetValidSize(myWidth);
|
||||||
unsigned int textureHeight = GetValidTextureSize(myHeight);
|
unsigned int textureHeight = GetValidSize(myHeight);
|
||||||
|
|
||||||
// Check the maximum texture size
|
// Check the maximum texture size
|
||||||
GLint maxSize;
|
unsigned int maxSize = GetMaximumSize();
|
||||||
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize));
|
if ((textureWidth > maxSize) || (textureHeight > maxSize))
|
||||||
if ((textureWidth > static_cast<unsigned int>(maxSize)) || (textureHeight > static_cast<unsigned int>(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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user