GteCuller.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
11 #include <Graphics/GteCamera.h>
12 #include <memory>
13 #include <vector>
14 
15 namespace gte
16 {
17 
18 // Support for determining the potentially visible set of Visual objects in
19 // a scene. The class is designed to support derived classes that provide
20 // specialized culling and sorting. One example is a culler that stores
21 // opaque objects in one set, sorted from front to back, and semitransparent
22 // objects in another set, sorted from back to front. Another example is a
23 // portal system (room-graph visibility) that must maintain a set of unique
24 // visible objects (one object viewed through two portals should not be
25 // inserted into the set twice).
26 
27 class Spatial;
28 class Visual;
29 
30 enum GTE_IMPEXP CullingMode
31 {
32  // Determine visibility state by comparing the world bounding volume
33  // to culling planes.
35 
36  // Force the object to be culled. If a Node is culled, its entire
37  // subtree is culled.
39 
40  // Never cull the object. If a Node is never culled, its entire
41  // subtree is never culled. To accomplish this, the first time such
42  // a Node is encountered, the 'noCull' parameter is set to 'true' in
43  // the recursive chain GetVisibleSet/OnGetVisibleSet.
44  CULL_NEVER
45 };
46 
47 typedef std::vector<Visual*> VisibleSet;
48 
50 {
51 public:
52  // Construction and destruction.
53  virtual ~Culler();
54  Culler();
55 
56  // Access to the stack of world culling planes. The first 6 planes are
57  // those associated with the camera's view frustum. You may push and pop
58  // planes to be used in addition to the view frustum planes. The return
59  // value for PushPlane is 'true' as long as you have not exceeded the
60  // stack capacity. The return value for PopPlane is 'true' as long as
61  // you pop planes you pushed; it is not possible to pop the 6 planes for
62  // the view frustum.
63  enum { MAX_PLANE_QUANTITY = 32 };
64  bool PushPlane(CullingPlane const& plane);
65  bool PopPlane();
66 
67  // This is the main function you should use for culling within a scene
68  // graph. Traverse the scene graph and construct the potentially visible
69  // set relative to the world planes.
70  void ComputeVisibleSet(std::shared_ptr<Camera> const& camera,
71  std::shared_ptr<Spatial> const& scene);
72 
73  // Access to the camera and potentially visible set.
74  inline VisibleSet& GetVisibleSet();
75 
76 protected:
77  enum { INITIALLY_VISIBLE = 128 };
78 
79  // These classes must make calls into the Culler, but applications are not
80  // allowed to.
81  friend class Spatial;
82  friend class Visual;
83 
84  // Compare the object's world bounding sphere against the culling planes.
85  // Only Spatial calls this function.
86  bool IsVisible(BoundingSphere const& sphere);
87 
88  // The base class behavior is to append the visible object to the end of
89  // the visible set (stored as an array). Derived classes may override
90  // this behavior; for example, the array might be maintained as a sorted
91  // array for minimizing render state changes or it might be maintained
92  // as a unique list of objects for a portal system. Only Visual calls
93  // this function.
94  virtual void Insert(Visual* visible);
95 
96  // See the comments before data member mPlaneState about the bit system
97  // for enabling and disabling planes during culling. Only Spatial calls
98  // these functions (during a scene graph traversal).
99  inline void SetPlaneState(unsigned int planeState);
100  inline unsigned int GetPlaneState() const;
101 
102  void PushViewFrustumPlanes(std::shared_ptr<Camera> const& camera);
103 
104  // The world culling planes corresponding to the view frustum plus any
105  // additional user-defined culling planes. The member mPlaneState
106  // represents bit flags to store whether or not a plane is active in the
107  // culling system. A bit of 1 means the plane is active; otherwise, the
108  // plane is inactive. An active plane is compared to bounding volumes,
109  // whereas an inactive plane is not. This supports an efficient culling
110  // of a hierarchy. For example, if a node's bounding volume is inside
111  // the left plane of the view frustum, then the left plane is set to
112  // inactive because the children of the node are automatically all inside
113  // the left plane.
115  CullingPlane mPlane[MAX_PLANE_QUANTITY];
116  unsigned int mPlaneState;
117 
118  // The potentially visible set generated by ComputeVisibleSet(scene).
119  VisibleSet mVisibleSet;
120 };
121 
122 
123 inline VisibleSet& Culler::GetVisibleSet()
124 {
125  return mVisibleSet;
126 }
127 
128 inline void Culler::SetPlaneState(unsigned int planeState)
129 {
130  mPlaneState = planeState;
131 }
132 
133 inline unsigned int Culler::GetPlaneState() const
134 {
135  return mPlaneState;
136 }
137 
138 
139 }
VisibleSet mVisibleSet
Definition: GteCuller.h:119
CULL_ALWAYS
Definition: GteCuller.h:34
CULL_DYNAMIC
Definition: GteCuller.h:34
int mPlaneQuantity
Definition: GteCuller.h:114
std::vector< Visual * > VisibleSet
Definition: GteCuller.h:47
VisibleSet & GetVisibleSet()
Definition: GteCuller.h:123
void SetPlaneState(unsigned int planeState)
Definition: GteCuller.h:128
unsigned int GetPlaneState() const
Definition: GteCuller.h:133
unsigned int mPlaneState
Definition: GteCuller.h:116
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59