Panda3D
 All Classes Functions Variables Enumerations
texGenAttrib.h
1 // Filename: texGenAttrib.h
2 // Created by: masad (21Jun04)
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 TEXGENATTRIB_H
16 #define TEXGENATTRIB_H
17 
18 #include "pandabase.h"
19 
20 #include "geom.h"
21 #include "renderAttrib.h"
22 #include "textureStage.h"
23 #include "texture.h"
24 #include "pointerTo.h"
25 #include "nodePath.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : TexGenAttrib
29 // Description : Computes texture coordinates for geometry
30 // automatically based on vertex position and/or normal.
31 // This can be used to implement reflection and/or
32 // refraction maps, for instance to make shiny surfaces,
33 // as well as other special effects such as projective
34 // texturing.
35 ////////////////////////////////////////////////////////////////////
36 class EXPCL_PANDA_PGRAPH TexGenAttrib : public RenderAttrib {
37 PUBLISHED:
38  // We inherit the definition of our Mode enumerated type from
39  // RenderAttrib. Normally, Mode would be defined here, but we
40  // define it in the base class instead as a hack to avoid a problem
41  // with circular includes.
42  typedef RenderAttrib::TexGenMode Mode;
43 
44 protected:
45  INLINE TexGenAttrib();
46  INLINE TexGenAttrib(const TexGenAttrib &copy);
47 
48 public:
49  virtual ~TexGenAttrib();
50 
51 PUBLISHED:
52  static CPT(RenderAttrib) make();
53  static CPT(RenderAttrib) make(TextureStage *stage, Mode mode);
54  static CPT(RenderAttrib) make_default();
55 
56  CPT(RenderAttrib) add_stage(TextureStage *stage, Mode mode) const;
57  CPT(RenderAttrib) add_stage(TextureStage *stage, Mode mode, const LTexCoord3 &constant_value) const;
58  CPT(RenderAttrib) remove_stage(TextureStage *stage) const;
59 
60  bool is_empty() const;
61  bool has_stage(TextureStage *stage) const;
62  Mode get_mode(TextureStage *stage) const;
63  bool has_gen_texcoord_stage(TextureStage *stage) const;
64  const LTexCoord3 &get_constant_value(TextureStage *stage) const;
65 
66  INLINE int get_geom_rendering(int geom_rendering) const;
67 
68 public:
69  virtual void output(ostream &out) const;
70 
71 protected:
72  virtual int compare_to_impl(const RenderAttrib *other) const;
73  virtual size_t get_hash_impl() const;
74  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
75  virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
76  virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
77 
78 private:
79  class ModeDef;
80  void filled_stages();
81  void record_stage(TextureStage *stage, ModeDef &mode_def);
82 
83  class ModeDef {
84  public:
85  INLINE ModeDef();
86  INLINE int compare_to(const ModeDef &other) const;
87  Mode _mode;
88  string _source_name;
89  NodePath _light;
90  LTexCoord3 _constant_value;
91  };
93  Stages _stages;
94 
95  // This is a set of TextureStage pointers for which texture
96  // coordinates will not be needed from the Geom. It's redundant;
97  // it's almost the same set that is listed in _stages, above. It's
98  // just here as an optimization during rendering.
100  NoTexCoordStages _no_texcoords;
101 
102  // This element is only used during reading from a bam file. It has
103  // no meaningful value any other time.
104  pvector<Mode> _read_modes;
105 
106  int _num_point_sprites;
107 
108  // _point_geom_rendering is the GeomRendering bits that are added by
109  // the TexGenAttrib if there are any points in the Geom.
110  // _geom_rendering is the GeomRendering bits that are added
111  // regardless of the kind of Geom it is.
112  int _point_geom_rendering;
113  int _geom_rendering;
114 
115  static CPT(RenderAttrib) _empty_attrib;
116 
117 PUBLISHED:
118  static int get_class_slot() {
119  return _attrib_slot;
120  }
121  virtual int get_slot() const {
122  return get_class_slot();
123  }
124 
125 public:
126  static void register_with_read_factory();
127  virtual void write_datagram(BamWriter *manager, Datagram &dg);
128  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
129 
130 protected:
131  static TypedWritable *make_from_bam(const FactoryParams &params);
132  void fillin(DatagramIterator &scan, BamReader *manager);
133 
134 public:
135  static TypeHandle get_class_type() {
136  return _type_handle;
137  }
138  static void init_type() {
139  RenderAttrib::init_type();
140  register_type(_type_handle, "TexGenAttrib",
141  RenderAttrib::get_class_type());
142  _attrib_slot = register_slot(_type_handle, 100, make_default);
143  }
144  virtual TypeHandle get_type() const {
145  return get_class_type();
146  }
147  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
148 
149 private:
150  static TypeHandle _type_handle;
151  static int _attrib_slot;
152 };
153 
154 #include "texGenAttrib.I"
155 
156 #endif
157 
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 a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
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()...
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
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:79
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
Computes texture coordinates for geometry automatically based on vertex position and/or normal...
Definition: texGenAttrib.h:36
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165