Esempio n. 1
0
        public object Compile(Shader s, ShaderType type, SourceDescription source)
        {
            var src = source.ToGlsl(type);

            int shader;

            switch (type)
            {
            case ShaderType.FragmentShader:
                shader = GL.CreateShader(global::OpenTK.Graphics.OpenGL.ShaderType.FragmentShader);
                break;

            case ShaderType.VertexShader:
                shader = GL.CreateShader(global::OpenTK.Graphics.OpenGL.ShaderType.VertexShader);
                break;

            default:
                throw new SLSharpException("Binding does not support " + type);
            }

            Utilities.CheckGL();

            GL.ShaderSource(shader, src);
            GL.CompileShader(shader);
            int compileResult;

            GL.GetShader(shader, ShaderParameter.CompileStatus, out compileResult);
            string info;

            GL.GetShaderInfoLog(shader, out info);

            if (compileResult != 1)
            {
                //Dump(type, src);
                throw new SLSharpException("Shader compilation failed: " + info);
            }

            if (info != string.Empty)
            {
                Console.WriteLine(info);
            }

            return(new Tuple <int, SourceDescription>(shader, source));
        }