ground_renderer.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include <QMatrix4x4>
  3. #include <QVector2D>
  4. #include <QVector3D>
  5. #include <cstdint>
  6. #include <vector>
  7. #include "../../game/map/terrain.h"
  8. #include "../../game/map/terrain_service.h"
  9. #include "../i_render_pass.h"
  10. #include "terrain_gpu.h"
  11. namespace Render::GL {
  12. class Renderer;
  13. class ResourceManager;
  14. class Mesh;
  15. class Texture;
  16. class GroundRenderer : public IRenderPass {
  17. public:
  18. void configure(float tile_size, int width, int height) {
  19. m_tile_size = tile_size;
  20. m_width = width;
  21. m_height = height;
  22. recompute_model();
  23. update_noise_offset();
  24. invalidate_params_cache();
  25. }
  26. void configure_extent(float extent) {
  27. m_extent = extent;
  28. recompute_model();
  29. update_noise_offset();
  30. invalidate_params_cache();
  31. }
  32. void set_color(const QVector3D &c) { m_color = c; }
  33. void set_biome(const Game::Map::BiomeSettings &settings) {
  34. m_biome_settings = settings;
  35. m_has_biome = true;
  36. update_noise_offset();
  37. invalidate_params_cache();
  38. }
  39. void submit(Renderer &renderer, ResourceManager *resources) override;
  40. private:
  41. void recompute_model();
  42. void update_noise_offset();
  43. auto build_params() const -> Render::GL::TerrainChunkParams;
  44. void sync_biome_from_service();
  45. static auto biome_equals(const Game::Map::BiomeSettings &a,
  46. const Game::Map::BiomeSettings &b) -> bool;
  47. float m_tile_size = 1.0F;
  48. int m_width = 50;
  49. int m_height = 50;
  50. float m_extent = 50.0F;
  51. QVector3D m_color{0.15F, 0.18F, 0.15F};
  52. QMatrix4x4 m_model;
  53. Game::Map::BiomeSettings m_biome_settings;
  54. bool m_has_biome = false;
  55. QVector2D m_noise_offset{0.0F, 0.0F};
  56. float m_noise_angle = 0.0F;
  57. mutable Render::GL::TerrainChunkParams m_cached_params{};
  58. mutable bool m_cached_params_valid = false;
  59. QMatrix4x4 m_last_submitted_model;
  60. bool m_model_dirty = true;
  61. std::uint64_t m_state_version = 1;
  62. std::uint64_t m_last_submitted_state_version = 0;
  63. void invalidate_params_cache() {
  64. m_cached_params_valid = false;
  65. ++m_state_version;
  66. }
  67. };
  68. } // namespace Render::GL