Removes GUI dependency from Canvas2D.
Initially the GetDefaultGuiMatrix function was added in4113aa0a36
and renamed in04c63a4093
. This was SVN commit r27111.
This commit is contained in:
parent
adc6447b7b
commit
4d77de66d4
@ -23,7 +23,6 @@
|
|||||||
#include "graphics/ShaderManager.h"
|
#include "graphics/ShaderManager.h"
|
||||||
#include "graphics/TextRenderer.h"
|
#include "graphics/TextRenderer.h"
|
||||||
#include "graphics/TextureManager.h"
|
#include "graphics/TextureManager.h"
|
||||||
#include "gui/GUIMatrix.h"
|
|
||||||
#include "maths/Rect.h"
|
#include "maths/Rect.h"
|
||||||
#include "maths/Vector2D.h"
|
#include "maths/Vector2D.h"
|
||||||
#include "ps/CStrInternStatic.h"
|
#include "ps/CStrInternStatic.h"
|
||||||
@ -89,8 +88,11 @@ inline void DrawTextureImpl(
|
|||||||
class CCanvas2D::Impl
|
class CCanvas2D::Impl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Impl(Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
|
Impl(
|
||||||
: DeviceCommandContext(deviceCommandContext)
|
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.grayscaleFactor = shader->GetBindingSlot(str_grayscaleFactor);
|
||||||
BindingSlots.tex = shader->GetBindingSlot(str_tex);
|
BindingSlots.tex = shader->GetBindingSlot(str_tex);
|
||||||
|
|
||||||
const CMatrix3D transform = GetDefaultGuiMatrix();
|
const CMatrix3D transform = GetTransform();
|
||||||
DeviceCommandContext->SetUniform(
|
DeviceCommandContext->SetUniform(
|
||||||
BindingSlots.transform, transform.AsFloatArray());
|
BindingSlots.transform, transform.AsFloatArray());
|
||||||
}
|
}
|
||||||
@ -128,6 +130,30 @@ public:
|
|||||||
Tech.reset();
|
Tech.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns model-view-projection matrix with (0,0) in top-left of screen.
|
||||||
|
*/
|
||||||
|
CMatrix3D GetTransform()
|
||||||
|
{
|
||||||
|
const float width = static_cast<float>(WidthInPixels) / Scale;
|
||||||
|
const float height = static_cast<float>(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;
|
Renderer::Backend::IDeviceCommandContext* DeviceCommandContext = nullptr;
|
||||||
CShaderTechniquePtr Tech;
|
CShaderTechniquePtr Tech;
|
||||||
|
|
||||||
@ -137,8 +163,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
CCanvas2D::CCanvas2D(
|
CCanvas2D::CCanvas2D(
|
||||||
|
const uint32_t widthInPixels, const uint32_t heightInPixels, const float scale,
|
||||||
Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
|
Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
|
||||||
: m(std::make_unique<Impl>(deviceCommandContext))
|
: m(std::make_unique<Impl>(widthInPixels, heightInPixels, scale, deviceCommandContext))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -413,7 +440,7 @@ void CCanvas2D::DrawText(CTextRenderer& textRenderer)
|
|||||||
m->DeviceCommandContext->SetUniform(
|
m->DeviceCommandContext->SetUniform(
|
||||||
m->BindingSlots.grayscaleFactor, 0.0f);
|
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()
|
void CCanvas2D::Flush()
|
||||||
|
@ -35,7 +35,9 @@ struct CColor;
|
|||||||
class CCanvas2D
|
class CCanvas2D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCanvas2D(Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
|
CCanvas2D(
|
||||||
|
const uint32_t widthInPixels, const uint32_t heightInPixels, const float scale,
|
||||||
|
Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
|
||||||
~CCanvas2D();
|
~CCanvas2D();
|
||||||
|
|
||||||
CCanvas2D(const CCanvas2D&) = delete;
|
CCanvas2D(const CCanvas2D&) = delete;
|
||||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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
|
|
@ -23,7 +23,6 @@
|
|||||||
#include "graphics/TextureManager.h"
|
#include "graphics/TextureManager.h"
|
||||||
#include "gui/CGUI.h"
|
#include "gui/CGUI.h"
|
||||||
#include "gui/CGUISprite.h"
|
#include "gui/CGUISprite.h"
|
||||||
#include "gui/GUIMatrix.h"
|
|
||||||
#include "gui/SettingTypes/CGUIColor.h"
|
#include "gui/SettingTypes/CGUIColor.h"
|
||||||
#include "i18n/L10n.h"
|
#include "i18n/L10n.h"
|
||||||
#include "lib/tex/tex.h"
|
#include "lib/tex/tex.h"
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include "CChart.h"
|
#include "CChart.h"
|
||||||
|
|
||||||
#include "graphics/Canvas2D.h"
|
#include "graphics/Canvas2D.h"
|
||||||
#include "gui/GUIMatrix.h"
|
|
||||||
#include "gui/SettingTypes/CGUIList.h"
|
#include "gui/SettingTypes/CGUIList.h"
|
||||||
#include "gui/SettingTypes/CGUISeries.h"
|
#include "gui/SettingTypes/CGUISeries.h"
|
||||||
#include "gui/SettingTypes/CGUIString.h"
|
#include "gui/SettingTypes/CGUIString.h"
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "graphics/Canvas2D.h"
|
#include "graphics/Canvas2D.h"
|
||||||
#include "graphics/FontMetrics.h"
|
#include "graphics/FontMetrics.h"
|
||||||
#include "graphics/TextRenderer.h"
|
#include "graphics/TextRenderer.h"
|
||||||
#include "gui/GUIMatrix.h"
|
|
||||||
#include "lib/external_libraries/libsdl.h"
|
#include "lib/external_libraries/libsdl.h"
|
||||||
#include "maths/Size2D.h"
|
#include "maths/Size2D.h"
|
||||||
#include "maths/Vector2D.h"
|
#include "maths/Vector2D.h"
|
||||||
|
@ -491,7 +491,7 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
|
|||||||
|
|
||||||
void CRenderer::RenderFrame2D(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);
|
m->sceneRenderer.RenderTextOverlays(canvas);
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "graphics/Camera.h"
|
#include "graphics/Camera.h"
|
||||||
#include "graphics/LightEnv.h"
|
#include "graphics/LightEnv.h"
|
||||||
#include "graphics/ShaderManager.h"
|
#include "graphics/ShaderManager.h"
|
||||||
#include "gui/GUIMatrix.h"
|
|
||||||
#include "lib/bits.h"
|
#include "lib/bits.h"
|
||||||
#include "maths/BoundingBoxAligned.h"
|
#include "maths/BoundingBoxAligned.h"
|
||||||
#include "maths/Brush.h"
|
#include "maths/Brush.h"
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "ps/CLogger.h"
|
#include "ps/CLogger.h"
|
||||||
#include "ps/GameSetup/Config.h"
|
#include "ps/GameSetup/Config.h"
|
||||||
#include "ps/ProfileViewer.h"
|
#include "ps/ProfileViewer.h"
|
||||||
|
#include "ps/VideoMode.h"
|
||||||
#include "renderer/Renderer.h"
|
#include "renderer/Renderer.h"
|
||||||
#include "renderer/RenderingOptions.h"
|
#include "renderer/RenderingOptions.h"
|
||||||
#include "renderer/Scene.h"
|
#include "renderer/Scene.h"
|
||||||
@ -61,6 +62,8 @@
|
|||||||
#include "simulation2/components/ICmpWaterManager.h"
|
#include "simulation2/components/ICmpWaterManager.h"
|
||||||
#include "simulation2/helpers/Render.h"
|
#include "simulation2/helpers/Render.h"
|
||||||
|
|
||||||
|
extern int g_xres, g_yres;
|
||||||
|
|
||||||
struct ActorViewerImpl : public Scene
|
struct ActorViewerImpl : public Scene
|
||||||
{
|
{
|
||||||
NONCOPYABLE(ActorViewerImpl);
|
NONCOPYABLE(ActorViewerImpl);
|
||||||
@ -530,7 +533,7 @@ void ActorViewer::Render()
|
|||||||
g_Renderer.GetSceneRenderer().RenderScene(g_Renderer.GetDeviceCommandContext(), m);
|
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_Logger->Render(canvas);
|
||||||
g_ProfileViewer.RenderProfile(canvas);
|
g_ProfileViewer.RenderProfile(canvas);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user