Panda3D

auxBitplaneAttrib.cxx

00001 // Filename: auxBitplaneAttrib.cxx
00002 // Created by:  drose (04Mar02)
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 "auxBitplaneAttrib.h"
00016 #include "graphicsStateGuardianBase.h"
00017 #include "dcast.h"
00018 #include "bamReader.h"
00019 #include "bamWriter.h"
00020 #include "datagram.h"
00021 #include "datagramIterator.h"
00022 
00023 TypeHandle AuxBitplaneAttrib::_type_handle;
00024 int AuxBitplaneAttrib::_attrib_slot;
00025 CPT(RenderAttrib) AuxBitplaneAttrib::_default;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: AuxBitplaneAttrib::make
00029 //       Access: Published, Static
00030 //  Description: Constructs a default AuxBitplaneAttrib object.
00031 ////////////////////////////////////////////////////////////////////
00032 CPT(RenderAttrib) AuxBitplaneAttrib::
00033 make() {
00034   if (_default == 0) {
00035     AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(0);
00036     _default = return_new(attrib);
00037   }
00038   return _default;
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: AuxBitplaneAttrib::make
00043 //       Access: Published, Static
00044 //  Description: Constructs a specified AuxBitplaneAttrib object.
00045 ////////////////////////////////////////////////////////////////////
00046 CPT(RenderAttrib) AuxBitplaneAttrib::
00047 make(int outputs) {
00048   AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(outputs);
00049   return return_new(attrib);
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: AuxBitplaneAttrib::make_default
00054 //       Access: Published, Static
00055 //  Description: Returns a RenderAttrib that corresponds to whatever
00056 //               the standard default properties for render attributes
00057 //               of this type ought to be.
00058 ////////////////////////////////////////////////////////////////////
00059 CPT(RenderAttrib) AuxBitplaneAttrib::
00060 make_default() {
00061   return return_new(new AuxBitplaneAttrib(0));
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: AuxBitplaneAttrib::output
00066 //       Access: Public, Virtual
00067 //  Description: 
00068 ////////////////////////////////////////////////////////////////////
00069 void AuxBitplaneAttrib::
00070 output(ostream &out) const {
00071   out << get_type() << "(" << _outputs << ")";
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: AuxBitplaneAttrib::compare_to_impl
00076 //       Access: Protected, Virtual
00077 //  Description: Intended to be overridden by derived AuxBitplaneAttrib
00078 //               types to return a unique number indicating whether
00079 //               this AuxBitplaneAttrib is equivalent to the other one.
00080 //
00081 //               This should return 0 if the two AuxBitplaneAttrib objects
00082 //               are equivalent, a number less than zero if this one
00083 //               should be sorted before the other one, and a number
00084 //               greater than zero otherwise.
00085 //
00086 //               This will only be called with two AuxBitplaneAttrib
00087 //               objects whose get_type() functions return the same.
00088 ////////////////////////////////////////////////////////////////////
00089 int AuxBitplaneAttrib::
00090 compare_to_impl(const RenderAttrib *other) const {
00091   const AuxBitplaneAttrib *ta;
00092   DCAST_INTO_R(ta, other, 0);
00093   int compare_result = _outputs - ta->_outputs;
00094   if (compare_result!=0) {
00095     return compare_result;
00096   }
00097   return 0;
00098 }
00099 
00100 ////////////////////////////////////////////////////////////////////
00101 //     Function: AuxBitplaneAttrib::register_with_read_factory
00102 //       Access: Public, Static
00103 //  Description: Tells the BamReader how to create objects of type
00104 //               AuxBitplaneAttrib.
00105 ////////////////////////////////////////////////////////////////////
00106 void AuxBitplaneAttrib::
00107 register_with_read_factory() {
00108   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: AuxBitplaneAttrib::write_datagram
00113 //       Access: Public, Virtual
00114 //  Description: Writes the contents of this object to the datagram
00115 //               for shipping out to a Bam file.
00116 ////////////////////////////////////////////////////////////////////
00117 void AuxBitplaneAttrib::
00118 write_datagram(BamWriter *manager, Datagram &dg) {
00119   RenderAttrib::write_datagram(manager, dg);
00120 
00121   dg.add_int32(_outputs);
00122 }
00123 
00124 ////////////////////////////////////////////////////////////////////
00125 //     Function: AuxBitplaneAttrib::make_from_bam
00126 //       Access: Protected, Static
00127 //  Description: This function is called by the BamReader's factory
00128 //               when a new object of type AuxBitplaneAttrib is encountered
00129 //               in the Bam file.  It should create the AuxBitplaneAttrib
00130 //               and extract its information from the file.
00131 ////////////////////////////////////////////////////////////////////
00132 TypedWritable *AuxBitplaneAttrib::
00133 make_from_bam(const FactoryParams &params) {
00134   AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(0);
00135   DatagramIterator scan;
00136   BamReader *manager;
00137 
00138   parse_params(params, scan, manager);
00139   attrib->fillin(scan, manager);
00140   
00141   return attrib;
00142 }
00143 
00144 ////////////////////////////////////////////////////////////////////
00145 //     Function: AuxBitplaneAttrib::fillin
00146 //       Access: Protected
00147 //  Description: This internal function is called by make_from_bam to
00148 //               read in all of the relevant data from the BamFile for
00149 //               the new AuxBitplaneAttrib.
00150 ////////////////////////////////////////////////////////////////////
00151 void AuxBitplaneAttrib::
00152 fillin(DatagramIterator &scan, BamReader *manager) {
00153   RenderAttrib::fillin(scan, manager);
00154 
00155   _outputs = scan.get_int32();
00156 }
 All Classes Functions Variables Enumerations