Example #1
0
        /// <summary>
        /// Specify values for matrix array uniform.
        /// </summary>
        /// <param name="name">The name of uniform variable in GLSL.</param>
        /// <param name="matrix">The array of matrix values.</param>
        public void SetUniformArray(string name, float[][] matrix)
        {
            int matrixSize = 0;

            if (matrix.Length == 3 * 3)
            {
                matrixSize = 3 * 3;
            }
            else if (matrix.Length == 4 * 4)
            {
                matrixSize = 4 * 4;
            }
            else
            {
                throw new ArgumentException("Matrix data must either 3x3 (9 elements) or 4x4 (16 elements).");
            }

            float[] contiguous = new float[matrixSize * matrix.Length];
            for (int i = 0; i < matrix.Length; ++i)
            {
                Array.Copy(matrix[i], 0, contiguous, matrixSize * i, matrixSize);
            }

            using (var binder = new UniformBinder(this, name))
            {
                if (binder.Location != -1)
                {
                    GLChecker.Check(() => GL.Uniform2(binder.Location, contiguous.Length, contiguous));
                }
            }
        }
Example #2
0
 /// <summary>
 /// Specify values for array uniform.
 /// </summary>
 /// <param name="name">The name of the uniform variable in GLSL.</param>
 /// <param name="scalarArray">The array of float values.</param>
 public void SetUniformArray(string name, float[] scalarArray)
 {
     using (var binder = new UniformBinder(this, name))
     {
         if (binder.Location != -1)
         {
             GLChecker.Check(() => GL.Uniform1(binder.Location, scalarArray.Length, scalarArray));
         }
     }
 }
Example #3
0
 /// <summary>
 /// Specify value for four component uniform.
 /// </summary>
 /// <param name="name">The name of uniform variable in GLSL.</param>
 /// <param name="vector">Value of the scalar.</param>
 public void SetUniform(string name, Vector4 <double> vector)
 {
     using (var binder = new UniformBinder(this, name))
     {
         if (binder.Location != -1)
         {
             GLChecker.Check(() => GL.Uniform4(binder.Location, vector.X, vector.Y, vector.Z, vector.W));
         }
     }
 }
Example #4
0
 /// <summary>
 /// Specify value for one component uniform.
 /// </summary>
 /// <param name="name">The name of uniform variable in GLSL.</param>
 /// <param name="x">Value of the scalar.</param>
 public void SetUniform(string name, double x)
 {
     using (var binder = new UniformBinder(this, name))
     {
         if (binder.Location != -1)
         {
             GLChecker.Check(() => GL.Uniform1(binder.Location, x));
         }
     }
 }
Example #5
0
 /// <summary>
 /// Specify values for array uniform.
 /// </summary>
 /// <param name="name">The name of uniform variable in GLSL.</param>
 /// <param name="vector">Value of the scalar.</param>
 public void SetUniformArray(string name, Vector4 <double>[] vector)
 {
     using (var binder = new UniformBinder(this, name))
     {
         if (binder.Location != -1)
         {
             double[] contiguous = vector.Flatten();
             GLChecker.Check(() => GL.Uniform2(binder.Location, contiguous.Length, contiguous));
         }
     }
 }
Example #6
0
 /// <summary>
 /// Specify value for matrix uniform.
 /// </summary>
 /// <param name="name">The name of uniform variable in GLSL.</param>
 /// <param name="matrix">Value of the scalar.</param>
 public void SetUniform(string name, float[] matrix)
 {
     using (var binder = new UniformBinder(this, name))
     {
         if (binder.Location != -1)
         {
             if (matrix.Length == 9)
             {
                 GLChecker.Check(() => GL.UniformMatrix3(binder.Location, 1, false, matrix));
             }
             else if (matrix.Length == 16)
             {
                 GLChecker.Check(() => GL.UniformMatrix4(binder.Location, 1, true, matrix));
             }
             else
             {
                 throw new ArgumentException("Matrix data must either 3x3 (9 elements) or 4x4 (16 elements).");
             }
         }
     }
 }