Panda3D
multitexReducer.h
1 // Filename: multitexReducer.h
2 // Created by: drose (30Nov04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef MULTITEXREDUCER_H
16 #define MULTITEXREDUCER_H
17 
18 #include "pandabase.h"
19 #include "texture.h"
20 #include "textureAttrib.h"
21 #include "textureStage.h"
22 #include "texMatrixAttrib.h"
23 #include "transformState.h"
24 #include "geomNode.h"
25 #include "nodePath.h"
26 #include "luse.h"
27 #include "pointerTo.h"
28 #include "pmap.h"
29 #include "pvector.h"
30 
31 class GraphicsOutput;
32 class PandaNode;
33 class RenderState;
34 class TransformState;
35 
36 ////////////////////////////////////////////////////////////////////
37 // Class : MultitexReducer
38 // Description : This object presents an interface for generating new
39 // texture images that represent the combined images
40 // from one or more individual textures, reproducing
41 // certain kinds of multitexture effects without
42 // depending on multitexture support in the hardware.
43 //
44 // This also flattens out texture matrices and removes
45 // extra texture coordinates from the Geoms. It is thus
46 // not a complete substitute for true multitexturing,
47 // because it does not lend itself well to dynamic
48 // animation of the textures once they have been
49 // flattened. It is, however, useful for "baking in" a
50 // particular multitexture effect.
51 ////////////////////////////////////////////////////////////////////
52 class EXPCL_PANDA_GRUTIL MultitexReducer {
53 PUBLISHED:
55  ~MultitexReducer();
56 
57  void clear();
58  INLINE void scan(const NodePath &node);
59  INLINE void scan(const NodePath &node, const NodePath &state_from);
60  void scan(PandaNode *node, const RenderState *state,
61  const TransformState *transform);
62 
63  void set_target(TextureStage *stage);
64  void set_use_geom(bool use_geom);
65  void set_allow_tex_mat(bool allow_tex_mat);
66 
67  void flatten(GraphicsOutput *window);
68 
69 private:
70  class StageInfo {
71  public:
72  StageInfo(TextureStage *stage, const TextureAttrib *ta,
73  const TexMatrixAttrib *tma);
74 
75  INLINE bool operator < (const StageInfo &other) const;
76 
77  PT(TextureStage) _stage;
78  PT(Texture) _tex;
79  CPT(TransformState) _tex_mat;
80  };
81 
83 
84  class GeomInfo {
85  public:
86  INLINE GeomInfo(const RenderState *state, const RenderState *geom_net_state,
87  GeomNode *geom_node, int index);
88 
89  CPT(RenderState) _state;
90  CPT(RenderState) _geom_net_state;
91  PT(GeomNode) _geom_node;
92  int _index;
93  };
94 
96 
97  class GeomNodeInfo {
98  public:
99  INLINE GeomNodeInfo(const RenderState *state, GeomNode *geom_node);
100  CPT(RenderState) _state;
101  PT(GeomNode) _geom_node;
102  };
103 
105 
107  Stages _stages;
108  GeomNodeList _geom_node_list;
109 
110  PT(TextureStage) _target_stage;
111  bool _use_geom;
112  bool _allow_tex_mat;
113 
114 private:
115  void scan_geom_node(GeomNode *node, const RenderState *state,
116  const TransformState *transform);
117 
118  void record_stage_list(const StageList &stage_list,
119  const GeomInfo &geom_info);
120 
121  size_t choose_model_stage(const StageList &stage_list) const;
122  bool determine_uv_range(LTexCoord &min_uv, LTexCoord &max_uv,
123  const StageInfo &model_stage,
124  const GeomList &geom_list) const;
125 
126  void get_uv_scale(LVecBase2 &uv_scale, LVecBase2 &uv_trans,
127  const LTexCoord &min_uv, const LTexCoord &max_uv) const;
128 
129  void choose_texture_size(int &x_size, int &y_size,
130  const StageInfo &model_stage,
131  const LVecBase2 &uv_scale,
132  GraphicsOutput *window) const;
133 
134  void make_texture_layer(const NodePath &render,
135  const StageInfo &stage_info,
136  const GeomList &geom_list,
137  const LTexCoord &min_uv, const LTexCoord &max_uv,
138  bool force_use_geom, bool transparent_base);
139  void transfer_geom(GeomNode *geom_node, const InternalName *texcoord_name,
140  const GeomList &geom_list, bool preserve_color);
141 
142  void scan_color(const GeomList &geom_list, LColor &geom_color,
143  int &num_colors) const;
144  bool scan_decal(const StageList &stage_list) const;
145 
146 };
147 
148 #include "multitexReducer.I"
149 
150 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
This object presents an interface for generating new texture images that represent the combined image...
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
Definition: textureAttrib.h:34
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:105
This is a base class for the various different classes that represent the result of a frame of render...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
Applies a transform matrix to UV&#39;s before they are rendered.
This is a two-component point in space.
Definition: lpoint2.h:92
Defines the properties of a named stage of the multitexture pipeline.
Definition: textureStage.h:38
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37