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;
|
||||
|
||||
Reference in New Issue
Block a user