예제 #1
0
        public unsafe void Link(IEnumerable <Shader> shaderList)
        {
            var programId = Gl.CreateProgram();

            foreach (var sd in shaderList)
            {
                Gl.AttachShader(programId, sd.Raw());
            }
            Gl.LinkProgram(programId);
            int status;

            Gl.GetProgramiv(programId, Gl.LinkStatus, &status);
            if (status == 0)
            {
                int infoLogLength;
                Gl.GetProgramiv(programId, Gl.InfoLogLength, &infoLogLength);
                var strInfoLog = Marshal.AllocHGlobal(infoLogLength + 1);
                Gl.GetProgramInfoLog(programId, infoLogLength, null, (char *)strInfoLog);
                var infoLog = Gl.Utf8ToManaged(strInfoLog);
                Marshal.FreeHGlobal(strInfoLog);
                throw new Exception("Linker failure: " + infoLog);
            }

            _hdc = programId;
        }
예제 #2
0
        /// <summary>
        /// Links a vertex and fragment shader together to create a shader program.
        /// </summary>
        /// <param name="vertexShader">Specifies the vertex shader.</param>
        /// <param name="fragmentShader">Specifies the fragment shader.</param>
        public ShaderProgram(Shader vertexShader, Shader fragmentShader)
        {
            this.VertexShader    = vertexShader;
            this.FragmentShader  = fragmentShader;
            this.ProgramID       = Gl.CreateProgram();
            this.DisposeChildren = false;

            Gl.AttachShader(ProgramID, vertexShader.ShaderID);
            Gl.AttachShader(ProgramID, fragmentShader.ShaderID);
            Gl.LinkProgram(ProgramID);

            GetParams();
        }
예제 #3
0
        /// <summary>
        /// Links a vertex and fragment shader together to create a shader program.
        /// </summary>
        /// <param name="vertexShader">Specifies the vertex shader.</param>
        /// <param name="fragmentShader">Specifies the fragment shader.</param>
        public ShaderProgram(Shader vertexShader, Shader fragmentShader)
        {
            this.VertexShader    = vertexShader;
            this.FragmentShader  = fragmentShader;
            this.ProgramID       = Gl.CreateProgram();
            this.DisposeChildren = false;

            Gl.AttachShader(ProgramID, vertexShader.ShaderID);
            Gl.AttachShader(ProgramID, fragmentShader.ShaderID);
            Gl.LinkProgram(ProgramID);

            //Check whether the program linked successfully.
            //If not then throw an error with the linking error.
            if (!Gl.GetProgramLinkStatus(ProgramID))
            {
                throw new Exception(ProgramLog);
            }

            GetParams();
        }
예제 #4
0
 /// <summary>
 /// Create a ShaderProgram name.
 /// </summary>
 /// <param name="ctx">
 /// A <see cref="GraphicsContext"/> used for creating this object name.
 /// </param>
 /// <returns>
 /// It returns a valid object name for this ShaderProgram.
 /// </returns>
 protected override uint CreateName(GraphicsContext ctx)
 {
     // Create program
     return(Gl.CreateProgram());
 }