Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
HeightMipmap.h
Go to the documentation of this file.
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
29class Path;
30using VfsPath = Path;
31
32struct SMipmap
33{
35 SMipmap(size_t MapSize, u16* Heightmap) : m_MapSize(MapSize), m_Heightmap(Heightmap) { }
36
37 size_t m_MapSize;
39};
40
42{
44public:
45
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
64private:
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
Definition: HeightMipmap.h:42
NONCOPYABLE(CHeightMipmap)
~CHeightMipmap()
Definition: HeightMipmap.cpp:35
size_t m_MapSize
Definition: HeightMipmap.h:76
float GetTrilinearGroundLevel(float x, float z, float radius) const
Definition: HeightMipmap.cpp:101
void Initialize(size_t mapSize, const u16 *ptr)
Definition: HeightMipmap.cpp:82
CHeightMipmap()
Definition: HeightMipmap.cpp:31
void ReleaseData()
Definition: HeightMipmap.cpp:40
void HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const u16 *ptr, size_t left, size_t bottom, size_t right, size_t top)
Definition: HeightMipmap.cpp:142
void BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const u16 *ptr, size_t left, size_t bottom, size_t right, size_t top)
Definition: HeightMipmap.cpp:174
float BilinearFilter(const SMipmap &mipmap, float x, float z) const
Definition: HeightMipmap.cpp:119
void Update(const u16 *ptr)
Definition: HeightMipmap.cpp:50
std::vector< SMipmap > m_Mipmap
Definition: HeightMipmap.h:79
void DumpToDisk(const VfsPath &path) const
Definition: HeightMipmap.cpp:222
Definition: path.h:80
Path()
Definition: path.h:84
Definition: HeightMipmap.h:33
SMipmap()
Definition: HeightMipmap.h:34
size_t m_MapSize
Definition: HeightMipmap.h:37
u16 * m_Heightmap
Definition: HeightMipmap.h:38
SMipmap(size_t MapSize, u16 *Heightmap)
Definition: HeightMipmap.h:35
uint16_t u16
Definition: types.h:38