Zoadian

sendUniform

Jul 1st, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.61 KB | None | 0 0
  1.     /// send Uniform
  2.     void sendUniform(T)(int position, T t) {
  3.         assert(this.isAttached, "cannot send uniform, shader not attached");
  4.         static if(isFloatingPoint!T) {
  5.             glUniform1f(position, t);
  6.         }
  7.         else static if(isIntegral!T) {
  8.             glUniform1i(position, t);
  9.         }
  10.         else static if(isVector!T && isFloatingPoint!(T.vt)) {
  11.             mixin("glUniform"~to!string(T.dimension)~"fv(position, 1, t.value_ptr);");
  12.         }
  13.         else static if(isVector!T && isIntegral!(T.vt)) {
  14.             mixin("glUniform"~to!string(T.dimension)~"iv(position, 1, t.value_ptr);");
  15.         }
  16.         else static if(isMatrix!T && isNumeric!(T.mt) && T.cols >= 2 && T.cols <= 4 && T.rows >= 2 && T.rows <= 4) {
  17.             static if(isFloatingPoint!(T.mt)) {
  18.                 static if(T.cols != T.rows)
  19.                     mixin("glUniformMatrix"~to!string(T.cols)~"x"~to!string(T.rows)~"fv(position, 1, false, t.value_ptr);");
  20.                 else
  21.                     mixin("glUniformMatrix"~to!string(T.cols)~"fv(position, 1, false, t.value_ptr);");
  22.             }
  23.             else static if(isIntegral!(T.mt)) {
  24.                 static if(T.cols != T.rows)
  25.                     mixin("glUniformMatrix"~to!string(T.cols)~"x"~to!string(T.rows)~"fi(position, 1, false, t.value_ptr);");
  26.                 else
  27.                     mixin("glUniformMatrix"~to!string(T.cols)~"fi(position, 1, false, t.value_ptr);");  
  28.             }
  29.         }
  30.         else
  31.         {
  32.             static assert(false, "Type "~T.stringof~" can not be sent via sendUniform");
  33.         }
  34.         glCheck();
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment