Panda3D

cullBinFixed.cxx

00001 // Filename: cullBinFixed.cxx
00002 // Created by:  drose (29May02)
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 "cullBinFixed.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 CullBinFixed::_type_handle;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: CullBinFixed::Destructor
00029 //       Access: Public, Virtual
00030 //  Description: 
00031 ////////////////////////////////////////////////////////////////////
00032 CullBinFixed::
00033 ~CullBinFixed() {
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: CullBinFixed::make_bin
00043 //       Access: Public, Static
00044 //  Description: Factory constructor for passing to the CullBinManager.
00045 ////////////////////////////////////////////////////////////////////
00046 CullBin *CullBinFixed::
00047 make_bin(const string &name, GraphicsStateGuardianBase *gsg,
00048          const PStatCollector &draw_region_pcollector) {
00049   return new CullBinFixed(name, gsg, draw_region_pcollector);
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: CullBinFixed::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 CullBinFixed::
00059 add_object(CullableObject *object, Thread *current_thread) {
00060   int draw_order = object->_state->get_draw_order();
00061   _objects.push_back(ObjectData(object, draw_order));
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: CullBinFixed::finish_cull
00066 //       Access: Public
00067 //  Description: Called after all the geoms have been added, this
00068 //               indicates that the cull process is finished for this
00069 //               frame and gives the bins a chance to do any
00070 //               post-processing (like sorting) before moving on to
00071 //               draw.
00072 ////////////////////////////////////////////////////////////////////
00073 void CullBinFixed::
00074 finish_cull(SceneSetup *, Thread *current_thread) {
00075   PStatTimer timer(_cull_this_pcollector, current_thread);
00076   stable_sort(_objects.begin(), _objects.end());
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////
00080 //     Function: CullBinFixed::draw
00081 //       Access: Public, Virtual
00082 //  Description: Draws all the geoms in the bin, in the appropriate
00083 //               order.
00084 ////////////////////////////////////////////////////////////////////
00085 void CullBinFixed::
00086 draw(bool force, Thread *current_thread) {
00087   PStatTimer timer(_draw_this_pcollector, current_thread);
00088   Objects::const_iterator oi;
00089   for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
00090     CullableObject *object = (*oi)._object;
00091     CullHandler::draw(object, _gsg, force, current_thread);
00092   }
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: CullBinFixed::fill_result_graph
00097 //       Access: Protected, Virtual
00098 //  Description: Called by CullBin::make_result_graph() to add all the
00099 //               geoms to the special cull result scene graph.
00100 ////////////////////////////////////////////////////////////////////
00101 void CullBinFixed::
00102 fill_result_graph(CullBin::ResultGraphBuilder &builder) {
00103   Objects::const_iterator oi;
00104   for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
00105     CullableObject *object = (*oi)._object;
00106     builder.add_object(object);
00107   }
00108 }
 All Classes Functions Variables Enumerations