From 68b3e31eecb1e6db614671fd4188c3299c57b2ad Mon Sep 17 00:00:00 2001 From: SirLynix Date: Tue, 30 May 2023 12:33:40 +0200 Subject: [PATCH] Utility/PixelFormat: use std::string_view to store name --- include/Nazara/Utility/PixelFormat.hpp | 10 +++++----- include/Nazara/Utility/PixelFormat.inl | 10 +++++----- src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp | 2 +- src/Nazara/Utility/Image.cpp | 8 ++++---- src/Nazara/VulkanRenderer/VulkanSwapchain.cpp | 2 +- src/Nazara/VulkanRenderer/VulkanTexture.cpp | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index b519be26e..f335fc545 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -26,9 +26,9 @@ namespace Nz { inline PixelFormatDescription(); inline PixelFormatDescription(PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType); - inline PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType); - inline PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType); - inline PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp = 0); + inline PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType); + inline PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType); + inline PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp = 0); inline void Clear(); @@ -39,7 +39,7 @@ namespace Nz inline bool Validate() const; - std::string name; + std::string_view name; // Warning: Masks bit order is reversed Bitset<> redMask; Bitset<> greenMask; @@ -72,7 +72,7 @@ namespace Nz static inline PixelFormatContent GetContent(PixelFormat format); static inline UInt8 GetBytesPerPixel(PixelFormat format); static inline const PixelFormatDescription& GetInfo(PixelFormat format); - static inline const std::string& GetName(PixelFormat format); + static inline std::string_view GetName(PixelFormat format); static inline bool HasAlpha(PixelFormat format); diff --git a/include/Nazara/Utility/PixelFormat.inl b/include/Nazara/Utility/PixelFormat.inl index b13b56d2f..817d7aa37 100644 --- a/include/Nazara/Utility/PixelFormat.inl +++ b/include/Nazara/Utility/PixelFormat.inl @@ -26,7 +26,7 @@ namespace Nz { } - inline PixelFormatDescription::PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) : + inline PixelFormatDescription::PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) : name(formatName), content(formatContent), redType(subType), @@ -37,12 +37,12 @@ namespace Nz { } - inline PixelFormatDescription::PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType) : + inline PixelFormatDescription::PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType) : PixelFormatDescription(formatName, formatContent, subType, rMask, subType, gMask, subType, bMask, subType, aMask) { } - inline PixelFormatDescription::PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp) : + inline PixelFormatDescription::PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp) : name(formatName), redMask(rMask), greenMask(gMask), @@ -70,7 +70,7 @@ namespace Nz blueMask.Clear(); greenMask.Clear(); redMask.Clear(); - name.clear(); + name = ""; } inline bool PixelFormatDescription::IsCompressed() const @@ -233,7 +233,7 @@ namespace Nz return s_pixelFormatInfos[format]; } - inline const std::string& PixelFormatInfo::GetName(PixelFormat format) + inline std::string_view PixelFormatInfo::GetName(PixelFormat format) { return s_pixelFormatInfos[format].name; } diff --git a/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp index fc76c826c..713da316f 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLFboFramebuffer.cpp @@ -133,7 +133,7 @@ namespace Nz case PixelFormatContent::Undefined: default: - throw std::runtime_error("unhandled pixel format " + PixelFormatInfo::GetName(textureFormat)); + throw std::runtime_error("unhandled pixel format " + std::string(PixelFormatInfo::GetName(textureFormat))); } if (glTexture.RequiresTextureViewEmulation()) diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index a18144f25..6ede60b79 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -94,7 +94,7 @@ namespace Nz if (!PixelFormatInfo::IsConversionSupported(m_sharedImage->format, newFormat)) { - NazaraError("Conversion from " + PixelFormatInfo::GetName(m_sharedImage->format) + " to " + PixelFormatInfo::GetName(newFormat) + " is not supported"); + NazaraError("Conversion from " + std::string(PixelFormatInfo::GetName(m_sharedImage->format)) + " to " + std::string(PixelFormatInfo::GetName(newFormat)) + " is not supported"); return false; } #endif @@ -313,7 +313,7 @@ namespace Nz std::unique_ptr colorBuffer(new UInt8[bpp]); if (!PixelFormatInfo::Convert(PixelFormat::RGBA8, m_sharedImage->format, &color.r, colorBuffer.get())) { - NazaraError("Failed to convert RGBA8 to " + PixelFormatInfo::GetName(m_sharedImage->format)); + NazaraError("Failed to convert RGBA8 to " + std::string(PixelFormatInfo::GetName(m_sharedImage->format))); return false; } @@ -391,7 +391,7 @@ namespace Nz std::unique_ptr colorBuffer(new UInt8[bpp]); if (!PixelFormatInfo::Convert(PixelFormat::RGBA8, m_sharedImage->format, &color.r, colorBuffer.get())) { - NazaraError("Failed to convert RGBA8 to " + PixelFormatInfo::GetName(m_sharedImage->format)); + NazaraError("Failed to convert RGBA8 to " + std::string(PixelFormatInfo::GetName(m_sharedImage->format))); return false; } @@ -463,7 +463,7 @@ namespace Nz std::unique_ptr colorBuffer(new UInt8[bpp]); if (!PixelFormatInfo::Convert(PixelFormat::RGBA8, m_sharedImage->format, &color.r, colorBuffer.get())) { - NazaraError("Failed to convert RGBA8 to " + PixelFormatInfo::GetName(m_sharedImage->format)); + NazaraError("Failed to convert RGBA8 to " + std::string(PixelFormatInfo::GetName(m_sharedImage->format))); return false; } diff --git a/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp b/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp index 0c7719da8..143aa5ec3 100644 --- a/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp +++ b/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp @@ -134,7 +134,7 @@ namespace Nz { PixelFormatContent formatContent = PixelFormatInfo::GetContent(format); if (formatContent != PixelFormatContent::DepthStencil && formatContent != PixelFormatContent::Stencil) - NazaraWarning("Invalid format " + PixelFormatInfo::GetName(format) + " for depth-stencil attachment"); + NazaraWarning("Invalid format " + std::string(PixelFormatInfo::GetName(format)) + " for depth-stencil attachment"); m_depthStencilFormat = ToVulkan(format); if (m_depthStencilFormat == VK_FORMAT_UNDEFINED) diff --git a/src/Nazara/VulkanRenderer/VulkanTexture.cpp b/src/Nazara/VulkanRenderer/VulkanTexture.cpp index ee7c1aaa6..d6ce433b0 100644 --- a/src/Nazara/VulkanRenderer/VulkanTexture.cpp +++ b/src/Nazara/VulkanRenderer/VulkanTexture.cpp @@ -553,7 +553,7 @@ namespace Nz } default: - throw std::runtime_error("Unsupported pixel format " + PixelFormatInfo::GetName(pixelFormat)); + throw std::runtime_error("Unsupported pixel format " + std::string(PixelFormatInfo::GetName(pixelFormat))); } } }