Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
OverlayRenderer.h
Go to the documentation of this file.
1/* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
18#ifndef INCLUDED_OVERLAYRENDERER
19#define INCLUDED_OVERLAYRENDERER
20
23
24struct SOverlayLine;
26struct SOverlaySprite;
27struct SOverlayQuad;
28struct SOverlaySphere;
29class CCamera;
30
32
33/**
34 * Class OverlayRenderer: Render various bits of data that overlay the
35 * game world (selection circles, health bars, etc).
36 */
38{
40
41public:
44
45 /**
46 * Performs one-time initialization. Called by CRenderer::Open after graphics
47 * capabilities and the shader path have been determined.
48 */
49 void Initialize();
50
51 /**
52 * Add a line overlay for rendering in this frame.
53 * @param overlay Must be non-null. The pointed-to object must remain valid at least
54 * until the end of the frame.
55 */
56 void Submit(SOverlayLine* overlay);
57
58 /**
59 * Add a textured line overlay for rendering in this frame.
60 * @param overlay Must be non-null. The pointed-to object must remain valid at least
61 * until the end of the frame.
62 */
63 void Submit(SOverlayTexturedLine* overlay);
64
65 /**
66 * Add a sprite overlay for rendering in this frame.
67 * @param overlay Must be non-null. The pointed-to object must remain valid at least
68 * until the end of the frame.
69 */
70 void Submit(SOverlaySprite* overlay);
71
72 /**
73 * Add a textured quad overlay for rendering in this frame.
74 * @param overlay Must be non-null. The pointed-to object must remain valid at least
75 * until the end of the frame.
76 */
77 void Submit(SOverlayQuad* overlay);
78
79 /**
80 * Add a sphere overlay for rendering in this frame.
81 * @param overlay Must be non-null. The pointed-to object must remain valid at least
82 * until the end of the frame.
83 */
84 void Submit(SOverlaySphere* overlay);
85
86 /**
87 * Prepare internal data structures for rendering.
88 * Must be called after all Submit calls for a frame, and before
89 * uploading data.
90 */
92
93 /**
94 * Upload prepared data to backend.
95 * Must be called after preparing, and before any rendering calls.
96 */
97 void Upload(
98 Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
99
100 /**
101 * Reset the list of submitted overlays.
102 */
103 void EndFrame();
104
105 /**
106 * Render all the submitted overlays that are embedded in the world
107 * (i.e. rendered behind other objects in the normal 3D way)
108 * and should be drawn before water (i.e. may be visible under the water)
109 */
111 Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
112
113 /**
114 * Render all the submitted overlays that are embedded in the world
115 * (i.e. rendered behind other objects in the normal 3D way)
116 * and should be drawn after water (i.e. may be visible on top of the water)
117 */
119 Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
120
121 /**
122 * Render all the submitted overlays that should appear on top of everything
123 * in the world.
124 * @param viewCamera camera to be used for billboard computations
125 */
127 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
128 const CCamera& viewCamera);
129
130 /// Small vertical offset of overlays from terrain to prevent visual glitches
131 static const float OVERLAY_VOFFSET;
132
133private:
134
135 /**
136 * Helper method; renders all overlay lines currently registered in the internals. Batch-
137 * renders textured overlay lines batched according to their visibility status by delegating
138 * to RenderTexturedOverlayLines(IShaderProgram, bool).
139 */
141
142 /**
143 * Helper method; renders those overlay lines currently registered in the internals (i.e.
144 * in m->texlines) for which the 'always visible' flag equals @p alwaysVisible. Used for
145 * batch rendering the overlay lines according to their alwaysVisible status, as this
146 * requires a separate shader to be used.
147 */
149 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
150 Renderer::Backend::IShaderProgram* shader, bool alwaysVisible);
151
152 /**
153 * Helper method; batch-renders all registered quad overlays, batched by their texture for effiency.
154 */
156
157 /**
158 * Helper method; batch-renders all sphere quad overlays.
159 */
161
162private:
164};
165
166#endif // INCLUDED_OVERLAYRENDERER
Definition: Camera.h:42
Class OverlayRenderer: Render various bits of data that overlay the game world (selection circles,...
Definition: OverlayRenderer.h:38
void Submit(SOverlayLine *overlay)
Add a line overlay for rendering in this frame.
Definition: OverlayRenderer.cpp:326
void EndFrame()
Reset the list of submitted overlays.
Definition: OverlayRenderer.cpp:355
void PrepareForRendering()
Prepare internal data structures for rendering.
Definition: OverlayRenderer.cpp:376
void RenderForegroundOverlays(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CCamera &viewCamera)
Render all the submitted overlays that should appear on top of everything in the world.
Definition: OverlayRenderer.cpp:655
~OverlayRenderer()
Definition: OverlayRenderer.cpp:316
void Initialize()
Performs one-time initialization.
Definition: OverlayRenderer.cpp:321
OverlayRenderer()
Definition: OverlayRenderer.cpp:311
void Upload(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Upload prepared data to backend.
Definition: OverlayRenderer.cpp:474
NONCOPYABLE(OverlayRenderer)
void RenderOverlaysAfterWater(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Render all the submitted overlays that are embedded in the world (i.e.
Definition: OverlayRenderer.cpp:496
void RenderOverlaysBeforeWater(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Render all the submitted overlays that are embedded in the world (i.e.
Definition: OverlayRenderer.cpp:481
OverlayRendererInternals * m
Definition: OverlayRenderer.h:163
void RenderQuadOverlays(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Helper method; batch-renders all registered quad overlays, batched by their texture for effiency.
Definition: OverlayRenderer.cpp:587
void RenderSphereOverlays(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Helper method; batch-renders all sphere quad overlays.
Definition: OverlayRenderer.cpp:791
void RenderTexturedOverlayLines(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Helper method; renders all overlay lines currently registered in the internals.
Definition: OverlayRenderer.cpp:507
static const float OVERLAY_VOFFSET
Small vertical offset of overlays from terrain to prevent visual glitches.
Definition: OverlayRenderer.h:131
Definition: IDeviceCommandContext.h:42
IShaderProgram is a container for multiple shaders of different types.
Definition: IShaderProgram.h:81
Definition: OverlayRenderer.cpp:153
Line-based overlay, with world-space coordinates, rendered in the world potentially behind other obje...
Definition: Overlay.h:39
Rectangular single-quad terrain overlay, in world space coordinates.
Definition: Overlay.h:161
Definition: Overlay.h:169
Billboard sprite overlay, with world-space coordinates, rendered on top of all other objects.
Definition: Overlay.h:148
Textured line overlay, with world-space coordinates, rendered in the world onto the terrain.
Definition: Overlay.h:66