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::get_hash_impl
00102 //       Access: Protected, Virtual
00103 //  Description: Intended to be overridden by derived RenderAttrib
00104 //               types to return a unique hash for these particular
00105 //               properties.  RenderAttribs that compare the same with
00106 //               compare_to_impl(), above, should return the same
00107 //               hash; RenderAttribs that compare differently should
00108 //               return a different hash.
00109 ////////////////////////////////////////////////////////////////////
00110 size_t AuxBitplaneAttrib::
00111 get_hash_impl() const {
00112   size_t hash = 0;
00113   hash = int_hash::add_hash(hash, _outputs);
00114   return hash;
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: AuxBitplaneAttrib::get_auto_shader_attrib_impl
00119 //       Access: Protected, Virtual
00120 //  Description: 
00121 ////////////////////////////////////////////////////////////////////
00122 CPT(RenderAttrib) AuxBitplaneAttrib::
00123 get_auto_shader_attrib_impl(const RenderState *state) const {
00124   return this;
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: AuxBitplaneAttrib::register_with_read_factory
00129 //       Access: Public, Static
00130 //  Description: Tells the BamReader how to create objects of type
00131 //               AuxBitplaneAttrib.
00132 ////////////////////////////////////////////////////////////////////
00133 void AuxBitplaneAttrib::
00134 register_with_read_factory() {
00135   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00136 }
00137 
00138 ////////////////////////////////////////////////////////////////////
00139 //     Function: AuxBitplaneAttrib::write_datagram
00140 //       Access: Public, Virtual
00141 //  Description: Writes the contents of this object to the datagram
00142 //               for shipping out to a Bam file.
00143 ////////////////////////////////////////////////////////////////////
00144 void AuxBitplaneAttrib::
00145 write_datagram(BamWriter *manager, Datagram &dg) {
00146   RenderAttrib::write_datagram(manager, dg);
00147 
00148   dg.add_int32(_outputs);
00149 }
00150 
00151 ////////////////////////////////////////////////////////////////////
00152 //     Function: AuxBitplaneAttrib::make_from_bam
00153 //       Access: Protected, Static
00154 //  Description: This function is called by the BamReader's factory
00155 //               when a new object of type AuxBitplaneAttrib is encountered
00156 //               in the Bam file.  It should create the AuxBitplaneAttrib
00157 //               and extract its information from the file.
00158 ////////////////////////////////////////////////////////////////////
00159 TypedWritable *AuxBitplaneAttrib::
00160 make_from_bam(const FactoryParams &params) {
00161   AuxBitplaneAttrib *attrib = new AuxBitplaneAttrib(0);
00162   DatagramIterator scan;
00163   BamReader *manager;
00164 
00165   parse_params(params, scan, manager);
00166   attrib->fillin(scan, manager);
00167   
00168   return attrib;
00169 }
00170 
00171 ////////////////////////////////////////////////////////////////////
00172 //     Function: AuxBitplaneAttrib::fillin
00173 //       Access: Protected
00174 //  Description: This internal function is called by make_from_bam to
00175 //               read in all of the relevant data from the BamFile for
00176 //               the new AuxBitplaneAttrib.
00177 ////////////////////////////////////////////////////////////////////
00178 void AuxBitplaneAttrib::
00179 fillin(DatagramIterator &scan, BamReader *manager) {
00180   RenderAttrib::fillin(scan, manager);
00181 
00182   _outputs = scan.get_int32();
00183 }
 All Classes Functions Variables Enumerations