Panda3D
 All Classes Functions Variables Enumerations
texMatrixAttrib.h
1 // Filename: texMatrixAttrib.h
2 // Created by: drose (14Mar02)
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 TEXMATRIXATTRIB_H
16 #define TEXMATRIXATTRIB_H
17 
18 #include "pandabase.h"
19 
20 #include "geom.h"
21 #include "renderAttrib.h"
22 #include "textureStage.h"
23 #include "transformState.h"
24 #include "pointerTo.h"
25 
26 class FactoryParams;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : TexMatrixAttrib
30 // Description : Applies a transform matrix to UV's before they are
31 // rendered.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_PANDA_PGRAPH TexMatrixAttrib : public RenderAttrib {
34 protected:
35  INLINE TexMatrixAttrib();
36  INLINE TexMatrixAttrib(const TexMatrixAttrib &copy);
37 
38 public:
39  virtual ~TexMatrixAttrib();
40 
41 PUBLISHED:
42  static CPT(RenderAttrib) make();
43  static CPT(RenderAttrib) make(const LMatrix4 &mat);
44  static CPT(RenderAttrib) make(TextureStage *stage, const TransformState *transform);
45  static CPT(RenderAttrib) make_default();
46 
47  CPT(RenderAttrib) add_stage(TextureStage *stage, const TransformState *transform, int override = 0) const;
48  CPT(RenderAttrib) remove_stage(TextureStage *stage) const;
49 
50  bool is_empty() const;
51  bool has_stage(TextureStage *stage) const;
52 
53  int get_num_stages() const;
54  TextureStage *get_stage(int n) const;
55  MAKE_SEQ(get_stages, get_num_stages, get_stage);
56 
57  const LMatrix4 &get_mat() const;
58  const LMatrix4 &get_mat(TextureStage *stage) const;
59 
60  CPT(TransformState) get_transform(TextureStage *stage) const;
61  INLINE int get_override(TextureStage *stage) const;
62 
63  INLINE int get_geom_rendering(int geom_rendering) const;
64 
65 public:
66  virtual void output(ostream &out) const;
67 
68 protected:
69  virtual int compare_to_impl(const RenderAttrib *other) const;
70  virtual size_t get_hash_impl() const;
71  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
72  virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
73  virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
74 
75 private:
76  INLINE void check_stage_list() const;
77  void rebuild_stage_list();
78 
79 private:
80  class StageNode {
81  public:
82  INLINE StageNode(const TextureStage *stage);
83 
84  INLINE bool operator < (const StageNode &other) const;
85 
86  PT(TextureStage) _stage;
87  CPT(TransformState) _transform;
88  int _override;
89  };
90 
91  class CompareTextureStagePointer {
92  public:
93  INLINE bool operator () (const TexMatrixAttrib::StageNode &a, const TexMatrixAttrib::StageNode &b) const;
94  };
95 
97  Stages _stages;
98 
99  static CPT(RenderAttrib) _empty_attrib;
100 
101 PUBLISHED:
102  static int get_class_slot() {
103  return _attrib_slot;
104  }
105  virtual int get_slot() const {
106  return get_class_slot();
107  }
108 
109 public:
110  static void register_with_read_factory();
111  virtual void write_datagram(BamWriter *manager, Datagram &dg);
112  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
113 
114 protected:
115  static TypedWritable *make_from_bam(const FactoryParams &params);
116  void fillin(DatagramIterator &scan, BamReader *manager);
117 
118 public:
119  static TypeHandle get_class_type() {
120  return _type_handle;
121  }
122  static void init_type() {
123  RenderAttrib::init_type();
124  register_type(_type_handle, "TexMatrixAttrib",
125  RenderAttrib::get_class_type());
126  _attrib_slot = register_slot(_type_handle, 100, make_default);
127  }
128  virtual TypeHandle get_type() const {
129  return get_class_type();
130  }
131  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
132 
133 private:
134  static TypeHandle _type_handle;
135  static int _attrib_slot;
136 };
137 
138 #include "texMatrixAttrib.I"
139 
140 #endif
141 
static int register_slot(TypeHandle type_handle, int sort, RenderAttribRegistry::MakeDefaultFunc *make_default_func)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition: renderAttrib.I:163
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:60
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager-&gt;read_pointer() was called in fillin()...
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
Applies a transform matrix to UV&#39;s before they are rendered.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Defines the properties of a named stage of the multitexture pipeline.
Definition: textureStage.h:38
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43