Update ifdef condition for MCST-LCC compiler (E2K)
[0ad.git] / source / renderer / Renderer.h
blobbe8c1f55eb4a4d2f2da2d9b9a52f0f259a28cc85
1 /* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_RENDERER
19 #define INCLUDED_RENDERER
21 #include "graphics/Camera.h"
22 #include "graphics/ShaderDefines.h"
23 #include "graphics/ShaderProgramPtr.h"
24 #include "ps/Singleton.h"
25 #include "renderer/backend/IDeviceCommandContext.h"
26 #include "renderer/RenderingOptions.h"
27 #include "renderer/Scene.h"
29 #include <memory>
31 class CDebugRenderer;
32 class CFontManager;
33 class CPostprocManager;
34 class CSceneRenderer;
35 class CShaderManager;
36 class CTextureManager;
37 class CTimeManager;
39 #define g_Renderer CRenderer::GetSingleton()
41 /**
42 * Higher level interface on top of the whole frame rendering. It does know
43 * what should be rendered and via which renderer but shouldn't know how to
44 * render a particular area, like UI or scene.
46 class CRenderer : public Singleton<CRenderer>
48 public:
49 // stats class - per frame counts of number of draw calls, poly counts etc
50 struct Stats
52 // set all stats to zero
53 void Reset() { memset(this, 0, sizeof(*this)); }
54 // number of draw calls per frame - total DrawElements + Begin/End immediate mode loops
55 size_t m_DrawCalls;
56 // number of terrain triangles drawn
57 size_t m_TerrainTris;
58 // number of water triangles drawn
59 size_t m_WaterTris;
60 // number of (non-transparent) model triangles drawn
61 size_t m_ModelTris;
62 // number of overlay triangles drawn
63 size_t m_OverlayTris;
64 // number of splat passes for alphamapping
65 size_t m_BlendSplats;
66 // number of particles
67 size_t m_Particles;
70 enum class ScreenShotType
72 NONE,
73 DEFAULT,
74 BIG
77 public:
78 CRenderer();
79 ~CRenderer();
81 // open up the renderer: performs any necessary initialisation
82 bool Open(int width, int height);
84 // resize renderer view
85 void Resize(int width, int height);
87 // return view width
88 int GetWidth() const { return m_Width; }
89 // return view height
90 int GetHeight() const { return m_Height; }
92 void RenderFrame(bool needsPresent);
94 // signal frame start
95 void BeginFrame();
96 // signal frame end
97 void EndFrame();
99 // trigger a reload of shaders (when parameters they depend on have changed)
100 void MakeShadersDirty();
102 // set the viewport
103 void SetViewport(const SViewPort &);
105 // get the last viewport
106 SViewPort GetViewport();
108 // return stats accumulated for current frame
109 Stats& GetStats() { return m_Stats; }
111 CTextureManager& GetTextureManager();
113 CShaderManager& GetShaderManager();
115 CFontManager& GetFontManager();
117 CTimeManager& GetTimeManager();
119 CPostprocManager& GetPostprocManager();
121 CSceneRenderer& GetSceneRenderer();
123 CDebugRenderer& GetDebugRenderer();
126 * Performs a complete frame without presenting to force loading all needed
127 * resources. It's used for the first frame on a game start.
128 * TODO: It might be better to preload resources without a complete frame
129 * rendering.
131 void PreloadResourcesBeforeNextFrame();
134 * Makes a screenshot on the next RenderFrame according of the given
135 * screenshot type.
137 void MakeScreenShotOnNextFrame(ScreenShotType screenShotType);
139 Renderer::Backend::IDeviceCommandContext* GetDeviceCommandContext();
141 protected:
142 friend class CPatchRData;
143 friend class CDecalRData;
144 friend class HWLightingModelRenderer;
145 friend class ShaderModelVertexRenderer;
146 friend class InstancingModelRenderer;
147 friend class CRenderingOptions;
149 bool ShouldRender() const;
151 void RenderFrameImpl(const bool renderGUI, const bool renderLogger);
152 void RenderFrame2D(const bool renderGUI, const bool renderLogger);
153 void RenderScreenShot(const bool needsPresent);
154 void RenderBigScreenShot(const bool needsPresent);
156 // SetRenderPath: Select the preferred render path.
157 // This may only be called before Open(), because the layout of vertex arrays and other
158 // data may depend on the chosen render path.
159 void SetRenderPath(RenderPath rp);
161 void ReloadShaders();
163 // Private data that is not needed by inline functions.
164 class Internals;
165 std::unique_ptr<Internals> m;
166 // view width
167 int m_Width = 0;
168 // view height
169 int m_Height = 0;
171 SViewPort m_Viewport;
173 // per-frame renderer stats
174 Stats m_Stats;
176 bool m_ShouldPreloadResourcesBeforeNextFrame = false;
178 ScreenShotType m_ScreenShotType = ScreenShotType::NONE;
181 #endif // INCLUDED_RENDERER