mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
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;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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
|
||||
|
@ -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<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
|
||||
|
||||
// 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;
|
||||
|
||||
// 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<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)
|
||||
{
|
||||
// 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<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
|
||||
|
||||
// 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;
|
||||
|
||||
// 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<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
|
||||
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<unsigned int>(maxSize)) || (textureHeight > static_cast<unsigned int>(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;
|
||||
}
|
||||
|
||||
|
@ -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<float>(myFont->GetCharacterSize());
|
||||
float charSize = static_cast<float>(myFont->GetCharacterSize());
|
||||
float factor = mySize / charSize;
|
||||
|
||||
// Bind the font texture
|
||||
|
Loading…
Reference in New Issue
Block a user