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

panda/src/pgraph/renderModeAttrib.cxx

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

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