Ejemplo n.º 1
0
 public ShaderProgram(string fProg, string vProg)
 {
     _fProg   = fProg;
     _vProg   = vProg;
     CacheLoc = new Dictionary <string, int>();
     Uniforms = new UniformCollection();
     PgmId    = GL.CreateProgram();
     Init();
 }
Ejemplo n.º 2
0
 protected virtual void SetupUniforms(UniformCollection uniforms)
 {
     foreach (var uniform in uniforms)
     {
         var loc  = GetCachedUniformLoc(uniform.Name);
         var val  = uniform.GetValue();
         var type = uniform.UniformType;
         if (type == typeof(float))
         {
             GL.Uniform1(loc, (float)val);
         }
         else if (type == typeof(double))
         {
             GL.Uniform1(loc, (double)val);
         }
         else if (type == typeof(int))
         {
             GL.Uniform1(loc, (int)val);
         }
         else if (type == typeof(uint))
         {
             GL.Uniform1(loc, (uint)val);
         }
         else if (type == typeof(Vector2))
         {
             var vec2 = (Vector2)val;
             GL.Uniform2(loc, vec2.X, vec2.Y);
         }
         else if (type == typeof(Vector3))
         {
             var vec3 = (Vector3)val;
             GL.Uniform3(loc, vec3.X, vec3.Y, vec3.Z);
         }
         else if (type == typeof(Matrix4))
         {
             var mat4 = (Matrix4)val;
             GL.UniformMatrix4(loc, false, ref mat4);
         }
         else
         {
             throw new ArgumentException($"Unsupported uniform type: {type} (\"{uniform.Name}\")");
         }
     }
 }
Ejemplo n.º 3
0
 public void Use(UniformCollection uniforms)
 {
     Use();
     SetupUniforms(uniforms);
 }