Panda3D
|
00001 // Filename: cullBinBackToFront.cxx 00002 // Created by: drose (28Feb02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "cullBinBackToFront.h" 00016 #include "graphicsStateGuardianBase.h" 00017 #include "geometricBoundingVolume.h" 00018 #include "cullableObject.h" 00019 #include "cullHandler.h" 00020 #include "pStatTimer.h" 00021 00022 #include <algorithm> 00023 00024 00025 TypeHandle CullBinBackToFront::_type_handle; 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: CullBinBackToFront::Destructor 00029 // Access: Public, Virtual 00030 // Description: 00031 //////////////////////////////////////////////////////////////////// 00032 CullBinBackToFront:: 00033 ~CullBinBackToFront() { 00034 Objects::iterator oi; 00035 for (oi = _objects.begin(); oi != _objects.end(); ++oi) { 00036 CullableObject *object = (*oi)._object; 00037 delete object; 00038 } 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: CullBinBackToFront::make_bin 00043 // Access: Public, Static 00044 // Description: Factory constructor for passing to the CullBinManager. 00045 //////////////////////////////////////////////////////////////////// 00046 CullBin *CullBinBackToFront:: 00047 make_bin(const string &name, GraphicsStateGuardianBase *gsg, 00048 const PStatCollector &draw_region_pcollector) { 00049 return new CullBinBackToFront(name, gsg, draw_region_pcollector); 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: CullBinBackToFront::add_object 00054 // Access: Public, Virtual 00055 // Description: Adds a geom, along with its associated state, to 00056 // the bin for rendering. 00057 //////////////////////////////////////////////////////////////////// 00058 void CullBinBackToFront:: 00059 add_object(CullableObject *object, Thread *current_thread) { 00060 // Determine the center of the bounding volume. 00061 CPT(BoundingVolume) volume = object->_geom->get_bounds(current_thread); 00062 if (volume->is_empty()) { 00063 delete object; 00064 return; 00065 } 00066 00067 const GeometricBoundingVolume *gbv; 00068 DCAST_INTO_V(gbv, volume); 00069 00070 LPoint3 center = gbv->get_approx_center(); 00071 nassertv(object->_modelview_transform != (const TransformState *)NULL); 00072 center = center * object->_modelview_transform->get_mat(); 00073 00074 PN_stdfloat distance = _gsg->compute_distance_to(center); 00075 _objects.push_back(ObjectData(object, distance)); 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: CullBinBackToFront::finish_cull 00080 // Access: Public 00081 // Description: Called after all the geoms have been added, this 00082 // indicates that the cull process is finished for this 00083 // frame and gives the bins a chance to do any 00084 // post-processing (like sorting) before moving on to 00085 // draw. 00086 //////////////////////////////////////////////////////////////////// 00087 void CullBinBackToFront:: 00088 finish_cull(SceneSetup *, Thread *current_thread) { 00089 PStatTimer timer(_cull_this_pcollector, current_thread); 00090 sort(_objects.begin(), _objects.end()); 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: CullBinBackToFront::draw 00095 // Access: Public, Virtual 00096 // Description: Draws all the geoms in the bin, in the appropriate 00097 // order. 00098 //////////////////////////////////////////////////////////////////// 00099 void CullBinBackToFront:: 00100 draw(bool force, Thread *current_thread) { 00101 PStatTimer timer(_draw_this_pcollector, current_thread); 00102 Objects::const_iterator oi; 00103 for (oi = _objects.begin(); oi != _objects.end(); ++oi) { 00104 CullableObject *object = (*oi)._object; 00105 CullHandler::draw(object, _gsg, force, current_thread); 00106 } 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: CullBinBackToFront::fill_result_graph 00111 // Access: Protected, Virtual 00112 // Description: Called by CullBin::make_result_graph() to add all the 00113 // geoms to the special cull result scene graph. 00114 //////////////////////////////////////////////////////////////////// 00115 void CullBinBackToFront:: 00116 fill_result_graph(CullBin::ResultGraphBuilder &builder) { 00117 Objects::const_iterator oi; 00118 for (oi = _objects.begin(); oi != _objects.end(); ++oi) { 00119 CullableObject *object = (*oi)._object; 00120 builder.add_object(object); 00121 } 00122 }