Panda3D

shaderInput.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 shaderInput.I
10 * @author jyelon
11 * @date 2005-09-01
12 * @author fperazzi, PandaSE
13 * @date 2010-04-06
14 */
15
16 /**
17 *
18 */
19 INLINE ShaderInput::
20 ShaderInput(CPT_InternalName name, int priority) :
21 _name(std::move(name)),
22 _type(M_invalid),
23 _priority(priority)
24 {
25 }
26
27 /**
28 *
29 */
30 INLINE ShaderInput::
31 ShaderInput(CPT_InternalName name, Texture *tex, int priority) :
32 _name(std::move(name)),
33 _type(M_texture),
34 _priority(priority),
35 _value(tex)
36 {
37 }
38
39 /**
40 *
41 */
42 INLINE ShaderInput::
43 ShaderInput(CPT_InternalName name, ParamValueBase *param, int priority) :
44 _name(std::move(name)),
45 _type(M_param),
46 _priority(priority),
47 _value(param)
48 {
49 }
50
51 /**
52 *
53 */
54 INLINE ShaderInput::
55 ShaderInput(CPT_InternalName name, ShaderBuffer *buf, int priority) :
56 _name(std::move(name)),
57 _type(M_buffer),
58 _priority(priority),
59 _value(buf)
60 {
61 }
62
63 /**
64 *
65 */
66 INLINE ShaderInput::
67 ShaderInput(CPT_InternalName name, const PTA_float &ptr, int priority) :
68 _name(std::move(name)),
69 _type(M_numeric),
70 _priority(priority),
71 _stored_ptr(ptr)
72 {
73 }
74
75 /**
76 *
77 */
78 INLINE ShaderInput::
79 ShaderInput(CPT_InternalName name, const PTA_LVecBase4f &ptr, int priority) :
80 _name(std::move(name)),
81 _type(M_numeric),
82 _priority(priority),
83 _stored_ptr(ptr)
84 {
85 }
86
87 /**
88 *
89 */
90 INLINE ShaderInput::
91 ShaderInput(CPT_InternalName name, const PTA_LVecBase3f &ptr, int priority) :
92 _name(std::move(name)),
93 _type(M_numeric),
94 _priority(priority),
95 _stored_ptr(ptr)
96 {
97 }
98
99 /**
100 *
101 */
102 INLINE ShaderInput::
103 ShaderInput(CPT_InternalName name, const PTA_LVecBase2f &ptr, int priority) :
104 _name(std::move(name)),
105 _type(M_numeric),
106 _priority(priority),
107 _stored_ptr(ptr)
108 {
109 }
110
111 /**
112 *
113 */
114 INLINE ShaderInput::
115 ShaderInput(CPT_InternalName name, const LVecBase4f &vec, int priority) :
116 _name(std::move(name)),
117 _type(M_vector),
118 _priority(priority),
119 _stored_ptr(vec),
120 _stored_vector(LCAST(PN_stdfloat, vec))
121 {
122 }
123
124 /**
125 *
126 */
127 INLINE ShaderInput::
128 ShaderInput(CPT_InternalName name, const LVecBase3f &vec, int priority) :
129 _name(std::move(name)),
130 _type(M_vector),
131 _priority(priority),
132 _stored_ptr(vec),
133 _stored_vector(vec.get_x(), vec.get_y(), vec.get_z(), 0.0)
134 {
135 }
136
137 /**
138 *
139 */
140 INLINE ShaderInput::
141 ShaderInput(CPT_InternalName name, const LVecBase2f &vec, int priority) :
142 _name(std::move(name)),
143 _type(M_vector),
144 _priority(priority),
145 _stored_ptr(vec),
146 _stored_vector(vec.get_x(), vec.get_y(), 0.0, 0.0)
147 {
148 }
149
150 /**
151 *
152 */
153 INLINE ShaderInput::
154 ShaderInput(CPT_InternalName name, const PTA_LMatrix4f &ptr, int priority) :
155 _name(std::move(name)),
156 _type(M_numeric),
157 _priority(priority),
158 _stored_ptr(ptr)
159 {
160 }
161
162 /**
163 *
164 */
165 INLINE ShaderInput::
166 ShaderInput(CPT_InternalName name, const PTA_LMatrix3f &ptr, int priority) :
167 _name(std::move(name)),
168 _type(M_numeric),
169 _priority(priority),
170 _stored_ptr(ptr)
171 {
172 }
173
174 /**
175 *
176 */
177 INLINE ShaderInput::
178 ShaderInput(CPT_InternalName name, const LMatrix4f &mat, int priority) :
179 _name(std::move(name)),
180 _type(M_numeric),
181 _priority(priority),
182 _stored_ptr(mat)
183 {
184 }
185
186 /**
187 *
188 */
189 INLINE ShaderInput::
190 ShaderInput(CPT_InternalName name, const LMatrix3f &mat, int priority) :
191 _name(std::move(name)),
192 _type(M_numeric),
193 _priority(priority),
194 _stored_ptr(mat)
195 {
196 }
197
198 /**
199 *
200 */
201 INLINE ShaderInput::
202 ShaderInput(CPT_InternalName name, const PTA_double &ptr, int priority) :
203 _name(std::move(name)),
204 _type(M_numeric),
205 _priority(priority),
206 _stored_ptr(ptr)
207 {
208 }
209
210 /**
211 *
212 */
213 INLINE ShaderInput::
214 ShaderInput(CPT_InternalName name, const PTA_LVecBase4d &ptr, int priority) :
215 _name(std::move(name)),
216 _type(M_numeric),
217 _priority(priority),
218 _stored_ptr(ptr)
219 {
220 }
221
222 /**
223 *
224 */
225 INLINE ShaderInput::
226 ShaderInput(CPT_InternalName name, const PTA_LVecBase3d &ptr, int priority) :
227 _name(std::move(name)),
228 _type(M_numeric),
229 _priority(priority),
230 _stored_ptr(ptr)
231 {
232 }
233
234 /**
235 *
236 */
237 INLINE ShaderInput::
238 ShaderInput(CPT_InternalName name, const PTA_LVecBase2d &ptr, int priority) :
239 _name(std::move(name)),
240 _type(M_numeric),
241 _priority(priority),
242 _stored_ptr(ptr)
243 {
244 }
245
246 /**
247 *
248 */
249 INLINE ShaderInput::
250 ShaderInput(CPT_InternalName name, const LVecBase4d &vec, int priority) :
251 _name(std::move(name)),
252 _type(M_numeric),
253 _priority(priority),
254 _stored_ptr(vec),
255 _stored_vector(LCAST(PN_stdfloat, vec))
256 {
257 }
258
259 /**
260 *
261 */
262 INLINE ShaderInput::
263 ShaderInput(CPT_InternalName name, const LVecBase3d &vec, int priority) :
264 _name(std::move(name)),
265 _type(M_numeric),
266 _priority(priority),
267 _stored_ptr(vec),
268 _stored_vector(vec.get_x(), vec.get_y(), vec.get_z(), 0.0)
269 {
270 }
271
272 /**
273 *
274 */
275 INLINE ShaderInput::
276 ShaderInput(CPT_InternalName name, const LVecBase2d &vec, int priority) :
277 _name(std::move(name)),
278 _type(M_numeric),
279 _priority(priority),
280 _stored_ptr(vec),
281 _stored_vector(vec.get_x(), vec.get_y(), 0.0, 0.0)
282 {
283 }
284
285 /**
286 *
287 */
288 INLINE ShaderInput::
289 ShaderInput(CPT_InternalName name, const PTA_LMatrix4d &ptr, int priority) :
290 _name(std::move(name)),
291 _type(M_numeric),
292 _priority(priority),
293 _stored_ptr(ptr)
294 {
295 }
296
297 /**
298 *
299 */
300 INLINE ShaderInput::
301 ShaderInput(CPT_InternalName name, const PTA_LMatrix3d &ptr, int priority) :
302 _name(std::move(name)),
303 _type(M_numeric),
304 _priority(priority),
305 _stored_ptr(ptr)
306 {
307 }
308
309 /**
310 *
311 */
312 INLINE ShaderInput::
313 ShaderInput(CPT_InternalName name, const LMatrix4d &mat, int priority) :
314 _name(std::move(name)),
315 _type(M_numeric),
316 _priority(priority),
317 _stored_ptr(mat)
318 {
319 }
320
321 /**
322 *
323 */
324 INLINE ShaderInput::
325 ShaderInput(CPT_InternalName name, const LMatrix3d &mat, int priority) :
326 _name(std::move(name)),
327 _type(M_numeric),
328 _priority(priority),
329 _stored_ptr(mat)
330 {
331 }
332
333 /**
334 *
335 */
336 INLINE ShaderInput::
337 ShaderInput(CPT_InternalName name, const PTA_int &ptr, int priority) :
338 _name(std::move(name)),
339 _type(M_numeric),
340 _priority(priority),
341 _stored_ptr(ptr)
342 {
343 }
344
345 /**
346 *
347 */
348 INLINE ShaderInput::
349 ShaderInput(CPT_InternalName name, const PTA_LVecBase4i &ptr, int priority) :
350 _name(std::move(name)),
351 _type(M_numeric),
352 _priority(priority),
353 _stored_ptr(ptr)
354 {
355 }
356
357 /**
358 *
359 */
360 INLINE ShaderInput::
361 ShaderInput(CPT_InternalName name, const PTA_LVecBase3i &ptr, int priority) :
362 _name(std::move(name)),
363 _type(M_numeric),
364 _priority(priority),
365 _stored_ptr(ptr)
366 {
367 }
368
369 /**
370 *
371 */
372 INLINE ShaderInput::
373 ShaderInput(CPT_InternalName name, const PTA_LVecBase2i &ptr, int priority) :
374 _name(std::move(name)),
375 _type(M_numeric),
376 _priority(priority),
377 _stored_ptr(ptr)
378 {
379 }
380
381 /**
382 *
383 */
384 INLINE ShaderInput::
385 ShaderInput(CPT_InternalName name, const LVecBase4i &vec, int priority) :
386 _name(std::move(name)),
387 _type(M_numeric),
388 _priority(priority),
389 _stored_ptr(vec),
390 _stored_vector((int)vec.get_x(), (int)vec.get_y(), (int)vec.get_z(), (int)vec.get_w())
391 {
392 }
393
394 /**
395 *
396 */
397 INLINE ShaderInput::
398 ShaderInput(CPT_InternalName name, const LVecBase3i &vec, int priority) :
399 _name(std::move(name)),
400 _type(M_numeric),
401 _priority(priority),
402 _stored_ptr(vec),
403 _stored_vector((int)vec.get_x(), (int)vec.get_y(), (int)vec.get_z(), 0.0)
404 {
405 }
406
407 /**
408 *
409 */
410 INLINE ShaderInput::
411 ShaderInput(CPT_InternalName name, const LVecBase2i &vec, int priority) :
412 _name(std::move(name)),
413 _type(M_numeric),
414 _priority(priority),
415 _stored_ptr(vec),
416 _stored_vector((int)vec.get_x(), (int)vec.get_y(), 0.0, 0.0)
417 {
418 }
419
420 /**
421 *
422 */
423 INLINE ShaderInput::
424 operator bool () const {
425 return _type != M_invalid;
426 }
427
428 /**
429 *
430 */
431 INLINE bool ShaderInput::
432 operator == (const ShaderInput &other) const {
433 if (_type != other._type || _name != other._name || _priority != other._priority) {
434 return false;
435 }
436 switch (_type) {
437 case M_invalid:
438 return true;
439
440 case M_vector:
441 return _stored_vector == other._stored_vector;
442
443 case M_numeric:
444 return _stored_ptr._ptr == other._stored_ptr._ptr;
445
446 default:
447 return _value == other._value;
448 }
449 }
450
451 /**
452 *
453 */
454 INLINE bool ShaderInput::
455 operator != (const ShaderInput &other) const {
456 if (_type != other._type || _name != other._name || _priority != other._priority) {
457 return true;
458 }
459 switch (_type) {
460 case M_invalid:
461 return false;
462
463 case M_vector:
464 return _stored_vector != other._stored_vector;
465
466 case M_numeric:
467 return _stored_ptr._ptr != other._stored_ptr._ptr;
468
469 default:
470 return _value != other._value;
471 }
472 }
473
474 /**
475 *
476 */
477 INLINE bool ShaderInput::
478 operator < (const ShaderInput &other) const {
479 if (_type != other._type) {
480 return (_type < other._type);
481 }
482 if (_name != other._name) {
483 return (_name < other._name);
484 }
485 if (_priority != other._priority) {
486 return (_priority < other._priority);
487 }
488 switch (_type) {
489 case M_invalid:
490 return false;
491
492 case M_vector:
493 if (_stored_vector[0] != other._stored_vector[0]) {
494 return _stored_vector[0] < other._stored_vector[0];
495 }
496 if (_stored_vector[1] != other._stored_vector[1]) {
497 return _stored_vector[1] < other._stored_vector[1];
498 }
499 if (_stored_vector[2] != other._stored_vector[2]) {
500 return _stored_vector[2] < other._stored_vector[2];
501 }
502 if (_stored_vector[3] != other._stored_vector[3]) {
503 return _stored_vector[3] < other._stored_vector[3];
504 }
505 return false;
506
507 case M_numeric:
508 return _stored_ptr._ptr < other._stored_ptr._ptr;
509
510 default:
511 return _value < other._value;
512 }
513 }
514
515 /**
516 *
517 */
518 INLINE const InternalName *ShaderInput::
519 get_name() const {
520 return _name;
521 }
522
523 /**
524 *
525 */
526 INLINE int ShaderInput::
527 get_value_type() const {
528 return _type;
529 }
530
531 /**
532 *
533 */
534 INLINE int ShaderInput::
535 get_priority() const {
536 return _priority;
537 }
538
539 /**
540 *
541 */
542 INLINE const LVecBase4 &ShaderInput::
543 get_vector() const {
544 return _stored_vector;
545 }
546
547 /**
548 *
549 */
550 INLINE const Shader::ShaderPtrData &ShaderInput::
551 get_ptr() const {
552 return _stored_ptr;
553 }
554
555 /**
556 *
557 */
558 INLINE ParamValueBase *ShaderInput::
559 get_param() const {
560 return DCAST(ParamValueBase, _value);
561 }
562
563 /**
564 *
565 */
566 INLINE TypedWritableReferenceCount *ShaderInput::
567 get_value() const {
568 return _value.p();
569 }
CPT_InternalName
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition: internalName.h:193
InternalName
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
ParamValueBase
A non-template base class of ParamValue (below), which serves mainly to define the placeholder for th...
Definition: paramValue.h:31
ShaderBuffer
This is a generic buffer object that lives in graphics memory.
Definition: shaderBuffer.h:33
ShaderInput
This is a small container class that can hold any one of the value types that can be passed as input ...
Definition: shaderInput.h:40
Texture
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
TypedWritableReferenceCount
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
Definition: typedWritableReferenceCount.h:31
Shader::ShaderPtrData
Definition: shader.h:364