Panda3D
renderAttrib.I
1 // Filename: renderAttrib.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: RenderAttrib::compose
18 // Access: Published
19 // Description: Returns a new RenderAttrib object that represents the
20 // composition of this attrib with the other attrib. In
21 // most cases, this is the same as the other attrib; a
22 // compose b produces b. Some kinds of attributes, like
23 // a TextureTransform, for instance, might produce a new
24 // result: a compose b produces c.
25 ////////////////////////////////////////////////////////////////////
26 INLINE CPT(RenderAttrib) RenderAttrib::
27 compose(const RenderAttrib *other) const {
28  return compose_impl(other);
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: RenderAttrib::invert_compose
33 // Access: Published
34 // Description: Returns a new RenderAttrib object that represents the
35 // composition of the inverse of this attrib with the
36 // other attrib. In most cases, this is the same as the
37 // other attrib; !a compose b produces b. Some kinds of
38 // attributes, like a TextureTransform, for instance,
39 // might produce a new result: !a compose b produces c.
40 //
41 // This is similar to compose() except that the source
42 // attrib is inverted first. This is used to compute
43 // the relative attribute for one node as viewed from
44 // some other node, which is especially useful for
45 // transform-type attributes.
46 ////////////////////////////////////////////////////////////////////
47 INLINE CPT(RenderAttrib) RenderAttrib::
48 invert_compose(const RenderAttrib *other) const {
49  return invert_compose_impl(other);
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: RenderAttrib::always_reissue
54 // Access: Public
55 // Description: Returns true if the RenderAttrib should be reissued
56 // to the GSG with every state change, even if it is the
57 // same pointer as it was before; or false for the
58 // normal case, to reissue only when the RenderAttrib
59 // pointer changes.
60 ////////////////////////////////////////////////////////////////////
61 INLINE bool RenderAttrib::
62 always_reissue() const {
63  return _always_reissue;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: RenderAttrib::compare_to
68 // Access: Published
69 // Description: Provides an arbitrary ordering among all unique
70 // RenderAttribs, so we can store the essentially
71 // different ones in a big set and throw away the rest.
72 //
73 // This method is not needed outside of the RenderAttrib
74 // class because all equivalent RenderAttrib objects are
75 // guaranteed to share the same pointer; thus, a pointer
76 // comparison is always sufficient.
77 ////////////////////////////////////////////////////////////////////
78 INLINE int RenderAttrib::
79 compare_to(const RenderAttrib &other) const {
80  // First, we compare the types; if they are of different types then
81  // they sort differently.
82  TypeHandle type = get_type();
83  TypeHandle other_type = other.get_type();
84  if (type != other_type) {
85  return type.get_index() - other_type.get_index();
86  }
87 
88  // We only call compare_to_impl() if they have the same type.
89  return compare_to_impl(&other);
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: RenderAttrib::get_hash
94 // Access: Published
95 // Description: Returns a suitable hash value for phash_map.
96 ////////////////////////////////////////////////////////////////////
97 INLINE size_t RenderAttrib::
98 get_hash() const {
99  return _hash;
100 }
101 
102 ////////////////////////////////////////////////////////////////////
103 // Function: RenderAttrib::get_unique
104 // Access: Published
105 // Description: Returns the pointer to the unique RenderAttrib in
106 // the cache that is equivalent to this one. This may
107 // be the same pointer as this object, or it may be a
108 // different pointer; but it will be an equivalent
109 // object, and it will be a shared pointer. This may be
110 // called from time to time to improve cache benefits.
111 ////////////////////////////////////////////////////////////////////
112 INLINE CPT(RenderAttrib) RenderAttrib::
113 get_unique() const {
114  return return_unique((RenderAttrib *)this);
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: RenderAttrib::get_auto_shader_attrib
119 // Access: Published
120 // Description: Returns the variant of this RenderAttrib that's most
121 // relevant for associating with an auto-generated
122 // shader. This should be a new RenderAttrib of the
123 // same type as this one, with any superfluous data set
124 // to neutral. Only the parts of the attrib that
125 // contribute to the shader should be reflected in the
126 // returned attrib. The idea is to associate the
127 // auto-generated shader with the most neutral form of
128 // all states, to allow it to be shared across as many
129 // RenderState objects as possible.
130 //
131 // If this RenderAttrib is completely irrelevant to the
132 // auto-shader, this should return NULL to indicate that
133 // the attrib won't be assocaited with the shader at
134 // all. In this case the attrib does not contribute to
135 // the shader meaningfully.
136 ////////////////////////////////////////////////////////////////////
137 INLINE CPT(RenderAttrib) RenderAttrib::
138 get_auto_shader_attrib(const RenderState *state) const {
139  return get_auto_shader_attrib_impl(state);
140 }
141 
142 ////////////////////////////////////////////////////////////////////
143 // Function: RenderAttrib::calc_hash
144 // Access: Published
145 // Description: Calculates a suitable hash value for phash_map.
146 ////////////////////////////////////////////////////////////////////
147 INLINE void RenderAttrib::
148 calc_hash() {
149  size_t hash = get_hash_impl();
150 
151  // The type is also added to the hash.
152  _hash = int_hash::add_hash(hash, get_type().get_index());
153 }
154 
155 ////////////////////////////////////////////////////////////////////
156 // Function: RenderAttrib::register_slot
157 // Access: Public, Static
158 // Description: Adds the indicated TypeHandle to the registry, if it
159 // is not there already, and returns a unique slot
160 // number. See RenderAttribRegistry.
161 ////////////////////////////////////////////////////////////////////
162 INLINE int RenderAttrib::
163 register_slot(TypeHandle type_handle, int sort,
164  RenderAttribRegistry::MakeDefaultFunc *make_default_func) {
165  RenderAttribRegistry *reg = RenderAttribRegistry::get_global_ptr();
166  return reg->register_slot(type_handle, sort, make_default_func);
167 }
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
int get_index() const
Returns the integer index associated with this TypeHandle.
Definition: typeHandle.I:253
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
Definition: stl_compares.I:122
int register_slot(TypeHandle type_handle, int sort, MakeDefaultFunc *make_default_func)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
This class is used to associate each RenderAttrib with a different slot index at runtime, so we can store a list of RenderAttribs in the RenderState object, and very quickly look them up by type.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85