Răsfoiți Sursa

pgraph named bins

David Rose 24 ani în urmă
părinte
comite
05fea3893d

+ 10 - 10
panda/src/egg2pg/qpeggLoader.cxx

@@ -26,6 +26,7 @@
 #include "texturePool.h"
 #include "billboardAttrib.h"
 #include "cullFaceAttrib.h"
+#include "cullBinAttrib.h"
 #include "transparencyAttrib.h"
 #include "qpgeomNode.h"
 #include "string_utils.h"
@@ -995,7 +996,7 @@ setup_bucket(BuilderBucket &bucket, PandaNode *parent,
     const TextureDef &def = _textures[egg_tex];
     if (def._texture != (const RenderAttrib *)NULL) {
       bucket.add_attrib(def._texture);
-      //      bucket._trans.set_transition(def._apply);
+      //      bucket.add_attrib(def._apply);
 
       // If neither the primitive nor the texture specified an alpha
       // mode, assume it should be alpha'ed if the texture has an
@@ -1016,7 +1017,7 @@ setup_bucket(BuilderBucket &bucket, PandaNode *parent,
   if (egg_prim->has_material()) {
     MaterialTransition *mt = get_material_transition(egg_prim->get_material(),
                                                      egg_prim->get_bface_flag());
-    bucket._trans.set_transition(mt);
+    bucket.add_attrib(mt);
   }
   */
 
@@ -1072,11 +1073,11 @@ setup_bucket(BuilderBucket &bucket, PandaNode *parent,
   /*
   switch (dwm) {
   case EggRenderMode::DWM_on:
-    bucket._trans.set_transition(new DepthWriteTransition);
+    bucket.add_attrib(new DepthWriteTransition);
     break;
 
   case EggRenderMode::DWM_off:
-    bucket._trans.set_transition(new DepthWriteTransition(DepthWriteTransition::off()));
+    bucket.add_attrib(new DepthWriteTransition(DepthWriteTransition::off()));
     break;
 
   default:
@@ -1087,11 +1088,11 @@ setup_bucket(BuilderBucket &bucket, PandaNode *parent,
   /*
   switch (dtm) {
   case EggRenderMode::DTM_on:
-    bucket._trans.set_transition(new DepthTestTransition(DepthTestProperty::M_less));
+    bucket.add_attrib(new DepthTestTransition(DepthTestProperty::M_less));
     break;
 
   case EggRenderMode::DTM_off:
-    bucket._trans.set_transition(new DepthTestTransition(DepthTestProperty::M_none));
+    bucket.add_attrib(new DepthTestTransition(DepthTestProperty::M_none));
     break;
 
   default:
@@ -1099,14 +1100,13 @@ setup_bucket(BuilderBucket &bucket, PandaNode *parent,
   }
   */
 
-  /*
   if (has_bin) {
-    bucket._trans.set_transition(new GeomBinTransition(bin, draw_order));
+    bucket.add_attrib(CullBinAttrib::make(bin, draw_order));
 
   } else if (has_draw_order) {
-    bucket._trans.set_transition(new GeomBinTransition("fixed", draw_order));
+    bucket.add_attrib(CullBinAttrib::make("fixed", draw_order));
   }
-  */
+ 
 
   if (egg_prim->get_bface_flag()) {
     // The primitive is marked with backface culling disabled--we want

+ 7 - 0
panda/src/glgsg/glGraphicsStateGuardian.cxx

@@ -4123,6 +4123,13 @@ get_texture_wrap_mode(Texture::WrapMode wm) {
     return GL_CLAMP;
   case Texture::WM_repeat:
     return GL_REPEAT;
+
+  case Texture::WM_mirror:
+  case Texture::WM_mirror_once:
+  case Texture::WM_border_color:
+    // These are unsupported for now.
+    return GL_REPEAT;
+
   case Texture::WM_invalid:
     break;
   }

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

@@ -12,6 +12,7 @@
     colorAttrib.h colorAttrib.I \
     config_pgraph.h \
     cullBin.h cullBin.I \
+    cullBinAttrib.h cullBinAttrib.I \
     cullBinBackToFront.h cullBinBackToFront.I \
     cullBinManager.h cullBinManager.I \
     cullBinUnsorted.h cullBinUnsorted.I \
@@ -44,6 +45,7 @@
     colorAttrib.cxx \
     config_pgraph.cxx \
     cullBin.cxx \
+    cullBinAttrib.cxx \
     cullBinBackToFront.cxx \
     cullBinManager.cxx \
     cullBinUnsorted.cxx \
@@ -81,6 +83,7 @@
     colorAttrib.h colorAttrib.I \
     config_pgraph.h \
     cullBin.h cullBin.I \
+    cullBinAttrib.h cullBinAttrib.I \
     cullBinBackToFront.h cullBinBackToFront.I \
     cullBinManager.h cullBinManager.I \
     cullBinUnsorted.h cullBinUnsorted.I \

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

@@ -23,6 +23,7 @@
 #include "colorAttrib.h"
 #include "cullFaceAttrib.h"
 #include "cullBin.h"
+#include "cullBinAttrib.h"
 #include "cullBinBackToFront.h"
 #include "cullBinUnsorted.h"
 #include "qpgeomNode.h"
@@ -68,6 +69,7 @@ init_libpgraph() {
   ColorAttrib::init_type();
   CullFaceAttrib::init_type();
   CullBin::init_type();
+  CullBinAttrib::init_type();
   CullBinBackToFront::init_type();
   CullBinUnsorted::init_type();
   qpGeomNode::init_type();

+ 54 - 0
panda/src/pgraph/cullBinAttrib.I

@@ -0,0 +1,54 @@
+// Filename: cullBinAttrib.I
+// Created by:  drose (01Mar02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::Constructor
+//       Access: Private
+//  Description: Use CullBinAttrib::make() to construct a new
+//               CullBinAttrib object.
+////////////////////////////////////////////////////////////////////
+INLINE CullBinAttrib::
+CullBinAttrib() {
+  _draw_order = 0;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::get_bin_name
+//       Access: Published
+//  Description: Returns the name of the bin this attribute specifies.
+//               If this is the empty string, it refers to the default
+//               bin.
+////////////////////////////////////////////////////////////////////
+INLINE const string &CullBinAttrib::
+get_bin_name() const {
+  return _bin_name;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::get_draw_order
+//       Access: Published
+//  Description: Returns the draw order this attribute specifies.
+//               Some bins (in particular, CullBinFixed bins) use this
+//               to further specify the order in which objects should
+//               be rendered.
+////////////////////////////////////////////////////////////////////
+INLINE int CullBinAttrib::
+get_draw_order() const {
+  return _draw_order;
+}

+ 151 - 0
panda/src/pgraph/cullBinAttrib.cxx

@@ -0,0 +1,151 @@
+// Filename: cullBinAttrib.cxx
+// Created by:  drose (01Mar02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "cullBinAttrib.h"
+#include "bamReader.h"
+#include "bamWriter.h"
+#include "datagram.h"
+#include "datagramIterator.h"
+
+TypeHandle CullBinAttrib::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::make
+//       Access: Published, Static
+//  Description: Constructs a new CullBinAttrib assigning geometry
+//               into the named bin.  If the bin name is the empty
+//               string, the default bin is used.
+//
+//               The draw_order specifies further ordering information
+//               which is relevant only to certain kinds of bins (in
+//               particular CullBinFixed type bins).
+////////////////////////////////////////////////////////////////////
+CPT(RenderAttrib) CullBinAttrib::
+make(const string &bin_name, int draw_order) {
+  CullBinAttrib *attrib = new CullBinAttrib;
+  attrib->_bin_name = bin_name;
+  attrib->_draw_order = draw_order;
+  return return_new(attrib);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::output
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void CullBinAttrib::
+output(ostream &out) const {
+  out << get_type() << ":";
+  if (_bin_name.empty()) {
+    out << "(default)";
+  } else {
+    out << _bin_name;
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::compare_to_impl
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by derived CullBinAttrib
+//               types to return a unique number indicating whether
+//               this CullBinAttrib is equivalent to the other one.
+//
+//               This should return 0 if the two CullBinAttrib objects
+//               are equivalent, a number less than zero if this one
+//               should be sorted before the other one, and a number
+//               greater than zero otherwise.
+//
+//               This will only be called with two CullBinAttrib
+//               objects whose get_type() functions return the same.
+////////////////////////////////////////////////////////////////////
+int CullBinAttrib::
+compare_to_impl(const RenderAttrib *other) const {
+  const CullBinAttrib *ta;
+  DCAST_INTO_R(ta, other, 0);
+  return strcmp(_bin_name.c_str(), ta->_bin_name.c_str());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::make_default_impl
+//       Access: Protected, Virtual
+//  Description: Intended to be overridden by derived CullBinAttrib
+//               types to specify what the default property for a
+//               CullBinAttrib of this type should be.
+//
+//               This should return a newly-allocated CullBinAttrib of
+//               the same type that corresponds to whatever the
+//               standard default for this kind of CullBinAttrib is.
+////////////////////////////////////////////////////////////////////
+RenderAttrib *CullBinAttrib::
+make_default_impl() const {
+  return new CullBinAttrib;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::register_with_read_factory
+//       Access: Public, Static
+//  Description: Tells the BamReader how to create objects of type
+//               CullBinAttrib.
+////////////////////////////////////////////////////////////////////
+void CullBinAttrib::
+register_with_read_factory() {
+  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::write_datagram
+//       Access: Public, Virtual
+//  Description: Writes the contents of this object to the datagram
+//               for shipping out to a Bam file.
+////////////////////////////////////////////////////////////////////
+void CullBinAttrib::
+write_datagram(BamWriter *manager, Datagram &dg) {
+  RenderAttrib::write_datagram(manager, dg);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::make_from_bam
+//       Access: Protected, Static
+//  Description: This function is called by the BamReader's factory
+//               when a new object of type CullBinAttrib is encountered
+//               in the Bam file.  It should create the CullBinAttrib
+//               and extract its information from the file.
+////////////////////////////////////////////////////////////////////
+TypedWritable *CullBinAttrib::
+make_from_bam(const FactoryParams &params) {
+  CullBinAttrib *attrib = new CullBinAttrib;
+  DatagramIterator scan;
+  BamReader *manager;
+
+  parse_params(params, scan, manager);
+  attrib->fillin(scan, manager);
+
+  return new_from_bam(attrib, manager);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CullBinAttrib::fillin
+//       Access: Protected
+//  Description: This internal function is called by make_from_bam to
+//               read in all of the relevant data from the BamFile for
+//               the new CullBinAttrib.
+////////////////////////////////////////////////////////////////////
+void CullBinAttrib::
+fillin(DatagramIterator &scan, BamReader *manager) {
+  RenderAttrib::fillin(scan, manager);
+}

+ 82 - 0
panda/src/pgraph/cullBinAttrib.h

@@ -0,0 +1,82 @@
+// Filename: cullBinAttrib.h
+// Created by:  drose (01Mar02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, 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://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CULLBINATTRIB_H
+#define CULLBINATTRIB_H
+
+#include "pandabase.h"
+
+#include "renderAttrib.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : CullBinAttrib
+// Description : Assigns geometry to a particular bin by name.  The
+//               bins must be created separately via the
+//               CullBinManager interface.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA CullBinAttrib : public RenderAttrib {
+private:
+  INLINE CullBinAttrib();
+
+PUBLISHED:
+  static CPT(RenderAttrib) make(const string &bin_name, int draw_order);
+
+  INLINE const string &get_bin_name() const;
+  INLINE int get_draw_order() const;
+
+public:
+  virtual void output(ostream &out) const;
+
+protected:
+  virtual int compare_to_impl(const RenderAttrib *other) const;
+  virtual RenderAttrib *make_default_impl() const;
+
+private:
+  string _bin_name;
+  int _draw_order;
+
+public:
+  static void register_with_read_factory();
+  virtual void write_datagram(BamWriter *manager, Datagram &dg);
+
+protected:
+  static TypedWritable *make_from_bam(const FactoryParams &params);
+  void fillin(DatagramIterator &scan, BamReader *manager);
+  
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    RenderAttrib::init_type();
+    register_type(_type_handle, "CullBinAttrib",
+                  RenderAttrib::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 "cullBinAttrib.I"
+
+#endif
+

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

@@ -4,6 +4,7 @@
 #include "colorAttrib.cxx"
 #include "config_pgraph.cxx"
 #include "cullBin.cxx"
+#include "cullBinAttrib.cxx"
 #include "cullBinBackToFront.cxx"
 #include "cullBinManager.cxx"
 #include "cullBinUnsorted.cxx"

+ 22 - 5
panda/src/pgraph/renderState.I

@@ -171,11 +171,11 @@ get_billboard() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: RenderState::get_bin_index
 //       Access: Public
-//  Description: Returns the bin index indicated by the CullBinAttrib
-//               transition, if any, associated by this state (or the
-//               default bin index if there is no CullBinAttrib).  As
-//               in get_billboard(), above, this function is provided
-//               as an optimization.
+//  Description: Returns the bin index indicated by the CullBinAttrib,
+//               if any, associated by this state (or the default bin
+//               index if there is no CullBinAttrib).  As in
+//               get_billboard(), above, this function is provided as
+//               an optimization.
 ////////////////////////////////////////////////////////////////////
 INLINE int RenderState::
 get_bin_index() const {
@@ -186,3 +186,20 @@ get_bin_index() const {
   }
   return _bin_index;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: RenderState::get_draw_order
+//       Access: Public
+//  Description: Returns the draw order indicated by the
+//               CullBinAttrib, if any, associated by this state (or 0
+//               if there is no CullBinAttrib).  See get_bin_index().
+////////////////////////////////////////////////////////////////////
+INLINE int RenderState::
+get_draw_order() const {
+  if ((_flags & F_checked_bin_index) == 0) {
+    // We pretend this function is const, even though it transparently
+    // modifies the internal draw_order cache.
+    ((RenderState *)this)->determine_bin_index();
+  }
+  return _draw_order;
+}

+ 7 - 5
panda/src/pgraph/renderState.cxx

@@ -19,6 +19,7 @@
 #include "renderState.h"
 #include "billboardAttrib.h"
 #include "transparencyAttrib.h"
+#include "cullBinAttrib.h"
 #include "cullBinManager.h"
 #include "config_pgraph.h"
 #include "bamReader.h"
@@ -863,19 +864,21 @@ determine_billboard() {
 //     Function: RenderState::determine_bin_index
 //       Access: Private
 //  Description: This is the private implementation of
-//               get_bin_index().
+//               get_bin_index() and get_draw_order().
 ////////////////////////////////////////////////////////////////////
 void RenderState::
 determine_bin_index() {
   string bin_name;
+  _draw_order = 0;
 
-  /*
   const RenderAttrib *attrib = get_attrib(CullBinAttrib::get_class_type());
   if (attrib != (const RenderAttrib *)NULL) {
     const CullBinAttrib *bin_attrib = DCAST(CullBinAttrib, attrib);
+    bin_name = bin_attrib->get_bin_name();
+    _draw_order = bin_attrib->get_draw_order();
   }
-  */
-  {
+
+  if (bin_name.empty()) {
     // No explicit bin is specified; put in the in the default bin,
     // either opaque or transparent, based on the transparency
     // setting.
@@ -897,7 +900,6 @@ determine_bin_index() {
     }
   }
 
-
   CullBinManager *bin_manager = CullBinManager::get_global_ptr();
   _bin_index = bin_manager->find_bin(bin_name);
   if (_bin_index == -1) {

+ 2 - 0
panda/src/pgraph/renderState.h

@@ -89,6 +89,7 @@ PUBLISHED:
 public:
   INLINE const BillboardAttrib *get_billboard() const;
   INLINE int get_bin_index() const;
+  INLINE int get_draw_order() const;
 
   CPT(RenderState) issue_delta_modify(const RenderState *other, 
                                       GraphicsStateGuardianBase *gsg) const;
@@ -161,6 +162,7 @@ private:
   
   // We also cache the index to the associated GeomBin.
   int _bin_index;
+  int _draw_order;
 
   enum Flags {
     F_checked_billboard    = 0x0001,