Line data Source code
1 : /* Copyright (C) 2020 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 :
19 : /*
20 : * Describes ground using heightmap mipmaps
21 : * Used for camera movement
22 : */
23 :
24 : #ifndef INCLUDED_HEIGHTMIPMAP
25 : #define INCLUDED_HEIGHTMIPMAP
26 :
27 : #include <vector>
28 :
29 : class Path;
30 : using VfsPath = Path;
31 :
32 : struct SMipmap
33 : {
34 : SMipmap() : m_MapSize(0), m_Heightmap(0) { }
35 157 : SMipmap(size_t MapSize, u16* Heightmap) : m_MapSize(MapSize), m_Heightmap(Heightmap) { }
36 :
37 : size_t m_MapSize;
38 : u16* m_Heightmap;
39 : };
40 :
41 : class CHeightMipmap
42 : {
43 : NONCOPYABLE(CHeightMipmap);
44 : public:
45 :
46 : CHeightMipmap();
47 : ~CHeightMipmap();
48 :
49 : void Initialize(size_t mapSize, const u16* ptr);
50 : void ReleaseData();
51 :
52 : // update the heightmap mipmaps
53 : void Update(const u16* ptr);
54 :
55 : // update a section of the heightmap mipmaps
56 : // (coordinates are heightmap cells, inclusive of lower bounds,
57 : // exclusive of upper bounds)
58 : void Update(const u16* ptr, size_t left, size_t bottom, size_t right, size_t top);
59 :
60 : float GetTrilinearGroundLevel(float x, float z, float radius) const;
61 :
62 : void DumpToDisk(const VfsPath& path) const;
63 :
64 : private:
65 :
66 : // get bilinear filtered height from mipmap
67 : float BilinearFilter(const SMipmap &mipmap, float x, float z) const;
68 :
69 : // update rectangle of the output mipmap by bilinear interpolating an input mipmap of exactly twice its size
70 : void HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const u16* ptr, size_t left, size_t bottom, size_t right, size_t top);
71 :
72 : // update rectangle of the output mipmap by bilinear interpolating the input mipmap
73 : void BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const u16* ptr, size_t left, size_t bottom, size_t right, size_t top);
74 :
75 : // size of this map in each direction
76 : size_t m_MapSize;
77 :
78 : // mipmap list
79 : std::vector<SMipmap> m_Mipmap;
80 : };
81 :
82 : #endif
|