Implement Texture and TextureSampler

This commit is contained in:
Lynix
2020-03-26 21:18:35 +01:00
parent b73d3e8f04
commit 874130efd4
21 changed files with 628 additions and 237 deletions

View File

@@ -22,6 +22,9 @@ namespace Nz
inline VkPolygonMode ToVulkan(FaceFilling faceFilling);
inline VkPrimitiveTopology ToVulkan(PrimitiveMode primitiveMode);
inline VkCompareOp ToVulkan(RendererComparison comparison);
inline VkFilter ToVulkan(SamplerFilter samplerFilter);
inline VkSamplerMipmapMode ToVulkan(SamplerMipmapMode samplerMipmap);
inline VkSamplerAddressMode ToVulkan(SamplerWrap samplerWrap);
inline VkDescriptorType ToVulkan(ShaderBindingType bindingType);
inline VkShaderStageFlagBits ToVulkan(ShaderStageType stageType);
inline VkShaderStageFlags ToVulkan(ShaderStageTypeFlags stageType);

View File

@@ -108,6 +108,43 @@ namespace Nz
return VK_COMPARE_OP_NEVER;
}
VkFilter ToVulkan(SamplerFilter samplerFilter)
{
switch (samplerFilter)
{
case SamplerFilter_Linear: return VK_FILTER_LINEAR;
case SamplerFilter_Nearest: return VK_FILTER_NEAREST;
}
NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(samplerFilter), 16));
return VK_FILTER_NEAREST;
}
VkSamplerMipmapMode ToVulkan(SamplerMipmapMode samplerMipmap)
{
switch (samplerMipmap)
{
case SamplerMipmapMode_Linear: return VK_SAMPLER_MIPMAP_MODE_LINEAR;
case SamplerMipmapMode_Nearest: return VK_SAMPLER_MIPMAP_MODE_NEAREST;
}
NazaraError("Unhandled SamplerMipmapMode 0x" + String::Number(UnderlyingCast(samplerMipmap), 16));
return VK_SAMPLER_MIPMAP_MODE_NEAREST;
}
VkSamplerAddressMode ToVulkan(SamplerWrap samplerWrap)
{
switch (samplerWrap)
{
case SamplerWrap_Clamp: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
case SamplerWrap_MirroredRepeat: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
case SamplerWrap_Repeat: return VK_SAMPLER_ADDRESS_MODE_REPEAT;
}
NazaraError("Unhandled SamplerWrap 0x" + String::Number(UnderlyingCast(samplerWrap), 16));
return VK_SAMPLER_ADDRESS_MODE_REPEAT;
}
VkDescriptorType ToVulkan(ShaderBindingType bindingType)
{
switch (bindingType)

View File

@@ -27,6 +27,8 @@ namespace Nz
std::unique_ptr<RenderPipeline> InstantiateRenderPipeline(RenderPipelineInfo pipelineInfo) override;
std::shared_ptr<RenderPipelineLayout> InstantiateRenderPipelineLayout(RenderPipelineLayoutInfo pipelineLayoutInfo) override;
std::shared_ptr<ShaderStageImpl> InstantiateShaderStage(ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize) override;
std::unique_ptr<Texture> InstantiateTexture(const TextureInfo& params) override;
std::unique_ptr<TextureSampler> InstantiateTextureSampler(const TextureSamplerInfo& params) override;
VulkanDevice& operator=(const VulkanDevice&) = delete;
VulkanDevice& operator=(VulkanDevice&&) = delete; ///TODO?

View File

@@ -0,0 +1,51 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VULKANRENDERER_VULKANTEXTURE_HPP
#define NAZARA_VULKANRENDERER_VULKANTEXTURE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/VulkanRenderer/Config.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Image.hpp>
#include <Nazara/VulkanRenderer/Wrapper/ImageView.hpp>
namespace Nz
{
class NAZARA_VULKANRENDERER_API VulkanTexture : public Texture
{
public:
VulkanTexture(Vk::Device& device, const TextureInfo& params);
VulkanTexture(const VulkanTexture&) = default;
VulkanTexture(VulkanTexture&&) noexcept = default;
~VulkanTexture();
PixelFormatType GetFormat() const override;
inline VkImage GetImage() const;
inline VkImageView GetImageView() const;
UInt8 GetLevelCount() const override;
Vector3ui GetSize(UInt8 level = 0) const override;
ImageType GetType() const override;
bool Update(const void* ptr) override;
VulkanTexture& operator=(const VulkanTexture&) = delete;
VulkanTexture& operator=(VulkanTexture&&) = delete;
private:
static void InitForFormat(PixelFormatType pixelFormat, VkImageCreateInfo& createImage, VkImageViewCreateInfo& createImageView);
VkImage m_image;
VmaAllocation m_allocation;
Vk::Device& m_device;
Vk::ImageView m_imageView;
TextureInfo m_params;
};
}
#include <Nazara/VulkanRenderer/VulkanTexture.inl>
#endif // NAZARA_VULKANRENDERER_VULKANTEXTURE_HPP

View File

@@ -0,0 +1,21 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/VulkanRenderer/VulkanTexture.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
{
inline VkImage VulkanTexture::GetImage() const
{
return m_image;
}
inline VkImageView VulkanTexture::GetImageView() const
{
return m_imageView;
}
}
#include <Nazara/VulkanRenderer/DebugOff.hpp>

View File

@@ -0,0 +1,36 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VULKANRENDERER_VULKANTEXTURESAMPLER_HPP
#define NAZARA_VULKANRENDERER_VULKANTEXTURESAMPLER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Sampler.hpp>
namespace Nz
{
class NAZARA_VULKANRENDERER_API VulkanTextureSampler : public TextureSampler
{
public:
VulkanTextureSampler(Vk::Device& device, TextureSamplerInfo samplerInfo);
VulkanTextureSampler(const VulkanTextureSampler&) = default;
VulkanTextureSampler(VulkanTextureSampler&&) noexcept = default;
~VulkanTextureSampler() = default;
inline VkSampler GetSampler() const;
VulkanTextureSampler& operator=(const VulkanTextureSampler&) = delete;
VulkanTextureSampler& operator=(VulkanTextureSampler&&) = delete;
private:
Vk::Sampler m_sampler;
};
}
#include <Nazara/VulkanRenderer/VulkanTextureSampler.inl>
#endif // NAZARA_VULKANRENDERER_VULKANTEXTURESAMPLER_HPP

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan Renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/VulkanRenderer/VulkanShaderBinding.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
{
inline VkSampler VulkanTextureSampler::GetSampler() const
{
return m_sampler;
}
}
#include <Nazara/VulkanRenderer/DebugOff.hpp>