Panda3D

depthTestAttrib.cxx

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