Panda3D
internalName.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 internalName.I
10  * @author masad
11  * @date 2004-07-15
12  */
13 
14 /**
15  * The public interface for constructing an InternalName pointer. This will
16  * return a new InternalName representing the indicated name, if this is the
17  * first time the particular name has been requested; if the name is already
18  * in use, it will return the existing pointer.
19  *
20  * If the string contains the '.' character, the string will be divided at the
21  * dots and the so-defined hierarchy of names will be registered. This is
22  * handled transparently.
23  */
24 INLINE PT(InternalName) InternalName::
25 make(const std::string &name) {
26  return get_root()->append(name);
27 }
28 
29 /**
30  * This version of make() is defined such as to accept mostly string literals,
31  * which may be string pooled by the compiler. This allows us to make an
32  * additional optimization.
33  *
34  * This constructor is also used for fixed-size arrays, since there is no neat
35  * way to catch string literals only. Presumably people aren't using
36  * InternalName in that way.
37  */
38 template<int N>
39 INLINE PT(InternalName) InternalName::
40 make(const char (&literal)[N]) {
41  LightMutexHolder holder(_literal_table_lock);
42  LiteralTable::const_iterator it = _literal_table.find(literal);
43 
44  if (it == _literal_table.end()) {
45  PT(InternalName) name = get_root()->append(literal);
46  _literal_table.insert(LiteralTable::value_type(literal, name));
47  return name;
48  } else {
49  return it->second;
50  }
51 }
52 
53 /**
54  * Return the parent of this InternalName. All names have a parent, except
55  * the root name.
56  */
58 get_parent() const {
59  return _parent;
60 }
61 
62 /**
63  * Return the name represented by just this particular InternalName object,
64  * ignoring its parents names. This is everything after the rightmost dot.
65  */
66 INLINE const std::string &InternalName::
67 get_basename() const {
68  return _basename;
69 }
70 
71 /**
72  * Returns the standard root InternalName. This is the root of all other
73  * InternalNames. It has no name itself, and it is the only InternalName with
74  * no parent.
75  */
76 INLINE PT(InternalName) InternalName::
77 get_root() {
78  if (_root == nullptr) {
79  _root = new InternalName(nullptr, "");
80  }
81  return _root;
82 }
83 
84 /**
85  * Returns the standard InternalName "error".
86  */
87 INLINE PT(InternalName) InternalName::
88 get_error() {
89  if (_error == nullptr) {
90  _error = InternalName::make("error");
91  }
92  return _error;
93 }
94 
95 /**
96  * Returns the standard InternalName "vertex". This is the column header for
97  * the 3-d or 4-d vertex position information for each vertex.
98  */
99 INLINE PT(InternalName) InternalName::
100 get_vertex() {
101  if (_vertex == nullptr) {
102  _vertex = InternalName::make("vertex");
103  }
104  return _vertex;
105 }
106 
107 /**
108  * Returns the standard InternalName "normal". This is the column header for
109  * the 3-d lighting normal for each vertex.
110  */
111 INLINE PT(InternalName) InternalName::
112 get_normal() {
113  if (_normal == nullptr) {
114  _normal = InternalName::make("normal");
115  }
116  return _normal;
117 }
118 
119 /**
120  * Returns the standard InternalName "tangent". This is the column header for
121  * the tangent vector associated with each vertex, which is a unit vector
122  * usually perpendicular to the normal and in the direction of the U texture
123  * coordinate change. It is used for deriving bump maps.
124  */
125 INLINE PT(InternalName) InternalName::
126 get_tangent() {
127  if (_tangent == nullptr) {
128  _tangent = InternalName::make("tangent");
129  }
130  return _tangent;
131 }
132 
133 /**
134  * Returns the InternalName "tangent.name", where name is the supplied string.
135  * This is the column header for the tangent associated with the named texture
136  * coordinate set.
137  */
138 INLINE PT(InternalName) InternalName::
139 get_tangent_name(const std::string &name) {
140  return get_tangent()->append(name);
141 }
142 
143 /**
144  * Returns the standard InternalName "binormal". This is the column header
145  * for the tangent vector associated with each vertex, which is a unit vector
146  * usually perpendicular to both the normal and the tangent, and in the
147  * direction of the V texture coordinate change. It is used for deriving bump
148  * maps.
149  */
150 INLINE PT(InternalName) InternalName::
151 get_binormal() {
152  if (_binormal == nullptr) {
153  _binormal = InternalName::make("binormal");
154  }
155  return _binormal;
156 }
157 
158 /**
159  * Returns the InternalName "binormal.name", where name is the supplied
160  * string. This is the column header for the binormal associated with the
161  * named texture coordinate set.
162  */
163 INLINE PT(InternalName) InternalName::
164 get_binormal_name(const std::string &name) {
165  return get_binormal()->append(name);
166 }
167 
168 /**
169  * Returns the standard InternalName "texcoord". This is the column header
170  * for the default texture coordinate set for each vertex. It is also used
171  * for identifying the default texture coordinate set in a TextureStage.
172  */
173 INLINE PT(InternalName) InternalName::
174 get_texcoord() {
175  if (_texcoord == nullptr) {
176  _texcoord = InternalName::make("texcoord");
177  }
178  return _texcoord;
179 }
180 
181 /**
182  * Returns the InternalName "texcoord.name", where name is the supplied
183  * string. This is the column header for the named texture coordinate set for
184  * each vertex. It is also used for identifying the named texture coordinate
185  * set in a TextureStage.
186  */
187 INLINE PT(InternalName) InternalName::
188 get_texcoord_name(const std::string &name) {
189  return get_texcoord()->append(name);
190 }
191 
192 /**
193  * Returns the standard InternalName "color". This is the column header for
194  * the 4-component color value for each vertex.
195  */
196 INLINE PT(InternalName) InternalName::
197 get_color() {
198  if (_color == nullptr) {
199  _color = InternalName::make("color");
200  }
201  return _color;
202 }
203 
204 /**
205  * Returns the standard InternalName "rotate". This is the column header for
206  * the floating-point rotate value, which represents a number of degrees
207  * counter-clockwise to rotate each point or point sprite.
208  */
209 INLINE PT(InternalName) InternalName::
210 get_rotate() {
211  if (_rotate == nullptr) {
212  _rotate = InternalName::make("rotate");
213  }
214  return _rotate;
215 }
216 
217 /**
218  * Returns the standard InternalName "size". This is the column header for
219  * the floating-point size value, which overrides the thickness parameter of
220  * the RenderModeAttrib on a per-vertex (e.g. per-point) basis.
221  */
222 INLINE PT(InternalName) InternalName::
223 get_size() {
224  if (_size == nullptr) {
225  _size = InternalName::make("size");
226  }
227  return _size;
228 }
229 
230 /**
231  * Returns the standard InternalName "aspect_ratio". This is the column header
232  * for the floating-point aspect ratio value, which is used to define non-
233  * square points. This number is the ratio x / y, where y is the point size
234  * (above).
235  */
236 INLINE PT(InternalName) InternalName::
237 get_aspect_ratio() {
238  if (_aspect_ratio == nullptr) {
239  _aspect_ratio = InternalName::make("aspect_ratio");
240  }
241  return _aspect_ratio;
242 }
243 
244 /**
245  * Returns the standard InternalName "transform_blend". This is the column
246  * header for the integer transform_blend index, which is used to define
247  * vertex animation on the CPU by indexing to a particular vertex weighting
248  * from the TransformBlendTable.
249  */
250 INLINE PT(InternalName) InternalName::
251 get_transform_blend() {
252  if (_transform_blend == nullptr) {
253  _transform_blend = InternalName::make("transform_blend");
254  }
255  return _transform_blend;
256 }
257 
258 /**
259  * Returns the standard InternalName "transform_weight". This is the column
260  * header for the n-component transform_weight value, which is used in
261  * conjuntion with "transform_index" to define vertex animation on the
262  * graphics card. The transform_weight value specifies the weight of the nth
263  * transform. By convention, there are 1 fewer weight values than transforms,
264  * since the weights are assumed to sum to 1 (and the last value is therefore
265  * implicit).
266  */
267 INLINE PT(InternalName) InternalName::
268 get_transform_weight() {
269  if (_transform_weight == nullptr) {
270  _transform_weight = InternalName::make("transform_weight");
271  }
272  return _transform_weight;
273 }
274 
275 /**
276  * Returns the standard InternalName "transform_index". This is the column
277  * header for the n-component transform_index value, which is used in
278  * conjuntion with "transform_weight" to define vertex animation on the
279  * graphics card. The transform_index value specifies the nth transform, by
280  * lookup in the TransformTable. The transform_index column may be omitted,
281  * in which case the nth transform is the nth entry in the table.
282  */
283 INLINE PT(InternalName) InternalName::
284 get_transform_index() {
285  if (_transform_index == nullptr) {
286  _transform_index = InternalName::make("transform_index");
287  }
288  return _transform_index;
289 }
290 
291 /**
292  * Returns an InternalName derived from the given base column name and the
293  * given slider name, which is the column header for the offset vector that
294  * should be applied to the base column name when the named morph slider is
295  * engaged.
296  *
297  * Each morph slider requires a set of n morph columns, one for each base
298  * column it applies to.
299  */
300 INLINE PT(InternalName) InternalName::
301 get_morph(InternalName *column, const std::string &slider) {
302  // This actually returns "column.morph.slider", although that's just an
303  // implementation detail--as long as it returns a consistent, unique name
304  // for each combination of column and slider, everything is good.
305  return column->append("morph")->append(slider);
306 }
307 
308 /**
309  * Returns the standard InternalName "index". This is the column header for
310  * the integer vertex index. It is not used in the vertex data itself, but is
311  * used in the GeomPrimitive structure to index into the vertex data.
312  */
313 INLINE PT(InternalName) InternalName::
314 get_index() {
315  if (_index == nullptr) {
316  _index = InternalName::make("index");
317  }
318  return _index;
319 }
320 
321 /**
322  * Returns the standard InternalName "world". This is used as a keyword in
323  * the shader subsystem.
324  */
325 INLINE PT(InternalName) InternalName::
326 get_world() {
327  if (_world == nullptr) {
328  _world = InternalName::make("world");
329  }
330  return _world;
331 }
332 
333 /**
334  * Returns the standard InternalName "camera". This is used as a keyword in
335  * the shader subsystem.
336  */
337 INLINE PT(InternalName) InternalName::
338 get_camera() {
339  if (_camera == nullptr) {
340  _camera = InternalName::make("camera");
341  }
342  return _camera;
343 }
344 
345 /**
346  * Returns the standard InternalName "model". This is used as a keyword in
347  * the shader subsystem.
348  */
349 INLINE PT(InternalName) InternalName::
350 get_model() {
351  if (_model == nullptr) {
352  _model = InternalName::make("model");
353  }
354  return _model;
355 }
356 
357 /**
358  * Returns the standard InternalName "view". This is used as a keyword in the
359  * shader subsystem.
360  */
361 INLINE PT(InternalName) InternalName::
362 get_view() {
363  if (_view == nullptr) {
364  _view = InternalName::make("view");
365  }
366  return _view;
367 }
368 
369 /**
370  *
371  */
372 INLINE std::ostream &
373 operator << (std::ostream &out, const InternalName &tcn) {
374  tcn.output(out);
375  return out;
376 }
377 
378 #ifndef CPPPARSER
379 /**
380  *
381  */
382 INLINE CPT_InternalName::
383 CPT_InternalName(const InternalName *ptr) :
385 {
386 }
387 
388 /**
389  *
390  */
391 INLINE CPT_InternalName::
392 CPT_InternalName(const PointerTo<InternalName> &copy) :
394 {
395 }
396 
397 /**
398  *
399  */
400 INLINE CPT_InternalName::
401 CPT_InternalName(const ConstPointerTo<InternalName> &copy) :
403 {
404 }
405 
406 /**
407  *
408  */
409 INLINE CPT_InternalName::
410 CPT_InternalName(const std::string &name) :
412 {
413 }
414 
415 /**
416  *
417  */
418 template<int N>
419 INLINE CPT_InternalName::
420 CPT_InternalName(const char (&literal)[N]) :
421  ConstPointerTo<InternalName>(InternalName::make(literal))
422 {
423 }
424 
425 /**
426  *
427  */
428 INLINE CPT_InternalName::
429 CPT_InternalName(PointerTo<InternalName> &&from) noexcept :
430  ConstPointerTo<InternalName>(std::move(from))
431 {
432 }
433 
434 /**
435  *
436  */
437 INLINE CPT_InternalName::
438 CPT_InternalName(ConstPointerTo<InternalName> &&from) noexcept :
439  ConstPointerTo<InternalName>(std::move(from))
440 {
441 }
442 
443 /**
444  *
445  */
446 INLINE CPT_InternalName &CPT_InternalName::
447 operator = (PointerTo<InternalName> &&from) noexcept {
448  this->reassign(std::move(from));
449  return *this;
450 }
451 
452 /**
453  *
454  */
455 INLINE CPT_InternalName &CPT_InternalName::
456 operator = (ConstPointerTo<InternalName> &&from) noexcept {
457  this->reassign(std::move(from));
458  return *this;
459 }
460 
461 /**
462  *
463  */
464 INLINE CPT_InternalName &CPT_InternalName::
465 operator = (const To *ptr) {
466  this->reassign((To *)ptr);
467  return *this;
468 }
469 
470 /**
471  *
472  */
473 INLINE CPT_InternalName &CPT_InternalName::
474 operator = (const PointerTo<InternalName> &copy) {
475  this->reassign((const ConstPointerTo<InternalName> &)copy);
476  return *this;
477 }
478 
479 /**
480  *
481  */
482 INLINE CPT_InternalName &CPT_InternalName::
483 operator = (const ConstPointerTo<InternalName> &copy) {
484  this->reassign((const ConstPointerTo<InternalName> &)copy);
485  return *this;
486 }
487 #endif // CPPPARSER
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition: internalName.h:193
PT(InternalName) InternalName
The public interface for constructing an InternalName pointer.
Definition: internalName.I:24
get_parent
Return the parent of this InternalName.
Definition: internalName.h:60
Similar to MutexHolder, but for a light mutex.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing.
Definition: pointerTo.h:144
This file defines the classes PointerTo and ConstPointerTo (and their abbreviations,...
Definition: pointerTo.h:69