collector.h 2.4 KB

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