Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pgraph/colorWriteAttrib.cxx

Go to the documentation of this file.
00001 // Filename: colorWriteAttrib.cxx
00002 // Created by:  drose (04Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "colorWriteAttrib.h"
00020 #include "graphicsStateGuardianBase.h"
00021 #include "dcast.h"
00022 #include "bamReader.h"
00023 #include "bamWriter.h"
00024 #include "datagram.h"
00025 #include "datagramIterator.h"
00026 
00027 TypeHandle ColorWriteAttrib::_type_handle;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: ColorWriteAttrib::make
00031 //       Access: Published, Static
00032 //  Description: Constructs a new ColorWriteAttrib object.
00033 ////////////////////////////////////////////////////////////////////
00034 CPT(RenderAttrib) ColorWriteAttrib::
00035 make(ColorWriteAttrib::Mode mode) {
00036   ColorWriteAttrib *attrib = new ColorWriteAttrib(mode);
00037   return return_new(attrib);
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: ColorWriteAttrib::issue
00042 //       Access: Public, Virtual
00043 //  Description: Calls the appropriate method on the indicated GSG
00044 //               to issue the graphics commands appropriate to the
00045 //               given attribute.  This is normally called
00046 //               (indirectly) only from
00047 //               GraphicsStateGuardian::set_state() or modify_state().
00048 ////////////////////////////////////////////////////////////////////
00049 void ColorWriteAttrib::
00050 issue(GraphicsStateGuardianBase *gsg) const {
00051   gsg->issue_color_write(this);
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: ColorWriteAttrib::output
00056 //       Access: Public, Virtual
00057 //  Description: 
00058 ////////////////////////////////////////////////////////////////////
00059 void ColorWriteAttrib::
00060 output(ostream &out) const {
00061   out << get_type() << ":";
00062   switch (get_mode()) {
00063   case M_off:
00064     out << "off";
00065     break;
00066   case M_on:
00067     out << "on";
00068     break;
00069   }
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: ColorWriteAttrib::compare_to_impl
00074 //       Access: Protected, Virtual
00075 //  Description: Intended to be overridden by derived ColorWriteAttrib
00076 //               types to return a unique number indicating whether
00077 //               this ColorWriteAttrib is equivalent to the other one.
00078 //
00079 //               This should return 0 if the two ColorWriteAttrib objects
00080 //               are equivalent, a number less than zero if this one
00081 //               should be sorted before the other one, and a number
00082 //               greater than zero otherwise.
00083 //
00084 //               This will only be called with two ColorWriteAttrib
00085 //               objects whose get_type() functions return the same.
00086 ////////////////////////////////////////////////////////////////////
00087 int ColorWriteAttrib::
00088 compare_to_impl(const RenderAttrib *other) const {
00089   const ColorWriteAttrib *ta;
00090   DCAST_INTO_R(ta, other, 0);
00091   return (int)_mode - (int)ta->_mode;
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //     Function: ColorWriteAttrib::make_default_impl
00096 //       Access: Protected, Virtual
00097 //  Description: Intended to be overridden by derived ColorWriteAttrib
00098 //               types to specify what the default property for a
00099 //               ColorWriteAttrib of this type should be.
00100 //
00101 //               This should return a newly-allocated ColorWriteAttrib of
00102 //               the same type that corresponds to whatever the
00103 //               standard default for this kind of ColorWriteAttrib is.
00104 ////////////////////////////////////////////////////////////////////
00105 RenderAttrib *ColorWriteAttrib::
00106 make_default_impl() const {
00107   return new ColorWriteAttrib;
00108 }
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function: ColorWriteAttrib::register_with_read_factory
00112 //       Access: Public, Static
00113 //  Description: Tells the BamReader how to create objects of type
00114 //               ColorWriteAttrib.
00115 ////////////////////////////////////////////////////////////////////
00116 void ColorWriteAttrib::
00117 register_with_read_factory() {
00118   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00119 }
00120 
00121 ////////////////////////////////////////////////////////////////////
00122 //     Function: ColorWriteAttrib::write_datagram
00123 //       Access: Public, Virtual
00124 //  Description: Writes the contents of this object to the datagram
00125 //               for shipping out to a Bam file.
00126 ////////////////////////////////////////////////////////////////////
00127 void ColorWriteAttrib::
00128 write_datagram(BamWriter *manager, Datagram &dg) {
00129   RenderAttrib::write_datagram(manager, dg);
00130 
00131   dg.add_int8(_mode);
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: ColorWriteAttrib::make_from_bam
00136 //       Access: Protected, Static
00137 //  Description: This function is called by the BamReader's factory
00138 //               when a new object of type ColorWriteAttrib is encountered
00139 //               in the Bam file.  It should create the ColorWriteAttrib
00140 //               and extract its information from the file.
00141 ////////////////////////////////////////////////////////////////////
00142 TypedWritable *ColorWriteAttrib::
00143 make_from_bam(const FactoryParams &params) {
00144   ColorWriteAttrib *attrib = new ColorWriteAttrib;
00145   DatagramIterator scan;
00146   BamReader *manager;
00147 
00148   parse_params(params, scan, manager);
00149   attrib->fillin(scan, manager);
00150 
00151   return attrib;
00152 }
00153 
00154 ////////////////////////////////////////////////////////////////////
00155 //     Function: ColorWriteAttrib::fillin
00156 //       Access: Protected
00157 //  Description: This internal function is called by make_from_bam to
00158 //               read in all of the relevant data from the BamFile for
00159 //               the new ColorWriteAttrib.
00160 ////////////////////////////////////////////////////////////////////
00161 void ColorWriteAttrib::
00162 fillin(DatagramIterator &scan, BamReader *manager) {
00163   RenderAttrib::fillin(scan, manager);
00164 
00165   _mode = (Mode)scan.get_int8();
00166 }

Generated on Fri May 2 00:41:13 2003 for Panda by doxygen1.3