]> git.lizzy.rs Git - minetest.git/blob - src/client/meshgen/collector.h
Update mesh collector and move it to a separate file (#6904)
[minetest.git] / src / client / meshgen / collector.h
1 /*
2 Minetest
3 Copyright (C) 2018 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21 #include <array>
22 #include <vector>
23 #include "irrlichttypes.h"
24 #include <S3DVertex.h>
25 #include "client/tile.h"
26
27 struct PreMeshBuffer
28 {
29         TileLayer layer;
30         std::vector<u16> indices;
31         std::vector<video::S3DVertex> vertices;
32
33         PreMeshBuffer() = default;
34         explicit PreMeshBuffer(const TileLayer &layer) : layer(layer) {}
35 };
36
37 struct MeshCollector
38 {
39         std::array<std::vector<PreMeshBuffer>, MAX_TILE_LAYERS> prebuffers;
40
41         // clang-format off
42         void append(const TileSpec &material,
43                         const video::S3DVertex *vertices, u32 numVertices,
44                         const u16 *indices, u32 numIndices);
45         void append(const TileSpec &material,
46                         const video::S3DVertex *vertices, u32 numVertices,
47                         const u16 *indices, u32 numIndices,
48                         v3f pos, video::SColor c, u8 light_source);
49         // clang-format on
50
51 private:
52         // clang-format off
53         void append(const TileLayer &material,
54                         const video::S3DVertex *vertices, u32 numVertices,
55                         const u16 *indices, u32 numIndices,
56                         u8 layernum, bool use_scale = false);
57         void append(const TileLayer &material,
58                         const video::S3DVertex *vertices, u32 numVertices,
59                         const u16 *indices, u32 numIndices,
60                         v3f pos, video::SColor c, u8 light_source,
61                         u8 layernum, bool use_scale = false);
62         // clang-format on
63
64         PreMeshBuffer &findBuffer(const TileLayer &layer, u8 layernum, u32 numVertices);
65 };