Пример #1
0
        private static Shader CompileFromShaders(IEnumerable <Step> shader_steps)
        {
            int id = GL.CreateProgram();

            foreach (var shader in shader_steps)
            {
                GL.AttachShader(id, shader.ResourceID);
            }

            GL.LinkProgram(id);

            foreach (var shader in shader_steps)
            {
                GL.DetachShader(id, shader.ResourceID);
            }

            string log = GL.GetProgramInfoLog(id);

            if (!string.IsNullOrWhiteSpace(log))
            {
                throw new Exception(log);
            }

            var model_id = new ShaderMatrix(GL.GetUniformLocation(id, "model_matrix"));
            int pos_id   = GL.GetAttribLocation(id, "position");
            int uv_id    = GL.GetAttribLocation(id, "vertexUV");
            int tex_id   = GL.GetUniformLocation(id, "texture");
            var proj_id  = new ShaderMatrix(GL.GetUniformLocation(id, "projection"));
            int z_id     = GL.GetUniformLocation(id, "z");
            var view_id  = new ShaderMatrix(GL.GetUniformLocation(id, "view"));
            var music    = new ShaderFloat(GL.GetUniformLocation(id, "music"));
            var uvo      = new ShaderMatrix(GL.GetUniformLocation(id, "uv_at"));

            return(new Shader(id, model_id, tex_id, pos_id, uv_id, proj_id, z_id, view_id, music, uvo));
        }
Пример #2
0
 public Shader(int shader_id,
               ShaderMatrix model_mat,
               int texture_location,
               int vertex_location,
               int uv_location,
               ShaderMatrix proj,
               int z_location,
               ShaderMatrix view,
               ShaderFloat music,
               ShaderMatrix uv_offset)
 {
     ShaderID        = shader_id;
     Model           = model_mat;
     TextureLocation = texture_location;
     VertexLocation  = vertex_location;
     UVLocation      = uv_location;
     Projection      = proj;
     ZLocation       = z_location;
     View            = view;
     Music           = music;
     UVOffset        = uv_offset;
 }
Пример #3
0
        /// <summary>
        /// Bind matrix to shader matrix
        /// </summary>
        /// <param name="nameInShader"></param>
        /// <param name="matrix"></param>
        public void SetMatrix4(ShaderMatrix nameInShader, ref Matrix4 matrix)
        {
            int location = GL.GetUniformLocation(Handle, nameInShader.ToString());

            GL.UniformMatrix4(location, true, ref matrix);
        }