Panda3D

transparencyAttrib.cxx

00001 // Filename: transparencyAttrib.cxx
00002 // Created by:  drose (28Feb02)
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 "transparencyAttrib.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 TransparencyAttrib::_type_handle;
00024 int TransparencyAttrib::_attrib_slot;
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: TransparencyAttrib::make
00028 //       Access: Published, Static
00029 //  Description: Constructs a new TransparencyAttrib object.
00030 ////////////////////////////////////////////////////////////////////
00031 CPT(RenderAttrib) TransparencyAttrib::
00032 make(TransparencyAttrib::Mode mode) {
00033   TransparencyAttrib *attrib = new TransparencyAttrib(mode);
00034   return return_new(attrib);
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: TransparencyAttrib::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) TransparencyAttrib::
00045 make_default() {
00046   return return_new(new TransparencyAttrib);
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: TransparencyAttrib::output
00051 //       Access: Public, Virtual
00052 //  Description: 
00053 ////////////////////////////////////////////////////////////////////
00054 void TransparencyAttrib::
00055 output(ostream &out) const {
00056   out << get_type() << ":";
00057   switch (get_mode()) {
00058   case M_none:
00059     out << "none";
00060     break;
00061 
00062   case M_alpha:
00063     out << "alpha";
00064     break;
00065 
00066   case M_multisample:
00067     out << "multisample";
00068     break;
00069 
00070   case M_multisample_mask:
00071     out << "multisample mask";
00072     break;
00073 
00074   case M_binary:
00075     out << "binary";
00076     break;
00077 
00078   case M_dual:
00079     out << "dual";
00080     break;
00081 
00082   case M_notused:
00083     break;
00084   }
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: TransparencyAttrib::compare_to_impl
00089 //       Access: Protected, Virtual
00090 //  Description: Intended to be overridden by derived TransparencyAttrib
00091 //               types to return a unique number indicating whether
00092 //               this TransparencyAttrib is equivalent to the other one.
00093 //
00094 //               This should return 0 if the two TransparencyAttrib objects
00095 //               are equivalent, a number less than zero if this one
00096 //               should be sorted before the other one, and a number
00097 //               greater than zero otherwise.
00098 //
00099 //               This will only be called with two TransparencyAttrib
00100 //               objects whose get_type() functions return the same.
00101 ////////////////////////////////////////////////////////////////////
00102 int TransparencyAttrib::
00103 compare_to_impl(const RenderAttrib *other) const {
00104   const TransparencyAttrib *ta;
00105   DCAST_INTO_R(ta, other, 0);
00106   return (int)_mode - (int)ta->_mode;
00107 }
00108 
00109 ////////////////////////////////////////////////////////////////////
00110 //     Function: TransparencyAttrib::get_hash_impl
00111 //       Access: Protected, Virtual
00112 //  Description: Intended to be overridden by derived RenderAttrib
00113 //               types to return a unique hash for these particular
00114 //               properties.  RenderAttribs that compare the same with
00115 //               compare_to_impl(), above, should return the same
00116 //               hash; RenderAttribs that compare differently should
00117 //               return a different hash.
00118 ////////////////////////////////////////////////////////////////////
00119 size_t TransparencyAttrib::
00120 get_hash_impl() const {
00121   size_t hash = 0;
00122   hash = int_hash::add_hash(hash, (int)_mode);
00123   return hash;
00124 }
00125 
00126 ////////////////////////////////////////////////////////////////////
00127 //     Function: TransparencyAttrib::get_auto_shader_attrib_impl
00128 //       Access: Protected, Virtual
00129 //  Description: 
00130 ////////////////////////////////////////////////////////////////////
00131 CPT(RenderAttrib) TransparencyAttrib::
00132 get_auto_shader_attrib_impl(const RenderState *state) const {
00133   return this;
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: TransparencyAttrib::register_with_read_factory
00138 //       Access: Public, Static
00139 //  Description: Tells the BamReader how to create objects of type
00140 //               TransparencyAttrib.
00141 ////////////////////////////////////////////////////////////////////
00142 void TransparencyAttrib::
00143 register_with_read_factory() {
00144   BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: TransparencyAttrib::write_datagram
00149 //       Access: Public, Virtual
00150 //  Description: Writes the contents of this object to the datagram
00151 //               for shipping out to a Bam file.
00152 ////////////////////////////////////////////////////////////////////
00153 void TransparencyAttrib::
00154 write_datagram(BamWriter *manager, Datagram &dg) {
00155   RenderAttrib::write_datagram(manager, dg);
00156 
00157   dg.add_int8(_mode);
00158 }
00159 
00160 ////////////////////////////////////////////////////////////////////
00161 //     Function: TransparencyAttrib::make_from_bam
00162 //       Access: Protected, Static
00163 //  Description: This function is called by the BamReader's factory
00164 //               when a new object of type TransparencyAttrib is encountered
00165 //               in the Bam file.  It should create the TransparencyAttrib
00166 //               and extract its information from the file.
00167 ////////////////////////////////////////////////////////////////////
00168 TypedWritable *TransparencyAttrib::
00169 make_from_bam(const FactoryParams &params) {
00170   TransparencyAttrib *attrib = new TransparencyAttrib;
00171   DatagramIterator scan;
00172   BamReader *manager;
00173 
00174   parse_params(params, scan, manager);
00175   attrib->fillin(scan, manager);
00176 
00177   return attrib;
00178 }
00179 
00180 ////////////////////////////////////////////////////////////////////
00181 //     Function: TransparencyAttrib::fillin
00182 //       Access: Protected
00183 //  Description: This internal function is called by make_from_bam to
00184 //               read in all of the relevant data from the BamFile for
00185 //               the new TransparencyAttrib.
00186 ////////////////////////////////////////////////////////////////////
00187 void TransparencyAttrib::
00188 fillin(DatagramIterator &scan, BamReader *manager) {
00189   RenderAttrib::fillin(scan, manager);
00190 
00191   _mode = (Mode)scan.get_int8();
00192 }
 All Classes Functions Variables Enumerations