Add initial support for texture views

This commit is contained in:
SirLynix
2022-11-30 18:45:07 +01:00
committed by Jérôme Leclercq
parent 902dee6121
commit 42f8cdb151
13 changed files with 239 additions and 78 deletions

View File

@@ -26,13 +26,23 @@ namespace Nz
PixelFormat pixelFormat;
ImageType type;
TextureUsageFlags usageFlags = TextureUsage::ShaderSampling | TextureUsage::TransferDestination;
UInt8 mipmapLevel = 1;
UInt8 levelCount = 1;
unsigned int layerCount = 1;
unsigned int depth = 1;
unsigned int height;
unsigned int width;
};
struct TextureViewInfo
{
ImageType viewType;
PixelFormat reinterpretFormat;
UInt8 baseMipLevel = 0;
UInt8 levelCount = 1;
unsigned int baseArrayLayer = 0;
unsigned int layerCount = 1;
};
struct NAZARA_RENDERER_API TextureParams : ImageParams
{
std::shared_ptr<RenderDevice> renderDevice;
@@ -56,9 +66,11 @@ namespace Nz
virtual ~Texture();
virtual bool Copy(const Texture& source, const Boxui& srcBox, const Vector3ui& dstPos = Vector3ui::Zero()) = 0;
virtual std::shared_ptr<Texture> CreateView(const TextureViewInfo& viewInfo) = 0;
virtual PixelFormat GetFormat() const = 0;
virtual UInt8 GetLevelCount() const = 0;
virtual Texture* GetParentTexture() const = 0;
virtual Vector3ui GetSize(UInt8 level = 0) const = 0;
virtual ImageType GetType() const = 0;
@@ -67,6 +79,7 @@ namespace Nz
Texture& operator=(const Texture&) = delete;
Texture& operator=(Texture&&) = delete;
static inline TextureInfo ApplyView(TextureInfo textureInfo, const TextureViewInfo& viewInfo);
static inline unsigned int GetLevelSize(unsigned int size, unsigned int level);
static std::shared_ptr<Texture> CreateFromImage(const Image& image, const TextureParams& params);

View File

@@ -7,6 +7,19 @@
namespace Nz
{
inline TextureInfo Texture::ApplyView(TextureInfo textureInfo, const TextureViewInfo& viewInfo)
{
textureInfo.type = viewInfo.viewType;
textureInfo.pixelFormat = viewInfo.reinterpretFormat;
textureInfo.width = GetLevelSize(textureInfo.width, viewInfo.baseMipLevel);
textureInfo.height = GetLevelSize(textureInfo.height, viewInfo.baseMipLevel);
textureInfo.depth = GetLevelSize(textureInfo.depth, viewInfo.baseMipLevel);
textureInfo.levelCount = (textureInfo.levelCount > viewInfo.baseMipLevel) ? (textureInfo.levelCount - viewInfo.baseMipLevel) : 1;
textureInfo.layerCount = (textureInfo.layerCount > viewInfo.baseArrayLayer) ? (textureInfo.layerCount - viewInfo.baseArrayLayer) : 1;
return textureInfo;
}
inline unsigned int Texture::GetLevelSize(unsigned int size, unsigned int level)
{
if (size == 0) // Possible dans le cas d'une image invalide