Panda3D
pipeOcclusionCullTraverser.h
1 // Filename: pipeOcclusionCullTraverser.h
2 // Created by: drose (29May07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PIPEOCCLUSIONCULLTRAVERSER_H
16 #define PIPEOCCLUSIONCULLTRAVERSER_H
17 
18 #include "pandabase.h"
19 #include "cullTraverser.h"
20 #include "graphicsOutput.h"
21 #include "displayRegion.h"
22 #include "cullHandler.h"
23 #include "texture.h"
24 
25 class GraphicsEngine;
26 class GraphicsPipe;
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : PipeOcclusionCullTraverser
31 // Description : This specialization of CullTraverser uses the
32 // graphics pipe itself to perform occlusion culling.
33 // As such, it's likely to be inefficient (since it
34 // interferes with the pipe's normal mode of rendering),
35 // and is mainly useful to test other, CPU-based
36 // occlusion algorithms.
37 //
38 // This cannot be used in a multithreaded pipeline
39 // environment where cull and draw are operating
40 // simultaneously.
41 //
42 // It can't be defined in the cull subdirectory, because
43 // it needs access to GraphicsPipe and DisplayRegion and
44 // other classes in display. So we put it in grutil
45 // instead, for lack of any better ideas.
46 ////////////////////////////////////////////////////////////////////
47 class EXPCL_PANDA_GRUTIL PipeOcclusionCullTraverser : public CullTraverser,
48  public CullHandler {
49 PUBLISHED:
52 
53  virtual void set_scene(SceneSetup *scene_setup,
55  bool dr_incomplete_render);
56  virtual void end_traverse();
57 
58  INLINE GraphicsOutput *get_buffer() const;
59  Texture *get_texture();
60 
61  INLINE void set_occlusion_mask(const DrawMask &occlusion_mask);
62  INLINE const DrawMask &get_occlusion_mask() const;
63 
64 protected:
65  virtual bool is_in_view(CullTraverserData &data);
66  virtual void traverse_below(CullTraverserData &data);
67 
68  virtual void record_object(CullableObject *object,
69  const CullTraverser *traverser);
70 
71 private:
72  void make_sphere();
73  static LVertex compute_sphere_point(PN_stdfloat latitude, PN_stdfloat longitude);
74  void make_box();
75 
76  void make_solid_test_state();
77 
78  bool get_volume_viz(const BoundingVolume *vol,
79  CPT(Geom) &geom, // OUT
80  CPT(TransformState) &net_transform, // IN-OUT
81  CPT(TransformState) &internal_transform // OUT
82  );
84  perform_occlusion_test(const Geom *geom,
85  const TransformState *net_transform,
86  const TransformState *internal_transform);
87 
88  void show_results(int num_fragments, const Geom *geom,
89  const TransformState *net_transform,
90  const TransformState *internal_transform);
91 private:
92  bool _live;
93 
94  PT(GraphicsOutput) _buffer;
95  PT(Texture) _texture;
96  PT(DisplayRegion) _display_region;
97  DrawMask _occlusion_mask;
98 
99  PT(SceneSetup) _scene;
100  PT(CullTraverser) _internal_trav;
101  CPT(TransformState) _inv_cs_world_transform;
102 
103  CullHandler *_internal_cull_handler;
104  CullHandler *_true_cull_handler;
105 
106  // This is the query that has already been performed on the current
107  // node or a parent.
108  PT(OcclusionQueryContext) _current_query;
109 
110  // This is the query that has been performed for any children.
111  PT(OcclusionQueryContext) _next_query;
112 
113  PT(Geom) _sphere_geom;
114  PT(Geom) _box_geom;
115  CPT(RenderState) _solid_test_state;
116 
117  class PendingObject {
118  public:
119  INLINE PendingObject(CullableObject *object);
120  INLINE ~PendingObject();
121 
122  CullableObject *_object;
123  PT(OcclusionQueryContext) _query;
124  };
126  PendingObjects _pending_objects;
127 
128  static PStatCollector _setup_occlusion_pcollector;
129  static PStatCollector _draw_occlusion_pcollector;
130  static PStatCollector _test_occlusion_pcollector;
131  static PStatCollector _finish_occlusion_pcollector;
132 
133  static PStatCollector _occlusion_untested_pcollector;
134  static PStatCollector _occlusion_passed_pcollector;
135  static PStatCollector _occlusion_failed_pcollector;
136  static PStatCollector _occlusion_tests_pcollector;
137 
138 public:
139  static TypeHandle get_class_type() {
140  return _type_handle;
141  }
142  static void init_type() {
143  CullTraverser::init_type();
144  register_type(_type_handle, "PipeOcclusionCullTraverser",
145  CullTraverser::get_class_type());
146  }
147  virtual TypeHandle get_type() const {
148  return get_class_type();
149  }
150  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
151 
152 private:
153  static TypeHandle _type_handle;
154 };
155 
156 #include "pipeOcclusionCullTraverser.I"
157 
158 #endif
159 
160 
161 
virtual void traverse_below(CullTraverserData &data)
Traverses all the children of the indicated node, with the given data, which has been converted into ...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This specialization of CullTraverser uses the graphics pipe itself to perform occlusion culling...
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
A lightweight class that represents a single element that may be timed and/or counted via stats...
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
Definition: cullHandler.h:31
virtual void end_traverse()
This callback function is intended to be overridden by a derived class.
Definition: cullHandler.cxx:66
The smallest atom of cull.
virtual void record_object(CullableObject *object, const CullTraverser *traverser)
This callback function is intended to be overridden by a derived class.
Definition: cullHandler.cxx:52
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
A container for geometry primitives.
Definition: geom.h:58
This is a base class for the various different classes that represent the result of a frame of render...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Encapsulates all the communication with a particular instance of a given rendering backend...
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:61
Returned from a GSG in response to begin_occlusion_query() .
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:35
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
virtual void set_scene(SceneSetup *scene_setup, GraphicsStateGuardianBase *gsg, bool dr_incomplete_render)
Sets the SceneSetup object that indicates the initial camera position, etc.