Panda3D

fogAttrib.cxx

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