Add texture in demo

This commit is contained in:
Lynix
2020-03-18 13:48:05 +01:00
parent 9cc206b33e
commit 4ede9f1cfe
15 changed files with 359 additions and 40 deletions

View File

@@ -52,6 +52,7 @@ namespace Nz
inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange* ranges);
inline void CopyBuffer(VkBuffer source, VkBuffer target, UInt32 size, UInt32 sourceOffset = 0, UInt32 targetOffset = 0);
inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, UInt32 width, UInt32 height);
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);

View File

@@ -203,6 +203,29 @@ namespace Nz
return m_pool->GetDevice()->vkCmdCopyBuffer(m_handle, source, target, 1, &region);
}
inline void CommandBuffer::CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, UInt32 width, UInt32 height)
{
VkBufferImageCopy region = {
0,
0,
0,
{ // imageSubresource
VK_IMAGE_ASPECT_COLOR_BIT, //< aspectMask
0,
0,
1
},
{ // imageOffset
0, 0, 0
},
{ // imageExtent
width, height, 1U
}
};
return m_pool->GetDevice()->vkCmdCopyBufferToImage(m_handle, source, target, targetLayout, 1, &region);
}
inline void CommandBuffer::Draw(UInt32 vertexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
{
return m_pool->GetDevice()->vkCmdDraw(m_handle, vertexCount, instanceCount, firstVertex, firstInstance);

View File

@@ -30,6 +30,13 @@ namespace Nz
inline bool IsValid() const;
inline void WriteCombinedImageSamplerDescriptor(UInt32 binding, VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout);
inline void WriteCombinedImageSamplerDescriptor(UInt32 binding, const VkDescriptorImageInfo& imageInfo);
inline void WriteCombinedImageSamplerDescriptor(UInt32 binding, UInt32 arrayElement, VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout);
inline void WriteCombinedImageSamplerDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorImageInfo& imageInfo);
inline void WriteCombinedImageSamplerDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorImageInfo* imageInfo);
inline void WriteCombinedImageSamplerDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorImageInfo* imageInfo);
inline void WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range);
inline void WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo);
inline void WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range);

View File

@@ -50,6 +50,55 @@ namespace Nz
return m_handle != VK_NULL_HANDLE;
}
inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout)
{
return WriteCombinedImageSamplerDescriptor(binding, 0, sampler, imageView, imageLayout);
}
inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, const VkDescriptorImageInfo& imageInfo)
{
return WriteCombinedImageSamplerDescriptor(binding, 0, imageInfo);
}
inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, UInt32 arrayElement, VkSampler sampler, VkImageView imageView, VkImageLayout imageLayout)
{
VkDescriptorImageInfo imageInfo = {
sampler,
imageView,
imageLayout
};
return WriteCombinedImageSamplerDescriptors(binding, arrayElement, 1U, &imageInfo);
}
inline void DescriptorSet::WriteCombinedImageSamplerDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorImageInfo& imageInfo)
{
return WriteCombinedImageSamplerDescriptors(binding, arrayElement, 1U, &imageInfo);
}
inline void DescriptorSet::WriteCombinedImageSamplerDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorImageInfo* imageInfo)
{
return WriteCombinedImageSamplerDescriptors(binding, 0U, descriptorCount, imageInfo);
}
inline void DescriptorSet::WriteCombinedImageSamplerDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorImageInfo* imageInfo)
{
VkWriteDescriptorSet writeDescriptorSet = {
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
nullptr,
m_handle,
binding,
arrayElement,
descriptorCount,
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
imageInfo,
nullptr,
nullptr
};
return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, nullptr);
}
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range)
{
return WriteUniformDescriptor(binding, 0U, buffer, offset, range);

View File

@@ -0,0 +1,39 @@
// 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
#pragma once
#ifndef NAZARA_VULKANRENDERER_VKSAMPLER_HPP
#define NAZARA_VULKANRENDERER_VKSAMPLER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp>
namespace Nz
{
namespace Vk
{
class Sampler : public DeviceObject<Sampler, VkSampler, VkSamplerCreateInfo>
{
friend DeviceObject;
public:
Sampler() = default;
Sampler(const Sampler&) = delete;
Sampler(Sampler&&) = default;
~Sampler() = default;
Sampler& operator=(const Sampler&) = delete;
Sampler& operator=(Sampler&&) = delete;
private:
static inline VkResult CreateHelper(Device& device, const VkSamplerCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSampler* handle);
static inline void DestroyHelper(Device& device, VkSampler handle, const VkAllocationCallbacks* allocator);
};
}
}
#include <Nazara/VulkanRenderer/Wrapper/Sampler.inl>
#endif // NAZARA_VULKANRENDERER_VKSAMPLER_HPP

View File

@@ -0,0 +1,24 @@
// 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/Wrapper/Sampler.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
{
namespace Vk
{
inline VkResult Sampler::CreateHelper(Device& device, const VkSamplerCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSampler* handle)
{
return device.vkCreateSampler(device, createInfo, allocator, handle);
}
inline void Sampler::DestroyHelper(Device& device, VkSampler handle, const VkAllocationCallbacks* allocator)
{
return device.vkDestroySampler(device, handle, allocator);
}
}
}
#include <Nazara/VulkanRenderer/DebugOff.hpp>