Renderer: Add mipmaps generation support

This commit is contained in:
SirLynix
2023-05-14 18:55:41 +02:00
parent 3712b641f8
commit 1d32af53c5
33 changed files with 488 additions and 183 deletions

View File

@@ -62,8 +62,9 @@ namespace Nz
Vertex,
Storage,
Uniform,
Upload,
Max = Uniform
Max = Upload
};
enum class BufferUsage

View File

@@ -110,9 +110,11 @@ namespace Nz
Image& operator=(const Image& image);
inline Image& operator=(Image&& image) noexcept;
static inline void ArrayToRegion(ImageType type, unsigned int baseLayer, unsigned int layerCount, Boxui& region);
static void Copy(UInt8* destination, const UInt8* source, PixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, unsigned int dstWidth = 0, unsigned int dstHeight = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0);
static UInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);
static UInt8 GetMaxLevel(ImageType type, unsigned int width, unsigned int height, unsigned int depth = 1);
static inline Boxui RegionToArray(ImageType type, Boxui region, unsigned int& baseLayer, unsigned int& layerCount);
// Load
static std::shared_ptr<Image> LoadFromFile(const std::filesystem::path& filePath, const ImageParams& params = ImageParams());

View File

@@ -18,6 +18,70 @@ namespace Nz
return *this;
}
inline void Image::ArrayToRegion(ImageType type, unsigned int baseLayer, unsigned int layerCount, Boxui& region)
{
switch (type)
{
case ImageType::E1D_Array:
region.y = baseLayer;
region.height = layerCount;
break;
case ImageType::Cubemap:
case ImageType::E2D_Array:
region.z = baseLayer;
region.depth = layerCount;
break;
case ImageType::E1D:
NazaraAssert(baseLayer == 0, "out of bounds");
NazaraAssert(layerCount <= 1, "out of bounds");
case ImageType::E2D:
NazaraAssert(baseLayer == 0, "out of bounds");
NazaraAssert(layerCount <= 1, "out of bounds");
case ImageType::E3D:
region.z = 0;
region.depth = 1;
break;
}
}
inline Boxui Image::RegionToArray(ImageType type, Boxui region, unsigned int& baseLayer, unsigned int& layerCount)
{
switch (type)
{
case ImageType::E1D_Array:
baseLayer = region.y;
layerCount = region.height;
region.y = 0;
region.height = 1;
break;
case ImageType::Cubemap:
case ImageType::E2D_Array:
baseLayer = region.z;
layerCount = region.depth;
region.z = 0;
region.depth = 1;
break;
case ImageType::E1D:
NazaraAssert(region.y == 0, "out of bounds");
NazaraAssert(region.height <= 1, "out of bounds");
case ImageType::E2D:
NazaraAssert(region.z == 0, "out of bounds");
NazaraAssert(region.depth <= 1, "out of bounds");
case ImageType::E3D:
baseLayer = 0;
layerCount = 1;
break;
}
return region;
}
}
#include <Nazara/Utility/DebugOff.hpp>