vsg  1.0.4
VulkanSceneGraph library
PagedLOD.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/io/FileSystem.h>
16 #include <vsg/io/Options.h>
17 #include <vsg/nodes/Node.h>
18 #include <vsg/vk/Semaphore.h>
19 
20 #include <array>
21 
22 namespace vsg
23 {
24 
25  // forward declare
26  class PagedLODList;
27 
35  class VSG_DECLSPEC PagedLOD : public Inherit<Node, PagedLOD>
36  {
37  public:
38  PagedLOD();
39 
40  template<class N, class V>
41  static void t_traverse(N& node, V& visitor)
42  {
43  for (auto& child : node.children)
44  {
45  if (child.node) child.node->accept(visitor);
46  }
47  }
48 
49  void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
50  void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
51  void traverse(RecordTraversal& visitor) const override { t_traverse(*this, visitor); }
52 
53  void read(Input& input) override;
54  void write(Output& output) const override;
55 
56  struct Child
57  {
58  double minimumScreenHeightRatio = 0.0; // 0.0 is always visible
59  ref_ptr<Node> node;
60  };
61 
62  // external file to load when child 0 is null.
63  Path filename;
64 
65  // priority value assigned by record traversal as a guide to how important the external child is for loading.
66  mutable std::atomic<double> priority{0.0};
67 
68  dsphere bound;
69 
70  using Children = std::array<Child, 2>;
71  Children children;
72 
73  bool highResActive(uint64_t frameCount) const
74  {
75  return (frameCount - frameHighResLastUsed.load()) <= 1;
76  }
77 
78  protected:
79  virtual ~PagedLOD();
80 
81  public:
82  ref_ptr<const Options> options;
83 
84  mutable std::atomic_uint64_t frameHighResLastUsed{0};
85  mutable std::atomic_uint requestCount{0};
86 
87  enum RequestStatus : unsigned int
88  {
89  NoRequest = 0,
90  ReadRequest = 1,
91  Reading = 2,
92  Compiling = 3,
93  MergeRequest = 4,
94  Merging = 5,
95  DeleteRequest = 6,
96  Deleting = 7
97  };
98 
99  mutable std::atomic<RequestStatus> requestStatus{NoRequest};
100  mutable uint32_t index = 0;
101 
102  ref_ptr<Node> pending;
103  };
104  VSG_type_name(vsg::PagedLOD);
105 
106  struct PagedLODContainer : public Inherit<Object, PagedLODContainer>
107  {
108  PagedLODContainer(uint32_t maxNumPagedLOD = 10000);
109 
110  struct List
111  {
112  uint32_t head = 0;
113  uint32_t tail = 0;
114  uint32_t count = 0;
115  std::string name;
116  };
117 
118  struct Element
119  {
120  uint32_t previous = 0;
121  uint32_t next = 0;
122  ref_ptr<PagedLOD> plod;
123  List* list = nullptr;
124  };
125 
126  using Elements = std::vector<Element>;
127 
128  Elements elements;
129  List availableList;
130  List inactiveList;
131  List activeList;
132 
133  void resize(uint32_t new_size);
134  void resize();
135  void inactive(const PagedLOD* plod);
136  void active(const PagedLOD* plod);
137  void remove(PagedLOD* plod);
138 
139  void _move(const PagedLOD* plod, List* targetList);
140 
141  bool check();
142  bool check(const List& list);
143 
144  void print(std::ostream& out);
145  };
146 
147 } // namespace vsg
Definition: ConstVisitor.h:140
Definition: Inherit.h:28
Definition: Input.h:43
Definition: Output.h:40
Definition: PagedLOD.h:36
Definition: Path.h:32
RecordTraversal traverses a scene graph doing view frustum culling and invoking state/commands to rec...
Definition: RecordTraversal.h:59
Definition: Visitor.h:140
Definition: ref_ptr.h:22
Definition: PagedLOD.h:119
Definition: PagedLOD.h:111
Definition: PagedLOD.h:107
Definition: PagedLOD.h:57