Add initial support for texture views
This commit is contained in:
committed by
Jérôme Leclercq
parent
902dee6121
commit
42f8cdb151
@@ -12,25 +12,31 @@
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Texture.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <optional>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_OPENGLRENDERER_API OpenGLTexture : public Texture
|
||||
{
|
||||
public:
|
||||
OpenGLTexture(OpenGLDevice& device, const TextureInfo& params);
|
||||
OpenGLTexture(OpenGLDevice& device, const TextureInfo& textureInfo);
|
||||
OpenGLTexture(std::shared_ptr<OpenGLTexture> parentTexture, const TextureViewInfo& viewInfo);
|
||||
OpenGLTexture(const OpenGLTexture&) = delete;
|
||||
OpenGLTexture(OpenGLTexture&&) = delete;
|
||||
~OpenGLTexture() = default;
|
||||
|
||||
bool Copy(const Texture& source, const Boxui& srcBox, const Vector3ui& dstPos) override;
|
||||
std::shared_ptr<Texture> CreateView(const TextureViewInfo& viewInfo) override;
|
||||
|
||||
PixelFormat GetFormat() const override;
|
||||
UInt8 GetLevelCount() const override;
|
||||
OpenGLTexture* GetParentTexture() const override;
|
||||
Vector3ui GetSize(UInt8 level = 0) const override;
|
||||
inline const GL::Texture& GetTexture() const;
|
||||
ImageType GetType() const override;
|
||||
|
||||
inline bool RequireTextureViewEmulation() const;
|
||||
|
||||
using Texture::Update;
|
||||
bool Update(const void* ptr, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||
|
||||
@@ -42,8 +48,10 @@ namespace Nz
|
||||
static inline GL::TextureTarget ToTextureTarget(ImageType imageType);
|
||||
|
||||
private:
|
||||
std::optional<TextureViewInfo> m_viewInfo;
|
||||
std::shared_ptr<OpenGLTexture> m_parentTexture;
|
||||
GL::Texture m_texture;
|
||||
TextureInfo m_params;
|
||||
TextureInfo m_textureInfo;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Nz
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
inline bool OpenGLTexture::RequireTextureViewEmulation() const
|
||||
{
|
||||
return m_viewInfo.has_value() && !m_texture.IsValid();
|
||||
}
|
||||
|
||||
inline GL::TextureTarget OpenGLTexture::ToTextureTarget(ImageType imageType)
|
||||
{
|
||||
switch (imageType)
|
||||
|
||||
@@ -60,8 +60,9 @@ namespace Nz::GL
|
||||
StorageBuffers,
|
||||
TextureCompressionS3tc,
|
||||
TextureFilterAnisotropic,
|
||||
TextureView,
|
||||
|
||||
Max = TextureFilterAnisotropic
|
||||
Max = TextureView
|
||||
};
|
||||
|
||||
enum class ExtensionStatus
|
||||
|
||||
@@ -26,6 +26,9 @@ typedef void (GL_APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
|
||||
// Depth clamp (OpenGL 3.2)
|
||||
#define GL_DEPTH_CLAMP 0x864F
|
||||
|
||||
// Texture views (OpenGL 4.3)
|
||||
typedef void (GL_APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
|
||||
|
||||
// Clip control (OpenGL 4.5)
|
||||
#define GL_LOWER_LEFT 0x8CA1
|
||||
#define GL_UPPER_LEFT 0x8CA2
|
||||
@@ -200,6 +203,8 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERPROC) (GLuint shader, const GLch
|
||||
extCb(glObjectLabel, PFNGLOBJECTLABELPROC) \
|
||||
extCb(glPopDebugGroup, PFNGLPOPDEBUGGROUPPROC) \
|
||||
extCb(glPushDebugGroup, PFNGLPUSHDEBUGGROUPPROC) \
|
||||
/* OpenGL 4.3 - GL_ARB_texture_view */ \
|
||||
extCb(glTextureView, PFNGLTEXTUREVIEWPROC) \
|
||||
/* OpenGL 4.5 - GL_ARB_clip_control/GL_EXT_clip_control */ \
|
||||
extCb(glClipControl, PFNGLCLIPCONTROLPROC) \
|
||||
/* OpenGL 4.6 - GL_ARB_spirv_extensions */\
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace Nz::GL
|
||||
inline void TexStorage3D(TextureTarget target, GLint levels, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth);
|
||||
inline void TexSubImage2D(TextureTarget target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* data);
|
||||
inline void TexSubImage3D(TextureTarget target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void* data);
|
||||
inline void TextureView(GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
|
||||
|
||||
Texture& operator=(const Texture&) = delete;
|
||||
Texture& operator=(Texture&&) noexcept = default;
|
||||
|
||||
@@ -111,6 +111,12 @@ namespace Nz::GL
|
||||
//< TODO: Handle errors
|
||||
}
|
||||
|
||||
inline void Texture::TextureView(GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers)
|
||||
{
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.glTextureView(m_objectId, target, origtexture, internalformat, minlevel, numlevels, minlayer, numlayers);
|
||||
}
|
||||
|
||||
inline GLuint Texture::CreateHelper(OpenGLDevice& /*device*/, const Context& context)
|
||||
{
|
||||
GLuint texture = 0;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -18,17 +18,20 @@ namespace Nz
|
||||
class NAZARA_VULKANRENDERER_API VulkanTexture : public Texture
|
||||
{
|
||||
public:
|
||||
VulkanTexture(Vk::Device& device, const TextureInfo& params);
|
||||
VulkanTexture(Vk::Device& device, const TextureInfo& textureInfo);
|
||||
VulkanTexture(std::shared_ptr<VulkanTexture> parentTexture, const TextureViewInfo& viewInfo);
|
||||
VulkanTexture(const VulkanTexture&) = delete;
|
||||
VulkanTexture(VulkanTexture&&) = delete;
|
||||
~VulkanTexture();
|
||||
|
||||
bool Copy(const Texture& source, const Boxui& srcBox, const Vector3ui& dstPos) override;
|
||||
std::shared_ptr<Texture> CreateView(const TextureViewInfo& viewInfo) override;
|
||||
|
||||
PixelFormat GetFormat() const override;
|
||||
inline VkImage GetImage() const;
|
||||
inline VkImageView GetImageView() const;
|
||||
UInt8 GetLevelCount() const override;
|
||||
VulkanTexture* GetParentTexture() const override;
|
||||
Vector3ui GetSize(UInt8 level = 0) const override;
|
||||
ImageType GetType() const override;
|
||||
|
||||
@@ -43,11 +46,12 @@ namespace Nz
|
||||
private:
|
||||
static void InitViewForFormat(PixelFormat pixelFormat, VkImageViewCreateInfo& createImageView);
|
||||
|
||||
std::shared_ptr<VulkanTexture> m_parentTexture;
|
||||
VkImage m_image;
|
||||
VmaAllocation m_allocation;
|
||||
Vk::Device& m_device;
|
||||
Vk::ImageView m_imageView;
|
||||
TextureInfo m_params;
|
||||
TextureInfo m_textureInfo;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user