Browse Source

isolate cull from pgraph

David Rose 20 years ago
parent
commit
38dde80e5f

+ 44 - 0
panda/src/cull/Sources.pp

@@ -0,0 +1,44 @@
+#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
+                   dtoolutil:c dtoolbase:c dtool:m prc:c
+#define LOCAL_LIBS \
+    pgraph lerp event gsgbase gobj putil linmath \
+    downloader express pandabase pstatclient 
+ 
+
+#begin lib_target
+  #define TARGET cull
+
+  #define SOURCES \
+    binCullHandler.h \
+    config_cull.h \
+    cullBinBackToFront.h cullBinFixed.h \
+    cullBinFrontToBack.h cullBinStateSorted.h cullBinUnsorted.h \
+    drawCullHandler.h binCullHandler.I cullBinBackToFront.I \
+    cullBinFixed.I cullBinFrontToBack.I cullBinStateSorted.I \
+    cullBinUnsorted.I drawCullHandler.I
+
+  #define COMBINED_SOURCES \
+    $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx
+
+  #define INCLUDED_SOURCES \
+    binCullHandler.cxx \
+    config_cull.cxx \
+    cullBinBackToFront.cxx \
+    cullBinFixed.cxx \
+    cullBinFrontToBack.cxx \
+    cullBinStateSorted.cxx \
+    cullBinUnsorted.cxx \
+    drawCullHandler.cxx
+
+  #define INSTALL_HEADERS \
+    binCullHandler.h \
+    config_cull.h \
+    cullBinBackToFront.h cullBinFixed.h \
+    cullBinFrontToBack.h cullBinStateSorted.h cullBinUnsorted.h \
+    drawCullHandler.h binCullHandler.I cullBinBackToFront.I \
+    cullBinFixed.I cullBinFrontToBack.I cullBinStateSorted.I \
+    cullBinUnsorted.I drawCullHandler.I
+
+  #define IGATESCAN all
+
+#end lib_target

+ 29 - 0
panda/src/cull/binCullHandler.I

@@ -0,0 +1,29 @@
+// Filename: binCullHandler.I
+// Created by:  drose (28Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: BinCullHandler::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE BinCullHandler::
+BinCullHandler(CullResult *cull_result) :
+  _cull_result(cull_result)
+{
+}

+ 32 - 0
panda/src/cull/binCullHandler.cxx

@@ -0,0 +1,32 @@
+// Filename: binCullHandler.cxx
+// Created by:  drose (28Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "binCullHandler.h"
+#include "pStatTimer.h"
+
+////////////////////////////////////////////////////////////////////
+//     Function: BinCullHandler::record_object
+//       Access: Public, Virtual
+//  Description: This callback function is intended to be overridden
+//               by a derived class.  This is called as each Geom is
+//               discovered by the CullTraverser.
+////////////////////////////////////////////////////////////////////
+void BinCullHandler::
+record_object(CullableObject *object, const CullTraverser *traverser) {
+  _cull_result->add_object(object, traverser);
+}

+ 50 - 0
panda/src/cull/binCullHandler.h

@@ -0,0 +1,50 @@
+// Filename: binCullHandler.h
+// Created by:  drose (28Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef BINCULLHANDLER_H
+#define BINCULLHANDLER_H
+
+#include "pandabase.h"
+#include "cullHandler.h"
+#include "cullResult.h"
+#include "pointerTo.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : BinCullHandler
+// Description : This CullHandler sends all of the geoms it receives
+//               into a CullResult object, for binning (and later
+//               drawing).  This is the kind of CullHandler to use for
+//               most normal rendering needs.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA BinCullHandler : public CullHandler {
+public:
+  INLINE BinCullHandler(CullResult *cull_result);
+
+  virtual void record_object(CullableObject *object, 
+                             const CullTraverser *traverser);
+
+private:
+  PT(CullResult) _cull_result;
+};
+
+#include "binCullHandler.I"
+
+#endif
+
+
+  

+ 91 - 0
panda/src/cull/config_cull.cxx

@@ -0,0 +1,91 @@
+// Filename: config_cull.cxx
+// Created by:  drose (23Mar06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "config_cull.h"
+
+#include "cullBinBackToFront.h"
+#include "cullBinFixed.h"
+#include "cullBinFrontToBack.h"
+#include "cullBinStateSorted.h"
+#include "cullBinUnsorted.h"
+
+#include "cullBinManager.h"
+#include "dconfig.h"
+
+ConfigureDef(config_cull);
+NotifyCategoryDef(cull, "");
+
+ConfigureFn(config_cull) {
+  init_libcull();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: init_libcull
+//  Description: Initializes the library.  This must be called at
+//               least once before any of the functions or classes in
+//               this library can be used.  Normally it will be
+//               called by the static initializers and need not be
+//               called explicitly, but special cases exist.
+////////////////////////////////////////////////////////////////////
+void
+init_libcull() {
+  static bool initialized = false;
+  if (initialized) {
+    return;
+  }
+  initialized = true;
+
+  CullBinBackToFront::init_type();
+  CullBinFixed::init_type();
+  CullBinFrontToBack::init_type();
+  CullBinStateSorted::init_type();
+  CullBinUnsorted::init_type();
+
+  cerr << "init_libcull\n";
+
+  CullBinManager *bin_manager = CullBinManager::get_global_ptr();
+  bin_manager->register_bin_type(CullBinManager::BT_unsorted,
+                                 CullBinUnsorted::make_bin);
+  bin_manager->register_bin_type(CullBinManager::BT_state_sorted,
+                                 CullBinStateSorted::make_bin);
+  bin_manager->register_bin_type(CullBinManager::BT_back_to_front,
+                                 CullBinBackToFront::make_bin);
+  bin_manager->register_bin_type(CullBinManager::BT_front_to_back,
+                                 CullBinFrontToBack::make_bin);
+  bin_manager->register_bin_type(CullBinManager::BT_fixed,
+                                 CullBinFixed::make_bin);
+  /*
+  switch () {
+  case BT_back_to_front:
+    return new CullBinBackToFront(name, gsg);
+
+  case BT_front_to_back:
+    return new CullBinFrontToBack(name, gsg);
+
+  case BT_fixed:
+    return new CullBinFixed(name, gsg);
+
+  case BT_state_sorted:
+    return new CullBinStateSorted(name, gsg);
+
+  default:
+    return new CullBinUnsorted(name, gsg);
+  }
+  */
+
+}

+ 33 - 0
panda/src/cull/config_cull.h

@@ -0,0 +1,33 @@
+// Filename: config_cull.h
+// Created by:  drose (23Mar06)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CONFIG_CULL_H
+#define CONFIG_CULL_H
+
+#include "pandabase.h"
+#include "notifyCategoryProxy.h"
+#include "dconfig.h"
+
+class DSearchPath;
+
+ConfigureDecl(config_cull, EXPCL_PANDA, EXPTP_PANDA);
+NotifyCategoryDecl(cull, EXPCL_PANDA, EXPTP_PANDA);
+
+extern EXPCL_PANDA void init_libcull();
+
+#endif

+ 53 - 0
panda/src/cull/cullBinBackToFront.I

@@ -0,0 +1,53 @@
+// Filename: cullBinBackToFront.I
+// Created by:  drose (28Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinBackToFront::ObjectData::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE CullBinBackToFront::ObjectData::
+ObjectData(CullableObject *object, float dist) :
+  _object(object),
+  _dist(dist)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinBackToFront::ObjectData::operator <
+//       Access: Public
+//  Description: Specifies the correct sort ordering for these
+//               objects.
+////////////////////////////////////////////////////////////////////
+INLINE bool CullBinBackToFront::ObjectData::
+operator < (const ObjectData &other) const {
+  return _dist > other._dist;
+}
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinBackToFront::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE CullBinBackToFront::
+CullBinBackToFront(const string &name, GraphicsStateGuardianBase *gsg) :
+  CullBin(name, gsg)
+{
+}

+ 110 - 0
panda/src/cull/cullBinBackToFront.cxx

@@ -0,0 +1,110 @@
+// Filename: cullBinBackToFront.cxx
+// Created by:  drose (28Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cullBinBackToFront.h"
+#include "graphicsStateGuardianBase.h"
+#include "geometricBoundingVolume.h"
+#include "cullableObject.h"
+#include "cullHandler.h"
+#include "pStatTimer.h"
+
+#include <algorithm>
+
+
+TypeHandle CullBinBackToFront::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinBackToFront::Destructor
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+CullBinBackToFront::
+~CullBinBackToFront() {
+  Objects::iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi)._object;
+    delete object;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinBackToFront::make_bin
+//       Access: Public, Static
+//  Description: Factory constructor for passing to the CullBinManager.
+////////////////////////////////////////////////////////////////////
+CullBin *CullBinBackToFront::
+make_bin(const string &name, GraphicsStateGuardianBase *gsg) {
+  return new CullBinBackToFront(name, gsg);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinBackToFront::add_object
+//       Access: Public, Virtual
+//  Description: Adds a geom, along with its associated state, to
+//               the bin for rendering.
+////////////////////////////////////////////////////////////////////
+void CullBinBackToFront::
+add_object(CullableObject *object) {
+  // Determine the center of the bounding volume.
+  CPT(BoundingVolume) volume = object->_geom->get_bounds();
+
+  if (!volume->is_empty() &&
+      volume->is_of_type(GeometricBoundingVolume::get_class_type())) {
+    const GeometricBoundingVolume *gbv;
+    DCAST_INTO_V(gbv, volume);
+    
+    LPoint3f center = gbv->get_approx_center();
+    nassertv(object->_modelview_transform != (const TransformState *)NULL);
+    center = center * object->_modelview_transform->get_mat();
+    
+    float distance = _gsg->compute_distance_to(center);
+    _objects.push_back(ObjectData(object, distance));
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinBackToFront::finish_cull
+//       Access: Public
+//  Description: Called after all the geoms have been added, this
+//               indicates that the cull process is finished for this
+//               frame and gives the bins a chance to do any
+//               post-processing (like sorting) before moving on to
+//               draw.
+////////////////////////////////////////////////////////////////////
+void CullBinBackToFront::
+finish_cull() {
+  PStatTimer timer(_cull_this_pcollector);
+  sort(_objects.begin(), _objects.end());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinBackToFront::draw
+//       Access: Public
+//  Description: Draws all the geoms in the bin, in the appropriate
+//               order.
+////////////////////////////////////////////////////////////////////
+void CullBinBackToFront::
+draw() {
+  PStatTimer timer(_draw_this_pcollector);
+  Objects::const_iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi)._object;
+    CullHandler::draw(object, _gsg);
+  }
+}
+

+ 86 - 0
panda/src/cull/cullBinBackToFront.h

@@ -0,0 +1,86 @@
+// Filename: cullBinBackToFront.h
+// Created by:  drose (28Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CULLBINBACKTOFRONT_H
+#define CULLBINBACKTOFRONT_H
+
+#include "pandabase.h"
+
+#include "cullBin.h"
+#include "geom.h"
+#include "transformState.h"
+#include "renderState.h"
+#include "pointerTo.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CullBinBackToFront
+// Description : A specific kind of CullBin that sorts geometry in
+//               order from furthest to nearest based on the center of
+//               its bounding volume.  This is primarily intended for
+//               rendering transparent and semi-transparent geometry
+//               that must be sorted from back to front.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA CullBinBackToFront : public CullBin {
+public:
+  INLINE CullBinBackToFront(const string &name, GraphicsStateGuardianBase *gsg);
+  virtual ~CullBinBackToFront();
+
+  static CullBin *make_bin(const string &name, GraphicsStateGuardianBase *gsg);
+  
+
+  virtual void add_object(CullableObject *object);
+  virtual void finish_cull();
+  virtual void draw();
+
+private:
+  class ObjectData {
+  public:
+    INLINE ObjectData(CullableObject *object, float dist);
+    INLINE bool operator < (const ObjectData &other) const;
+    
+    CullableObject *_object;
+    float _dist;
+  };
+
+  typedef pvector<ObjectData> Objects;
+  Objects _objects;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CullBin::init_type();
+    register_type(_type_handle, "CullBinBackToFront",
+                  CullBin::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cullBinBackToFront.I"
+
+#endif
+
+
+  

+ 53 - 0
panda/src/cull/cullBinFixed.I

@@ -0,0 +1,53 @@
+// Filename: cullBinFixed.I
+// Created by:  drose (29May02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFixed::ObjectData::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE CullBinFixed::ObjectData::
+ObjectData(CullableObject *object, int draw_order) :
+  _object(object),
+  _draw_order(draw_order)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFixed::ObjectData::operator <
+//       Access: Public
+//  Description: Specifies the correct sort ordering for these
+//               objects.
+////////////////////////////////////////////////////////////////////
+INLINE bool CullBinFixed::ObjectData::
+operator < (const ObjectData &other) const {
+  return _draw_order < other._draw_order;
+}
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFixed::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE CullBinFixed::
+CullBinFixed(const string &name, GraphicsStateGuardianBase *gsg) :
+  CullBin(name, gsg)
+{
+}

+ 97 - 0
panda/src/cull/cullBinFixed.cxx

@@ -0,0 +1,97 @@
+// Filename: cullBinFixed.cxx
+// Created by:  drose (29May02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cullBinFixed.h"
+#include "graphicsStateGuardianBase.h"
+#include "geometricBoundingVolume.h"
+#include "cullableObject.h"
+#include "cullHandler.h"
+#include "pStatTimer.h"
+
+#include <algorithm>
+
+
+TypeHandle CullBinFixed::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFixed::Destructor
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+CullBinFixed::
+~CullBinFixed() {
+  Objects::iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi)._object;
+    delete object;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFixed::make_bin
+//       Access: Public, Static
+//  Description: Factory constructor for passing to the CullBinManager.
+////////////////////////////////////////////////////////////////////
+CullBin *CullBinFixed::
+make_bin(const string &name, GraphicsStateGuardianBase *gsg) {
+  return new CullBinFixed(name, gsg);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFixed::add_object
+//       Access: Public, Virtual
+//  Description: Adds a geom, along with its associated state, to
+//               the bin for rendering.
+////////////////////////////////////////////////////////////////////
+void CullBinFixed::
+add_object(CullableObject *object) {
+  int draw_order = object->_state->get_draw_order();
+  _objects.push_back(ObjectData(object, draw_order));
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFixed::finish_cull
+//       Access: Public
+//  Description: Called after all the geoms have been added, this
+//               indicates that the cull process is finished for this
+//               frame and gives the bins a chance to do any
+//               post-processing (like sorting) before moving on to
+//               draw.
+////////////////////////////////////////////////////////////////////
+void CullBinFixed::
+finish_cull() {
+  PStatTimer timer(_cull_this_pcollector);
+  stable_sort(_objects.begin(), _objects.end());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFixed::draw
+//       Access: Public
+//  Description: Draws all the geoms in the bin, in the appropriate
+//               order.
+////////////////////////////////////////////////////////////////////
+void CullBinFixed::
+draw() {
+  PStatTimer timer(_draw_this_pcollector);
+  Objects::const_iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi)._object;
+    CullHandler::draw(object, _gsg);
+  }
+}
+

+ 88 - 0
panda/src/cull/cullBinFixed.h

@@ -0,0 +1,88 @@
+// Filename: cullBinFixed.h
+// Created by:  drose (29May02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CULLBINFIXED_H
+#define CULLBINFIXED_H
+
+#include "pandabase.h"
+
+#include "cullBin.h"
+#include "geom.h"
+#include "transformState.h"
+#include "renderState.h"
+#include "pointerTo.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CullBinFixed
+// Description : A specific kind of CullBin that sorts geometry in
+//               the order specified by the user-specified draw_order
+//               parameter.  This allows precise relative ordering of
+//               two objects.
+//
+//               When two or more objects are assigned the same
+//               draw_order, they are drawn in scene-graph order (as
+//               with CullBinUnsorted).
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA CullBinFixed : public CullBin {
+public:
+  INLINE CullBinFixed(const string &name, GraphicsStateGuardianBase *gsg);
+  virtual ~CullBinFixed();
+
+  static CullBin *make_bin(const string &name, GraphicsStateGuardianBase *gsg);
+
+  virtual void add_object(CullableObject *object);
+  virtual void finish_cull();
+  virtual void draw();
+
+private:
+  class ObjectData {
+  public:
+    INLINE ObjectData(CullableObject *object, int draw_order);
+    INLINE bool operator < (const ObjectData &other) const;
+    
+    CullableObject *_object;
+    int _draw_order;
+  };
+
+  typedef pvector<ObjectData> Objects;
+  Objects _objects;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CullBin::init_type();
+    register_type(_type_handle, "CullBinFixed",
+                  CullBin::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cullBinFixed.I"
+
+#endif
+
+
+  

+ 53 - 0
panda/src/cull/cullBinFrontToBack.I

@@ -0,0 +1,53 @@
+// Filename: cullBinFrontToBack.I
+// Created by:  drose (29May02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFrontToBack::ObjectData::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE CullBinFrontToBack::ObjectData::
+ObjectData(CullableObject *object, float dist) :
+  _object(object),
+  _dist(dist)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFrontToBack::ObjectData::operator <
+//       Access: Public
+//  Description: Specifies the correct sort ordering for these
+//               objects.
+////////////////////////////////////////////////////////////////////
+INLINE bool CullBinFrontToBack::ObjectData::
+operator < (const ObjectData &other) const {
+  return _dist < other._dist;
+}
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFrontToBack::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE CullBinFrontToBack::
+CullBinFrontToBack(const string &name, GraphicsStateGuardianBase *gsg) :
+  CullBin(name, gsg)
+{
+}

+ 110 - 0
panda/src/cull/cullBinFrontToBack.cxx

@@ -0,0 +1,110 @@
+// Filename: cullBinFrontToBack.cxx
+// Created by:  drose (29May02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cullBinFrontToBack.h"
+#include "graphicsStateGuardianBase.h"
+#include "geometricBoundingVolume.h"
+#include "cullableObject.h"
+#include "cullHandler.h"
+#include "pStatTimer.h"
+
+#include <algorithm>
+
+
+TypeHandle CullBinFrontToBack::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFrontToBack::Destructor
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+CullBinFrontToBack::
+~CullBinFrontToBack() {
+  Objects::iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi)._object;
+    delete object;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFrontToBack::make_bin
+//       Access: Public, Static
+//  Description: Factory constructor for passing to the CullBinManager.
+////////////////////////////////////////////////////////////////////
+CullBin *CullBinFrontToBack::
+make_bin(const string &name, GraphicsStateGuardianBase *gsg) {
+  return new CullBinFrontToBack(name, gsg);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFrontToBack::add_object
+//       Access: Public, Virtual
+//  Description: Adds a geom, along with its associated state, to
+//               the bin for rendering.
+////////////////////////////////////////////////////////////////////
+void CullBinFrontToBack::
+add_object(CullableObject *object) {
+  // Determine the center of the bounding volume.
+  CPT(BoundingVolume) volume = object->_geom->get_bounds();
+
+  if (!volume->is_empty() &&
+      volume->is_of_type(GeometricBoundingVolume::get_class_type())) {
+    const GeometricBoundingVolume *gbv;
+    DCAST_INTO_V(gbv, volume);
+    
+    LPoint3f center = gbv->get_approx_center();
+    nassertv(object->_modelview_transform != (const TransformState *)NULL);
+    center = center * object->_modelview_transform->get_mat();
+    
+    float distance = _gsg->compute_distance_to(center);
+    _objects.push_back(ObjectData(object, distance));
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFrontToBack::finish_cull
+//       Access: Public
+//  Description: Called after all the geoms have been added, this
+//               indicates that the cull process is finished for this
+//               frame and gives the bins a chance to do any
+//               post-processing (like sorting) before moving on to
+//               draw.
+////////////////////////////////////////////////////////////////////
+void CullBinFrontToBack::
+finish_cull() {
+  PStatTimer timer(_cull_this_pcollector);
+  sort(_objects.begin(), _objects.end());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinFrontToBack::draw
+//       Access: Public
+//  Description: Draws all the geoms in the bin, in the appropriate
+//               order.
+////////////////////////////////////////////////////////////////////
+void CullBinFrontToBack::
+draw() {
+  PStatTimer timer(_draw_this_pcollector);
+  Objects::const_iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi)._object;
+    CullHandler::draw(object, _gsg);
+  }
+}
+

+ 86 - 0
panda/src/cull/cullBinFrontToBack.h

@@ -0,0 +1,86 @@
+// Filename: cullBinFrontToBack.h
+// Created by:  drose (29May02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CULLBINFRONTTOBACK_H
+#define CULLBINFRONTTOBACK_H
+
+#include "pandabase.h"
+
+#include "cullBin.h"
+#include "geom.h"
+#include "transformState.h"
+#include "renderState.h"
+#include "pointerTo.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CullBinFrontToBack
+// Description : A specific kind of CullBin that sorts geometry in
+//               order from nearest to furthest based on the center of
+//               its bounding volume.
+//
+//               This is useful for rendering opaque geometry, taking
+//               optimal advantage of a hierarchical Z-buffer.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA CullBinFrontToBack : public CullBin {
+public:
+  INLINE CullBinFrontToBack(const string &name, GraphicsStateGuardianBase *gsg);
+  virtual ~CullBinFrontToBack();
+
+  static CullBin *make_bin(const string &name, GraphicsStateGuardianBase *gsg);
+
+  virtual void add_object(CullableObject *object);
+  virtual void finish_cull();
+  virtual void draw();
+
+private:
+  class ObjectData {
+  public:
+    INLINE ObjectData(CullableObject *object, float dist);
+    INLINE bool operator < (const ObjectData &other) const;
+    
+    CullableObject *_object;
+    float _dist;
+  };
+
+  typedef pvector<ObjectData> Objects;
+  Objects _objects;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CullBin::init_type();
+    register_type(_type_handle, "CullBinFrontToBack",
+                  CullBin::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cullBinFrontToBack.I"
+
+#endif
+
+
+  

+ 75 - 0
panda/src/cull/cullBinStateSorted.I

@@ -0,0 +1,75 @@
+// Filename: cullBinStateSorted.I
+// Created by:  drose (22Mar05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinStateSorted::ObjectData::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE CullBinStateSorted::ObjectData::
+ObjectData(CullableObject *object) :
+  _object(object)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinStateSorted::ObjectData::operator <
+//       Access: Public
+//  Description: Specifies the correct sort ordering for these
+//               objects.
+////////////////////////////////////////////////////////////////////
+INLINE bool CullBinStateSorted::ObjectData::
+operator < (const ObjectData &other) const {
+  const RenderState *sa = _object->_state;
+  const RenderState *sb = other._object->_state;
+
+  if (sa != sb) {
+    // First, group objects by texture, since conventional wisdom is
+    // that texture changes are the most expensive state changes in a
+    // graphics context.
+    const TextureAttrib *ta = sa->get_texture();
+    const TextureAttrib *tb = sb->get_texture();
+    if (ta != tb) {
+      return ta < tb;
+    }
+  }
+
+  // Then group objects by transform, since these are supposed to be
+  // expensive too.
+  if (_object->_modelview_transform != other._object->_modelview_transform) {
+    return _object->_modelview_transform < other._object->_modelview_transform;
+  }
+      
+  // Then, sort by all the other states, in no particular order,
+  // just as long as objects with identical state are all grouped
+  // together.
+  return sa < sb;
+}
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinStateSorted::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE CullBinStateSorted::
+CullBinStateSorted(const string &name, GraphicsStateGuardianBase *gsg) :
+  CullBin(name, gsg)
+{
+}

+ 97 - 0
panda/src/cull/cullBinStateSorted.cxx

@@ -0,0 +1,97 @@
+// Filename: cullBinStateSorted.cxx
+// Created by:  drose (22Mar05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cullBinStateSorted.h"
+#include "graphicsStateGuardianBase.h"
+#include "geometricBoundingVolume.h"
+#include "cullableObject.h"
+#include "cullHandler.h"
+#include "pStatTimer.h"
+
+#include <algorithm>
+
+
+TypeHandle CullBinStateSorted::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinStateSorted::Destructor
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+CullBinStateSorted::
+~CullBinStateSorted() {
+  Objects::iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi)._object;
+    delete object;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinStateSorted::make_bin
+//       Access: Public, Static
+//  Description: Factory constructor for passing to the CullBinManager.
+////////////////////////////////////////////////////////////////////
+CullBin *CullBinStateSorted::
+make_bin(const string &name, GraphicsStateGuardianBase *gsg) {
+  return new CullBinStateSorted(name, gsg);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinStateSorted::add_object
+//       Access: Public, Virtual
+//  Description: Adds a geom, along with its associated state, to
+//               the bin for rendering.
+////////////////////////////////////////////////////////////////////
+void CullBinStateSorted::
+add_object(CullableObject *object) {
+  _objects.push_back(ObjectData(object));
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinStateSorted::finish_cull
+//       Access: Public
+//  Description: Called after all the geoms have been added, this
+//               indicates that the cull process is finished for this
+//               frame and gives the bins a chance to do any
+//               post-processing (like sorting) before moving on to
+//               draw.
+////////////////////////////////////////////////////////////////////
+void CullBinStateSorted::
+finish_cull() {
+  PStatTimer timer(_cull_this_pcollector);
+  sort(_objects.begin(), _objects.end());
+}
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinStateSorted::draw
+//       Access: Public
+//  Description: Draws all the geoms in the bin, in the appropriate
+//               order.
+////////////////////////////////////////////////////////////////////
+void CullBinStateSorted::
+draw() {
+  PStatTimer timer(_draw_this_pcollector);
+  Objects::const_iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi)._object;
+    CullHandler::draw(object, _gsg);
+  }
+}
+

+ 89 - 0
panda/src/cull/cullBinStateSorted.h

@@ -0,0 +1,89 @@
+// Filename: cullBinStateSorted.h
+// Created by:  drose (22Mar05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CULLBINSTATESORTED_H
+#define CULLBINSTATESORTED_H
+
+#include "pandabase.h"
+
+#include "cullBin.h"
+#include "cullableObject.h"
+#include "geom.h"
+#include "transformState.h"
+#include "renderState.h"
+#include "pointerTo.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CullBinStateSorted
+// Description : A specific kind of CullBin that sorts geometry to
+//               collect items of the same state together, so that
+//               minimal state changes are required on the GSG to
+//               render them.
+//
+//               This also sorts objects front-to-back within a
+//               particular state, to take advantage of hierarchical
+//               Z-buffer algorithms which can early-out when an
+//               object appears behind another one.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA CullBinStateSorted : public CullBin {
+public:
+  INLINE CullBinStateSorted(const string &name, GraphicsStateGuardianBase *gsg);
+  virtual ~CullBinStateSorted();
+
+  static CullBin *make_bin(const string &name, GraphicsStateGuardianBase *gsg);
+
+  virtual void add_object(CullableObject *object);
+  virtual void finish_cull();
+  virtual void draw();
+
+private:
+  class ObjectData {
+  public:
+    INLINE ObjectData(CullableObject *object);
+    INLINE bool operator < (const ObjectData &other) const;
+    
+    CullableObject *_object;
+  };
+
+  typedef pvector<ObjectData> Objects;
+  Objects _objects;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CullBin::init_type();
+    register_type(_type_handle, "CullBinStateSorted",
+                  CullBin::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cullBinStateSorted.I"
+
+#endif
+
+
+  

+ 29 - 0
panda/src/cull/cullBinUnsorted.I

@@ -0,0 +1,29 @@
+// Filename: cullBinUnsorted.I
+// Created by:  drose (28Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinUnsorted::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE CullBinUnsorted::
+CullBinUnsorted(const string &name, GraphicsStateGuardianBase *gsg) :
+  CullBin(name, gsg)
+{
+}

+ 77 - 0
panda/src/cull/cullBinUnsorted.cxx

@@ -0,0 +1,77 @@
+// Filename: cullBinUnsorted.cxx
+// Created by:  drose (28Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cullBinUnsorted.h"
+#include "cullHandler.h"
+#include "graphicsStateGuardianBase.h"
+#include "pStatTimer.h"
+
+
+TypeHandle CullBinUnsorted::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinUnsorted::Destructor
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+CullBinUnsorted::
+~CullBinUnsorted() {
+  Objects::iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi);
+    delete object;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinUnsorted::make_bin
+//       Access: Public, Static
+//  Description: Factory constructor for passing to the CullBinManager.
+////////////////////////////////////////////////////////////////////
+CullBin *CullBinUnsorted::
+make_bin(const string &name, GraphicsStateGuardianBase *gsg) {
+  return new CullBinUnsorted(name, gsg);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinUnsorted::add_object
+//       Access: Public, Virtual
+//  Description: Adds a geom, along with its associated state, to
+//               the bin for rendering.
+////////////////////////////////////////////////////////////////////
+void CullBinUnsorted::
+add_object(CullableObject *object) {
+  _objects.push_back(object);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinUnsorted::draw
+//       Access: Public
+//  Description: Draws all the objects in the bin, in the appropriate
+//               order.
+////////////////////////////////////////////////////////////////////
+void CullBinUnsorted::
+draw() {
+  PStatTimer timer(_draw_this_pcollector);
+  Objects::iterator oi;
+  for (oi = _objects.begin(); oi != _objects.end(); ++oi) {
+    CullableObject *object = (*oi);
+    CullHandler::draw(object, _gsg);
+  }
+}
+

+ 71 - 0
panda/src/cull/cullBinUnsorted.h

@@ -0,0 +1,71 @@
+// Filename: cullBinUnsorted.h
+// Created by:  drose (28Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CULLBINUNSORTED_H
+#define CULLBINUNSORTED_H
+
+#include "pandabase.h"
+
+#include "cullBin.h"
+#include "pointerTo.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CullBinUnsorted
+// Description : A specific kind of CullBin that does not reorder the
+//               geometry; it simply passes it through to the GSG in
+//               the same order it was encountered, which will be in
+//               scene-graph order.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA CullBinUnsorted : public CullBin {
+public:
+  INLINE CullBinUnsorted(const string &name, GraphicsStateGuardianBase *gsg);
+  ~CullBinUnsorted();
+
+  static CullBin *make_bin(const string &name, GraphicsStateGuardianBase *gsg);
+
+  virtual void add_object(CullableObject *object);
+  virtual void draw();
+
+private:
+  typedef pvector<CullableObject *> Objects;
+  Objects _objects;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    CullBin::init_type();
+    register_type(_type_handle, "CullBinUnsorted",
+                  CullBin::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "cullBinUnsorted.I"
+
+#endif
+
+
+  

+ 4 - 0
panda/src/cull/cull_composite1.cxx

@@ -0,0 +1,4 @@
+#include "binCullHandler.cxx"
+#include "config_cull.cxx"
+#include "cullBinBackToFront.cxx"
+#include "cullBinFixed.cxx"

+ 4 - 0
panda/src/cull/cull_composite2.cxx

@@ -0,0 +1,4 @@
+#include "cullBinFrontToBack.cxx"
+#include "cullBinStateSorted.cxx"
+#include "cullBinUnsorted.cxx"
+#include "drawCullHandler.cxx"

+ 29 - 0
panda/src/cull/drawCullHandler.I

@@ -0,0 +1,29 @@
+// Filename: drawCullHandler.I
+// Created by:  drose (25Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: DrawCullHandler::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+INLINE DrawCullHandler::
+DrawCullHandler(GraphicsStateGuardianBase *gsg) :
+  _gsg(gsg)
+{
+}

+ 43 - 0
panda/src/cull/drawCullHandler.cxx

@@ -0,0 +1,43 @@
+// Filename: drawCullHandler.cxx
+// Created by:  drose (25Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "drawCullHandler.h"
+#include "cullableObject.h"
+#include "geom.h"
+#include "transformState.h"
+#include "renderState.h"
+#include "graphicsStateGuardianBase.h"
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: DrawCullHandler::record_object
+//       Access: Public, Virtual
+//  Description: This callback function is intended to be overridden
+//               by a derived class.  This is called as each Geom is
+//               discovered by the CullTraverser.
+////////////////////////////////////////////////////////////////////
+void DrawCullHandler::
+record_object(CullableObject *object, const CullTraverser *traverser) {
+  // Munge vertices as needed for the GSG's requirements, and the
+  // object's current state.
+  object->munge_geom(_gsg, _gsg->get_geom_munger(object->_state), traverser);
+
+  // And draw the object, then dispense with it.
+  draw(object, _gsg);
+  delete object;
+}

+ 54 - 0
panda/src/cull/drawCullHandler.h

@@ -0,0 +1,54 @@
+// Filename: drawCullHandler.h
+// Created by:  drose (25Feb02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef DRAWCULLHANDLER_H
+#define DRAWCULLHANDLER_H
+
+#include "pandabase.h"
+#include "cullHandler.h"
+
+class GraphicsStateGuardianBase;
+
+////////////////////////////////////////////////////////////////////
+//       Class : DrawCullHandler
+// Description : This special kind of CullHandler immediately draws
+//               its contents as soon as it receives them.  This draws
+//               geometry immediately as it is encountered in the
+//               scene graph by cull, mixing the draw and cull
+//               traversals into one traversal, and prohibiting state
+//               sorting.  However, it has somewhat lower overhead
+//               than separating out draw and cull, if state sorting
+//               and multiprocessing are not required.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA DrawCullHandler : public CullHandler {
+public:
+  INLINE DrawCullHandler(GraphicsStateGuardianBase *gsg);
+
+  virtual void record_object(CullableObject *object, 
+                             const CullTraverser *traverser);
+
+private:
+  GraphicsStateGuardianBase *_gsg;
+};
+
+#include "drawCullHandler.I"
+
+#endif
+
+
+  

+ 0 - 21
panda/src/pgraph/Sources.pp

@@ -17,7 +17,6 @@
     auxSceneData.I auxSceneData.h \
     bamFile.I bamFile.h \
     billboardEffect.I billboardEffect.h \
-    binCullHandler.I binCullHandler.h \
     camera.I camera.h \
     clipPlaneAttrib.I clipPlaneAttrib.h \
     colorAttrib.I colorAttrib.h \
@@ -28,12 +27,7 @@
     config_pgraph.h \
     cullBin.I cullBin.h \
     cullBinAttrib.I cullBinAttrib.h \
-    cullBinBackToFront.I cullBinBackToFront.h \
-    cullBinFixed.I cullBinFixed.h \
-    cullBinFrontToBack.I cullBinFrontToBack.h \
     cullBinManager.I cullBinManager.h \
-    cullBinStateSorted.I cullBinStateSorted.h \
-    cullBinUnsorted.I cullBinUnsorted.h \
     cullFaceAttrib.I cullFaceAttrib.h \
     cullHandler.I cullHandler.h \
     cullPlanes.I cullPlanes.h \
@@ -46,7 +40,6 @@
     depthTestAttrib.I depthTestAttrib.h \
     depthWriteAttrib.I depthWriteAttrib.h \
     directionalLight.I directionalLight.h \
-    drawCullHandler.I drawCullHandler.h \
     drawMaskAttrib.I drawMaskAttrib.h \
     fadeLodNode.I fadeLodNode.h fadeLodNodeData.h \
     findApproxLevelEntry.I findApproxLevelEntry.h \
@@ -126,7 +119,6 @@
     auxSceneData.cxx \
     bamFile.cxx \
     billboardEffect.cxx \
-    binCullHandler.cxx \
     camera.cxx \
     clipPlaneAttrib.cxx \
     colorAttrib.cxx \
@@ -137,12 +129,7 @@
     config_pgraph.cxx \
     cullBin.cxx \
     cullBinAttrib.cxx \
-    cullBinBackToFront.cxx \
-    cullBinFixed.cxx \
-    cullBinFrontToBack.cxx \
     cullBinManager.cxx \
-    cullBinStateSorted.cxx \
-    cullBinUnsorted.cxx \
     cullFaceAttrib.cxx \
     cullHandler.cxx \
     cullPlanes.cxx \
@@ -155,7 +142,6 @@
     depthTestAttrib.cxx \
     depthWriteAttrib.cxx \
     directionalLight.cxx \
-    drawCullHandler.cxx \
     drawMaskAttrib.cxx \
     fadeLodNode.cxx fadeLodNodeData.cxx \
     findApproxLevelEntry.cxx \
@@ -231,7 +217,6 @@
     auxSceneData.I auxSceneData.h \
     bamFile.I bamFile.h \
     billboardEffect.I billboardEffect.h \
-    binCullHandler.I binCullHandler.h \
     camera.I camera.h \
     clipPlaneAttrib.I clipPlaneAttrib.h \
     colorAttrib.I colorAttrib.h \
@@ -242,12 +227,7 @@
     config_pgraph.h \
     cullBin.I cullBin.h \
     cullBinAttrib.I cullBinAttrib.h \
-    cullBinBackToFront.I cullBinBackToFront.h \
-    cullBinFixed.I cullBinFixed.h \
-    cullBinFrontToBack.I cullBinFrontToBack.h \
     cullBinManager.I cullBinManager.h \
-    cullBinStateSorted.I cullBinStateSorted.h \
-    cullBinUnsorted.I cullBinUnsorted.h \
     cullFaceAttrib.I cullFaceAttrib.h \
     cullHandler.I cullHandler.h \
     cullPlanes.I cullPlanes.h \
@@ -260,7 +240,6 @@
     depthTestAttrib.I depthTestAttrib.h \
     depthWriteAttrib.I depthWriteAttrib.h \
     directionalLight.I directionalLight.h \
-    drawCullHandler.I drawCullHandler.h \
     drawMaskAttrib.I drawMaskAttrib.h \
     fadeLodNode.I fadeLodNode.h fadeLodNodeData.h \
     fog.I fog.h \

+ 0 - 10
panda/src/pgraph/config_pgraph.cxx

@@ -33,11 +33,6 @@
 #include "cullFaceAttrib.h"
 #include "cullBin.h"
 #include "cullBinAttrib.h"
-#include "cullBinBackToFront.h"
-#include "cullBinFixed.h"
-#include "cullBinFrontToBack.h"
-#include "cullBinStateSorted.h"
-#include "cullBinUnsorted.h"
 #include "cullTraverser.h"
 #include "cullableObject.h"
 #include "decalEffect.h"
@@ -276,11 +271,6 @@ init_libpgraph() {
   CullFaceAttrib::init_type();
   CullBin::init_type();
   CullBinAttrib::init_type();
-  CullBinBackToFront::init_type();
-  CullBinFixed::init_type();
-  CullBinFrontToBack::init_type();
-  CullBinStateSorted::init_type();
-  CullBinUnsorted::init_type();
   CullTraverser::init_type();
   CullableObject::init_type();
   DecalEffect::init_type();

+ 23 - 15
panda/src/pgraph/cullBinManager.cxx

@@ -17,11 +17,13 @@
 ////////////////////////////////////////////////////////////////////
 
 #include "cullBinManager.h"
+/*
 #include "cullBinBackToFront.h"
 #include "cullBinFrontToBack.h"
 #include "cullBinFixed.h"
 #include "cullBinStateSorted.h"
 #include "cullBinUnsorted.h"
+*/
 #include "renderState.h"
 #include "cullResult.h"
 #include "config_pgraph.h"
@@ -49,7 +51,7 @@ CullBinManager() {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: CullBinManager::Destructor
-//       Access: Protected
+//       Access: Protected, Virtual
 //  Description: Don't call the destructor.
 ////////////////////////////////////////////////////////////////////
 CullBinManager::
@@ -221,22 +223,28 @@ make_new_bin(int bin_index, GraphicsStateGuardianBase *gsg) {
   nassertr(_bin_definitions[bin_index]._in_use, NULL);
   string name = get_bin_name(bin_index);
 
-  switch (_bin_definitions[bin_index]._type) {
-  case BT_back_to_front:
-    return new CullBinBackToFront(name, gsg);
-
-  case BT_front_to_back:
-    return new CullBinFrontToBack(name, gsg);
-
-  case BT_fixed:
-    return new CullBinFixed(name, gsg);
+  BinType type = _bin_definitions[bin_index]._type;
+  BinConstructors::const_iterator ci = _bin_constructors.find(type);
+  if (ci != _bin_constructors.end()) {
+    BinConstructor *constructor = (*ci).second;
+    return constructor(name, gsg);
+  }
 
-  case BT_state_sorted:
-    return new CullBinStateSorted(name, gsg);
+  // Hmm, unknown (or unregistered) bin type.
+  nassertr(false, NULL);
+  return NULL;
+}
 
-  default:
-    return new CullBinUnsorted(name, gsg);
-  }
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinManager::register_bin_type
+//       Access: Public
+//  Description: Intended to be called at startup type by each CullBin
+//               type, to register the constructor for each type.
+////////////////////////////////////////////////////////////////////
+void CullBinManager::
+register_bin_type(BinType type, CullBinManager::BinConstructor *constructor) {
+  bool inserted = _bin_constructors.insert(BinConstructors::value_type(type, constructor)).second;
+  nassertv(inserted);
 }
 
 ////////////////////////////////////////////////////////////////////

+ 10 - 0
panda/src/pgraph/cullBinManager.h

@@ -70,6 +70,13 @@ public:
   // This interface is only intended to be used by CullResult.
   PT(CullBin) make_new_bin(int bin_index, GraphicsStateGuardianBase *gsg);
 
+  // This defines the factory interface for defining constructors to
+  // bin types (the implementations are in the cull directory, not
+  // here in pgraph, so we can't call the constructors directly).
+  typedef CullBin *BinConstructor(const string &name, GraphicsStateGuardianBase *gsg);
+
+  void register_bin_type(BinType type, BinConstructor *constructor);
+
 private:
   void do_sort_bins();
   void setup_initial_bins();
@@ -100,6 +107,9 @@ private:
   bool _bins_are_sorted;
   bool _unused_bin_index;
 
+  typedef pmap<BinType, BinConstructor *> BinConstructors;
+  BinConstructors _bin_constructors;
+
   static CullBinManager *_global_ptr;
   friend class SortBins;
 };

+ 0 - 1
panda/src/pgraph/pgraph_composite1.cxx

@@ -5,7 +5,6 @@
 #include "attribSlots.cxx"
 #include "bamFile.cxx"
 #include "billboardEffect.cxx"
-#include "binCullHandler.cxx"
 #include "camera.cxx"
 #include "clipPlaneAttrib.cxx"
 #include "colorAttrib.cxx"

+ 0 - 6
panda/src/pgraph/pgraph_composite2.cxx

@@ -1,11 +1,6 @@
 #include "cullBin.cxx"
 #include "cullBinAttrib.cxx"
-#include "cullBinBackToFront.cxx"
-#include "cullBinFixed.cxx"
-#include "cullBinFrontToBack.cxx"
 #include "cullBinManager.cxx"
-#include "cullBinStateSorted.cxx"
-#include "cullBinUnsorted.cxx"
 #include "cullFaceAttrib.cxx"
 #include "cullHandler.cxx"
 #include "cullPlanes.cxx"
@@ -19,7 +14,6 @@
 #include "depthWriteAttrib.cxx"
 #include "alphaTestAttrib.cxx"
 #include "directionalLight.cxx"
-#include "drawCullHandler.cxx"
 #include "drawMaskAttrib.cxx"
 #include "fadeLodNode.cxx"
 #include "fadeLodNodeData.cxx"