TerrainPatch.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "Drawable.h"
  25. class Geometry;
  26. class Terrain;
  27. class VertexBuffer;
  28. class TerrainPatch : public Drawable
  29. {
  30. friend class Terrain;
  31. OBJECT(TerrainPatch);
  32. public:
  33. /// Construct.
  34. TerrainPatch(Context* context);
  35. /// Destruct.
  36. ~TerrainPatch();
  37. /// Register object factory.
  38. static void RegisterObject(Context* context);
  39. /// Process octree raycast. May be called from a worker thread.
  40. virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
  41. /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
  42. virtual void UpdateBatches(const FrameInfo& frame);
  43. /// Prepare geometry for rendering. Called from a worker thread if possible (no GPU update.)
  44. virtual void UpdateGeometry(const FrameInfo& frame);
  45. /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
  46. virtual UpdateGeometryType GetUpdateGeometryType();
  47. /// Return number of occlusion geometry triangles.
  48. virtual unsigned GetNumOccluderTriangles();
  49. /// Draw to occlusion buffer. Return true if did not run out of triangles.
  50. virtual bool DrawOcclusion(OcclusionBuffer* buffer);
  51. protected:
  52. /// Recalculate the world-space bounding box.
  53. virtual void OnWorldBoundingBoxUpdate();
  54. private:
  55. /// Geometry.
  56. SharedPtr<Geometry> geometry_;
  57. /// Vertex buffer.
  58. SharedPtr<VertexBuffer> vertexBuffer_;
  59. /// Parent terrain.
  60. WeakPtr<Terrain> owner_;
  61. /// North neighbor patch.
  62. WeakPtr<TerrainPatch> north_;
  63. /// South neighbor patch.
  64. WeakPtr<TerrainPatch> south_;
  65. /// West neighbor patch.
  66. WeakPtr<TerrainPatch> west_;
  67. /// East neighbor patch.
  68. WeakPtr<TerrainPatch> east_;
  69. /// Local-space bounding box.
  70. BoundingBox boundingBox_;
  71. /// Patch X-coordinate in the terrain.
  72. unsigned x_;
  73. /// Patch Z-coordinate in the terrain.
  74. unsigned z_;
  75. /// Current LOD level.
  76. unsigned lodLevel_;
  77. /// Geometrical error per LOD level.
  78. PODVector<float> lodErrors_;
  79. /// LOD level dirty flag.
  80. bool lodDirty_;
  81. };