Panda3D

cullBinStateSorted.cxx

00001 // Filename: cullBinStateSorted.cxx
00002 // Created by:  drose (22Mar05)
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 "cullBinStateSorted.h"
00016 #include "graphicsStateGuardianBase.h"
00017 #include "cullableObject.h"
00018 #include "cullHandler.h"
00019 #include "pStatTimer.h"
00020 
00021 #include <algorithm>
00022 
00023 
00024 TypeHandle CullBinStateSorted::_type_handle;
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: CullBinStateSorted::Destructor
00028 //       Access: Public, Virtual
00029 //  Description: 
00030 ////////////////////////////////////////////////////////////////////
00031 CullBinStateSorted::
00032 ~CullBinStateSorted() {
00033   Objects::iterator oi;
00034   for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
00035     CullableObject *object = (*oi)._object;
00036     delete object;
00037   }
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: CullBinStateSorted::make_bin
00042 //       Access: Public, Static
00043 //  Description: Factory constructor for passing to the CullBinManager.
00044 ////////////////////////////////////////////////////////////////////
00045 CullBin *CullBinStateSorted::
00046 make_bin(const string &name, GraphicsStateGuardianBase *gsg,
00047          const PStatCollector &draw_region_pcollector) {
00048   return new CullBinStateSorted(name, gsg, draw_region_pcollector);
00049 }
00050 
00051 ////////////////////////////////////////////////////////////////////
00052 //     Function: CullBinStateSorted::add_object
00053 //       Access: Public, Virtual
00054 //  Description: Adds a geom, along with its associated state, to
00055 //               the bin for rendering.
00056 ////////////////////////////////////////////////////////////////////
00057 void CullBinStateSorted::
00058 add_object(CullableObject *object, Thread *current_thread) {
00059   _objects.push_back(ObjectData(object));
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: CullBinStateSorted::finish_cull
00064 //       Access: Public
00065 //  Description: Called after all the geoms have been added, this
00066 //               indicates that the cull process is finished for this
00067 //               frame and gives the bins a chance to do any
00068 //               post-processing (like sorting) before moving on to
00069 //               draw.
00070 ////////////////////////////////////////////////////////////////////
00071 void CullBinStateSorted::
00072 finish_cull(SceneSetup *, Thread *current_thread) {
00073   PStatTimer timer(_cull_this_pcollector, current_thread);
00074   sort(_objects.begin(), _objects.end());
00075 }
00076 
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: CullBinStateSorted::draw
00080 //       Access: Public, Virtual
00081 //  Description: Draws all the geoms in the bin, in the appropriate
00082 //               order.
00083 ////////////////////////////////////////////////////////////////////
00084 void CullBinStateSorted::
00085 draw(bool force, Thread *current_thread) {
00086   PStatTimer timer(_draw_this_pcollector, current_thread);
00087   Objects::const_iterator oi;
00088   for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
00089     CullableObject *object = (*oi)._object;
00090     CullHandler::draw(object, _gsg, force, current_thread);
00091   }
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //     Function: CullBinStateSorted::fill_result_graph
00096 //       Access: Protected, Virtual
00097 //  Description: Called by CullBin::make_result_graph() to add all the
00098 //               geoms to the special cull result scene graph.
00099 ////////////////////////////////////////////////////////////////////
00100 void CullBinStateSorted::
00101 fill_result_graph(CullBin::ResultGraphBuilder &builder) {
00102   Objects::const_iterator oi;
00103   for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
00104     CullableObject *object = (*oi)._object;
00105     builder.add_object(object);
00106   }
00107 }
 All Classes Functions Variables Enumerations