Ejemplo n.º 1
0
 protected virtual void SetupUniforms(IEnumerable <Uniform> uniforms)
 {
     foreach (var uniform in uniforms)
     {
         var loc  = GL.GetUniformLocation(PgmId, uniform.Name);
         var val  = uniform.GetValue();
         var type = val.GetType();
         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
         {
             throw new ArgumentException($"Unsupported uniform type: {type}");
         }
     }
 }
        public void SetVectorArrayParameter(string name, int index, Vector3 vector, string shader)
        {
            GL.UseProgram(_shaderHandleDictionary[shader]);
            int location = GL.GetUniformLocation(_shaderHandleDictionary[shader], name + "[" + index + "]");

            if (location != -1)
            {
                GL.Uniform3(location, vector);
            }
        }
        public void SetNumericParameter(string name, float number, string shader)
        {
            GL.UseProgram(_shaderHandleDictionary[shader]);
            int location = GL.GetUniformLocation(_shaderHandleDictionary[shader], name);

            if (location != -1)
            {
                GL.Uniform1(location, number);
            }
        }
        public void SetMatrixParameter(string name, Matrix4 matrix, string shader)
        {
            GL.UseProgram(_shaderHandleDictionary[shader]);
            int location = GL.GetUniformLocation(_shaderHandleDictionary[shader], name);

            if (location != -1)
            {
                GL.UniformMatrix4(location, false, ref matrix);
            }
        }
 public void SetNumericParameter(string name, float number)
 {
     foreach (var shaderHandle in _shaderHandleDictionary.Values)
     {
         GL.UseProgram(shaderHandle);
         int location = GL.GetUniformLocation(shaderHandle, name);
         if (location != -1)
         {
             GL.Uniform1(location, number);
         }
     }
 }
 public void SetVectorArrayParameter(string name, int index, Vector3 vector)
 {
     foreach (var shaderHandle in _shaderHandleDictionary.Values)
     {
         GL.UseProgram(shaderHandle);
         int location = GL.GetUniformLocation(shaderHandle, name + "[" + index + "]");
         if (location != -1)
         {
             GL.Uniform3(location, vector);
         }
     }
 }
 public void SetMatrixParameter(string name, Matrix4 matrix)
 {
     foreach (var shaderHandle in _shaderHandleDictionary.Values)
     {
         GL.UseProgram(shaderHandle);
         int location = GL.GetUniformLocation(shaderHandle, name);
         if (location != -1)
         {
             GL.UniformMatrix4(location, false, ref matrix);
         }
     }
 }
        public void UseTexture(string textureName, string shader, string uniformName)
        {
            if (!_textureHandleDictionary.ContainsKey(textureName))
            {
                throw new ApplicationException("Texture has to be added before using");
            }
            GL.UseProgram(_shaderHandleDictionary[shader]);
            var textureInfo = _textureHandleDictionary[textureName];

            GL.ActiveTexture(TextureUnit.Texture0 + textureInfo.Unit);
            GL.BindTexture(TextureTarget.Texture2D, textureInfo.Handle);
            int location = GL.GetUniformLocation(_shaderHandleDictionary[shader], uniformName);

            if (location != -1)
            {
                int textureUnitIndex = textureInfo.Unit;
                GL.Uniform1(location, textureUnitIndex);
            }
        }