Aiv.Fast2D.Shader.Shader C# (CSharp) Метод

Shader() публичный Метод

public Shader ( string vertexModern, string fragmentModern, string vertexObsolete = null, string fragmentObsolete = null, string attribs = null ) : OpenTK.Graphics.OpenGL
vertexModern string
fragmentModern string
vertexObsolete string
fragmentObsolete string
attribs string
Результат OpenTK.Graphics.OpenGL
        public Shader(string vertexModern, string fragmentModern, string vertexObsolete = null, string fragmentObsolete = null, string[] attribs = null)
        {
            string vertex = vertexModern;
            string fragment = fragmentModern;

            if (Window.IsObsolete)
            {
                if (vertexObsolete == null || fragmentObsolete == null || attribs == null)
                {
                    throw new UnsupportedVersionException("Unsupported OpenGL version for this shader");
                }
                vertex = vertexObsolete;
                fragment = fragmentObsolete;
            #if !__MOBILE__
                // obsolete Desktop OpenGL does not have medium precision
                fragment = fragment.Replace("precision mediump float;", "");
            #endif
            }
            #if __MOBILE__
            vertex = vertex.Trim(new char[] { '\r', '\n' }).Replace("330 core", "300 es");
            fragment = fragment.Trim(new char[] { '\r', '\n' }).Replace("330 core", "300 es");
            #endif
            int vertexShaderId = GL.CreateShader(ShaderType.VertexShader);
            int fragmentShaderId = GL.CreateShader(ShaderType.FragmentShader);

            GL.ShaderSource(vertexShaderId, vertex);
            GL.CompileShader(vertexShaderId);

            string vertexShaderCompilationError = GL.GetShaderInfoLog(vertexShaderId);
            if (vertexShaderCompilationError != null && vertexShaderCompilationError != "")
            {
                throw new CompilationException(vertexShaderCompilationError);
            }

            GL.ShaderSource(fragmentShaderId, fragment);
            GL.CompileShader(fragmentShaderId);
            string fragmentShaderCompilationError = GL.GetShaderInfoLog(fragmentShaderId);
            if (fragmentShaderCompilationError != null && fragmentShaderCompilationError != "")
            {
                throw new CompilationException(fragmentShaderCompilationError);
            }

            this.programId = GL.CreateProgram();
            GL.AttachShader(programId, vertexShaderId);
            GL.AttachShader(programId, fragmentShaderId);

            if (Window.IsObsolete)
            {
                if (attribs != null)
                {
                    for (int i = 0; i < attribs.Length; i++)
                    {
                        GL.BindAttribLocation(programId, i, attribs[i]);
                    }
                }
            }

            GL.LinkProgram(programId);

            GL.DetachShader(programId, vertexShaderId);
            GL.DetachShader(programId, fragmentShaderId);

            GL.DeleteShader(vertexShaderId);
            GL.DeleteShader(fragmentShaderId);

            this.uniformCache = new Dictionary<string, int>();
        }