Renderer: Add support for cubemaps
This commit is contained in:
@@ -244,10 +244,16 @@ namespace Nz
|
||||
{
|
||||
switch (textureTarget)
|
||||
{
|
||||
case GL::TextureTarget::Cubemap: return GL_TEXTURE_CUBE_MAP;
|
||||
case GL::TextureTarget::Target2D: return GL_TEXTURE_2D;
|
||||
case GL::TextureTarget::Target2D_Array: return GL_TEXTURE_2D_ARRAY;
|
||||
case GL::TextureTarget::Target3D: return GL_TEXTURE_3D;
|
||||
case GL::TextureTarget::Cubemap: return GL_TEXTURE_CUBE_MAP;
|
||||
case GL::TextureTarget::CubemapNegativeX: return GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
|
||||
case GL::TextureTarget::CubemapNegativeY: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
|
||||
case GL::TextureTarget::CubemapNegativeZ: return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
|
||||
case GL::TextureTarget::CubemapPositiveX: return GL_TEXTURE_CUBE_MAP_POSITIVE_X;
|
||||
case GL::TextureTarget::CubemapPositiveY: return GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
|
||||
case GL::TextureTarget::CubemapPositiveZ: return GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
|
||||
case GL::TextureTarget::Target2D: return GL_TEXTURE_2D;
|
||||
case GL::TextureTarget::Target2D_Array: return GL_TEXTURE_2D_ARRAY;
|
||||
case GL::TextureTarget::Target3D: return GL_TEXTURE_3D;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled GL::TextureTarget 0x" + NumberToString(UnderlyingCast(textureTarget), 16));
|
||||
|
||||
@@ -72,6 +72,12 @@ namespace Nz::GL
|
||||
enum class TextureTarget
|
||||
{
|
||||
Cubemap,
|
||||
CubemapNegativeX,
|
||||
CubemapNegativeY,
|
||||
CubemapNegativeZ,
|
||||
CubemapPositiveX,
|
||||
CubemapPositiveY,
|
||||
CubemapPositiveZ,
|
||||
Target2D,
|
||||
Target2D_Array,
|
||||
Target3D,
|
||||
|
||||
@@ -29,10 +29,14 @@ namespace Nz::GL
|
||||
inline void SetParameterfv(GLenum pname, const GLfloat* param);
|
||||
inline void SetParameteriv(GLenum pname, const GLint* param);
|
||||
|
||||
inline void TexImage2D(GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type);
|
||||
inline void TexImage2D(GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* data);
|
||||
inline void TexStorage2D(GLint levels, GLint internalFormat, GLsizei width, GLsizei height);
|
||||
inline void TexSubImage2D(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* data);
|
||||
inline void TexImage2D(TextureTarget target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type);
|
||||
inline void TexImage2D(TextureTarget target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* data);
|
||||
inline void TexImage3D(TextureTarget target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type);
|
||||
inline void TexImage3D(TextureTarget target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void* data);
|
||||
inline void TexStorage2D(TextureTarget target, GLint levels, GLint internalFormat, GLsizei width, GLsizei height);
|
||||
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);
|
||||
|
||||
Texture& operator=(const Texture&) = delete;
|
||||
Texture& operator=(Texture&&) noexcept = default;
|
||||
|
||||
@@ -44,34 +44,65 @@ namespace Nz::GL
|
||||
context.glTexParameteriv(ToOpenGL(m_target), pname, param);
|
||||
}
|
||||
|
||||
inline void Texture::TexImage2D(GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type)
|
||||
inline void Texture::TexImage2D(TextureTarget target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type)
|
||||
{
|
||||
return TexImage2D(level, internalFormat, width, height, border, format, type, nullptr);
|
||||
return TexImage2D(target, level, internalFormat, width, height, border, format, type, nullptr);
|
||||
}
|
||||
|
||||
inline void Texture::TexImage2D(GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* data)
|
||||
inline void Texture::TexImage2D(TextureTarget target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* data)
|
||||
{
|
||||
m_target = TextureTarget::Target2D;
|
||||
m_target = target;
|
||||
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.BindTexture(m_target, m_objectId);
|
||||
context.glTexImage2D(ToOpenGL(m_target), level, internalFormat, width, height, border, format, type, data);
|
||||
}
|
||||
|
||||
inline void Texture::TexStorage2D(GLint levels, GLint internalFormat, GLsizei width, GLsizei height)
|
||||
inline void Texture::TexImage3D(TextureTarget target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type)
|
||||
{
|
||||
m_target = TextureTarget::Target2D;
|
||||
return TexImage3D(target, level, internalFormat, width, height, depth, border, format, type, nullptr);
|
||||
}
|
||||
|
||||
inline void Texture::TexImage3D(TextureTarget target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void* data)
|
||||
{
|
||||
m_target = target;
|
||||
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.BindTexture(m_target, m_objectId);
|
||||
context.glTexImage3D(ToOpenGL(m_target), level, internalFormat, width, height, depth, border, format, type, data);
|
||||
}
|
||||
|
||||
inline void Texture::TexStorage2D(TextureTarget target, GLint levels, GLint internalFormat, GLsizei width, GLsizei height)
|
||||
{
|
||||
m_target = target;
|
||||
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.BindTexture(m_target, m_objectId);
|
||||
context.glTexStorage2D(ToOpenGL(m_target), levels, internalFormat, width, height);
|
||||
}
|
||||
|
||||
inline void Texture::TexSubImage2D(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* data)
|
||||
inline void Texture::TexStorage3D(TextureTarget target, GLint levels, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth)
|
||||
{
|
||||
m_target = target;
|
||||
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.BindTexture(m_target, m_objectId);
|
||||
context.glTexStorage3D(ToOpenGL(m_target), levels, internalFormat, width, height, depth);
|
||||
}
|
||||
|
||||
inline void Texture::TexSubImage2D(TextureTarget target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* data)
|
||||
{
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.BindTexture(m_target, m_objectId);
|
||||
context.glTexSubImage2D(ToOpenGL(m_target), level, xoffset, yoffset, width, height, format, type, data);
|
||||
context.glTexSubImage2D(ToOpenGL(target), level, xoffset, yoffset, width, height, format, type, data);
|
||||
//< TODO: Handle errors
|
||||
}
|
||||
|
||||
inline void Texture::TexSubImage3D(TextureTarget target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void* data)
|
||||
{
|
||||
const Context& context = EnsureDeviceContext();
|
||||
context.BindTexture(m_target, m_objectId);
|
||||
context.glTexSubImage3D(ToOpenGL(target), level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
|
||||
//< TODO: Handle errors
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,16 @@ namespace Nz
|
||||
static std::shared_ptr<Texture> LoadFromMemory(const void* data, std::size_t size, const TextureParams& params);
|
||||
static std::shared_ptr<Texture> LoadFromStream(Stream& stream, const TextureParams& params);
|
||||
|
||||
// LoadArray
|
||||
static std::shared_ptr<Texture> LoadArrayFromFile(const std::filesystem::path& filePath, const TextureParams& textureParams, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
static std::shared_ptr<Texture> LoadArrayFromMemory(const void* data, std::size_t size, const TextureParams& textureParams, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
static std::shared_ptr<Texture> LoadArrayFromStream(Stream& stream, const TextureParams& textureParams, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
|
||||
// LoadCubemap
|
||||
static std::shared_ptr<Texture> LoadCubemapFromFile(const std::filesystem::path& filePath, const TextureParams& textureParams, const CubemapParams& cubemapParams = CubemapParams());
|
||||
static std::shared_ptr<Texture> LoadCubemapFromMemory(const void* data, std::size_t size, const TextureParams& textureParams, const CubemapParams& cubemapParams = CubemapParams());
|
||||
static std::shared_ptr<Texture> LoadCubemapFromStream(Stream& stream, const TextureParams& textureParams, const CubemapParams& cubemapParams = CubemapParams());
|
||||
|
||||
Texture& operator=(const Texture&) = delete;
|
||||
Texture& operator=(Texture&&) = delete;
|
||||
};
|
||||
|
||||
@@ -72,10 +72,10 @@ namespace Nz
|
||||
std::optional<bool> depth;
|
||||
std::optional<bool> sampled;
|
||||
SpirvDim dim;
|
||||
SpirvImageFormat format;
|
||||
SpirvImageFormat format = SpirvImageFormat::Unknown;
|
||||
TypePtr sampledType;
|
||||
bool arrayed;
|
||||
bool multisampled;
|
||||
bool arrayed = false;
|
||||
bool multisampled = false;
|
||||
};
|
||||
|
||||
struct Pointer
|
||||
|
||||
@@ -57,6 +57,7 @@ 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, UInt32 width, UInt32 height, UInt32 depth = 1);
|
||||
|
||||
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);
|
||||
|
||||
@@ -225,17 +225,24 @@ namespace Nz
|
||||
}
|
||||
|
||||
inline void CommandBuffer::CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, UInt32 width, UInt32 height, UInt32 depth)
|
||||
{
|
||||
VkImageSubresourceLayers subresourceLayers = {
|
||||
VK_IMAGE_ASPECT_COLOR_BIT, //< aspectMask
|
||||
0,
|
||||
0,
|
||||
1
|
||||
};
|
||||
|
||||
return CopyBufferToImage(source, target, targetLayout, subresourceLayers, width, height, depth);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, const VkImageSubresourceLayers& subresourceLayers, UInt32 width, UInt32 height, UInt32 depth)
|
||||
{
|
||||
VkBufferImageCopy region = {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
{ // imageSubresource
|
||||
VK_IMAGE_ASPECT_COLOR_BIT, //< aspectMask
|
||||
0,
|
||||
0,
|
||||
1
|
||||
},
|
||||
subresourceLayers,
|
||||
{ // imageOffset
|
||||
0, 0, 0
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user