From abfd41c35f9aca269fbb92adb5d95184e7172baa Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 28 Mar 2020 15:59:50 -0300 Subject: [PATCH] Use named casts in openrct2-ui/drawing --- src/openrct2-ui/drawing/BitmapReader.cpp | 6 +-- .../drawing/engines/DrawingEngineFactory.hpp | 2 +- .../engines/HardwareDisplayDrawingEngine.cpp | 25 ++++++----- .../drawing/engines/SoftwareDrawingEngine.cpp | 4 +- .../engines/opengl/ApplyPaletteShader.cpp | 8 ++-- .../opengl/ApplyTransparencyShader.cpp | 6 ++- .../drawing/engines/opengl/DrawLineShader.cpp | 25 +++++++---- .../drawing/engines/opengl/DrawRectShader.cpp | 45 ++++++++++++------- .../engines/opengl/OpenGLDrawingEngine.cpp | 20 ++++----- .../engines/opengl/OpenGLFramebuffer.cpp | 2 +- .../engines/opengl/OpenGLShaderProgram.cpp | 4 +- .../drawing/engines/opengl/TextureCache.cpp | 6 +-- .../drawing/engines/opengl/TextureCache.h | 14 +++--- 13 files changed, 96 insertions(+), 71 deletions(-) diff --git a/src/openrct2-ui/drawing/BitmapReader.cpp b/src/openrct2-ui/drawing/BitmapReader.cpp index 820e782ae4..712d2ad3d7 100644 --- a/src/openrct2-ui/drawing/BitmapReader.cpp +++ b/src/openrct2-ui/drawing/BitmapReader.cpp @@ -24,7 +24,7 @@ static std::vector ReadToVector(std::istream& stream) auto size = stream.tellg(); result.resize(size); stream.seekg(0, std::ios_base::beg); - stream.read((char*)result.data(), size); + stream.read(reinterpret_cast(result.data()), size); } return result; } @@ -34,7 +34,7 @@ static std::vector ReadToVector(std::istream& stream) static Image ReadBitmap(std::istream& istream, IMAGE_FORMAT format) { auto buffer = ReadToVector(istream); - auto sdlStream = SDL_RWFromConstMem(buffer.data(), (int)buffer.size()); + auto sdlStream = SDL_RWFromConstMem(buffer.data(), static_cast(buffer.size())); auto bitmap = SDL_LoadBMP_RW(sdlStream, 1); if (bitmap != nullptr) { @@ -59,7 +59,7 @@ static Image ReadBitmap(std::istream& istream, IMAGE_FORMAT format) std::fill(image.Pixels.begin(), image.Pixels.end(), 0xFF); // Copy pixels over - auto src = (const uint8_t*)bitmap->pixels; + auto src = static_cast(bitmap->pixels); auto dst = image.Pixels.data(); if (numChannels == 4) { diff --git a/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp b/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp index f78083a076..22fbdbba07 100644 --- a/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp +++ b/src/openrct2-ui/drawing/engines/DrawingEngineFactory.hpp @@ -33,7 +33,7 @@ namespace OpenRCT2 std::unique_ptr Create( DRAWING_ENGINE_TYPE type, const std::shared_ptr& uiContext) override { - switch ((int32_t)type) + switch (static_cast(type)) { case DRAWING_ENGINE_SOFTWARE: return CreateSoftwareDrawingEngine(uiContext); diff --git a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp index a474d9d124..c3fe0a2b5b 100644 --- a/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/HardwareDisplayDrawingEngine.cpp @@ -57,7 +57,7 @@ public: : X8DrawingEngine(uiContext) , _uiContext(uiContext) { - _window = (SDL_Window*)_uiContext->GetWindow(); + _window = static_cast(_uiContext->GetWindow()); } ~HardwareDisplayDrawingEngine() override @@ -221,7 +221,8 @@ private: else #endif { - CopyBitsToTexture(_screenTexture, _bits, (int32_t)_width, (int32_t)_height, _paletteHWMapped); + CopyBitsToTexture( + _screenTexture, _bits, static_cast(_width), static_cast(_height), _paletteHWMapped); } if (smoothNN) { @@ -279,11 +280,11 @@ private: { for (int32_t x = width; x > 0; x--) { - const uint8_t lower = *(uint8_t*)(&palette[*src++]); - const uint8_t upper = *(uint8_t*)(&palette[*src++]); + const uint8_t lower = *reinterpret_cast(&palette[*src++]); + const uint8_t upper = *reinterpret_cast(&palette[*src++]); *dst++ = (lower << 8) | upper; } - dst = (uint16_t*)(((uint8_t*)dst) + padding); + dst = reinterpret_cast(reinterpret_cast(dst) + padding); } } else if (pitch == width + padding) @@ -293,7 +294,7 @@ private: { for (int32_t x = width; x > 0; x--) { - *dst++ = *(uint8_t*)(&palette[*src++]); + *dst++ = *reinterpret_cast(&palette[*src++]); } dst += padding; } @@ -352,13 +353,13 @@ private: auto timeLeft = GetDirtyVisualTime(x, y); if (timeLeft > 0) { - uint8_t alpha = (uint8_t)(timeLeft * 5 / 2); + uint8_t alpha = static_cast(timeLeft * 5 / 2); SDL_Rect ddRect; - ddRect.x = (int32_t)(x * _dirtyGrid.BlockWidth * scaleX); - ddRect.y = (int32_t)(y * _dirtyGrid.BlockHeight * scaleY); - ddRect.w = (int32_t)(_dirtyGrid.BlockWidth * scaleX); - ddRect.h = (int32_t)(_dirtyGrid.BlockHeight * scaleY); + ddRect.x = static_cast(x * _dirtyGrid.BlockWidth * scaleX); + ddRect.y = static_cast(y * _dirtyGrid.BlockHeight * scaleY); + ddRect.w = static_cast(_dirtyGrid.BlockWidth * scaleX); + ddRect.h = static_cast(_dirtyGrid.BlockHeight * scaleY); SDL_SetRenderDrawColor(_sdlRenderer, 255, 255, 255, alpha); SDL_RenderFillRect(_sdlRenderer, &ddRect); @@ -369,7 +370,7 @@ private: void ReadCentrePixel(uint32_t* pixel) { - SDL_Rect centrePixelRegion = { (int32_t)(_width / 2), (int32_t)(_height / 2), 1, 1 }; + SDL_Rect centrePixelRegion = { static_cast(_width / 2), static_cast(_height / 2), 1, 1 }; SDL_RenderReadPixels(_sdlRenderer, ¢rePixelRegion, SDL_PIXELFORMAT_RGBA8888, pixel, sizeof(uint32_t)); } diff --git a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp index 4ef671c301..f7fe303956 100644 --- a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp @@ -37,7 +37,7 @@ public: : X8DrawingEngine(uiContext) , _uiContext(uiContext) { - _window = (SDL_Window*)_uiContext->GetWindow(); + _window = static_cast(_uiContext->GetWindow()); } ~SoftwareDrawingEngine() override @@ -113,7 +113,7 @@ private: } // Copy pixels from the virtual screen buffer to the surface - std::copy_n(_bits, _surface->pitch * _surface->h, (uint8_t*)_surface->pixels); + std::copy_n(_bits, _surface->pitch * _surface->h, static_cast(_surface->pixels)); // Unlock the surface if (SDL_MUSTLOCK(_surface)) diff --git a/src/openrct2-ui/drawing/engines/opengl/ApplyPaletteShader.cpp b/src/openrct2-ui/drawing/engines/opengl/ApplyPaletteShader.cpp index 6ee690e44a..572f55ba4d 100644 --- a/src/openrct2-ui/drawing/engines/opengl/ApplyPaletteShader.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/ApplyPaletteShader.cpp @@ -39,9 +39,11 @@ ApplyPaletteShader::ApplyPaletteShader() glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW); glBindVertexArray(_vao); - glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, position)); glVertexAttribPointer( - vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, texturecoordinate)); + vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, position))); + glVertexAttribPointer( + vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), + reinterpret_cast(offsetof(VDStruct, texturecoordinate))); glEnableVertexAttribArray(vPosition); glEnableVertexAttribArray(vTextureCoordinate); @@ -72,7 +74,7 @@ void ApplyPaletteShader::SetTexture(GLuint texture) void ApplyPaletteShader::SetPalette(const vec4* glPalette) { - glUniform4fv(uPalette, 256, (const GLfloat*)glPalette); + glUniform4fv(uPalette, 256, reinterpret_cast(glPalette)); } void ApplyPaletteShader::Draw() diff --git a/src/openrct2-ui/drawing/engines/opengl/ApplyTransparencyShader.cpp b/src/openrct2-ui/drawing/engines/opengl/ApplyTransparencyShader.cpp index 5eb10a33bd..ea9d4600cd 100644 --- a/src/openrct2-ui/drawing/engines/opengl/ApplyTransparencyShader.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/ApplyTransparencyShader.cpp @@ -39,9 +39,11 @@ ApplyTransparencyShader::ApplyTransparencyShader() glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW); glBindVertexArray(_vao); - glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, position)); glVertexAttribPointer( - vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, texturecoordinate)); + vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, position))); + glVertexAttribPointer( + vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), + reinterpret_cast(offsetof(VDStruct, texturecoordinate))); glEnableVertexAttribArray(vPosition); glEnableVertexAttribArray(vTextureCoordinate); diff --git a/src/openrct2-ui/drawing/engines/opengl/DrawLineShader.cpp b/src/openrct2-ui/drawing/engines/opengl/DrawLineShader.cpp index 19cba2d1e2..cb0e953dd4 100644 --- a/src/openrct2-ui/drawing/engines/opengl/DrawLineShader.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/DrawLineShader.cpp @@ -39,16 +39,23 @@ DrawLineShader::DrawLineShader() glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW); glBindVertexArray(_vao); - glVertexAttribPointer(vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[0])); - glVertexAttribPointer(vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[1])); - glVertexAttribPointer(vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[2])); - glVertexAttribPointer(vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[3])); + glVertexAttribPointer( + vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[0]))); + glVertexAttribPointer( + vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[1]))); + glVertexAttribPointer( + vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[2]))); + glVertexAttribPointer( + vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[3]))); glBindBuffer(GL_ARRAY_BUFFER, _vboInstances); - glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, clip)); - glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, bounds)); - glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, colour)); - glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, depth)); + glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawLineCommand), reinterpret_cast(offsetof(DrawLineCommand, clip))); + glVertexAttribIPointer( + vBounds, 4, GL_INT, sizeof(DrawLineCommand), reinterpret_cast(offsetof(DrawLineCommand, bounds))); + glVertexAttribIPointer( + vColour, 1, GL_UNSIGNED_INT, sizeof(DrawLineCommand), reinterpret_cast(offsetof(DrawLineCommand, colour))); + glVertexAttribIPointer( + vDepth, 1, GL_INT, sizeof(DrawLineCommand), reinterpret_cast(offsetof(DrawLineCommand, depth))); glEnableVertexAttribArray(vVertMat + 0); glEnableVertexAttribArray(vVertMat + 1); @@ -98,7 +105,7 @@ void DrawLineShader::DrawInstances(const LineCommandBatch& instances) glBindBuffer(GL_ARRAY_BUFFER, _vboInstances); glBufferData(GL_ARRAY_BUFFER, sizeof(DrawLineCommand) * instances.size(), instances.data(), GL_STREAM_DRAW); - glDrawArraysInstanced(GL_LINES, 0, 2, (GLsizei)instances.size()); + glDrawArraysInstanced(GL_LINES, 0, 2, static_cast(instances.size())); } #endif /* DISABLE_OPENGL */ diff --git a/src/openrct2-ui/drawing/engines/opengl/DrawRectShader.cpp b/src/openrct2-ui/drawing/engines/opengl/DrawRectShader.cpp index c2bf52ec31..2ba7f5a1be 100644 --- a/src/openrct2-ui/drawing/engines/opengl/DrawRectShader.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/DrawRectShader.cpp @@ -41,26 +41,39 @@ DrawRectShader::DrawRectShader() glBindVertexArray(_vao); - glVertexAttribPointer(vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[0])); - glVertexAttribPointer(vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[1])); - glVertexAttribPointer(vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[2])); - glVertexAttribPointer(vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[3])); - glVertexAttribPointer(vVertVec, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, vec)); + glVertexAttribPointer( + vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[0]))); + glVertexAttribPointer( + vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[1]))); + glVertexAttribPointer( + vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[2]))); + glVertexAttribPointer( + vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, mat[3]))); + glVertexAttribPointer(vVertVec, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast(offsetof(VDStruct, vec))); glBindBuffer(GL_ARRAY_BUFFER, _vboInstances); - glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, clip)); + glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, clip))); glVertexAttribIPointer( - vTexColourAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texColourAtlas)); + vTexColourAtlas, 1, GL_INT, sizeof(DrawRectCommand), + reinterpret_cast(offsetof(DrawRectCommand, texColourAtlas))); glVertexAttribPointer( - vTexColourBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texColourBounds)); - glVertexAttribIPointer(vTexMaskAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texMaskAtlas)); + vTexColourBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), + reinterpret_cast(offsetof(DrawRectCommand, texColourBounds))); + glVertexAttribIPointer( + vTexMaskAtlas, 1, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, texMaskAtlas))); glVertexAttribPointer( - vTexMaskBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texMaskBounds)); - glVertexAttribIPointer(vPalettes, 3, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, palettes)); - glVertexAttribIPointer(vFlags, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, flags)); - glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, colour)); - glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, bounds)); - glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, depth)); + vTexMaskBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), + reinterpret_cast(offsetof(DrawRectCommand, texMaskBounds))); + glVertexAttribIPointer( + vPalettes, 3, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, palettes))); + glVertexAttribIPointer( + vFlags, 1, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, flags))); + glVertexAttribIPointer( + vColour, 1, GL_UNSIGNED_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, colour))); + glVertexAttribIPointer( + vBounds, 4, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, bounds))); + glVertexAttribIPointer( + vDepth, 1, GL_INT, sizeof(DrawRectCommand), reinterpret_cast(offsetof(DrawRectCommand, depth))); glEnableVertexAttribArray(vVertMat + 0); glEnableVertexAttribArray(vVertMat + 1); @@ -152,7 +165,7 @@ void DrawRectShader::SetInstances(const RectCommandBatch& instances) glBindBuffer(GL_ARRAY_BUFFER, _vboInstances); glBufferData(GL_ARRAY_BUFFER, sizeof(DrawRectCommand) * instances.size(), instances.data(), GL_STREAM_DRAW); - _instanceCount = (GLsizei)instances.size(); + _instanceCount = static_cast(instances.size()); } void DrawRectShader::DrawInstances() diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp index 8c0f86b620..e434555d71 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -153,7 +153,7 @@ public: uint32_t finalPixelOffset = width + pixelOffset; uint32_t xPixelOffset = pixelOffset; - xPixelOffset += ((uint8_t)(patternX - patternStartXOffset)) % patternXSpace; + xPixelOffset += (static_cast(patternX - patternStartXOffset)) % patternXSpace; uint8_t patternPixel = pattern[patternYPos * 2 + 1]; for (; xPixelOffset < finalPixelOffset; xPixelOffset += patternXSpace) @@ -204,7 +204,7 @@ public: , _drawingContext(new OpenGLDrawingContext(this)) , _rainDrawer(_drawingContext) { - _window = (SDL_Window*)_uiContext->GetWindow(); + _window = static_cast(_uiContext->GetWindow()); _bitsDPI.DrawingEngine = this; # ifdef __ENABLE_LIGHTFX__ lightfx_set_available(false); @@ -839,8 +839,8 @@ void OpenGLDrawingContext::DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, int32_t drawOffsetX = g1Element->x_offset; int32_t drawOffsetY = g1Element->y_offset; - int32_t drawWidth = (uint16_t)g1Element->width; - int32_t drawHeight = (uint16_t)g1Element->height; + int32_t drawWidth = static_cast(g1Element->width); + int32_t drawHeight = static_cast(g1Element->height); int32_t left = x + drawOffsetX; int32_t top = y + drawOffsetY; @@ -887,8 +887,8 @@ void OpenGLDrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8 int32_t drawOffsetX = g1Element->x_offset; int32_t drawOffsetY = g1Element->y_offset; - int32_t drawWidth = (uint16_t)g1Element->width; - int32_t drawHeight = (uint16_t)g1Element->height; + int32_t drawWidth = static_cast(g1Element->width); + int32_t drawHeight = static_cast(g1Element->height); int32_t left = x + drawOffsetX; int32_t top = y + drawOffsetY; @@ -1003,14 +1003,14 @@ void OpenGLDrawingContext::SetDPI(rct_drawpixelinfo* dpi) { rct_drawpixelinfo* screenDPI = _engine->GetDPI(); # ifndef NDEBUG - size_t bitsSize = (size_t)screenDPI->height * (size_t)(screenDPI->width + screenDPI->pitch); + size_t bitsSize = static_cast(screenDPI->height) * static_cast(screenDPI->width + screenDPI->pitch); # endif - size_t bitsOffset = (size_t)(dpi->bits - screenDPI->bits); + size_t bitsOffset = static_cast(dpi->bits - screenDPI->bits); assert(bitsOffset < bitsSize); - _clipLeft = (int32_t)(bitsOffset % (screenDPI->width + screenDPI->pitch)); - _clipTop = (int32_t)(bitsOffset / (screenDPI->width + screenDPI->pitch)); + _clipLeft = static_cast(bitsOffset % (screenDPI->width + screenDPI->pitch)); + _clipTop = static_cast(bitsOffset / (screenDPI->width + screenDPI->pitch)); _clipRight = _clipLeft + (dpi->width / dpi->zoom_level); _clipBottom = _clipTop + (dpi->height / dpi->zoom_level); _offsetX = _clipLeft - dpi->x; diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLFramebuffer.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLFramebuffer.cpp index e8951c9404..cf19540416 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLFramebuffer.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLFramebuffer.cpp @@ -72,7 +72,7 @@ OpenGLFramebuffer::~OpenGLFramebuffer() void OpenGLFramebuffer::Bind() const { glBindFramebuffer(GL_FRAMEBUFFER, _id); - glViewport(0, 0, (GLsizei)_width, (GLsizei)_height); + glViewport(0, 0, static_cast(_width), static_cast(_height)); } void OpenGLFramebuffer::BindDraw() const diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp index 44f4e92f18..67e8689391 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp @@ -29,7 +29,7 @@ OpenGLShader::OpenGLShader(const char* name, GLenum type) auto sourceCodeStr = sourceCode.c_str(); _id = glCreateShader(type); - glShaderSource(_id, 1, (const GLchar**)&sourceCodeStr, nullptr); + glShaderSource(_id, 1, static_cast(&sourceCodeStr), nullptr); glCompileShader(_id); GLint status; @@ -84,7 +84,7 @@ std::string OpenGLShader::ReadSourceCode(const std::string& path) } auto fileData = std::string((size_t)fileLength + 1, '\0'); - fs.Read((void*)fileData.data(), fileLength); + fs.Read(static_cast(fileData.data()), fileLength); return fileData; } diff --git a/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp b/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp index c353b6f0a3..88ca07becb 100644 --- a/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/TextureCache.cpp @@ -86,7 +86,7 @@ BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32_t image) // Load new texture. unique_lock lock(_mutex); - index = (uint32_t)_textureCache.size(); + index = static_cast(_textureCache.size()); AtlasTextureInfo info = LoadImageTexture(image); @@ -105,7 +105,7 @@ BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t* pa { shared_lock lock(_mutex); - std::copy_n(palette, sizeof(glyphId.Palette), (uint8_t*)&glyphId.Palette); + std::copy_n(palette, sizeof(glyphId.Palette), reinterpret_cast(&glyphId.Palette)); auto kvp = _glyphTextureMap.find(glyphId); if (kvp != _glyphTextureMap.end()) @@ -271,7 +271,7 @@ AtlasTextureInfo TextureCache::AllocateImage(int32_t imageWidth, int32_t imageHe } // If there is no such atlas, then create a new one - if ((int32_t)_atlases.size() >= _atlasesTextureIndicesLimit) + if (static_cast(_atlases.size()) >= _atlasesTextureIndicesLimit) { throw std::runtime_error("more texture atlases required, but device limit reached!"); } diff --git a/src/openrct2-ui/drawing/engines/opengl/TextureCache.h b/src/openrct2-ui/drawing/engines/opengl/TextureCache.h index 5ee5a7417c..a7065ee75e 100644 --- a/src/openrct2-ui/drawing/engines/opengl/TextureCache.h +++ b/src/openrct2-ui/drawing/engines/opengl/TextureCache.h @@ -105,7 +105,7 @@ public: _freeSlots.resize(_cols * _rows); for (size_t i = 0; i < _freeSlots.size(); i++) { - _freeSlots[i] = (GLuint)i; + _freeSlots[i] = static_cast(i); } } @@ -146,7 +146,7 @@ public: [[nodiscard]] int32_t GetFreeSlots() const { - return (int32_t)_freeSlots.size(); + return static_cast(_freeSlots.size()); } static int32_t CalculateImageSizeOrder(int32_t actualWidth, int32_t actualHeight) @@ -158,7 +158,7 @@ public: actualSize = TEXTURE_CACHE_SMALLEST_SLOT; } - return (int32_t)ceil(log2f((float)actualSize)); + return static_cast(ceil(log2f(static_cast(actualSize)))); } private: @@ -178,10 +178,10 @@ private: [[nodiscard]] vec4 NormalizeCoordinates(const ivec4& coords) const { return vec4{ - coords.x / (float)_atlasWidth, - coords.y / (float)_atlasHeight, - coords.z / (float)_atlasWidth, - coords.w / (float)_atlasHeight, + coords.x / static_cast(_atlasWidth), + coords.y / static_cast(_atlasHeight), + coords.z / static_cast(_atlasWidth), + coords.w / static_cast(_atlasHeight), }; } };