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