ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/shader.h
Revision: 1.16
Committed: Thu Oct 28 23:24:49 2004 UTC (19 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.15: +77 -45 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef SHADER_H
2 #define SHADER_H
3
4 #include <map>
5 #include <sstream>
6
7 #include "opengl.h"
8 #include "util.h"
9
10 namespace shader {
11
12 using namespace std;
13
14 const int NAMELEN = 32;
15
16 template<class T>
17 struct sl_expr {
18 const T t;
19 sl_expr (const T &t) : t(t) { }
20 void operator ()() const { t (); }
21 template<typename expr>
22 const sl_expr &operator =(const expr &e) const;
23 };
24
25 template<class A, class B>
26 struct sl_concat2
27 {
28 const A a; const B b;
29 sl_concat2 (const A &a, const B &b) : a(a), b(b) { }
30 void operator ()() const { a (); b (); }
31 };
32
33 template<class A, class B, class C>
34 struct sl_concat3
35 {
36 const A a; const B b; const C c;
37 sl_concat3 (const A &a, const B &b, const C &c) : a(a), b(b), c(c) { }
38 void operator ()() const { a (); b (); c (); }
39 };
40
41 template<class A, class B, class C, class D>
42 struct sl_concat4
43 {
44 const A a; const B b; const C c; const D d;
45 sl_concat4 (const A &a, const B &b, const C &c, const D &d) : a(a), b(b), c(c), d(d) { }
46 void operator ()() const { a (); b (); c (); d(); }
47 };
48
49 struct sl_func0
50 {
51 const char *name_par;
52 sl_func0 (const char *name_par) : name_par(name_par) { }
53 void begin () const;
54 void comma () const;
55 void end () const;
56 void operator ()() const
57 {
58 begin ();
59 end ();
60 }
61 };
62
63 template<class A>
64 struct sl_func1 : sl_func0
65 {
66 const A a;
67 sl_func1 (const char *name, const A &a) : sl_func0(name), a(a) { }
68 void operator ()() const { begin (); a (); end (); }
69 };
70
71 template<class A, class B>
72 struct sl_func2 : sl_func0
73 {
74 const A a; const B b;
75 sl_func2 (const char *name, const A &a, const B &b) : sl_func0(name), a(a), b(b) { }
76 void operator ()() const { begin (); a (); comma (); b (); end (); }
77 };
78
79 template<class A, class B, class C>
80 struct sl_func3 : sl_func0
81 {
82 const A a; const B b; const C c;
83 sl_func3 (const char *name, const A &a, const B &b, const C &c) : sl_func0(name), a(a), b(b), c(c) { }
84 void operator ()() const { begin (); a (); comma (); b (); comma (); c (); end (); }
85 };
86
87 template<class A, class B, class C, class D>
88 struct sl_func4 : sl_func0
89 {
90 const A a; const B b; const C c; const D d;
91 sl_func4 (const char *name, const A &a, const B &b, const C &c, const D &d) : sl_func0(name), a(a), b(b), c(c), d(d) { }
92 void operator ()() const { begin (); a (); comma (); b (); comma (); c (); comma (); d(); end (); }
93 };
94
95 class refcounted
96 {
97 template<class type> friend class ref;
98 mutable int refcnt;
99 void refcnt_inc () const { refcnt++; }
100 void refcnt_dec () const;
101 public:
102 refcounted () : refcnt(0) { }
103 virtual ~refcounted ();
104 };
105
106 template<class type>
107 struct ref
108 {
109 type *p;
110
111 ref ()
112 {
113 p = new type;
114 p->refcnt_inc ();
115 }
116
117 ref (type &d)
118 {
119 d.refcnt_inc ();
120 p = &d;
121 }
122
123 ref (const ref &r)
124 {
125 r.p->refcnt_inc ();
126 p = r.p;
127 }
128
129 template<class type2>
130 ref (const ref<type2> &r)
131 {
132 r.p->refcnt_inc ();
133 p = r.p;
134 }
135
136 ~ref ()
137 {
138 p->refcnt_dec ();
139 }
140
141 ref &operator =(type &d)
142 {
143 d.refcnt_inc ();
144 p->refcnt_dec ();
145 p = &d;
146 return *this;
147 }
148
149 type *operator ->() const { return p; }
150
151 operator type &() const { return *p; }
152
153 template<class type2>
154 bool operator ==(const ref<type2> b) const
155 {
156 return (void *)p == (void *)b.p;
157 }
158 };
159
160 // ref with auto-construct
161 template<class type>
162 struct auto_ref0 : ref<type>
163 {
164 auto_ref0 () : ref<type> (*new type ()) { }
165 };
166
167 template<class type, typename arg1>
168 struct auto_ref1 : ref<type>
169 {
170 auto_ref1 (arg1 a) : ref<type> (*new type (a)) { }
171 };
172
173 template<class type>
174 struct auto_lvalue_ref0 : ref<type>
175 {
176 auto_lvalue_ref0 () : ref<type> (*new type ()) { }
177 template<typename expr>
178 const auto_lvalue_ref0 &operator =(const expr &e) const;
179 };
180
181 template<class type, typename arg1>
182 struct auto_lvalue_ref1 : ref<type>
183 {
184 auto_lvalue_ref1 (arg1 a) : ref<type> (*new type (a)) { }
185 template<class expr>
186 const auto_lvalue_ref1 &operator =(const expr &e) const;
187 };
188
189 extern const char str_float [];
190 extern const char str_vec2 [];
191 extern const char str_vec3 [];
192 extern const char str_vec4 [];
193 extern const char str_mat2 [];
194 extern const char str_mat3 [];
195 extern const char str_mat4 [];
196
197 extern const char str_sampler_1d [];
198 extern const char str_sampler_1d_shadow [];
199 extern const char str_sampler_2d [];
200 extern const char str_sampler_2d_shadow [];
201 extern const char str_sampler_2d_rect [];
202 extern const char str_sampler_2d_rect_shadow [];
203 extern const char str_sampler_3d [];
204 extern const char str_sampler_3d_rect [];
205 extern const char str_sampler_cube [];
206
207 typedef ref<struct var_i> var;
208 typedef ref<struct uniform_i> uniform;
209
210 struct shader_builder
211 {
212 vector<uniform> refs; // uniform parameters
213 vector<var> temps; // temporary variables
214 vector<var> streams; // varying inputs & outputs
215
216 ostringstream source;
217
218 template<typename type>
219 shader_builder &operator <<(const type &t)
220 {
221 source << t;
222 return *this;
223 }
224 };
225
226 struct fragment_i : refcounted
227 {
228 virtual void build (shader_builder &b) = 0;
229 };
230
231 typedef ref<fragment_i> fragment;
232
233 struct lvalue_i : fragment_i
234 {
235 };
236
237 // a simple predeclared variable with unspecified type
238 struct gluvar_i : lvalue_i
239 {
240 const char *name;
241 void build (shader_builder &b);
242 gluvar_i (const char *name) : name (name) { }
243 };
244
245 typedef auto_lvalue_ref1<gluvar_i, const char *> gluvar;
246
247 struct var_i : lvalue_i
248 {
249 static unsigned int next_id;
250
251 char name[NAMELEN];
252 const char *typestr;
253
254 void build (shader_builder &b);
255 virtual void build_decl (ostringstream &b);
256
257 var_i (const char *typestr);
258 ~var_i ();
259 };
260
261 struct uniform_i : var_i
262 {
263 void build (shader_builder &b);
264 void build_decl (ostringstream &b);
265
266 GLint location ();
267
268 uniform_i (const char *strtype);
269 };
270
271 template<int dimension, typename gltype, const char *strtype>
272 struct uniform2_i : uniform_i
273 {
274 gltype data[dimension];
275
276 uniform2_i () : uniform_i (strtype) { }
277 };
278
279 template<int dimension, const char *strtype>
280 struct uniform_f_i : uniform2_i<dimension, GLfloat, strtype>
281 {
282 };
283
284 struct uniform_1f_i : uniform_f_i<1, str_float> {
285 void set (GLfloat v)
286 {
287 data[0] = v;
288 glUniform1fvARB (location(), 1, data);
289 }
290 };
291
292 struct uniform_2f_i : uniform_f_i<2, str_vec2> {
293 void set (GLfloat x, GLfloat y)
294 {
295 data[0] = x;
296 data[1] = y;
297 glUniform2fvARB (location(), 2, data);
298 }
299
300 void set (const vec2 &v) { set (v.x, v.y); }
301 };
302
303 struct uniform_3f_i : uniform_f_i<3, str_vec3> {
304 void set (GLfloat x, GLfloat y, GLfloat z)
305 {
306 data[0] = x;
307 data[1] = y;
308 data[2] = z;
309 glUniform3fvARB (location(), 3, data);
310 }
311
312 void set (const vec3 &v) { set (v.x, v.y, v.z); }
313 };
314
315 struct uniform_4f_i : uniform_f_i<4, str_vec4> {
316 void set (GLfloat x, GLfloat y, GLfloat z, GLfloat w)
317 {
318 data[0] = x;
319 data[1] = y;
320 data[2] = z;
321 data[3] = w;
322
323 glUniform4fvARB (location(), 4, data);
324 }
325
326 void set (const vec4 &v) { set (v.x, v.y, v.z, v.w); }
327 };
328
329 struct uniform_matrix_2f_i : uniform_f_i< 4, str_mat2>
330 {
331 void set (const GLfloat d[4])
332 {
333 memcpy (data, d, 4 * sizeof (GLfloat));
334 glUniformMatrix2fvARB (location (), 4, 0, data);
335 }
336 };
337
338 struct uniform_matrix_3f_i : uniform_f_i< 9, str_mat3>
339 {
340 void set (const GLfloat d[9])
341 {
342 memcpy (data, d, 9 * sizeof (GLfloat));
343 glUniformMatrix3fvARB (location (), 9, 0, data);
344 }
345 };
346
347 struct uniform_matrix_4f_i : uniform_f_i<16, str_mat4>
348 {
349 void set (const gl::matrix &m)
350 {
351 memcpy (data, m.data, 16 * sizeof (GLfloat));
352 glUniformMatrix4fvARB (location (), 16, 0, data);
353 }
354 };
355
356 template<class var_i>
357 struct var_ref : ref<var_i>
358 {
359 var_ref (const char *glname = 0)
360 : ref<var_i> (*new var_i)
361 {
362 if (glname)
363 strcpy ((*this)->name, glname);
364 }
365 };
366
367 typedef var_ref<uniform_1f_i> uniform_1f;
368 typedef var_ref<uniform_2f_i> uniform_2f;
369 typedef var_ref<uniform_3f_i> uniform_3f;
370 typedef var_ref<uniform_4f_i> uniform_4f;
371 typedef var_ref<uniform_matrix_2f_i> uniform_matrix_2f;
372 typedef var_ref<uniform_matrix_3f_i> uniform_matrix_3f;
373 typedef var_ref<uniform_matrix_4f_i> uniform_matrix_4f;
374
375 struct stream_i : var_i
376 {
377 void build (shader_builder &b);
378 void build_decl (ostringstream &b);
379 stream_i (const char *strtype);
380 };
381
382 template<int dimension, GLenum gltype, const char *strtype>
383 struct varying_i : stream_i
384 {
385 varying_i () : stream_i (strtype) { }
386
387 void set (GLsizei stride, GLvoid *ptr)
388 {
389 //cgGLSetParameterPointer (param, dimension, gltype, stride, ptr);
390 }
391 };
392
393 template<int dimension, const char *strtype>
394 struct varying_f_i : varying_i<dimension, GL_FLOAT, strtype>
395 {
396 void set (const gl::vertex_buffer_object &vb, GLint offset)
397 {
398 varying_i<dimension, GL_FLOAT, strtype>::set (gl::format_stride (vb.format), (GLvoid *)(long)offset);
399 }
400 };
401
402 struct varying_1f_i : varying_f_i<1, str_float>
403 {
404 };
405
406 struct varying_2f_i : varying_f_i<2, str_vec2>
407 {
408 void set_t (const gl::vertex_buffer_object &vb)
409 {
410 set (vb, gl::format_offset_t (vb.format));
411 }
412 };
413
414 struct varying_3f_i : varying_f_i<3, str_vec3>
415 {
416 void set_p (const gl::vertex_buffer_object &vb)
417 {
418 set (vb, gl::format_offset_p (vb.format));
419 }
420
421 void set_n (const gl::vertex_buffer_object &vb)
422 {
423 set (vb, gl::format_offset_n (vb.format));
424 }
425 };
426
427 struct varying_4f_i : varying_f_i<4, str_vec4>
428 {
429 };
430
431 typedef var_ref<varying_1f_i> varying_1f;
432 typedef var_ref<varying_2f_i> varying_2f;
433 typedef var_ref<varying_3f_i> varying_3f;
434 typedef var_ref<varying_4f_i> varying_4f;
435
436 struct temporary_i : var_i
437 {
438 void build (shader_builder &b);
439
440 temporary_i (const char *strtype);
441 };
442
443 template<const char *strtype>
444 struct temp_ref : ref<temporary_i>
445 {
446 temp_ref ()
447 : ref<temporary_i> (*new temporary_i (strtype))
448 {
449 }
450
451 #if 0
452 template<typename expr>
453 temp_ref (const expr &e)
454 : ref<temporary_i> (*new temporary_i (strtype))
455 {
456 (*this) = e;
457 }
458 #endif
459
460 template<typename expr>
461 const temp_ref &operator =(const expr &e) const;
462 };
463
464 typedef temp_ref<str_float> temp_1f;
465 typedef temp_ref<str_vec2> temp_2f;
466 typedef temp_ref<str_vec3> temp_3f;
467 typedef temp_ref<str_vec4> temp_4f;
468 typedef temp_ref<str_mat2> temp_matrix_2f;
469 typedef temp_ref<str_mat3> temp_matrix_3f;
470 typedef temp_ref<str_mat4> temp_matrix_4f;
471
472 template<GLenum gltype, const char *strtype>
473 struct sampler_i : uniform_i
474 {
475 GLuint unit;
476
477 void update ()
478 {
479 if (dirty)
480 {
481 //cgGLSetTextureParameter (param, texture);
482 dirty = false;
483 }
484 }
485
486 void begin ()
487 {
488 //cgGLEnableTextureParameter (unit);
489 }
490
491 sampler_i (GLuint textureunit) : uniform_i (strtype), unit (textureunit) { }
492 };
493
494 struct sampler_1d_i : sampler_i<GL_SAMPLER_1D_ARB, str_sampler_1d>
495 {
496 sampler_1d_i (GLuint textureunit) : sampler_i<GL_SAMPLER_1D_ARB, str_sampler_1d> (textureunit) { }
497 };
498
499 struct sampler_1d_shadow_i : sampler_i<GL_SAMPLER_1D_SHADOW_ARB, str_sampler_1d_shadow>
500 {
501 sampler_1d_shadow_i (GLuint textureunit) : sampler_i<GL_SAMPLER_1D_SHADOW_ARB, str_sampler_1d_shadow> (textureunit) { }
502 };
503
504 struct sampler_2d_i : sampler_i<GL_SAMPLER_2D_ARB, str_sampler_2d>
505 {
506 sampler_2d_i (GLuint textureunit) : sampler_i<GL_SAMPLER_2D_ARB, str_sampler_2d> (textureunit) { }
507 };
508
509 struct sampler_2d_shadow_i : sampler_i<GL_SAMPLER_2D_SHADOW_ARB, str_sampler_2d_shadow>
510 {
511 sampler_2d_shadow_i (GLuint textureunit) : sampler_i<GL_SAMPLER_2D_SHADOW_ARB, str_sampler_2d_shadow> (textureunit) { }
512 };
513
514 struct sampler_2d_rect_i : sampler_i<GL_SAMPLER_2D_RECT_ARB, str_sampler_2d_rect>
515 {
516 sampler_2d_rect_i (GLuint textureunit) : sampler_i<GL_SAMPLER_2D_RECT_ARB, str_sampler_2d_rect> (textureunit) { }
517 };
518
519 struct sampler_2d_rect_shadow_i : sampler_i<GL_SAMPLER_2D_RECT_SHADOW_ARB, str_sampler_2d_rect_shadow>
520 {
521 sampler_2d_rect_shadow_i (GLuint textureunit) : sampler_i<GL_SAMPLER_2D_RECT_SHADOW_ARB, str_sampler_2d_rect_shadow> (textureunit) { }
522 };
523
524 struct sampler_3d_i : sampler_i<GL_SAMPLER_3D_ARB, str_sampler_3d>
525 {
526 sampler_3d_i (GLuint textureunit) : sampler_i<GL_SAMPLER_3D_ARB, str_sampler_3d> (textureunit) { }
527 };
528
529 struct sampler_3d_rect_i : sampler_i<GL_SAMPLER_3D_ARB, str_sampler_3d_rect>
530 {
531 sampler_3d_rect_i (GLuint textureunit) : sampler_i<GL_SAMPLER_3D_ARB, str_sampler_3d_rect> (textureunit) { }
532 };
533
534 struct sampler_cube_i : sampler_i<GL_SAMPLER_CUBE_ARB, str_sampler_cube>
535 {
536 sampler_cube_i (GLuint textureunit) : sampler_i<GL_SAMPLER_CUBE_ARB, str_sampler_cube> (textureunit) { }
537 };
538
539 typedef auto_ref1<sampler_1d_i, GLuint> sampler_1d;
540 typedef auto_ref1<sampler_1d_shadow_i, GLuint> sampler_1d_shadow;
541 typedef auto_ref1<sampler_2d_i, GLuint> sampler_2d;
542 typedef auto_ref1<sampler_2d_shadow_i, GLuint> sampler_2d_shadow;
543 typedef auto_ref1<sampler_2d_rect_i, GLuint> sampler_2d_rect;
544 typedef auto_ref1<sampler_2d_rect_shadow_i, GLuint> sampler_2d_rect_shadow;
545 typedef auto_ref1<sampler_3d_i, GLuint> sampler_3d;
546 typedef auto_ref1<sampler_3d_rect_i, GLuint> sampler_3d_rect;
547 typedef auto_ref1<sampler_cube_i, GLuint> sampler_cube;
548
549 struct fragment_const_string_i : fragment_i
550 {
551 const char *str;
552
553 void build (shader_builder &b);
554
555 fragment_const_string_i (const char *str) : str(str) { }
556 };
557
558 typedef auto_ref1<fragment_const_string_i, const char *> fragment_const_string;
559
560 struct fragment_string_i : fragment_i
561 {
562 char *str;
563
564 void build (shader_builder &b);
565
566 fragment_string_i (const char *str) : str (strdup (str)) { }
567 ~fragment_string_i ();
568 };
569
570 struct fragment_vector_i : fragment_i, vector<fragment>
571 {
572 void build (shader_builder &b);
573
574 template<class fragment_i>
575 void append (const ref<fragment_i> &f)
576 {
577 push_back (f);
578 }
579
580 template<class expr>
581 void append (const sl_expr<expr> &e)
582 {
583 e ();
584 }
585
586 void append_const (const char *s)
587 {
588 push_back (*new fragment_const_string_i (s));
589 }
590
591 void append_string (const char *s)
592 {
593 push_back (*new fragment_string_i (s));
594 }
595 };
596
597 typedef ref<fragment_vector_i> fragment_vector;
598
599 struct shader_object_i : fragment_vector_i
600 {
601 GLenum type;
602 GLuint id; // GLhandleARB, but 2.0 will use uint
603
604 string source ();
605 void compile ();
606 void start ();
607 void stop ();
608
609 shader_object_i (GLenum type);
610 ~shader_object_i ();
611 };
612
613 extern shader_object_i *cur; // record actions to this shader
614
615 template<GLenum type>
616 struct shader_object : ref<shader_object_i>
617 {
618 shader_object ()
619 : ref<shader_object_i> (*new shader_object_i (type))
620 {
621 }
622 };
623
624 typedef shader_object<GL_VERTEX_SHADER_ARB> vertex_shader;
625 typedef shader_object<GL_FRAGMENT_SHADER_ARB> fragment_shader;
626
627 struct program_object
628 {
629 static struct program_object *cur; // currently bound program
630
631 GLuint id;
632
633 vertex_shader vsh;
634 fragment_shader fsh;
635
636 map<uniform_i *,GLint> uloc; // uniform location
637
638 program_object ();
639 ~program_object ();
640
641 void link ();
642
643 void begin ()
644 {
645 glUseProgramObjectARB (id);
646 cur = this;
647 }
648
649 void end ()
650 {
651 glUseProgramObjectARB (0);
652 cur = 0;
653 }
654 };
655
656 template<typename T>
657 struct sl_append
658 {
659 T t;
660
661 sl_append (const T &t) : t(t) { }
662
663 void operator ()() const
664 {
665 cur->push_back (t);
666 }
667 };
668
669 template<int length>
670 struct sl_string
671 {
672 char str[length];
673
674 void operator ()() const
675 {
676 cur->push_back (*new fragment_string_i (str));
677 }
678 };
679
680 struct sl_float
681 {
682 const GLfloat c;
683
684 sl_float (GLfloat c) : c(c) { }
685
686 void operator ()() const;
687 };
688
689 template<class A, class B>
690 inline sl_expr< sl_concat2<A, B> >
691 concat (const A &a, const B &b)
692 {
693 typedef sl_concat2<A, B> expr;
694 return sl_expr<expr> (expr (a, b));
695 }
696
697 template<class A, class B, class C>
698 inline sl_expr< sl_concat3<A, B, C> >
699 concat (const A &a, const B &b, const C &c)
700 {
701 typedef sl_concat3<A, B, C> expr;
702 return sl_expr<expr> (expr (a, b, c));
703 }
704
705 template<class A, class B, class C, class D>
706 inline sl_expr< sl_concat4<A, B, C, D> >
707 concat (const A &a, const B &b, const C &c, const D &d)
708 {
709 typedef sl_concat4<A, B, C, D> expr;
710 return sl_expr<expr> (expr (a, b, c, d));
711 }
712
713 template<typename expr>
714 struct sl_convert
715 {
716 typedef sl_expr<expr> T;
717 static inline const T &convert (const T &e)
718 {
719 return e;
720 }
721 };
722
723 template<>
724 struct sl_convert<GLfloat>
725 {
726 typedef sl_expr<sl_float> T;
727 static inline const T convert (GLfloat f)
728 {
729 return sl_float (f);
730 }
731 };
732
733 template<>
734 struct sl_convert<GLdouble>
735 {
736 typedef sl_expr<sl_float> T;
737 static inline const T convert (GLdouble d)
738 {
739 return sl_float (d);
740 }
741 };
742
743 template<>
744 struct sl_convert<GLint>
745 {
746 typedef sl_expr<sl_float> T;
747 static inline const T convert (GLint i)
748 {
749 return sl_float (i);
750 }
751 };
752
753 template<>
754 struct sl_convert<vec2>
755 {
756 typedef sl_expr< sl_string<60> > T;
757 static const T convert (const vec2 &v);
758 };
759
760 template<>
761 struct sl_convert<vec3>
762 {
763 typedef sl_expr< sl_string<80> > T;
764 static const T convert (const vec3 &v);
765 };
766
767 template<>
768 struct sl_convert<vec4>
769 {
770 typedef sl_expr< sl_string<100> > T;
771 static const T convert (const vec4 &v);
772 };
773
774 template<>
775 template<class V>
776 struct sl_convert< var_ref<V> >
777 {
778 typedef sl_expr< sl_append< var_ref<V> > > T;
779 static inline const T convert (const var_ref<V> &v)
780 {
781 return sl_append< var_ref<V> > (v);
782 }
783 };
784
785 template<>
786 struct sl_convert<gluvar>
787 {
788 typedef sl_expr< sl_append<gluvar> > T;
789 static inline const T convert (const gluvar &v)
790 {
791 return sl_append<gluvar> (v);
792 }
793 };
794
795 template<>
796 template<const char *strtype>
797 struct sl_convert< temp_ref<strtype> >
798 {
799 typedef sl_expr< sl_append< temp_ref<strtype> > > T;
800 static inline const T convert (const temp_ref<strtype> &v)
801 {
802 return sl_expr< sl_append< temp_ref<strtype> > >(
803 sl_append< temp_ref<strtype> > (v)
804 );
805 }
806 };
807
808 extern const fragment_const_string str_2sp;
809 extern const fragment_const_string str_equal;
810 extern const fragment_const_string str_comma;
811 extern const fragment_const_string str_endl;
812
813 template<class fragment, typename expr>
814 inline void sl_assign (const fragment &f, const expr &e)
815 {
816 cur->append (str_2sp);
817 cur->append (f);
818 cur->append (str_equal);
819 sl_convert<expr>::convert (e) ();
820 cur->append (str_endl);
821 }
822
823 template<class type>
824 template<typename expr>
825 inline const auto_lvalue_ref0<type> &auto_lvalue_ref0<type>::operator =(const expr &e) const
826 {
827 sl_assign (*this, e);
828 return *this;
829 }
830
831 template<class type, typename arg1>
832 template<typename expr>
833 inline const auto_lvalue_ref1<type,arg1> &auto_lvalue_ref1<type,arg1>::operator =(const expr &e) const
834 {
835 sl_assign (*this, e);
836 return *this;
837 }
838
839 template<class T>
840 template<typename expr>
841 inline const sl_expr<T> &sl_expr<T>::operator =(const expr &e) const
842 {
843 sl_assign (*this, e);
844 return *this;
845 }
846
847 template<const char *strtype>
848 template<typename expr>
849 inline const temp_ref<strtype> &temp_ref<strtype>::operator =(const expr &e) const
850 {
851 sl_assign (*this, e);
852 return *this;
853 }
854
855 struct sl_append_const_string
856 {
857 fragment_const_string str;
858 sl_append_const_string (const char *s)
859 : str (s)
860 { }
861
862 void operator ()() const
863 {
864 cur->push_back (str);
865 }
866 };
867
868 extern const sl_append_const_string str_lpar;
869 extern const sl_append_const_string str_rpar;
870
871 template<class A, class B, class C>
872 struct sl_binop
873 {
874 const A a; const B b; const C c;
875 sl_binop (const A &a, const B &b, const C &c) : a(a), b(b), c(c) { }
876 void operator ()() const { str_lpar (); a (); b (); c (); str_rpar (); }
877 };
878
879 # define SHADER_BINOP(op, str) \
880 extern const sl_append_const_string str_ ## str; \
881 template<typename A, typename B> \
882 inline const sl_expr< sl_binop< typename sl_convert<A>::T, \
883 sl_append_const_string, \
884 typename sl_convert<B>::T > > \
885 operator op(const A &a, const B &b) \
886 { \
887 return sl_binop< typename sl_convert<A>::T, sl_append_const_string, typename sl_convert<B>::T > \
888 (sl_convert<A>::convert (a), str_ ## str, sl_convert<B>::convert (b)); \
889 }
890
891 SHADER_BINOP (+, plus);
892 SHADER_BINOP (-, minus);
893 SHADER_BINOP (*, mul);
894 SHADER_BINOP (/, div);
895 SHADER_BINOP (%, mod);
896
897 # undef SHADER_BINOP
898
899 void swizzle_mask (sl_string<7> &s, int mask);
900
901 template<typename T>
902 inline const sl_expr< sl_concat3< sl_append_const_string,
903 typename sl_convert<T>::T,
904 sl_string<7>
905 > >
906 swizzle (const T &t, int a, int b = 0, int c = 0, int d = 0)
907 {
908 sl_string<7> s;
909 swizzle_mask (s, ((d * 5 + c) * 5 + b) * 5 + a);
910 return concat (str_lpar, sl_convert<T>::convert (t), s);
911 }
912
913 # define SHADER_SWIZZLE_OP(abcd,type) \
914 template<typename T> \
915 inline const sl_expr< sl_concat3< sl_append_const_string, \
916 typename sl_convert<T>::T, \
917 sl_string<7> \
918 > > \
919 type (const T &t) \
920 { \
921 return swizzle (t, (abcd / 1000) % 5, (abcd / 100) % 5, (abcd / 10) % 5, (abcd / 1) % 5); \
922 }
923
924 // brute force is lovely, ain't it?
925 SHADER_SWIZZLE_OP (1 , x ) SHADER_SWIZZLE_OP (11 , xx ) SHADER_SWIZZLE_OP (111 , xxx ) SHADER_SWIZZLE_OP (1111, xxxx)
926 SHADER_SWIZZLE_OP (1112, xxxy) SHADER_SWIZZLE_OP (1113, xxxz) SHADER_SWIZZLE_OP (1114, xxxw) SHADER_SWIZZLE_OP (112 , xxy )
927 SHADER_SWIZZLE_OP (1121, xxyx) SHADER_SWIZZLE_OP (1122, xxyy) SHADER_SWIZZLE_OP (1123, xxyz) SHADER_SWIZZLE_OP (1124, xxyw)
928 SHADER_SWIZZLE_OP (113 , xxz ) SHADER_SWIZZLE_OP (1131, xxzx) SHADER_SWIZZLE_OP (1132, xxzy) SHADER_SWIZZLE_OP (1133, xxzz)
929 SHADER_SWIZZLE_OP (1134, xxzw) SHADER_SWIZZLE_OP (114 , xxw ) SHADER_SWIZZLE_OP (1141, xxwx) SHADER_SWIZZLE_OP (1142, xxwy)
930 SHADER_SWIZZLE_OP (1143, xxwz) SHADER_SWIZZLE_OP (1144, xxww) SHADER_SWIZZLE_OP (12 , xy ) SHADER_SWIZZLE_OP (121 , xyx )
931 SHADER_SWIZZLE_OP (1211, xyxx) SHADER_SWIZZLE_OP (1212, xyxy) SHADER_SWIZZLE_OP (1213, xyxz) SHADER_SWIZZLE_OP (1214, xyxw)
932 SHADER_SWIZZLE_OP (122 , xyy ) SHADER_SWIZZLE_OP (1221, xyyx) SHADER_SWIZZLE_OP (1222, xyyy) SHADER_SWIZZLE_OP (1223, xyyz)
933 SHADER_SWIZZLE_OP (1224, xyyw) SHADER_SWIZZLE_OP (123 , xyz ) SHADER_SWIZZLE_OP (1231, xyzx) SHADER_SWIZZLE_OP (1232, xyzy)
934 SHADER_SWIZZLE_OP (1233, xyzz) SHADER_SWIZZLE_OP (1234, xyzw) SHADER_SWIZZLE_OP (124 , xyw ) SHADER_SWIZZLE_OP (1241, xywx)
935 SHADER_SWIZZLE_OP (1242, xywy) SHADER_SWIZZLE_OP (1243, xywz) SHADER_SWIZZLE_OP (1244, xyww) SHADER_SWIZZLE_OP (13 , xz )
936 SHADER_SWIZZLE_OP (131 , xzx ) SHADER_SWIZZLE_OP (1311, xzxx) SHADER_SWIZZLE_OP (1312, xzxy) SHADER_SWIZZLE_OP (1313, xzxz)
937 SHADER_SWIZZLE_OP (1314, xzxw) SHADER_SWIZZLE_OP (132 , xzy ) SHADER_SWIZZLE_OP (1321, xzyx) SHADER_SWIZZLE_OP (1322, xzyy)
938 SHADER_SWIZZLE_OP (1323, xzyz) SHADER_SWIZZLE_OP (1324, xzyw) SHADER_SWIZZLE_OP (133 , xzz ) SHADER_SWIZZLE_OP (1331, xzzx)
939 SHADER_SWIZZLE_OP (1332, xzzy) SHADER_SWIZZLE_OP (1333, xzzz) SHADER_SWIZZLE_OP (1334, xzzw) SHADER_SWIZZLE_OP (134 , xzw )
940 SHADER_SWIZZLE_OP (1341, xzwx) SHADER_SWIZZLE_OP (1342, xzwy) SHADER_SWIZZLE_OP (1343, xzwz) SHADER_SWIZZLE_OP (1344, xzww)
941 SHADER_SWIZZLE_OP (14 , xw ) SHADER_SWIZZLE_OP (141 , xwx ) SHADER_SWIZZLE_OP (1411, xwxx) SHADER_SWIZZLE_OP (1412, xwxy)
942 SHADER_SWIZZLE_OP (1413, xwxz) SHADER_SWIZZLE_OP (1414, xwxw) SHADER_SWIZZLE_OP (142 , xwy ) SHADER_SWIZZLE_OP (1421, xwyx)
943 SHADER_SWIZZLE_OP (1422, xwyy) SHADER_SWIZZLE_OP (1423, xwyz) SHADER_SWIZZLE_OP (1424, xwyw) SHADER_SWIZZLE_OP (143 , xwz )
944 SHADER_SWIZZLE_OP (1431, xwzx) SHADER_SWIZZLE_OP (1432, xwzy) SHADER_SWIZZLE_OP (1433, xwzz) SHADER_SWIZZLE_OP (1434, xwzw)
945 SHADER_SWIZZLE_OP (144 , xww ) SHADER_SWIZZLE_OP (1441, xwwx) SHADER_SWIZZLE_OP (1442, xwwy) SHADER_SWIZZLE_OP (1443, xwwz)
946 SHADER_SWIZZLE_OP (1444, xwww) SHADER_SWIZZLE_OP (2 , y ) SHADER_SWIZZLE_OP (21 , yx ) SHADER_SWIZZLE_OP (211 , yxx )
947 SHADER_SWIZZLE_OP (2111, yxxx) SHADER_SWIZZLE_OP (2112, yxxy) SHADER_SWIZZLE_OP (2113, yxxz) SHADER_SWIZZLE_OP (2114, yxxw)
948 SHADER_SWIZZLE_OP (212 , yxy ) SHADER_SWIZZLE_OP (2121, yxyx) SHADER_SWIZZLE_OP (2122, yxyy) SHADER_SWIZZLE_OP (2123, yxyz)
949 SHADER_SWIZZLE_OP (2124, yxyw) SHADER_SWIZZLE_OP (213 , yxz ) SHADER_SWIZZLE_OP (2131, yxzx) SHADER_SWIZZLE_OP (2132, yxzy)
950 SHADER_SWIZZLE_OP (2133, yxzz) SHADER_SWIZZLE_OP (2134, yxzw) SHADER_SWIZZLE_OP (214 , yxw ) SHADER_SWIZZLE_OP (2141, yxwx)
951 SHADER_SWIZZLE_OP (2142, yxwy) SHADER_SWIZZLE_OP (2143, yxwz) SHADER_SWIZZLE_OP (2144, yxww) SHADER_SWIZZLE_OP (22 , yy )
952 SHADER_SWIZZLE_OP (221 , yyx ) SHADER_SWIZZLE_OP (2211, yyxx) SHADER_SWIZZLE_OP (2212, yyxy) SHADER_SWIZZLE_OP (2213, yyxz)
953 SHADER_SWIZZLE_OP (2214, yyxw) SHADER_SWIZZLE_OP (222 , yyy ) SHADER_SWIZZLE_OP (2221, yyyx) SHADER_SWIZZLE_OP (2222, yyyy)
954 SHADER_SWIZZLE_OP (2223, yyyz) SHADER_SWIZZLE_OP (2224, yyyw) SHADER_SWIZZLE_OP (223 , yyz ) SHADER_SWIZZLE_OP (2231, yyzx)
955 SHADER_SWIZZLE_OP (2232, yyzy) SHADER_SWIZZLE_OP (2233, yyzz) SHADER_SWIZZLE_OP (2234, yyzw) SHADER_SWIZZLE_OP (224 , yyw )
956 SHADER_SWIZZLE_OP (2241, yywx) SHADER_SWIZZLE_OP (2242, yywy) SHADER_SWIZZLE_OP (2243, yywz) SHADER_SWIZZLE_OP (2244, yyww)
957 SHADER_SWIZZLE_OP (23 , yz ) SHADER_SWIZZLE_OP (231 , yzx ) SHADER_SWIZZLE_OP (2311, yzxx) SHADER_SWIZZLE_OP (2312, yzxy)
958 SHADER_SWIZZLE_OP (2313, yzxz) SHADER_SWIZZLE_OP (2314, yzxw) SHADER_SWIZZLE_OP (232 , yzy ) SHADER_SWIZZLE_OP (2321, yzyx)
959 SHADER_SWIZZLE_OP (2322, yzyy) SHADER_SWIZZLE_OP (2323, yzyz) SHADER_SWIZZLE_OP (2324, yzyw) SHADER_SWIZZLE_OP (233 , yzz )
960 SHADER_SWIZZLE_OP (2331, yzzx) SHADER_SWIZZLE_OP (2332, yzzy) SHADER_SWIZZLE_OP (2333, yzzz) SHADER_SWIZZLE_OP (2334, yzzw)
961 SHADER_SWIZZLE_OP (234 , yzw ) SHADER_SWIZZLE_OP (2341, yzwx) SHADER_SWIZZLE_OP (2342, yzwy) SHADER_SWIZZLE_OP (2343, yzwz)
962 SHADER_SWIZZLE_OP (2344, yzww) SHADER_SWIZZLE_OP (24 , yw ) SHADER_SWIZZLE_OP (241 , ywx ) SHADER_SWIZZLE_OP (2411, ywxx)
963 SHADER_SWIZZLE_OP (2412, ywxy) SHADER_SWIZZLE_OP (2413, ywxz) SHADER_SWIZZLE_OP (2414, ywxw) SHADER_SWIZZLE_OP (242 , ywy )
964 SHADER_SWIZZLE_OP (2421, ywyx) SHADER_SWIZZLE_OP (2422, ywyy) SHADER_SWIZZLE_OP (2423, ywyz) SHADER_SWIZZLE_OP (2424, ywyw)
965 SHADER_SWIZZLE_OP (243 , ywz ) SHADER_SWIZZLE_OP (2431, ywzx) SHADER_SWIZZLE_OP (2432, ywzy) SHADER_SWIZZLE_OP (2433, ywzz)
966 SHADER_SWIZZLE_OP (2434, ywzw) SHADER_SWIZZLE_OP (244 , yww ) SHADER_SWIZZLE_OP (2441, ywwx) SHADER_SWIZZLE_OP (2442, ywwy)
967 SHADER_SWIZZLE_OP (2443, ywwz) SHADER_SWIZZLE_OP (2444, ywww) SHADER_SWIZZLE_OP (3 , z ) SHADER_SWIZZLE_OP (31 , zx )
968 SHADER_SWIZZLE_OP (311 , zxx ) SHADER_SWIZZLE_OP (3111, zxxx) SHADER_SWIZZLE_OP (3112, zxxy) SHADER_SWIZZLE_OP (3113, zxxz)
969 SHADER_SWIZZLE_OP (3114, zxxw) SHADER_SWIZZLE_OP (312 , zxy ) SHADER_SWIZZLE_OP (3121, zxyx) SHADER_SWIZZLE_OP (3122, zxyy)
970 SHADER_SWIZZLE_OP (3123, zxyz) SHADER_SWIZZLE_OP (3124, zxyw) SHADER_SWIZZLE_OP (313 , zxz ) SHADER_SWIZZLE_OP (3131, zxzx)
971 SHADER_SWIZZLE_OP (3132, zxzy) SHADER_SWIZZLE_OP (3133, zxzz) SHADER_SWIZZLE_OP (3134, zxzw) SHADER_SWIZZLE_OP (314 , zxw )
972 SHADER_SWIZZLE_OP (3141, zxwx) SHADER_SWIZZLE_OP (3142, zxwy) SHADER_SWIZZLE_OP (3143, zxwz) SHADER_SWIZZLE_OP (3144, zxww)
973 SHADER_SWIZZLE_OP (32 , zy ) SHADER_SWIZZLE_OP (321 , zyx ) SHADER_SWIZZLE_OP (3211, zyxx) SHADER_SWIZZLE_OP (3212, zyxy)
974 SHADER_SWIZZLE_OP (3213, zyxz) SHADER_SWIZZLE_OP (3214, zyxw) SHADER_SWIZZLE_OP (322 , zyy ) SHADER_SWIZZLE_OP (3221, zyyx)
975 SHADER_SWIZZLE_OP (3222, zyyy) SHADER_SWIZZLE_OP (3223, zyyz) SHADER_SWIZZLE_OP (3224, zyyw) SHADER_SWIZZLE_OP (323 , zyz )
976 SHADER_SWIZZLE_OP (3231, zyzx) SHADER_SWIZZLE_OP (3232, zyzy) SHADER_SWIZZLE_OP (3233, zyzz) SHADER_SWIZZLE_OP (3234, zyzw)
977 SHADER_SWIZZLE_OP (324 , zyw ) SHADER_SWIZZLE_OP (3241, zywx) SHADER_SWIZZLE_OP (3242, zywy) SHADER_SWIZZLE_OP (3243, zywz)
978 SHADER_SWIZZLE_OP (3244, zyww) SHADER_SWIZZLE_OP (33 , zz ) SHADER_SWIZZLE_OP (331 , zzx ) SHADER_SWIZZLE_OP (3311, zzxx)
979 SHADER_SWIZZLE_OP (3312, zzxy) SHADER_SWIZZLE_OP (3313, zzxz) SHADER_SWIZZLE_OP (3314, zzxw) SHADER_SWIZZLE_OP (332 , zzy )
980 SHADER_SWIZZLE_OP (3321, zzyx) SHADER_SWIZZLE_OP (3322, zzyy) SHADER_SWIZZLE_OP (3323, zzyz) SHADER_SWIZZLE_OP (3324, zzyw)
981 SHADER_SWIZZLE_OP (333 , zzz ) SHADER_SWIZZLE_OP (3331, zzzx) SHADER_SWIZZLE_OP (3332, zzzy) SHADER_SWIZZLE_OP (3333, zzzz)
982 SHADER_SWIZZLE_OP (3334, zzzw) SHADER_SWIZZLE_OP (334 , zzw ) SHADER_SWIZZLE_OP (3341, zzwx) SHADER_SWIZZLE_OP (3342, zzwy)
983 SHADER_SWIZZLE_OP (3343, zzwz) SHADER_SWIZZLE_OP (3344, zzww) SHADER_SWIZZLE_OP (34 , zw ) SHADER_SWIZZLE_OP (341 , zwx )
984 SHADER_SWIZZLE_OP (3411, zwxx) SHADER_SWIZZLE_OP (3412, zwxy) SHADER_SWIZZLE_OP (3413, zwxz) SHADER_SWIZZLE_OP (3414, zwxw)
985 SHADER_SWIZZLE_OP (342 , zwy ) SHADER_SWIZZLE_OP (3421, zwyx) SHADER_SWIZZLE_OP (3422, zwyy) SHADER_SWIZZLE_OP (3423, zwyz)
986 SHADER_SWIZZLE_OP (3424, zwyw) SHADER_SWIZZLE_OP (343 , zwz ) SHADER_SWIZZLE_OP (3431, zwzx) SHADER_SWIZZLE_OP (3432, zwzy)
987 SHADER_SWIZZLE_OP (3433, zwzz) SHADER_SWIZZLE_OP (3434, zwzw) SHADER_SWIZZLE_OP (344 , zww ) SHADER_SWIZZLE_OP (3441, zwwx)
988 SHADER_SWIZZLE_OP (3442, zwwy) SHADER_SWIZZLE_OP (3443, zwwz) SHADER_SWIZZLE_OP (3444, zwww) SHADER_SWIZZLE_OP (4 , w )
989 SHADER_SWIZZLE_OP (41 , wx ) SHADER_SWIZZLE_OP (411 , wxx ) SHADER_SWIZZLE_OP (4111, wxxx) SHADER_SWIZZLE_OP (4112, wxxy)
990 SHADER_SWIZZLE_OP (4113, wxxz) SHADER_SWIZZLE_OP (4114, wxxw) SHADER_SWIZZLE_OP (412 , wxy ) SHADER_SWIZZLE_OP (4121, wxyx)
991 SHADER_SWIZZLE_OP (4122, wxyy) SHADER_SWIZZLE_OP (4123, wxyz) SHADER_SWIZZLE_OP (4124, wxyw) SHADER_SWIZZLE_OP (413 , wxz )
992 SHADER_SWIZZLE_OP (4131, wxzx) SHADER_SWIZZLE_OP (4132, wxzy) SHADER_SWIZZLE_OP (4133, wxzz) SHADER_SWIZZLE_OP (4134, wxzw)
993 SHADER_SWIZZLE_OP (414 , wxw ) SHADER_SWIZZLE_OP (4141, wxwx) SHADER_SWIZZLE_OP (4142, wxwy) SHADER_SWIZZLE_OP (4143, wxwz)
994 SHADER_SWIZZLE_OP (4144, wxww) SHADER_SWIZZLE_OP (42 , wy ) SHADER_SWIZZLE_OP (421 , wyx ) SHADER_SWIZZLE_OP (4211, wyxx)
995 SHADER_SWIZZLE_OP (4212, wyxy) SHADER_SWIZZLE_OP (4213, wyxz) SHADER_SWIZZLE_OP (4214, wyxw) SHADER_SWIZZLE_OP (422 , wyy )
996 SHADER_SWIZZLE_OP (4221, wyyx) SHADER_SWIZZLE_OP (4222, wyyy) SHADER_SWIZZLE_OP (4223, wyyz) SHADER_SWIZZLE_OP (4224, wyyw)
997 SHADER_SWIZZLE_OP (423 , wyz ) SHADER_SWIZZLE_OP (4231, wyzx) SHADER_SWIZZLE_OP (4232, wyzy) SHADER_SWIZZLE_OP (4233, wyzz)
998 SHADER_SWIZZLE_OP (4234, wyzw) SHADER_SWIZZLE_OP (424 , wyw ) SHADER_SWIZZLE_OP (4241, wywx) SHADER_SWIZZLE_OP (4242, wywy)
999 SHADER_SWIZZLE_OP (4243, wywz) SHADER_SWIZZLE_OP (4244, wyww) SHADER_SWIZZLE_OP (43 , wz ) SHADER_SWIZZLE_OP (431 , wzx )
1000 SHADER_SWIZZLE_OP (4311, wzxx) SHADER_SWIZZLE_OP (4312, wzxy) SHADER_SWIZZLE_OP (4313, wzxz) SHADER_SWIZZLE_OP (4314, wzxw)
1001 SHADER_SWIZZLE_OP (432 , wzy ) SHADER_SWIZZLE_OP (4321, wzyx) SHADER_SWIZZLE_OP (4322, wzyy) SHADER_SWIZZLE_OP (4323, wzyz)
1002 SHADER_SWIZZLE_OP (4324, wzyw) SHADER_SWIZZLE_OP (433 , wzz ) SHADER_SWIZZLE_OP (4331, wzzx) SHADER_SWIZZLE_OP (4332, wzzy)
1003 SHADER_SWIZZLE_OP (4333, wzzz) SHADER_SWIZZLE_OP (4334, wzzw) SHADER_SWIZZLE_OP (434 , wzw ) SHADER_SWIZZLE_OP (4341, wzwx)
1004 SHADER_SWIZZLE_OP (4342, wzwy) SHADER_SWIZZLE_OP (4343, wzwz) SHADER_SWIZZLE_OP (4344, wzww) SHADER_SWIZZLE_OP (44 , ww )
1005 SHADER_SWIZZLE_OP (441 , wwx ) SHADER_SWIZZLE_OP (4411, wwxx) SHADER_SWIZZLE_OP (4412, wwxy) SHADER_SWIZZLE_OP (4413, wwxz)
1006 SHADER_SWIZZLE_OP (4414, wwxw) SHADER_SWIZZLE_OP (442 , wwy ) SHADER_SWIZZLE_OP (4421, wwyx) SHADER_SWIZZLE_OP (4422, wwyy)
1007 SHADER_SWIZZLE_OP (4423, wwyz) SHADER_SWIZZLE_OP (4424, wwyw) SHADER_SWIZZLE_OP (443 , wwz ) SHADER_SWIZZLE_OP (4431, wwzx)
1008 SHADER_SWIZZLE_OP (4432, wwzy) SHADER_SWIZZLE_OP (4433, wwzz) SHADER_SWIZZLE_OP (4434, wwzw) SHADER_SWIZZLE_OP (444 , www )
1009 SHADER_SWIZZLE_OP (4441, wwwx) SHADER_SWIZZLE_OP (4442, wwwy) SHADER_SWIZZLE_OP (4443, wwwz) SHADER_SWIZZLE_OP (4444, wwww)
1010
1011 # undef SHADER_SWIZZLE_OP
1012
1013 # define SHADER_FUNC0_(name, glname) \
1014 template<typename A> \
1015 inline const sl_expr<sl_func0> \
1016 name () \
1017 { \
1018 return sl_func0 (#glname " ("); \
1019 }
1020
1021 # define SHADER_FUNC0(name) SHADER_FUNC0_(name,name)
1022
1023 # define SHADER_FUNC1_(name, glname) \
1024 template<typename A> \
1025 inline const sl_expr< sl_func1<typename sl_convert<A>::T> > \
1026 name (const A &a) \
1027 { \
1028 return sl_func1<typename sl_convert<A>::T> (#glname " (", sl_convert<A>::convert (a));\
1029 }
1030
1031 # define SHADER_FUNC1(name) SHADER_FUNC1_(name,name)
1032
1033 # define SHADER_FUNC2_(name, glname) \
1034 template<typename A, typename B> \
1035 inline const sl_expr< sl_func2<typename sl_convert<A>::T, typename sl_convert<B>::T> > \
1036 name (const A &a, const B &b) \
1037 { \
1038 return sl_func2<typename sl_convert<A>::T, typename sl_convert<B>::T> (#glname " (", sl_convert<A>::convert (a), sl_convert<B>::convert (b));\
1039 }
1040
1041 # define SHADER_FUNC2(name) SHADER_FUNC2_(name,name)
1042
1043 # define SHADER_FUNC3_(name, glname) \
1044 template<typename A, typename B, typename C> \
1045 inline const sl_expr< sl_func3<typename sl_convert<A>::T, typename sl_convert<B>::T, typename sl_convert<C>::T> > \
1046 name (const A &a, const B &b, const C &c) \
1047 { \
1048 return sl_func3<typename sl_convert<A>::T, typename sl_convert<B>::T, typename sl_convert<C>::T> (#glname " (", sl_convert<A>::convert (a), sl_convert<B>::convert (b), sl_convert<C>::convert (c));\
1049 }
1050
1051 # define SHADER_FUNC3(name) SHADER_FUNC3_(name,name)
1052
1053 # define SHADER_FUNC4_(name, glname) \
1054 template<typename A, typename B, typename C, typename D> \
1055 inline const sl_expr< sl_func4<typename sl_convert<A>::T, typename sl_convert<B>::T, typename sl_convert<C>::T, typename sl_convert<D>::T > > \
1056 name (const A &a, const B &b, const C &c, const D &d) \
1057 { \
1058 return sl_func4<typename sl_convert<A>::T, typename sl_convert<B>::T, typename sl_convert<C>::T, typename sl_convert<D>::T> (#glname " (", sl_convert<A>::convert (a), sl_convert<B>::convert (b), sl_convert<C>::convert (c), sl_convert<D>::convert (d));\
1059 }
1060
1061 # define SHADER_FUNC4(name) SHADER_FUNC4_(name,name)
1062
1063 SHADER_FUNC1 (abs)
1064 SHADER_FUNC1 (acos)
1065 SHADER_FUNC1 (all)
1066 SHADER_FUNC1 (any)
1067 SHADER_FUNC1 (asin)
1068 SHADER_FUNC1 (atan)
1069 SHADER_FUNC2 (atan)
1070 SHADER_FUNC1 (ceil)
1071 SHADER_FUNC3 (clamp)
1072 SHADER_FUNC1 (cos)
1073 SHADER_FUNC2 (cross)
1074 SHADER_FUNC1 (dFdx)
1075 SHADER_FUNC1 (dFdy)
1076 SHADER_FUNC1 (degrees)
1077 SHADER_FUNC2 (distance)
1078 SHADER_FUNC2 (dot)
1079 SHADER_FUNC2_(equal, equal)
1080 SHADER_FUNC1 (exp)
1081 SHADER_FUNC1 (exp2)
1082 SHADER_FUNC3 (faceforward)
1083 SHADER_FUNC1 (floor)
1084 SHADER_FUNC1 (fract)
1085 SHADER_FUNC0 (ftransform)
1086 SHADER_FUNC1 (fwidth)
1087 SHADER_FUNC2_(greater_than_equal, greaterThanEqual)
1088 SHADER_FUNC2_(greater_then, greaterThan)
1089 SHADER_FUNC1 (inversesqrt)
1090 SHADER_FUNC1 (length)
1091 SHADER_FUNC2_(less_than, lessThan)
1092 SHADER_FUNC2_(less_than_equal, lessThanEqual)
1093 SHADER_FUNC1 (log)
1094 SHADER_FUNC1 (log2)
1095 SHADER_FUNC2_(matrix_comp_mult, matrixCompMult)
1096 SHADER_FUNC2 (max)
1097 SHADER_FUNC2 (min)
1098 SHADER_FUNC3 (mix)
1099 SHADER_FUNC2 (mod)
1100 SHADER_FUNC1 (noise1)
1101 SHADER_FUNC1 (noise2)
1102 SHADER_FUNC1 (noise3)
1103 SHADER_FUNC1 (noise4)
1104 SHADER_FUNC1 (normalize)
1105 SHADER_FUNC1 (gl_not) // TODO
1106 SHADER_FUNC2_(notequal, notEqual)
1107 SHADER_FUNC2 (pow)
1108 SHADER_FUNC1 (radians)
1109 SHADER_FUNC2 (reflect)
1110 SHADER_FUNC3 (refract)
1111 SHADER_FUNC2_(shadow_1d, shadow1D)
1112 SHADER_FUNC3_(shadow_1d, shadow1D)
1113 SHADER_FUNC3_(shadow_1d_lod, shadow1DLod)
1114 SHADER_FUNC2_(shadow_1d_proj, shadow1DProj)
1115 SHADER_FUNC3_(shadow_1d_proj, shadow1DProj)
1116 SHADER_FUNC3_(shadow_1d_proj_lod, shadow1DProjLod)
1117 SHADER_FUNC2_(shadow_2d, shadow2D)
1118 SHADER_FUNC3_(shadow_2d, shadow2D)
1119 SHADER_FUNC3_(shadow_2d_lod, shadow2DLod)
1120 SHADER_FUNC2_(shadow_2d_proj, shadow2DProj)
1121 SHADER_FUNC3_(shadow_2d_proj, shadow2DProj)
1122 SHADER_FUNC3_(shadow_2d_proj_lod, shadow2DProjLod)
1123 SHADER_FUNC1 (sign)
1124 SHADER_FUNC1 (sin)
1125 SHADER_FUNC3 (smoothstep)
1126 SHADER_FUNC1 (sqrt)
1127 SHADER_FUNC2 (step)
1128 SHADER_FUNC1 (tan)
1129 SHADER_FUNC2_(texture_1d, texture1D)
1130 SHADER_FUNC3_(texture_1d, texture1D)
1131 SHADER_FUNC3_(texture_1d_lod, texture1DLod)
1132 SHADER_FUNC2_(texture_1d_proj, texture1DProj)
1133 SHADER_FUNC3_(texture_1d_proj, texture1DProj)
1134 SHADER_FUNC3_(texture_1d_proj_lod, texture1DProjLod)
1135 SHADER_FUNC2_(texture_2d, texture2D)
1136 SHADER_FUNC3_(texture_2d, texture2D)
1137 SHADER_FUNC3_(texture_2d_lod, texture2DLod)
1138 SHADER_FUNC2_(texture_2d_proj, texture2DProj)
1139 SHADER_FUNC3_(texture_2d_proj, texture2DProj)
1140 SHADER_FUNC3_(texture_2d_proj_lod, texture2DProjLod)
1141 SHADER_FUNC2_(texture_3d, texture3D)
1142 SHADER_FUNC3_(texture_3d, texture3D)
1143 SHADER_FUNC3_(texture_3d_lod, texture3DLod)
1144 SHADER_FUNC2_(texture_3d_proj, texture3DProj)
1145 SHADER_FUNC3_(texture_3d_proj, texture3DProj)
1146 SHADER_FUNC3_(texture_3d_proj_lod, texture3DProjLod)
1147 SHADER_FUNC2_(texture_cube, textureCube)
1148 SHADER_FUNC3_(texture_cube, textureCube)
1149 SHADER_FUNC3_(texture_cude_lod, textureCubeLod)
1150 SHADER_FUNC1 (vec2) SHADER_FUNC2 (vec2)
1151 SHADER_FUNC1 (vec3) SHADER_FUNC2 (vec3) SHADER_FUNC3 (vec3)
1152 SHADER_FUNC1 (vec4) SHADER_FUNC2 (vec4) SHADER_FUNC3 (vec4) SHADER_FUNC4 (vec4)
1153 SHADER_FUNC1 (mat2) SHADER_FUNC2 (mat2)
1154 SHADER_FUNC1 (mat3) SHADER_FUNC2 (mat3) SHADER_FUNC3 (mat3)
1155 SHADER_FUNC1 (mat4) SHADER_FUNC2 (mat4) SHADER_FUNC3 (mat4) SHADER_FUNC4 (mat4)
1156
1157 # undef SHADER_FUNC0
1158 # undef SHADER_FUNC0_
1159 # undef SHADER_FUNC1
1160 # undef SHADER_FUNC1_
1161 # undef SHADER_FUNC2
1162 # undef SHADER_FUNC2_
1163 # undef SHADER_FUNC3
1164 # undef SHADER_FUNC3_
1165 # undef SHADER_FUNC4
1166 # undef SHADER_FUNC5_
1167
1168 void debdebdebdebug ();//D
1169 }
1170
1171 #endif
1172