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