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