Uses CDeviceCommandContext as an input parameter for CCanvas2D.
This was SVN commit r26480.
This commit is contained in:
parent
d1f1d41a9f
commit
8a63adc40d
@ -27,7 +27,6 @@
|
||||
#include "maths/Rect.h"
|
||||
#include "maths/Vector2D.h"
|
||||
#include "ps/CStrInternStatic.h"
|
||||
#include "renderer/backend/gl/DeviceCommandContext.h"
|
||||
#include "renderer/Renderer.h"
|
||||
|
||||
#include <array>
|
||||
@ -69,9 +68,8 @@ inline void DrawTextureImpl(
|
||||
class CCanvas2D::Impl
|
||||
{
|
||||
public:
|
||||
Impl()
|
||||
// TODO: remove global renderer access as pass as an argument.
|
||||
: DeviceCommandContext(g_Renderer.GetDeviceCommandContext())
|
||||
Impl(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext)
|
||||
: DeviceCommandContext(deviceCommandContext)
|
||||
{
|
||||
}
|
||||
|
||||
@ -103,7 +101,9 @@ public:
|
||||
CShaderTechniquePtr Tech;
|
||||
};
|
||||
|
||||
CCanvas2D::CCanvas2D() : m(std::make_unique<Impl>())
|
||||
CCanvas2D::CCanvas2D(
|
||||
Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext)
|
||||
: m(std::make_unique<Impl>(deviceCommandContext))
|
||||
{
|
||||
|
||||
}
|
||||
@ -319,7 +319,7 @@ void CCanvas2D::DrawText(CTextRenderer& textRenderer)
|
||||
{
|
||||
m->BindTechIfNeeded();
|
||||
|
||||
CShaderProgramPtr shader = m->Tech->GetShader();
|
||||
const CShaderProgramPtr& shader = m->Tech->GetShader();
|
||||
shader->Uniform(str_grayscaleFactor, 0.0f);
|
||||
|
||||
textRenderer.Render(m->DeviceCommandContext, shader, GetDefaultGuiMatrix());
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "graphics/Texture.h"
|
||||
#include "maths/Vector2D.h"
|
||||
#include "renderer/backend/gl/DeviceCommandContext.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@ -34,7 +35,7 @@ struct CColor;
|
||||
class CCanvas2D
|
||||
{
|
||||
public:
|
||||
CCanvas2D();
|
||||
CCanvas2D(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext);
|
||||
~CCanvas2D();
|
||||
|
||||
CCanvas2D(const CCanvas2D&) = delete;
|
||||
|
@ -225,6 +225,8 @@ void CTextRenderer::Render(
|
||||
++it;
|
||||
}
|
||||
|
||||
bool transformChanged = false;
|
||||
|
||||
CTexture* lastTexture = nullptr;
|
||||
for (std::list<SBatch>::iterator it = m_Batches.begin(); it != m_Batches.end(); ++it)
|
||||
{
|
||||
@ -239,9 +241,13 @@ void CTextRenderer::Render(
|
||||
shader->BindTexture(str_tex, lastTexture->GetBackendTexture());
|
||||
}
|
||||
|
||||
CMatrix3D translation;
|
||||
translation.SetTranslation(batch.translate.X, batch.translate.Y, 0.0f);
|
||||
shader->Uniform(str_transform, transform * translation);
|
||||
if (batch.translate.X != 0.0f || batch.translate.Y != 0.0f)
|
||||
{
|
||||
CMatrix3D translation;
|
||||
translation.SetTranslation(batch.translate.X, batch.translate.Y, 0.0f);
|
||||
shader->Uniform(str_transform, transform * translation);
|
||||
transformChanged = true;
|
||||
}
|
||||
|
||||
// ALPHA-only textures will have .rgb sampled as 0, so we need to
|
||||
// replace it with white (but not affect RGBA textures)
|
||||
@ -320,4 +326,7 @@ void CTextRenderer::Render(
|
||||
}
|
||||
|
||||
m_Batches.clear();
|
||||
|
||||
if (transformChanged)
|
||||
shader->Uniform(str_transform, transform);
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ void CGUI::SendEventToAll(const CStr& eventName, const JS::HandleValueArray& par
|
||||
object->ScriptEvent(eventName, paramData);
|
||||
}
|
||||
|
||||
void CGUI::Draw()
|
||||
void CGUI::Draw(CCanvas2D& canvas)
|
||||
{
|
||||
using Arena = Allocators::DynamicArena<128 * KiB>;
|
||||
using ObjectListAllocator = ProxyAllocator<VisibleObject, Arena>;
|
||||
@ -342,7 +342,6 @@ void CGUI::Draw()
|
||||
return visibleObject1.index < visibleObject2.index;
|
||||
});
|
||||
|
||||
CCanvas2D canvas;
|
||||
for (const VisibleObject& visibleObject : visibleObjects)
|
||||
visibleObject.object->Draw(canvas);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* 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
|
||||
@ -97,7 +97,7 @@ public:
|
||||
/**
|
||||
* Displays the whole GUI
|
||||
*/
|
||||
void Draw();
|
||||
void Draw(CCanvas2D& canvas);
|
||||
|
||||
/**
|
||||
* Draw GUI Sprite
|
||||
|
@ -372,12 +372,12 @@ void CGUIManager::TickObjects()
|
||||
p.gui->TickObjects();
|
||||
}
|
||||
|
||||
void CGUIManager::Draw() const
|
||||
void CGUIManager::Draw(CCanvas2D& canvas) const
|
||||
{
|
||||
PROFILE3_GPU("gui");
|
||||
|
||||
for (const SGUIPage& p : m_PageStack)
|
||||
p.gui->Draw();
|
||||
p.gui->Draw(canvas);
|
||||
}
|
||||
|
||||
void CGUIManager::UpdateResolution()
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* 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
|
||||
@ -28,6 +28,7 @@
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
class CCanvas2D;
|
||||
class CGUI;
|
||||
|
||||
/**
|
||||
@ -106,7 +107,7 @@ public:
|
||||
/**
|
||||
* See CGUI::Draw; applies to @em all loaded pages.
|
||||
*/
|
||||
void Draw() const;
|
||||
void Draw(CCanvas2D& canvas) const;
|
||||
|
||||
/**
|
||||
* See CGUI::UpdateResolution; applies to @em all loaded pages.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* 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
|
||||
@ -190,15 +190,13 @@ void CConsole::Update(const float deltaRealTime)
|
||||
}
|
||||
}
|
||||
|
||||
void CConsole::Render()
|
||||
void CConsole::Render(CCanvas2D& canvas)
|
||||
{
|
||||
if (!(m_Visible || m_Toggle))
|
||||
return;
|
||||
|
||||
PROFILE3_GPU("console");
|
||||
|
||||
CCanvas2D canvas;
|
||||
|
||||
DrawWindow(canvas);
|
||||
|
||||
CTextRenderer textRenderer;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* 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
|
||||
@ -60,7 +60,7 @@ public:
|
||||
*/
|
||||
void Update(const float deltaRealTime);
|
||||
|
||||
void Render();
|
||||
void Render(CCanvas2D& canvas);
|
||||
|
||||
void InsertChar(const int szChar, const wchar_t cooked);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* 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
|
||||
@ -203,7 +203,7 @@ void CLogger::WriteWarning(const char* message)
|
||||
PushRenderMessage(Warning, message);
|
||||
}
|
||||
|
||||
void CLogger::Render()
|
||||
void CLogger::Render(CCanvas2D& canvas)
|
||||
{
|
||||
PROFILE3_GPU("logger");
|
||||
|
||||
@ -255,7 +255,6 @@ void CLogger::Render()
|
||||
textRenderer.Translate(0.0f, (float)lineSpacing);
|
||||
}
|
||||
|
||||
CCanvas2D canvas;
|
||||
canvas.DrawText(textRenderer);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* 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
|
||||
@ -19,11 +19,12 @@
|
||||
#define INCLUDED_CLOGGER
|
||||
|
||||
#include <deque>
|
||||
#include <fmt/printf.h>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include <fmt/printf.h>
|
||||
class CCanvas2D;
|
||||
|
||||
class CLogger;
|
||||
extern CLogger* g_Logger;
|
||||
@ -69,7 +70,7 @@ public:
|
||||
void WriteWarning(const char* message);
|
||||
|
||||
// Render recent log messages onto the screen
|
||||
void Render();
|
||||
void Render(CCanvas2D& canvas);
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* 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
|
||||
@ -15,11 +15,6 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Implementation of profile display (containing only display routines,
|
||||
* the data model(s) are implemented elsewhere).
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "ProfileViewer.h"
|
||||
@ -40,8 +35,8 @@
|
||||
#include "scriptinterface/Object.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
|
||||
struct CProfileViewerInternals
|
||||
{
|
||||
@ -149,7 +144,7 @@ CProfileViewer::~CProfileViewer()
|
||||
|
||||
|
||||
// Render
|
||||
void CProfileViewer::RenderProfile()
|
||||
void CProfileViewer::RenderProfile(CCanvas2D& canvas)
|
||||
{
|
||||
if (!m->profileVisible)
|
||||
return;
|
||||
@ -170,8 +165,6 @@ void CProfileViewer::RenderProfile()
|
||||
CFontMetrics font(font_name);
|
||||
int lineSpacing = font.GetLineSpacing();
|
||||
|
||||
CCanvas2D canvas;
|
||||
|
||||
// Render background.
|
||||
float estimateWidth = 50.0f;
|
||||
for (const ProfileColumn& column : columns)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* 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
|
||||
@ -28,6 +28,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
class CCanvas2D;
|
||||
|
||||
/**
|
||||
* Struct ProfileColumn: Describes one column of an AbstractProfileTable.
|
||||
*/
|
||||
@ -138,7 +140,7 @@ public:
|
||||
* RenderProfile: Render the profile display using OpenGL if the user
|
||||
* has enabled it.
|
||||
*/
|
||||
void RenderProfile();
|
||||
void RenderProfile(CCanvas2D& canvas);
|
||||
|
||||
/**
|
||||
* Input: Filter and handle any input events that the profile display
|
||||
|
@ -466,8 +466,6 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
|
||||
m->deviceCommandContext->SetFramebuffer(
|
||||
m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
|
||||
|
||||
m->sceneRenderer.RenderTextOverlays();
|
||||
|
||||
// If we're in Atlas game view, render special tools
|
||||
if (g_AtlasGameLoop && g_AtlasGameLoop->view)
|
||||
{
|
||||
@ -481,42 +479,7 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
if (renderGUI)
|
||||
{
|
||||
GPU_SCOPED_LABEL(m->deviceCommandContext.get(), "Render GUI");
|
||||
// All GUI elements are drawn in Z order to render semi-transparent
|
||||
// objects correctly.
|
||||
g_GUI->Draw();
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
// If we're in Atlas game view, render special overlays (e.g. editor bandbox).
|
||||
if (g_AtlasGameLoop && g_AtlasGameLoop->view)
|
||||
{
|
||||
CCanvas2D canvas;
|
||||
g_AtlasGameLoop->view->DrawOverlays(canvas);
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
{
|
||||
GPU_SCOPED_LABEL(m->deviceCommandContext.get(), "Render console");
|
||||
g_Console->Render();
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
if (renderLogger)
|
||||
{
|
||||
GPU_SCOPED_LABEL(m->deviceCommandContext.get(), "Render logger");
|
||||
g_Logger->Render();
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
{
|
||||
GPU_SCOPED_LABEL(m->deviceCommandContext.get(), "Render profiler");
|
||||
// Profile information
|
||||
g_ProfileViewer.RenderProfile();
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
RenderFrame2D(renderGUI, renderLogger);
|
||||
|
||||
EndFrame();
|
||||
|
||||
@ -535,6 +498,49 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
void CRenderer::RenderFrame2D(const bool renderGUI, const bool renderLogger)
|
||||
{
|
||||
CCanvas2D canvas(m->deviceCommandContext.get());
|
||||
|
||||
m->sceneRenderer.RenderTextOverlays(canvas);
|
||||
|
||||
if (renderGUI)
|
||||
{
|
||||
GPU_SCOPED_LABEL(m->deviceCommandContext.get(), "Render GUI");
|
||||
// All GUI elements are drawn in Z order to render semi-transparent
|
||||
// objects correctly.
|
||||
g_GUI->Draw(canvas);
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
// If we're in Atlas game view, render special overlays (e.g. editor bandbox).
|
||||
if (g_AtlasGameLoop && g_AtlasGameLoop->view)
|
||||
{
|
||||
g_AtlasGameLoop->view->DrawOverlays(canvas);
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
{
|
||||
GPU_SCOPED_LABEL(m->deviceCommandContext.get(), "Render console");
|
||||
g_Console->Render(canvas);
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
if (renderLogger)
|
||||
{
|
||||
GPU_SCOPED_LABEL(m->deviceCommandContext.get(), "Render logger");
|
||||
g_Logger->Render(canvas);
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
||||
{
|
||||
GPU_SCOPED_LABEL(m->deviceCommandContext.get(), "Render profiler");
|
||||
// Profile information
|
||||
g_ProfileViewer.RenderProfile(canvas);
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
}
|
||||
|
||||
void CRenderer::RenderScreenShot()
|
||||
{
|
||||
m_ScreenShotType = ScreenShotType::NONE;
|
||||
|
@ -149,6 +149,7 @@ protected:
|
||||
bool ShouldRender() const;
|
||||
|
||||
void RenderFrameImpl(const bool renderGUI, const bool renderLogger);
|
||||
void RenderFrame2D(const bool renderGUI, const bool renderLogger);
|
||||
void RenderScreenShot();
|
||||
void RenderBigScreenShot(const bool needsPresent);
|
||||
|
||||
|
@ -1025,12 +1025,12 @@ void CSceneRenderer::DisplayFrustum()
|
||||
}
|
||||
|
||||
// Text overlay rendering
|
||||
void CSceneRenderer::RenderTextOverlays()
|
||||
void CSceneRenderer::RenderTextOverlays(CCanvas2D& canvas)
|
||||
{
|
||||
PROFILE3_GPU("text overlays");
|
||||
|
||||
if (m_DisplayTerrainPriorities)
|
||||
m->terrainRenderer.RenderPriorities(CULL_DEFAULT);
|
||||
m->terrainRenderer.RenderPriorities(canvas, CULL_DEFAULT);
|
||||
|
||||
ogl_WarnIfError();
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
class CCanvas2D;
|
||||
class CLightEnv;
|
||||
class CMaterial;
|
||||
class CMaterialManager;
|
||||
@ -109,7 +110,7 @@ public:
|
||||
* Assumes the caller has set up the GL environment for orthographic rendering
|
||||
* with texturing and blending.
|
||||
*/
|
||||
void RenderTextOverlays();
|
||||
void RenderTextOverlays(CCanvas2D& canvas);
|
||||
|
||||
// set the current lighting environment; (note: the passed pointer is just copied to a variable within the renderer,
|
||||
// so the lightenv passed must be scoped such that it is not destructed until after the renderer is no longer rendering)
|
||||
|
@ -612,13 +612,12 @@ void TerrainRenderer::RenderWaterFoamOccluders(
|
||||
deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
|
||||
}
|
||||
|
||||
void TerrainRenderer::RenderPriorities(int cullGroup)
|
||||
void TerrainRenderer::RenderPriorities(CCanvas2D& canvas, int cullGroup)
|
||||
{
|
||||
PROFILE("priorities");
|
||||
|
||||
ENSURE(m->phase == Phase_Render);
|
||||
|
||||
CCanvas2D canvas;
|
||||
CTextRenderer textRenderer;
|
||||
textRenderer.SetCurrentFont(CStrIntern("mono-stroke-10"));
|
||||
textRenderer.SetCurrentColor(CColor(1.0f, 1.0f, 0.0f, 1.0f));
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "renderer/backend/gl/Texture.h"
|
||||
|
||||
class CCamera;
|
||||
class CCanvas2D;
|
||||
class CMatrix3D;
|
||||
class CModelDecal;
|
||||
class CPatch;
|
||||
@ -154,7 +155,7 @@ public:
|
||||
/**
|
||||
* Render priority text for all submitted patches, for debugging.
|
||||
*/
|
||||
void RenderPriorities(int cullGroup);
|
||||
void RenderPriorities(CCanvas2D& canvas, int cullGroup);
|
||||
|
||||
/**
|
||||
* Render texture unit 0 over the terrain mesh, with UV coords calculated
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "View.h"
|
||||
|
||||
#include "graphics/Canvas2D.h"
|
||||
#include "graphics/ColladaManager.h"
|
||||
#include "graphics/LOSTexture.h"
|
||||
#include "graphics/MiniMapTexture.h"
|
||||
@ -524,8 +525,11 @@ void ActorViewer::Render()
|
||||
|
||||
g_Renderer.GetSceneRenderer().RenderScene(g_Renderer.GetDeviceCommandContext(), m);
|
||||
|
||||
g_Logger->Render();
|
||||
g_ProfileViewer.RenderProfile();
|
||||
{
|
||||
CCanvas2D canvas(g_Renderer.GetDeviceCommandContext());
|
||||
g_Logger->Render(canvas);
|
||||
g_ProfileViewer.RenderProfile(canvas);
|
||||
}
|
||||
|
||||
g_Renderer.EndFrame();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user