00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef MULTITEXREDUCER_H
00016 #define MULTITEXREDUCER_H
00017
00018 #include "pandabase.h"
00019 #include "texture.h"
00020 #include "textureAttrib.h"
00021 #include "textureStage.h"
00022 #include "texMatrixAttrib.h"
00023 #include "transformState.h"
00024 #include "geomNode.h"
00025 #include "nodePath.h"
00026 #include "luse.h"
00027 #include "pointerTo.h"
00028 #include "pmap.h"
00029 #include "pvector.h"
00030
00031 class GraphicsOutput;
00032 class PandaNode;
00033 class RenderState;
00034 class TransformState;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 class EXPCL_PANDA_GRUTIL MultitexReducer {
00053 PUBLISHED:
00054 MultitexReducer();
00055 ~MultitexReducer();
00056
00057 void clear();
00058 INLINE void scan(const NodePath &node);
00059 INLINE void scan(const NodePath &node, const NodePath &state_from);
00060 void scan(PandaNode *node, const RenderState *state,
00061 const TransformState *transform);
00062
00063 void set_target(TextureStage *stage);
00064 void set_use_geom(bool use_geom);
00065 void set_allow_tex_mat(bool allow_tex_mat);
00066
00067 void flatten(GraphicsOutput *window);
00068
00069 private:
00070 class StageInfo {
00071 public:
00072 StageInfo(TextureStage *stage, const TextureAttrib *ta,
00073 const TexMatrixAttrib *tma);
00074
00075 INLINE bool operator < (const StageInfo &other) const;
00076
00077 PT(TextureStage) _stage;
00078 PT(Texture) _tex;
00079 CPT(TransformState) _tex_mat;
00080 };
00081
00082 typedef pvector<StageInfo> StageList;
00083
00084 class GeomInfo {
00085 public:
00086 INLINE GeomInfo(const RenderState *state, const RenderState *geom_net_state,
00087 GeomNode *geom_node, int index);
00088
00089 CPT(RenderState) _state;
00090 CPT(RenderState) _geom_net_state;
00091 PT(GeomNode) _geom_node;
00092 int _index;
00093 };
00094
00095 typedef pvector<GeomInfo> GeomList;
00096
00097 class GeomNodeInfo {
00098 public:
00099 INLINE GeomNodeInfo(const RenderState *state, GeomNode *geom_node);
00100 CPT(RenderState) _state;
00101 PT(GeomNode) _geom_node;
00102 };
00103
00104 typedef pvector<GeomNodeInfo> GeomNodeList;
00105
00106 typedef pmap<StageList, GeomList> Stages;
00107 Stages _stages;
00108 GeomNodeList _geom_node_list;
00109
00110 PT(TextureStage) _target_stage;
00111 bool _use_geom;
00112 bool _allow_tex_mat;
00113
00114 private:
00115 void scan_geom_node(GeomNode *node, const RenderState *state,
00116 const TransformState *transform);
00117
00118 void record_stage_list(const StageList &stage_list,
00119 const GeomInfo &geom_info);
00120
00121 size_t choose_model_stage(const StageList &stage_list) const;
00122 bool determine_uv_range(LTexCoord &min_uv, LTexCoord &max_uv,
00123 const StageInfo &model_stage,
00124 const GeomList &geom_list) const;
00125
00126 void get_uv_scale(LVecBase2 &uv_scale, LVecBase2 &uv_trans,
00127 const LTexCoord &min_uv, const LTexCoord &max_uv) const;
00128
00129 void choose_texture_size(int &x_size, int &y_size,
00130 const StageInfo &model_stage,
00131 const LVecBase2 &uv_scale,
00132 GraphicsOutput *window) const;
00133
00134 void make_texture_layer(const NodePath &render,
00135 const StageInfo &stage_info,
00136 const GeomList &geom_list,
00137 const LTexCoord &min_uv, const LTexCoord &max_uv,
00138 bool force_use_geom, bool transparent_base);
00139 void transfer_geom(GeomNode *geom_node, const InternalName *texcoord_name,
00140 const GeomList &geom_list, bool preserve_color);
00141
00142 void scan_color(const GeomList &geom_list, LColor &geom_color,
00143 int &num_colors) const;
00144 bool scan_decal(const StageList &stage_list) const;
00145
00146 };
00147
00148 #include "multitexReducer.I"
00149
00150 #endif