Panda3D
 All Classes Functions Variables Enumerations
renderAttrib.h
1 // Filename: renderAttrib.h
2 // Created by: drose (21Feb02)
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 RENDERATTRIB_H
16 #define RENDERATTRIB_H
17 
18 #include "pandabase.h"
19 
20 #include "typedWritableReferenceCount.h"
21 #include "renderAttribRegistry.h"
22 #include "pointerTo.h"
23 #include "simpleHashMap.h"
24 #include "lightReMutex.h"
25 #include "pStatCollector.h"
26 
27 class AttribSlots;
29 class CullTraverser;
30 class CullTraverserData;
31 class RenderState;
32 
33 ////////////////////////////////////////////////////////////////////
34 // Class : RenderAttrib
35 // Description : This is the base class for a number of render
36 // attributes (other than transform) that may be set on
37 // scene graph nodes to control the appearance of
38 // geometry. This includes TextureAttrib, ColorAttrib,
39 // etc.
40 //
41 // RenderAttrib represents render attributes that always
42 // propagate down to the leaves without regard to the
43 // particular node they are assigned to. A RenderAttrib
44 // will have the same effect on a leaf node whether it
45 // is assigned to the graph at the leaf or several nodes
46 // above. This is different from RenderEffect, which
47 // represents a particular render property that is
48 // applied immediately to the node on which it is
49 // encountered, like billboarding or decaling.
50 //
51 // You should not attempt to create or modify a
52 // RenderAttrib directly; instead, use the make() method
53 // of the appropriate kind of attrib you want. This
54 // will allocate and return a new RenderAttrib of the
55 // appropriate type, and it may share pointers if
56 // possible. Do not modify the new RenderAttrib if you
57 // wish to change its properties; instead, create a new
58 // one.
59 ////////////////////////////////////////////////////////////////////
60 class EXPCL_PANDA_PGRAPH RenderAttrib : public TypedWritableReferenceCount {
61 protected:
62  RenderAttrib();
63 private:
64  RenderAttrib(const RenderAttrib &copy);
65  void operator = (const RenderAttrib &copy);
66 
67 public:
68  virtual ~RenderAttrib();
69 
70 PUBLISHED:
71  INLINE CPT(RenderAttrib) compose(const RenderAttrib *other) const;
72  INLINE CPT(RenderAttrib) invert_compose(const RenderAttrib *other) const;
73  virtual bool lower_attrib_can_override() const;
74 
75 public:
76  INLINE bool always_reissue() const;
77 
78  virtual bool has_cull_callback() const;
79  virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const;
80 
81 PUBLISHED:
82  INLINE int compare_to(const RenderAttrib &other) const;
83  INLINE size_t get_hash() const;
84  INLINE CPT(RenderAttrib) get_unique() const;
85  INLINE CPT(RenderAttrib) get_auto_shader_attrib(const RenderState *state) const;
86 
87  virtual bool unref() const FINAL;
88 
89  virtual void output(ostream &out) const;
90  virtual void write(ostream &out, int indent_level) const;
91 
92  static int get_num_attribs();
93  static void list_attribs(ostream &out);
94  static int garbage_collect();
95  static bool validate_attribs();
96 
97  virtual int get_slot() const=0;
98 
99  enum PandaCompareFunc { // intentionally defined to match D3DCMPFUNC
100  M_none=0, // alpha-test disabled (always-draw)
101  M_never, // Never draw.
102  M_less, // incoming < reference_alpha
103  M_equal, // incoming == reference_alpha
104  M_less_equal, // incoming <= reference_alpha
105  M_greater, // incoming > reference_alpha
106  M_not_equal, // incoming != reference_alpha
107  M_greater_equal, // incoming >= reference_alpha
108  M_always // Always draw.
109  };
110 
111  // This is the enumerated type for TexGenAttrib. It is inherited
112  // into TexGenAttrib. It is defined up at this level only to avoid
113  // circular dependencies in the header files.
114  enum TexGenMode {
115  M_off,
116 
117  // In the types below, "eye" means the coordinate space of the
118  // observing camera, and "world" means world coordinates, e.g. the
119  // coordinate space of the root of the graph.
120 
121  // Sphere maps are classic static reflection maps. They are
122  // supported on just about any hardware, and require a precomputed
123  // 360-degree fisheye image. Sphere maps only make sense in eye
124  // coordinate space.
125  M_eye_sphere_map,
126 
127  // Cube maps are a modern improvement on the sphere map; they
128  // don't suffer from any polar singularities, but they require six
129  // texture images. They can also be generated dynamically for
130  // real-time reflections (see GraphicsOutput::make_cube_map()).
131  // Typically, a statically-generated cube map will be in eye
132  // space, while a dynamically-generated map will be in world
133  // space.
134  //
135  // Cube mapping is not supported on all hardware.
136  M_world_cube_map,
137  M_eye_cube_map,
138 
139  // Normal maps are most useful for applying diffuse lighting
140  // effects via a pregenerated cube map.
141  M_world_normal,
142  M_eye_normal,
143 
144  // Position maps convert XYZ coordinates directly to texture
145  // coordinates. This is particularly useful for implementing
146  // projective texturing (see NodePath::project_texture()).
147  M_world_position,
148  M_unused, // formerly M_object_position, now deprecated.
149  M_eye_position,
150 
151  // With M_point_sprite, texture coordinates will be generated for
152  // large points in the range (0,0) - (1,1) from upper-left to
153  // lower-right across the point's face. Without this, each point
154  // will have just a single uniform texture coordinate value across
155  // its face.
156  //
157  // Unfortunately, the generated texture coordinates are inverted
158  // (upside-down) from Panda's usual convention, but this is what
159  // the graphics card manufacturers decided to use. You could use
160  // a texture matrix to re-invert the texture, but that will
161  // probably force the sprites' vertices to be computed in the CPU.
162  // You'll have to paint your textures upside-down if you want true
163  // hardware sprites.
164  M_point_sprite,
165 
166  // M_light_vector generated special 3-d texture coordinates that
167  // represented the vector to a particular Light in the scene graph,
168  // expressed in each vertex's tangent space. This has now been
169  // removed. We need to reserve the slot in the enum, though, to
170  // make sure the following enum value still has the same value.
171  M_unused2,
172 
173  // M_constant generates the same fixed texture coordinates at each
174  // vertex. Not terribly useful, of course, except for certain
175  // special effects involving moving a flat color over an object.
176  M_constant,
177  };
178 
179 protected:
180  INLINE void calc_hash();
181 
182  static CPT(RenderAttrib) return_new(RenderAttrib *attrib);
183  static CPT(RenderAttrib) return_unique(RenderAttrib *attrib);
184  virtual int compare_to_impl(const RenderAttrib *other) const;
185  virtual size_t get_hash_impl() const;
186  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
187  virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
188  virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
189  void output_comparefunc(ostream &out, PandaCompareFunc fn) const;
190 
191 public:
192  INLINE static int register_slot(TypeHandle type_handle, int sort,
193  RenderAttribRegistry::MakeDefaultFunc *make_default_func);
194 
195 private:
196  void release_new();
197 
198 protected:
199  bool _always_reissue;
200 
201 public:
202  static void init_attribs();
203 
204 private:
205  // This mutex protects _attribs.
206  static LightReMutex *_attribs_lock;
207  class Empty {
208  };
210  static Attribs *_attribs;
211 
212  int _saved_entry;
213  size_t _hash;
214 
215  // This keeps track of our current position through the garbage
216  // collection cycle.
217  static int _garbage_index;
218 
219  static PStatCollector _garbage_collect_pcollector;
220 
221 public:
222  virtual void write_datagram(BamWriter *manager, Datagram &dg);
223  static TypedWritable *change_this(TypedWritable *old_ptr, BamReader *manager);
224  virtual void finalize(BamReader *manager);
225 
226 protected:
227  static TypedWritable *new_from_bam(RenderAttrib *attrib, BamReader *manager);
228  void fillin(DatagramIterator &scan, BamReader *manager);
229 
230 public:
231  static TypeHandle get_class_type() {
232  return _type_handle;
233  }
234  static void init_type() {
235  TypedWritableReferenceCount::init_type();
236  register_type(_type_handle, "RenderAttrib",
237  TypedWritableReferenceCount::get_class_type());
238  }
239  virtual TypeHandle get_type() const {
240  return get_class_type();
241  }
242  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
243 
244 private:
245  static TypeHandle _type_handle;
246 };
247 
248 INLINE ostream &operator << (ostream &out, const RenderAttrib &attrib) {
249  attrib.output(out);
250  return out;
251 }
252 
253 #include "renderAttrib.I"
254 
255 #endif
256 
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:60
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
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
A lightweight reentrant mutex.
Definition: lightReMutex.h:34
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This template class implements an unordered map of keys to data, implemented as a hashtable...
Definition: simpleHashMap.h:33
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A lightweight class that represents a single element that may be timed and/or counted via stats...
This describes the structure of a single array within a Geom data.
virtual bool unref() const
Explicitly decrements the reference count.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
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
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
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
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48