vsg  1.1.0
VulkanSceneGraph library
RecordTraversal.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/core/Mask.h>
16 #include <vsg/core/Object.h>
17 #include <vsg/core/type_name.h>
18 #include <vsg/maths/mat4.h>
19 
20 #include <set>
21 #include <vector>
22 
23 namespace vsg
24 {
25 
26  // forward declare nodes
27  class Node;
28  class Group;
29  class QuadGroup;
30  class LOD;
31  class PagedLOD;
32  class StateGroup;
33  class CullGroup;
34  class CullNode;
35  class DepthSorted;
36  class Transform;
37  class MatrixTransform;
38  class Command;
39  class Commands;
40  class CommandBuffer;
41  class State;
42  class DatabasePager;
43  class FrameStamp;
44  class CulledPagedLODs;
45  class View;
46  class Bin;
47  class Switch;
48  class ViewDependentState;
49  class Light;
50  class AmbientLight;
51  class DirectionalLight;
52  class PointLight;
53  class SpotLight;
54  class CommandGraph;
55  class RecordedCommandBuffers;
56 
57  VSG_type_name(vsg::RecordTraversal);
58 
60  class VSG_DECLSPEC RecordTraversal : public Object
61  {
62  public:
63  explicit RecordTraversal(uint32_t in_maxSlot = 2, std::set<Bin*> in_bins = {});
64 
65  RecordTraversal(const RecordTraversal&) = delete;
66  RecordTraversal& operator=(const RecordTraversal& rhs) = delete;
67 
68  template<typename... Args>
69  static ref_ptr<RecordTraversal> create(Args&&... args)
70  {
71  return ref_ptr<RecordTraversal>(new RecordTraversal(args...));
72  }
73 
74  std::size_t sizeofObject() const noexcept override { return sizeof(RecordTraversal); }
75  const char* className() const noexcept override { return type_name<RecordTraversal>(); }
76 
77  Mask traversalMask = MASK_ALL;
78  Mask overrideMask = MASK_OFF;
79 
82 
84  State* getState() { return _state; }
85 
88 
90  uint32_t deviceID() const;
91 
92  void setFrameStamp(FrameStamp* fs);
93  FrameStamp* getFrameStamp() { return _frameStamp; }
94 
95  void setDatabasePager(DatabasePager* dp);
96  DatabasePager* getDatabasePager() { return _databasePager; }
97 
98  void apply(const Object& object);
99 
100  // scene graph nodes
101  void apply(const Group& group);
102  void apply(const QuadGroup& quadGroup);
103  void apply(const LOD& lod);
104  void apply(const PagedLOD& pagedLOD);
105  void apply(const CullGroup& cullGroup);
106  void apply(const CullNode& cullNode);
107  void apply(const DepthSorted& depthSorted);
108  void apply(const Switch& sw);
109 
110  // positional state
111  void apply(const Light& light);
112  void apply(const AmbientLight& light);
113  void apply(const DirectionalLight& light);
114  void apply(const PointLight& light);
115  void apply(const SpotLight& light);
116 
117  // Vulkan nodes
118  void apply(const Transform& transform);
119  void apply(const MatrixTransform& mt);
120  void apply(const StateGroup& object);
121  void apply(const Commands& commands);
122  void apply(const Command& command);
123 
124  // Viewer level nodes
125  void apply(const View& view);
126  void apply(const CommandGraph& commandGraph);
127 
128  // clear the bins to record a new frame.
129  void clearBins();
130 
131  protected:
132  virtual ~RecordTraversal();
133 
134  ref_ptr<FrameStamp> _frameStamp;
135  ref_ptr<State> _state;
136 
137  // used to handle loading of PagedLOD external children.
138  ref_ptr<DatabasePager> _databasePager;
139  ref_ptr<CulledPagedLODs> _culledPagedLODs;
140 
141  int32_t _minimumBinNumber = 0;
142  std::vector<ref_ptr<Bin>> _bins;
143  ref_ptr<ViewDependentState> _viewDependentState;
144  };
145 
146 } // namespace vsg
CommandBuffer encapsulates VkCommandBuffer.
Definition: CommandBuffer.h:27
Definition: DatabasePager.h:86
FrameStamp represents the time and frame count of a specific frame.
Definition: FrameStamp.h:22
Definition: Object.h:42
RecordTraversal traverses a scene graph doing view frustum culling and invoking state/commands to rec...
Definition: RecordTraversal.h:61
State * getState()
get the current State object used to track state and projection/modelview matrices for the current su...
Definition: RecordTraversal.h:84
uint32_t deviceID() const
get the current DeviceID for the current subgraph being traversed
CommandBuffer * getCommandBuffer()
get the current CommandBuffer for the current subgraph being traversed
ref_ptr< RecordedCommandBuffers > recordedCommandBuffers
Container for CommandBuffers that have been recorded in current frame.
Definition: RecordTraversal.h:81
vsg::State is used by vsg::RecordTraversal to manage state stacks, projection and modelview matrices ...
Definition: State.h:228
Definition: ref_ptr.h:22