00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef SCENEGRAPHREDUCER_H
00016 #define SCENEGRAPHREDUCER_H
00017
00018 #include "pandabase.h"
00019 #include "transformState.h"
00020 #include "renderAttrib.h"
00021 #include "renderState.h"
00022 #include "accumulatedAttribs.h"
00023 #include "geomTransformer.h"
00024 #include "pStatCollector.h"
00025 #include "pStatTimer.h"
00026 #include "typedObject.h"
00027 #include "pointerTo.h"
00028 #include "graphicsStateGuardianBase.h"
00029
00030 class PandaNode;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 class EXPCL_PANDA_PGRAPH SceneGraphReducer {
00044 PUBLISHED:
00045 INLINE SceneGraphReducer(GraphicsStateGuardianBase *gsg = NULL);
00046 INLINE ~SceneGraphReducer();
00047
00048 enum AttribTypes {
00049 TT_transform = 0x001,
00050 TT_color = 0x002,
00051 TT_color_scale = 0x004,
00052 TT_tex_matrix = 0x008,
00053 TT_clip_plane = 0x010,
00054 TT_cull_face = 0x020,
00055 TT_apply_texture_color = 0x040,
00056 TT_other = 0x080,
00057 };
00058
00059 enum CombineSiblings {
00060 CS_geom_node = 0x001,
00061 CS_within_radius = 0x002,
00062 CS_other = 0x004,
00063 CS_recurse = 0x008,
00064 };
00065
00066 enum CollectVertexData {
00067
00068
00069 CVD_name = 0x001,
00070
00071
00072
00073
00074 CVD_model = 0x002,
00075
00076
00077
00078
00079 CVD_transform = 0x004,
00080
00081
00082
00083
00084
00085 CVD_avoid_dynamic = 0x008,
00086
00087
00088
00089 CVD_one_node_only = 0x010,
00090
00091
00092
00093
00094
00095 CVD_format = 0x020,
00096
00097
00098
00099
00100 CVD_usage_hint = 0x040,
00101
00102
00103
00104 CVD_animation_type = 0x080,
00105 };
00106
00107 enum MakeNonindexed {
00108
00109
00110
00111 MN_composite_only = 0x001,
00112
00113
00114
00115
00116 MN_avoid_animated = 0x002,
00117
00118
00119
00120 MN_avoid_dynamic = 0x004,
00121 };
00122
00123 void set_gsg(GraphicsStateGuardianBase *gsg);
00124 void clear_gsg();
00125 INLINE GraphicsStateGuardianBase *get_gsg() const;
00126
00127 INLINE void set_combine_radius(PN_stdfloat combine_radius);
00128 INLINE PN_stdfloat get_combine_radius() const;
00129
00130 INLINE void apply_attribs(PandaNode *node, int attrib_types = ~(TT_clip_plane | TT_cull_face | TT_apply_texture_color));
00131 INLINE void apply_attribs(PandaNode *node, const AccumulatedAttribs &attribs,
00132 int attrib_types, GeomTransformer &transformer);
00133
00134 int flatten(PandaNode *root, int combine_siblings_bits);
00135
00136 int remove_column(PandaNode *root, const InternalName *column);
00137
00138 int make_compatible_state(PandaNode *root);
00139
00140 INLINE int make_compatible_format(PandaNode *root, int collect_bits = ~0);
00141 void decompose(PandaNode *root);
00142
00143 INLINE int collect_vertex_data(PandaNode *root, int collect_bits = ~0);
00144 INLINE int make_nonindexed(PandaNode *root, int nonindexed_bits = ~0);
00145 void unify(PandaNode *root, bool preserve_order);
00146 void remove_unused_vertices(PandaNode *root);
00147
00148 INLINE void premunge(PandaNode *root, const RenderState *initial_state);
00149 bool check_live_flatten(PandaNode *node);
00150
00151 protected:
00152 void r_apply_attribs(PandaNode *node, const AccumulatedAttribs &attribs,
00153 int attrib_types, GeomTransformer &transformer);
00154
00155 int r_flatten(PandaNode *grandparent_node, PandaNode *parent_node,
00156 int combine_siblings_bits);
00157 int flatten_siblings(PandaNode *parent_node,
00158 int combine_siblings_bits);
00159
00160 bool consider_child(PandaNode *grandparent_node,
00161 PandaNode *parent_node, PandaNode *child_node);
00162 bool consider_siblings(PandaNode *parent_node, PandaNode *child1,
00163 PandaNode *child2);
00164
00165 bool do_flatten_child(PandaNode *grandparent_node,
00166 PandaNode *parent_node, PandaNode *child_node);
00167
00168 PandaNode *do_flatten_siblings(PandaNode *parent_node,
00169 PandaNode *child1, PandaNode *child2);
00170
00171 PT(PandaNode) collapse_nodes(PandaNode *node1, PandaNode *node2,
00172 bool siblings);
00173 void choose_name(PandaNode *preserve, PandaNode *source1,
00174 PandaNode *source2);
00175
00176 int r_remove_column(PandaNode *node, const InternalName *column,
00177 GeomTransformer &transformer);
00178
00179 int r_make_compatible_state(PandaNode *node, GeomTransformer &transformer);
00180
00181 int r_collect_vertex_data(PandaNode *node, int collect_bits,
00182 GeomTransformer &transformer, bool format_only);
00183 int r_make_nonindexed(PandaNode *node, int collect_bits);
00184 void r_unify(PandaNode *node, int max_indices, bool preserve_order);
00185 void r_register_vertices(PandaNode *node, GeomTransformer &transformer);
00186 void r_decompose(PandaNode *node);
00187
00188 void r_premunge(PandaNode *node, const RenderState *state);
00189
00190 private:
00191 PT(GraphicsStateGuardianBase) _gsg;
00192 PN_stdfloat _combine_radius;
00193 GeomTransformer _transformer;
00194
00195 static PStatCollector _flatten_collector;
00196 static PStatCollector _apply_collector;
00197 static PStatCollector _remove_column_collector;
00198 static PStatCollector _compatible_state_collector;
00199 static PStatCollector _collect_collector;
00200 static PStatCollector _make_nonindexed_collector;
00201 static PStatCollector _unify_collector;
00202 static PStatCollector _remove_unused_collector;
00203 static PStatCollector _premunge_collector;
00204 };
00205
00206 #include "sceneGraphReducer.I"
00207
00208 #endif