From e0e7435c5541aeafc9f5ac348115d652132da308 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 27 May 2020 20:03:46 +0200 Subject: [PATCH] Merge fixes --- examples/VulkanTest/main.cpp | 14 +++---- include/Nazara/Renderer/RenderWindow.hpp | 4 +- include/Nazara/Renderer/RenderWindow.inl | 4 +- src/Nazara/OpenGLRenderer/DummySurface.cpp | 2 +- .../Wrapper/Win32/WGLContext.cpp | 13 ++++++- src/Nazara/Platform/SDL2/CursorImpl.cpp | 2 +- src/Nazara/Platform/SDL2/IconImpl.cpp | 2 +- src/Nazara/Platform/SDL2/WindowImpl.cpp | 3 -- src/Nazara/Renderer/RenderWindow.cpp | 39 +++++++++---------- src/Nazara/Renderer/Renderer.cpp | 1 + src/Nazara/VulkanRenderer/VulkanSurface.cpp | 4 +- 11 files changed, 48 insertions(+), 40 deletions(-) diff --git a/examples/VulkanTest/main.cpp b/examples/VulkanTest/main.cpp index c777a65b2..bfda1e2b2 100644 --- a/examples/VulkanTest/main.cpp +++ b/examples/VulkanTest/main.cpp @@ -3,7 +3,7 @@ #include #include -#define SPIRV 0 +#define SPIRV 1 int main() { @@ -266,27 +266,27 @@ int main() float cameraSpeed = 2.f * updateClock.GetSeconds(); updateClock.Restart(); - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Z)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Z)) viewerPos += camQuat * Nz::Vector3f::Forward() * cameraSpeed; // Si la flèche du bas ou la touche S est pressée, on recule - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Down) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::S)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Down) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::S)) viewerPos += camQuat * Nz::Vector3f::Backward() * cameraSpeed; // Etc... - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Left) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Q)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Left) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Q)) viewerPos += camQuat * Nz::Vector3f::Left() * cameraSpeed; // Etc... - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Right) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::D)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Right) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::D)) viewerPos += camQuat * Nz::Vector3f::Right() * cameraSpeed; // Majuscule pour monter, notez l'utilisation d'une direction globale (Non-affectée par la rotation) - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::RShift)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RShift)) viewerPos += Nz::Vector3f::Up() * cameraSpeed; // Contrôle (Gauche ou droite) pour descendre dans l'espace global, etc... - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::LControl) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::RControl)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LControl) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RControl)) viewerPos += Nz::Vector3f::Down() * cameraSpeed; } diff --git a/include/Nazara/Renderer/RenderWindow.hpp b/include/Nazara/Renderer/RenderWindow.hpp index c7ce97ffd..0d3521a00 100644 --- a/include/Nazara/Renderer/RenderWindow.hpp +++ b/include/Nazara/Renderer/RenderWindow.hpp @@ -26,11 +26,11 @@ namespace Nz public: inline RenderWindow(); inline RenderWindow(VideoMode mode, const String &title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters ¶meters = RenderWindowParameters()); - inline explicit RenderWindow(void *handle, const RenderWindowParameters ¶meters = RenderWindowParameters()); + inline explicit RenderWindow(void* handle, const RenderWindowParameters ¶meters = RenderWindowParameters()); inline ~RenderWindow(); inline bool Create(VideoMode mode, const String &title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters ¶meters = RenderWindowParameters()); - inline bool Create(void *handle, const RenderWindowParameters ¶meters = RenderWindowParameters()); + inline bool Create(void* handle, const RenderWindowParameters ¶meters = RenderWindowParameters()); void Display(); diff --git a/include/Nazara/Renderer/RenderWindow.inl b/include/Nazara/Renderer/RenderWindow.inl index 7b926ce55..6b868a3b6 100644 --- a/include/Nazara/Renderer/RenderWindow.inl +++ b/include/Nazara/Renderer/RenderWindow.inl @@ -20,7 +20,7 @@ namespace Nz Create(mode, title, style, parameters); } - inline RenderWindow::RenderWindow(WindowHandle handle, const RenderWindowParameters& parameters) + inline RenderWindow::RenderWindow(void* handle, const RenderWindowParameters& parameters) { ErrorFlags errFlags(ErrorFlag_ThrowException, true); @@ -39,7 +39,7 @@ namespace Nz return Window::Create(mode, title, style); } - inline bool RenderWindow::Create(WindowHandle handle, const RenderWindowParameters& parameters) + inline bool RenderWindow::Create(void* handle, const RenderWindowParameters& parameters) { m_parameters = parameters; diff --git a/src/Nazara/OpenGLRenderer/DummySurface.cpp b/src/Nazara/OpenGLRenderer/DummySurface.cpp index ec74f480e..b35e1a6d7 100644 --- a/src/Nazara/OpenGLRenderer/DummySurface.cpp +++ b/src/Nazara/OpenGLRenderer/DummySurface.cpp @@ -15,6 +15,6 @@ namespace Nz void DummySurface::Destroy() { - m_handle = nullptr; + m_handle = WindowHandle{}; } } diff --git a/src/Nazara/OpenGLRenderer/Wrapper/Win32/WGLContext.cpp b/src/Nazara/OpenGLRenderer/Wrapper/Win32/WGLContext.cpp index 1593cef1c..c5faa2bfa 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/Win32/WGLContext.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/Win32/WGLContext.cpp @@ -29,12 +29,21 @@ namespace Nz::GL ::ShowWindow(m_window.get(), FALSE); - return Create(baseContext, params, m_window.get(), shareContext); + m_deviceContext = ::GetDC(m_window.get()); + if (!m_deviceContext) + { + NazaraError("failed to retrieve dummy window device context: " + Error::GetLastSystemError()); + return false; + } + + return CreateInternal(baseContext, params, shareContext); } bool WGLContext::Create(const WGLContext* baseContext, const ContextParams& params, WindowHandle window, const WGLContext* shareContext) { - m_deviceContext = ::GetDC(static_cast(window)); + NazaraAssert(window.type == WindowManager::Windows, "expected Windows window"); + + m_deviceContext = ::GetDC(static_cast(window.windows.window)); if (!m_deviceContext) { NazaraError("failed to retrieve window device context: " + Error::GetLastSystemError()); diff --git a/src/Nazara/Platform/SDL2/CursorImpl.cpp b/src/Nazara/Platform/SDL2/CursorImpl.cpp index c9497a2e8..60ddd4bd4 100644 --- a/src/Nazara/Platform/SDL2/CursorImpl.cpp +++ b/src/Nazara/Platform/SDL2/CursorImpl.cpp @@ -13,7 +13,7 @@ namespace Nz bool CursorImpl::Create(const Image& cursor, int hotSpotX, int hotSpotY) { m_iconImage = cursor; - if (!m_iconImage.Convert(PixelFormatType_BGRA8)) + if (!m_iconImage.Convert(PixelFormat_BGRA8)) { NazaraError("Failed to convert icon to BGRA8"); return false; diff --git a/src/Nazara/Platform/SDL2/IconImpl.cpp b/src/Nazara/Platform/SDL2/IconImpl.cpp index b802b1176..50d1dff42 100644 --- a/src/Nazara/Platform/SDL2/IconImpl.cpp +++ b/src/Nazara/Platform/SDL2/IconImpl.cpp @@ -12,7 +12,7 @@ namespace Nz bool IconImpl::Create(const Image& icon) { m_iconImage = icon; - if (!m_iconImage.Convert(PixelFormatType_BGRA8)) + if (!m_iconImage.Convert(PixelFormat_BGRA8)) { NazaraError("Failed to convert icon to BGRA8"); return false; diff --git a/src/Nazara/Platform/SDL2/WindowImpl.cpp b/src/Nazara/Platform/SDL2/WindowImpl.cpp index acbbc8382..20cd731df 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.cpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.cpp @@ -4,11 +4,8 @@ #include #include -#include #include #include -#include -#include #include #include #include diff --git a/src/Nazara/Renderer/RenderWindow.cpp b/src/Nazara/Renderer/RenderWindow.cpp index 03b475804..a03cf295c 100644 --- a/src/Nazara/Renderer/RenderWindow.cpp +++ b/src/Nazara/Renderer/RenderWindow.cpp @@ -40,7 +40,7 @@ namespace Nz { RendererImpl *rendererImpl = Renderer::GetRendererImpl(); auto surface = rendererImpl->CreateRenderSurfaceImpl(); - if (!surface->Create(GetHandle())) + if (!surface->Create(GetSystemHandle())) { NazaraError("Failed to create render surface: " + Error::GetLastError()); return false; @@ -49,26 +49,25 @@ namespace Nz auto impl = rendererImpl->CreateRenderWindowImpl(); if (!impl->Create(rendererImpl, surface.get(), GetSize(), m_parameters)) { - { - NazaraError("Failed to create render window implementation: " + Error::GetLastError()); - return false; - } - - m_impl = std::move(impl); - m_surface = std::move(surface); - - m_clock.Restart(); - - return true; + NazaraError("Failed to create render window implementation: " + Error::GetLastError()); + return false; } - void RenderWindow::OnWindowDestroy() - { - m_impl.reset(); - m_surface.reset(); - } + m_impl = std::move(impl); + m_surface = std::move(surface); - void RenderWindow::OnWindowResized() - { - } + m_clock.Restart(); + + return true; } + + void RenderWindow::OnWindowDestroy() + { + m_impl.reset(); + m_surface.reset(); + } + + void RenderWindow::OnWindowResized() + { + } +} diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 477a340f3..6954f5cf0 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -110,6 +110,7 @@ namespace Nz chosenImpl = std::move(impl); //< Move (and delete previous) implementation before unloading library chosenLib = std::move(implLib); + break; } if (!chosenImpl) diff --git a/src/Nazara/VulkanRenderer/VulkanSurface.cpp b/src/Nazara/VulkanRenderer/VulkanSurface.cpp index fbb9e0ff7..a114b12ca 100644 --- a/src/Nazara/VulkanRenderer/VulkanSurface.cpp +++ b/src/Nazara/VulkanRenderer/VulkanSurface.cpp @@ -18,7 +18,9 @@ namespace Nz bool success = false; #if defined(NAZARA_PLATFORM_WINDOWS) { - HWND winHandle = reinterpret_cast(handle); + NazaraAssert(handle.type == WindowManager::Windows, "expected Windows window"); + + HWND winHandle = reinterpret_cast(handle.windows.window); HINSTANCE instance = reinterpret_cast(GetWindowLongPtrW(winHandle, GWLP_HINSTANCE)); success = m_surface.Create(instance, winHandle);