Panda3D

depthOffsetAttrib.cxx

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