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"
33 class CPostprocManager
;
36 class CTextureManager
;
39 #define g_Renderer CRenderer::GetSingleton()
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
>
49 // stats class - per frame counts of number of draw calls, poly counts etc
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
56 // number of terrain triangles drawn
58 // number of water triangles drawn
60 // number of (non-transparent) model triangles drawn
62 // number of overlay triangles drawn
64 // number of splat passes for alphamapping
66 // number of particles
70 enum class ScreenShotType
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
);
88 int GetWidth() const { return m_Width
; }
90 int GetHeight() const { return m_Height
; }
92 void RenderFrame(bool needsPresent
);
99 // trigger a reload of shaders (when parameters they depend on have changed)
100 void MakeShadersDirty();
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
131 void PreloadResourcesBeforeNextFrame();
134 * Makes a screenshot on the next RenderFrame according of the given
137 void MakeScreenShotOnNextFrame(ScreenShotType screenShotType
);
139 Renderer::Backend::IDeviceCommandContext
* GetDeviceCommandContext();
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.
165 std::unique_ptr
<Internals
> m
;
171 SViewPort m_Viewport
;
173 // per-frame renderer stats
176 bool m_ShouldPreloadResourcesBeforeNextFrame
= false;
178 ScreenShotType m_ScreenShotType
= ScreenShotType::NONE
;
181 #endif // INCLUDED_RENDERER