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

panda/src/pgraph/transparencyAttrib.cxx

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

Generated on Fri May 2 00:42:32 2003 for Panda by doxygen1.3