#ifndef SHADER_H #define SHADER_H #include #include "opengl.h" #include "util.h" namespace shader { using namespace std; const int NAMELEN = 32; template struct sl_expr { const T t; sl_expr (const T &t) : t(t) { } void operator ()() const { t (); } template const sl_expr &operator =(const expr &e) const; }; template struct sl_concat2 { const A a; const B b; sl_concat2 (const A &a, const B &b) : a(a), b(b) { } void operator ()() const { a (); b (); } }; template struct sl_concat3 { const A a; const B b; const C c; sl_concat3 (const A &a, const B &b, const C &c) : a(a), b(b), c(c) { } void operator ()() const { a (); b (); c (); } }; template struct sl_concat4 { const A a; const B b; const C c; const D d; sl_concat4 (const A &a, const B &b, const C &c, const D &d) : a(a), b(b), c(c), d(d) { } void operator ()() const { a (); b (); c (); d(); } }; struct sl_func0 { const char *name_par; sl_func0 (const char *name_par) : name_par(name_par) { } void begin () const; void comma () const; void end () const; void operator ()() const { begin (); end (); } }; template struct sl_func1 : sl_func0 { const A a; sl_func1 (const char *name, const A &a) : sl_func0(name), a(a) { } void operator ()() const { begin (); a (); end (); } }; template struct sl_func2 : sl_func0 { const A a; const B b; sl_func2 (const char *name, const A &a, const B &b) : sl_func0(name), a(a), b(b) { } void operator ()() const { begin (); a (); comma (); b (); end (); } }; template struct sl_func3 : sl_func0 { const A a; const B b; const C c; sl_func3 (const char *name, const A &a, const B &b, const C &c) : sl_func0(name), a(a), b(b), c(c) { } void operator ()() const { begin (); a (); comma (); b (); comma (); c (); end (); } }; template struct sl_func4 : sl_func0 { const A a; const B b; const C c; const D d; 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) { } void operator ()() const { begin (); a (); comma (); b (); comma (); c (); comma (); d(); end (); } }; class refcounted { template friend class ref; mutable int refcnt; void refcnt_inc () const { refcnt++; } void refcnt_dec () const; public: refcounted () : refcnt(0) { } virtual ~refcounted (); }; template struct ref { type *p; ref () { p = new type; p->refcnt_inc (); } ref (type &d) { d.refcnt_inc (); p = &d; } ref (const ref &r) { r.p->refcnt_inc (); p = r.p; } template ref (const ref &r) { r.p->refcnt_inc (); p = r.p; } ~ref () { p->refcnt_dec (); } ref &operator =(type &d) { d.refcnt_inc (); p->refcnt_dec (); p = &d; return *this; } type *operator ->() const { return p; } operator type &() const { return *p; } template bool operator ==(const ref b) const { return (void *)p == (void *)b.p; } }; // ref with auto-construct template struct auto_ref0 : ref { auto_ref0 () : ref (*new type ()) { } }; template struct auto_ref1 : ref { auto_ref1 (arg1 a) : ref (*new type (a)) { } }; template struct auto_lvalue_ref0 : ref { auto_lvalue_ref0 () : ref (*new type ()) { } template const auto_lvalue_ref0 &operator =(const expr &e) const; }; template struct auto_lvalue_ref1 : ref { auto_lvalue_ref1 (arg1 a) : ref (*new type (a)) { } template const auto_lvalue_ref1 &operator =(const expr &e) const; }; extern const char str_float []; extern const char str_vec2 []; extern const char str_vec3 []; extern const char str_vec4 []; extern const char str_mat2 []; extern const char str_mat3 []; extern const char str_mat4 []; extern const char str_sampler_1d []; extern const char str_sampler_1d_shadow []; extern const char str_sampler_2d []; extern const char str_sampler_2d_shadow []; extern const char str_sampler_2d_rect []; extern const char str_sampler_2d_rect_shadow []; extern const char str_sampler_3d []; extern const char str_sampler_3d_rect []; extern const char str_sampler_cube []; typedef ref var; typedef ref uniform; struct shader_builder { vector refs; // uniform parameters vector temps; // temporary variables vector streams; // varying inputs & outputs ostringstream source; template shader_builder &operator <<(const type &t) { source << t; return *this; } }; struct fragment_i : refcounted { virtual void build (shader_builder &b) = 0; }; typedef ref fragment; struct lvalue_i : fragment_i { }; // a simple predeclared variable with unspecified type struct glvar_i : lvalue_i { const char *name; void build (shader_builder &b); glvar_i (const char *name) : name (name) { } }; typedef auto_lvalue_ref1 glvar; struct var_i : lvalue_i { static unsigned int next_id; char name[NAMELEN]; const char *typestr; void build (shader_builder &b); virtual void build_decl (ostringstream &b); var_i (const char *typestr); ~var_i (); }; struct uniform_i : var_i { bool dirty; GLint location; virtual void update () = 0; void build (shader_builder &b); void build_decl (ostringstream &b); void update_location (GLint program) { location = glGetUniformLocationARB (program, name); } uniform_i (const char *strtype); }; template struct uniform2_i : uniform_i { gltype data[dimension]; void update () { if (dirty) { if (location >= 0) upd (location, dimension, data); dirty = false; } } uniform2_i () : uniform_i (strtype) { } }; template struct uniform_f_i : uniform2_i { }; struct uniform_1f_i : uniform_f_i<1, str_float, glUniform1fvARB> { void operator =(GLfloat v) { data[0] = v; dirty = true; } }; struct uniform_2f_i : uniform_f_i<2, str_vec2, glUniform2fvARB> { }; struct uniform_3f_i : uniform_f_i<3, str_vec3, glUniform3fvARB> { void operator =(const vec3 &v) { data[0] = v.x; data[1] = v.y; data[2] = v.z; dirty = true; } }; struct uniform_4f_i : uniform_f_i<4, str_vec4, glUniform4fvARB> { #if 0 void operator =(const gl::matrix &m) { memcpy (data, m.data, 16 * sizeof (GLfloat)); dirty = true; } #endif }; inline void UniformMatrix2fv (GLint l, GLsizei s, const GLfloat *m) { glUniformMatrix2fvARB (l, s, 0, m); } inline void UniformMatrix3fv (GLint l, GLsizei s, const GLfloat *m) { glUniformMatrix3fvARB (l, s, 0, m); } inline void UniformMatrix4fv (GLint l, GLsizei s, const GLfloat *m) { glUniformMatrix4fvARB (l, s, 0, m); } struct uniform_matrix_2f_i : uniform_f_i< 4, str_mat2, UniformMatrix2fv> { }; struct uniform_matrix_3f_i : uniform_f_i< 9, str_mat3, UniformMatrix3fv> { }; struct uniform_matrix_4f_i : uniform_f_i<16, str_mat4, UniformMatrix4fv> { }; template struct var_ref : ref { var_ref (const char *glname = 0) : ref (*new var_i) { if (glname) strcpy ((*this)->name, glname); } }; typedef var_ref uniform_1f; typedef var_ref uniform_2f; typedef var_ref uniform_3f; typedef var_ref uniform_4f; typedef var_ref uniform_matrix_2f; typedef var_ref uniform_matrix_3f; typedef var_ref uniform_matrix_4f; struct stream_i : var_i { void build (shader_builder &b); void build_decl (ostringstream &b); stream_i (const char *strtype); }; template struct varying_i : stream_i { varying_i () : stream_i (strtype) { } void set (GLsizei stride, GLvoid *ptr) { //cgGLSetParameterPointer (param, dimension, gltype, stride, ptr); } }; template struct varying_f_i : varying_i { void set (const gl::vertex_buffer_object &vb, GLint offset) { varying_i::set (gl::format_stride (vb.format), (GLvoid *)(long)offset); } }; struct varying_1f_i : varying_f_i<1, str_float> { }; struct varying_2f_i : varying_f_i<2, str_vec2> { void set_t (const gl::vertex_buffer_object &vb) { set (vb, gl::format_offset_t (vb.format)); } }; struct varying_3f_i : varying_f_i<3, str_vec3> { void set_p (const gl::vertex_buffer_object &vb) { set (vb, gl::format_offset_p (vb.format)); } void set_n (const gl::vertex_buffer_object &vb) { set (vb, gl::format_offset_n (vb.format)); } }; struct varying_4f_i : varying_f_i<4, str_vec4> { }; typedef var_ref varying_1f; typedef var_ref varying_2f; typedef var_ref varying_3f; typedef var_ref varying_4f; struct temporary_i : var_i { void build (shader_builder &b); temporary_i (const char *strtype); }; template struct temp_ref : ref { temp_ref () : ref (*new temporary_i (strtype)) { } #if 0 template temp_ref (const expr &e) : ref (*new temporary_i (strtype)) { (*this) = e; } #endif template const temp_ref &operator =(const expr &e) const; }; typedef temp_ref temp_1f; typedef temp_ref temp_2f; typedef temp_ref temp_3f; typedef temp_ref temp_4f; typedef temp_ref temp_matrix_2f; typedef temp_ref temp_matrix_3f; typedef temp_ref temp_matrix_4f; template struct sampler_i : uniform_i { GLuint unit; void update () { if (dirty) { //cgGLSetTextureParameter (param, texture); dirty = false; } } void begin () { cgGLEnableTextureParameter (unit); } sampler_i (GLuint textureunit) : uniform_i (strtype), unit (textureunit) { } }; struct sampler_1d_i : sampler_i { sampler_1d_i (GLuint textureunit) : sampler_i (textureunit) { } }; struct sampler_1d_shadow_i : sampler_i { sampler_1d_shadow_i (GLuint textureunit) : sampler_i (textureunit) { } }; struct sampler_2d_i : sampler_i { sampler_2d_i (GLuint textureunit) : sampler_i (textureunit) { } }; struct sampler_2d_shadow_i : sampler_i { sampler_2d_shadow_i (GLuint textureunit) : sampler_i (textureunit) { } }; struct sampler_2d_rect_i : sampler_i { sampler_2d_rect_i (GLuint textureunit) : sampler_i (textureunit) { } }; struct sampler_2d_rect_shadow_i : sampler_i { sampler_2d_rect_shadow_i (GLuint textureunit) : sampler_i (textureunit) { } }; struct sampler_3d_i : sampler_i { sampler_3d_i (GLuint textureunit) : sampler_i (textureunit) { } }; struct sampler_3d_rect_i : sampler_i { sampler_3d_rect_i (GLuint textureunit) : sampler_i (textureunit) { } }; struct sampler_cube_i : sampler_i { sampler_cube_i (GLuint textureunit) : sampler_i (textureunit) { } }; typedef auto_ref1 sampler_1d; typedef auto_ref1 sampler_1d_shadow; typedef auto_ref1 sampler_2d; typedef auto_ref1 sampler_2d_shadow; typedef auto_ref1 sampler_2d_rect; typedef auto_ref1 sampler_2d_rect_shadow; typedef auto_ref1 sampler_3d; typedef auto_ref1 sampler_3d_rect; typedef auto_ref1 sampler_cube; struct fragment_const_string_i : fragment_i { const char *str; void build (shader_builder &b); fragment_const_string_i (const char *str) : str(str) { } }; typedef auto_ref1 fragment_const_string; struct fragment_string_i : fragment_i { char *str; void build (shader_builder &b); fragment_string_i (const char *str) : str (strdup (str)) { } ~fragment_string_i (); }; struct fragment_vector_i : fragment_i, vector { void build (shader_builder &b); template void append (const ref &f) { push_back (f); } template void append (const sl_expr &e) { e (); } void append_const (const char *s) { push_back (*new fragment_const_string_i (s)); } void append_string (const char *s) { push_back (*new fragment_string_i (s)); } }; typedef ref fragment_vector; struct shader_object_i : fragment_vector_i { GLenum type; GLuint id; // GLhandleARB, but 2.0 will use uint string source (); void compile (); void start (); void stop (); shader_object_i (GLenum type); ~shader_object_i (); }; extern shader_object_i *cur; // record actions to this shader template struct shader_object : ref { shader_object () : ref (*new shader_object_i (type)) { } }; typedef shader_object vertex_shader; typedef shader_object fragment_shader; struct program_object { GLuint id; vertex_shader vsh; fragment_shader fsh; program_object (); ~program_object (); void link (); }; template struct sl_append { T t; sl_append (const T &t) : t(t) { } void operator ()() const { cur->push_back (t); } }; template struct sl_string { char str[length]; void operator ()() const { cur->push_back (*new fragment_string_i (str)); } }; struct sl_float { const GLfloat c; sl_float (GLfloat c) : c(c) { } void operator ()() const; }; template inline sl_expr< sl_concat2 > concat (const A &a, const B &b) { typedef sl_concat2 expr; return sl_expr (expr (a, b)); } template inline sl_expr< sl_concat3 > concat (const A &a, const B &b, const C &c) { typedef sl_concat3 expr; return sl_expr (expr (a, b, c)); } template inline sl_expr< sl_concat4 > concat (const A &a, const B &b, const C &c, const D &d) { typedef sl_concat4 expr; return sl_expr (expr (a, b, c, d)); } template struct sl_convert { typedef sl_expr T; static inline const T &convert (const T &e) { return e; } }; template<> struct sl_convert { typedef sl_expr T; static inline const T convert (GLfloat f) { return sl_float (f); } }; template<> struct sl_convert { typedef sl_expr T; static inline const T convert (GLdouble d) { return sl_float (d); } }; template<> struct sl_convert { typedef sl_expr T; static inline const T convert (GLint i) { return sl_float (i); } }; template<> struct sl_convert { typedef sl_expr< sl_string<60> > T; static const T convert (const vec2 &v); }; template<> struct sl_convert { typedef sl_expr< sl_string<80> > T; static const T convert (const vec3 &v); }; template<> struct sl_convert { typedef sl_expr< sl_string<100> > T; static const T convert (const vec4 &v); }; template<> template struct sl_convert< var_ref > { typedef sl_expr< sl_append< var_ref > > T; static inline const T convert (const var_ref &v) { return sl_append< var_ref > (v); } }; template<> struct sl_convert { typedef sl_expr< sl_append > T; static inline const T convert (const glvar &v) { return sl_append (v); } }; template<> template struct sl_convert< temp_ref > { typedef sl_expr< sl_append< temp_ref > > T; static inline const T convert (const temp_ref &v) { return sl_expr< sl_append< temp_ref > >( sl_append< temp_ref > (v) ); } }; extern const fragment_const_string str_2sp; extern const fragment_const_string str_equal; extern const fragment_const_string str_comma; extern const fragment_const_string str_endl; template inline void sl_assign (const fragment &f, const expr &e) { cur->append (str_2sp); cur->append (f); cur->append (str_equal); sl_convert::convert (e) (); cur->append (str_endl); } template template inline const auto_lvalue_ref0 &auto_lvalue_ref0::operator =(const expr &e) const { sl_assign (*this, e); return *this; } template template inline const auto_lvalue_ref1 &auto_lvalue_ref1::operator =(const expr &e) const { sl_assign (*this, e); return *this; } template template inline const sl_expr &sl_expr::operator =(const expr &e) const { sl_assign (*this, e); return *this; } template template inline const temp_ref &temp_ref::operator =(const expr &e) const { sl_assign (*this, e); return *this; } struct sl_append_const_string { fragment_const_string str; sl_append_const_string (const char *s) : str (s) { } void operator ()() const { cur->push_back (str); } }; extern const sl_append_const_string str_lpar; extern const sl_append_const_string str_rpar; template struct sl_binop { const A a; const B b; const C c; sl_binop (const A &a, const B &b, const C &c) : a(a), b(b), c(c) { } void operator ()() const { str_lpar (); a (); b (); c (); str_rpar (); } }; # define SHADER_BINOP(op, str) \ extern const sl_append_const_string str_ ## str; \ template \ inline const sl_expr< sl_binop< typename sl_convert::T, \ sl_append_const_string, \ typename sl_convert::T > > \ operator op(const A &a, const B &b) \ { \ return sl_binop< typename sl_convert::T, sl_append_const_string, typename sl_convert::T > \ (sl_convert::convert (a), str_ ## str, sl_convert::convert (b)); \ } SHADER_BINOP (+, plus); SHADER_BINOP (-, minus); SHADER_BINOP (*, mul); SHADER_BINOP (/, div); SHADER_BINOP (%, mod); # undef SHADER_BINOP void swizzle_mask (sl_string<7> &s, int mask); template inline const sl_expr< sl_concat3< sl_append_const_string, typename sl_convert::T, sl_string<7> > > swizzle (const T &t, int a, int b = 0, int c = 0, int d = 0) { sl_string<7> s; swizzle_mask (s, ((d * 5 + c) * 5 + b) * 5 + a); return concat (str_lpar, sl_convert::convert (t), s); } # define SHADER_SWIZZLE_OP(abcd,type) \ template \ inline const sl_expr< sl_concat3< sl_append_const_string, \ typename sl_convert::T, \ sl_string<7> \ > > \ type (const T &t) \ { \ return swizzle (t, (abcd / 1000) % 5, (abcd / 100) % 5, (abcd / 10) % 5, (abcd / 1) % 5); \ } // brute force is lovely, ain't it? SHADER_SWIZZLE_OP (1 , x ) SHADER_SWIZZLE_OP (11 , xx ) SHADER_SWIZZLE_OP (111 , xxx ) SHADER_SWIZZLE_OP (1111, xxxx) SHADER_SWIZZLE_OP (1112, xxxy) SHADER_SWIZZLE_OP (1113, xxxz) SHADER_SWIZZLE_OP (1114, xxxw) SHADER_SWIZZLE_OP (112 , xxy ) SHADER_SWIZZLE_OP (1121, xxyx) SHADER_SWIZZLE_OP (1122, xxyy) SHADER_SWIZZLE_OP (1123, xxyz) SHADER_SWIZZLE_OP (1124, xxyw) SHADER_SWIZZLE_OP (113 , xxz ) SHADER_SWIZZLE_OP (1131, xxzx) SHADER_SWIZZLE_OP (1132, xxzy) SHADER_SWIZZLE_OP (1133, xxzz) SHADER_SWIZZLE_OP (1134, xxzw) SHADER_SWIZZLE_OP (114 , xxw ) SHADER_SWIZZLE_OP (1141, xxwx) SHADER_SWIZZLE_OP (1142, xxwy) SHADER_SWIZZLE_OP (1143, xxwz) SHADER_SWIZZLE_OP (1144, xxww) SHADER_SWIZZLE_OP (12 , xy ) SHADER_SWIZZLE_OP (121 , xyx ) SHADER_SWIZZLE_OP (1211, xyxx) SHADER_SWIZZLE_OP (1212, xyxy) SHADER_SWIZZLE_OP (1213, xyxz) SHADER_SWIZZLE_OP (1214, xyxw) SHADER_SWIZZLE_OP (122 , xyy ) SHADER_SWIZZLE_OP (1221, xyyx) SHADER_SWIZZLE_OP (1222, xyyy) SHADER_SWIZZLE_OP (1223, xyyz) SHADER_SWIZZLE_OP (1224, xyyw) SHADER_SWIZZLE_OP (123 , xyz ) SHADER_SWIZZLE_OP (1231, xyzx) SHADER_SWIZZLE_OP (1232, xyzy) SHADER_SWIZZLE_OP (1233, xyzz) SHADER_SWIZZLE_OP (1234, xyzw) SHADER_SWIZZLE_OP (124 , xyw ) SHADER_SWIZZLE_OP (1241, xywx) SHADER_SWIZZLE_OP (1242, xywy) SHADER_SWIZZLE_OP (1243, xywz) SHADER_SWIZZLE_OP (1244, xyww) SHADER_SWIZZLE_OP (13 , xz ) SHADER_SWIZZLE_OP (131 , xzx ) SHADER_SWIZZLE_OP (1311, xzxx) SHADER_SWIZZLE_OP (1312, xzxy) SHADER_SWIZZLE_OP (1313, xzxz) SHADER_SWIZZLE_OP (1314, xzxw) SHADER_SWIZZLE_OP (132 , xzy ) SHADER_SWIZZLE_OP (1321, xzyx) SHADER_SWIZZLE_OP (1322, xzyy) SHADER_SWIZZLE_OP (1323, xzyz) SHADER_SWIZZLE_OP (1324, xzyw) SHADER_SWIZZLE_OP (133 , xzz ) SHADER_SWIZZLE_OP (1331, xzzx) SHADER_SWIZZLE_OP (1332, xzzy) SHADER_SWIZZLE_OP (1333, xzzz) SHADER_SWIZZLE_OP (1334, xzzw) SHADER_SWIZZLE_OP (134 , xzw ) SHADER_SWIZZLE_OP (1341, xzwx) SHADER_SWIZZLE_OP (1342, xzwy) SHADER_SWIZZLE_OP (1343, xzwz) SHADER_SWIZZLE_OP (1344, xzww) SHADER_SWIZZLE_OP (14 , xw ) SHADER_SWIZZLE_OP (141 , xwx ) SHADER_SWIZZLE_OP (1411, xwxx) SHADER_SWIZZLE_OP (1412, xwxy) SHADER_SWIZZLE_OP (1413, xwxz) SHADER_SWIZZLE_OP (1414, xwxw) SHADER_SWIZZLE_OP (142 , xwy ) SHADER_SWIZZLE_OP (1421, xwyx) SHADER_SWIZZLE_OP (1422, xwyy) SHADER_SWIZZLE_OP (1423, xwyz) SHADER_SWIZZLE_OP (1424, xwyw) SHADER_SWIZZLE_OP (143 , xwz ) SHADER_SWIZZLE_OP (1431, xwzx) SHADER_SWIZZLE_OP (1432, xwzy) SHADER_SWIZZLE_OP (1433, xwzz) SHADER_SWIZZLE_OP (1434, xwzw) SHADER_SWIZZLE_OP (144 , xww ) SHADER_SWIZZLE_OP (1441, xwwx) SHADER_SWIZZLE_OP (1442, xwwy) SHADER_SWIZZLE_OP (1443, xwwz) SHADER_SWIZZLE_OP (1444, xwww) SHADER_SWIZZLE_OP (2 , y ) SHADER_SWIZZLE_OP (21 , yx ) SHADER_SWIZZLE_OP (211 , yxx ) SHADER_SWIZZLE_OP (2111, yxxx) SHADER_SWIZZLE_OP (2112, yxxy) SHADER_SWIZZLE_OP (2113, yxxz) SHADER_SWIZZLE_OP (2114, yxxw) SHADER_SWIZZLE_OP (212 , yxy ) SHADER_SWIZZLE_OP (2121, yxyx) SHADER_SWIZZLE_OP (2122, yxyy) SHADER_SWIZZLE_OP (2123, yxyz) SHADER_SWIZZLE_OP (2124, yxyw) SHADER_SWIZZLE_OP (213 , yxz ) SHADER_SWIZZLE_OP (2131, yxzx) SHADER_SWIZZLE_OP (2132, yxzy) SHADER_SWIZZLE_OP (2133, yxzz) SHADER_SWIZZLE_OP (2134, yxzw) SHADER_SWIZZLE_OP (214 , yxw ) SHADER_SWIZZLE_OP (2141, yxwx) SHADER_SWIZZLE_OP (2142, yxwy) SHADER_SWIZZLE_OP (2143, yxwz) SHADER_SWIZZLE_OP (2144, yxww) SHADER_SWIZZLE_OP (22 , yy ) SHADER_SWIZZLE_OP (221 , yyx ) SHADER_SWIZZLE_OP (2211, yyxx) SHADER_SWIZZLE_OP (2212, yyxy) SHADER_SWIZZLE_OP (2213, yyxz) SHADER_SWIZZLE_OP (2214, yyxw) SHADER_SWIZZLE_OP (222 , yyy ) SHADER_SWIZZLE_OP (2221, yyyx) SHADER_SWIZZLE_OP (2222, yyyy) SHADER_SWIZZLE_OP (2223, yyyz) SHADER_SWIZZLE_OP (2224, yyyw) SHADER_SWIZZLE_OP (223 , yyz ) SHADER_SWIZZLE_OP (2231, yyzx) SHADER_SWIZZLE_OP (2232, yyzy) SHADER_SWIZZLE_OP (2233, yyzz) SHADER_SWIZZLE_OP (2234, yyzw) SHADER_SWIZZLE_OP (224 , yyw ) SHADER_SWIZZLE_OP (2241, yywx) SHADER_SWIZZLE_OP (2242, yywy) SHADER_SWIZZLE_OP (2243, yywz) SHADER_SWIZZLE_OP (2244, yyww) SHADER_SWIZZLE_OP (23 , yz ) SHADER_SWIZZLE_OP (231 , yzx ) SHADER_SWIZZLE_OP (2311, yzxx) SHADER_SWIZZLE_OP (2312, yzxy) SHADER_SWIZZLE_OP (2313, yzxz) SHADER_SWIZZLE_OP (2314, yzxw) SHADER_SWIZZLE_OP (232 , yzy ) SHADER_SWIZZLE_OP (2321, yzyx) SHADER_SWIZZLE_OP (2322, yzyy) SHADER_SWIZZLE_OP (2323, yzyz) SHADER_SWIZZLE_OP (2324, yzyw) SHADER_SWIZZLE_OP (233 , yzz ) SHADER_SWIZZLE_OP (2331, yzzx) SHADER_SWIZZLE_OP (2332, yzzy) SHADER_SWIZZLE_OP (2333, yzzz) SHADER_SWIZZLE_OP (2334, yzzw) SHADER_SWIZZLE_OP (234 , yzw ) SHADER_SWIZZLE_OP (2341, yzwx) SHADER_SWIZZLE_OP (2342, yzwy) SHADER_SWIZZLE_OP (2343, yzwz) SHADER_SWIZZLE_OP (2344, yzww) SHADER_SWIZZLE_OP (24 , yw ) SHADER_SWIZZLE_OP (241 , ywx ) SHADER_SWIZZLE_OP (2411, ywxx) SHADER_SWIZZLE_OP (2412, ywxy) SHADER_SWIZZLE_OP (2413, ywxz) SHADER_SWIZZLE_OP (2414, ywxw) SHADER_SWIZZLE_OP (242 , ywy ) SHADER_SWIZZLE_OP (2421, ywyx) SHADER_SWIZZLE_OP (2422, ywyy) SHADER_SWIZZLE_OP (2423, ywyz) SHADER_SWIZZLE_OP (2424, ywyw) SHADER_SWIZZLE_OP (243 , ywz ) SHADER_SWIZZLE_OP (2431, ywzx) SHADER_SWIZZLE_OP (2432, ywzy) SHADER_SWIZZLE_OP (2433, ywzz) SHADER_SWIZZLE_OP (2434, ywzw) SHADER_SWIZZLE_OP (244 , yww ) SHADER_SWIZZLE_OP (2441, ywwx) SHADER_SWIZZLE_OP (2442, ywwy) SHADER_SWIZZLE_OP (2443, ywwz) SHADER_SWIZZLE_OP (2444, ywww) SHADER_SWIZZLE_OP (3 , z ) SHADER_SWIZZLE_OP (31 , zx ) SHADER_SWIZZLE_OP (311 , zxx ) SHADER_SWIZZLE_OP (3111, zxxx) SHADER_SWIZZLE_OP (3112, zxxy) SHADER_SWIZZLE_OP (3113, zxxz) SHADER_SWIZZLE_OP (3114, zxxw) SHADER_SWIZZLE_OP (312 , zxy ) SHADER_SWIZZLE_OP (3121, zxyx) SHADER_SWIZZLE_OP (3122, zxyy) SHADER_SWIZZLE_OP (3123, zxyz) SHADER_SWIZZLE_OP (3124, zxyw) SHADER_SWIZZLE_OP (313 , zxz ) SHADER_SWIZZLE_OP (3131, zxzx) SHADER_SWIZZLE_OP (3132, zxzy) SHADER_SWIZZLE_OP (3133, zxzz) SHADER_SWIZZLE_OP (3134, zxzw) SHADER_SWIZZLE_OP (314 , zxw ) SHADER_SWIZZLE_OP (3141, zxwx) SHADER_SWIZZLE_OP (3142, zxwy) SHADER_SWIZZLE_OP (3143, zxwz) SHADER_SWIZZLE_OP (3144, zxww) SHADER_SWIZZLE_OP (32 , zy ) SHADER_SWIZZLE_OP (321 , zyx ) SHADER_SWIZZLE_OP (3211, zyxx) SHADER_SWIZZLE_OP (3212, zyxy) SHADER_SWIZZLE_OP (3213, zyxz) SHADER_SWIZZLE_OP (3214, zyxw) SHADER_SWIZZLE_OP (322 , zyy ) SHADER_SWIZZLE_OP (3221, zyyx) SHADER_SWIZZLE_OP (3222, zyyy) SHADER_SWIZZLE_OP (3223, zyyz) SHADER_SWIZZLE_OP (3224, zyyw) SHADER_SWIZZLE_OP (323 , zyz ) SHADER_SWIZZLE_OP (3231, zyzx) SHADER_SWIZZLE_OP (3232, zyzy) SHADER_SWIZZLE_OP (3233, zyzz) SHADER_SWIZZLE_OP (3234, zyzw) SHADER_SWIZZLE_OP (324 , zyw ) SHADER_SWIZZLE_OP (3241, zywx) SHADER_SWIZZLE_OP (3242, zywy) SHADER_SWIZZLE_OP (3243, zywz) SHADER_SWIZZLE_OP (3244, zyww) SHADER_SWIZZLE_OP (33 , zz ) SHADER_SWIZZLE_OP (331 , zzx ) SHADER_SWIZZLE_OP (3311, zzxx) SHADER_SWIZZLE_OP (3312, zzxy) SHADER_SWIZZLE_OP (3313, zzxz) SHADER_SWIZZLE_OP (3314, zzxw) SHADER_SWIZZLE_OP (332 , zzy ) SHADER_SWIZZLE_OP (3321, zzyx) SHADER_SWIZZLE_OP (3322, zzyy) SHADER_SWIZZLE_OP (3323, zzyz) SHADER_SWIZZLE_OP (3324, zzyw) SHADER_SWIZZLE_OP (333 , zzz ) SHADER_SWIZZLE_OP (3331, zzzx) SHADER_SWIZZLE_OP (3332, zzzy) SHADER_SWIZZLE_OP (3333, zzzz) SHADER_SWIZZLE_OP (3334, zzzw) SHADER_SWIZZLE_OP (334 , zzw ) SHADER_SWIZZLE_OP (3341, zzwx) SHADER_SWIZZLE_OP (3342, zzwy) SHADER_SWIZZLE_OP (3343, zzwz) SHADER_SWIZZLE_OP (3344, zzww) SHADER_SWIZZLE_OP (34 , zw ) SHADER_SWIZZLE_OP (341 , zwx ) SHADER_SWIZZLE_OP (3411, zwxx) SHADER_SWIZZLE_OP (3412, zwxy) SHADER_SWIZZLE_OP (3413, zwxz) SHADER_SWIZZLE_OP (3414, zwxw) SHADER_SWIZZLE_OP (342 , zwy ) SHADER_SWIZZLE_OP (3421, zwyx) SHADER_SWIZZLE_OP (3422, zwyy) SHADER_SWIZZLE_OP (3423, zwyz) SHADER_SWIZZLE_OP (3424, zwyw) SHADER_SWIZZLE_OP (343 , zwz ) SHADER_SWIZZLE_OP (3431, zwzx) SHADER_SWIZZLE_OP (3432, zwzy) SHADER_SWIZZLE_OP (3433, zwzz) SHADER_SWIZZLE_OP (3434, zwzw) SHADER_SWIZZLE_OP (344 , zww ) SHADER_SWIZZLE_OP (3441, zwwx) SHADER_SWIZZLE_OP (3442, zwwy) SHADER_SWIZZLE_OP (3443, zwwz) SHADER_SWIZZLE_OP (3444, zwww) SHADER_SWIZZLE_OP (4 , w ) SHADER_SWIZZLE_OP (41 , wx ) SHADER_SWIZZLE_OP (411 , wxx ) SHADER_SWIZZLE_OP (4111, wxxx) SHADER_SWIZZLE_OP (4112, wxxy) SHADER_SWIZZLE_OP (4113, wxxz) SHADER_SWIZZLE_OP (4114, wxxw) SHADER_SWIZZLE_OP (412 , wxy ) SHADER_SWIZZLE_OP (4121, wxyx) SHADER_SWIZZLE_OP (4122, wxyy) SHADER_SWIZZLE_OP (4123, wxyz) SHADER_SWIZZLE_OP (4124, wxyw) SHADER_SWIZZLE_OP (413 , wxz ) SHADER_SWIZZLE_OP (4131, wxzx) SHADER_SWIZZLE_OP (4132, wxzy) SHADER_SWIZZLE_OP (4133, wxzz) SHADER_SWIZZLE_OP (4134, wxzw) SHADER_SWIZZLE_OP (414 , wxw ) SHADER_SWIZZLE_OP (4141, wxwx) SHADER_SWIZZLE_OP (4142, wxwy) SHADER_SWIZZLE_OP (4143, wxwz) SHADER_SWIZZLE_OP (4144, wxww) SHADER_SWIZZLE_OP (42 , wy ) SHADER_SWIZZLE_OP (421 , wyx ) SHADER_SWIZZLE_OP (4211, wyxx) SHADER_SWIZZLE_OP (4212, wyxy) SHADER_SWIZZLE_OP (4213, wyxz) SHADER_SWIZZLE_OP (4214, wyxw) SHADER_SWIZZLE_OP (422 , wyy ) SHADER_SWIZZLE_OP (4221, wyyx) SHADER_SWIZZLE_OP (4222, wyyy) SHADER_SWIZZLE_OP (4223, wyyz) SHADER_SWIZZLE_OP (4224, wyyw) SHADER_SWIZZLE_OP (423 , wyz ) SHADER_SWIZZLE_OP (4231, wyzx) SHADER_SWIZZLE_OP (4232, wyzy) SHADER_SWIZZLE_OP (4233, wyzz) SHADER_SWIZZLE_OP (4234, wyzw) SHADER_SWIZZLE_OP (424 , wyw ) SHADER_SWIZZLE_OP (4241, wywx) SHADER_SWIZZLE_OP (4242, wywy) SHADER_SWIZZLE_OP (4243, wywz) SHADER_SWIZZLE_OP (4244, wyww) SHADER_SWIZZLE_OP (43 , wz ) SHADER_SWIZZLE_OP (431 , wzx ) SHADER_SWIZZLE_OP (4311, wzxx) SHADER_SWIZZLE_OP (4312, wzxy) SHADER_SWIZZLE_OP (4313, wzxz) SHADER_SWIZZLE_OP (4314, wzxw) SHADER_SWIZZLE_OP (432 , wzy ) SHADER_SWIZZLE_OP (4321, wzyx) SHADER_SWIZZLE_OP (4322, wzyy) SHADER_SWIZZLE_OP (4323, wzyz) SHADER_SWIZZLE_OP (4324, wzyw) SHADER_SWIZZLE_OP (433 , wzz ) SHADER_SWIZZLE_OP (4331, wzzx) SHADER_SWIZZLE_OP (4332, wzzy) SHADER_SWIZZLE_OP (4333, wzzz) SHADER_SWIZZLE_OP (4334, wzzw) SHADER_SWIZZLE_OP (434 , wzw ) SHADER_SWIZZLE_OP (4341, wzwx) SHADER_SWIZZLE_OP (4342, wzwy) SHADER_SWIZZLE_OP (4343, wzwz) SHADER_SWIZZLE_OP (4344, wzww) SHADER_SWIZZLE_OP (44 , ww ) SHADER_SWIZZLE_OP (441 , wwx ) SHADER_SWIZZLE_OP (4411, wwxx) SHADER_SWIZZLE_OP (4412, wwxy) SHADER_SWIZZLE_OP (4413, wwxz) SHADER_SWIZZLE_OP (4414, wwxw) SHADER_SWIZZLE_OP (442 , wwy ) SHADER_SWIZZLE_OP (4421, wwyx) SHADER_SWIZZLE_OP (4422, wwyy) SHADER_SWIZZLE_OP (4423, wwyz) SHADER_SWIZZLE_OP (4424, wwyw) SHADER_SWIZZLE_OP (443 , wwz ) SHADER_SWIZZLE_OP (4431, wwzx) SHADER_SWIZZLE_OP (4432, wwzy) SHADER_SWIZZLE_OP (4433, wwzz) SHADER_SWIZZLE_OP (4434, wwzw) SHADER_SWIZZLE_OP (444 , www ) SHADER_SWIZZLE_OP (4441, wwwx) SHADER_SWIZZLE_OP (4442, wwwy) SHADER_SWIZZLE_OP (4443, wwwz) SHADER_SWIZZLE_OP (4444, wwww) # undef SHADER_SWIZZLE_OP # define SHADER_FUNC0_(name, glname) \ template \ inline const sl_expr \ name () \ { \ return sl_func0 (#glname " ("); \ } # define SHADER_FUNC0(name) SHADER_FUNC0_(name,name) # define SHADER_FUNC1_(name, glname) \ template \ inline const sl_expr< sl_func1::T> > \ name (const A &a) \ { \ return sl_func1::T> (#glname " (", sl_convert::convert (a));\ } # define SHADER_FUNC1(name) SHADER_FUNC1_(name,name) # define SHADER_FUNC2_(name, glname) \ template \ inline const sl_expr< sl_func2::T, typename sl_convert::T> > \ name (const A &a, const B &b) \ { \ return sl_func2::T, typename sl_convert::T> (#glname " (", sl_convert::convert (a), sl_convert::convert (b));\ } # define SHADER_FUNC2(name) SHADER_FUNC2_(name,name) # define SHADER_FUNC3_(name, glname) \ template \ inline const sl_expr< sl_func3::T, typename sl_convert::T, typename sl_convert::T> > \ name (const A &a, const B &b, const C &c) \ { \ return sl_func3::T, typename sl_convert::T, typename sl_convert::T> (#glname " (", sl_convert::convert (a), sl_convert::convert (b), sl_convert::convert (c));\ } # define SHADER_FUNC3(name) SHADER_FUNC3_(name,name) # define SHADER_FUNC4_(name, glname) \ template \ inline const sl_expr< sl_func4::T, typename sl_convert::T, typename sl_convert::T, typename sl_convert::T > > \ name (const A &a, const B &b, const C &c, const D &d) \ { \ return sl_func4::T, typename sl_convert::T, typename sl_convert::T, typename sl_convert::T> (#glname " (", sl_convert::convert (a), sl_convert::convert (b), sl_convert::convert (c), sl_convert::convert (d));\ } # define SHADER_FUNC4(name) SHADER_FUNC4_(name,name) SHADER_FUNC1 (abs) SHADER_FUNC1 (acos) SHADER_FUNC1 (all) SHADER_FUNC1 (any) SHADER_FUNC1 (asin) SHADER_FUNC1 (atan) SHADER_FUNC2 (atan) SHADER_FUNC1 (ceil) SHADER_FUNC3 (clamp) SHADER_FUNC1 (cos) SHADER_FUNC2 (cross) SHADER_FUNC1 (dFdx) SHADER_FUNC1 (dFdy) SHADER_FUNC1 (degrees) SHADER_FUNC2 (distance) SHADER_FUNC2 (dot) SHADER_FUNC2_(equal, equal) SHADER_FUNC1 (exp) SHADER_FUNC1 (exp2) SHADER_FUNC3 (faceforward) SHADER_FUNC1 (floor) SHADER_FUNC1 (fract) SHADER_FUNC0 (ftransform) SHADER_FUNC1 (fwidth) SHADER_FUNC2_(greater_than_equal, greaterThanEqual) SHADER_FUNC2_(greater_then, greaterThan) SHADER_FUNC1 (inversesqrt) SHADER_FUNC1 (length) SHADER_FUNC2_(less_than, lessThan) SHADER_FUNC2_(less_than_equal, lessThanEqual) SHADER_FUNC1 (log) SHADER_FUNC1 (log2) SHADER_FUNC2_(matrix_comp_mult, matrixCompMult) SHADER_FUNC2 (max) SHADER_FUNC2 (min) SHADER_FUNC3 (mix) SHADER_FUNC2 (mod) SHADER_FUNC1 (noise1) SHADER_FUNC1 (noise2) SHADER_FUNC1 (noise3) SHADER_FUNC1 (noise4) SHADER_FUNC1 (normalize) SHADER_FUNC1 (gl_not) // TODO SHADER_FUNC2_(notequal, notEqual) SHADER_FUNC2 (pow) SHADER_FUNC1 (radians) SHADER_FUNC2 (reflect) SHADER_FUNC3 (refract) SHADER_FUNC2_(shadow_1d, shadow1D) SHADER_FUNC3_(shadow_1d, shadow1D) SHADER_FUNC3_(shadow_1d_lod, shadow1DLod) SHADER_FUNC2_(shadow_1d_proj, shadow1DProj) SHADER_FUNC3_(shadow_1d_proj, shadow1DProj) SHADER_FUNC3_(shadow_1d_proj_lod, shadow1DProjLod) SHADER_FUNC2_(shadow_2d, shadow2D) SHADER_FUNC3_(shadow_2d, shadow2D) SHADER_FUNC3_(shadow_2d_lod, shadow2DLod) SHADER_FUNC2_(shadow_2d_proj, shadow2DProj) SHADER_FUNC3_(shadow_2d_proj, shadow2DProj) SHADER_FUNC3_(shadow_2d_proj_lod, shadow2DProjLod) SHADER_FUNC1 (sign) SHADER_FUNC1 (sin) SHADER_FUNC3 (smoothstep) SHADER_FUNC1 (sqrt) SHADER_FUNC2 (step) SHADER_FUNC1 (tan) SHADER_FUNC2_(texture_1d, texture1D) SHADER_FUNC3_(texture_1d, texture1D) SHADER_FUNC3_(texture_1d_lod, texture1DLod) SHADER_FUNC2_(texture_1d_proj, texture1DProj) SHADER_FUNC3_(texture_1d_proj, texture1DProj) SHADER_FUNC3_(texture_1d_proj_lod, texture1DProjLod) SHADER_FUNC2_(texture_2d, texture2D) SHADER_FUNC3_(texture_2d, texture2D) SHADER_FUNC3_(texture_2d_lod, texture2DLod) SHADER_FUNC2_(texture_2d_proj, texture2DProj) SHADER_FUNC3_(texture_2d_proj, texture2DProj) SHADER_FUNC3_(texture_2d_proj_lod, texture2DProjLod) SHADER_FUNC2_(texture_3d, texture3D) SHADER_FUNC3_(texture_3d, texture3D) SHADER_FUNC3_(texture_3d_lod, texture3DLod) SHADER_FUNC2_(texture_3d_proj, texture3DProj) SHADER_FUNC3_(texture_3d_proj, texture3DProj) SHADER_FUNC3_(texture_3d_proj_lod, texture3DProjLod) SHADER_FUNC2_(texture_cube, textureCube) SHADER_FUNC3_(texture_cube, textureCube) SHADER_FUNC3_(texture_cude_lod, textureCubeLod) SHADER_FUNC1 (vec2) SHADER_FUNC2 (vec2) SHADER_FUNC1 (vec3) SHADER_FUNC2 (vec3) SHADER_FUNC3 (vec3) SHADER_FUNC1 (vec4) SHADER_FUNC2 (vec4) SHADER_FUNC3 (vec4) SHADER_FUNC4 (vec4) SHADER_FUNC1 (mat2) SHADER_FUNC2 (mat2) SHADER_FUNC1 (mat3) SHADER_FUNC2 (mat3) SHADER_FUNC3 (mat3) SHADER_FUNC1 (mat4) SHADER_FUNC2 (mat4) SHADER_FUNC3 (mat4) SHADER_FUNC4 (mat4) # undef SHADER_FUNC0 # undef SHADER_FUNC0_ # undef SHADER_FUNC1 # undef SHADER_FUNC1_ # undef SHADER_FUNC2 # undef SHADER_FUNC2_ # undef SHADER_FUNC3 # undef SHADER_FUNC3_ # undef SHADER_FUNC4 # undef SHADER_FUNC5_ void debdebdebdebug ();//D } #endif