Panda3D
cullBinUnsorted.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 cullBinUnsorted.cxx
10  * @author drose
11  * @date 2002-02-28
12  */
13 
14 #include "cullBinUnsorted.h"
15 #include "cullHandler.h"
17 #include "pStatTimer.h"
18 
19 
20 TypeHandle CullBinUnsorted::_type_handle;
21 
22 /**
23  *
24  */
25 CullBinUnsorted::
26 ~CullBinUnsorted() {
27  Objects::iterator oi;
28  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
29  CullableObject *object = (*oi);
30  delete object;
31  }
32 }
33 
34 /**
35  * Factory constructor for passing to the CullBinManager.
36  */
38 make_bin(const std::string &name, GraphicsStateGuardianBase *gsg,
39  const PStatCollector &draw_region_pcollector) {
40  return new CullBinUnsorted(name, gsg, draw_region_pcollector);
41 }
42 
43 /**
44  * Adds a geom, along with its associated state, to the bin for rendering.
45  */
47 add_object(CullableObject *object, Thread *current_thread) {
48  _objects.push_back(object);
49 }
50 
51 /**
52  * Draws all the objects in the bin, in the appropriate order.
53  */
55 draw(bool force, Thread *current_thread) {
56  PStatTimer timer(_draw_this_pcollector, current_thread);
57 
58  Objects::iterator oi;
59  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
60  CullableObject *object = (*oi);
61 
62  if (object->_draw_callback == nullptr) {
63  nassertd(object->_geom != nullptr) continue;
64 
65  _gsg->set_state_and_transform(object->_state, object->_internal_transform);
66 
67  GeomPipelineReader geom_reader(object->_geom, current_thread);
68  GeomVertexDataPipelineReader data_reader(object->_munged_data, current_thread);
69  data_reader.check_array_readers();
70  geom_reader.draw(_gsg, &data_reader, force);
71  } else {
72  // It has a callback associated.
73  object->draw_callback(_gsg, force, current_thread);
74  // Now the callback has taken care of drawing.
75  }
76  }
77 }
78 
79 /**
80  * Called by CullBin::make_result_graph() to add all the geoms to the special
81  * cull result scene graph.
82  */
83 void CullBinUnsorted::
84 fill_result_graph(CullBin::ResultGraphBuilder &builder) {
85  Objects::const_iterator oi;
86  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
87  CullableObject *object = (*oi);
88  builder.add_object(object);
89  }
90 }
A specific kind of CullBin that does not reorder the geometry; it simply passes it through to the GSG...
virtual void add_object(CullableObject *object, Thread *current_thread)
Adds a geom, along with its associated state, to the bin for rendering.
virtual void draw(bool force, Thread *current_thread)
Draws all the objects in the bin, in the appropriate order.
static CullBin * make_bin(const std::string &name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector)
Factory constructor for passing to the CullBinManager.
A collection of Geoms and their associated state, for a particular scene.
Definition: cullBin.h:40
The smallest atom of cull.
Encapsulates the data from a Geom, pre-fetched for one stage of the pipeline.
Definition: geom.h:405
bool draw(GraphicsStateGuardianBase *gsg, const GeomVertexDataPipelineReader *data_reader, bool force) const
The implementation of Geom::draw().
Definition: geom.cxx:1862
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A lightweight class that represents a single element that may be timed and/or counted via stats.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
Definition: pStatTimer.h:30
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.