diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index 129afe22..841e7865 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -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 "$") + target_include_directories(${target} SYSTEM INTERFACE "$") endforeach() endif() diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index 52385782..a939a988 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -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") diff --git a/src/SFML/Graphics/CircleShape.cpp b/src/SFML/Graphics/CircleShape.cpp index 72814675..6dc41909 100644 --- a/src/SFML/Graphics/CircleShape.cpp +++ b/src/SFML/Graphics/CircleShape.cpp @@ -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(index) * 2.f * pi / static_cast(m_pointCount) - pi / 2.f; float x = std::cos(angle) * m_radius; float y = std::sin(angle) * m_radius; diff --git a/src/SFML/Graphics/Color.cpp b/src/SFML/Graphics/Color.cpp index f8cd4edf..c2429ee7 100644 --- a/src/SFML/Graphics/Color.cpp +++ b/src/SFML/Graphics/Color.cpp @@ -69,7 +69,7 @@ a(alpha) //////////////////////////////////////////////////////////// Color::Color(Uint32 color) : -r((color & 0xff000000) >> 24), +r(static_cast((color & 0xff000000) >> 24)), g(static_cast((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((r << 24) | (g << 16) | (b << 8) | a); } diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 09948ee7..27cd90e2 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -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(offset); sf::InputStream* stream = static_cast(rec->descriptor.pointer); - if (static_cast(stream->seek(offset)) == offset) + if (stream->seek(convertedOffset) == convertedOffset) { if (count > 0) - return static_cast(stream->read(reinterpret_cast(buffer), count)); + return static_cast(stream->read(reinterpret_cast(buffer), static_cast(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(characterSize) / 10.f; return -static_cast(FT_MulFix(face->underline_position, face->size->metrics.y_scale)) / static_cast(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(characterSize) / 14.f; return static_cast(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale)) / static_cast(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(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(weight) / static_cast(1 << 6); - glyph.lsbDelta = face->glyph->lsb_delta; - glyph.rsbDelta = face->glyph->rsb_delta; + glyph.lsbDelta = static_cast(face->glyph->lsb_delta); + glyph.rsbDelta = static_cast(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(padding); + glyph.textureRect.top += static_cast(padding); + glyph.textureRect.width -= static_cast(2 * padding); + glyph.textureRect.height -= static_cast(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(glyph.textureRect.left) - padding; + unsigned int y = static_cast(glyph.textureRect.top) - padding; + unsigned int w = static_cast(glyph.textureRect.width) + 2 * padding; + unsigned int h = static_cast(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::iterator it = page.rows.begin(); it != page.rows.end() && !row; ++it) { - float ratio = static_cast(height) / it->height; + float ratio = static_cast(height) / static_cast(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(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 diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 089ff827..606fd664 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -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(source.m_size.x); + srcRect.height = static_cast(source.m_size.y); } else { if (srcRect.left < 0) srcRect.left = 0; if (srcRect.top < 0) srcRect.top = 0; - if (srcRect.width > static_cast(source.m_size.x)) srcRect.width = source.m_size.x; - if (srcRect.height > static_cast(source.m_size.y)) srcRect.height = source.m_size.y; + if (srcRect.width > static_cast(source.m_size.x)) srcRect.width = static_cast(source.m_size.x); + if (srcRect.height > static_cast(source.m_size.y)) srcRect.height = static_cast(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(srcRect.width); + unsigned int height = static_cast(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(width) * 4; + unsigned int rows = height; + int srcStride = static_cast(source.m_size.x) * 4; + int dstStride = static_cast(m_size.x) * 4; + const Uint8* srcPixels = &source.m_pixels[0] + (static_cast(srcRect.left) + static_cast(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((src[0] * alpha + dst[0] * (255 - alpha)) / 255); + dst[1] = static_cast((src[1] * alpha + dst[1] * (255 - alpha)) / 255); + dst[2] = static_cast((src[2] * alpha + dst[2] * (255 - alpha)) / 255); + dst[3] = static_cast(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::iterator left = m_pixels.begin() + y * rowSize; - std::vector::iterator right = m_pixels.begin() + (y + 1) * rowSize - 4; + std::vector::iterator left = m_pixels.begin() + static_cast::iterator::difference_type>(y * rowSize); + std::vector::iterator right = m_pixels.begin() + static_cast::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::iterator::difference_type rowSize = static_cast::iterator::difference_type>(m_size.x * 4); std::vector::iterator top = m_pixels.begin(); std::vector::iterator bottom = m_pixels.end() - rowSize; diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index 93113fba..4cfc9e4b 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -115,13 +115,13 @@ bool ImageLoader::loadImageFromFile(const std::string& filename, std::vector(width); + size.y = static_cast(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(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(width); + size.y = static_cast(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(width * height * 4)); memcpy(&pixels[0], ptr, pixels.size()); } @@ -214,13 +214,13 @@ bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector& p if (ptr) { // Assign the image properties - size.x = width; - size.y = height; + size.x = static_cast(width); + size.y = static_cast(height); if (width && height) { // Copy the loaded pixels to the pixel buffer - pixels.resize(width * height * 4); + pixels.resize(static_cast(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(point.x) - viewport.left) / viewport.width; + normalized.y = 1.f - 2.f * (static_cast(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(( normalized.x + 1.f) / 2.f * viewport.width + viewport.left); pixel.y = static_cast((-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(getSize().y) - (viewport.top + viewport.height); glCheck(glViewport(viewport.left, top, viewport.width, viewport.height)); // Set the projection matrix diff --git a/src/SFML/Graphics/RenderTextureImplDefault.cpp b/src/SFML/Graphics/RenderTextureImplDefault.cpp index 17d9cf86..92d364ec 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.cpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.cpp @@ -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(m_width), static_cast(m_height))); } } // namespace priv diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp index a2a67bf9..ba8c1f65 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.cpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp @@ -90,7 +90,7 @@ namespace { if (iter->first == contextId) { - GLuint frameBuffer = static_cast(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(m_colorBuffer); + GLuint colorBuffer = m_colorBuffer; glCheck(GLEXT_glDeleteRenderbuffers(1, &colorBuffer)); } // Destroy the depth/stencil buffer if (m_depthStencilBuffer) { - GLuint depthStencilBuffer = static_cast(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(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(width), static_cast(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(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(width), static_cast(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(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(settings.antialiasingLevel), m_sRgb ? GL_SRGB8_ALPHA8_EXT : GL_RGBA, static_cast(width), static_cast(height))); // Create the multisample depth/stencil buffer if requested if (settings.stencilBits) { GLuint depthStencil = 0; glCheck(GLEXT_glGenRenderbuffers(1, &depthStencil)); - m_depthStencilBuffer = static_cast(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(settings.antialiasingLevel), GLEXT_GL_DEPTH24_STENCIL8, static_cast(width), static_cast(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(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(settings.antialiasingLevel), GLEXT_GL_DEPTH_COMPONENT, static_cast(width), static_cast(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(readFramebuffer))); + glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, static_cast(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(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(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(m_width), static_cast(m_height), 0, 0, static_cast(m_width), static_cast(m_height), GL_COLOR_BUFFER_BIT, GL_NEAREST)); glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, multisampleIter->second)); } } diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index ce1be3b8..e5b26593 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -976,7 +976,7 @@ void Shader::bindTextures() const { GLint index = static_cast(i + 1); glCheck(GLEXT_glUniform1i(it->first, index)); - glCheck(GLEXT_glActiveTexture(GLEXT_GL_TEXTURE0 + index)); + glCheck(GLEXT_glActiveTexture(GLEXT_GL_TEXTURE0 + static_cast(index))); Texture::bind(it->second); ++it; } diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index 50a7ab04..8acc286d 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -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(texture->getSize().x), static_cast(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; } } diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 6a23258c..100ac673 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -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(m_textureRect.left); - float right = left + m_textureRect.width; - float top = static_cast(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); diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 8869a247..bf546ccf 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -113,7 +113,7 @@ Texture::~Texture() { TransientContextLock lock; - GLuint texture = static_cast(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(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(m_actualSize.x), static_cast(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(rectangle.width), static_cast(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(x), static_cast(y), static_cast(width), static_cast(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(texture.m_size.y) : 0, static_cast(texture.m_size.x), texture.m_pixelsFlipped ? 0 : static_cast(texture.m_size.y), // Source rectangle, flip y if source is flipped + static_cast(x), static_cast(y), static_cast(x + texture.m_size.x), static_cast(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(readFramebuffer))); + glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, static_cast(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(x), static_cast(y), 0, 0, static_cast(window.getSize().x), static_cast(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(texture->m_actualSize.x); + matrix[5] = 1.f / static_cast(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(texture->m_size.y) / texture->m_actualSize.y; + matrix[13] = static_cast(texture->m_size.y) / static_cast(texture->m_actualSize.y); } // Load the matrix diff --git a/src/SFML/Graphics/TextureSaver.cpp b/src/SFML/Graphics/TextureSaver.cpp index b5b10f50..1fef485c 100644 --- a/src/SFML/Graphics/TextureSaver.cpp +++ b/src/SFML/Graphics/TextureSaver.cpp @@ -42,7 +42,7 @@ TextureSaver::TextureSaver() //////////////////////////////////////////////////////////// TextureSaver::~TextureSaver() { - glCheck(glBindTexture(GL_TEXTURE_2D, m_textureBinding)); + glCheck(glBindTexture(GL_TEXTURE_2D, static_cast(m_textureBinding))); } } // namespace priv diff --git a/src/SFML/Graphics/Transformable.cpp b/src/SFML/Graphics/Transformable.cpp index f1b11444..689d74fe 100644 --- a/src/SFML/Graphics/Transformable.cpp +++ b/src/SFML/Graphics/Transformable.cpp @@ -71,7 +71,7 @@ void Transformable::setPosition(const Vector2f& position) //////////////////////////////////////////////////////////// void Transformable::setRotation(float angle) { - m_rotation = static_cast(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(std::cos(angle)); - float sine = static_cast(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; diff --git a/src/SFML/Graphics/VertexBuffer.cpp b/src/SFML/Graphics/VertexBuffer.cpp index 9fb1a853..d70fef1b 100644 --- a/src/SFML/Graphics/VertexBuffer.cpp +++ b/src/SFML/Graphics/VertexBuffer.cpp @@ -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(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(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(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(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(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)); diff --git a/src/SFML/Graphics/View.cpp b/src/SFML/Graphics/View.cpp index 5a77b930..32432a75 100644 --- a/src/SFML/Graphics/View.cpp +++ b/src/SFML/Graphics/View.cpp @@ -108,7 +108,7 @@ void View::setSize(const Vector2f& size) //////////////////////////////////////////////////////////// void View::setRotation(float angle) { - m_rotation = static_cast(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(std::cos(angle)); - float sine = static_cast(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;