Vulkan/RenderWindow: Add support for depth buffer

Former-commit-id: 42f113fcb7463c0f010fdc325b9024b08de3c667 [formerly 95040d268ff328f2d54459bf11c269dd5f042f73] [formerly 77c2d1139585cbf31f881ffddfb43b23284a7073 [formerly d235ff32fae4612d95d25524410bf1b43974d520]]
Former-commit-id: bab56f18d034bade640bf023c97810adf2c717ff [formerly c62041abb56103d6c7aeac2b55f7bf66acd8882b]
Former-commit-id: cef0ac55f6eaa54f17d3d0cc2030a4b9de7b166c
This commit is contained in:
Lynix
2016-08-09 13:53:12 +02:00
parent 16818fa7a3
commit 8776ffe953
4 changed files with 277 additions and 40 deletions

View File

@@ -16,7 +16,9 @@
#include <Nazara/Vulkan/VkCommandBuffer.hpp>
#include <Nazara/Vulkan/VkCommandPool.hpp>
#include <Nazara/Vulkan/VkDevice.hpp>
#include <Nazara/Vulkan/VkDeviceMemory.hpp>
#include <Nazara/Vulkan/VkFramebuffer.hpp>
#include <Nazara/Vulkan/VkImage.hpp>
#include <Nazara/Vulkan/VkSurface.hpp>
#include <Nazara/Vulkan/VkSwapchain.hpp>
#include <Nazara/Utility/Window.hpp>
@@ -39,13 +41,11 @@ namespace Nz
void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const override;
UInt32 GetFramebufferCount() const;
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
bool Create(WindowHandle handle);
const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const override;
UInt32 GetFramebufferCount() const;
const Vk::DeviceHandle& GetDevice() const;
UInt32 GetPresentableFamilyQueue() const;
const Vk::Surface& GetSurface() const;
@@ -55,6 +55,7 @@ namespace Nz
bool IsValid() const;
void SetDepthStencilFormats(std::vector<PixelFormatType> pixelFormat);
void SetPhysicalDevice(VkPhysicalDevice device);
RenderWindow& operator=(const RenderWindow&) = delete;
@@ -65,17 +66,21 @@ namespace Nz
void OnWindowDestroy() override;
void OnWindowResized() override;
bool SetupCommandBuffers();
bool SetupDepthBuffer();
bool SetupRenderPass();
bool SetupSwapchain();
Clock m_clock;
VkFormat m_colorFormat;
VkFormat m_depthFormat;
VkColorSpaceKHR m_colorSpace;
VkFormat m_colorFormat;
VkFormat m_depthStencilFormat;
VkPhysicalDevice m_forcedPhysicalDevice;
std::vector<PixelFormatType> m_wantedDepthStencilFormats;
std::vector<Vk::Framebuffer> m_frameBuffers;
Vk::DeviceHandle m_device;
Vk::DeviceMemory m_depthBufferMemory;
Vk::Image m_depthBuffer;
Vk::ImageView m_depthBufferView;
Vk::Queue m_presentQueue;
Vk::Surface m_surface;
Vk::Swapchain m_swapchain;

View File

@@ -0,0 +1,43 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VULKAN_VKIMAGE_HPP
#define NAZARA_VULKAN_VKIMAGE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Vulkan/VkDeviceObject.hpp>
namespace Nz
{
namespace Vk
{
class Image : public DeviceObject<Image, VkImage, VkImageCreateInfo>
{
friend DeviceObject;
public:
Image() = default;
Image(const Image&) = delete;
Image(Image&&) = default;
~Image() = default;
bool BindImageMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
VkMemoryRequirements GetMemoryRequirements() const;
Image& operator=(const Image&) = delete;
Image& operator=(Image&&) = delete;
private:
static inline VkResult CreateHelper(const DeviceHandle& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle);
static inline void DestroyHelper(const DeviceHandle& device, VkImage handle, const VkAllocationCallbacks* allocator);
};
}
}
#include <Nazara/Vulkan/VkImage.inl>
#endif // NAZARA_VULKAN_VKIMAGE_HPP

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Vulkan"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Vulkan/VkImage.hpp>
#include <Nazara/Vulkan/Debug.hpp>
namespace Nz
{
namespace Vk
{
inline bool Image::BindImageMemory(VkDeviceMemory memory, VkDeviceSize offset)
{
m_lastErrorCode = m_device->vkBindImageMemory(*m_device, m_handle, memory, offset);
if (m_lastErrorCode != VK_SUCCESS)
{
NazaraError("Failed to bind buffer memory");
return false;
}
return true;
}
inline VkMemoryRequirements Image::GetMemoryRequirements() const
{
NazaraAssert(IsValid(), "Invalid image");
VkMemoryRequirements memoryRequirements;
m_device->vkGetImageMemoryRequirements(*m_device, m_handle, &memoryRequirements);
return memoryRequirements;
}
inline VkResult Image::CreateHelper(const DeviceHandle& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle)
{
return device->vkCreateImage(*device, createInfo, allocator, handle);
}
inline void Image::DestroyHelper(const DeviceHandle& device, VkImage handle, const VkAllocationCallbacks* allocator)
{
return device->vkDestroyImage(*device, handle, allocator);
}
}
}
#include <Nazara/Vulkan/DebugOff.hpp>