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

panda/src/pgraph/depthOffsetAttrib.cxx

Go to the documentation of this file.
00001 // Filename: depthOffsetAttrib.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 "depthOffsetAttrib.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 DepthOffsetAttrib::_type_handle;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: DepthOffsetAttrib::make
00031 //       Access: Published, Static
00032 //  Description: Constructs a new DepthOffsetAttrib object that
00033 //               indicates the relative amount of bias to write to the
00034 //               depth buffer for subsequent geometry.
00035 ////////////////////////////////////////////////////////////////////
00036 CPT(RenderAttrib) DepthOffsetAttrib::
00037 make(int offset) {
00038   DepthOffsetAttrib *attrib = new DepthOffsetAttrib(offset);
00039   return return_new(attrib);
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: DepthOffsetAttrib::issue
00044 //       Access: Public, Virtual
00045 //  Description: Calls the appropriate method on the indicated GSG
00046 //               to issue the graphics commands appropriate to the
00047 //               given attribute.  This is normally called
00048 //               (indirectly) only from
00049 //               GraphicsStateGuardian::set_state() or modify_state().
00050 ////////////////////////////////////////////////////////////////////
00051 void DepthOffsetAttrib::
00052 issue(GraphicsStateGuardianBase *gsg) const {
00053   gsg->issue_depth_offset(this);
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: DepthOffsetAttrib::output
00058 //       Access: Public, Virtual
00059 //  Description: 
00060 ////////////////////////////////////////////////////////////////////
00061 void DepthOffsetAttrib::
00062 output(ostream &out) const {
00063   out << get_type() << ":(" << get_offset() << ")";
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: DepthOffsetAttrib::compare_to_impl
00068 //       Access: Protected, Virtual
00069 //  Description: Intended to be overridden by derived DepthOffsetAttrib
00070 //               types to return a unique number indicating whether
00071 //               this DepthOffsetAttrib is equivalent to the other one.
00072 //
00073 //               This should return 0 if the two DepthOffsetAttrib objects
00074 //               are equivalent, a number less than zero if this one
00075 //               should be sorted before the other one, and a number
00076 //               greater than zero otherwise.
00077 //
00078 //               This will only be called with two DepthOffsetAttrib
00079 //               objects whose get_type() functions return the same.
00080 ////////////////////////////////////////////////////////////////////
00081 int DepthOffsetAttrib::
00082 compare_to_impl(const RenderAttrib *other) const {
00083   const DepthOffsetAttrib *ta;
00084   DCAST_INTO_R(ta, other, 0);
00085   return _offset - ta->_offset;
00086 }
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //     Function: DepthOffsetAttrib::compose_impl
00090 //       Access: Protected, Virtual
00091 //  Description: Intended to be overridden by derived RenderAttrib
00092 //               types to specify how two consecutive RenderAttrib
00093 //               objects of the same type interact.
00094 //
00095 //               This should return the result of applying the other
00096 //               RenderAttrib to a node in the scene graph below this
00097 //               RenderAttrib, which was already applied.  In most
00098 //               cases, the result is the same as the other
00099 //               RenderAttrib (that is, a subsequent RenderAttrib
00100 //               completely replaces the preceding one).  On the other
00101 //               hand, some kinds of RenderAttrib (for instance,
00102 //               ColorTransformAttrib) might combine in meaningful
00103 //               ways.
00104 ////////////////////////////////////////////////////////////////////
00105 CPT(RenderAttrib) DepthOffsetAttrib::
00106 compose_impl(const RenderAttrib *other) const {
00107   const DepthOffsetAttrib *ta;
00108   DCAST_INTO_R(ta, other, 0);
00109   int new_offset = ta->_offset + _offset;
00110 
00111   DepthOffsetAttrib *attrib = new DepthOffsetAttrib(new_offset);
00112   return return_new(attrib);
00113 }
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 //     Function: DepthOffsetAttrib::invert_compose_impl
00117 //       Access: Protected, Virtual
00118 //  Description: Intended to be overridden by derived RenderAttrib
00119 //               types to specify how two consecutive RenderAttrib
00120 //               objects of the same type interact.
00121 //
00122 //               See invert_compose() and compose_impl().
00123 ////////////////////////////////////////////////////////////////////
00124 CPT(RenderAttrib) DepthOffsetAttrib::
00125 invert_compose_impl(const RenderAttrib *other) const {
00126   const DepthOffsetAttrib *ta;
00127   DCAST_INTO_R(ta, other, 0);
00128   int new_offset = ta->_offset - _offset;
00129 
00130   DepthOffsetAttrib *attrib = new DepthOffsetAttrib(new_offset);
00131   return return_new(attrib);
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: DepthOffsetAttrib::make_default_impl
00136 //       Access: Protected, Virtual
00137 //  Description: Intended to be overridden by derived DepthOffsetAttrib
00138 //               types to specify what the default property for a
00139 //               DepthOffsetAttrib of this type should be.
00140 //
00141 //               This should return a newly-allocated DepthOffsetAttrib of
00142 //               the same type that corresponds to whatever the
00143 //               standard default for this kind of DepthOffsetAttrib is.
00144 ////////////////////////////////////////////////////////////////////
00145 RenderAttrib *DepthOffsetAttrib::
00146 make_default_impl() const {
00147   return new DepthOffsetAttrib(0);
00148 }
00149 
00150 ////////////////////////////////////////////////////////////////////
00151 //     Function: DepthOffsetAttrib::register_with_read_factory
00152 //       Access: Public, Static
00153 //  Description: Tells the BamReader how to create objects of type
00154 //               DepthOffsetAttrib.
00155 ////////////////////////////////////////////////////////////////////
00156 void DepthOffsetAttrib::
00157 register_with_read_factory() {
00158   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00159 }
00160 
00161 ////////////////////////////////////////////////////////////////////
00162 //     Function: DepthOffsetAttrib::write_datagram
00163 //       Access: Public, Virtual
00164 //  Description: Writes the contents of this object to the datagram
00165 //               for shipping out to a Bam file.
00166 ////////////////////////////////////////////////////////////////////
00167 void DepthOffsetAttrib::
00168 write_datagram(BamWriter *manager, Datagram &dg) {
00169   RenderAttrib::write_datagram(manager, dg);
00170 
00171   dg.add_int32(_offset);
00172 }
00173 
00174 ////////////////////////////////////////////////////////////////////
00175 //     Function: DepthOffsetAttrib::make_from_bam
00176 //       Access: Protected, Static
00177 //  Description: This function is called by the BamReader's factory
00178 //               when a new object of type DepthOffsetAttrib is encountered
00179 //               in the Bam file.  It should create the DepthOffsetAttrib
00180 //               and extract its information from the file.
00181 ////////////////////////////////////////////////////////////////////
00182 TypedWritable *DepthOffsetAttrib::
00183 make_from_bam(const FactoryParams &params) {
00184   DepthOffsetAttrib *attrib = new DepthOffsetAttrib(0);
00185   DatagramIterator scan;
00186   BamReader *manager;
00187 
00188   parse_params(params, scan, manager);
00189   attrib->fillin(scan, manager);
00190 
00191   return attrib;
00192 }
00193 
00194 ////////////////////////////////////////////////////////////////////
00195 //     Function: DepthOffsetAttrib::fillin
00196 //       Access: Protected
00197 //  Description: This internal function is called by make_from_bam to
00198 //               read in all of the relevant data from the BamFile for
00199 //               the new DepthOffsetAttrib.
00200 ////////////////////////////////////////////////////////////////////
00201 void DepthOffsetAttrib::
00202 fillin(DatagramIterator &scan, BamReader *manager) {
00203   RenderAttrib::fillin(scan, manager);
00204 
00205   _offset = scan.get_int32();
00206 }

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