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