diff --git a/source/graphics/Canvas2D.cpp b/source/graphics/Canvas2D.cpp index 9abbc31067..16fa87d7d3 100644 --- a/source/graphics/Canvas2D.cpp +++ b/source/graphics/Canvas2D.cpp @@ -23,7 +23,6 @@ #include "graphics/ShaderManager.h" #include "graphics/TextRenderer.h" #include "graphics/TextureManager.h" -#include "gui/GUIMatrix.h" #include "maths/Rect.h" #include "maths/Vector2D.h" #include "ps/CStrInternStatic.h" @@ -89,8 +88,11 @@ inline void DrawTextureImpl( class CCanvas2D::Impl { public: - Impl(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) - : DeviceCommandContext(deviceCommandContext) + Impl( + const uint32_t widthInPixels, const uint32_t heightInPixels, const float scale, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) + : WidthInPixels(widthInPixels), HeightInPixels(heightInPixels), + Scale(scale), DeviceCommandContext(deviceCommandContext) { } @@ -114,7 +116,7 @@ public: BindingSlots.grayscaleFactor = shader->GetBindingSlot(str_grayscaleFactor); BindingSlots.tex = shader->GetBindingSlot(str_tex); - const CMatrix3D transform = GetDefaultGuiMatrix(); + const CMatrix3D transform = GetTransform(); DeviceCommandContext->SetUniform( BindingSlots.transform, transform.AsFloatArray()); } @@ -128,6 +130,30 @@ public: Tech.reset(); } + /** + * Returns model-view-projection matrix with (0,0) in top-left of screen. + */ + CMatrix3D GetTransform() + { + const float width = static_cast(WidthInPixels) / Scale; + const float height = static_cast(HeightInPixels) / Scale; + + CMatrix3D transform; + transform.SetIdentity(); + transform.Scale(1.0f, -1.f, 1.0f); + transform.Translate(0.0f, height, -1000.0f); + + CMatrix3D projection; + projection.SetOrtho(0.f, width, 0.f, height, -1.f, 1000.f); + transform = projection * transform; + + return transform; + } + + uint32_t WidthInPixels = 1; + uint32_t HeightInPixels = 1; + float Scale = 1.0f; + Renderer::Backend::IDeviceCommandContext* DeviceCommandContext = nullptr; CShaderTechniquePtr Tech; @@ -137,8 +163,9 @@ public: }; CCanvas2D::CCanvas2D( + const uint32_t widthInPixels, const uint32_t heightInPixels, const float scale, Renderer::Backend::IDeviceCommandContext* deviceCommandContext) - : m(std::make_unique(deviceCommandContext)) + : m(std::make_unique(widthInPixels, heightInPixels, scale, deviceCommandContext)) { } @@ -413,7 +440,7 @@ void CCanvas2D::DrawText(CTextRenderer& textRenderer) m->DeviceCommandContext->SetUniform( m->BindingSlots.grayscaleFactor, 0.0f); - textRenderer.Render(m->DeviceCommandContext, m->Tech->GetShader(), GetDefaultGuiMatrix()); + textRenderer.Render(m->DeviceCommandContext, m->Tech->GetShader(), m->GetTransform()); } void CCanvas2D::Flush() diff --git a/source/graphics/Canvas2D.h b/source/graphics/Canvas2D.h index 49ef288ece..12a10f2c6a 100644 --- a/source/graphics/Canvas2D.h +++ b/source/graphics/Canvas2D.h @@ -35,7 +35,9 @@ struct CColor; class CCanvas2D { public: - CCanvas2D(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); + CCanvas2D( + const uint32_t widthInPixels, const uint32_t heightInPixels, const float scale, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); ~CCanvas2D(); CCanvas2D(const CCanvas2D&) = delete; diff --git a/source/gui/GUIMatrix.cpp b/source/gui/GUIMatrix.cpp deleted file mode 100644 index 68d6342ec0..0000000000 --- a/source/gui/GUIMatrix.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 2022 Wildfire Games. - * This file is part of 0 A.D. - * - * 0 A.D. is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * 0 A.D. is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with 0 A.D. If not, see . - */ - -#include "precompiled.h" - -#include "GUIMatrix.h" -#include "maths/Matrix3D.h" -#include "ps/VideoMode.h" - -extern int g_xres, g_yres; - -CMatrix3D GetDefaultGuiMatrix() -{ - float xres = g_xres / g_VideoMode.GetScale(); - float yres = g_yres / g_VideoMode.GetScale(); - - CMatrix3D m; - m.SetIdentity(); - m.Scale(1.0f, -1.f, 1.0f); - m.Translate(0.0f, yres, -1000.0f); - - CMatrix3D proj; - proj.SetOrtho(0.f, xres, 0.f, yres, -1.f, 1000.f); - m = proj * m; - - return m; -} diff --git a/source/gui/GUIMatrix.h b/source/gui/GUIMatrix.h deleted file mode 100644 index 72e27aa34b..0000000000 --- a/source/gui/GUIMatrix.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2019 Wildfire Games. - * This file is part of 0 A.D. - * - * 0 A.D. is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * 0 A.D. is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with 0 A.D. If not, see . - */ - -#ifndef INCLUDED_GUIMATRIX -#define INCLUDED_GUIMATRIX - -class CMatrix3D; - -/** - * Model-view-projection matrix with (0,0) in top-left of screen - */ -CMatrix3D GetDefaultGuiMatrix(); - -#endif // INCLUDED_GUIMATRIX diff --git a/source/gui/GUIRenderer.cpp b/source/gui/GUIRenderer.cpp index 94a6bc4b5a..2531f01d60 100644 --- a/source/gui/GUIRenderer.cpp +++ b/source/gui/GUIRenderer.cpp @@ -23,7 +23,6 @@ #include "graphics/TextureManager.h" #include "gui/CGUI.h" #include "gui/CGUISprite.h" -#include "gui/GUIMatrix.h" #include "gui/SettingTypes/CGUIColor.h" #include "i18n/L10n.h" #include "lib/tex/tex.h" diff --git a/source/gui/ObjectTypes/CChart.cpp b/source/gui/ObjectTypes/CChart.cpp index de3f4d1fbf..b97352888e 100644 --- a/source/gui/ObjectTypes/CChart.cpp +++ b/source/gui/ObjectTypes/CChart.cpp @@ -20,7 +20,6 @@ #include "CChart.h" #include "graphics/Canvas2D.h" -#include "gui/GUIMatrix.h" #include "gui/SettingTypes/CGUIList.h" #include "gui/SettingTypes/CGUISeries.h" #include "gui/SettingTypes/CGUIString.h" diff --git a/source/ps/ProfileViewer.cpp b/source/ps/ProfileViewer.cpp index c37f87962b..5deef65778 100644 --- a/source/ps/ProfileViewer.cpp +++ b/source/ps/ProfileViewer.cpp @@ -22,7 +22,6 @@ #include "graphics/Canvas2D.h" #include "graphics/FontMetrics.h" #include "graphics/TextRenderer.h" -#include "gui/GUIMatrix.h" #include "lib/external_libraries/libsdl.h" #include "maths/Size2D.h" #include "maths/Vector2D.h" diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index e08c650fac..12d441de37 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -491,7 +491,7 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger) void CRenderer::RenderFrame2D(const bool renderGUI, const bool renderLogger) { - CCanvas2D canvas(m->deviceCommandContext.get()); + CCanvas2D canvas(g_xres, g_yres, g_VideoMode.GetScale(), m->deviceCommandContext.get()); m->sceneRenderer.RenderTextOverlays(canvas); diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp index 6cfb3b9931..29aa5ebe96 100644 --- a/source/renderer/ShadowMap.cpp +++ b/source/renderer/ShadowMap.cpp @@ -22,7 +22,6 @@ #include "graphics/Camera.h" #include "graphics/LightEnv.h" #include "graphics/ShaderManager.h" -#include "gui/GUIMatrix.h" #include "lib/bits.h" #include "maths/BoundingBoxAligned.h" #include "maths/Brush.h" diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index 5962bc3637..b41d5fc71d 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -43,6 +43,7 @@ #include "ps/CLogger.h" #include "ps/GameSetup/Config.h" #include "ps/ProfileViewer.h" +#include "ps/VideoMode.h" #include "renderer/Renderer.h" #include "renderer/RenderingOptions.h" #include "renderer/Scene.h" @@ -61,6 +62,8 @@ #include "simulation2/components/ICmpWaterManager.h" #include "simulation2/helpers/Render.h" +extern int g_xres, g_yres; + struct ActorViewerImpl : public Scene { NONCOPYABLE(ActorViewerImpl); @@ -530,7 +533,7 @@ void ActorViewer::Render() g_Renderer.GetSceneRenderer().RenderScene(g_Renderer.GetDeviceCommandContext(), m); { - CCanvas2D canvas(g_Renderer.GetDeviceCommandContext()); + CCanvas2D canvas(g_xres, g_yres, g_VideoMode.GetScale(), g_Renderer.GetDeviceCommandContext()); g_Logger->Render(canvas); g_ProfileViewer.RenderProfile(canvas); }