00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00031
00032
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
00067
00068
00069
00070
00071
00072 void AccumulatedAttribs::
00073 collect(PandaNode *node, int attrib_types) {
00074 if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
00075
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
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
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
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
00125 nassertv(_other != (RenderState *)NULL);
00126 _other = _other->compose(node->get_state());
00127 node->set_state(RenderState::make_empty());
00128 }
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
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 }