diff --git a/.clang-tidy b/.clang-tidy index 5fbfdfdc..37cf2a2f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -62,7 +62,6 @@ cert-str34-c, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-pro-type-member-init, -cppcoreguidelines-pro-type-static-cast-downcast, cppcoreguidelines-slicing, google-default-arguments, google-runtime-operator, diff --git a/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp b/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp index 05df1b67..56a83b03 100644 --- a/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp +++ b/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp @@ -1403,7 +1403,7 @@ namespace MobileGL::MG_Backend::DirectGLES { return; } - auto* textureMipmapObject = dynamic_cast(textureObject.get()); + auto* textureMipmapObject = static_cast(textureObject.get()); auto& levelRange = textureMipmapObject->GetLevelRange(); MGLOG_D("GetTexImage: mipmap level range = [%d, %d)", levelRange.x(), levelRange.y()); diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index 838bbf10..3195b39f 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -391,7 +391,7 @@ namespace MobileGL::MG_Backend::DirectGLES { switch (stateTextureObject->GetStorageType()) { case TextureStorageType::Mipmap: { auto* textureMipmapObject = - dynamic_cast(stateTextureObject.get()); + static_cast(stateTextureObject.get()); const auto mipmapCount = textureMipmapObject->GetMipmapLevelCount(); currentTextureInfo.mipmapLevels = mipmapCount; @@ -515,7 +515,7 @@ namespace MobileGL::MG_Backend::DirectGLES { } case TextureStorageType::Buffer: { auto* textureBufferObject = - dynamic_cast(stateTextureObject.get()); + static_cast(stateTextureObject.get()); auto& slot = textureBufferObject->GetBufferBindingSlot(); auto& buffer = slot.GetBoundObject(); auto bufferIndex = buffer->GetExternalIndex(); diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureSamplerManager.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureSamplerManager.cpp index 221f0ace..e4129171 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureSamplerManager.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureSamplerManager.cpp @@ -145,7 +145,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { return false; } - const auto* mipTexture = dynamic_cast(&texture); + const auto* mipTexture = static_cast(&texture); if (!mipTexture) { return false; } @@ -198,7 +198,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { imageInfo.format = format; imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + imageInfo.usage = + VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; VK_VERIFY(vkCreateImage(m_device, &imageInfo, nullptr, &resource.image), "vkCreateImage(texture)"); @@ -257,9 +258,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { VkMemoryAllocateInfo allocInfo{}; allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; allocInfo.allocationSize = requirements.size; - allocInfo.memoryTypeIndex = - FindMemoryType(requirements.memoryTypeBits, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + allocInfo.memoryTypeIndex = FindMemoryType( + requirements.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); VK_VERIFY(vkAllocateMemory(m_device, &allocInfo, nullptr, &stagingMemory), "vkAllocateMemory(staging texture)"); VK_VERIFY(vkBindBufferMemory(m_device, stagingBuffer, stagingMemory, 0), "vkBindBufferMemory(staging texture)"); @@ -296,8 +296,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { copy.imageSubresource.layerCount = 1; copy.imageOffset = {0, 0, 0}; copy.imageExtent = {resource.extent.width, resource.extent.height, 1}; - vkCmdCopyBufferToImage(commandBuffer, stagingBuffer, resource.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, - ©); + vkCmdCopyBufferToImage(commandBuffer, stagingBuffer, resource.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + 1, ©); VkImageMemoryBarrier toSampled{}; toSampled.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; @@ -313,8 +313,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { toSampled.subresourceRange.levelCount = 1; toSampled.subresourceRange.baseArrayLayer = 0; toSampled.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, - 0, nullptr, 0, nullptr, 1, &toSampled); + vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, 0, nullptr, 0, nullptr, 1, &toSampled); }); vkDestroyBuffer(m_device, stagingBuffer, nullptr); @@ -378,7 +378,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { Bool VkTextureSamplerManager::ResolveLevel0(const MG_State::GLState::ITextureObject& texture, TextureUploadTarget& outTarget, IntVec3& outTexelSize, SizeT& outByteSize) { - const auto* mipTexture = dynamic_cast(&texture); + const auto* mipTexture = static_cast(&texture); if (!mipTexture) { return false; } @@ -435,7 +435,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { samplerInfo.mipLodBias = sampler.GetLodBias(); samplerInfo.anisotropyEnable = VK_FALSE; samplerInfo.maxAnisotropy = 1.0f; - samplerInfo.compareEnable = sampler.GetCompareMode() == SamplerCompareMode::CompareToTexture ? VK_TRUE : VK_FALSE; + samplerInfo.compareEnable = + sampler.GetCompareMode() == SamplerCompareMode::CompareToTexture ? VK_TRUE : VK_FALSE; samplerInfo.compareOp = ToVkCompareOp(sampler.GetSamplerCompareFunc()); samplerInfo.minLod = sampler.GetMinLod(); samplerInfo.maxLod = sampler.GetMaxLod(); @@ -531,10 +532,12 @@ namespace MobileGL::MG_Backend::DirectVulkan { VkMemoryAllocateInfo imageAllocInfo{}; imageAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; imageAllocInfo.allocationSize = imageMemReq.size; - imageAllocInfo.memoryTypeIndex = FindMemoryType(imageMemReq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + imageAllocInfo.memoryTypeIndex = + FindMemoryType(imageMemReq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); VK_VERIFY(vkAllocateMemory(m_device, &imageAllocInfo, nullptr, &m_fallbackImageMemory), "vkAllocateMemory(fallback)"); - VK_VERIFY(vkBindImageMemory(m_device, m_fallbackImage, m_fallbackImageMemory, 0), "vkBindImageMemory(fallback)"); + VK_VERIFY(vkBindImageMemory(m_device, m_fallbackImage, m_fallbackImageMemory, 0), + "vkBindImageMemory(fallback)"); VkBuffer stagingBuffer = VK_NULL_HANDLE; VkDeviceMemory stagingMemory = VK_NULL_HANDLE; @@ -552,9 +555,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { VkMemoryAllocateInfo stagingAllocInfo{}; stagingAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; stagingAllocInfo.allocationSize = stagingMemReq.size; - stagingAllocInfo.memoryTypeIndex = - FindMemoryType(stagingMemReq.memoryTypeBits, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + stagingAllocInfo.memoryTypeIndex = FindMemoryType( + stagingMemReq.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); VK_VERIFY(vkAllocateMemory(m_device, &stagingAllocInfo, nullptr, &stagingMemory), "vkAllocateMemory(fallback)"); VK_VERIFY(vkBindBufferMemory(m_device, stagingBuffer, stagingMemory, 0), "vkBindBufferMemory(fallback)"); @@ -587,8 +589,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { copy.imageSubresource.baseArrayLayer = 0; copy.imageSubresource.layerCount = 1; copy.imageExtent = {1, 1, 1}; - vkCmdCopyBufferToImage(commandBuffer, stagingBuffer, m_fallbackImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, - ©); + vkCmdCopyBufferToImage(commandBuffer, stagingBuffer, m_fallbackImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + 1, ©); VkImageMemoryBarrier toSampled{}; toSampled.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; @@ -604,8 +606,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { toSampled.subresourceRange.levelCount = 1; toSampled.subresourceRange.baseArrayLayer = 0; toSampled.subresourceRange.layerCount = 1; - vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, - 0, nullptr, 0, nullptr, 1, &toSampled); + vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, 0, nullptr, 0, nullptr, 1, &toSampled); }); vkDestroyBuffer(m_device, stagingBuffer, nullptr); diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index fa54de40..31a9b221 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -103,9 +103,9 @@ namespace MobileGL::MG_Impl::GLImpl { // Assert this for extra safety. // This should automatically compiled out in release, // so that we don't take the perf hit of dyn-cast. - MOBILEGL_ASSERT(nullptr != dynamic_cast(textureObject.get()), + MOBILEGL_ASSERT(nullptr != static_cast(textureObject.get()), "Texture object here should always be an object with mipmap"); - auto textureMipmapObject = dynamic_cast(textureObject.get()); + auto textureMipmapObject = static_cast(textureObject.get()); auto texelSize = textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, level); SizeT inputSize = 0; @@ -569,9 +569,9 @@ namespace MobileGL::MG_Impl::GLImpl { reinterpret_cast(pixels); } - MOBILEGL_ASSERT(nullptr != dynamic_cast(textureObject.get()), + MOBILEGL_ASSERT(nullptr != static_cast(textureObject.get()), "Texture object here should always be an object with mipmap"); - auto textureMipmapObject = dynamic_cast(textureObject.get()); + auto textureMipmapObject = static_cast(textureObject.get()); // Allocate in TextureObject textureMipmapObject->AllocateStorage(textureUploadTarget, level, {{width, height, depth}, internalBytes}); @@ -686,9 +686,9 @@ namespace MobileGL::MG_Impl::GLImpl { reinterpret_cast(pixels); } - MOBILEGL_ASSERT(nullptr != dynamic_cast(textureObject.get()), + MOBILEGL_ASSERT(nullptr != static_cast(textureObject.get()), "Texture object here should always be an object with mipmap"); - auto textureMipmapObject = dynamic_cast(textureObject.get()); + auto textureMipmapObject = static_cast(textureObject.get()); // Allocate in TextureObject MGLOG_D("%s: Allocating %d bytes at mip %d", __func__, internalBytes, level); @@ -764,7 +764,7 @@ namespace MobileGL::MG_Impl::GLImpl { // ======================= Processing ================================ // Now we can rest assured, and down-cast texture object to texture buffer - auto* texBufferObject = dynamic_cast(textureObject.get()); + auto* texBufferObject = static_cast(textureObject.get()); auto& bufferSlot = texBufferObject->GetBufferBindingSlot(); bufferSlot.Bind(bufferObject); @@ -978,7 +978,7 @@ namespace MobileGL::MG_Impl::GLImpl { switch (textureObject->GetStorageType()) { case TextureStorageType::Mipmap: { const auto textureMipmapObject = - dynamic_cast(textureObject.get()); + static_cast(textureObject.get()); *params = textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, level).x(); break; } @@ -992,7 +992,7 @@ namespace MobileGL::MG_Impl::GLImpl { switch (textureObject->GetStorageType()) { case TextureStorageType::Mipmap: { const auto textureMipmapObject = - dynamic_cast(textureObject.get()); + static_cast(textureObject.get()); *params = textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, level).y(); break; } @@ -1006,7 +1006,7 @@ namespace MobileGL::MG_Impl::GLImpl { switch (textureObject->GetStorageType()) { case TextureStorageType::Mipmap: { const auto textureMipmapObject = - dynamic_cast(textureObject.get()); + static_cast(textureObject.get()); *params = textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, level).z(); break; } @@ -1067,7 +1067,7 @@ namespace MobileGL::MG_Impl::GLImpl { switch (textureObject->GetStorageType()) { case TextureStorageType::Mipmap: { const auto textureMipmapObject = - dynamic_cast(textureObject.get()); + static_cast(textureObject.get()); *params = (GLfloat)textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, level).x(); break; } @@ -1081,7 +1081,7 @@ namespace MobileGL::MG_Impl::GLImpl { switch (textureObject->GetStorageType()) { case TextureStorageType::Mipmap: { const auto textureMipmapObject = - dynamic_cast(textureObject.get()); + static_cast(textureObject.get()); *params = (GLfloat)textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, level).y(); break; } @@ -1095,7 +1095,7 @@ namespace MobileGL::MG_Impl::GLImpl { switch (textureObject->GetStorageType()) { case TextureStorageType::Mipmap: { const auto textureMipmapObject = - dynamic_cast(textureObject.get()); + static_cast(textureObject.get()); *params = (GLfloat)textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, level).z(); break; } @@ -1441,7 +1441,7 @@ namespace MobileGL::MG_Impl::GLImpl { // Check for multisampling if (textureObject->GetStorageType() == TextureStorageType::Mipmap) { - auto mipmapObject = dynamic_cast(textureObject.get()); + auto mipmapObject = static_cast(textureObject.get()); if (mipmapObject->GetMipmapLevelCount() > 1) { MG_State::pGLContext->RecordError( ErrorCode::InvalidOperation, diff --git a/MobileGL/MG_State/GLState/FramebufferState/FramebufferObject.cpp b/MobileGL/MG_State/GLState/FramebufferState/FramebufferObject.cpp index 1fbf6765..ebdf348f 100644 --- a/MobileGL/MG_State/GLState/FramebufferState/FramebufferObject.cpp +++ b/MobileGL/MG_State/GLState/FramebufferState/FramebufferObject.cpp @@ -60,9 +60,9 @@ namespace MobileGL::MG_State::GLState { IntVec3 FramebufferAttachmentObject::GetSize() const { if (IsTexture()) { // TODO: get correct upload target - MOBILEGL_ASSERT(nullptr != dynamic_cast(m_texture.get()), + MOBILEGL_ASSERT(nullptr != static_cast(m_texture.get()), "Texture object here should always be an object with mipmap"); - auto textureMipmapObject = dynamic_cast(m_texture.get()); + auto textureMipmapObject = static_cast(m_texture.get()); return textureMipmapObject->GetMipmapTexelSize(TextureUploadTarget::Texture2D, m_textureLevel); } else if (IsRenderbuffer()) { return {m_renderbuffer->GetWidth(), m_renderbuffer->GetHeight(), 1};