vsg  1.0.4
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 
55  VSG_type_name(vsg::RecordTraversal);
56 
58  class VSG_DECLSPEC RecordTraversal : public Object
59  {
60  public:
61  explicit RecordTraversal(CommandBuffer* in_commandBuffer = nullptr, uint32_t in_maxSlot = 2, std::set<Bin*> in_bins = {});
62 
63  RecordTraversal(const RecordTraversal&) = delete;
64  RecordTraversal& operator=(const RecordTraversal& rhs) = delete;
65 
66  template<typename... Args>
67  static ref_ptr<RecordTraversal> create(Args&&... args)
68  {
69  return ref_ptr<RecordTraversal>(new RecordTraversal(args...));
70  }
71 
72  std::size_t sizeofObject() const noexcept override { return sizeof(RecordTraversal); }
73  const char* className() const noexcept override { return type_name<RecordTraversal>(); }
74 
75  Mask traversalMask = MASK_ALL;
76  Mask overrideMask = MASK_OFF;
77 
79  State* getState() { return _state; }
80 
83 
85  uint32_t deviceID() const;
86 
87  void setFrameStamp(FrameStamp* fs);
88  FrameStamp* getFrameStamp() { return _frameStamp; }
89 
90  void setDatabasePager(DatabasePager* dp);
91  DatabasePager* getDatabasePager() { return _databasePager; }
92 
93  void setProjectionAndViewMatrix(const dmat4& projMatrix, const dmat4& viewMatrix);
94 
95  void apply(const Object& object);
96 
97  // scene graph nodes
98  void apply(const Group& group);
99  void apply(const QuadGroup& quadGroup);
100  void apply(const LOD& lod);
101  void apply(const PagedLOD& pagedLOD);
102  void apply(const CullGroup& cullGroup);
103  void apply(const CullNode& cullNode);
104  void apply(const DepthSorted& depthSorted);
105  void apply(const Switch& sw);
106 
107  // positional state
108  void apply(const Light& light);
109  void apply(const AmbientLight& light);
110  void apply(const DirectionalLight& light);
111  void apply(const PointLight& light);
112  void apply(const SpotLight& light);
113 
114  // Vulkan nodes
115  void apply(const Transform& transform);
116  void apply(const MatrixTransform& mt);
117  void apply(const StateGroup& object);
118  void apply(const Commands& commands);
119  void apply(const Command& command);
120 
121  // Viewer level nodes
122  void apply(const View& view);
123 
124  // clear the bins to record a new frame.
125  void clearBins();
126 
127  protected:
128  virtual ~RecordTraversal();
129 
130  FrameStamp* _frameStamp = nullptr;
131  State* _state = nullptr;
132 
133  // used to handle loading of PagedLOD external children.
134  DatabasePager* _databasePager = nullptr;
135  CulledPagedLODs* _culledPagedLODs = nullptr;
136 
137  int32_t _minimumBinNumber = 0;
138  std::vector<ref_ptr<Bin>> _bins;
139  ref_ptr<ViewDependentState> _viewDependentState;
140  };
141 
142 } // 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:59
State * getState()
get the current State object used to track state and projection/modelview matrices for current subgra...
Definition: RecordTraversal.h:79
uint32_t deviceID() const
get the current DeviceID for current subgraph being traversed
CommandBuffer * getCommandBuffer()
get the current CommandBuffer for current subgraph being traversed
vsg::State used by vsg::RecordTraversal to manage state stacks, projection, modelview matrix and frus...
Definition: State.h:228
Definition: ref_ptr.h:22