… | |
… | |
41 | struct sl_concat4 |
41 | struct sl_concat4 |
42 | { |
42 | { |
43 | 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; |
44 | 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) { } |
45 | void operator ()() const { a (); b (); c (); d(); } |
45 | void operator ()() const { a (); b (); c (); d(); } |
|
|
46 | }; |
|
|
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 (); } |
46 | }; |
92 | }; |
47 | |
93 | |
48 | class refcounted |
94 | class refcounted |
49 | { |
95 | { |
50 | template<class type> friend class ref; |
96 | template<class type> friend class ref; |
… | |
… | |
186 | struct lvalue_i : fragment_i |
232 | struct lvalue_i : fragment_i |
187 | { |
233 | { |
188 | }; |
234 | }; |
189 | |
235 | |
190 | // a simple predeclared variable with unspecified type |
236 | // a simple predeclared variable with unspecified type |
191 | struct glvar_i : lvalue_i |
237 | struct gluvar_i : lvalue_i |
192 | { |
238 | { |
193 | const char *name; |
239 | const char *name; |
194 | void build (shader_builder &b); |
240 | void build (shader_builder &b); |
195 | glvar_i (const char *name) : name (name) { } |
241 | gluvar_i (const char *name) : name (name) { } |
196 | }; |
242 | }; |
197 | |
243 | |
198 | typedef auto_lvalue_ref1<glvar_i, const char *> glvar; |
244 | typedef auto_lvalue_ref1<gluvar_i, const char *> gluvar; |
199 | |
245 | |
200 | struct var_i : lvalue_i |
246 | struct var_i : lvalue_i |
201 | { |
247 | { |
202 | static unsigned int next_id; |
248 | static unsigned int next_id; |
203 | |
249 | |
… | |
… | |
212 | }; |
258 | }; |
213 | |
259 | |
214 | struct uniform_i : var_i |
260 | struct uniform_i : var_i |
215 | { |
261 | { |
216 | bool dirty; |
262 | bool dirty; |
|
|
263 | GLint location; |
217 | |
264 | |
218 | virtual void update () = 0; |
265 | virtual void update () = 0; |
219 | |
266 | |
220 | void build (shader_builder &b); |
267 | void build (shader_builder &b); |
221 | 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 | |
222 | uniform_i (const char *strtype); |
275 | uniform_i (const char *strtype); |
223 | }; |
276 | }; |
224 | |
277 | |
225 | 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 *)> |
226 | struct uniform2_i : uniform_i |
279 | struct uniform2_i : uniform_i |
227 | { |
280 | { |
228 | gltype data[dimension]; |
281 | gltype data[dimension]; |
229 | |
282 | |
230 | void update () |
283 | void update () |
231 | { |
284 | { |
232 | if (dirty) |
285 | if (dirty) |
233 | { |
286 | { |
234 | //upd (param, data); |
287 | if (location >= 0) |
|
|
288 | upd (location, dimension, data); |
|
|
289 | |
235 | dirty = false; |
290 | dirty = false; |
236 | } |
291 | } |
237 | } |
292 | } |
238 | |
293 | |
239 | uniform2_i () : uniform_i (strtype) { } |
294 | uniform2_i () : uniform_i (strtype) { } |
240 | }; |
295 | }; |
241 | |
296 | |
242 | template<int dimension, const char *strtype, void (*update)(CGparameter, const GLfloat *)> |
297 | template<int dimension, const char *strtype, void (*update)(GLint, GLsizei, const GLfloat *)> |
243 | struct uniform_f_i : uniform2_i<dimension, GLfloat, strtype, update> |
298 | struct uniform_f_i : uniform2_i<dimension, GLfloat, strtype, update> |
244 | { |
299 | { |
245 | }; |
300 | }; |
246 | |
301 | |
247 | struct uniform_1f_i : uniform_f_i<1, str_float, cgGLSetParameter1fv> { |
302 | struct uniform_1f_i : uniform_f_i<1, str_float, glUniform1fvARB> { |
248 | void operator =(GLfloat v) |
303 | void operator =(GLfloat v) |
249 | { |
304 | { |
250 | data[0] = v; |
305 | data[0] = v; |
251 | dirty = true; |
306 | dirty = true; |
252 | } |
307 | } |
253 | }; |
308 | }; |
254 | |
309 | |
255 | struct uniform_2f_i : uniform_f_i<2, str_vec2, cgGLSetParameter2fv> { }; |
310 | struct uniform_2f_i : uniform_f_i<2, str_vec2, glUniform2fvARB> { }; |
256 | |
311 | |
257 | struct uniform_3f_i : uniform_f_i<3, str_vec3, cgGLSetParameter3fv> { |
312 | struct uniform_3f_i : uniform_f_i<3, str_vec3, glUniform3fvARB> { |
258 | void operator =(const vec3 &v) |
313 | void operator =(const vec3 &v) |
259 | { |
314 | { |
260 | data[0] = v.x; |
315 | data[0] = v.x; |
261 | data[1] = v.y; |
316 | data[1] = v.y; |
262 | data[2] = v.z; |
317 | data[2] = v.z; |
263 | dirty = true; |
318 | dirty = true; |
264 | } |
319 | } |
265 | }; |
320 | }; |
266 | |
321 | |
267 | struct uniform_4f_i : uniform_f_i<4, str_vec4, cgGLSetParameter4fv> { |
322 | struct uniform_4f_i : uniform_f_i<4, str_vec4, glUniform4fvARB> { |
268 | #if 0 |
323 | #if 0 |
269 | void operator =(const gl::matrix &m) |
324 | void operator =(const gl::matrix &m) |
270 | { |
325 | { |
271 | memcpy (data, m.data, 16 * sizeof (GLfloat)); |
326 | memcpy (data, m.data, 16 * sizeof (GLfloat)); |
272 | dirty = true; |
327 | dirty = true; |
273 | } |
328 | } |
274 | #endif |
329 | #endif |
275 | }; |
330 | }; |
276 | |
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 | |
277 | 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> { }; |
278 | 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> { }; |
279 | 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> { }; |
280 | |
339 | |
281 | template<class var_i> |
340 | template<class var_i> |
282 | struct var_ref : ref<var_i> |
341 | struct var_ref : ref<var_i> |
283 | { |
342 | { |
284 | var_ref (const char *glname = 0) |
343 | var_ref (const char *glname = 0) |
… | |
… | |
371 | temp_ref () |
430 | temp_ref () |
372 | : ref<temporary_i> (*new temporary_i (strtype)) |
431 | : ref<temporary_i> (*new temporary_i (strtype)) |
373 | { |
432 | { |
374 | } |
433 | } |
375 | |
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 | |
376 | template<typename expr> |
444 | template<typename expr> |
377 | const temp_ref &operator =(const expr &e) const; |
445 | const temp_ref &operator =(const expr &e) const; |
378 | }; |
446 | }; |
379 | |
447 | |
380 | typedef temp_ref<str_float> temp_1f; |
448 | typedef temp_ref<str_float> temp_1f; |
… | |
… | |
386 | typedef temp_ref<str_mat4> temp_matrix_4f; |
454 | typedef temp_ref<str_mat4> temp_matrix_4f; |
387 | |
455 | |
388 | template<GLenum gltype, const char *strtype> |
456 | template<GLenum gltype, const char *strtype> |
389 | struct sampler_i : uniform_i |
457 | struct sampler_i : uniform_i |
390 | { |
458 | { |
391 | GLuint texture; |
459 | GLuint unit; |
392 | |
460 | |
393 | void update () |
461 | void update () |
394 | { |
462 | { |
395 | if (dirty) |
463 | if (dirty) |
396 | { |
464 | { |
… | |
… | |
399 | } |
467 | } |
400 | } |
468 | } |
401 | |
469 | |
402 | void begin () |
470 | void begin () |
403 | { |
471 | { |
404 | cgGLEnableTextureParameter (texture); |
472 | //cgGLEnableTextureParameter (unit); |
405 | } |
473 | } |
406 | |
474 | |
407 | sampler_i (GLuint texturename) : uniform_i (strtype), texture (texturename) { } |
475 | sampler_i (GLuint textureunit) : uniform_i (strtype), unit (textureunit) { } |
408 | }; |
476 | }; |
409 | |
477 | |
410 | struct sampler_1d_i : sampler_i<CG_SAMPLER1D, str_sampler_1d> |
478 | struct sampler_1d_i : sampler_i<GL_SAMPLER_1D_ARB, str_sampler_1d> |
411 | { |
479 | { |
412 | sampler_1d_i (GLuint texturename) : sampler_i<CG_SAMPLER1D, str_sampler_1d> (texturename) { } |
480 | sampler_1d_i (GLuint textureunit) : sampler_i<GL_SAMPLER_1D_ARB, str_sampler_1d> (textureunit) { } |
413 | }; |
481 | }; |
414 | |
482 | |
415 | struct sampler_1d_shadow_i : sampler_i<CG_SAMPLER1D, str_sampler_1d_shadow> |
483 | struct sampler_1d_shadow_i : sampler_i<GL_SAMPLER_1D_SHADOW_ARB, str_sampler_1d_shadow> |
416 | { |
484 | { |
417 | sampler_1d_shadow_i (GLuint texturename) : sampler_i<CG_SAMPLER1D, str_sampler_1d_shadow> (texturename) { } |
485 | sampler_1d_shadow_i (GLuint textureunit) : sampler_i<GL_SAMPLER_1D_SHADOW_ARB, str_sampler_1d_shadow> (textureunit) { } |
418 | }; |
486 | }; |
419 | |
487 | |
420 | struct sampler_2d_i : sampler_i<CG_SAMPLER2D, str_sampler_2d> |
488 | struct sampler_2d_i : sampler_i<GL_SAMPLER_2D_ARB, str_sampler_2d> |
421 | { |
489 | { |
422 | sampler_2d_i (GLuint texturename) : sampler_i<CG_SAMPLER2D, str_sampler_2d> (texturename) { } |
490 | sampler_2d_i (GLuint textureunit) : sampler_i<GL_SAMPLER_2D_ARB, str_sampler_2d> (textureunit) { } |
423 | }; |
491 | }; |
424 | |
492 | |
425 | struct sampler_2d_shadow_i : sampler_i<CG_SAMPLER2D, str_sampler_2d_shadow> |
493 | struct sampler_2d_shadow_i : sampler_i<GL_SAMPLER_2D_SHADOW_ARB, str_sampler_2d_shadow> |
426 | { |
494 | { |
427 | sampler_2d_shadow_i (GLuint texturename) : sampler_i<CG_SAMPLER2D, str_sampler_2d_shadow> (texturename) { } |
495 | sampler_2d_shadow_i (GLuint textureunit) : sampler_i<GL_SAMPLER_2D_SHADOW_ARB, str_sampler_2d_shadow> (textureunit) { } |
428 | }; |
496 | }; |
429 | |
497 | |
430 | struct sampler_2d_rect_i : sampler_i<CG_SAMPLERRECT, str_sampler_2d_rect> |
498 | struct sampler_2d_rect_i : sampler_i<GL_SAMPLER_2D_RECT_ARB, str_sampler_2d_rect> |
431 | { |
499 | { |
432 | sampler_2d_rect_i (GLuint texturename) : sampler_i<CG_SAMPLERRECT, str_sampler_2d_rect> (texturename) { } |
500 | sampler_2d_rect_i (GLuint textureunit) : sampler_i<GL_SAMPLER_2D_RECT_ARB, str_sampler_2d_rect> (textureunit) { } |
433 | }; |
501 | }; |
434 | |
502 | |
435 | struct sampler_2d_rect_shadow_i : sampler_i<CG_SAMPLERRECT, str_sampler_2d_rect_shadow> |
503 | struct sampler_2d_rect_shadow_i : sampler_i<GL_SAMPLER_2D_RECT_SHADOW_ARB, str_sampler_2d_rect_shadow> |
436 | { |
504 | { |
437 | 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<GL_SAMPLER_2D_RECT_SHADOW_ARB, str_sampler_2d_rect_shadow> (textureunit) { } |
438 | }; |
506 | }; |
439 | |
507 | |
440 | struct sampler_3d_i : sampler_i<CG_SAMPLER3D, str_sampler_3d> |
508 | struct sampler_3d_i : sampler_i<GL_SAMPLER_3D_ARB, str_sampler_3d> |
441 | { |
509 | { |
442 | sampler_3d_i (GLuint texturename) : sampler_i<CG_SAMPLER3D, str_sampler_3d> (texturename) { } |
510 | sampler_3d_i (GLuint textureunit) : sampler_i<GL_SAMPLER_3D_ARB, str_sampler_3d> (textureunit) { } |
443 | }; |
511 | }; |
444 | |
512 | |
445 | struct sampler_3d_rect_i : sampler_i<CG_SAMPLER3D, str_sampler_3d_rect> |
513 | struct sampler_3d_rect_i : sampler_i<GL_SAMPLER_3D_ARB, str_sampler_3d_rect> |
446 | { |
514 | { |
447 | sampler_3d_rect_i (GLuint texturename) : sampler_i<CG_SAMPLER3D, str_sampler_3d_rect> (texturename) { } |
515 | sampler_3d_rect_i (GLuint textureunit) : sampler_i<GL_SAMPLER_3D_ARB, str_sampler_3d_rect> (textureunit) { } |
448 | }; |
516 | }; |
449 | |
517 | |
450 | struct sampler_cube_i : sampler_i<CG_SAMPLERCUBE, str_sampler_cube> |
518 | struct sampler_cube_i : sampler_i<GL_SAMPLER_CUBE_ARB, str_sampler_cube> |
451 | { |
519 | { |
452 | sampler_cube_i (GLuint texturename) : sampler_i<CG_SAMPLERCUBE, str_sampler_cube> (texturename) { } |
520 | sampler_cube_i (GLuint textureunit) : sampler_i<GL_SAMPLER_CUBE_ARB, str_sampler_cube> (textureunit) { } |
453 | }; |
521 | }; |
454 | |
522 | |
455 | typedef auto_ref1<sampler_1d_i, GLuint> sampler_1d; |
523 | typedef auto_ref1<sampler_1d_i, GLuint> sampler_1d; |
456 | typedef auto_ref1<sampler_1d_shadow_i, GLuint> sampler_1d_shadow; |
524 | typedef auto_ref1<sampler_1d_shadow_i, GLuint> sampler_1d_shadow; |
457 | typedef auto_ref1<sampler_2d_i, GLuint> sampler_2d; |
525 | typedef auto_ref1<sampler_2d_i, GLuint> sampler_2d; |
… | |
… | |
506 | |
574 | |
507 | void append_string (const char *s) |
575 | void append_string (const char *s) |
508 | { |
576 | { |
509 | push_back (*new fragment_string_i (s)); |
577 | push_back (*new fragment_string_i (s)); |
510 | } |
578 | } |
511 | |
|
|
512 | #if 0 |
|
|
513 | fragment_vector_i &operator <<(statement_i &f) |
|
|
514 | { |
|
|
515 | push_back (*new fragment_const_string_i (" ")); |
|
|
516 | |
|
|
517 | for (vector<fragment>::iterator i = f.begin (); i != f.end (); i++) |
|
|
518 | push_back (*i); |
|
|
519 | |
|
|
520 | push_back (*new fragment_const_string_i (";\n")); |
|
|
521 | return *this; |
|
|
522 | } |
|
|
523 | #endif |
|
|
524 | }; |
579 | }; |
525 | |
580 | |
526 | typedef ref<fragment_vector_i> fragment_vector; |
581 | typedef ref<fragment_vector_i> fragment_vector; |
527 | |
582 | |
528 | struct shader_object_i : fragment_vector_i |
583 | struct shader_object_i : fragment_vector_i |
… | |
… | |
550 | } |
605 | } |
551 | }; |
606 | }; |
552 | |
607 | |
553 | typedef shader_object<GL_VERTEX_SHADER_ARB> vertex_shader; |
608 | typedef shader_object<GL_VERTEX_SHADER_ARB> vertex_shader; |
554 | typedef shader_object<GL_FRAGMENT_SHADER_ARB> fragment_shader; |
609 | typedef shader_object<GL_FRAGMENT_SHADER_ARB> fragment_shader; |
|
|
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 | }; |
555 | |
623 | |
556 | template<typename T> |
624 | template<typename T> |
557 | struct sl_append |
625 | struct sl_append |
558 | { |
626 | { |
559 | T t; |
627 | T t; |
… | |
… | |
681 | return sl_append< var_ref<V> > (v); |
749 | return sl_append< var_ref<V> > (v); |
682 | } |
750 | } |
683 | }; |
751 | }; |
684 | |
752 | |
685 | template<> |
753 | template<> |
686 | struct sl_convert<glvar> |
754 | struct sl_convert<gluvar> |
687 | { |
755 | { |
688 | typedef sl_expr< sl_append<glvar> > T; |
756 | typedef sl_expr< sl_append<gluvar> > T; |
689 | static inline const T convert (const glvar &v) |
757 | static inline const T convert (const gluvar &v) |
690 | { |
758 | { |
691 | return sl_append<glvar> (v); |
759 | return sl_append<gluvar> (v); |
692 | } |
760 | } |
693 | }; |
761 | }; |
694 | |
762 | |
695 | template<> |
763 | template<> |
696 | template<const char *strtype> |
764 | template<const char *strtype> |
… | |
… | |
705 | } |
773 | } |
706 | }; |
774 | }; |
707 | |
775 | |
708 | extern const fragment_const_string str_2sp; |
776 | extern const fragment_const_string str_2sp; |
709 | extern const fragment_const_string str_equal; |
777 | extern const fragment_const_string str_equal; |
|
|
778 | extern const fragment_const_string str_comma; |
710 | extern const fragment_const_string str_endl; |
779 | extern const fragment_const_string str_endl; |
711 | |
780 | |
712 | template<class fragment, typename expr> |
781 | template<class fragment, typename expr> |
713 | inline void sl_assign (const fragment &f, const expr &e) |
782 | inline void sl_assign (const fragment &f, const expr &e) |
714 | { |
783 | { |
… | |
… | |
762 | { |
831 | { |
763 | cur->push_back (str); |
832 | cur->push_back (str); |
764 | } |
833 | } |
765 | }; |
834 | }; |
766 | |
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 | |
767 | # define SHADER_BINOP(op, str) \ |
847 | # define SHADER_BINOP(op, str) \ |
768 | extern const sl_append_const_string str_ ## str; \ |
848 | extern const sl_append_const_string str_ ## str; \ |
769 | template<typename A, typename B> \ |
849 | template<typename A, typename B> \ |
770 | inline const sl_expr< sl_concat3< typename sl_convert<A>::T, \ |
850 | inline const sl_expr< sl_binop< typename sl_convert<A>::T, \ |
771 | sl_append_const_string, \ |
851 | sl_append_const_string, \ |
772 | typename sl_convert<B>::T > > \ |
852 | typename sl_convert<B>::T > > \ |
773 | operator op(const A &a, const B &b) \ |
853 | operator op(const A &a, const B &b) \ |
774 | { \ |
854 | { \ |
|
|
855 | return sl_binop< typename sl_convert<A>::T, sl_append_const_string, typename sl_convert<B>::T > \ |
775 | 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)); \ |
776 | } |
857 | } |
777 | |
858 | |
778 | SHADER_BINOP (+, plus); |
859 | SHADER_BINOP (+, plus); |
779 | SHADER_BINOP (-, minus); |
860 | SHADER_BINOP (-, minus); |
780 | SHADER_BINOP (*, mul); |
861 | SHADER_BINOP (*, mul); |
781 | SHADER_BINOP (/, div); |
862 | SHADER_BINOP (/, div); |
|
|
863 | SHADER_BINOP (%, mod); |
782 | |
864 | |
783 | # undef SHADER_BINOP |
865 | # undef SHADER_BINOP |
784 | |
866 | |
785 | void swizzle_mask (sl_string<7> &s, int mask); |
867 | void swizzle_mask (sl_string<7> &s, int mask); |
786 | |
|
|
787 | extern const sl_append_const_string str_lpar; |
|
|
788 | extern const sl_append_const_string str_rpar; |
|
|
789 | |
868 | |
790 | template<typename T> |
869 | template<typename T> |
791 | inline const sl_expr< sl_concat3< sl_append_const_string, |
870 | inline const sl_expr< sl_concat3< sl_append_const_string, |
792 | typename sl_convert<T>::T, |
871 | typename sl_convert<T>::T, |
793 | sl_string<7> |
872 | sl_string<7> |
… | |
… | |
897 | SHADER_SWIZZLE_OP (4432, wwzy) SHADER_SWIZZLE_OP (4433, wwzz) SHADER_SWIZZLE_OP (4434, wwzw) SHADER_SWIZZLE_OP (444 , www ) |
976 | SHADER_SWIZZLE_OP (4432, wwzy) SHADER_SWIZZLE_OP (4433, wwzz) SHADER_SWIZZLE_OP (4434, wwzw) SHADER_SWIZZLE_OP (444 , www ) |
898 | SHADER_SWIZZLE_OP (4441, wwwx) SHADER_SWIZZLE_OP (4442, wwwy) SHADER_SWIZZLE_OP (4443, wwwz) SHADER_SWIZZLE_OP (4444, wwww) |
977 | SHADER_SWIZZLE_OP (4441, wwwx) SHADER_SWIZZLE_OP (4442, wwwy) SHADER_SWIZZLE_OP (4443, wwwz) SHADER_SWIZZLE_OP (4444, wwww) |
899 | |
978 | |
900 | # undef SHADER_SWIZZLE_OP |
979 | # undef SHADER_SWIZZLE_OP |
901 | |
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_ |
|
|
1135 | |
902 | void debdebdebdebug ();//D |
1136 | void debdebdebdebug ();//D |
903 | } |
1137 | } |
904 | |
1138 | |
905 | #endif |
1139 | #endif |
906 | |
1140 | |