From d688cecbdeb373f6c98b7b74c56ff3aedce5fcee Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 28 Oct 2017 23:26:22 +0200 Subject: [PATCH] Renderer: Replaced RenderTarget::Get[Height|Width] by RenderTarget::GetSize Utility: Removed Window::Get[Height|Width] methods --- ChangeLog.md | 2 ++ .../NDK/Components/CameraComponent.inl | 5 ++-- SDK/src/NDK/Application.cpp | 8 ++++-- SDK/src/NDK/Components/CameraComponent.cpp | 12 ++++----- examples/FirstScene/main.cpp | 3 ++- examples/Particles/LogoDemo.cpp | 11 ++++---- examples/Particles/SpacebattleDemo.cpp | 3 ++- examples/Particles/main.cpp | 5 ++-- examples/Tut01/main.cpp | 3 ++- include/Nazara/Platform/Window.hpp | 2 -- include/Nazara/Renderer/RenderTarget.hpp | 4 +-- include/Nazara/Renderer/RenderTexture.hpp | 2 -- include/Nazara/Renderer/RenderWindow.hpp | 3 +-- src/Nazara/Platform/Win32/WindowImpl.cpp | 10 ------- src/Nazara/Platform/Win32/WindowImpl.hpp | 2 -- src/Nazara/Platform/Window.cpp | 26 ------------------- src/Nazara/Renderer/OpenGL.cpp | 8 +++--- src/Nazara/Renderer/RenderTexture.cpp | 26 +++---------------- src/Nazara/Renderer/RenderWindow.cpp | 9 ++----- src/Nazara/Renderer/Renderer.cpp | 2 +- 20 files changed, 44 insertions(+), 102 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 55662f1b5..ad22e30a9 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,8 @@ Nazara Engine: - VertexMapper:GetComponentPtr no longer throw an error if component is disabled or incompatible with template type, instead a null pointer is returned. - Bitset swap operation is now correctly marked as noexcept` - Mesh loaders now takes MeshParams vertexDeclaration into account +- ⚠️ Replaced RenderTarget::Get[Height|Width] by RenderTarget::GetSize +- ⚠️ Removed Window::Get[Height|Width] methods # 0.4: diff --git a/SDK/include/NDK/Components/CameraComponent.inl b/SDK/include/NDK/Components/CameraComponent.inl index 14e76176a..7d624f522 100644 --- a/SDK/include/NDK/Components/CameraComponent.inl +++ b/SDK/include/NDK/Components/CameraComponent.inl @@ -237,10 +237,9 @@ namespace Ndk NazaraAssert(m_target, "Component has no render target"); // We compute the region necessary to make this view port with the actual size of the target - float invWidth = 1.f / m_target->GetWidth(); - float invHeight = 1.f / m_target->GetHeight(); + Nz::Vector2f invSize = 1.f / Nz::Vector2f(m_target->GetSize()); - SetTargetRegion(Nz::Rectf(invWidth * viewport.x, invHeight * viewport.y, invWidth * viewport.width, invHeight * viewport.height)); + SetTargetRegion(Nz::Rectf(invSize.x * viewport.x, invSize.y * viewport.y, invSize.x * viewport.width, invSize.y * viewport.height)); } /*! diff --git a/SDK/src/NDK/Application.cpp b/SDK/src/NDK/Application.cpp index 67040db69..e9b866d4e 100644 --- a/SDK/src/NDK/Application.cpp +++ b/SDK/src/NDK/Application.cpp @@ -148,7 +148,10 @@ namespace Ndk Nz::Vector2ui windowDimensions; if (info.window->IsValid()) - windowDimensions.Set(info.window->GetWidth(), info.window->GetHeight() / 4); + { + windowDimensions = info.window->GetSize(); + windowDimensions.y /= 4; + } else windowDimensions.MakeZero(); @@ -212,7 +215,8 @@ namespace Ndk overlay->resizedSlot.Connect(info.renderTarget->OnRenderTargetSizeChange, [&consoleRef] (const Nz::RenderTarget* renderTarget) { - consoleRef.SetSize({float(renderTarget->GetWidth()), renderTarget->GetHeight() / 4.f}); + Nz::Vector2ui size = renderTarget->GetSize(); + consoleRef.SetSize({float(size.x), size.y / 4.f}); }); info.console = std::move(overlay); diff --git a/SDK/src/NDK/Components/CameraComponent.cpp b/SDK/src/NDK/Components/CameraComponent.cpp index 2441dd7a8..58523bcea 100644 --- a/SDK/src/NDK/Components/CameraComponent.cpp +++ b/SDK/src/NDK/Components/CameraComponent.cpp @@ -334,15 +334,15 @@ namespace Ndk { NazaraAssert(m_target, "CameraComponent has no target"); - unsigned int targetWidth = m_target->GetWidth(); - unsigned int targetHeight = std::max(m_target->GetHeight(), 1U); // Let's make sure we won't divide by zero + Nz::Vector2ui targetSize = m_target->GetSize(); + targetSize.y = std::max(targetSize.y, 1U); // Let's make sure we won't divide by zero // Our target region is expressed as % of the viewport dimensions, let's compute it in pixels Nz::Rectf fViewport(m_targetRegion); - fViewport.x *= targetWidth; - fViewport.y *= targetHeight; - fViewport.width *= targetWidth; - fViewport.height *= targetHeight; + fViewport.x *= targetSize.x; + fViewport.y *= targetSize.y; + fViewport.width *= targetSize.x; + fViewport.height *= targetSize.y; // Compute the new aspect ratio, if it's different we need to invalidate the projection matrix float aspectRatio = fViewport.width/fViewport.height; diff --git a/examples/FirstScene/main.cpp b/examples/FirstScene/main.cpp index 4acbdf5a1..3da45342e 100644 --- a/examples/FirstScene/main.cpp +++ b/examples/FirstScene/main.cpp @@ -307,7 +307,8 @@ int main() // Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre // Cette fonction est codée de sorte à ne pas provoquer d'évènement MouseMoved - Nz::Mouse::SetPosition(window.GetWidth() / 2, window.GetHeight() / 2, window); + Nz::Vector2ui size = window.GetSize(); + Nz::Mouse::SetPosition(size.x / 2, size.y / 2, window); break; } diff --git a/examples/Particles/LogoDemo.cpp b/examples/Particles/LogoDemo.cpp index f35d3fa5e..e5e6c0925 100644 --- a/examples/Particles/LogoDemo.cpp +++ b/examples/Particles/LogoDemo.cpp @@ -251,21 +251,20 @@ bool LogoExample::Update(Ndk::StateMachine& fsm, float elapsedTime) void LogoExample::ResetParticles(float elapsed) { - unsigned int width = m_shared.target->GetWidth(); - unsigned int height = m_shared.target->GetHeight(); + Nz::Vector2ui size = m_shared.target->GetSize(); - Nz::Vector2f center = {width / 2.f, height / 2.f}; + Nz::Vector2f center = {size.x / 2.f, size.y / 2.f}; Nz::Vector2f offset = center - Nz::Vector2f(Nz::Vector2ui(m_logo.GetSize()) / 2); - std::uniform_real_distribution disX(0.f, float(width)); - std::uniform_real_distribution disY(-float(height) * 0.5f, float(height) * 1.5f); + std::uniform_real_distribution disX(0.f, float(size.x)); + std::uniform_real_distribution disY(-float(size.y) * 0.5f, float(size.y) * 1.5f); ParticleData* sprite = static_cast(m_particles); for (PixelData& data : m_pixels) { sprite->color = data.color; sprite->destination = offset + Nz::Vector2f(data.pos); - sprite->position.Set(disX(m_shared.randomGen) - float(width), disY(m_shared.randomGen), 0.f); + sprite->position.Set(disX(m_shared.randomGen) - float(size.x), disY(m_shared.randomGen), 0.f); sprite->velocity = Nz::Vector2f::Zero(); sprite++; } diff --git a/examples/Particles/SpacebattleDemo.cpp b/examples/Particles/SpacebattleDemo.cpp index 7b15febbc..1dd7eb0ec 100644 --- a/examples/Particles/SpacebattleDemo.cpp +++ b/examples/Particles/SpacebattleDemo.cpp @@ -820,5 +820,6 @@ void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* /*eventHandler*/, m_turretCannonBaseRotation = Nz::Clamp(m_turretCannonBaseRotation + speed * event.deltaY, -65.f, 40.f); m_turretBaseRotation -= event.deltaX * speed; - Nz::Mouse::SetPosition(m_shared.target->GetWidth() / 2, m_shared.target->GetHeight() / 2, *m_shared.target); + Nz::Vector2ui size = m_shared.target->GetSize(); + Nz::Mouse::SetPosition(size.x / 2, size.y / 2, *m_shared.target); } diff --git a/examples/Particles/main.cpp b/examples/Particles/main.cpp index a61e8b778..cdc22d379 100644 --- a/examples/Particles/main.cpp +++ b/examples/Particles/main.cpp @@ -100,9 +100,10 @@ int main() Nz::Boxf fpsCountBox = fpsGfx.GetBoundingVolume().aabb; Nz::Boxf particleCountBox = particleCountGfx.GetBoundingVolume().aabb; + Nz::Vector2ui windowSize = window.GetSize(); demoNameNode.SetPosition(5.f, 5.f); - particleCountNode.SetPosition(5.f, window.GetHeight() - particleCountBox.height - 5.f); - fpsNode.SetPosition(5.f, window.GetHeight() - fpsCountBox.height - particleCountBox.height - 5.f); + particleCountNode.SetPosition(5.f, windowSize.y - particleCountBox.height - 5.f); + fpsNode.SetPosition(5.f, windowSize.x - fpsCountBox.height - particleCountBox.height - 5.f); shared.demos.push_back(std::make_shared(shared)); diff --git a/examples/Tut01/main.cpp b/examples/Tut01/main.cpp index b1d962e1e..8a3df36ff 100644 --- a/examples/Tut01/main.cpp +++ b/examples/Tut01/main.cpp @@ -40,7 +40,8 @@ int main(int argc, char* argv[]) graphicsComponent.Attach(textSprite); Nz::Boxf textBox = graphicsComponent.GetBoundingVolume().aabb; - nodeComponent.SetPosition(mainWindow.GetWidth() / 2 - textBox.width / 2, mainWindow.GetHeight() / 2 - textBox.height / 2); + Nz::Vector2ui windowSize = mainWindow.GetSize(); + nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2); while (application.Run()) { diff --git a/include/Nazara/Platform/Window.hpp b/include/Nazara/Platform/Window.hpp index c22c00d64..28c77d76f 100644 --- a/include/Nazara/Platform/Window.hpp +++ b/include/Nazara/Platform/Window.hpp @@ -62,12 +62,10 @@ namespace Nz inline CursorController& GetCursorController(); inline EventHandler& GetEventHandler(); WindowHandle GetHandle() const; - unsigned int GetHeight() const; Vector2i GetPosition() const; Vector2ui GetSize() const; WindowStyleFlags GetStyle() const; String GetTitle() const; - unsigned int GetWidth() const; bool HasFocus() const; diff --git a/include/Nazara/Renderer/RenderTarget.hpp b/include/Nazara/Renderer/RenderTarget.hpp index 673996a93..fb07ad745 100644 --- a/include/Nazara/Renderer/RenderTarget.hpp +++ b/include/Nazara/Renderer/RenderTarget.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -24,9 +25,8 @@ namespace Nz RenderTarget(RenderTarget&&) noexcept = default; virtual ~RenderTarget(); - virtual unsigned int GetHeight() const = 0; virtual RenderTargetParameters GetParameters() const = 0; - virtual unsigned int GetWidth() const = 0; + virtual Vector2ui GetSize() const = 0; bool IsActive() const; virtual bool IsRenderable() const = 0; diff --git a/include/Nazara/Renderer/RenderTexture.hpp b/include/Nazara/Renderer/RenderTexture.hpp index 253f4a680..ba9b8680e 100644 --- a/include/Nazara/Renderer/RenderTexture.hpp +++ b/include/Nazara/Renderer/RenderTexture.hpp @@ -43,10 +43,8 @@ namespace Nz void Detach(AttachmentPoint attachmentPoint, UInt8 index); - unsigned int GetHeight() const override; RenderTargetParameters GetParameters() const override; Vector2ui GetSize() const; - unsigned int GetWidth() const override; bool IsComplete() const; bool IsRenderable() const override; diff --git a/include/Nazara/Renderer/RenderWindow.hpp b/include/Nazara/Renderer/RenderWindow.hpp index 33f9bd4df..4c42c3758 100644 --- a/include/Nazara/Renderer/RenderWindow.hpp +++ b/include/Nazara/Renderer/RenderWindow.hpp @@ -44,9 +44,8 @@ namespace Nz void EnableVerticalSync(bool enabled); - unsigned int GetHeight() const override; RenderTargetParameters GetParameters() const override; - unsigned int GetWidth() const override; + Vector2ui GetSize() const override; bool IsRenderable() const override; bool IsValid() const; diff --git a/src/Nazara/Platform/Win32/WindowImpl.cpp b/src/Nazara/Platform/Win32/WindowImpl.cpp index b49392222..0eb2c670d 100644 --- a/src/Nazara/Platform/Win32/WindowImpl.cpp +++ b/src/Nazara/Platform/Win32/WindowImpl.cpp @@ -218,11 +218,6 @@ namespace Nz return m_handle; } - unsigned int WindowImpl::GetHeight() const - { - return m_size.y; - } - Vector2i WindowImpl::GetPosition() const { return m_position; @@ -252,11 +247,6 @@ namespace Nz return String::Unicode(wTitle.get()); } - unsigned int WindowImpl::GetWidth() const - { - return m_size.x; - } - bool WindowImpl::HasFocus() const { return GetForegroundWindow() == m_handle; diff --git a/src/Nazara/Platform/Win32/WindowImpl.hpp b/src/Nazara/Platform/Win32/WindowImpl.hpp index 1cdaff70e..6e10a5283 100644 --- a/src/Nazara/Platform/Win32/WindowImpl.hpp +++ b/src/Nazara/Platform/Win32/WindowImpl.hpp @@ -46,12 +46,10 @@ namespace Nz void EnableSmoothScrolling(bool enable); WindowHandle GetHandle() const; - unsigned int GetHeight() const; Vector2i GetPosition() const; Vector2ui GetSize() const; WindowStyleFlags GetStyle() const; String GetTitle() const; - unsigned int GetWidth() const; bool HasFocus() const; diff --git a/src/Nazara/Platform/Window.cpp b/src/Nazara/Platform/Window.cpp index 8bab956b1..69758cdb0 100644 --- a/src/Nazara/Platform/Window.cpp +++ b/src/Nazara/Platform/Window.cpp @@ -203,19 +203,6 @@ namespace Nz return m_impl->GetHandle(); } - unsigned int Window::GetHeight() const - { - #if NAZARA_PLATFORM_SAFE - if (!m_impl) - { - NazaraError("Window not created"); - return 0; - } - #endif - - return m_impl->GetHeight(); - } - Vector2i Window::GetPosition() const { #if NAZARA_PLATFORM_SAFE @@ -268,19 +255,6 @@ namespace Nz return m_impl->GetTitle(); } - unsigned int Window::GetWidth() const - { - #if NAZARA_PLATFORM_SAFE - if (!m_impl) - { - NazaraError("Window not created"); - return 0; - } - #endif - - return m_impl->GetWidth(); - } - bool Window::HasFocus() const { #if NAZARA_PLATFORM_SAFE diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index b748c8e7d..7be48585f 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -402,7 +402,7 @@ namespace Nz { if (s_contextStates->currentTarget) { - unsigned int height = s_contextStates->currentTarget->GetHeight(); + unsigned int height = s_contextStates->currentTarget->GetSize().y; glScissor(scissorBox.x, height - scissorBox.height - scissorBox.y, scissorBox.width, scissorBox.height); s_contextStates->scissorBoxUpdated = true; } @@ -494,7 +494,7 @@ namespace Nz { if (s_contextStates->currentTarget) { - unsigned int height = s_contextStates->currentTarget->GetHeight(); + unsigned int height = s_contextStates->currentTarget->GetSize().y; glViewport(viewport.x, height - viewport.height - viewport.y, viewport.width, viewport.height); s_contextStates->viewportUpdated = true; } @@ -1287,7 +1287,7 @@ namespace Nz { const Recti& scissorBox = s_contextStates->currentViewport; - unsigned int height = s_contextStates->currentTarget->GetHeight(); + unsigned int height = s_contextStates->currentTarget->GetSize().y; glScissor(scissorBox.x, height - scissorBox.height - scissorBox.y, scissorBox.width, scissorBox.height); s_contextStates->scissorBoxUpdated = true; @@ -1297,7 +1297,7 @@ namespace Nz { const Recti& viewport = s_contextStates->currentViewport; - unsigned int height = s_contextStates->currentTarget->GetHeight(); + unsigned int height = s_contextStates->currentTarget->GetSize().y; glViewport(viewport.x, height - viewport.height - viewport.y, viewport.width, viewport.height); s_contextStates->viewportUpdated = true; diff --git a/src/Nazara/Renderer/RenderTexture.cpp b/src/Nazara/Renderer/RenderTexture.cpp index 8ae1a4bb1..5d5d9fb0f 100644 --- a/src/Nazara/Renderer/RenderTexture.cpp +++ b/src/Nazara/Renderer/RenderTexture.cpp @@ -438,16 +438,6 @@ namespace Nz m_checked = false; } - unsigned int RenderTexture::GetHeight() const - { - NazaraAssert(m_impl, "Invalid render texture"); - - if (!m_sizeUpdated) - UpdateSize(); - - return m_impl->height; - } - RenderTargetParameters RenderTexture::GetParameters() const { NazaraAssert(m_impl, "Invalid render texture"); @@ -466,16 +456,6 @@ namespace Nz return Vector2ui(m_impl->width, m_impl->height); } - unsigned int RenderTexture::GetWidth() const - { - NazaraAssert(m_impl, "Invalid render texture"); - - if (!m_sizeUpdated) - UpdateSize(); - - return m_impl->width; - } - bool RenderTexture::IsComplete() const { NazaraAssert(m_impl, "Invalid render texture"); @@ -665,13 +645,15 @@ namespace Nz NazaraAssert(dst && dst->IsValid(), "Invalid destination render texture"); #if NAZARA_RENDERER_SAFE - if (srcRect.x+srcRect.width > src->GetWidth() || srcRect.y+srcRect.height > src->GetHeight()) + Vector2ui srcSize = src->GetSize(); + if (srcRect.x+srcRect.width > srcSize.x || srcRect.y+srcRect.height > srcSize.y) { NazaraError("Source rectangle dimensions are out of bounds"); return; } - if (dstRect.x+dstRect.width > dst->GetWidth() || dstRect.y+dstRect.height > dst->GetHeight()) + Vector2ui dstSize = dst->GetSize(); + if (dstRect.x+dstRect.width > dstSize.x || dstRect.y+dstRect.height > dstSize.y) { NazaraError("Destination rectangle dimensions are out of bounds"); return; diff --git a/src/Nazara/Renderer/RenderWindow.cpp b/src/Nazara/Renderer/RenderWindow.cpp index bc7210975..b1ade1d95 100644 --- a/src/Nazara/Renderer/RenderWindow.cpp +++ b/src/Nazara/Renderer/RenderWindow.cpp @@ -162,11 +162,6 @@ namespace Nz NazaraError("No context"); } - unsigned int RenderWindow::GetHeight() const - { - return Window::GetHeight(); - } - RenderTargetParameters RenderWindow::GetParameters() const { if (m_context) @@ -181,9 +176,9 @@ namespace Nz } } - unsigned int RenderWindow::GetWidth() const + Vector2ui RenderWindow::GetSize() const { - return Window::GetWidth(); + return Window::GetSize(); } bool RenderWindow::IsRenderable() const diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 4fc42df3e..d2a3ed7e1 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -1444,7 +1444,7 @@ namespace Nz } // Envoi des uniformes liées au Renderer - Vector2ui targetSize(s_target->GetWidth(), s_target->GetHeight()); + Vector2ui targetSize = s_target->GetSize(); if (s_targetSize != targetSize) { int location;