Panda3D
renderAttrib.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file renderAttrib.I
10  * @author drose
11  * @date 2002-02-21
12  */
13 
14 /**
15  * Returns a new RenderAttrib object that represents the composition of this
16  * attrib with the other attrib. In most cases, this is the same as the other
17  * attrib; a compose b produces b. Some kinds of attributes, like a
18  * TextureTransform, for instance, might produce a new result: a compose b
19  * produces c.
20  */
21 INLINE CPT(RenderAttrib) RenderAttrib::
22 compose(const RenderAttrib *other) const {
23  return compose_impl(other);
24 }
25 
26 /**
27  * Returns a new RenderAttrib object that represents the composition of the
28  * inverse of this attrib with the other attrib. In most cases, this is the
29  * same as the other attrib; !a compose b produces b. Some kinds of
30  * attributes, like a TextureTransform, for instance, might produce a new
31  * result: !a compose b produces c.
32  *
33  * This is similar to compose() except that the source attrib is inverted
34  * first. This is used to compute the relative attribute for one node as
35  * viewed from some other node, which is especially useful for transform-type
36  * attributes.
37  */
38 INLINE CPT(RenderAttrib) RenderAttrib::
39 invert_compose(const RenderAttrib *other) const {
40  return invert_compose_impl(other);
41 }
42 
43 /**
44  * Provides an arbitrary ordering among all unique RenderAttribs, so we can
45  * store the essentially different ones in a big set and throw away the rest.
46  *
47  * This method is not needed outside of the RenderAttrib class because all
48  * equivalent RenderAttrib objects are guaranteed to share the same pointer;
49  * thus, a pointer comparison is always sufficient.
50  */
51 INLINE int RenderAttrib::
52 compare_to(const RenderAttrib &other) const {
53  // First, we compare the types; if they are of different types then they
54  // sort differently.
55  TypeHandle type = get_type();
56  TypeHandle other_type = other.get_type();
57  if (type != other_type) {
58  return type.get_index() - other_type.get_index();
59  }
60 
61  // We only call compare_to_impl() if they have the same type.
62  return compare_to_impl(&other);
63 }
64 
65 /**
66  * Returns a suitable hash value for phash_map.
67  */
68 INLINE size_t RenderAttrib::
69 get_hash() const {
70  return _hash;
71 }
72 
73 /**
74  * Returns the pointer to the unique RenderAttrib in the cache that is
75  * equivalent to this one. This may be the same pointer as this object, or it
76  * may be a different pointer; but it will be an equivalent object, and it
77  * will be a shared pointer. This may be called from time to time to improve
78  * cache benefits.
79  */
80 INLINE CPT(RenderAttrib) RenderAttrib::
81 get_unique() const {
82  return return_unique((RenderAttrib *)this);
83 }
84 
85 /**
86  * Calculates a suitable hash value for phash_map.
87  */
88 INLINE void RenderAttrib::
89 calc_hash() {
90  size_t hash = get_hash_impl();
91 
92  // The type is also added to the hash.
93  _hash = int_hash::add_hash(hash, get_type().get_index());
94 }
95 
96 /**
97  * Adds the indicated TypeHandle to the registry, if it is not there already,
98  * and returns a unique slot number. See RenderAttribRegistry.
99  */
100 INLINE int RenderAttrib::
101 register_slot(TypeHandle type_handle, int sort, RenderAttrib *default_attrib) {
102  RenderAttribRegistry *reg = RenderAttribRegistry::get_global_ptr();
103  return reg->register_slot(type_handle, sort, default_attrib);
104 }
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
CPT(RenderAttrib) RenderAttrib
Returns a new RenderAttrib object that represents the composition of this attrib with the other attri...
Definition: renderAttrib.I:21
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
Definition: stl_compares.I:101
int register_slot(TypeHandle type_handle, int sort, RenderAttrib *default_attrib)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
static int register_slot(TypeHandle type_handle, int sort, RenderAttrib *default_attrib)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition: renderAttrib.I:101
This class is used to associate each RenderAttrib with a different slot index at runtime,...
get_index
Returns the integer index associated with this TypeHandle.
Definition: typeHandle.h:135
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81