//TODO: Maybe rewrite and document? /// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <param name="input"></param> public void SetAttribute <T>(String name, T input) { Int32 program = GL.GetUniformLocation(this.address, name); switch (typeof(T).Name) //hmm { case nameof(Int16): { Int16 output = (Int16)(Object)input; GL.Uniform1(program, output); break; } case nameof(Int32): { Int32 output = (Int32)(Object)input; GL.Uniform1(program, output); break; } case nameof(Int64): { Int64 output = (Int64)(Object)input; GL.Uniform1(program, output); break; } case nameof(Single): { Single output = (Single)(Object)input; GL.Uniform1(program, output); break; } case nameof(Double): { Double output = (Double)(Object)input; GL.Uniform1(program, output); break; } case nameof(OpenTK.Vector2): { OpenTK.Vector2 output = (OpenTK.Vector2)(Object) input; GL.Uniform2(program, ref output); break; } case nameof(OpenTK.Vector3): { OpenTK.Vector3 output = (OpenTK.Vector3)(Object) input; GL.Uniform3(program, ref output); break; } case nameof(OpenTK.Vector4): { OpenTK.Vector4 output = (OpenTK.Vector4)(Object) input; GL.Uniform4(program, ref output); break; } case nameof(OpenTK.Matrix2): { OpenTK.Matrix2 output = (OpenTK.Matrix2)(Object) input; GL.UniformMatrix2(program, false, ref output); break; } case nameof(OpenTK.Matrix3): { OpenTK.Matrix3 output = (OpenTK.Matrix3)(Object) input; GL.UniformMatrix3(program, false, ref output); break; } case nameof(OpenTK.Matrix4): { OpenTK.Matrix4 output = (OpenTK.Matrix4)(Object) input; GL.UniformMatrix4(program, false, ref output); break; } default: throw new Exception("Bad type providen"); } }
public override int Serialize(ref byte[] bytes, int offset, OpenTK.Matrix2 value) { BinaryUtil.WriteSingle(ref bytes, offset, value.M11); offset += Marshal.SizeOf(typeof(float)); BinaryUtil.WriteSingle(ref bytes, offset, value.M12); offset += Marshal.SizeOf(typeof(float)); BinaryUtil.WriteSingle(ref bytes, offset, value.M21); offset += Marshal.SizeOf(typeof(float)); BinaryUtil.WriteSingle(ref bytes, offset, value.M22); offset += Marshal.SizeOf(typeof(float)); return(OpenTK.Vector2.SizeInBytes * 2); }
public override OpenTK.Matrix2 Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize) { var result = new OpenTK.Matrix2(); result.M11 = BinaryUtil.ReadSingle(ref bytes, offset); offset += Marshal.SizeOf(typeof(float)); result.M12 = BinaryUtil.ReadSingle(ref bytes, offset); offset += Marshal.SizeOf(typeof(float)); result.M21 = BinaryUtil.ReadSingle(ref bytes, offset); offset += Marshal.SizeOf(typeof(float)); result.M22 = BinaryUtil.ReadSingle(ref bytes, offset); offset += Marshal.SizeOf(typeof(float)); byteSize = OpenTK.Vector2.SizeInBytes * 2; return(result); }