Pyrogenesis  trunk
OverlayRenderer.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 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 
21 #include "graphics/ShaderManager.h"
22 
23 struct SOverlayLine;
25 struct SOverlaySprite;
26 struct SOverlayQuad;
27 struct SOverlaySphere;
28 class CCamera;
29 
31 
32 /**
33  * Class OverlayRenderer: Render various bits of data that overlay the
34  * game world (selection circles, health bars, etc).
35  */
37 {
39 
40 public:
43 
44  /**
45  * Performs one-time initialization. Called by CRenderer::Open after graphics
46  * capabilities and the shader path have been determined (notably VBO support).
47  */
48  void Initialize();
49 
50  /**
51  * Add a line overlay for rendering in this frame.
52  * @param overlay Must be non-null. The pointed-to object must remain valid at least
53  * until the end of the frame.
54  */
55  void Submit(SOverlayLine* overlay);
56 
57  /**
58  * Add a textured line overlay for rendering in this frame.
59  * @param overlay Must be non-null. The pointed-to object must remain valid at least
60  * until the end of the frame.
61  */
62  void Submit(SOverlayTexturedLine* overlay);
63 
64  /**
65  * Add a sprite overlay for rendering in this frame.
66  * @param overlay Must be non-null. The pointed-to object must remain valid at least
67  * until the end of the frame.
68  */
69  void Submit(SOverlaySprite* overlay);
70 
71  /**
72  * Add a textured quad overlay for rendering in this frame.
73  * @param overlay Must be non-null. The pointed-to object must remain valid at least
74  * until the end of the frame.
75  */
76  void Submit(SOverlayQuad* overlay);
77 
78  /**
79  * Add a sphere overlay for rendering in this frame.
80  * @param overlay Must be non-null. The pointed-to object must remain valid at least
81  * until the end of the frame.
82  */
83  void Submit(SOverlaySphere* overlay);
84 
85  /**
86  * Prepare internal data structures for rendering.
87  * Must be called after all Submit calls for a frame, and before
88  * any rendering calls.
89  */
90  void PrepareForRendering();
91 
92  /**
93  * Reset the list of submitted overlays.
94  */
95  void EndFrame();
96 
97  /**
98  * Render all the submitted overlays that are embedded in the world
99  * (i.e. rendered behind other objects in the normal 3D way)
100  * and should be drawn before water (i.e. may be visible under the water)
101  */
103 
104  /**
105  * Render all the submitted overlays that are embedded in the world
106  * (i.e. rendered behind other objects in the normal 3D way)
107  * and should be drawn after water (i.e. may be visible on top of the water)
108  */
110 
111  /**
112  * Render all the submitted overlays that should appear on top of everything
113  * in the world.
114  * @param viewCamera camera to be used for billboard computations
115  */
116  void RenderForegroundOverlays(const CCamera& viewCamera);
117 
118  /// Small vertical offset of overlays from terrain to prevent visual glitches
119  static const float OVERLAY_VOFFSET;
120 
121 private:
122 
123  /**
124  * Helper method; renders all overlay lines currently registered in the internals. Batch-
125  * renders textured overlay lines batched according to their visibility status by delegating
126  * to RenderTexturedOverlayLines(CShaderProgramPtr, bool).
127  */
129 
130  /**
131  * Helper method; renders those overlay lines currently registered in the internals (i.e.
132  * in m->texlines) for which the 'always visible' flag equals @p alwaysVisible. Used for
133  * batch rendering the overlay lines according to their alwaysVisible status, as this
134  * requires a separate shader to be used.
135  */
136  void RenderTexturedOverlayLines(CShaderProgramPtr shader, bool alwaysVisible);
137 
138  /**
139  * Helper method; batch-renders all registered quad overlays, batched by their texture for effiency.
140  */
141  void RenderQuadOverlays();
142 
143  /**
144  * Helper method; batch-renders all sphere quad overlays.
145  */
146  void RenderSphereOverlays();
147 
148 private:
150 };
151 
152 #endif // INCLUDED_OVERLAYRENDERER
void RenderSphereOverlays()
Helper method; batch-renders all sphere quad overlays.
Definition: OverlayRenderer.cpp:719
OverlayRenderer()
Definition: OverlayRenderer.cpp:189
Line-based overlay, with world-space coordinates, rendered in the world potentially behind other obje...
Definition: Overlay.h:35
NONCOPYABLE(OverlayRenderer)
Class OverlayRenderer: Render various bits of data that overlay the game world (selection circles...
Definition: OverlayRenderer.h:36
void RenderQuadOverlays()
Helper method; batch-renders all registered quad overlays, batched by their texture for effiency...
Definition: OverlayRenderer.cpp:489
Definition: OverlayRenderer.cpp:80
Billboard sprite overlay, with world-space coordinates, rendered on top of all other objects...
Definition: Overlay.h:136
void Submit(SOverlayLine *overlay)
Add a line overlay for rendering in this frame.
Definition: OverlayRenderer.cpp:204
void EndFrame()
Reset the list of submitted overlays.
Definition: OverlayRenderer.cpp:237
Textured line overlay, with world-space coordinates, rendered in the world onto the terrain...
Definition: Overlay.h:61
~OverlayRenderer()
Definition: OverlayRenderer.cpp:194
void Initialize()
Performs one-time initialization.
Definition: OverlayRenderer.cpp:199
Definition: Camera.h:39
void RenderForegroundOverlays(const CCamera &viewCamera)
Render all the submitted overlays that should appear on top of everything in the world.
Definition: OverlayRenderer.cpp:580
Rectangular single-quad terrain overlay, in world space coordinates.
Definition: Overlay.h:149
void RenderOverlaysAfterWater()
Render all the submitted overlays that are embedded in the world (i.e.
Definition: OverlayRenderer.cpp:396
OverlayRendererInternals * m
Definition: OverlayRenderer.h:149
static const float OVERLAY_VOFFSET
Small vertical offset of overlays from terrain to prevent visual glitches.
Definition: OverlayRenderer.h:119
void RenderOverlaysBeforeWater()
Render all the submitted overlays that are embedded in the world (i.e.
Definition: OverlayRenderer.cpp:358
void PrepareForRendering()
Prepare internal data structures for rendering.
Definition: OverlayRenderer.cpp:258
Definition: Overlay.h:157
std::shared_ptr< CShaderProgram > CShaderProgramPtr
Definition: ShaderProgramPtr.h:25
void RenderTexturedOverlayLines()
Helper method; renders all overlay lines currently registered in the internals.
Definition: OverlayRenderer.cpp:405