Panda3D
 All Classes Functions Variables Enumerations
cullBin.cxx
1 // Filename: cullBin.cxx
2 // Created by: drose (28Feb02)
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 #include "cullBin.h"
16 #include "config_pgraph.h"
17 #include "pandaNode.h"
18 #include "geomNode.h"
19 #include "cullableObject.h"
20 #include "decalEffect.h"
21 #include "string_utils.h"
22 
23 PStatCollector CullBin::_cull_bin_pcollector("Cull:Sort");
24 
25 TypeHandle CullBin::_type_handle;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: CullBin::Destructor
29 // Access: Public, Virtual
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 CullBin::
33 ~CullBin() {
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: CullBin::make_next
38 // Access: Public, Virtual
39 // Description: Returns a newly-allocated CullBin object that
40 // contains a copy of just the subset of the data from
41 // this CullBin object that is worth keeping around
42 // for next frame.
43 //
44 // If a particular CullBin object has no data worth
45 // preserving till next frame, it is acceptable to
46 // return NULL (which is the default behavior of this
47 // method).
48 ////////////////////////////////////////////////////////////////////
49 PT(CullBin) CullBin::
50 make_next() const {
51  return (CullBin *)NULL;
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: CullBin::finish_cull
56 // Access: Public, Virtual
57 // Description: Called after all the geoms have been added, this
58 // indicates that the cull process is finished for this
59 // frame and gives the bins a chance to do any
60 // post-processing (like sorting) before moving on to
61 // draw.
62 ////////////////////////////////////////////////////////////////////
63 void CullBin::
64 finish_cull(SceneSetup *, Thread *) {
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: CullBin::make_result_graph
69 // Access: Public
70 // Description: Returns a special scene graph constructed to
71 // represent the results of the cull. This will be a
72 // single node with a list of GeomNode children, which
73 // represent the various geom objects discovered by the
74 // cull.
75 //
76 // This is useful mainly for high-level debugging and
77 // abstraction tools; it should not be mistaken for the
78 // low-level cull result itself. For the low-level cull
79 // result, use draw() to efficiently draw the culled
80 // scene.
81 ////////////////////////////////////////////////////////////////////
82 PT(PandaNode) CullBin::
83 make_result_graph() {
84  PT(PandaNode) root_node = new PandaNode(get_name());
85  ResultGraphBuilder builder(root_node);
86  fill_result_graph(builder);
87  return root_node;
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function: CullBin::ResultGraphBuilder::Constructor
92 // Access: Public
93 // Description:
94 ////////////////////////////////////////////////////////////////////
95 CullBin::ResultGraphBuilder::
96 ResultGraphBuilder(PandaNode *root_node) :
97  _object_index(0),
98  _root_node(root_node)
99 {
100 }
101 
102 ////////////////////////////////////////////////////////////////////
103 // Function: CullBin::ResultGraphBuilder::add_object
104 // Access: Public
105 // Description: Called in fill_result_graph() by a derived CullBin
106 // class to add each culled object to the result
107 // returned by make_result_graph().
108 ////////////////////////////////////////////////////////////////////
109 void CullBin::ResultGraphBuilder::
110 add_object(CullableObject *object) {
111  if (_current_transform != object->_internal_transform ||
112  _current_state != object->_state) {
113  // Create a new GeomNode to hold the net transform and state. We
114  // choose to create a new GeomNode for each new state, to make it
115  // clearer to the observer when the state changes.
116  _current_transform = object->_internal_transform;
117  _current_state = object->_state;
118  _current_node = new GeomNode("object_" + format_string(_object_index));
119  _root_node->add_child(_current_node);
120  _current_node->set_transform(_current_transform);
121  _current_node->set_state(_current_state);
122  }
123 
124  record_one_object(_current_node, object);
125  ++_object_index;
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: CullBin::ResultGraphBuilder::record_one_object
130 // Access: Private
131 // Description: Records a single object.
132 ////////////////////////////////////////////////////////////////////
133 void CullBin::ResultGraphBuilder::
134 record_one_object(GeomNode *node, CullableObject *object) {
135  PT(Geom) new_geom = object->_geom->make_copy();
136  new_geom->set_vertex_data(object->_munged_data);
137  node->add_geom(new_geom);
138 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
A collection of Geoms and their associated state, for a particular scene.
Definition: cullBin.h:44
A lightweight class that represents a single element that may be timed and/or counted via stats...
The smallest atom of cull.
A container for geometry primitives.
Definition: geom.h:58
A thread; that is, a lightweight process.
Definition: thread.h:51
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
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37