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

panda/src/pgraph/fogAttrib.cxx

Go to the documentation of this file.
00001 // Filename: fogAttrib.cxx
00002 // Created by:  drose (14Mar02)
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 "fogAttrib.h"
00020 #include "graphicsStateGuardianBase.h"
00021 #include "bamReader.h"
00022 #include "bamWriter.h"
00023 #include "datagram.h"
00024 #include "datagramIterator.h"
00025 
00026 TypeHandle FogAttrib::_type_handle;
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: FogAttrib::make
00030 //       Access: Published, Static
00031 //  Description: Constructs a new FogAttrib object suitable for
00032 //               rendering the indicated fog onto geometry.
00033 ////////////////////////////////////////////////////////////////////
00034 CPT(RenderAttrib) FogAttrib::
00035 make(Fog *fog) {
00036   FogAttrib *attrib = new FogAttrib;
00037   attrib->_fog = fog;
00038   return return_new(attrib);
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: FogAttrib::make_off
00043 //       Access: Published, Static
00044 //  Description: Constructs a new FogAttrib object suitable for
00045 //               rendering unfogd geometry.
00046 ////////////////////////////////////////////////////////////////////
00047 CPT(RenderAttrib) FogAttrib::
00048 make_off() {
00049   FogAttrib *attrib = new FogAttrib;
00050   return return_new(attrib);
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: FogAttrib::issue
00055 //       Access: Public, Virtual
00056 //  Description: Calls the appropriate method on the indicated GSG
00057 //               to issue the graphics commands appropriate to the
00058 //               given attribute.  This is normally called
00059 //               (indirectly) only from
00060 //               GraphicsStateGuardian::set_state() or modify_state().
00061 ////////////////////////////////////////////////////////////////////
00062 void FogAttrib::
00063 issue(GraphicsStateGuardianBase *gsg) const {
00064   gsg->issue_fog(this);
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function: FogAttrib::output
00069 //       Access: Public, Virtual
00070 //  Description: 
00071 ////////////////////////////////////////////////////////////////////
00072 void FogAttrib::
00073 output(ostream &out) const {
00074   out << get_type() << ":";
00075   if (is_off()) {
00076     out << "(off)";
00077   } else {
00078     out << *_fog;
00079   }
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: FogAttrib::compare_to_impl
00084 //       Access: Protected, Virtual
00085 //  Description: Intended to be overridden by derived FogAttrib
00086 //               types to return a unique number indicating whether
00087 //               this FogAttrib is equivalent to the other one.
00088 //
00089 //               This should return 0 if the two FogAttrib objects
00090 //               are equivalent, a number less than zero if this one
00091 //               should be sorted before the other one, and a number
00092 //               greater than zero otherwise.
00093 //
00094 //               This will only be called with two FogAttrib
00095 //               objects whose get_type() functions return the same.
00096 ////////////////////////////////////////////////////////////////////
00097 int FogAttrib::
00098 compare_to_impl(const RenderAttrib *other) const {
00099   const FogAttrib *ta;
00100   DCAST_INTO_R(ta, other, 0);
00101 
00102   // Comparing pointers by subtraction is problematic.  Instead of
00103   // doing this, we'll just depend on the built-in != and < operators
00104   // for comparing pointers.
00105   if (_fog != ta->_fog) {
00106     return _fog < ta->_fog ? -1 : 1;
00107   }
00108   return 0;
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: FogAttrib::make_default_impl
00113 //       Access: Protected, Virtual
00114 //  Description: Intended to be overridden by derived FogAttrib
00115 //               types to specify what the default property for a
00116 //               FogAttrib of this type should be.
00117 //
00118 //               This should return a newly-allocated FogAttrib of
00119 //               the same type that corresponds to whatever the
00120 //               standard default for this kind of FogAttrib is.
00121 ////////////////////////////////////////////////////////////////////
00122 RenderAttrib *FogAttrib::
00123 make_default_impl() const {
00124   return new FogAttrib;
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: FogAttrib::register_with_read_factory
00129 //       Access: Public, Static
00130 //  Description: Tells the BamReader how to create objects of type
00131 //               FogAttrib.
00132 ////////////////////////////////////////////////////////////////////
00133 void FogAttrib::
00134 register_with_read_factory() {
00135   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00136 }
00137 
00138 ////////////////////////////////////////////////////////////////////
00139 //     Function: FogAttrib::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 FogAttrib::
00145 write_datagram(BamWriter *manager, Datagram &dg) {
00146   RenderAttrib::write_datagram(manager, dg);
00147 
00148   manager->write_pointer(dg, _fog);
00149 }
00150 
00151 ////////////////////////////////////////////////////////////////////
00152 //     Function: FogAttrib::complete_pointers
00153 //       Access: Public, Virtual
00154 //  Description: Receives an array of pointers, one for each time
00155 //               manager->read_pointer() was called in fillin().
00156 //               Returns the number of pointers processed.
00157 ////////////////////////////////////////////////////////////////////
00158 int FogAttrib::
00159 complete_pointers(TypedWritable **p_list, BamReader *manager) {
00160   int pi = RenderAttrib::complete_pointers(p_list, manager);
00161 
00162   TypedWritable *fog = p_list[pi++];
00163   if (fog != (TypedWritable *)NULL) {
00164     _fog = DCAST(Fog, fog);
00165   }
00166 
00167   return pi;
00168 }
00169 
00170 ////////////////////////////////////////////////////////////////////
00171 //     Function: FogAttrib::make_from_bam
00172 //       Access: Protected, Static
00173 //  Description: This function is called by the BamReader's factory
00174 //               when a new object of type FogAttrib is encountered
00175 //               in the Bam file.  It should create the FogAttrib
00176 //               and extract its information from the file.
00177 ////////////////////////////////////////////////////////////////////
00178 TypedWritable *FogAttrib::
00179 make_from_bam(const FactoryParams &params) {
00180   FogAttrib *attrib = new FogAttrib;
00181   DatagramIterator scan;
00182   BamReader *manager;
00183 
00184   parse_params(params, scan, manager);
00185   attrib->fillin(scan, manager);
00186 
00187   return attrib;
00188 }
00189 
00190 ////////////////////////////////////////////////////////////////////
00191 //     Function: FogAttrib::fillin
00192 //       Access: Protected
00193 //  Description: This internal function is called by make_from_bam to
00194 //               read in all of the relevant data from the BamFile for
00195 //               the new FogAttrib.
00196 ////////////////////////////////////////////////////////////////////
00197 void FogAttrib::
00198 fillin(DatagramIterator &scan, BamReader *manager) {
00199   RenderAttrib::fillin(scan, manager);
00200 
00201   // Read the _fog pointer.
00202   manager->read_pointer(scan);
00203 }

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