Commit WIP about RenderSurface
This commit is contained in:
parent
86b892c3bc
commit
c136f8eddc
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright (C) 2016 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_RENDERDEVICEINSTANCE_HPP
|
||||||
|
#define NAZARA_RENDERDEVICEINSTANCE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
///TODO: Rename
|
||||||
|
class NAZARA_RENDERER_API RenderDeviceInstance
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RenderDeviceInstance() = default;
|
||||||
|
virtual ~RenderDeviceInstance();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/RenderDeviceInstance.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_RENDERDEVICEINSTANCE_HPP
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright (C) 2016 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
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
|
||||||
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/DebugOff.hpp>
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright (C) 2016 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_RENDERSURFACE_HPP
|
||||||
|
#define NAZARA_RENDERSURFACE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Utility/WindowHandle.hpp>
|
||||||
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
///TODO: Rename
|
||||||
|
class NAZARA_RENDERER_API RenderSurface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RenderSurface() = default;
|
||||||
|
virtual ~RenderSurface();
|
||||||
|
|
||||||
|
virtual bool Create(WindowHandle handle) = 0;
|
||||||
|
virtual void Destroy() = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/RenderSurface.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_RENDERSURFACE_HPP
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright (C) 2016 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
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/RenderSurface.hpp>
|
||||||
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/DebugOff.hpp>
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <Nazara/Core/Clock.hpp>
|
#include <Nazara/Core/Clock.hpp>
|
||||||
#include <Nazara/Math/Rect.hpp>
|
#include <Nazara/Math/Rect.hpp>
|
||||||
#include <Nazara/Math/Vector3.hpp>
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderSurface.hpp>
|
||||||
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
||||||
#include <Nazara/Renderer/RenderWindowParameters.hpp>
|
#include <Nazara/Renderer/RenderWindowParameters.hpp>
|
||||||
#include <Nazara/Utility/Window.hpp>
|
#include <Nazara/Utility/Window.hpp>
|
||||||
|
|
@ -52,6 +53,7 @@ namespace Nz
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<RenderWindowImpl> m_impl;
|
std::unique_ptr<RenderWindowImpl> m_impl;
|
||||||
Clock m_clock;
|
Clock m_clock;
|
||||||
|
std::unique_ptr<RenderSurface> m_surface;
|
||||||
RenderWindowParameters m_parameters;
|
RenderWindowParameters m_parameters;
|
||||||
unsigned int m_framerateLimit;
|
unsigned int m_framerateLimit;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,15 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
class RenderSurface;
|
||||||
|
|
||||||
class NAZARA_RENDERER_API RenderWindowImpl
|
class NAZARA_RENDERER_API RenderWindowImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RenderWindowImpl() = default;
|
RenderWindowImpl() = default;
|
||||||
virtual ~RenderWindowImpl();
|
virtual ~RenderWindowImpl();
|
||||||
|
|
||||||
virtual bool Create(WindowHandle handle, const Vector2ui& size, const RenderWindowParameters& parameters) = 0;
|
virtual bool Create(RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ namespace Nz
|
||||||
class AbstractBuffer;
|
class AbstractBuffer;
|
||||||
class Buffer;
|
class Buffer;
|
||||||
class RendererImpl;
|
class RendererImpl;
|
||||||
|
class RenderDeviceInstance;
|
||||||
|
class RenderSurface;
|
||||||
class RenderWindowImpl;
|
class RenderWindowImpl;
|
||||||
|
|
||||||
using CreateRendererImplFunc = RendererImpl*(*)();
|
using CreateRendererImplFunc = RendererImpl*(*)();
|
||||||
|
|
@ -32,8 +34,11 @@ namespace Nz
|
||||||
virtual ~RendererImpl();
|
virtual ~RendererImpl();
|
||||||
|
|
||||||
virtual std::unique_ptr<AbstractBuffer> CreateHardwareBufferImpl(Buffer* parent, BufferType type) = 0;
|
virtual std::unique_ptr<AbstractBuffer> CreateHardwareBufferImpl(Buffer* parent, BufferType type) = 0;
|
||||||
|
virtual std::unique_ptr<RenderSurface> CreateRenderSurfaceImpl() = 0;
|
||||||
virtual std::unique_ptr<RenderWindowImpl> CreateRenderWindowImpl() = 0;
|
virtual std::unique_ptr<RenderWindowImpl> CreateRenderWindowImpl() = 0;
|
||||||
|
|
||||||
|
virtual std::unique_ptr<RenderDeviceInstance> InstanciateRenderDevice(std::size_t deviceIndex) = 0;
|
||||||
|
|
||||||
virtual bool IsBetterThan(const RendererImpl* other) const = 0;
|
virtual bool IsBetterThan(const RendererImpl* other) const = 0;
|
||||||
|
|
||||||
virtual RenderAPI QueryAPI() const = 0;
|
virtual RenderAPI QueryAPI() const = 0;
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,12 @@ namespace Nz
|
||||||
void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
||||||
void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
||||||
|
|
||||||
bool Create(WindowHandle handle, const Vector2ui& size, const RenderWindowParameters& parameters) override;
|
bool Create(RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) override;
|
||||||
|
|
||||||
inline const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const override;
|
inline const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const override;
|
||||||
inline UInt32 GetFramebufferCount() const;
|
inline UInt32 GetFramebufferCount() const;
|
||||||
inline const Vk::DeviceHandle& GetDevice() const;
|
inline const Vk::DeviceHandle& GetDevice() const;
|
||||||
inline UInt32 GetPresentableFamilyQueue() const;
|
inline UInt32 GetPresentableFamilyQueue() const;
|
||||||
inline const Vk::Surface& GetSurface() const;
|
|
||||||
inline const Vk::Swapchain& GetSwapchain() const;
|
inline const Vk::Swapchain& GetSwapchain() const;
|
||||||
|
|
||||||
void Present(UInt32 imageIndex) override;
|
void Present(UInt32 imageIndex) override;
|
||||||
|
|
@ -56,7 +55,7 @@ namespace Nz
|
||||||
private:
|
private:
|
||||||
bool SetupDepthBuffer(const Vector2ui& size);
|
bool SetupDepthBuffer(const Vector2ui& size);
|
||||||
bool SetupRenderPass(const Vector2ui& size);
|
bool SetupRenderPass(const Vector2ui& size);
|
||||||
bool SetupSwapchain(const Vector2ui& size);
|
bool SetupSwapchain(Vk::Surface& surface, const Vector2ui& size);
|
||||||
|
|
||||||
Clock m_clock;
|
Clock m_clock;
|
||||||
VkColorSpaceKHR m_colorSpace;
|
VkColorSpaceKHR m_colorSpace;
|
||||||
|
|
@ -69,7 +68,6 @@ namespace Nz
|
||||||
Vk::Image m_depthBuffer;
|
Vk::Image m_depthBuffer;
|
||||||
Vk::ImageView m_depthBufferView;
|
Vk::ImageView m_depthBufferView;
|
||||||
Vk::Queue m_presentQueue;
|
Vk::Queue m_presentQueue;
|
||||||
Vk::Surface m_surface;
|
|
||||||
Vk::Swapchain m_swapchain;
|
Vk::Swapchain m_swapchain;
|
||||||
UInt32 m_presentableFamilyQueue;
|
UInt32 m_presentableFamilyQueue;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,6 @@ namespace Nz
|
||||||
return m_presentableFamilyQueue;
|
return m_presentableFamilyQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Vk::Surface& VkRenderWindow::GetSurface() const
|
|
||||||
{
|
|
||||||
return m_surface;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const Vk::Swapchain& VkRenderWindow::GetSwapchain() const
|
inline const Vk::Swapchain& VkRenderWindow::GetSwapchain() const
|
||||||
{
|
{
|
||||||
return m_swapchain;
|
return m_swapchain;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright (C) 2015 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_VULKANDEVICE_HPP
|
||||||
|
#define NAZARA_VULKANRENDERER_VULKANDEVICE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
//TODO: Move all the software stuff to the Renderer
|
||||||
|
|
||||||
|
class NAZARA_VULKANRENDERER_API VulkanDevice : public RenderDeviceInstance
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VulkanDevice(Vk::DeviceHandle device);
|
||||||
|
~VulkanDevice();
|
||||||
|
|
||||||
|
VulkanDevice& operator=(const VulkanDevice&) = delete;
|
||||||
|
VulkanDevice& operator=(VulkanDevice&&) = delete; ///TODO
|
||||||
|
|
||||||
|
private:
|
||||||
|
Vk::DeviceHandle m_device;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/VulkanRenderer/VulkanDevice.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_VULKANRENDERER_VULKANDEVICE_HPP
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright (C) 2016 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/VulkanDevice.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||||
|
|
@ -25,8 +25,12 @@ namespace Nz
|
||||||
VulkanRenderer() = default;
|
VulkanRenderer() = default;
|
||||||
~VulkanRenderer();
|
~VulkanRenderer();
|
||||||
|
|
||||||
|
std::unique_ptr<AbstractBuffer> CreateHardwareBufferImpl(Buffer* parent, BufferType type) override;
|
||||||
|
std::unique_ptr<RenderSurface> CreateRenderSurfaceImpl() override;
|
||||||
std::unique_ptr<RenderWindowImpl> CreateRenderWindowImpl() override;
|
std::unique_ptr<RenderWindowImpl> CreateRenderWindowImpl() override;
|
||||||
|
|
||||||
|
std::unique_ptr<RenderDeviceInstance> InstanciateRenderDevice(std::size_t deviceIndex) override;
|
||||||
|
|
||||||
bool IsBetterThan(const RendererImpl* other) const override;
|
bool IsBetterThan(const RendererImpl* other) const override;
|
||||||
|
|
||||||
RenderAPI QueryAPI() const override;
|
RenderAPI QueryAPI() const override;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
// Copyright (C) 2015 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_SURFACE_HPP
|
||||||
|
#define NAZARA_VULKANRENDERER_SURFACE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderSurface.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/Wrapper/Surface.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/Wrapper/Swapchain.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
class NAZARA_VULKANRENDERER_API VulkanSurface : public RenderSurface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VulkanSurface();
|
||||||
|
VulkanSurface(const VulkanSurface&) = delete;
|
||||||
|
VulkanSurface(VulkanSurface&&) = delete; ///TODO
|
||||||
|
virtual ~VulkanSurface();
|
||||||
|
|
||||||
|
bool Create(WindowHandle handle) override;
|
||||||
|
void Destroy() override;
|
||||||
|
|
||||||
|
inline Vk::Surface& GetSurface();
|
||||||
|
|
||||||
|
VulkanSurface& operator=(const VulkanSurface&) = delete;
|
||||||
|
VulkanSurface& operator=(VulkanSurface&&) = delete; ///TODO
|
||||||
|
|
||||||
|
private:
|
||||||
|
Vk::Surface m_surface;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/VulkanRenderer/VulkanSurface.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_VULKANRENDERER_SURFACE_HPP
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright (C) 2016 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/VulkanSurface.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
inline Vk::Surface& VulkanSurface::GetSurface()
|
||||||
|
{
|
||||||
|
return m_surface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
// Copyright (C) 2015 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
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
|
||||||
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
RenderDeviceInstance::~RenderDeviceInstance() = default;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
// Copyright (C) 2015 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
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/RenderSurface.hpp>
|
||||||
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
RenderSurface::~RenderSurface() = default;
|
||||||
|
}
|
||||||
|
|
@ -35,14 +35,22 @@ namespace Nz
|
||||||
|
|
||||||
bool RenderWindow::OnWindowCreated()
|
bool RenderWindow::OnWindowCreated()
|
||||||
{
|
{
|
||||||
|
auto surface = Renderer::GetRendererImpl()->CreateRenderSurfaceImpl();
|
||||||
|
if (!surface->Create(GetHandle()))
|
||||||
|
{
|
||||||
|
NazaraError("Failed to create render surface: " + Error::GetLastError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto impl = Renderer::GetRendererImpl()->CreateRenderWindowImpl();
|
auto impl = Renderer::GetRendererImpl()->CreateRenderWindowImpl();
|
||||||
if (!impl->Create(GetHandle(), Vector2ui(GetWidth(), GetHeight()), m_parameters))
|
if (!impl->Create(surface.get(), Vector2ui(GetWidth(), GetHeight()), m_parameters))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to create render window implementation: " + Error::GetLastError());
|
NazaraError("Failed to create render window implementation: " + Error::GetLastError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_impl = std::move(impl);
|
m_impl = std::move(impl);
|
||||||
|
m_surface = std::move(surface);
|
||||||
|
|
||||||
m_clock.Restart();
|
m_clock.Restart();
|
||||||
|
|
||||||
|
|
@ -52,6 +60,7 @@ namespace Nz
|
||||||
void RenderWindow::OnWindowDestroy()
|
void RenderWindow::OnWindowDestroy()
|
||||||
{
|
{
|
||||||
m_impl.reset();
|
m_impl.reset();
|
||||||
|
m_surface.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderWindow::OnWindowResized()
|
void RenderWindow::OnWindowResized()
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
#include <Nazara/Utility/PixelFormat.hpp>
|
#include <Nazara/Utility/PixelFormat.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Vulkan.hpp>
|
#include <Nazara/VulkanRenderer/Vulkan.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||||
|
|
@ -14,7 +15,6 @@
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
VkRenderWindow::VkRenderWindow() :
|
VkRenderWindow::VkRenderWindow() :
|
||||||
m_surface(Nz::Vulkan::GetInstance()),
|
|
||||||
m_physicalDevice(nullptr),
|
m_physicalDevice(nullptr),
|
||||||
m_depthStencilFormat(VK_FORMAT_MAX_ENUM)
|
m_depthStencilFormat(VK_FORMAT_MAX_ENUM)
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +27,6 @@ namespace Nz
|
||||||
m_renderPass.Destroy();
|
m_renderPass.Destroy();
|
||||||
|
|
||||||
m_swapchain.Destroy();
|
m_swapchain.Destroy();
|
||||||
m_surface.Destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VkRenderWindow::Acquire(UInt32* imageIndex) const
|
bool VkRenderWindow::Acquire(UInt32* imageIndex) const
|
||||||
|
|
@ -65,25 +64,13 @@ namespace Nz
|
||||||
//commandBuffer.SetImageLayout(m_swapchain.GetBuffer(imageIndex).image, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
//commandBuffer.SetImageLayout(m_swapchain.GetBuffer(imageIndex).image, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VkRenderWindow::Create(WindowHandle handle, const Vector2ui& size, const RenderWindowParameters& parameters)
|
bool VkRenderWindow::Create(RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters)
|
||||||
{
|
{
|
||||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
|
||||||
HWND winHandle = reinterpret_cast<HWND>(handle);
|
|
||||||
HINSTANCE instance = reinterpret_cast<HINSTANCE>(GetWindowLongPtrW(winHandle, GWLP_HINSTANCE));
|
|
||||||
bool success = m_surface.Create(instance, winHandle);
|
|
||||||
#else
|
|
||||||
#error This OS is not supported by Vulkan
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to create Vulkan surface");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_physicalDevice = Vulkan::GetPhysicalDevices()[0].device;
|
m_physicalDevice = Vulkan::GetPhysicalDevices()[0].device;
|
||||||
|
|
||||||
m_device = Vulkan::SelectDevice(m_physicalDevice, m_surface, &m_presentableFamilyQueue);
|
Vk::Surface& vulkanSurface = static_cast<VulkanSurface*>(surface)->GetSurface();
|
||||||
|
|
||||||
|
m_device = Vulkan::SelectDevice(m_physicalDevice, vulkanSurface, &m_presentableFamilyQueue);
|
||||||
if (!m_device)
|
if (!m_device)
|
||||||
{
|
{
|
||||||
NazaraError("Failed to get compatible Vulkan device");
|
NazaraError("Failed to get compatible Vulkan device");
|
||||||
|
|
@ -93,7 +80,7 @@ namespace Nz
|
||||||
m_presentQueue = m_device->GetQueue(m_presentableFamilyQueue, 0);
|
m_presentQueue = m_device->GetQueue(m_presentableFamilyQueue, 0);
|
||||||
|
|
||||||
std::vector<VkSurfaceFormatKHR> surfaceFormats;
|
std::vector<VkSurfaceFormatKHR> surfaceFormats;
|
||||||
if (!m_surface.GetFormats(m_physicalDevice, &surfaceFormats))
|
if (!vulkanSurface.GetFormats(m_physicalDevice, &surfaceFormats))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to query supported surface formats");
|
NazaraError("Failed to query supported surface formats");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -159,7 +146,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetupSwapchain(size))
|
if (!SetupSwapchain(vulkanSurface, size))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to create swapchain");
|
NazaraError("Failed to create swapchain");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -369,10 +356,10 @@ namespace Nz
|
||||||
return m_renderPass.Create(m_device, createInfo);
|
return m_renderPass.Create(m_device, createInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VkRenderWindow::SetupSwapchain(const Vector2ui& size)
|
bool VkRenderWindow::SetupSwapchain(Vk::Surface& surface, const Vector2ui& size)
|
||||||
{
|
{
|
||||||
VkSurfaceCapabilitiesKHR surfaceCapabilities;
|
VkSurfaceCapabilitiesKHR surfaceCapabilities;
|
||||||
if (!m_surface.GetCapabilities(m_physicalDevice, &surfaceCapabilities))
|
if (!surface.GetCapabilities(m_physicalDevice, &surfaceCapabilities))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to query surface capabilities");
|
NazaraError("Failed to query surface capabilities");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -392,7 +379,7 @@ namespace Nz
|
||||||
extent = surfaceCapabilities.currentExtent;
|
extent = surfaceCapabilities.currentExtent;
|
||||||
|
|
||||||
std::vector<VkPresentModeKHR> presentModes;
|
std::vector<VkPresentModeKHR> presentModes;
|
||||||
if (!m_surface.GetPresentModes(m_physicalDevice, &presentModes))
|
if (!surface.GetPresentModes(m_physicalDevice, &presentModes))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to query supported present modes");
|
NazaraError("Failed to query supported present modes");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -415,7 +402,7 @@ namespace Nz
|
||||||
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
|
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
|
||||||
nullptr,
|
nullptr,
|
||||||
0,
|
0,
|
||||||
m_surface,
|
surface,
|
||||||
imageCount,
|
imageCount,
|
||||||
m_colorFormat,
|
m_colorFormat,
|
||||||
m_colorSpace,
|
m_colorSpace,
|
||||||
|
|
|
||||||
|
|
@ -392,7 +392,10 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
if (presentableQueueFamilyIndex != UINT32_MAX)
|
if (presentableQueueFamilyIndex != UINT32_MAX)
|
||||||
|
{
|
||||||
*presentableFamilyQueue = presentableQueueFamilyIndex;
|
*presentableFamilyQueue = presentableQueueFamilyIndex;
|
||||||
|
return device.CreateHandle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
// Copyright (C) 2016 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/VulkanDevice.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
VulkanDevice::~VulkanDevice() = default;
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
#include <Nazara/VulkanRenderer/VulkanRenderer.hpp>
|
#include <Nazara/VulkanRenderer/VulkanRenderer.hpp>
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderDeviceInstance.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/VulkanBuffer.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
|
||||||
#include <Nazara/VulkanRenderer/VkRenderWindow.hpp>
|
#include <Nazara/VulkanRenderer/VkRenderWindow.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Wrapper/Loader.hpp>
|
#include <Nazara/VulkanRenderer/Wrapper/Loader.hpp>
|
||||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||||
|
|
@ -15,11 +18,26 @@ namespace Nz
|
||||||
Vulkan::Uninitialize();
|
Vulkan::Uninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<AbstractBuffer> VulkanRenderer::CreateHardwareBufferImpl(Buffer* parent, BufferType type)
|
||||||
|
{
|
||||||
|
return nullptr; //< TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<RenderSurface> VulkanRenderer::CreateRenderSurfaceImpl()
|
||||||
|
{
|
||||||
|
return std::make_unique<VulkanSurface>();
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<RenderWindowImpl> VulkanRenderer::CreateRenderWindowImpl()
|
std::unique_ptr<RenderWindowImpl> VulkanRenderer::CreateRenderWindowImpl()
|
||||||
{
|
{
|
||||||
return std::make_unique<VkRenderWindow>();
|
return std::make_unique<VkRenderWindow>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<RenderDeviceInstance> VulkanRenderer::InstanciateRenderDevice(std::size_t deviceIndex)
|
||||||
|
{
|
||||||
|
return std::unique_ptr<RenderDeviceInstance>();
|
||||||
|
}
|
||||||
|
|
||||||
bool VulkanRenderer::IsBetterThan(const RendererImpl* other) const
|
bool VulkanRenderer::IsBetterThan(const RendererImpl* other) const
|
||||||
{
|
{
|
||||||
if (other->QueryAPI() == RenderAPI_Vulkan && QueryAPIVersion() < other->QueryAPIVersion())
|
if (other->QueryAPI() == RenderAPI_Vulkan && QueryAPIVersion() < other->QueryAPIVersion())
|
||||||
|
|
@ -41,14 +59,14 @@ namespace Nz
|
||||||
String VulkanRenderer::QueryAPIString() const
|
String VulkanRenderer::QueryAPIString() const
|
||||||
{
|
{
|
||||||
StringStream ss;
|
StringStream ss;
|
||||||
ss << "Vulkan renderer " << VK_VERSION_MAJOR(m_apiVersion) << '.' << VK_VERSION_MINOR(m_apiVersion) << '.' << VK_VERSION_PATCH(m_apiVersion);
|
ss << "Vulkan renderer " << VK_VERSION_MAJOR(APIVersion) << '.' << VK_VERSION_MINOR(APIVersion) << '.' << VK_VERSION_PATCH(APIVersion);
|
||||||
|
|
||||||
return ss;
|
return ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 VulkanRenderer::QueryAPIVersion() const
|
UInt32 VulkanRenderer::QueryAPIVersion() const
|
||||||
{
|
{
|
||||||
return m_apiVersion;
|
return APIVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<RenderDevice> VulkanRenderer::QueryRenderDevices() const
|
std::vector<RenderDevice> VulkanRenderer::QueryRenderDevices() const
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright (C) 2016 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/VulkanSurface.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/Vulkan.hpp>
|
||||||
|
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
VulkanSurface::VulkanSurface() :
|
||||||
|
m_surface(Vulkan::GetInstance())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VulkanSurface::~VulkanSurface() = default;
|
||||||
|
|
||||||
|
bool VulkanSurface::Create(WindowHandle handle)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||||
|
{
|
||||||
|
HWND winHandle = reinterpret_cast<HWND>(handle);
|
||||||
|
HINSTANCE instance = reinterpret_cast<HINSTANCE>(GetWindowLongPtrW(winHandle, GWLP_HINSTANCE));
|
||||||
|
|
||||||
|
success = m_surface.Create(instance, winHandle);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error This OS is not supported by Vulkan
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
NazaraError("Failed to create Vulkan surface: " + TranslateVulkanError(m_surface.GetLastErrorCode()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanSurface::Destroy()
|
||||||
|
{
|
||||||
|
m_surface.Destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue