Replace RenderWindow with swapchains

This commit is contained in:
SirLynix
2023-01-21 12:02:34 +01:00
committed by Jérôme Leclercq
parent 8db1c04568
commit 18851c9185
66 changed files with 1404 additions and 2048 deletions

View File

@@ -13,6 +13,7 @@
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Graphics/Components/GraphicsComponent.hpp>
#include <Nazara/Graphics/Components/LightComponent.hpp>
#include <Nazara/Renderer/WindowSwapchain.hpp>
#include <Nazara/Utility/Node.hpp>
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utils/MemoryPool.hpp>
@@ -27,7 +28,6 @@ namespace Nz
class CommandBufferBuilder;
class FramePipeline;
class RenderFrame;
class RenderWindow;
class UploadPool;
class NAZARA_GRAPHICS_API RenderSystem
@@ -41,7 +41,7 @@ namespace Nz
RenderSystem(RenderSystem&&) = delete;
~RenderSystem();
template<typename T = RenderWindow, typename... Args> T& CreateWindow(Args&&... args);
WindowSwapchain& CreateSwapchain(Window& window, const SwapchainParameters& parameters = SwapchainParameters{});
inline FramePipeline& GetFramePipeline();
inline const FramePipeline& GetFramePipeline() const;
@@ -133,7 +133,7 @@ namespace Nz
std::unordered_set<GraphicsEntity*> m_newlyVisibleGfxEntities;
std::unordered_set<LightEntity*> m_newlyHiddenLightEntities;
std::unordered_set<LightEntity*> m_newlyVisibleLightEntities;
std::vector<std::unique_ptr<RenderWindow>> m_renderWindows;
std::vector<std::unique_ptr<WindowSwapchain>> m_windowSwapchains;
ElementRendererRegistry m_elementRegistry;
MemoryPool<CameraEntity> m_cameraEntityPool;
MemoryPool<GraphicsEntity> m_graphicsEntityPool;

View File

@@ -8,19 +8,6 @@
namespace Nz
{
template<typename T, typename ...Args>
T& RenderSystem::CreateWindow(Args&& ...args)
{
static_assert(std::is_base_of_v<RenderWindow, T>, "T must inherit RenderWindow");
auto windowPtr = std::make_unique<T>(std::forward<Args>(args)...);
T& windowRef = *windowPtr;
m_renderWindows.emplace_back(std::move(windowPtr));
return windowRef;
}
inline FramePipeline& RenderSystem::GetFramePipeline()
{
return *m_pipeline;

View File

@@ -30,7 +30,6 @@
#define NAZARA_GLOBAL_OPENGLRENDERER_HPP
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/OpenGLRenderer/DummySurface.hpp>
#include <Nazara/OpenGLRenderer/OpenGLBuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp>
#include <Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.hpp>
@@ -44,9 +43,9 @@
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPipeline.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderPipelineLayout.hpp>
#include <Nazara/OpenGLRenderer/OpenGLRenderWindow.hpp>
#include <Nazara/OpenGLRenderer/OpenGLShaderBinding.hpp>
#include <Nazara/OpenGLRenderer/OpenGLShaderModule.hpp>
#include <Nazara/OpenGLRenderer/OpenGLSwapchain.hpp>
#include <Nazara/OpenGLRenderer/OpenGLTexture.hpp>
#include <Nazara/OpenGLRenderer/OpenGLTextureSampler.hpp>
#include <Nazara/OpenGLRenderer/OpenGLUploadPool.hpp>

View File

@@ -1,34 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - OpenGL renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_OPENGLRENDERER_DUMMYSURFACE_HPP
#define NAZARA_OPENGLRENDERER_DUMMYSURFACE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/OpenGLRenderer/Config.hpp>
#include <Nazara/Renderer/RenderSurface.hpp>
namespace Nz
{
class NAZARA_OPENGLRENDERER_API DummySurface : public RenderSurface
{
public:
DummySurface() = default;
~DummySurface() = default;
bool Create(WindowHandle handle) override;
void Destroy() override;
inline WindowHandle GetWindowHandle() const;
private:
WindowHandle m_handle;
};
}
#include <Nazara/OpenGLRenderer/DummySurface.inl>
#endif // NAZARA_OPENGLRENDERER_DUMMYSURFACE_HPP

View File

@@ -1,16 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - OpenGL renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/DummySurface.hpp>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz
{
inline WindowHandle DummySurface::GetWindowHandle() const
{
return m_handle;
}
}
#include <Nazara/OpenGLRenderer/DebugOff.hpp>

View File

@@ -45,6 +45,7 @@ namespace Nz
std::shared_ptr<RenderPipelineLayout> InstantiateRenderPipelineLayout(RenderPipelineLayoutInfo pipelineLayoutInfo) override;
std::shared_ptr<ShaderModule> InstantiateShaderModule(nzsl::ShaderStageTypeFlags shaderStages, const nzsl::Ast::Module& shaderModule, const nzsl::ShaderWriter::States& states) override;
std::shared_ptr<ShaderModule> InstantiateShaderModule(nzsl::ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const void* source, std::size_t sourceSize, const nzsl::ShaderWriter::States& states) override;
std::shared_ptr<Swapchain> InstantiateSwapchain(WindowHandle windowHandle, const Vector2ui& windowSize, const SwapchainParameters& parameters) override;
std::shared_ptr<Texture> InstantiateTexture(const TextureInfo& params) override;
std::shared_ptr<TextureSampler> InstantiateTextureSampler(const TextureSamplerInfo& params) override;

View File

@@ -15,12 +15,12 @@
namespace Nz
{
class OpenGLCommandBuffer;
class OpenGLRenderWindow;
class OpenGLSwapchain;
class NAZARA_OPENGLRENDERER_API OpenGLRenderImage : public RenderImage
{
public:
OpenGLRenderImage(OpenGLRenderWindow& owner);
OpenGLRenderImage(OpenGLSwapchain& owner);
void Execute(const FunctionRef<void(CommandBufferBuilder& builder)>& callback, QueueTypeFlags queueTypeFlags) override;
@@ -31,7 +31,7 @@ namespace Nz
void SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags) override;
private:
OpenGLRenderWindow& m_owner;
OpenGLSwapchain& m_owner;
OpenGLUploadPool m_uploadPool;
};
}

View File

@@ -22,9 +22,6 @@ namespace Nz
OpenGLRenderer() = default;
~OpenGLRenderer();
std::unique_ptr<RenderSurface> CreateRenderSurfaceImpl() override;
std::unique_ptr<RenderWindowImpl> CreateRenderWindowImpl(RenderWindow& owner) override;
std::shared_ptr<RenderDevice> InstanciateRenderDevice(std::size_t deviceIndex, const RenderDeviceFeatures& enabledFeatures) override;
RenderAPI QueryAPI() const override;

View File

@@ -14,23 +14,21 @@
#include <Nazara/OpenGLRenderer/OpenGLRenderPass.hpp>
#include <Nazara/OpenGLRenderer/OpenGLWindowFramebuffer.hpp>
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
#include <Nazara/Renderer/RenderWindowImpl.hpp>
#include <Nazara/Renderer/Swapchain.hpp>
#include <Nazara/Renderer/SwapchainParameters.hpp>
#include <optional>
#include <vector>
namespace Nz
{
class RenderWindow;
class NAZARA_OPENGLRENDERER_API OpenGLRenderWindow final : public RenderWindowImpl
class NAZARA_OPENGLRENDERER_API OpenGLSwapchain final : public Swapchain
{
public:
OpenGLRenderWindow(RenderWindow& owner);
~OpenGLRenderWindow() = default;
OpenGLSwapchain(OpenGLDevice& device, WindowHandle windowHandle, const Vector2ui& windowSize, const SwapchainParameters& parameters);
~OpenGLSwapchain() = default;
RenderFrame Acquire() override;
RenderFrame AcquireFrame() override;
bool Create(RendererImpl* renderer, RenderSurface* surface, const RenderWindowParameters& parameters) override;
std::shared_ptr<CommandPool> CreateCommandPool(QueueType queueType) override;
inline GL::Context& GetContext();
@@ -39,6 +37,8 @@ namespace Nz
const OpenGLRenderPass& GetRenderPass() const override;
const Vector2ui& GetSize() const override;
void NotifyResize(const Vector2ui& newSize) override;
void Present();
private:
@@ -47,11 +47,11 @@ namespace Nz
std::vector<std::unique_ptr<OpenGLRenderImage>> m_renderImage;
std::unique_ptr<GL::Context> m_context;
OpenGLWindowFramebuffer m_framebuffer;
RenderWindow& m_owner;
Vector2ui m_size;
bool m_sizeInvalidated;
};
}
#include <Nazara/OpenGLRenderer/OpenGLRenderWindow.inl>
#include <Nazara/OpenGLRenderer/OpenGLSwapchain.inl>
#endif // NAZARA_OPENGLRENDERER_OPENGLRENDERWINDOW_HPP

View File

@@ -2,13 +2,13 @@
// This file is part of the "Nazara Engine - OpenGL renderer"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/OpenGLRenderer/OpenGLRenderWindow.hpp>
#include <Nazara/OpenGLRenderer/OpenGLSwapchain.hpp>
#include <cassert>
#include <Nazara/OpenGLRenderer/Debug.hpp>
namespace Nz
{
inline GL::Context& OpenGLRenderWindow::GetContext()
inline GL::Context& OpenGLSwapchain::GetContext()
{
assert(m_context);
return *m_context;

View File

@@ -12,12 +12,12 @@
namespace Nz
{
class OpenGLRenderWindow;
class OpenGLSwapchain;
class NAZARA_OPENGLRENDERER_API OpenGLWindowFramebuffer : public OpenGLFramebuffer
{
public:
inline OpenGLWindowFramebuffer(OpenGLRenderWindow& renderWindow);
inline OpenGLWindowFramebuffer(OpenGLSwapchain& renderWindow);
OpenGLWindowFramebuffer(const OpenGLWindowFramebuffer&) = delete;
OpenGLWindowFramebuffer(OpenGLWindowFramebuffer&&) noexcept = default;
~OpenGLWindowFramebuffer() = default;
@@ -34,7 +34,7 @@ namespace Nz
OpenGLWindowFramebuffer& operator=(OpenGLWindowFramebuffer&&) = delete;
private:
OpenGLRenderWindow& m_renderWindow;
OpenGLSwapchain& m_renderWindow;
};
}

View File

@@ -7,7 +7,7 @@
namespace Nz
{
inline OpenGLWindowFramebuffer::OpenGLWindowFramebuffer(OpenGLRenderWindow& renderWindow) :
inline OpenGLWindowFramebuffer::OpenGLWindowFramebuffer(OpenGLSwapchain& renderWindow) :
OpenGLFramebuffer(FramebufferType::Window),
m_renderWindow(renderWindow)
{

View File

@@ -34,8 +34,8 @@
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/CursorController.hpp>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Platform/Event.hpp>
#include <Nazara/Platform/EventHandler.hpp>
#include <Nazara/Platform/WindowEvent.hpp>
#include <Nazara/Platform/WindowEventHandler.hpp>
#include <Nazara/Platform/Icon.hpp>
#include <Nazara/Platform/Joystick.hpp>
#include <Nazara/Platform/Keyboard.hpp>

View File

@@ -48,10 +48,13 @@ namespace Nz
enum class WindowEventType
{
Created,
Destruction,
GainedFocus,
LostFocus,
KeyPressed,
KeyReleased,
Minimized,
MouseButtonPressed,
MouseButtonReleased,
MouseEntered,
@@ -61,6 +64,7 @@ namespace Nz
Moved,
Quit,
Resized,
Restored,
TextEdited,
TextEntered,

View File

@@ -1,57 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PLATFORM_EVENTHANDLER_HPP
#define NAZARA_PLATFORM_EVENTHANDLER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Event.hpp>
#include <Nazara/Utils/Signal.hpp>
namespace Nz
{
class EventHandler;
using EventHandlerHandle = ObjectHandle<EventHandler>;
class EventHandler : public HandledObject<EventHandler>
{
public:
EventHandler() = default;
explicit EventHandler(const EventHandler&);
EventHandler(EventHandler&&) noexcept = default;
~EventHandler() = default;
inline void Dispatch(const WindowEvent& event);
EventHandler& operator=(const EventHandler&) = delete;
EventHandler& operator=(EventHandler&&) noexcept = default;
NazaraSignal(OnEvent, const EventHandler* /*eventHandler*/, const WindowEvent& /*event*/);
NazaraSignal(OnGainedFocus, const EventHandler* /*eventHandler*/);
NazaraSignal(OnLostFocus, const EventHandler* /*eventHandler*/);
NazaraSignal(OnKeyPressed, const EventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnKeyReleased, const EventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnMouseButtonPressed, const EventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseButtonReleased, const EventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseEntered, const EventHandler* /*eventHandler*/);
NazaraSignal(OnMouseLeft, const EventHandler* /*eventHandler*/);
NazaraSignal(OnMouseMoved, const EventHandler* /*eventHandler*/, const WindowEvent::MouseMoveEvent& /*event*/);
NazaraSignal(OnMouseWheelMoved, const EventHandler* /*eventHandler*/, const WindowEvent::MouseWheelEvent& /*event*/);
NazaraSignal(OnMoved, const EventHandler* /*eventHandler*/, const WindowEvent::PositionEvent& /*event*/);
NazaraSignal(OnQuit, const EventHandler* /*eventHandler*/);
NazaraSignal(OnResized, const EventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/);
NazaraSignal(OnTextEntered, const EventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/);
NazaraSignal(OnTextEdited, const EventHandler* /*eventHandler*/, const WindowEvent::EditEvent& /*event*/);
};
}
#include <Nazara/Platform/EventHandler.inl>
#endif // NAZARA_PLATFORM_EVENTHANDLER_HPP

View File

@@ -15,7 +15,7 @@
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/CursorController.hpp>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Platform/EventHandler.hpp>
#include <Nazara/Platform/WindowEventHandler.hpp>
#include <Nazara/Platform/Icon.hpp>
#include <Nazara/Platform/VideoMode.hpp>
#include <Nazara/Platform/WindowHandle.hpp>
@@ -38,35 +38,31 @@ namespace Nz
public:
Window();
inline Window(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default);
inline explicit Window(void* handle);
inline explicit Window(WindowHandle handle);
Window(const Window&) = delete;
Window(Window&& window);
virtual ~Window();
Window(Window&& window) noexcept;
~Window();
inline void Close();
bool Create(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default);
bool Create(void* handle);
bool Create(WindowHandle handle);
void Destroy();
inline void EnableCloseOnQuit(bool closeOnQuit);
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
inline void EnableEventPolling(bool enable);
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
inline const std::shared_ptr<Cursor>& GetCursor() const;
inline CursorController& GetCursorController();
inline EventHandler& GetEventHandler();
inline WindowEventHandler& GetEventHandler();
WindowHandle GetHandle() const;
Vector2i GetPosition() const;
Vector2ui GetSize() const;
WindowStyleFlags GetStyle() const;
WindowHandle GetSystemHandle() const;
std::string GetTitle() const;
void HandleEvent(const WindowEvent& event);
bool HasFocus() const;
bool IsMinimized() const;
@@ -75,16 +71,8 @@ namespace Nz
inline bool IsValid() const;
bool IsVisible() const;
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
bool PollEvent(WindowEvent* event);
void PushEvent(const WindowEvent& event);
void ProcessEvents(bool block = false);
void SetCursor(std::shared_ptr<Cursor> cursor);
inline void SetCursor(SystemCursor systemCursor);
void SetEventListener(bool listener);
void SetFocus();
void SetIcon(std::shared_ptr<Icon> icon);
void SetMaximumSize(const Vector2i& maxSize);
@@ -99,20 +87,10 @@ namespace Nz
void SetTitle(const std::string& title);
void SetVisible(bool visible);
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
bool WaitEvent(WindowEvent* event);
Window& operator=(const Window&) = delete;
Window& operator=(Window&& window);
Window& operator=(Window&& window) noexcept;
protected:
void* GetHandle();
virtual bool OnWindowCreated();
virtual void OnWindowDestroy();
virtual void OnWindowResized();
MovablePtr<WindowImpl> m_impl;
static void ProcessEvents();
private:
void ConnectSlots();
@@ -122,26 +100,21 @@ namespace Nz
inline const WindowImpl* GetImpl() const;
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
void HandleEvent(const WindowEvent& event);
static bool Initialize();
static void Uninitialize();
NazaraSlot(CursorController, OnCursorUpdated, m_cursorUpdateSlot);
std::queue<WindowEvent> m_events;
std::vector<WindowEvent> m_pendingEvents;
std::condition_variable m_eventCondition;
CursorController m_cursorController;
std::shared_ptr<Cursor> m_cursor;
EventHandler m_eventHandler;
std::shared_ptr<Icon> m_icon;
std::mutex m_eventMutex;
std::mutex m_eventConditionMutex;
bool m_asyncWindow;
std::unique_ptr<WindowImpl> m_impl;
CursorController m_cursorController;
Vector2i m_position;
Vector2ui m_size;
WindowEventHandler m_eventHandler;
bool m_closed;
bool m_closeOnQuit;
bool m_eventPolling;
bool m_ownsWindow;
bool m_waitForEvent;
};

View File

@@ -19,7 +19,7 @@ namespace Nz
Create(mode, title, style);
}
inline Window::Window(void* handle) :
inline Window::Window(WindowHandle handle) :
Window()
{
ErrorFlags flags(ErrorMode::ThrowException, true);
@@ -36,16 +36,6 @@ namespace Nz
m_closeOnQuit = closeOnQuit;
}
inline void Window::EnableEventPolling(bool enable)
{
m_eventPolling = enable;
if (!m_eventPolling)
{
while (!m_events.empty())
m_events.pop();
}
}
inline const std::shared_ptr<Cursor>& Window::GetCursor() const
{
return m_cursor;
@@ -56,7 +46,7 @@ namespace Nz
return m_cursorController;
}
inline EventHandler& Nz::Window::GetEventHandler()
inline WindowEventHandler& Nz::Window::GetEventHandler()
{
return m_eventHandler;
}
@@ -90,34 +80,14 @@ namespace Nz
SetCursor(Cursor::Get(systemCursor));
}
inline void Window::PushEvent(const WindowEvent& event)
{
if (!m_asyncWindow)
HandleEvent(event);
else
{
{
std::lock_guard<std::mutex> eventLock(m_eventMutex);
m_pendingEvents.push_back(event);
}
if (m_waitForEvent)
{
std::lock_guard<std::mutex> lock(m_eventConditionMutex);
m_eventCondition.notify_all();
}
}
}
inline WindowImpl* Window::GetImpl()
{
return m_impl;
return m_impl.get();
}
inline const WindowImpl* Window::GetImpl() const
{
return m_impl;
return m_impl.get();
}
}

View File

@@ -9,11 +9,10 @@
#ifndef NAZARA_PLATFORM_EVENT_HPP
#define NAZARA_PLATFORM_EVENT_HPP
#include <array>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Mouse.hpp>
#include <array>
namespace Nz
{

View File

@@ -0,0 +1,61 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PLATFORM_EVENTHANDLER_HPP
#define NAZARA_PLATFORM_EVENTHANDLER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/WindowEvent.hpp>
#include <Nazara/Utils/Signal.hpp>
namespace Nz
{
class WindowEventHandler;
using EventHandlerHandle = ObjectHandle<WindowEventHandler>;
class WindowEventHandler : public HandledObject<WindowEventHandler>
{
public:
WindowEventHandler() = default;
explicit WindowEventHandler(const WindowEventHandler&);
WindowEventHandler(WindowEventHandler&&) noexcept = default;
~WindowEventHandler() = default;
inline void Dispatch(const WindowEvent& event);
WindowEventHandler& operator=(const WindowEventHandler&) = delete;
WindowEventHandler& operator=(WindowEventHandler&&) noexcept = default;
NazaraSignal(OnCreated, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnDestruction, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnEvent, const WindowEventHandler* /*eventHandler*/, const WindowEvent& /*event*/);
NazaraSignal(OnGainedFocus, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnLostFocus, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnKeyPressed, const WindowEventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnKeyReleased, const WindowEventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnMinimized, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnMouseButtonPressed, const WindowEventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseButtonReleased, const WindowEventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseEntered, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnMouseLeft, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnMouseMoved, const WindowEventHandler* /*eventHandler*/, const WindowEvent::MouseMoveEvent& /*event*/);
NazaraSignal(OnMouseWheelMoved, const WindowEventHandler* /*eventHandler*/, const WindowEvent::MouseWheelEvent& /*event*/);
NazaraSignal(OnMoved, const WindowEventHandler* /*eventHandler*/, const WindowEvent::PositionEvent& /*event*/);
NazaraSignal(OnQuit, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnResized, const WindowEventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/);
NazaraSignal(OnRestored, const WindowEventHandler* /*eventHandler*/);
NazaraSignal(OnTextEntered, const WindowEventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/);
NazaraSignal(OnTextEdited, const WindowEventHandler* /*eventHandler*/, const WindowEvent::EditEvent& /*event*/);
};
}
#include <Nazara/Platform/WindowEventHandler.inl>
#endif // NAZARA_PLATFORM_EVENTHANDLER_HPP

View File

@@ -2,23 +2,31 @@
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/EventHandler.hpp>
#include <Nazara/Platform/WindowEventHandler.hpp>
#include <memory>
#include <Nazara/Platform/Debug.hpp>
namespace Nz
{
inline EventHandler::EventHandler(const EventHandler& other) :
inline WindowEventHandler::WindowEventHandler(const WindowEventHandler& other) :
HandledObject(other)
{
}
inline void EventHandler::Dispatch(const WindowEvent& event)
inline void WindowEventHandler::Dispatch(const WindowEvent& event)
{
OnEvent(this, event);
switch (event.type)
{
case WindowEventType::Created:
OnCreated(this);
break;
case WindowEventType::Destruction:
OnDestruction(this);
break;
case WindowEventType::GainedFocus:
OnGainedFocus(this);
break;
@@ -35,6 +43,10 @@ namespace Nz
OnLostFocus(this);
break;
case WindowEventType::Minimized:
OnMinimized(this);
break;
case WindowEventType::MouseButtonPressed:
OnMouseButtonPressed(this, event.mouseButton);
break;
@@ -71,6 +83,10 @@ namespace Nz
OnResized(this, event.size);
break;
case WindowEventType::Restored:
OnRestored(this);
break;
case WindowEventType::TextEntered:
OnTextEntered(this, event.text);
break;

View File

@@ -51,15 +51,14 @@
#include <Nazara/Renderer/RenderPipeline.hpp>
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/RenderSurface.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/RenderWindow.hpp>
#include <Nazara/Renderer/RenderWindowImpl.hpp>
#include <Nazara/Renderer/RenderWindowParameters.hpp>
#include <Nazara/Renderer/ShaderBinding.hpp>
#include <Nazara/Renderer/ShaderModule.hpp>
#include <Nazara/Renderer/Swapchain.hpp>
#include <Nazara/Renderer/SwapchainParameters.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#include <Nazara/Renderer/WindowSwapchain.hpp>
#endif // NAZARA_GLOBAL_RENDERER_HPP

View File

@@ -17,6 +17,8 @@
#include <Nazara/Renderer/RenderPass.hpp>
#include <Nazara/Renderer/RenderPipeline.hpp>
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
#include <Nazara/Renderer/Swapchain.hpp>
#include <Nazara/Renderer/SwapchainParameters.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
@@ -49,6 +51,7 @@ namespace Nz
virtual std::shared_ptr<ShaderModule> InstantiateShaderModule(nzsl::ShaderStageTypeFlags shaderStages, const nzsl::Ast::Module& shaderModule, const nzsl::ShaderWriter::States& states) = 0;
virtual std::shared_ptr<ShaderModule> InstantiateShaderModule(nzsl::ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const void* source, std::size_t sourceSize, const nzsl::ShaderWriter::States& states) = 0;
std::shared_ptr<ShaderModule> InstantiateShaderModule(nzsl::ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const std::filesystem::path& sourcePath, const nzsl::ShaderWriter::States& states);
virtual std::shared_ptr<Swapchain> InstantiateSwapchain(WindowHandle windowHandle, const Vector2ui& windowSize, const SwapchainParameters& parameters) = 0;
virtual std::shared_ptr<Texture> InstantiateTexture(const TextureInfo& params) = 0;
virtual std::shared_ptr<TextureSampler> InstantiateTextureSampler(const TextureSamplerInfo& params) = 0;

View File

@@ -1,30 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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_RENDERER_RENDERSURFACE_HPP
#define NAZARA_RENDERER_RENDERSURFACE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Platform/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_RENDERER_RENDERSURFACE_HPP

View File

@@ -1,12 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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>

View File

@@ -1,67 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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_RENDERER_RENDERWINDOW_HPP
#define NAZARA_RENDERER_RENDERWINDOW_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Renderer/RenderSurface.hpp>
#include <Nazara/Renderer/RenderWindowImpl.hpp>
#include <Nazara/Renderer/RenderWindowParameters.hpp>
#include <memory>
namespace Nz
{
class RenderDevice;
class NAZARA_RENDERER_API RenderWindow : public Window
{
public:
inline RenderWindow();
inline RenderWindow(std::shared_ptr<RenderDevice> renderDevice, VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
inline RenderWindow(std::shared_ptr<RenderDevice> renderDevice, void* handle, const RenderWindowParameters& parameters = RenderWindowParameters());
inline ~RenderWindow();
RenderFrame AcquireFrame();
bool Create(std::shared_ptr<RenderDevice> renderDevice, VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
bool Create(std::shared_ptr<RenderDevice> renderDevice, void* handle, const RenderWindowParameters &parameters = RenderWindowParameters());
void EnableVerticalSync(bool enabled);
inline const std::shared_ptr<RenderDevice>& GetRenderDevice() const;
inline const RenderTarget* GetRenderTarget() const;
inline RenderSurface* GetSurface();
inline bool IsValid() const;
inline void SetFramerateLimit(unsigned int limit);
RenderWindow &operator=(const RenderWindow &) = delete;
RenderWindow &operator=(RenderWindow &&) = delete; ///TODO
protected:
bool OnWindowCreated() override;
void OnWindowDestroy() override;
void OnWindowResized() override;
private:
std::shared_ptr<RenderDevice> m_renderDevice;
std::unique_ptr<RenderSurface> m_surface;
std::unique_ptr<RenderWindowImpl> m_impl;
MillisecondClock m_clock;
RenderWindowParameters m_parameters;
unsigned int m_framerateLimit;
};
} // namespace Nz
#include <Nazara/Renderer/RenderWindow.inl>
#endif // NAZARA_RENDERER_RENDERWINDOW_HPP

View File

@@ -1,62 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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/RenderWindow.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
inline RenderWindow::RenderWindow() :
m_framerateLimit(0U)
{
}
inline RenderWindow::RenderWindow(std::shared_ptr<RenderDevice> renderDevice, VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters) :
RenderWindow()
{
ErrorFlags errFlags(ErrorMode::ThrowException, true);
Create(std::move(renderDevice), mode, title, style, parameters);
}
inline RenderWindow::RenderWindow(std::shared_ptr<RenderDevice> renderDevice, void* handle, const RenderWindowParameters& parameters)
{
ErrorFlags errFlags(ErrorMode::ThrowException, true);
Create(std::move(renderDevice), handle, parameters);
}
inline RenderWindow::~RenderWindow()
{
Destroy();
}
inline const std::shared_ptr<RenderDevice>& RenderWindow::GetRenderDevice() const
{
return m_renderDevice;
}
inline const RenderTarget* RenderWindow::GetRenderTarget() const
{
return m_impl.get();
}
inline RenderSurface* RenderWindow::GetSurface()
{
return m_surface.get();
}
inline bool RenderWindow::IsValid() const
{
return m_impl != nullptr;
}
inline void RenderWindow::SetFramerateLimit(unsigned int limit)
{
m_framerateLimit = limit;
}
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -23,8 +23,8 @@ namespace Nz
class RendererImpl;
class RenderDevice;
class RenderSurface;
class RenderWindow;
class RenderWindowImpl;
class WindowSwapchain;
class Swapchain;
using CreateRendererImplFunc = RendererImpl*(*)();
@@ -34,9 +34,6 @@ namespace Nz
RendererImpl() = default;
virtual ~RendererImpl();
virtual std::unique_ptr<RenderSurface> CreateRenderSurfaceImpl() = 0;
virtual std::unique_ptr<RenderWindowImpl> CreateRenderWindowImpl(RenderWindow& owner) = 0;
virtual std::shared_ptr<RenderDevice> InstanciateRenderDevice(std::size_t deviceIndex, const RenderDeviceFeatures& enabledFeatures) = 0;
virtual RenderAPI QueryAPI() const = 0;

View File

@@ -4,41 +4,38 @@
#pragma once
#ifndef NAZARA_RENDERER_RENDERWINDOWIMPL_HPP
#define NAZARA_RENDERER_RENDERWINDOWIMPL_HPP
#ifndef NAZARA_RENDERER_SWAPCHAIN_HPP
#define NAZARA_RENDERER_SWAPCHAIN_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/WindowHandle.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/RenderDevice.hpp>
#include <Nazara/Renderer/RenderFrame.hpp>
#include <Nazara/Renderer/RenderPass.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/RenderWindowParameters.hpp>
#include <vector>
namespace Nz
{
class CommandPool;
class RendererImpl;
class RenderDevice;
class RenderSurface;
class NAZARA_RENDERER_API RenderWindowImpl : public RenderTarget
class NAZARA_RENDERER_API Swapchain : public RenderTarget
{
public:
RenderWindowImpl() = default;
virtual ~RenderWindowImpl();
Swapchain() = default;
virtual ~Swapchain();
virtual RenderFrame Acquire() = 0;
virtual RenderFrame AcquireFrame() = 0;
virtual bool Create(RendererImpl* renderer, RenderSurface* surface, const RenderWindowParameters& parameters) = 0;
virtual std::shared_ptr<CommandPool> CreateCommandPool(QueueType queueType) = 0;
virtual void NotifyResize(const Vector2ui& newSize) = 0;
protected:
static void BuildRenderPass(PixelFormat colorFormat, PixelFormat depthFormat, std::vector<RenderPass::Attachment>& attachments, std::vector<RenderPass::SubpassDescription>& subpassDescriptions, std::vector<RenderPass::SubpassDependency>& subpassDependencies);
};
}
#endif // NAZARA_RENDERER_RENDERWINDOWIMPL_HPP
#endif // NAZARA_RENDERER_SWAPCHAIN_HPP

View File

@@ -13,7 +13,7 @@
namespace Nz
{
struct RenderWindowParameters
struct SwapchainParameters
{
std::vector<PixelFormat> depthFormats = {Nz::PixelFormat::Depth24Stencil8, Nz::PixelFormat::Depth32FStencil8, Nz::PixelFormat::Depth16Stencil8, Nz::PixelFormat::Depth32F, Nz::PixelFormat::Depth24}; //< By order of preference
bool verticalSync = false;

View File

@@ -0,0 +1,65 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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_RENDERER_RENDERWINDOW_HPP
#define NAZARA_RENDERER_RENDERWINDOW_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Platform/WindowEventHandler.hpp>
#include <Nazara/Renderer/Swapchain.hpp>
#include <Nazara/Renderer/SwapchainParameters.hpp>
#include <memory>
namespace Nz
{
class RenderDevice;
class Window;
class NAZARA_RENDERER_API WindowSwapchain
{
public:
WindowSwapchain(std::shared_ptr<RenderDevice> renderDevice, Window& window, SwapchainParameters parameters = SwapchainParameters());
WindowSwapchain(const WindowSwapchain&) = delete;
inline WindowSwapchain(WindowSwapchain&& windowSwapchain) noexcept;
~WindowSwapchain() = default;
inline RenderFrame AcquireFrame();
inline bool DoesRenderOnlyIfFocused() const;
inline void EnableRenderOnlyIfFocused(bool enable = true);
inline Swapchain& GetSwapchain();
inline const Swapchain& GetSwapchain() const;
WindowSwapchain& operator=(const WindowSwapchain&) = default;
inline WindowSwapchain& operator=(WindowSwapchain&& windowSwapchain) noexcept;
private:
void ConnectSignals();
inline void DisconnectSignals();
NazaraSlot(WindowEventHandler, OnCreated, m_onCreated);
NazaraSlot(WindowEventHandler, OnDestruction, m_onDestruction);
NazaraSlot(WindowEventHandler, OnGainedFocus, m_onGainedFocus);
NazaraSlot(WindowEventHandler, OnLostFocus, m_onLostFocus);
NazaraSlot(WindowEventHandler, OnMinimized, m_onMinimized);
NazaraSlot(WindowEventHandler, OnResized, m_onResized);
NazaraSlot(WindowEventHandler, OnRestored, m_onRestored);
std::shared_ptr<RenderDevice> m_renderDevice;
std::shared_ptr<Swapchain> m_swapchain;
MovablePtr<Window> m_window;
SwapchainParameters m_parameters;
bool m_renderOnlyIfFocused;
bool m_hasFocus;
bool m_isMinimized;
};
}
#include <Nazara/Renderer/WindowSwapchain.inl>
#endif // NAZARA_RENDERER_RENDERWINDOW_HPP

View File

@@ -0,0 +1,76 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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/WindowSwapchain.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
inline WindowSwapchain::WindowSwapchain(WindowSwapchain&& windowSwapchain) noexcept :
m_renderDevice(std::move(windowSwapchain.m_renderDevice)),
m_swapchain(std::move(windowSwapchain.m_swapchain)),
m_window(std::move(windowSwapchain.m_window)),
m_renderOnlyIfFocused(windowSwapchain.m_renderOnlyIfFocused),
m_hasFocus(windowSwapchain.m_hasFocus),
m_isMinimized(windowSwapchain.m_isMinimized)
{
ConnectSignals();
}
inline RenderFrame WindowSwapchain::AcquireFrame()
{
if (m_isMinimized || (!m_hasFocus && m_renderOnlyIfFocused))
return RenderFrame{};
return m_swapchain->AcquireFrame();
}
inline bool WindowSwapchain::DoesRenderOnlyIfFocused() const
{
return m_renderOnlyIfFocused;
}
inline void WindowSwapchain::EnableRenderOnlyIfFocused(bool enable)
{
m_renderOnlyIfFocused = enable;
}
inline Swapchain& WindowSwapchain::GetSwapchain()
{
return *m_swapchain;
}
inline const Swapchain& WindowSwapchain::GetSwapchain() const
{
return *m_swapchain;
}
inline WindowSwapchain& WindowSwapchain::operator=(WindowSwapchain&& windowSwapchain) noexcept
{
windowSwapchain.DisconnectSignals();
m_renderDevice = std::move(windowSwapchain.m_renderDevice);
m_swapchain = std::move(windowSwapchain.m_swapchain);
m_window = std::move(windowSwapchain.m_window);
m_renderOnlyIfFocused = windowSwapchain.m_renderOnlyIfFocused;
m_hasFocus = windowSwapchain.m_hasFocus;
m_isMinimized = windowSwapchain.m_isMinimized;
ConnectSignals();
return *this;
}
void WindowSwapchain::DisconnectSignals()
{
m_onGainedFocus.Disconnect();
m_onLostFocus.Disconnect();
m_onMinimized.Disconnect();
m_onResized.Disconnect();
m_onRestored.Disconnect();
}
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -45,10 +45,9 @@
#include <Nazara/VulkanRenderer/VulkanRenderPass.hpp>
#include <Nazara/VulkanRenderer/VulkanRenderPipeline.hpp>
#include <Nazara/VulkanRenderer/VulkanRenderPipelineLayout.hpp>
#include <Nazara/VulkanRenderer/VulkanRenderWindow.hpp>
#include <Nazara/VulkanRenderer/VulkanShaderBinding.hpp>
#include <Nazara/VulkanRenderer/VulkanShaderModule.hpp>
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
#include <Nazara/VulkanRenderer/VulkanSwapchain.hpp>
#include <Nazara/VulkanRenderer/VulkanTexture.hpp>
#include <Nazara/VulkanRenderer/VulkanTextureFramebuffer.hpp>
#include <Nazara/VulkanRenderer/VulkanTextureSampler.hpp>

View File

@@ -35,6 +35,7 @@ namespace Nz
std::shared_ptr<RenderPipelineLayout> InstantiateRenderPipelineLayout(RenderPipelineLayoutInfo pipelineLayoutInfo) override;
std::shared_ptr<ShaderModule> InstantiateShaderModule(nzsl::ShaderStageTypeFlags stages, const nzsl::Ast::Module& shaderModule, const nzsl::ShaderWriter::States& states) override;
std::shared_ptr<ShaderModule> InstantiateShaderModule(nzsl::ShaderStageTypeFlags stages, ShaderLanguage lang, const void* source, std::size_t sourceSize, const nzsl::ShaderWriter::States& states) override;
std::shared_ptr<Swapchain> InstantiateSwapchain(WindowHandle windowHandle, const Vector2ui& windowSize, const SwapchainParameters& parameters) override;
std::shared_ptr<Texture> InstantiateTexture(const TextureInfo& params) override;
std::shared_ptr<TextureSampler> InstantiateTextureSampler(const TextureSamplerInfo& params) override;

View File

@@ -18,12 +18,12 @@
namespace Nz
{
class VulkanRenderWindow;
class VulkanSwapchain;
class NAZARA_VULKANRENDERER_API VulkanRenderImage : public RenderImage
{
public:
VulkanRenderImage(VulkanRenderWindow& owner);
VulkanRenderImage(VulkanSwapchain& owner);
VulkanRenderImage(const VulkanRenderImage&) = delete;
VulkanRenderImage(VulkanRenderImage&&) = delete;
~VulkanRenderImage();
@@ -50,7 +50,7 @@ namespace Nz
std::size_t m_currentCommandBuffer;
std::vector<Vk::AutoCommandBuffer> m_inFlightCommandBuffers;
std::vector<VkCommandBuffer> m_graphicalCommandsBuffers;
VulkanRenderWindow& m_owner;
VulkanSwapchain& m_owner;
Vk::CommandPool m_commandPool;
Vk::Fence m_inFlightFence;
Vk::Semaphore m_imageAvailableSemaphore;

View File

@@ -25,9 +25,6 @@ namespace Nz
VulkanRenderer() = default;
~VulkanRenderer();
std::unique_ptr<RenderSurface> CreateRenderSurfaceImpl() override;
std::unique_ptr<RenderWindowImpl> CreateRenderWindowImpl(RenderWindow& owner) override;
std::shared_ptr<RenderDevice> InstanciateRenderDevice(std::size_t deviceIndex, const RenderDeviceFeatures& enabledFeatures) override;
RenderAPI QueryAPI() const override;

View File

@@ -1,40 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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_VULKANSURFACE_HPP
#define NAZARA_VULKANRENDERER_VULKANSURFACE_HPP
#include <Nazara/Prerequisites.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
~VulkanSurface() = default;
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_VULKANSURFACE_HPP

View File

@@ -1,16 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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>

View File

@@ -12,8 +12,9 @@
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/RenderWindowImpl.hpp>
#include <Nazara/Renderer/Swapchain.hpp>
#include <Nazara/Renderer/RendererImpl.hpp>
#include <Nazara/Renderer/SwapchainParameters.hpp>
#include <Nazara/VulkanRenderer/Config.hpp>
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
#include <Nazara/VulkanRenderer/VulkanRenderImage.hpp>
@@ -33,17 +34,15 @@
namespace Nz
{
class NAZARA_VULKANRENDERER_API VulkanRenderWindow : public RenderWindowImpl
class NAZARA_VULKANRENDERER_API VulkanSwapchain : public Swapchain
{
public:
VulkanRenderWindow(RenderWindow& owner);
VulkanRenderWindow(const VulkanRenderWindow&) = delete;
VulkanRenderWindow(VulkanRenderWindow&&) = delete; ///TODO
~VulkanRenderWindow();
VulkanSwapchain(VulkanDevice& device, WindowHandle windowHandle, const Vector2ui& windowSize, const SwapchainParameters& parameters);
VulkanSwapchain(const VulkanSwapchain&) = delete;
VulkanSwapchain(VulkanSwapchain&&) = delete;
~VulkanSwapchain();
RenderFrame Acquire() override;
bool Create(RendererImpl* renderer, RenderSurface* surface, const RenderWindowParameters& parameters) override;
RenderFrame AcquireFrame() override;
std::shared_ptr<CommandPool> CreateCommandPool(QueueType queueType) override;
@@ -56,20 +55,22 @@ namespace Nz
const Vector2ui& GetSize() const override;
inline const Vk::Swapchain& GetSwapchain() const;
void NotifyResize(const Vector2ui& newSize) override;
void Present(UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE);
VulkanRenderWindow& operator=(const VulkanRenderWindow&) = delete;
VulkanRenderWindow& operator=(VulkanRenderWindow&&) = delete; ///TODO
VulkanSwapchain& operator=(const VulkanSwapchain&) = delete;
VulkanSwapchain& operator=(VulkanSwapchain&&) = delete;
private:
bool CreateSwapchain(Vk::Surface& surface, const Vector2ui& size);
bool SetupDepthBuffer(const Vector2ui& size);
bool SetupFrameBuffers(const Vector2ui& size);
bool CreateSwapchain();
bool SetupDepthBuffer();
bool SetupFrameBuffers();
bool SetupRenderPass();
bool SetupSwapchain(const Vk::PhysicalDevice& deviceInfo, Vk::Surface& surface, const Vector2ui& size);
bool SetupSurface(WindowHandle windowHandle);
bool SetupSwapchain(const Vk::PhysicalDevice& deviceInfo);
std::optional<VulkanRenderPass> m_renderPass;
std::shared_ptr<VulkanDevice> m_device;
std::size_t m_currentFrame;
std::vector<VulkanWindowFramebuffer> m_framebuffers;
std::vector<Vk::Fence*> m_inflightFences;
@@ -80,15 +81,16 @@ namespace Nz
Vk::QueueHandle m_graphicsQueue;
Vk::QueueHandle m_presentQueue;
Vk::QueueHandle m_transferQueue;
Vk::Surface m_surface;
Vk::Swapchain m_swapchain;
RenderWindow& m_owner;
Vector2ui m_swapchainSize;
VkFormat m_depthStencilFormat;
VkSurfaceFormatKHR m_surfaceFormat;
VulkanDevice& m_device;
bool m_shouldRecreateSwapchain;
};
}
#include <Nazara/VulkanRenderer/VulkanRenderWindow.inl>
#include <Nazara/VulkanRenderer/VulkanSwapchain.inl>
#endif // NAZARA_VULKANRENDERER_VULKANRENDERWINDOW_HPP

View File

@@ -2,27 +2,27 @@
// 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/VulkanRenderWindow.hpp>
#include <Nazara/VulkanRenderer/VulkanSwapchain.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
{
inline VulkanDevice& VulkanRenderWindow::GetDevice()
inline VulkanDevice& VulkanSwapchain::GetDevice()
{
return *m_device;
return m_device;
}
inline const VulkanDevice& VulkanRenderWindow::GetDevice() const
inline const VulkanDevice& VulkanSwapchain::GetDevice() const
{
return *m_device;
return m_device;
}
inline Vk::QueueHandle& VulkanRenderWindow::GetGraphicsQueue()
inline Vk::QueueHandle& VulkanSwapchain::GetGraphicsQueue()
{
return m_graphicsQueue;
}
inline const Vk::Swapchain& VulkanRenderWindow::GetSwapchain() const
inline const Vk::Swapchain& VulkanSwapchain::GetSwapchain() const
{
return m_swapchain;
}

View File

@@ -17,78 +17,75 @@
#include <vulkan/vulkan_metal.h>
#endif
namespace Nz
namespace Nz::Vk
{
namespace Vk
class Surface
{
class Surface
{
public:
inline Surface(Instance& instance);
Surface(const Surface&) = delete;
Surface(Surface&& surface);
inline ~Surface();
public:
inline Surface(Instance& instance);
Surface(const Surface&) = delete;
Surface(Surface&& surface) noexcept;
inline ~Surface();
#ifdef VK_USE_PLATFORM_ANDROID_KHR
// VK_KHR_android_surface
inline bool Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_ANDROID_KHR
// VK_KHR_android_surface
inline bool Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
// VK_KHR_xcb_surface
inline bool Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
// VK_KHR_xcb_surface
inline bool Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_XLIB_KHR
// VK_KHR_xlib_surface
inline bool Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_XLIB_KHR
// VK_KHR_xlib_surface
inline bool Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
// VK_KHR_wayland_surface
inline bool Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
// VK_KHR_wayland_surface
inline bool Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_WIN32_KHR
// VK_KHR_win32_surface
inline bool Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_WIN32_KHR
// VK_KHR_win32_surface
inline bool Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_METAL_EXT
inline bool Create(const VkMetalSurfaceCreateInfoEXT& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(id layer, const VkAllocationCallbacks* allocator = nullptr);
#endif
#ifdef VK_USE_PLATFORM_METAL_EXT
inline bool Create(const VkMetalSurfaceCreateInfoEXT& createInfo, const VkAllocationCallbacks* allocator = nullptr);
inline bool Create(id layer, const VkAllocationCallbacks* allocator = nullptr);
#endif
inline void Destroy();
inline void Destroy();
bool GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const;
bool GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const;
bool GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const;
bool GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const;
bool GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const;
bool GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const;
bool GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const;
bool GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const;
inline VkResult GetLastErrorCode() const;
inline VkResult GetLastErrorCode() const;
Surface& operator=(const Surface&) = delete;
Surface& operator=(Surface&&) = delete;
Surface& operator=(const Surface&) = delete;
Surface& operator=(Surface&&) = delete;
inline operator VkSurfaceKHR() const;
inline operator VkSurfaceKHR() const;
static inline bool IsSupported(const Instance& instance);
static inline bool IsSupported(const Instance& instance);
private:
inline bool Create(const VkAllocationCallbacks* allocator);
private:
inline bool Create(const VkAllocationCallbacks* allocator);
Instance& m_instance;
VkAllocationCallbacks m_allocator;
VkSurfaceKHR m_surface;
mutable VkResult m_lastErrorCode;
};
}
Instance& m_instance;
VkAllocationCallbacks m_allocator;
VkSurfaceKHR m_surface;
mutable VkResult m_lastErrorCode;
};
}
#include <Nazara/VulkanRenderer/Wrapper/Surface.inl>

View File

@@ -7,305 +7,302 @@
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
namespace Nz::Vk
{
namespace Vk
inline Surface::Surface(Instance& instance) :
m_instance(instance),
m_surface(VK_NULL_HANDLE)
{
inline Surface::Surface(Instance& instance) :
m_instance(instance),
m_surface(VK_NULL_HANDLE)
}
inline Surface::Surface(Surface&& surface) noexcept :
m_instance(surface.m_instance),
m_allocator(surface.m_allocator),
m_surface(surface.m_surface),
m_lastErrorCode(surface.m_lastErrorCode)
{
surface.m_surface = VK_NULL_HANDLE;
}
inline Surface::~Surface()
{
Destroy();
}
#ifdef VK_USE_PLATFORM_ANDROID_KHR
inline bool Surface::Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateAndroidSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
{
VkAndroidSurfaceCreateInfoKHR createInfo =
{
}
VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
window
};
inline Surface::Surface(Surface&& surface) :
m_instance(surface.m_instance),
m_allocator(surface.m_allocator),
m_surface(surface.m_surface),
m_lastErrorCode(surface.m_lastErrorCode)
return Create(createInfo, allocator);
}
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
inline bool Surface::Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateXcbSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
{
VkXcbSurfaceCreateInfoKHR createInfo =
{
surface.m_surface = VK_NULL_HANDLE;
}
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
connection,
window
};
inline Surface::~Surface()
return Create(createInfo, allocator);
}
#endif
#ifdef VK_USE_PLATFORM_XLIB_KHR
inline bool Surface::Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateXlibSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
{
VkXlibSurfaceCreateInfoKHR createInfo =
{
Destroy();
}
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
display,
window
};
#ifdef VK_USE_PLATFORM_ANDROID_KHR
inline bool Surface::Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
return Create(createInfo, allocator);
}
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
inline bool Surface::Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateWaylandSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
{
VkWaylandSurfaceCreateInfoKHR createInfo =
{
m_lastErrorCode = m_instance.vkCreateAndroidSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
display,
surface
};
inline bool Surface::Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
return Create(createInfo, allocator);
}
#endif
#ifdef VK_USE_PLATFORM_WIN32_KHR
inline bool Surface::Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateWin32SurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
{
VkWin32SurfaceCreateInfoKHR createInfo =
{
VkAndroidSurfaceCreateInfoKHR createInfo =
{
VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
window
};
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
instance,
handle
};
return Create(createInfo, allocator);
}
#endif
return Create(createInfo, allocator);
}
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
inline bool Surface::Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
#ifdef VK_USE_PLATFORM_METAL_EXT
inline bool Surface::Create(const VkMetalSurfaceCreateInfoEXT& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateMetalSurfaceEXT(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(id layer, const VkAllocationCallbacks* allocator)
{
VkMetalSurfaceCreateInfoEXT createInfo =
{
m_lastErrorCode = m_instance.vkCreateXcbSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT,
nullptr,
0,
layer
};
inline bool Surface::Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
return Create(createInfo, allocator);
}
#endif
inline void Surface::Destroy()
{
if (m_surface != VK_NULL_HANDLE)
{
VkXcbSurfaceCreateInfoKHR createInfo =
{
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
connection,
window
};
return Create(createInfo, allocator);
}
#endif
#ifdef VK_USE_PLATFORM_XLIB_KHR
inline bool Surface::Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateXlibSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
{
VkXlibSurfaceCreateInfoKHR createInfo =
{
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
display,
window
};
return Create(createInfo, allocator);
}
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
inline bool Surface::Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateWaylandSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
{
VkWaylandSurfaceCreateInfoKHR createInfo =
{
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
display,
surface
};
return Create(createInfo, allocator);
}
#endif
#ifdef VK_USE_PLATFORM_WIN32_KHR
inline bool Surface::Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateWin32SurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
{
VkWin32SurfaceCreateInfoKHR createInfo =
{
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
nullptr,
flags,
instance,
handle
};
return Create(createInfo, allocator);
}
#endif
#ifdef VK_USE_PLATFORM_METAL_EXT
inline bool Surface::Create(const VkMetalSurfaceCreateInfoEXT& createInfo, const VkAllocationCallbacks* allocator)
{
m_lastErrorCode = m_instance.vkCreateMetalSurfaceEXT(m_instance, &createInfo, allocator, &m_surface);
return Create(allocator);
}
inline bool Surface::Create(id layer, const VkAllocationCallbacks* allocator)
{
VkMetalSurfaceCreateInfoEXT createInfo =
{
VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT,
nullptr,
0,
layer
};
return Create(createInfo, allocator);
}
#endif
inline void Surface::Destroy()
{
if (m_surface != VK_NULL_HANDLE)
{
m_instance.vkDestroySurfaceKHR(m_instance, m_surface, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
m_surface = VK_NULL_HANDLE;
}
m_instance.vkDestroySurfaceKHR(m_instance, m_surface, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
m_surface = VK_NULL_HANDLE;
}
}
inline VkResult Surface::GetLastErrorCode() const
inline VkResult Surface::GetLastErrorCode() const
{
return m_lastErrorCode;
}
inline bool Surface::GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const
{
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, surfaceCapabilities);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
return m_lastErrorCode;
}
inline bool Surface::GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const
{
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, surfaceCapabilities);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query surface capabilities: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
return true;
}
inline bool Surface::GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const
{
// First, query format count
UInt32 surfaceCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS || surfaceCount == 0)
{
NazaraError("Failed to query format count: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
// Now we can get the list of the available physical device
surfaceFormats->resize(surfaceCount);
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, surfaceFormats->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query formats: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
return true;
}
inline bool Surface::GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const
{
// First, query present modes count
UInt32 presentModeCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS || presentModeCount == 0)
{
NazaraError("Failed to query present mode count");
return false;
}
// Now we can get the list of the available physical device
presentModes->resize(presentModeCount);
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, presentModes->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query present modes: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
return true;
}
inline bool Surface::GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const
{
VkBool32 presentationSupported = VK_FALSE;
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, m_surface, &presentationSupported);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query surface capabilities: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
*supported = (presentationSupported == VK_TRUE);
return true;
}
inline Surface::operator VkSurfaceKHR() const
{
return m_surface;
}
inline bool Surface::IsSupported(const Instance& instance)
{
if (!instance.IsExtensionLoaded(VK_KHR_SURFACE_EXTENSION_NAME))
return false;
#ifdef VK_USE_PLATFORM_ANDROID_KHR
if (instance.IsExtensionLoaded(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
if (instance.IsExtensionLoaded(VK_KHR_XCB_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_XLIB_KHR
if (instance.IsExtensionLoaded(VK_KHR_XLIB_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
if (instance.IsExtensionLoaded(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_WIN32_KHR
if (instance.IsExtensionLoaded(VK_KHR_WIN32_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_METAL_EXT
if (instance.IsExtensionLoaded(VK_EXT_METAL_SURFACE_EXTENSION_NAME))
return true;
#endif
NazaraError("Failed to query surface capabilities: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
inline bool Surface::Create(const VkAllocationCallbacks* allocator)
return true;
}
inline bool Surface::GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const
{
// First, query format count
UInt32 surfaceCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS || surfaceCount == 0)
{
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan surface: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
// Store the allocator to access them when needed
if (allocator)
m_allocator = *allocator;
else
m_allocator.pfnAllocation = nullptr;
return true;
NazaraError("Failed to query format count: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
// Now we can get the list of the available physical device
surfaceFormats->resize(surfaceCount);
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, surfaceFormats->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query formats: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
return true;
}
inline bool Surface::GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const
{
// First, query present modes count
UInt32 presentModeCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, nullptr);
if (m_lastErrorCode != VkResult::VK_SUCCESS || presentModeCount == 0)
{
NazaraError("Failed to query present mode count");
return false;
}
// Now we can get the list of the available physical device
presentModes->resize(presentModeCount);
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, presentModes->data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query present modes: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
return true;
}
inline bool Surface::GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const
{
VkBool32 presentationSupported = VK_FALSE;
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, m_surface, &presentationSupported);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to query surface capabilities: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
*supported = (presentationSupported == VK_TRUE);
return true;
}
inline Surface::operator VkSurfaceKHR() const
{
return m_surface;
}
inline bool Surface::IsSupported(const Instance& instance)
{
if (!instance.IsExtensionLoaded(VK_KHR_SURFACE_EXTENSION_NAME))
return false;
#ifdef VK_USE_PLATFORM_ANDROID_KHR
if (instance.IsExtensionLoaded(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
if (instance.IsExtensionLoaded(VK_KHR_XCB_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_XLIB_KHR
if (instance.IsExtensionLoaded(VK_KHR_XLIB_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
if (instance.IsExtensionLoaded(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_WIN32_KHR
if (instance.IsExtensionLoaded(VK_KHR_WIN32_SURFACE_EXTENSION_NAME))
return true;
#endif
#ifdef VK_USE_PLATFORM_METAL_EXT
if (instance.IsExtensionLoaded(VK_EXT_METAL_SURFACE_EXTENSION_NAME))
return true;
#endif
return false;
}
inline bool Surface::Create(const VkAllocationCallbacks* allocator)
{
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to create Vulkan surface: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
// Store the allocator to access them when needed
if (allocator)
m_allocator = *allocator;
else
m_allocator.pfnAllocation = nullptr;
return true;
}
}

View File

@@ -8,7 +8,7 @@
#define NAZARA_WIDGETS_BASEWIDGET_HPP
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Platform/Event.hpp>
#include <Nazara/Platform/WindowEvent.hpp>
#include <Nazara/Platform/Mouse.hpp>
#include <Nazara/Utility/Node.hpp>
#include <Nazara/Widgets/Config.hpp>

View File

@@ -8,7 +8,7 @@
#define NAZARA_WIDGETS_CANVAS_HPP
#include <Nazara/Platform/CursorController.hpp>
#include <Nazara/Platform/EventHandler.hpp>
#include <Nazara/Platform/WindowEventHandler.hpp>
#include <Nazara/Widgets/BaseWidget.hpp>
#include <entt/entity/registry.hpp>
#include <bitset>
@@ -20,7 +20,7 @@ namespace Nz
friend BaseWidget;
public:
Canvas(entt::registry& registry, EventHandler& eventHandler, CursorControllerHandle cursorController, UInt32 renderMask, int initialRenderLayer = 0);
Canvas(entt::registry& registry, WindowEventHandler& eventHandler, CursorControllerHandle cursorController, UInt32 renderMask, int initialRenderLayer = 0);
Canvas(const Canvas&) = delete;
Canvas(Canvas&&) = delete;
inline ~Canvas();
@@ -32,8 +32,8 @@ namespace Nz
Canvas& operator=(const Canvas&) = delete;
Canvas& operator=(Canvas&&) = delete;
NazaraSignal(OnUnhandledKeyPressed, const EventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnUnhandledKeyReleased, const EventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnUnhandledKeyPressed, const WindowEventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnUnhandledKeyReleased, const WindowEventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
protected:
inline void ClearKeyboardOwner(std::size_t canvasIndex);
@@ -57,17 +57,17 @@ namespace Nz
private:
template<typename F> void DispatchEvent(std::size_t widgetIndex, F&& functor);
void OnEventMouseButtonPressed(const EventHandler* eventHandler, const WindowEvent::MouseButtonEvent& event);
void OnEventMouseButtonRelease(const EventHandler* eventHandler, const WindowEvent::MouseButtonEvent& event);
void OnEventMouseEntered(const EventHandler* eventHandler);
void OnEventMouseLeft(const EventHandler* eventHandler);
void OnEventMouseMoved(const EventHandler* eventHandler, const WindowEvent::MouseMoveEvent& event);
void OnEventMouseButtonPressed(const WindowEventHandler* eventHandler, const WindowEvent::MouseButtonEvent& event);
void OnEventMouseButtonRelease(const WindowEventHandler* eventHandler, const WindowEvent::MouseButtonEvent& event);
void OnEventMouseEntered(const WindowEventHandler* eventHandler);
void OnEventMouseLeft(const WindowEventHandler* eventHandler);
void OnEventMouseMoved(const WindowEventHandler* eventHandler, const WindowEvent::MouseMoveEvent& event);
void OnEventMouseWheelMoved(const EventHandler* eventHandler, const WindowEvent::MouseWheelEvent& event);
void OnEventKeyPressed(const EventHandler* eventHandler, const WindowEvent::KeyEvent& event);
void OnEventKeyReleased(const EventHandler* eventHandler, const WindowEvent::KeyEvent& event);
void OnEventTextEntered(const EventHandler* eventHandler, const WindowEvent::TextEvent& event);
void OnEventTextEdited(const EventHandler* eventHandler, const WindowEvent::EditEvent& event);
void OnEventMouseWheelMoved(const WindowEventHandler* eventHandler, const WindowEvent::MouseWheelEvent& event);
void OnEventKeyPressed(const WindowEventHandler* eventHandler, const WindowEvent::KeyEvent& event);
void OnEventKeyReleased(const WindowEventHandler* eventHandler, const WindowEvent::KeyEvent& event);
void OnEventTextEntered(const WindowEventHandler* eventHandler, const WindowEvent::TextEvent& event);
void OnEventTextEdited(const WindowEventHandler* eventHandler, const WindowEvent::EditEvent& event);
void UpdateHoveredWidget(int x, int y);
@@ -78,16 +78,16 @@ namespace Nz
SystemCursor cursor;
};
NazaraSlot(EventHandler, OnKeyPressed, m_keyPressedSlot);
NazaraSlot(EventHandler, OnKeyReleased, m_keyReleasedSlot);
NazaraSlot(EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot);
NazaraSlot(EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
NazaraSlot(EventHandler, OnMouseEntered, m_mouseEnteredSlot);
NazaraSlot(EventHandler, OnMouseLeft, m_mouseLeftSlot);
NazaraSlot(EventHandler, OnMouseMoved, m_mouseMovedSlot);
NazaraSlot(EventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot);
NazaraSlot(EventHandler, OnTextEntered, m_textEnteredSlot);
NazaraSlot(EventHandler, OnTextEdited, m_textEditedSlot);
NazaraSlot(WindowEventHandler, OnKeyPressed, m_keyPressedSlot);
NazaraSlot(WindowEventHandler, OnKeyReleased, m_keyReleasedSlot);
NazaraSlot(WindowEventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot);
NazaraSlot(WindowEventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
NazaraSlot(WindowEventHandler, OnMouseEntered, m_mouseEnteredSlot);
NazaraSlot(WindowEventHandler, OnMouseLeft, m_mouseLeftSlot);
NazaraSlot(WindowEventHandler, OnMouseMoved, m_mouseMovedSlot);
NazaraSlot(WindowEventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot);
NazaraSlot(WindowEventHandler, OnTextEntered, m_textEnteredSlot);
NazaraSlot(WindowEventHandler, OnTextEdited, m_textEditedSlot);
CursorControllerHandle m_cursorController;
UInt32 m_renderMask;