Renderer/Texture: Implement Update of a region + inherit AbstractImage
This commit is contained in:
@@ -29,7 +29,8 @@ namespace Nz
|
||||
inline const GL::Texture& GetTexture() const;
|
||||
ImageType GetType() const override;
|
||||
|
||||
bool Update(const void* ptr) override;
|
||||
using Texture::Update;
|
||||
bool Update(const void* ptr, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||
|
||||
OpenGLTexture& operator=(const OpenGLTexture&) = delete;
|
||||
OpenGLTexture& operator=(OpenGLTexture&&) = delete;
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Nz
|
||||
using TextureLoader = ResourceLoader<Texture, TextureParams>;
|
||||
using TextureManager = ResourceManager<Texture, TextureParams>;
|
||||
|
||||
class NAZARA_RENDERER_API Texture : public Resource
|
||||
class NAZARA_RENDERER_API Texture : public AbstractImage, public Resource, public std::enable_shared_from_this<Texture> //< FIXME
|
||||
{
|
||||
public:
|
||||
Texture() = default;
|
||||
@@ -59,8 +59,6 @@ namespace Nz
|
||||
virtual Vector3ui GetSize(UInt8 level = 0) const = 0;
|
||||
virtual ImageType GetType() const = 0;
|
||||
|
||||
virtual bool Update(const void* ptr) = 0;
|
||||
|
||||
static inline unsigned int GetLevelSize(unsigned int size, unsigned int level);
|
||||
|
||||
static std::shared_ptr<Texture> CreateFromImage(const Image& image, const TextureParams& params);
|
||||
|
||||
@@ -27,23 +27,17 @@ namespace Nz
|
||||
virtual ~AbstractImage();
|
||||
|
||||
UInt8 GetBytesPerPixel() const;
|
||||
virtual unsigned int GetDepth(UInt8 level = 0) const = 0;
|
||||
virtual PixelFormat GetFormat() const = 0;
|
||||
virtual unsigned int GetHeight(UInt8 level = 0) const = 0;
|
||||
virtual UInt8 GetLevelCount() const = 0;
|
||||
virtual UInt8 GetMaxLevel() const = 0;
|
||||
virtual std::size_t GetMemoryUsage() const = 0;
|
||||
virtual std::size_t GetMemoryUsage(UInt8 level) const = 0;
|
||||
virtual Vector3ui GetSize(UInt8 level = 0) const = 0;
|
||||
virtual ImageType GetType() const = 0;
|
||||
virtual unsigned int GetWidth(UInt8 level = 0) const = 0;
|
||||
|
||||
bool IsCompressed() const;
|
||||
bool IsCubemap() const;
|
||||
|
||||
virtual bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) = 0;
|
||||
virtual bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) = 0;
|
||||
virtual bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) = 0;
|
||||
inline bool Update(const void* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
virtual bool Update(const void* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) = 0;
|
||||
inline bool Update(const void* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
|
||||
AbstractImage& operator=(const AbstractImage&) = default;
|
||||
AbstractImage& operator=(AbstractImage&&) noexcept = default;
|
||||
|
||||
@@ -2,10 +2,20 @@
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/AbstractImage.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline bool AbstractImage::Update(const void* pixels, unsigned int srcWidth, unsigned int srcHeight, UInt8 level)
|
||||
{
|
||||
return Update(pixels, GetSize(level), srcWidth, srcHeight, level);
|
||||
}
|
||||
|
||||
inline bool AbstractImage::Update(const void* pixels, const Rectui& rect, unsigned int z, unsigned int srcWidth, unsigned int srcHeight, UInt8 level)
|
||||
{
|
||||
return Update(pixels, Boxui(rect.x, rect.y, z, rect.width, rect.height, 1), srcWidth, srcHeight, level);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
|
||||
@@ -249,16 +249,16 @@ namespace Nz
|
||||
{
|
||||
switch (pixelFormat)
|
||||
{
|
||||
case PixelFormat::BGRA8: return VK_FORMAT_B8G8R8A8_UNORM;
|
||||
case PixelFormat::BGRA8_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
|
||||
case PixelFormat::Depth16: return VK_FORMAT_D16_UNORM;
|
||||
case PixelFormat::Depth16Stencil8: return VK_FORMAT_D16_UNORM_S8_UINT;
|
||||
case PixelFormat::Depth24Stencil8: return VK_FORMAT_D24_UNORM_S8_UINT;
|
||||
case PixelFormat::Depth32F: return VK_FORMAT_D32_SFLOAT;
|
||||
case PixelFormat::BGRA8: return VK_FORMAT_B8G8R8A8_UNORM;
|
||||
case PixelFormat::BGRA8_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
|
||||
case PixelFormat::Depth16: return VK_FORMAT_D16_UNORM;
|
||||
case PixelFormat::Depth16Stencil8: return VK_FORMAT_D16_UNORM_S8_UINT;
|
||||
case PixelFormat::Depth24Stencil8: return VK_FORMAT_D24_UNORM_S8_UINT;
|
||||
case PixelFormat::Depth32F: return VK_FORMAT_D32_SFLOAT;
|
||||
case PixelFormat::Depth32FStencil8: return VK_FORMAT_D32_SFLOAT_S8_UINT;
|
||||
case PixelFormat::RGBA8: return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
case PixelFormat::RGBA8_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
|
||||
case PixelFormat::RGBA32F: return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
case PixelFormat::RGBA8: return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
case PixelFormat::RGBA8_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
|
||||
case PixelFormat::RGBA32F: return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace Nz
|
||||
Vector3ui GetSize(UInt8 level = 0) const override;
|
||||
ImageType GetType() const override;
|
||||
|
||||
bool Update(const void* ptr) override;
|
||||
using Texture::Update;
|
||||
bool Update(const void* ptr, const Boxui& box, unsigned int srcWidth, unsigned int srcHeight, UInt8 level) override;
|
||||
|
||||
VulkanTexture& operator=(const VulkanTexture&) = delete;
|
||||
VulkanTexture& operator=(VulkanTexture&&) = delete;
|
||||
|
||||
@@ -57,7 +57,10 @@ namespace Nz
|
||||
|
||||
inline void CopyBuffer(VkBuffer source, VkBuffer target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0);
|
||||
inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, UInt32 width, UInt32 height, UInt32 depth = 1);
|
||||
inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, Int32 x, Int32 y, Int32 z, UInt32 width, UInt32 height, UInt32 depth);
|
||||
inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, UInt32 width, UInt32 height, UInt32 depth = 1);
|
||||
inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, const VkBufferImageCopy& region);
|
||||
inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, UInt32 regionCount, const VkBufferImageCopy* regions);
|
||||
|
||||
inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
|
||||
inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0);
|
||||
|
||||
@@ -236,6 +236,24 @@ namespace Nz
|
||||
return CopyBufferToImage(source, target, targetLayout, subresourceLayers, width, height, depth);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, Int32 x, Int32 y, Int32 z, UInt32 width, UInt32 height, UInt32 depth)
|
||||
{
|
||||
VkBufferImageCopy region = {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
subresourceLayers,
|
||||
{ // imageOffset
|
||||
x, y, z
|
||||
},
|
||||
{ // imageExtent
|
||||
width, height, depth
|
||||
}
|
||||
};
|
||||
|
||||
return CopyBufferToImage(source, target, targetLayout, subresourceLayers, region);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, UInt32 width, UInt32 height, UInt32 depth)
|
||||
{
|
||||
VkBufferImageCopy region = {
|
||||
@@ -251,7 +269,17 @@ namespace Nz
|
||||
}
|
||||
};
|
||||
|
||||
return m_pool->GetDevice()->vkCmdCopyBufferToImage(m_handle, source, target, targetLayout, 1, ®ion);
|
||||
return CopyBufferToImage(source, target, targetLayout, subresourceLayers, region);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, const VkBufferImageCopy& region)
|
||||
{
|
||||
return CopyBufferToImage(source, target, targetLayout, subresourceLayers, 1, ®ion);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, UInt32 regionCount, const VkBufferImageCopy* regions)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdCopyBufferToImage(m_handle, source, target, targetLayout, regionCount, regions);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::Draw(UInt32 vertexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
|
||||
|
||||
Reference in New Issue
Block a user