Panda3D
cullBinFixed.cxx
1 // Filename: cullBinFixed.cxx
2 // Created by: drose (29May02)
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 "cullBinFixed.h"
16 #include "graphicsStateGuardianBase.h"
17 #include "geometricBoundingVolume.h"
18 #include "cullableObject.h"
19 #include "cullHandler.h"
20 #include "pStatTimer.h"
21 
22 #include <algorithm>
23 
24 
25 TypeHandle CullBinFixed::_type_handle;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: CullBinFixed::Destructor
29 // Access: Public, Virtual
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 CullBinFixed::
33 ~CullBinFixed() {
34  Objects::iterator oi;
35  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
36  CullableObject *object = (*oi)._object;
37  delete object;
38  }
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: CullBinFixed::make_bin
43 // Access: Public, Static
44 // Description: Factory constructor for passing to the CullBinManager.
45 ////////////////////////////////////////////////////////////////////
47 make_bin(const string &name, GraphicsStateGuardianBase *gsg,
48  const PStatCollector &draw_region_pcollector) {
49  return new CullBinFixed(name, gsg, draw_region_pcollector);
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: CullBinFixed::add_object
54 // Access: Public, Virtual
55 // Description: Adds a geom, along with its associated state, to
56 // the bin for rendering.
57 ////////////////////////////////////////////////////////////////////
58 void CullBinFixed::
59 add_object(CullableObject *object, Thread *current_thread) {
60  int draw_order = object->_state->get_draw_order();
61  _objects.push_back(ObjectData(object, draw_order));
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: CullBinFixed::finish_cull
66 // Access: Public
67 // Description: Called after all the geoms have been added, this
68 // indicates that the cull process is finished for this
69 // frame and gives the bins a chance to do any
70 // post-processing (like sorting) before moving on to
71 // draw.
72 ////////////////////////////////////////////////////////////////////
73 void CullBinFixed::
74 finish_cull(SceneSetup *, Thread *current_thread) {
75  PStatTimer timer(_cull_this_pcollector, current_thread);
76  stable_sort(_objects.begin(), _objects.end());
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: CullBinFixed::draw
81 // Access: Public, Virtual
82 // Description: Draws all the geoms in the bin, in the appropriate
83 // order.
84 ////////////////////////////////////////////////////////////////////
85 void CullBinFixed::
86 draw(bool force, Thread *current_thread) {
87  PStatTimer timer(_draw_this_pcollector, current_thread);
88  Objects::const_iterator oi;
89  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
90  CullableObject *object = (*oi)._object;
91  CullHandler::draw(object, _gsg, force, current_thread);
92  }
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: CullBinFixed::fill_result_graph
97 // Access: Protected, Virtual
98 // Description: Called by CullBin::make_result_graph() to add all the
99 // geoms to the special cull result scene graph.
100 ////////////////////////////////////////////////////////////////////
101 void CullBinFixed::
102 fill_result_graph(CullBin::ResultGraphBuilder &builder) {
103  Objects::const_iterator oi;
104  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
105  CullableObject *object = (*oi)._object;
106  builder.add_object(object);
107  }
108 }
A specific kind of CullBin that sorts geometry in the order specified by the user-specified draw_orde...
Definition: cullBinFixed.h:37
virtual void draw(bool force, Thread *current_thread)
Draws all the geoms in the bin, in the appropriate order.
A collection of Geoms and their associated state, for a particular scene.
Definition: cullBin.h:44
virtual void finish_cull(SceneSetup *scene_setup, Thread *current_thread)
Called after all the geoms have been added, this indicates that the cull process is finished for this...
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
Definition: pStatTimer.h:34
static CullBin * make_bin(const string &name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector)
Factory constructor for passing to the CullBinManager.
virtual void add_object(CullableObject *object, Thread *current_thread)
Adds a geom, along with its associated state, to the bin for rendering.
A lightweight class that represents a single element that may be timed and/or counted via stats...
static void draw(CullableObject *object, GraphicsStateGuardianBase *gsg, bool force, Thread *current_thread)
Draws the indicated CullableObject, with full support for decals if they are attached to the object...
Definition: cullHandler.I:24
The smallest atom of cull.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
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