Merge 'remotes/trunk'
[0ad.git] / source / renderer / OverlayRenderer.h
blob4327caf2b9f80e3341b83a986785b258401f038f
1 /* Copyright (C) 2013 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_OVERLAYRENDERER
19 #define INCLUDED_OVERLAYRENDERER
21 #include "graphics/ShaderManager.h"
23 struct SOverlayLine;
24 struct SOverlayTexturedLine;
25 struct SOverlaySprite;
26 struct SOverlayQuad;
27 struct SOverlaySphere;
28 class CCamera;
30 struct OverlayRendererInternals;
32 /**
33 * Class OverlayRenderer: Render various bits of data that overlay the
34 * game world (selection circles, health bars, etc).
36 class OverlayRenderer
38 NONCOPYABLE(OverlayRenderer);
40 public:
41 OverlayRenderer();
42 ~OverlayRenderer();
44 /**
45 * Performs one-time initialization. Called by CRenderer::Open after graphics
46 * capabilities and the shader path have been determined (notably VBO support).
48 void Initialize();
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.
55 void Submit(SOverlayLine* overlay);
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.
62 void Submit(SOverlayTexturedLine* overlay);
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.
69 void Submit(SOverlaySprite* overlay);
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.
76 void Submit(SOverlayQuad* overlay);
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.
83 void Submit(SOverlaySphere* overlay);
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.
90 void PrepareForRendering();
92 /**
93 * Reset the list of submitted overlays.
95 void EndFrame();
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)
102 void RenderOverlaysBeforeWater();
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)
109 void RenderOverlaysAfterWater();
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
116 void RenderForegroundOverlays(const CCamera& viewCamera);
118 /// Small vertical offset of overlays from terrain to prevent visual glitches
119 static const float OVERLAY_VOFFSET;
121 private:
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).
128 void RenderTexturedOverlayLines();
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.
136 void RenderTexturedOverlayLines(CShaderProgramPtr shader, bool alwaysVisible);
139 * Helper method; batch-renders all registered quad overlays, batched by their texture for effiency.
141 void RenderQuadOverlays();
144 * Helper method; batch-renders all sphere quad overlays.
146 void RenderSphereOverlays();
148 private:
149 OverlayRendererInternals* m;
152 #endif // INCLUDED_OVERLAYRENDERER