Fix conversion warnings for the Graphics module

- Fix conversion and shadowing warnings
- Add SYSTEM indicator for stb_*, FreeType and other headers
This commit is contained in:
Lukas Dürrenberger 2021-04-22 00:48:56 +02:00 committed by Lukas Dürrenberger
parent 0468612ac0
commit 01836ccea4
18 changed files with 135 additions and 128 deletions

View File

@ -350,7 +350,7 @@ function(sfml_add_external)
if (NOT include_dir)
message(FATAL_ERROR "No path given for include dir ${THIS_INCLUDE}")
endif()
target_include_directories(${target} INTERFACE "$<BUILD_INTERFACE:${include_dir}>")
target_include_directories(${target} SYSTEM INTERFACE "$<BUILD_INTERFACE:${include_dir}>")
endforeach()
endif()

View File

@ -93,7 +93,7 @@ sfml_add_library(sfml-graphics
target_link_libraries(sfml-graphics PUBLIC sfml-window)
# stb_image sources
target_include_directories(sfml-graphics PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/stb_image")
target_include_directories(sfml-graphics SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/stb_image")
# glad sources
target_include_directories(sfml-graphics SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/glad/include")

View File

@ -74,7 +74,7 @@ Vector2f CircleShape::getPoint(std::size_t index) const
{
static const float pi = 3.141592654f;
float angle = index * 2 * pi / m_pointCount - pi / 2;
float angle = static_cast<float>(index) * 2.f * pi / static_cast<float>(m_pointCount) - pi / 2.f;
float x = std::cos(angle) * m_radius;
float y = std::sin(angle) * m_radius;

View File

@ -69,7 +69,7 @@ a(alpha)
////////////////////////////////////////////////////////////
Color::Color(Uint32 color) :
r((color & 0xff000000) >> 24),
r(static_cast<Uint8>((color & 0xff000000) >> 24)),
g(static_cast<Uint8>((color & 0x00ff0000) >> 16)),
b((color & 0x0000ff00) >> 8 ),
a((color & 0x000000ff) >> 0 )
@ -81,7 +81,7 @@ a((color & 0x000000ff) >> 0 )
////////////////////////////////////////////////////////////
Uint32 Color::toInteger() const
{
return (r << 24) | (g << 16) | (b << 8) | a;
return static_cast<Uint32>((r << 24) | (g << 16) | (b << 8) | a);
}

View File

@ -48,11 +48,12 @@ namespace
// FreeType callbacks that operate on a sf::InputStream
unsigned long read(FT_Stream rec, unsigned long offset, unsigned char* buffer, unsigned long count)
{
sf::Int64 convertedOffset = static_cast<sf::Int64>(offset);
sf::InputStream* stream = static_cast<sf::InputStream*>(rec->descriptor.pointer);
if (static_cast<unsigned long>(stream->seek(offset)) == offset)
if (stream->seek(convertedOffset) == convertedOffset)
{
if (count > 0)
return static_cast<unsigned long>(stream->read(reinterpret_cast<char*>(buffer), count));
return static_cast<unsigned long>(stream->read(reinterpret_cast<char*>(buffer), static_cast<sf::Int64>(count)));
else
return 0;
}
@ -441,7 +442,7 @@ float Font::getUnderlinePosition(unsigned int characterSize) const
{
// Return a fixed position if font is a bitmap font
if (!FT_IS_SCALABLE(face))
return characterSize / 10.f;
return static_cast<float>(characterSize) / 10.f;
return -static_cast<float>(FT_MulFix(face->underline_position, face->size->metrics.y_scale)) / static_cast<float>(1 << 6);
}
@ -461,7 +462,7 @@ float Font::getUnderlineThickness(unsigned int characterSize) const
{
// Return a fixed thickness if font is a bitmap font
if (!FT_IS_SCALABLE(face))
return characterSize / 14.f;
return static_cast<float>(characterSize) / 14.f;
return static_cast<float>(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale)) / static_cast<float>(1 << 6);
}
@ -600,7 +601,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f
{
if (bold)
{
FT_OutlineGlyph outlineGlyph = (FT_OutlineGlyph)glyphDesc;
FT_OutlineGlyph outlineGlyph = reinterpret_cast<FT_OutlineGlyph>(glyphDesc);
FT_Outline_Embolden(&outlineGlyph->outline, weight);
}
@ -635,11 +636,11 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f
if (bold)
glyph.advance += static_cast<float>(weight) / static_cast<float>(1 << 6);
glyph.lsbDelta = face->glyph->lsb_delta;
glyph.rsbDelta = face->glyph->rsb_delta;
glyph.lsbDelta = static_cast<int>(face->glyph->lsb_delta);
glyph.rsbDelta = static_cast<int>(face->glyph->rsb_delta);
int width = bitmap.width;
int height = bitmap.rows;
unsigned int width = bitmap.width;
unsigned int height = bitmap.rows;
if ((width > 0) && (height > 0))
{
@ -658,10 +659,10 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f
// Make sure the texture data is positioned in the center
// of the allocated texture rectangle
glyph.textureRect.left += padding;
glyph.textureRect.top += padding;
glyph.textureRect.width -= 2 * padding;
glyph.textureRect.height -= 2 * padding;
glyph.textureRect.left += static_cast<int>(padding);
glyph.textureRect.top += static_cast<int>(padding);
glyph.textureRect.width -= static_cast<int>(2 * padding);
glyph.textureRect.height -= static_cast<int>(2 * padding);
// Compute the glyph's bounding box
glyph.bounds.left = bitmapGlyph->left;
@ -715,10 +716,10 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f
}
// Write the pixels to the texture
unsigned int x = glyph.textureRect.left - padding;
unsigned int y = glyph.textureRect.top - padding;
unsigned int w = glyph.textureRect.width + 2 * padding;
unsigned int h = glyph.textureRect.height + 2 * padding;
unsigned int x = static_cast<unsigned int>(glyph.textureRect.left) - padding;
unsigned int y = static_cast<unsigned int>(glyph.textureRect.top) - padding;
unsigned int w = static_cast<unsigned int>(glyph.textureRect.width) + 2 * padding;
unsigned int h = static_cast<unsigned int>(glyph.textureRect.height) + 2 * padding;
page.texture.update(&m_pixelBuffer[0], w, h, x, y);
}
@ -738,7 +739,7 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height)
float bestRatio = 0;
for (std::vector<Row>::iterator it = page.rows.begin(); it != page.rows.end() && !row; ++it)
{
float ratio = static_cast<float>(height) / it->height;
float ratio = static_cast<float>(height) / static_cast<float>(it->height);
// Ignore rows that are either too small or too high
if ((ratio < 0.7f) || (ratio > 1.f))
@ -760,7 +761,7 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height)
// If we didn't find a matching row, create a new one (10% taller than the glyph)
if (!row)
{
int rowHeight = height + height / 10;
unsigned int rowHeight = height + height / 10;
while ((page.nextRow + rowHeight >= page.texture.getSize().y) || (width >= page.texture.getSize().x))
{
// Not enough space: resize the texture if possible
@ -790,7 +791,7 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height)
}
// Find the glyph's rectangle on the selected row
IntRect rect(row->width, row->top, width, height);
IntRect rect(Rect<unsigned int>(row->width, row->top, width, height));
// Update the row informations
row->width += width;
@ -822,7 +823,7 @@ bool Font::setCurrentSize(unsigned int characterSize) const
err() << "Available sizes are: ";
for (int i = 0; i < face->num_fixed_sizes; ++i)
{
const unsigned int size = (face->available_sizes[i].y_ppem + 32) >> 6;
const long size = (face->available_sizes[i].y_ppem + 32) >> 6;
err() << size << " ";
}
err() << std::endl;
@ -849,8 +850,8 @@ nextRow(3)
image.create(128, 128, Color(255, 255, 255, 0));
// Reserve a 2x2 white square for texturing underlines
for (int x = 0; x < 2; ++x)
for (int y = 0; y < 2; ++y)
for (unsigned int x = 0; x < 2; ++x)
for (unsigned int y = 0; y < 2; ++y)
image.setPixel(x, y, Color(255, 255, 255, 255));
// Create the texture

View File

@ -199,20 +199,20 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co
{
srcRect.left = 0;
srcRect.top = 0;
srcRect.width = source.m_size.x;
srcRect.height = source.m_size.y;
srcRect.width = static_cast<int>(source.m_size.x);
srcRect.height = static_cast<int>(source.m_size.y);
}
else
{
if (srcRect.left < 0) srcRect.left = 0;
if (srcRect.top < 0) srcRect.top = 0;
if (srcRect.width > static_cast<int>(source.m_size.x)) srcRect.width = source.m_size.x;
if (srcRect.height > static_cast<int>(source.m_size.y)) srcRect.height = source.m_size.y;
if (srcRect.width > static_cast<int>(source.m_size.x)) srcRect.width = static_cast<int>(source.m_size.x);
if (srcRect.height > static_cast<int>(source.m_size.y)) srcRect.height = static_cast<int>(source.m_size.y);
}
// Then find the valid bounds of the destination rectangle
int width = srcRect.width;
int height = srcRect.height;
unsigned int width = static_cast<unsigned int>(srcRect.width);
unsigned int height = static_cast<unsigned int>(srcRect.height);
if (destX + width > m_size.x) width = m_size.x - destX;
if (destY + height > m_size.y) height = m_size.y - destY;
@ -221,20 +221,20 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co
return;
// Precompute as much as possible
int pitch = width * 4;
int rows = height;
int srcStride = source.m_size.x * 4;
int dstStride = m_size.x * 4;
const Uint8* srcPixels = &source.m_pixels[0] + (srcRect.left + srcRect.top * source.m_size.x) * 4;
std::size_t pitch = static_cast<std::size_t>(width) * 4;
unsigned int rows = height;
int srcStride = static_cast<int>(source.m_size.x) * 4;
int dstStride = static_cast<int>(m_size.x) * 4;
const Uint8* srcPixels = &source.m_pixels[0] + (static_cast<unsigned int>(srcRect.left) + static_cast<unsigned int>(srcRect.top) * source.m_size.x) * 4;
Uint8* dstPixels = &m_pixels[0] + (destX + destY * m_size.x) * 4;
// Copy the pixels
if (applyAlpha)
{
// Interpolation using alpha values, pixel by pixel (slower)
for (int i = 0; i < rows; ++i)
for (unsigned int i = 0; i < rows; ++i)
{
for (int j = 0; j < width; ++j)
for (unsigned int j = 0; j < width; ++j)
{
// Get a direct pointer to the components of the current pixel
const Uint8* src = srcPixels + j * 4;
@ -242,10 +242,10 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co
// Interpolate RGBA components using the alpha value of the source pixel
Uint8 alpha = src[3];
dst[0] = (src[0] * alpha + dst[0] * (255 - alpha)) / 255;
dst[1] = (src[1] * alpha + dst[1] * (255 - alpha)) / 255;
dst[2] = (src[2] * alpha + dst[2] * (255 - alpha)) / 255;
dst[3] = alpha + dst[3] * (255 - alpha) / 255;
dst[0] = static_cast<Uint8>((src[0] * alpha + dst[0] * (255 - alpha)) / 255);
dst[1] = static_cast<Uint8>((src[1] * alpha + dst[1] * (255 - alpha)) / 255);
dst[2] = static_cast<Uint8>((src[2] * alpha + dst[2] * (255 - alpha)) / 255);
dst[3] = static_cast<Uint8>(alpha + dst[3] * (255 - alpha) / 255);
}
srcPixels += srcStride;
@ -255,7 +255,7 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co
else
{
// Optimized copy ignoring alpha values, row by row (faster)
for (int i = 0; i < rows; ++i)
for (unsigned int i = 0; i < rows; ++i)
{
std::memcpy(dstPixels, srcPixels, pitch);
srcPixels += srcStride;
@ -308,8 +308,8 @@ void Image::flipHorizontally()
for (std::size_t y = 0; y < m_size.y; ++y)
{
std::vector<Uint8>::iterator left = m_pixels.begin() + y * rowSize;
std::vector<Uint8>::iterator right = m_pixels.begin() + (y + 1) * rowSize - 4;
std::vector<Uint8>::iterator left = m_pixels.begin() + static_cast<std::vector<Uint8>::iterator::difference_type>(y * rowSize);
std::vector<Uint8>::iterator right = m_pixels.begin() + static_cast<std::vector<Uint8>::iterator::difference_type>((y + 1) * rowSize - 4);
for (std::size_t x = 0; x < m_size.x / 2; ++x)
{
@ -328,7 +328,7 @@ void Image::flipVertically()
{
if (!m_pixels.empty())
{
std::size_t rowSize = m_size.x * 4;
std::vector<Uint8>::iterator::difference_type rowSize = static_cast<std::vector<Uint8>::iterator::difference_type>(m_size.x * 4);
std::vector<Uint8>::iterator top = m_pixels.begin();
std::vector<Uint8>::iterator bottom = m_pixels.end() - rowSize;

View File

@ -115,13 +115,13 @@ bool ImageLoader::loadImageFromFile(const std::string& filename, std::vector<Uin
if (ptr)
{
// Assign the image properties
size.x = width;
size.y = height;
size.x = static_cast<unsigned int>(width);
size.y = static_cast<unsigned int>(height);
if (width && height)
if (width > 0 && height > 0)
{
// Copy the loaded pixels to the pixel buffer
pixels.resize(width * height * 4);
pixels.resize(static_cast<std::size_t>(width * height * 4));
memcpy(&pixels[0], ptr, pixels.size());
}
@ -159,13 +159,13 @@ bool ImageLoader::loadImageFromMemory(const void* data, std::size_t dataSize, st
if (ptr)
{
// Assign the image properties
size.x = width;
size.y = height;
size.x = static_cast<unsigned int>(width);
size.y = static_cast<unsigned int>(height);
if (width && height)
if (width > 0 && height > 0)
{
// Copy the loaded pixels to the pixel buffer
pixels.resize(width * height * 4);
pixels.resize(static_cast<std::size_t>(width * height * 4));
memcpy(&pixels[0], ptr, pixels.size());
}
@ -214,13 +214,13 @@ bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector<Uint8>& p
if (ptr)
{
// Assign the image properties
size.x = width;
size.y = height;
size.x = static_cast<unsigned int>(width);
size.y = static_cast<unsigned int>(height);
if (width && height)
{
// Copy the loaded pixels to the pixel buffer
pixels.resize(width * height * 4);
pixels.resize(static_cast<std::size_t>(width * height * 4));
memcpy(&pixels[0], ptr, pixels.size());
}
@ -250,29 +250,30 @@ bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector
// Extract the extension
const std::size_t dot = filename.find_last_of('.');
const std::string extension = dot != std::string::npos ? toLower(filename.substr(dot + 1)) : "";
const Vector2i convertedSize = Vector2i(size);
if (extension == "bmp")
{
// BMP format
if (stbi_write_bmp(filename.c_str(), size.x, size.y, 4, &pixels[0]))
if (stbi_write_bmp(filename.c_str(), convertedSize.x, convertedSize.y, 4, &pixels[0]))
return true;
}
else if (extension == "tga")
{
// TGA format
if (stbi_write_tga(filename.c_str(), size.x, size.y, 4, &pixels[0]))
if (stbi_write_tga(filename.c_str(), convertedSize.x, convertedSize.y, 4, &pixels[0]))
return true;
}
else if (extension == "png")
{
// PNG format
if (stbi_write_png(filename.c_str(), size.x, size.y, 4, &pixels[0], 0))
if (stbi_write_png(filename.c_str(), convertedSize.x, convertedSize.y, 4, &pixels[0], 0))
return true;
}
else if (extension == "jpg" || extension == "jpeg")
{
// JPG format
if (stbi_write_jpg(filename.c_str(), size.x, size.y, 4, &pixels[0], 90))
if (stbi_write_jpg(filename.c_str(), convertedSize.x, convertedSize.y, 4, &pixels[0], 90))
return true;
}
}
@ -290,29 +291,30 @@ bool ImageLoader::saveImageToMemory(const std::string& format, std::vector<sf::U
// Choose function based on format
std::string specified = toLower(format);
const Vector2i convertedSize = Vector2i(size);
if (specified == "bmp")
{
// BMP format
if (stbi_write_bmp_to_func(&bufferFromCallback, &output, size.x, size.y, 4, &pixels[0]))
if (stbi_write_bmp_to_func(&bufferFromCallback, &output, convertedSize.x, convertedSize.y, 4, &pixels[0]))
return true;
}
else if (specified == "tga")
{
// TGA format
if (stbi_write_tga_to_func(&bufferFromCallback, &output, size.x, size.y, 4, &pixels[0]))
if (stbi_write_tga_to_func(&bufferFromCallback, &output, convertedSize.x, convertedSize.y, 4, &pixels[0]))
return true;
}
else if (specified == "png")
{
// PNG format
if (stbi_write_png_to_func(&bufferFromCallback, &output, size.x, size.y, 4, &pixels[0], 0))
if (stbi_write_png_to_func(&bufferFromCallback, &output, convertedSize.x, convertedSize.y, 4, &pixels[0], 0))
return true;
}
else if (specified == "jpg" || specified == "jpeg")
{
// JPG format
if (stbi_write_jpg_to_func(&bufferFromCallback, &output, size.x, size.y, 4, &pixels[0], 90))
if (stbi_write_jpg_to_func(&bufferFromCallback, &output, convertedSize.x, convertedSize.y, 4, &pixels[0], 90))
return true;
}
}

View File

@ -230,9 +230,9 @@ Vector2f RenderTarget::mapPixelToCoords(const Vector2i& point, const View& view)
{
// First, convert from viewport coordinates to homogeneous coordinates
Vector2f normalized;
IntRect viewport = getViewport(view);
normalized.x = -1.f + 2.f * (point.x - viewport.left) / viewport.width;
normalized.y = 1.f - 2.f * (point.y - viewport.top) / viewport.height;
FloatRect viewport = FloatRect(getViewport(view));
normalized.x = -1.f + 2.f * (static_cast<float>(point.x) - viewport.left) / viewport.width;
normalized.y = 1.f - 2.f * (static_cast<float>(point.y) - viewport.top) / viewport.height;
// Then transform by the inverse of the view matrix
return view.getInverseTransform().transformPoint(normalized);
@ -254,7 +254,7 @@ Vector2i RenderTarget::mapCoordsToPixel(const Vector2f& point, const View& view)
// Then convert to viewport coordinates
Vector2i pixel;
IntRect viewport = getViewport(view);
FloatRect viewport = FloatRect(getViewport(view));
pixel.x = static_cast<int>(( normalized.x + 1.f) / 2.f * viewport.width + viewport.left);
pixel.y = static_cast<int>((-normalized.y + 1.f) / 2.f * viewport.height + viewport.top);
@ -596,7 +596,7 @@ void RenderTarget::applyCurrentView()
{
// Set the viewport
IntRect viewport = getViewport(m_view);
int top = getSize().y - (viewport.top + viewport.height);
int top = static_cast<int>(getSize().y) - (viewport.top + viewport.height);
glCheck(glViewport(viewport.left, top, viewport.width, viewport.height));
// Set the projection matrix

View File

@ -99,7 +99,7 @@ void RenderTextureImplDefault::updateTexture(unsigned int textureId)
// Copy the rendered pixels to the texture
glCheck(glBindTexture(GL_TEXTURE_2D, textureId));
glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height));
glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, static_cast<GLsizei>(m_width), static_cast<GLsizei>(m_height)));
}
} // namespace priv

View File

@ -90,7 +90,7 @@ namespace
{
if (iter->first == contextId)
{
GLuint frameBuffer = static_cast<GLuint>(iter->second);
GLuint frameBuffer = iter->second;
glCheck(GLEXT_glDeleteFramebuffers(1, &frameBuffer));
// Erase the entry from the RenderTextureImplFBO's map
@ -148,14 +148,14 @@ RenderTextureImplFBO::~RenderTextureImplFBO()
// Destroy the color buffer
if (m_colorBuffer)
{
GLuint colorBuffer = static_cast<GLuint>(m_colorBuffer);
GLuint colorBuffer = m_colorBuffer;
glCheck(GLEXT_glDeleteRenderbuffers(1, &colorBuffer));
}
// Destroy the depth/stencil buffer
if (m_depthStencilBuffer)
{
GLuint depthStencilBuffer = static_cast<GLuint>(m_depthStencilBuffer);
GLuint depthStencilBuffer = m_depthStencilBuffer;
glCheck(GLEXT_glDeleteRenderbuffers(1, &depthStencilBuffer));
}
@ -260,14 +260,14 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
GLuint depthStencil = 0;
glCheck(GLEXT_glGenRenderbuffers(1, &depthStencil));
m_depthStencilBuffer = static_cast<unsigned int>(depthStencil);
m_depthStencilBuffer = depthStencil;
if (!m_depthStencilBuffer)
{
err() << "Impossible to create render texture (failed to create the attached depth/stencil buffer)" << std::endl;
return false;
}
glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_depthStencilBuffer));
glCheck(GLEXT_glRenderbufferStorage(GLEXT_GL_RENDERBUFFER, GLEXT_GL_DEPTH24_STENCIL8, width, height));
glCheck(GLEXT_glRenderbufferStorage(GLEXT_GL_RENDERBUFFER, GLEXT_GL_DEPTH24_STENCIL8, static_cast<GLsizei>(width), static_cast<GLsizei>(height)));
#else
@ -283,14 +283,14 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
{
GLuint depthStencil = 0;
glCheck(GLEXT_glGenRenderbuffers(1, &depthStencil));
m_depthStencilBuffer = static_cast<unsigned int>(depthStencil);
m_depthStencilBuffer = depthStencil;
if (!m_depthStencilBuffer)
{
err() << "Impossible to create render texture (failed to create the attached depth buffer)" << std::endl;
return false;
}
glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_depthStencilBuffer));
glCheck(GLEXT_glRenderbufferStorage(GLEXT_GL_RENDERBUFFER, GLEXT_GL_DEPTH_COMPONENT, width, height));
glCheck(GLEXT_glRenderbufferStorage(GLEXT_GL_RENDERBUFFER, GLEXT_GL_DEPTH_COMPONENT, static_cast<GLsizei>(width), static_cast<GLsizei>(height)));
}
}
else
@ -301,28 +301,28 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
// Create the multisample color buffer
GLuint color = 0;
glCheck(GLEXT_glGenRenderbuffers(1, &color));
m_colorBuffer = static_cast<unsigned int>(color);
m_colorBuffer = color;
if (!m_colorBuffer)
{
err() << "Impossible to create render texture (failed to create the attached multisample color buffer)" << std::endl;
return false;
}
glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_colorBuffer));
glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, settings.antialiasingLevel, m_sRgb ? GL_SRGB8_ALPHA8_EXT : GL_RGBA, width, height));
glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, static_cast<GLsizei>(settings.antialiasingLevel), m_sRgb ? GL_SRGB8_ALPHA8_EXT : GL_RGBA, static_cast<GLsizei>(width), static_cast<GLsizei>(height)));
// Create the multisample depth/stencil buffer if requested
if (settings.stencilBits)
{
GLuint depthStencil = 0;
glCheck(GLEXT_glGenRenderbuffers(1, &depthStencil));
m_depthStencilBuffer = static_cast<unsigned int>(depthStencil);
m_depthStencilBuffer = depthStencil;
if (!m_depthStencilBuffer)
{
err() << "Impossible to create render texture (failed to create the attached multisample depth/stencil buffer)" << std::endl;
return false;
}
glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_depthStencilBuffer));
glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, settings.antialiasingLevel, GLEXT_GL_DEPTH24_STENCIL8, width, height));
glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, static_cast<GLsizei>(settings.antialiasingLevel), GLEXT_GL_DEPTH24_STENCIL8, static_cast<GLsizei>(width), static_cast<GLsizei>(height)));
m_stencil = true;
}
@ -330,14 +330,14 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
{
GLuint depthStencil = 0;
glCheck(GLEXT_glGenRenderbuffers(1, &depthStencil));
m_depthStencilBuffer = static_cast<unsigned int>(depthStencil);
m_depthStencilBuffer = depthStencil;
if (!m_depthStencilBuffer)
{
err() << "Impossible to create render texture (failed to create the attached multisample depth buffer)" << std::endl;
return false;
}
glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_depthStencilBuffer));
glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, settings.antialiasingLevel, GLEXT_GL_DEPTH_COMPONENT, width, height));
glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, static_cast<GLsizei>(settings.antialiasingLevel), GLEXT_GL_DEPTH_COMPONENT, static_cast<GLsizei>(width), static_cast<GLsizei>(height)));
}
#else
@ -371,8 +371,8 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig
if (createFrameBuffer())
{
// Restore previously bound framebuffers
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_READ_FRAMEBUFFER, readFramebuffer));
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, drawFramebuffer));
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_READ_FRAMEBUFFER, static_cast<GLuint>(readFramebuffer)));
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, static_cast<GLuint>(drawFramebuffer)));
return true;
}
@ -446,7 +446,7 @@ bool RenderTextureImplFBO::createFrameBuffer()
Lock lock(mutex);
// Insert the FBO into our map
m_frameBuffers.insert(std::make_pair(Context::getActiveContextId(), static_cast<unsigned int>(frameBuffer)));
m_frameBuffers.insert(std::make_pair(Context::getActiveContextId(), frameBuffer));
}
#ifndef SFML_OPENGL_ES
@ -493,7 +493,7 @@ bool RenderTextureImplFBO::createFrameBuffer()
Lock lock(mutex);
// Insert the FBO into our map
m_multisampleFrameBuffers.insert(std::make_pair(Context::getActiveContextId(), static_cast<unsigned int>(multisampleFrameBuffer)));
m_multisampleFrameBuffers.insert(std::make_pair(Context::getActiveContextId(), multisampleFrameBuffer));
}
}
@ -601,7 +601,7 @@ void RenderTextureImplFBO::updateTexture(unsigned int)
{
// Set up the blit target (draw framebuffer) and blit (from the read framebuffer, our multisample FBO)
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, iter->second));
glCheck(GLEXT_glBlitFramebuffer(0, 0, m_width, m_height, 0, 0, m_width, m_height, GL_COLOR_BUFFER_BIT, GL_NEAREST));
glCheck(GLEXT_glBlitFramebuffer(0, 0, static_cast<GLint>(m_width), static_cast<GLint>(m_height), 0, 0, static_cast<GLint>(m_width), static_cast<GLint>(m_height), GL_COLOR_BUFFER_BIT, GL_NEAREST));
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, multisampleIter->second));
}
}

View File

@ -976,7 +976,7 @@ void Shader::bindTextures() const
{
GLint index = static_cast<GLsizei>(i + 1);
glCheck(GLEXT_glUniform1i(it->first, index));
glCheck(GLEXT_glActiveTexture(GLEXT_GL_TEXTURE0 + index));
glCheck(GLEXT_glActiveTexture(GLEXT_GL_TEXTURE0 + static_cast<GLenum>(index)));
Texture::bind(it->second);
++it;
}

View File

@ -66,7 +66,7 @@ void Shape::setTexture(const Texture* texture, bool resetRect)
{
// Recompute the texture area if requested, or if there was no texture & rect before
if (resetRect || (!m_texture && (m_textureRect == IntRect())))
setTextureRect(IntRect(0, 0, texture->getSize().x, texture->getSize().y));
setTextureRect(IntRect(0, 0, static_cast<int>(texture->getSize().x), static_cast<int>(texture->getSize().y)));
}
// Assign the new texture
@ -237,12 +237,14 @@ void Shape::updateFillColors()
////////////////////////////////////////////////////////////
void Shape::updateTexCoords()
{
FloatRect convertedTextureRect = FloatRect(m_textureRect);
for (std::size_t i = 0; i < m_vertices.getVertexCount(); ++i)
{
float xratio = m_insideBounds.width > 0 ? (m_vertices[i].position.x - m_insideBounds.left) / m_insideBounds.width : 0;
float yratio = m_insideBounds.height > 0 ? (m_vertices[i].position.y - m_insideBounds.top) / m_insideBounds.height : 0;
m_vertices[i].texCoords.x = m_textureRect.left + m_textureRect.width * xratio;
m_vertices[i].texCoords.y = m_textureRect.top + m_textureRect.height * yratio;
m_vertices[i].texCoords.x = convertedTextureRect.left + convertedTextureRect.width * xratio;
m_vertices[i].texCoords.y = convertedTextureRect.top + convertedTextureRect.height * yratio;
}
}

View File

@ -68,7 +68,7 @@ void Sprite::setTexture(const Texture& texture, bool resetRect)
// Recompute the texture area if requested, or if there was no valid texture & rect before
if (resetRect || (!m_texture && (m_textureRect == sf::IntRect())))
{
Vector2u size = texture.getSize();
Vector2i size = Vector2i(texture.getSize());
setTextureRect(IntRect(0, 0, size.x, size.y));
}
@ -165,10 +165,12 @@ void Sprite::updatePositions()
////////////////////////////////////////////////////////////
void Sprite::updateTexCoords()
{
float left = static_cast<float>(m_textureRect.left);
float right = left + m_textureRect.width;
float top = static_cast<float>(m_textureRect.top);
float bottom = top + m_textureRect.height;
FloatRect convertedTextureRect = FloatRect(m_textureRect);
float left = convertedTextureRect.left;
float right = left + convertedTextureRect.width;
float top = convertedTextureRect.top;
float bottom = top + convertedTextureRect.height;
m_vertices[0].texCoords = Vector2f(left, top);
m_vertices[1].texCoords = Vector2f(left, bottom);

View File

@ -113,7 +113,7 @@ Texture::~Texture()
{
TransientContextLock lock;
GLuint texture = static_cast<GLuint>(m_texture);
GLuint texture = m_texture;
glCheck(glDeleteTextures(1, &texture));
}
}
@ -160,7 +160,7 @@ bool Texture::create(unsigned int width, unsigned int height)
{
GLuint texture;
glCheck(glGenTextures(1, &texture));
m_texture = static_cast<unsigned int>(texture);
m_texture = texture;
}
// Make sure that the current texture binding will be preserved
@ -205,7 +205,7 @@ bool Texture::create(unsigned int width, unsigned int height)
// Initialize the texture
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
glCheck(glTexImage2D(GL_TEXTURE_2D, 0, (m_sRgb ? GLEXT_GL_SRGB8_ALPHA8 : GL_RGBA), m_actualSize.x, m_actualSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
glCheck(glTexImage2D(GL_TEXTURE_2D, 0, (m_sRgb ? GLEXT_GL_SRGB8_ALPHA8 : GL_RGBA), static_cast<GLsizei>(m_actualSize.x), static_cast<GLsizei>(m_actualSize.y), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP)));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP)));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
@ -277,7 +277,7 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area)
if (rectangle.top + rectangle.height > height) rectangle.height = height - rectangle.top;
// Create the texture and upload the pixels
if (create(rectangle.width, rectangle.height))
if (create(static_cast<unsigned int>(rectangle.width), static_cast<unsigned int>(rectangle.height)))
{
TransientContextLock lock;
@ -371,8 +371,8 @@ Image Texture::copyToImage() const
// Then we copy the useful pixels from the temporary array to the final one
const Uint8* src = &allPixels[0];
Uint8* dst = &pixels[0];
int srcPitch = m_actualSize.x * 4;
int dstPitch = m_size.x * 4;
unsigned int srcPitch = m_actualSize.x * 4;
unsigned int dstPitch = m_size.x * 4;
// Handle the case where source pixels are flipped vertically
if (m_pixelsFlipped)
@ -422,7 +422,7 @@ void Texture::update(const Uint8* pixels, unsigned int width, unsigned int heigh
// Copy pixels from the given array to the texture
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height), GL_RGBA, GL_UNSIGNED_BYTE, pixels));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
m_hasMipmap = false;
m_pixelsFlipped = false;
@ -503,8 +503,8 @@ void Texture::update(const Texture& texture, unsigned int x, unsigned int y)
{
// Blit the texture contents from the source to the destination texture
glCheck(GLEXT_glBlitFramebuffer(
0, texture.m_pixelsFlipped ? texture.m_size.y : 0, texture.m_size.x, texture.m_pixelsFlipped ? 0 : texture.m_size.y, // Source rectangle, flip y if source is flipped
x, y, x + texture.m_size.x, y + texture.m_size.y, // Destination rectangle
0, texture.m_pixelsFlipped ? static_cast<GLint>(texture.m_size.y) : 0, static_cast<GLint>(texture.m_size.x), texture.m_pixelsFlipped ? 0 : static_cast<GLint>(texture.m_size.y), // Source rectangle, flip y if source is flipped
static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLint>(x + texture.m_size.x), static_cast<GLint>(y + texture.m_size.y), // Destination rectangle
GL_COLOR_BUFFER_BIT, GL_NEAREST
));
}
@ -514,8 +514,8 @@ void Texture::update(const Texture& texture, unsigned int x, unsigned int y)
}
// Restore previously bound framebuffers
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_READ_FRAMEBUFFER, readFramebuffer));
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, drawFramebuffer));
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_READ_FRAMEBUFFER, static_cast<GLuint>(readFramebuffer)));
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, static_cast<GLuint>(drawFramebuffer)));
// Delete the framebuffers
glCheck(GLEXT_glDeleteFramebuffers(1, &sourceFrameBuffer));
@ -581,7 +581,7 @@ void Texture::update(const Window& window, unsigned int x, unsigned int y)
// Copy pixels from the back-buffer to the texture
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 0, 0, window.getSize().x, window.getSize().y));
glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(x), static_cast<GLint>(y), 0, 0, static_cast<GLsizei>(window.getSize().x), static_cast<GLsizei>(window.getSize().y)));
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST));
m_hasMipmap = false;
m_pixelsFlipped = true;
@ -757,15 +757,15 @@ void Texture::bind(const Texture* texture, CoordinateType coordinateType)
// setup scale factors that convert the range [0 .. size] to [0 .. 1]
if (coordinateType == Pixels)
{
matrix[0] = 1.f / texture->m_actualSize.x;
matrix[5] = 1.f / texture->m_actualSize.y;
matrix[0] = 1.f / static_cast<float>(texture->m_actualSize.x);
matrix[5] = 1.f / static_cast<float>(texture->m_actualSize.y);
}
// If pixels are flipped we must invert the Y axis
if (texture->m_pixelsFlipped)
{
matrix[5] = -matrix[5];
matrix[13] = static_cast<float>(texture->m_size.y) / texture->m_actualSize.y;
matrix[13] = static_cast<float>(texture->m_size.y) / static_cast<float>(texture->m_actualSize.y);
}
// Load the matrix

View File

@ -42,7 +42,7 @@ TextureSaver::TextureSaver()
////////////////////////////////////////////////////////////
TextureSaver::~TextureSaver()
{
glCheck(glBindTexture(GL_TEXTURE_2D, m_textureBinding));
glCheck(glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(m_textureBinding)));
}
} // namespace priv

View File

@ -71,7 +71,7 @@ void Transformable::setPosition(const Vector2f& position)
////////////////////////////////////////////////////////////
void Transformable::setRotation(float angle)
{
m_rotation = static_cast<float>(fmod(angle, 360));
m_rotation = std::fmod(angle, 360.f);
if (m_rotation < 0)
m_rotation += 360.f;
@ -184,8 +184,8 @@ const Transform& Transformable::getTransform() const
if (m_transformNeedUpdate)
{
float angle = -m_rotation * 3.141592654f / 180.f;
float cosine = static_cast<float>(std::cos(angle));
float sine = static_cast<float>(std::sin(angle));
float cosine = std::cos(angle);
float sine = std::sin(angle);
float sxc = m_scale.x * cosine;
float syc = m_scale.y * cosine;
float sxs = m_scale.x * sine;

View File

@ -147,7 +147,7 @@ bool VertexBuffer::create(std::size_t vertexCount)
}
glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, m_buffer));
glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, sizeof(Vertex) * vertexCount, 0, VertexBufferImpl::usageToGlEnum(m_usage)));
glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast<GLsizeiptrARB>(sizeof(Vertex) * vertexCount), 0, VertexBufferImpl::usageToGlEnum(m_usage)));
glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, 0));
m_size = vertexCount;
@ -190,12 +190,12 @@ bool VertexBuffer::update(const Vertex* vertices, std::size_t vertexCount, unsig
// Check if we need to resize or orphan the buffer
if (vertexCount >= m_size)
{
glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, sizeof(Vertex) * vertexCount, 0, VertexBufferImpl::usageToGlEnum(m_usage)));
glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast<GLsizeiptrARB>(sizeof(Vertex) * vertexCount), 0, VertexBufferImpl::usageToGlEnum(m_usage)));
m_size = vertexCount;
}
glCheck(GLEXT_glBufferSubData(GLEXT_GL_ARRAY_BUFFER, sizeof(Vertex) * offset, sizeof(Vertex) * vertexCount, vertices));
glCheck(GLEXT_glBufferSubData(GLEXT_GL_ARRAY_BUFFER, sizeof(Vertex) * offset, static_cast<GLsizeiptrARB>(sizeof(Vertex) * vertexCount), vertices));
glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, 0));
@ -225,7 +225,7 @@ bool VertexBuffer::update(const VertexBuffer& vertexBuffer)
glCheck(GLEXT_glBindBuffer(GLEXT_GL_COPY_READ_BUFFER, vertexBuffer.m_buffer));
glCheck(GLEXT_glBindBuffer(GLEXT_GL_COPY_WRITE_BUFFER, m_buffer));
glCheck(GLEXT_glCopyBufferSubData(GLEXT_GL_COPY_READ_BUFFER, GLEXT_GL_COPY_WRITE_BUFFER, 0, 0, sizeof(Vertex) * vertexBuffer.m_size));
glCheck(GLEXT_glCopyBufferSubData(GLEXT_GL_COPY_READ_BUFFER, GLEXT_GL_COPY_WRITE_BUFFER, 0, 0, static_cast<GLsizeiptr>(sizeof(Vertex) * vertexBuffer.m_size)));
glCheck(GLEXT_glBindBuffer(GLEXT_GL_COPY_WRITE_BUFFER, 0));
glCheck(GLEXT_glBindBuffer(GLEXT_GL_COPY_READ_BUFFER, 0));
@ -234,7 +234,7 @@ bool VertexBuffer::update(const VertexBuffer& vertexBuffer)
}
glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, m_buffer));
glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, sizeof(Vertex) * vertexBuffer.m_size, 0, VertexBufferImpl::usageToGlEnum(m_usage)));
glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast<GLsizeiptrARB>(sizeof(Vertex) * vertexBuffer.m_size), 0, VertexBufferImpl::usageToGlEnum(m_usage)));
void* destination = 0;
glCheck(destination = GLEXT_glMapBuffer(GLEXT_GL_ARRAY_BUFFER, GLEXT_GL_WRITE_ONLY));

View File

@ -108,7 +108,7 @@ void View::setSize(const Vector2f& size)
////////////////////////////////////////////////////////////
void View::setRotation(float angle)
{
m_rotation = static_cast<float>(fmod(angle, 360));
m_rotation = std::fmod(angle, 360.f);
if (m_rotation < 0)
m_rotation += 360.f;
@ -202,8 +202,8 @@ const Transform& View::getTransform() const
{
// Rotation components
float angle = m_rotation * 3.141592654f / 180.f;
float cosine = static_cast<float>(std::cos(angle));
float sine = static_cast<float>(std::sin(angle));
float cosine = std::cos(angle);
float sine = std::sin(angle);
float tx = -m_center.x * cosine - m_center.y * sine + m_center.x;
float ty = m_center.x * sine - m_center.y * cosine + m_center.y;