11#include " gfx/materials.h"
22
3+ // IWYU pragma: begin_keep
34#include < Corrade/Containers/OptionalStl.h>
45#include < Corrade/Containers/PairStl.h>
56#include < Corrade/Containers/StringStl.h>
7+ // IWYU pragma: end_keep
68
79#include < Corrade/Containers/Array.h>
810#include < Corrade/Utility/Algorithms.h>
1113#include < Magnum/GL/Texture.h>
1214#include < Magnum/GL/TextureFormat.h>
1315#include < Magnum/ImageView.h>
14- #include < Magnum/Math/Functions.h>
1516#include < Magnum/PixelFormat.h>
1617#include < Magnum/Trade/AbstractImporter.h>
1718#include < Magnum/Trade/ImageData.h>
1819#include < Magnum/Trade/MaterialData.h>
1920#include < Magnum/Trade/PhongMaterialData.h>
2021#include < Magnum/Trade/TextureData.h>
2122#include < fmt/format.h>
23+ #include < cstddef>
2224#include < optional>
2325#include " log.h"
2426
@@ -33,15 +35,17 @@ void loadImage(Magnum::GL::Texture2D& texture, const Magnum::Trade::ImageData2D&
3335 const uint32_t channelCount = pixelFormatChannelCount (image.format ());
3436 if (channelCount == 1 || channelCount == 2 ) {
3537 if (GL::Context::current ().isExtensionSupported <GL::Extensions::ARB::texture_swizzle>()) {
36- if (channelCount == 1 )
38+ if (channelCount == 1 ) {
3739 texture.setSwizzle <' r' , ' r' , ' r' , ' 1' >();
38- else if (channelCount == 2 )
40+ } else if (channelCount == 2 ) {
3941 texture.setSwizzle <' r' , ' r' , ' r' , ' g' >();
42+ }
4043 } else {
4144 const PixelFormat imageFormat =
4245 pixelFormat (image.format (), channelCount == 2 ? 4 : 3 , isPixelFormatSrgb (image.format ()));
4346 Debug{} << " Texture swizzle not supported, expanding a" << image.format () << " image to" << imageFormat;
44- const std::size_t rowStride = 4 * ((pixelFormatSize (imageFormat) * image.size ().x () + 3 ) / 4 );
47+ const std::size_t rowStride =
48+ static_cast <std::size_t >(4 * ((pixelFormatSize (imageFormat) * image.size ().x () + 3 ) / 4 ));
4549 usedImageStorage = Containers::Array<char >{NoInit, std::size_t (rowStride * image.size ().y ())};
4650 const MutableImageView2D usedMutableImage{imageFormat, image.size (), usedImageStorage};
4751 usedImage = usedMutableImage;
@@ -53,11 +57,12 @@ void loadImage(Magnum::GL::Texture2D& texture, const Magnum::Trade::ImageData2D&
5357 usedMutableImage.pixels ().expanded <2 >(Containers::Size2D{dstChannelCount, channelSize});
5458 Utility::copy (src.exceptSuffix ({0 , 0 , channelCount == 2 ? 1 : 0 , 0 }).broadcasted <2 >(3 ),
5559 dst.exceptSuffix ({0 , 0 , channelCount == 2 ? 1 : 0 , 0 }));
56- if (channelCount == 2 )
60+ if (channelCount == 2 ) {
5761 Utility::copy (src.exceptPrefix ({0 , 0 , 1 , 0 }), dst.exceptPrefix ({0 , 0 , 3 , 0 }));
62+ }
5863 }
5964 }
60- GL::TextureFormat format;
65+ GL::TextureFormat format{} ;
6166 switch (usedImage.format ()) {
6267 case PixelFormat::R8Unorm:
6368 case PixelFormat::RG8Unorm:
@@ -84,11 +89,10 @@ void loadImage(Magnum::GL::Texture2D& texture, const Magnum::Trade::ImageData2D&
8489 fmt::format (" cannot load image of format {} " , static_cast <uint32_t >(usedImage.format ())));
8590 return ;
8691 }
87- texture.setStorage (Math::log2 (usedImage.size ().max ()) + 1 , format, usedImage.size ())
88- .setSubImage (0 , {}, usedImage)
89- .generateMipmap ();
92+ int32_t levels = static_cast <int32_t >(std::log2<int32_t >(usedImage.size ().max ()) + 1 );
93+ texture.setStorage (levels, format, usedImage.size ()).setSubImage (0 , {}, usedImage).generateMipmap ();
9094 } else {
91- GL::TextureFormat format;
95+ GL::TextureFormat format{} ;
9296 switch (image.compressedFormat ()) {
9397 case CompressedPixelFormat::Bc4RSnorm:
9498 case CompressedPixelFormat::Bc5RGSnorm:
0 commit comments