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

panda/src/pgraph/accumulatedAttribs.cxx

Go to the documentation of this file.
00001 // Filename: accumulatedAttribs.cxx
00002 // Created by:  drose (30Jan03)
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 "accumulatedAttribs.h"
00020 #include "sceneGraphReducer.h"
00021 #include "geomTransformer.h"
00022 #include "pandaNode.h"
00023 #include "colorAttrib.h"
00024 #include "colorScaleAttrib.h"
00025 #include "texMatrixAttrib.h"
00026 #include "config_pgraph.h"
00027 
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: AccumulatedAttribs::write
00031 //       Access: Public
00032 //  Description:
00033 ////////////////////////////////////////////////////////////////////
00034 void AccumulatedAttribs::
00035 write(ostream &out, int attrib_types, int indent_level) const {
00036   if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
00037     _transform->write(out, indent_level);
00038   }
00039   if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
00040     if (_color == (const RenderAttrib *)NULL) {
00041       indent(out, indent_level) << "no color\n";
00042     } else {
00043       _color->write(out, indent_level);
00044     }
00045   }
00046   if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
00047     if (_color_scale == (const RenderAttrib *)NULL) {
00048       indent(out, indent_level) << "no color scale\n";
00049     } else {
00050       _color_scale->write(out, indent_level);
00051     }
00052   }
00053   if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
00054     if (_tex_matrix == (const RenderAttrib *)NULL) {
00055       indent(out, indent_level) << "no tex matrix\n";
00056     } else {
00057       _tex_matrix->write(out, indent_level);
00058     }
00059   }
00060   if ((attrib_types & SceneGraphReducer::TT_other) != 0) {
00061     _other->write(out, indent_level);
00062   }
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: AccumulatedAttribs::collect
00067 //       Access: Public
00068 //  Description: Collects the state and transform from the indicated
00069 //               node and adds it to the accumulator, removing it from
00070 //               the node.
00071 ////////////////////////////////////////////////////////////////////
00072 void AccumulatedAttribs::
00073 collect(PandaNode *node, int attrib_types) {
00074   if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
00075     // Collect the node's transform.
00076     nassertv(_transform != (TransformState *)NULL);
00077     _transform = _transform->compose(node->get_transform());
00078     node->set_transform(TransformState::make_identity());
00079   }
00080 
00081   if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
00082     const RenderAttrib *node_attrib = 
00083       node->get_attrib(ColorAttrib::get_class_type());
00084     if (node_attrib != (const RenderAttrib *)NULL) {
00085       // The node has a color attribute; apply it.
00086       if (_color == (const RenderAttrib *)NULL) {
00087         _color = node_attrib;
00088       } else {
00089         _color = _color->compose(node_attrib);
00090       }
00091       node->clear_attrib(ColorAttrib::get_class_type());
00092     }
00093   }
00094 
00095   if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
00096     const RenderAttrib *node_attrib = 
00097       node->get_attrib(ColorScaleAttrib::get_class_type());
00098     if (node_attrib != (const RenderAttrib *)NULL) {
00099       // The node has a color scale attribute; apply it.
00100       if (_color_scale == (const RenderAttrib *)NULL) {
00101         _color_scale = node_attrib;
00102       } else {
00103         _color_scale = _color_scale->compose(node_attrib);
00104       }
00105       node->clear_attrib(ColorScaleAttrib::get_class_type());
00106     }
00107   }
00108 
00109   if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
00110     const RenderAttrib *node_attrib = 
00111       node->get_attrib(TexMatrixAttrib::get_class_type());
00112     if (node_attrib != (const RenderAttrib *)NULL) {
00113       // The node has a tex matrix attribute; apply it.
00114       if (_tex_matrix == (const RenderAttrib *)NULL) {
00115         _tex_matrix = node_attrib;
00116       } else {
00117         _tex_matrix = _tex_matrix->compose(node_attrib);
00118       }
00119       node->clear_attrib(TexMatrixAttrib::get_class_type());
00120     }
00121   }
00122 
00123   if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
00124     // Collect everything else.
00125     nassertv(_other != (RenderState *)NULL);
00126     _other = _other->compose(node->get_state());
00127     node->set_state(RenderState::make_empty());
00128   }
00129 }
00130 
00131 ////////////////////////////////////////////////////////////////////
00132 //     Function: AccumulatedAttribs::apply_to_node
00133 //       Access: Public
00134 //  Description: Stores the indicated attributes in the node's
00135 //               transform and state information; does not attempt to
00136 //               apply the properties to the vertices.  Clears the
00137 //               attributes from the accumulator for future
00138 //               traversals.
00139 ////////////////////////////////////////////////////////////////////
00140 void AccumulatedAttribs::
00141 apply_to_node(PandaNode *node, int attrib_types) {
00142   if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
00143     node->set_transform(_transform->compose(node->get_transform()));
00144     _transform = TransformState::make_identity();
00145   }
00146 
00147   if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
00148     if (_color != (RenderAttrib *)NULL) {
00149       const RenderAttrib *node_attrib =
00150         node->get_attrib(ColorAttrib::get_class_type());
00151       if (node_attrib != (RenderAttrib *)NULL) {
00152         node->set_attrib(_color->compose(node_attrib));
00153       } else {
00154         node->set_attrib(_color);
00155       }
00156       _color = (RenderAttrib *)NULL;
00157     }
00158   }
00159 
00160   if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
00161     if (_color_scale != (RenderAttrib *)NULL) {
00162       const RenderAttrib *node_attrib =
00163         node->get_attrib(ColorScaleAttrib::get_class_type());
00164       if (node_attrib != (RenderAttrib *)NULL) {
00165         node->set_attrib(_color_scale->compose(node_attrib));
00166       } else {
00167         node->set_attrib(_color_scale);
00168       }
00169       _color_scale = (RenderAttrib *)NULL;
00170     }
00171   }
00172 
00173   if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
00174     if (_tex_matrix != (RenderAttrib *)NULL) {
00175       const RenderAttrib *node_attrib =
00176         node->get_attrib(TexMatrixAttrib::get_class_type());
00177       if (node_attrib != (RenderAttrib *)NULL) {
00178         node->set_attrib(_tex_matrix->compose(node_attrib));
00179       } else {
00180         node->set_attrib(_tex_matrix);
00181       }
00182       _tex_matrix = (RenderAttrib *)NULL;
00183     }
00184   }
00185 
00186   if ((attrib_types & SceneGraphReducer::TT_other) != 0) {
00187     node->set_state(_other->compose(node->get_state()));
00188     _other = RenderState::make_empty();
00189   }
00190 }

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