1 /* Copyright (C) 2012 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/>.
19 * System for representing tile-based information on top of the
23 #ifndef INCLUDED_TERRAINOVERLAY
24 #define INCLUDED_TERRAINOVERLAY
34 * Common interface for terrain-tile-based and texture-based debug overlays.
36 * An overlay object will be rendered for as long as it is allocated
37 * (it is automatically registered/deregistered by constructor/destructor).
41 NONCOPYABLE(ITerrainOverlay
);
44 virtual ~ITerrainOverlay();
46 virtual void RenderBeforeWater() { }
48 virtual void RenderAfterWater(int UNUSED(cullGroup
)) { }
51 * Draw all ITerrainOverlay objects that exist
52 * and that should be drawn before water.
54 static void RenderOverlaysBeforeWater();
57 * Draw all ITerrainOverlay objects that exist
58 * and that should be drawn after water.
60 static void RenderOverlaysAfterWater(int cullGroup
);
63 ITerrainOverlay(int priority
);
67 * Base class for (relatively) simple drawing of
68 * data onto terrain tiles, intended for debugging purposes and for the Atlas
69 * editor (hence not trying to be very efficient).
71 * To start drawing a terrain overlay, first create a subclass of TerrainOverlay.
72 * Override the method GetTileExtents if you want to change the range over which
74 * Override ProcessTile to do your processing for each tile, which should call
75 * RenderTile and RenderTileOutline as appropriate.
77 class TerrainOverlay
: public ITerrainOverlay
81 * Construct the object and register it with the global
82 * list of terrain overlays.
84 * The priority parameter controls the order in which overlays are drawn,
85 * if several exist - they are processed in order of increasing priority,
86 * so later ones draw on top of earlier ones.
87 * Most should use the default of 100. Numbers from 200 are used
90 * @param priority controls the order of drawing
92 TerrainOverlay(const CSimContext
& simContext
, int priority
= 100);
95 * Override to perform processing at the start of the overlay rendering,
96 * before the ProcessTile calls
98 virtual void StartRender();
101 * Override to perform processing at the end of the overlay rendering,
102 * after the ProcessTile calls
104 virtual void EndRender();
107 * Override to limit the range over which ProcessTile will
108 * be called. Defaults to the size of the map.
110 * @param min_i_inclusive [output] smallest <i>i</i> coordinate, in tile-space units
111 * (1 unit per tile, <i>+i</i> is world-space <i>+x</i> and game-space East)
112 * @param min_j_inclusive [output] smallest <i>j</i> coordinate
113 * (<i>+j</i> is world-space <i>+z</i> and game-space North)
114 * @param max_i_inclusive [output] largest <i>i</i> coordinate
115 * @param max_j_inclusive [output] largest <i>j</i> coordinate
117 virtual void GetTileExtents(ssize_t
& min_i_inclusive
, ssize_t
& min_j_inclusive
,
118 ssize_t
& max_i_inclusive
, ssize_t
& max_j_inclusive
);
121 * Override to perform processing of each tile. Typically calls
122 * RenderTile and/or RenderTileOutline.
124 * @param i <i>i</i> coordinate of tile being processed
125 * @param j <i>j</i> coordinate of tile being processed
127 virtual void ProcessTile(ssize_t i
, ssize_t j
) = 0;
130 * Draw a filled quad on top of the current tile.
132 * @param color color to draw. May be transparent (alpha < 1)
133 * @param draw_hidden true if hidden tiles (i.e. those behind other tiles)
136 void RenderTile(const CColor
& color
, bool draw_hidden
);
139 * Draw a filled quad on top of the given tile.
141 void RenderTile(const CColor
& color
, bool draw_hidden
, ssize_t i
, ssize_t j
);
144 * Draw an outlined quad on top of the current tile.
146 * @param color color to draw. May be transparent (alpha < 1)
147 * @param line_width width of lines in pixels. 1 is a sensible value
148 * @param draw_hidden true if hidden tiles (i.e. those behind other tiles)
151 void RenderTileOutline(const CColor
& color
, int line_width
, bool draw_hidden
);
154 * Draw an outlined quad on top of the given tile.
156 void RenderTileOutline(const CColor
& color
, int line_width
, bool draw_hidden
, ssize_t i
, ssize_t j
);
160 virtual void RenderBeforeWater();
162 // Temporary storage of tile coordinates, so ProcessTile doesn't need to
163 // pass it to RenderTile/etc (and doesn't have a chance to get it wrong)
170 * Base class for texture-based terrain overlays, with an arbitrary number of
171 * texels per terrain tile, intended for debugging purposes.
172 * Subclasses must implement BuildTextureRGBA which will be called each frame.
174 class TerrainTextureOverlay
: public ITerrainOverlay
177 TerrainTextureOverlay(float texelsPerTile
, int priority
= 100);
179 virtual ~TerrainTextureOverlay();
183 * Called each frame to generate the texture to render on the terrain.
184 * @p data is w*h*4 bytes, where w and h are the terrain size multiplied
185 * by texelsPerTile. @p data defaults to fully transparent, and should
186 * be filled with data in RGBA order.
188 virtual void BuildTextureRGBA(u8
* data
, size_t w
, size_t h
) = 0;
191 * Returns an arbitrary color, for subclasses that want to distinguish
192 * different integers visually.
194 SColor4ub
GetColor(size_t idx
, u8 alpha
) const;
197 void RenderAfterWater(int cullGroup
);
199 float m_TexelsPerTile
;
201 GLsizei m_TextureW
, m_TextureH
;
204 #endif // INCLUDED_TERRAINOVERLAY