Renderer: Replaced RenderTarget::Get[Height|Width] by RenderTarget::GetSize

Utility: Removed Window::Get[Height|Width] methods
This commit is contained in:
Lynix 2017-10-28 23:26:22 +02:00
parent bf8ebbd046
commit d688cecbde
20 changed files with 44 additions and 102 deletions

View File

@ -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:

View File

@ -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));
}
/*!

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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<float> disX(0.f, float(width));
std::uniform_real_distribution<float> disY(-float(height) * 0.5f, float(height) * 1.5f);
std::uniform_real_distribution<float> disX(0.f, float(size.x));
std::uniform_real_distribution<float> disY(-float(size.y) * 0.5f, float(size.y) * 1.5f);
ParticleData* sprite = static_cast<ParticleData*>(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++;
}

View File

@ -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);
}

View File

@ -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<LogoExample>(shared));

View File

@ -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())
{

View File

@ -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;

View File

@ -9,6 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/RenderTargetParameters.hpp>
@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;