Panda3D
shader.I
1 // Filename: shader.I
2 // Heavily Modified: jyelon (Sep05)
3 // Updated by: fperazzi, PandaSE(06Apr10)
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: Shader::get_filename
18 // Access: Published
19 // Description: Return the Shader's filename for the given shader
20 // type.
21 ////////////////////////////////////////////////////////////////////
22 INLINE Filename Shader::
23 get_filename(const ShaderType &type) const {
24  if (_filename._separate && type != ST_none) {
25  switch (type) {
26  case ST_vertex:
27  return _filename._vertex;
28  break;
29  case ST_fragment:
30  return _filename._fragment;
31  break;
32  case ST_geometry:
33  return _filename._geometry;
34  break;
35  case ST_tess_control:
36  return _filename._tess_control;
37  break;
38  case ST_tess_evaluation:
39  return _filename._tess_evaluation;
40  break;
41  case ST_compute:
42  return _filename._compute;
43  break;
44  default:
45  return _filename._shared;
46  }
47  } else if (!_filename._shared.empty()) {
48  return _filename._shared;
49 
50  } else {
51  // Um, better than nothing?
52  return _filename._vertex;
53  }
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: Shader::get_text
58 // Access: Published
59 // Description: Return the Shader's text for the given shader type.
60 ////////////////////////////////////////////////////////////////////
61 INLINE const string &Shader::
62 get_text(const ShaderType &type) const {
63  if (_text._separate) {
64  nassertr(type != ST_none || !_text._shared.empty(), _text._shared);
65  switch (type) {
66  case ST_vertex:
67  return _text._vertex;
68  break;
69  case ST_fragment:
70  return _text._fragment;
71  break;
72  case ST_geometry:
73  return _text._geometry;
74  break;
75  case ST_tess_control:
76  return _text._tess_control;
77  break;
78  case ST_tess_evaluation:
79  return _text._tess_evaluation;
80  break;
81  case ST_compute:
82  return _text._compute;
83  break;
84  default:
85  return _text._shared;
86  }
87  } else {
88  return _text._shared;
89  }
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: Shader::get_error_flag
94 // Access: Public
95 // Description: Returns true if the shader contains a compile-time
96 // error. This doesn't tell you whether or not the
97 // shader is supported on the current video card.
98 ////////////////////////////////////////////////////////////////////
99 INLINE bool Shader::
100 get_error_flag() const {
101  return _error_flag;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: Shader::set_shader_utilization
106 // Access: Published, Static
107 // Description: Set this flag to SUT_none, SUT_basic, or
108 // SUT_advanced to limit panda's automatic shader
109 // generation facilities.
110 ////////////////////////////////////////////////////////////////////
111 INLINE void Shader::
112 set_shader_utilization(ShaderUtilization sut) {
113  _shader_utilization = sut;
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: Shader::get_shader_utilization
118 // Access: Published, Static
119 // Description: This flag returns SUT_none, SUT_basic, or
120 // SUT_advanced and controls the automatic generation
121 // of shaders. It is initialized from the config
122 // variable of the same name, but it can be
123 // subsequently adjusted.
124 ////////////////////////////////////////////////////////////////////
125 INLINE ShaderUtilization Shader::
127  if (_shader_utilization == SUT_unspecified) {
128  return shader_utilization;
129  } else {
130  return _shader_utilization;
131  }
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: Shader::have_shader_utilization
136 // Access: Published, Static
137 // Description: If true, then get_shader_utilization has been
138 // set using set_shader_utilization.
139 // If false, then get_shader_utilization simply
140 // returns the config variable of the same name.
141 ////////////////////////////////////////////////////////////////////
142 INLINE bool Shader::
144  return (_shader_utilization != SUT_unspecified);
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: Shader::get_language
149 // Access: Published
150 // Description: Returns the shader language in which this shader
151 // was written.
152 ////////////////////////////////////////////////////////////////////
153 INLINE Shader::ShaderLanguage Shader::
154 get_language() const {
155  return _language;
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: Shader::ShaderCapabilities Constructor
160 // Access: Public
161 // Description:
162 ////////////////////////////////////////////////////////////////////
163 INLINE Shader::ShaderCaps::
164 ShaderCaps() {
165  clear();
166 }
167 
168 ////////////////////////////////////////////////////////////////////
169 // Function: Shader::ShaderCapabilities::operator ==
170 // Access: Public
171 // Description:
172 ////////////////////////////////////////////////////////////////////
173 INLINE bool Shader::ShaderCaps::
174 operator == (const ShaderCaps &other) const {
175 #ifdef HAVE_CG
176  if ((_active_vprofile != other._active_vprofile) ||
177  (_active_fprofile != other._active_fprofile) ||
178  (_active_gprofile != other._active_gprofile) ||
179  (_ultimate_vprofile != other._ultimate_vprofile) ||
180  (_ultimate_fprofile != other._ultimate_fprofile) ||
181  (_ultimate_gprofile != other._ultimate_gprofile)) {
182  return false;
183  }
184 #endif
185  return true;
186 }
187 
188 ////////////////////////////////////////////////////////////////////
189 // Function: Shader::ShaderPtrData Constructor
190 // Access:
191 // Description:
192 ////////////////////////////////////////////////////////////////////
193 INLINE Shader::ShaderPtrData::
194 ShaderPtrData() :
195  _ptr(NULL),
196  _type(SPT_unknown),
197  _updated(true),
198  _size(0)
199 {
200 }
201 
202 ////////////////////////////////////////////////////////////////////
203 // Function: Shader::ShaderPtrData Constructor
204 // Access:
205 // Description:
206 ////////////////////////////////////////////////////////////////////
207 INLINE Shader::ShaderPtrData::
208 ShaderPtrData(const PTA_float &ptr):
209  _pta(ptr.v0()),
210  _ptr(ptr.p()),
211  _type(SPT_float),
212  _updated(true),
213  _size(ptr.size())
214 {
215 }
216 
217 ////////////////////////////////////////////////////////////////////
218 // Function: Shader::ShaderPtrData Constructor
219 // Access:
220 // Description:
221 ////////////////////////////////////////////////////////////////////
222 INLINE Shader::ShaderPtrData::
223 ShaderPtrData(const PTA_LMatrix4f &ptr):
224  _pta(ptr.v0()),
225  _ptr(ptr.p()),
226  _type(SPT_float),
227  _updated(true),
228  _size(ptr.size() * 16)
229 {
230 }
231 
232 ////////////////////////////////////////////////////////////////////
233 // Function: Shader::ShaderPtrData Constructor
234 // Access:
235 // Description:
236 ////////////////////////////////////////////////////////////////////
237 INLINE Shader::ShaderPtrData::
238 ShaderPtrData(const PTA_LMatrix3f &ptr):
239  _pta(ptr.v0()),
240  _ptr(ptr.p()),
241  _type(SPT_float),
242  _updated(true),
243  _size(ptr.size() * 9)
244 {
245 }
246 
247 ////////////////////////////////////////////////////////////////////
248 // Function: Shader::ShaderPtrData Constructor
249 // Access:
250 // Description:
251 ////////////////////////////////////////////////////////////////////
252 INLINE Shader::ShaderPtrData::
253 ShaderPtrData(const PTA_LVecBase4f &ptr):
254  _pta(ptr.v0()),
255  _ptr(ptr.p()),
256  _type(SPT_float),
257  _updated(true),
258  _size(ptr.size() * 4)
259 {
260 }
261 
262 ////////////////////////////////////////////////////////////////////
263 // Function: Shader::ShaderPtrData Constructor
264 // Access:
265 // Description:
266 ////////////////////////////////////////////////////////////////////
267 INLINE Shader::ShaderPtrData::
268 ShaderPtrData(const PTA_LVecBase3f &ptr):
269  _pta(ptr.v0()),
270  _ptr(ptr.p()),
271  _type(SPT_float),
272  _updated(true),
273  _size(ptr.size() * 3)
274 {
275 }
276 
277 ////////////////////////////////////////////////////////////////////
278 // Function: Shader::ShaderPtrData Constructor
279 // Access:
280 // Description:
281 ////////////////////////////////////////////////////////////////////
282 INLINE Shader::ShaderPtrData::
283 ShaderPtrData(const PTA_LVecBase2f &ptr):
284  _pta(ptr.v0()),
285  _ptr(ptr.p()),
286  _type(SPT_float),
287  _updated(true),
288  _size(ptr.size() * 2)
289 {
290 }
291 
292 ////////////////////////////////////////////////////////////////////
293 // Function: Shader::ShaderPtrData Constructor
294 // Access:
295 // Description:
296 ////////////////////////////////////////////////////////////////////
297 INLINE Shader::ShaderPtrData::
298 ShaderPtrData(const LVecBase4f &vec) :
299  _type(SPT_float),
300  _updated(true),
301  _size(4)
302 {
303  PTA_float pta = PTA_float::empty_array(4);
304  _pta = pta.v0();
305  _ptr = pta.p();
306  nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0]));
307  memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components());
308 }
309 
310 ////////////////////////////////////////////////////////////////////
311 // Function: Shader::ShaderPtrData Constructor
312 // Access:
313 // Description:
314 ////////////////////////////////////////////////////////////////////
315 INLINE Shader::ShaderPtrData::
316 ShaderPtrData(const LVecBase3f &vec) :
317  _type(SPT_float),
318  _updated(true),
319  _size(3)
320 {
321  PTA_float pta = PTA_float::empty_array(3);
322  _pta = pta.v0();
323  _ptr = pta.p();
324  nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0]));
325  memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components());
326 }
327 
328 ////////////////////////////////////////////////////////////////////
329 // Function: Shader::ShaderPtrData Constructor
330 // Access:
331 // Description:
332 ////////////////////////////////////////////////////////////////////
333 INLINE Shader::ShaderPtrData::
334 ShaderPtrData(const LVecBase2f &vec) :
335  _type(SPT_float),
336  _updated(true),
337  _size(2)
338 {
339  PTA_float pta = PTA_float::empty_array(2);
340  _pta = pta.v0();
341  _ptr = pta.p();
342  nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0]));
343  memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components());
344 }
345 
346 ////////////////////////////////////////////////////////////////////
347 // Function: Shader::ShaderPtrData Constructor
348 // Access:
349 // Description:
350 ////////////////////////////////////////////////////////////////////
351 INLINE Shader::ShaderPtrData::
352 ShaderPtrData(const LMatrix4f &mat) :
353  _type(SPT_float),
354  _updated(true),
355  _size(16)
356 {
357  PTA_float pta = PTA_float::empty_array(16);
358  _pta = pta.v0();
359  _ptr = pta.p();
360  nassertv(sizeof(mat(0, 0)) * mat.get_num_components() == pta.size() * sizeof(pta[0]));
361  memcpy(_ptr, mat.get_data(), sizeof(mat(0, 0)) * mat.get_num_components());
362 }
363 
364 ////////////////////////////////////////////////////////////////////
365 // Function: Shader::ShaderPtrData Constructor
366 // Access:
367 // Description:
368 ////////////////////////////////////////////////////////////////////
369 INLINE Shader::ShaderPtrData::
370 ShaderPtrData(const LMatrix3f &mat) :
371  _type(SPT_float),
372  _updated(true),
373  _size(9)
374 {
375  PTA_float pta = PTA_float::empty_array(9);
376  _pta = pta.v0();
377  _ptr = pta.p();
378  nassertv(sizeof(mat(0, 0)) * mat.get_num_components() == pta.size() * sizeof(pta[0]));
379  memcpy(_ptr, mat.get_data(), sizeof(mat(0, 0)) * mat.get_num_components());
380 }
381 
382 ////////////////////////////////////////////////////////////////////
383 // Function: Shader::ShaderPtrData Constructor
384 // Access:
385 // Description:
386 ////////////////////////////////////////////////////////////////////
387 INLINE Shader::ShaderPtrData::
388 ShaderPtrData(const PTA_double &ptr):
389  _pta(ptr.v0()),
390  _ptr(ptr.p()),
391  _type(SPT_double),
392  _updated(true),
393  _size(ptr.size())
394 {
395 }
396 
397 ////////////////////////////////////////////////////////////////////
398 // Function: Shader::ShaderPtrData Constructor
399 // Access:
400 // Description:
401 ////////////////////////////////////////////////////////////////////
402 INLINE Shader::ShaderPtrData::
403 ShaderPtrData(const PTA_LMatrix4d &ptr):
404  _pta(ptr.v0()),
405  _ptr(ptr.p()),
406  _type(SPT_double),
407  _updated(true),
408  _size(ptr.size() * 16)
409 {
410 }
411 
412 ////////////////////////////////////////////////////////////////////
413 // Function: Shader::ShaderPtrData Constructor
414 // Access:
415 // Description:
416 ////////////////////////////////////////////////////////////////////
417 INLINE Shader::ShaderPtrData::
418 ShaderPtrData(const PTA_LMatrix3d &ptr):
419  _pta(ptr.v0()),
420  _ptr(ptr.p()),
421  _type(SPT_double),
422  _updated(true),
423  _size(ptr.size() * 9)
424 {
425 }
426 
427 ////////////////////////////////////////////////////////////////////
428 // Function: Shader::ShaderPtrData Constructor
429 // Access:
430 // Description:
431 ////////////////////////////////////////////////////////////////////
432 INLINE Shader::ShaderPtrData::
433 ShaderPtrData(const PTA_LVecBase4d &ptr):
434  _pta(ptr.v0()),
435  _ptr(ptr.p()),
436  _type(SPT_double),
437  _updated(true),
438  _size(ptr.size() * 4)
439 {
440 }
441 
442 ////////////////////////////////////////////////////////////////////
443 // Function: Shader::ShaderPtrData Constructor
444 // Access:
445 // Description:
446 ////////////////////////////////////////////////////////////////////
447 INLINE Shader::ShaderPtrData::
448 ShaderPtrData(const PTA_LVecBase3d &ptr):
449  _pta(ptr.v0()),
450  _ptr(ptr.p()),
451  _type(SPT_double),
452  _updated(true),
453  _size(ptr.size() * 3)
454 {
455 }
456 
457 ////////////////////////////////////////////////////////////////////
458 // Function: Shader::ShaderPtrData Constructor
459 // Access:
460 // Description:
461 ////////////////////////////////////////////////////////////////////
462 INLINE Shader::ShaderPtrData::
463 ShaderPtrData(const PTA_LVecBase2d &ptr):
464  _pta(ptr.v0()),
465  _ptr(ptr.p()),
466  _type(SPT_double),
467  _updated(true),
468  _size(ptr.size() * 2)
469 {
470 }
471 
472 ////////////////////////////////////////////////////////////////////
473 // Function: Shader::ShaderPtrData Constructor
474 // Access:
475 // Description:
476 ////////////////////////////////////////////////////////////////////
477 INLINE Shader::ShaderPtrData::
478 ShaderPtrData(const LVecBase4d &vec) :
479  _type(SPT_double),
480  _updated(true),
481  _size(4)
482 {
483  PTA_double pta = PTA_double::empty_array(4);
484  _pta = pta.v0();
485  _ptr = pta.p();
486  nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0]));
487  memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components());
488 }
489 
490 ////////////////////////////////////////////////////////////////////
491 // Function: Shader::ShaderPtrData Constructor
492 // Access:
493 // Description:
494 ////////////////////////////////////////////////////////////////////
495 INLINE Shader::ShaderPtrData::
496 ShaderPtrData(const LVecBase3d &vec) :
497  _type(SPT_double),
498  _updated(true),
499  _size(3)
500 {
501  PTA_double pta = PTA_double::empty_array(3);
502  _pta = pta.v0();
503  _ptr = pta.p();
504  nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0]));
505  memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components());
506 }
507 
508 ////////////////////////////////////////////////////////////////////
509 // Function: Shader::ShaderPtrData Constructor
510 // Access:
511 // Description:
512 ////////////////////////////////////////////////////////////////////
513 INLINE Shader::ShaderPtrData::
514 ShaderPtrData(const LVecBase2d &vec) :
515  _type(SPT_double),
516  _updated(true),
517  _size(2)
518 {
519  PTA_double pta = PTA_double::empty_array(2);
520  _pta = pta.v0();
521  _ptr = pta.p();
522  nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0]));
523  memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components());
524 }
525 
526 ////////////////////////////////////////////////////////////////////
527 // Function: Shader::ShaderPtrData Constructor
528 // Access:
529 // Description:
530 ////////////////////////////////////////////////////////////////////
531 INLINE Shader::ShaderPtrData::
532 ShaderPtrData(const LMatrix4d &mat) :
533  _type(SPT_double),
534  _updated(true),
535  _size(16)
536 {
537  PTA_double pta = PTA_double::empty_array(16);
538  _pta = pta.v0();
539  _ptr = pta.p();
540  nassertv(sizeof(mat(0, 0)) * mat.get_num_components() == pta.size() * sizeof(pta[0]));
541  memcpy(_ptr, mat.get_data(), sizeof(mat(0, 0)) * mat.get_num_components());
542 }
543 
544 ////////////////////////////////////////////////////////////////////
545 // Function: Shader::ShaderPtrData Constructor
546 // Access:
547 // Description:
548 ////////////////////////////////////////////////////////////////////
549 INLINE Shader::ShaderPtrData::
550 ShaderPtrData(const LMatrix3d &mat) :
551  _type(SPT_double),
552  _updated(true),
553  _size(9)
554 {
555  PTA_double pta = PTA_double::empty_array(9);
556  _pta = pta.v0();
557  _ptr = pta.p();
558  nassertv(sizeof(mat(0, 0)) * mat.get_num_components() == pta.size() * sizeof(pta[0]));
559  memcpy(_ptr, mat.get_data(), sizeof(mat(0, 0)) * mat.get_num_components());
560 }
561 
562 ////////////////////////////////////////////////////////////////////
563 // Function: Shader::ShaderPtrData Constructor
564 // Access:
565 // Description:
566 ////////////////////////////////////////////////////////////////////
567 INLINE Shader::ShaderPtrData::
568 ShaderPtrData(const PTA_int &ptr):
569  _pta(ptr.v0()),
570  _ptr(ptr.p()),
571  _type(SPT_int),
572  _updated(true),
573  _size(ptr.size())
574 {
575 }
576 
577 ////////////////////////////////////////////////////////////////////
578 // Function: Shader::ShaderPtrData Constructor
579 // Access:
580 // Description:
581 ////////////////////////////////////////////////////////////////////
582 INLINE Shader::ShaderPtrData::
583 ShaderPtrData(const PTA_LVecBase4i &ptr):
584  _pta(ptr.v0()),
585  _ptr(ptr.p()),
586  _type(SPT_int),
587  _updated(true),
588  _size(ptr.size() * 4)
589 {
590 }
591 
592 ////////////////////////////////////////////////////////////////////
593 // Function: Shader::ShaderPtrData Constructor
594 // Access:
595 // Description:
596 ////////////////////////////////////////////////////////////////////
597 INLINE Shader::ShaderPtrData::
598 ShaderPtrData(const PTA_LVecBase3i &ptr):
599  _pta(ptr.v0()),
600  _ptr(ptr.p()),
601  _type(SPT_int),
602  _updated(true),
603  _size(ptr.size() * 3)
604 {
605 }
606 
607 ////////////////////////////////////////////////////////////////////
608 // Function: Shader::ShaderPtrData Constructor
609 // Access:
610 // Description:
611 ////////////////////////////////////////////////////////////////////
612 INLINE Shader::ShaderPtrData::
613 ShaderPtrData(const PTA_LVecBase2i &ptr):
614  _pta(ptr.v0()),
615  _ptr(ptr.p()),
616  _type(SPT_int),
617  _updated(true),
618  _size(ptr.size() * 2)
619 {
620 }
621 
622 ////////////////////////////////////////////////////////////////////
623 // Function: Shader::ShaderPtrData Constructor
624 // Access:
625 // Description:
626 ////////////////////////////////////////////////////////////////////
627 INLINE Shader::ShaderPtrData::
628 ShaderPtrData(const LVecBase4i &vec) :
629  _type(SPT_int),
630  _updated(true),
631  _size(4)
632 {
633  PTA_int pta = PTA_int::empty_array(4);
634  _pta = pta.v0();
635  _ptr = pta.p();
636  nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0]));
637  memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components());
638 }
639 
640 ////////////////////////////////////////////////////////////////////
641 // Function: Shader::ShaderPtrData Constructor
642 // Access:
643 // Description:
644 ////////////////////////////////////////////////////////////////////
645 INLINE Shader::ShaderPtrData::
646 ShaderPtrData(const LVecBase3i &vec) :
647  _type(SPT_int),
648  _updated(true),
649  _size(3)
650 {
651  PTA_int pta = PTA_int::empty_array(3);
652  _pta = pta.v0();
653  _ptr = pta.p();
654  nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0]));
655  memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components());
656 }
657 
658 ////////////////////////////////////////////////////////////////////
659 // Function: Shader::ShaderPtrData Constructor
660 // Access:
661 // Description:
662 ////////////////////////////////////////////////////////////////////
663 INLINE Shader::ShaderPtrData::
664 ShaderPtrData(const LVecBase2i &vec) :
665  _type(SPT_int),
666  _updated(true),
667  _size(2)
668 {
669  PTA_int pta = PTA_int::empty_array(2);
670  _pta = pta.v0();
671  _ptr = pta.p();
672  nassertv(sizeof(vec[0]) * vec.get_num_components() == pta.size() * sizeof(pta[0]));
673  memcpy(_ptr, vec.get_data(), sizeof(vec[0]) * vec.get_num_components());
674 }
675 
676 ////////////////////////////////////////////////////////////////////
677 // Function: Shader::ShaderPtrData::write_datagram
678 // Access: Public
679 // Description: Writes the contents of this object to the datagram
680 // for shipping out to a Bam file.
681 ////////////////////////////////////////////////////////////////////
682 INLINE void Shader::ShaderPtrData::
684  dg.add_uint8(_type);
685  dg.add_uint32((PN_uint32)_size);
686 
687  if (_type == SPT_double) {
688  const double *data = (const double *) _ptr;
689  for (size_t i = 0; i < _size; ++i) {
690  dg.add_float64(data[i]);
691  }
692 
693  } else if (_type == SPT_float) {
694  const float *data = (const float *) _ptr;
695  for (size_t i = 0; i < _size; ++i) {
696  dg.add_float32(data[i]);
697  }
698  } else if (_type == SPT_int) {
699  const int *data = (const int *) _ptr;
700  for (size_t i = 0; i < _size; ++i) {
701  dg.add_int32(data[i]);
702  }
703  }
704 }
705 
706 ////////////////////////////////////////////////////////////////////
707 // Function: Shader::ShaderPtrData::write_datagram
708 // Access: Public
709 // Description: Reads the object from a Datagram.
710 ////////////////////////////////////////////////////////////////////
711 INLINE void Shader::ShaderPtrData::
713  _type = (ShaderPtrType) scan.get_uint8();
714  _size = scan.get_uint32();
715 
716  if (_type == SPT_double) {
717  PTA_double pta = PTA_double::empty_array(_size);
718  for (size_t i = 0; i < _size; ++i) {
719  pta[i] = scan.get_float64();
720  }
721  _pta = pta.v0();
722  _ptr = pta.p();
723 
724  } else if (_type == SPT_float) {
725  PTA_float pta = PTA_float::empty_array(_size);
726  for (size_t i = 0; i < _size; ++i) {
727  pta[i] = scan.get_float32();
728  }
729  _pta = pta.v0();
730  _ptr = pta.p();
731 
732  } else if (_type == SPT_int) {
733  PTA_int pta = PTA_int::empty_array(_size);
734  for (size_t i = 0; i < _size; ++i) {
735  pta[i] = scan.get_int32();
736  }
737  _pta = pta.v0();
738  _ptr = pta.p();
739  }
740 }
741 
742 ////////////////////////////////////////////////////////////////////
743 // Function: Shader::ShaderFile::Constructor
744 // Access: Public
745 // Description:
746 ////////////////////////////////////////////////////////////////////
747 INLINE Shader::ShaderFile::
748 ShaderFile(const string &shared) :
749  _separate(false),
750  _shared(shared)
751 {
752 }
753 
754 ////////////////////////////////////////////////////////////////////
755 // Function: Shader::ShaderFile::Constructor
756 // Access: Public
757 // Description:
758 ////////////////////////////////////////////////////////////////////
759 INLINE Shader::ShaderFile::
760 ShaderFile(const string &vertex,
761  const string &fragment,
762  const string &geometry,
763  const string &tess_control,
764  const string &tess_evaluation) :
765  _separate(true),
766  _vertex(vertex),
767  _fragment(fragment),
768  _geometry(geometry),
769  _tess_control(tess_control),
770  _tess_evaluation(tess_evaluation)
771 {
772 }
773 
774 ////////////////////////////////////////////////////////////////////
775 // Function: Shader::ShaderFile::write_datagram
776 // Access: Public
777 // Description: Writes the contents of this object to the datagram
778 // for shipping out to a Bam file.
779 ////////////////////////////////////////////////////////////////////
780 INLINE void Shader::ShaderFile::
782  if (_separate) {
783  dg.add_uint8(6);
784  dg.add_string(_vertex);
785  dg.add_string(_fragment);
786  dg.add_string(_geometry);
787  dg.add_string(_tess_control);
788  dg.add_string(_tess_evaluation);
789  dg.add_string(_compute);
790  } else {
791  dg.add_uint8(0);
792  dg.add_string(_shared);
793  }
794 }
795 
796 ////////////////////////////////////////////////////////////////////
797 // Function: Shader::ShaderFile::write_datagram
798 // Access: Public
799 // Description: Reads the object from a Datagram.
800 ////////////////////////////////////////////////////////////////////
801 INLINE void Shader::ShaderFile::
803  short count = scan.get_uint8();
804  if (count > 0) {
805  if (count-- > 0) _vertex = scan.get_string();
806  if (count-- > 0) _fragment = scan.get_string();
807  if (count-- > 0) _geometry = scan.get_string();
808  if (count-- > 0) _tess_control = scan.get_string();
809  if (count-- > 0) _tess_evaluation = scan.get_string();
810  if (count-- > 0) _compute = scan.get_string();
811  while (count-- > 0) {
812  scan.get_string();
813  }
814  } else {
815  _shared = scan.get_string();
816  }
817 }
818 
819 ////////////////////////////////////////////////////////////////////
820 // Function: Shader::ShaderFile::operator <
821 // Access: Public
822 // Description: Ordering operator
823 ////////////////////////////////////////////////////////////////////
824 INLINE bool Shader::ShaderFile::
825 operator < (const Shader::ShaderFile &other) const {
826  if (_separate != other._separate) {
827  return (!_separate && other._separate);
828  }
829  if (_shared != other._shared) {
830  return (_shared < other._shared);
831  }
832  if (_vertex != other._vertex) {
833  return (_vertex < other._vertex);
834  }
835  if (_fragment != other._fragment) {
836  return (_fragment < other._fragment);
837  }
838  if (_geometry != other._geometry) {
839  return (_geometry < other._geometry);
840  }
841  if (_tess_control != other._tess_control) {
842  return (_tess_control < other._tess_control);
843  }
844  if (_tess_evaluation != other._tess_evaluation) {
845  return (_tess_evaluation < other._tess_evaluation);
846  }
847  if (_compute != other._compute) {
848  return (_compute < other._compute);
849  }
850  return false;
851 }
852 
853 ////////////////////////////////////////////////////////////////////
854 // Function: Shader::get_filename_from_index
855 // Access: Public
856 // Description: Returns the filename of the included shader with
857 // the given source file index (as recorded in the
858 // #line statement in r_preprocess_source). We use
859 // this to associate error messages with included files.
860 ////////////////////////////////////////////////////////////////////
861 INLINE Filename Shader::
862 get_filename_from_index(int index, ShaderType type) const {
863  if (index == 0) {
864  Filename fn = get_filename(type);
865  if (!fn.empty()) {
866  return fn;
867  }
868  } else if (glsl_preprocess && index >= 2048 &&
869  (index - 2048) < (int)_included_files.size()) {
870  return _included_files[(size_t)index - 2048];
871  }
872  // Must be a mistake. Quietly put back the integer.
873  char str[32];
874  sprintf(str, "%d", index);
875  return Filename(str);
876 }
int get_num_components() const
Returns the number of elements in the matrix, 16.
Definition: lmatrix.h:5743
int get_num_components() const
Returns the number of elements in the vector, three.
Definition: lvecBase3.h:3330
void add_uint8(PN_uint8 value)
Adds an unsigned 8-bit integer to the datagram.
Definition: datagram.I:138
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
int get_num_components() const
Returns the number of elements in the matrix, nine.
Definition: lmatrix.h:7471
const float * get_data() const
Returns the address of the first of the four data elements in the vector.
Definition: lvecBase4.h:746
const double * get_data() const
Returns the address of the first of the nine data elements in the matrix.
Definition: lmatrix.h:5733
static void set_shader_utilization(ShaderUtilization utl)
Set this flag to SUT_none, SUT_basic, or SUT_advanced to limit panda&#39;s automatic shader generation fa...
Definition: shader.I:112
int get_num_components() const
Returns the number of elements in the vector, three.
Definition: lvecBase3.h:2013
int get_num_components() const
Returns the number of elements in the vector, four.
Definition: lvecBase4.h:2322
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
void add_string(const string &str)
Adds a variable-length string to the datagram.
Definition: datagram.I:351
static bool have_shader_utilization()
If true, then get_shader_utilization has been set using set_shader_utilization.
Definition: shader.I:143
int get_num_components() const
Returns the number of elements in the vector, four.
Definition: lvecBase4.h:756
void add_float64(PN_float64 value)
Adds a 64-bit floating-point number to the datagram.
Definition: datagram.I:228
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:1257
void write_datagram(Datagram &dg) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: shader.I:683
void add_float32(PN_float32 value)
Adds a 32-bit single-precision floating-point number to the datagram.
Definition: datagram.I:217
const double * get_data() const
Returns the address of the first of the two data elements in the vector.
Definition: lvecBase2.h:1693
const int * get_data() const
Returns the address of the first of the two data elements in the vector.
Definition: lvecBase2.h:2796
bool operator<(const ShaderFile &other) const
Ordering operator.
Definition: shader.I:825
bool get_error_flag() const
Returns true if the shader contains a compile-time error.
Definition: shader.I:100
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:2360
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:1677
static ShaderUtilization get_shader_utilization()
This flag returns SUT_none, SUT_basic, or SUT_advanced and controls the automatic generation of shade...
Definition: shader.I:126
PN_int32 get_int32()
Extracts a signed 32-bit integer.
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
PN_uint32 get_uint32()
Extracts an unsigned 32-bit integer.
int get_num_components() const
Returns the number of elements in the vector, two.
Definition: lvecBase2.h:1703
int get_num_components() const
Returns the number of elements in the vector, two.
Definition: lvecBase2.h:551
int get_num_components() const
Returns the number of elements in the vector, three.
Definition: lvecBase3.h:647
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:3194
ShaderLanguage get_language() const
Returns the shader language in which this shader was written.
Definition: shader.I:154
string get_string()
Extracts a variable-length string.
Filename get_filename_from_index(int index, ShaderType type) const
Returns the filename of the included shader with the given source file index (as recorded in the #lin...
Definition: shader.I:862
PN_float32 get_float32()
Extracts a 32-bit single-precision floating-point number.
int get_num_components() const
Returns the number of elements in the vector, two.
Definition: lvecBase2.h:2806
void read_datagram(DatagramIterator &source)
Reads the object from a Datagram.
Definition: shader.I:802
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:4375
const double * get_data() const
Returns the address of the first of the four data elements in the vector.
Definition: lvecBase4.h:2312
void read_datagram(DatagramIterator &source)
Reads the object from a Datagram.
Definition: shader.I:712
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
void write_datagram(Datagram &dg) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: shader.I:781
int get_num_components() const
Returns the number of elements in the matrix, nine.
Definition: lmatrix.h:3206
const int * get_data() const
Returns the address of the first of the three data elements in the vector.
Definition: lvecBase3.h:3320
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
const int * get_data() const
Returns the address of the first of the four data elements in the vector.
Definition: lvecBase4.h:3829
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:105
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:1471
int get_num_components() const
Returns the number of elements in the matrix, 16.
Definition: lmatrix.h:1478
const float * get_data() const
Returns the address of the first of the nine data elements in the matrix.
Definition: lmatrix.h:1468
const float * get_data() const
Returns the address of the first of the two data elements in the vector.
Definition: lvecBase2.h:541
int get_num_components() const
Returns the number of elements in the vector, four.
Definition: lvecBase4.h:3839
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:2788
PN_float64 get_float64()
Extracts a 64-bit floating-point number.
const string & get_text(const ShaderType &type=ST_none) const
Return the Shader&#39;s text for the given shader type.
Definition: shader.I:62
Filename get_filename(const ShaderType &type=ST_none) const
Return the Shader&#39;s filename for the given shader type.
Definition: shader.I:23
void add_uint32(PN_uint32 value)
Adds an unsigned 32-bit integer to the datagram.
Definition: datagram.I:192
const double * get_data() const
Returns the address of the first of the three data elements in the vector.
Definition: lvecBase3.h:2003
const float * get_data() const
Returns the address of the first of the nine data elements in the matrix.
Definition: lmatrix.h:3196
void add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
Definition: datagram.I:159
A class to retrieve the individual data elements previously stored in a Datagram. ...
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
const float * get_data() const
Returns the address of the first of the three data elements in the vector.
Definition: lvecBase3.h:637
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
const double * get_data() const
Returns the address of the first of the nine data elements in the matrix.
Definition: lmatrix.h:7461