Duality.Resources.ShaderProgram.Compile C# (CSharp) Method

Compile() public method

Compiles the ShaderProgram. This is done automatically when loading the ShaderProgram or when binding it.
public Compile ( ) : void
return void
        public void Compile()
        {
            DualityApp.GuardSingleThreadState();

            if (this.glProgramId == 0) return;
            if (this.compiled) return;

            GL.LinkProgram(this.glProgramId);

            int result;
            GL.GetProgram(this.glProgramId, GetProgramParameterName.LinkStatus, out result);
            if (result == 0)
            {
                string infoLog = GL.GetProgramInfoLog(this.glProgramId);
                Log.Core.WriteError("Error linking shader program. InfoLog:{1}{0}", infoLog, Environment.NewLine);
                return;
            }
            this.compiled = true;

            // Collect variable infos from sub programs
            ShaderVarInfo[] geomVarArray = this.geom.IsAvailable ? this.geom.Res.VarInfo : null;
            ShaderVarInfo[] fragVarArray = this.frag.IsAvailable ? this.frag.Res.VarInfo : null;
            ShaderVarInfo[] vertVarArray = this.vert.IsAvailable ? this.vert.Res.VarInfo : null;

            var emptyShaderInfo = new ShaderVarInfo[0];
            this.varInfo = (vertVarArray ?? emptyShaderInfo)
                .Union(fragVarArray ?? emptyShaderInfo)
                .Union(geomVarArray ?? emptyShaderInfo)
                .ToArray();

            // Determine actual variable locations
            for (int i = 0; i < this.varInfo.Length; i++)
            {
                if (this.varInfo[i].scope == ShaderVarScope.Uniform)
                    this.varInfo[i].glVarLoc = GL.GetUniformLocation(this.glProgramId, this.varInfo[i].name);
                else
                    this.varInfo[i].glVarLoc = GL.GetAttribLocation(this.glProgramId, this.varInfo[i].name);
            }
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Binds a ShaderProgram in order to use it.
        /// </summary>
        /// <param name="prog">The ShaderProgram to be bound.</param>
        public static void Bind(ContentRef <ShaderProgram> prog)
        {
            ShaderProgram progRes = prog.IsExplicitNull ? null : prog.Res;

            if (curBound == progRes)
            {
                return;
            }

            if (progRes == null)
            {
                GL.UseProgram(0);
                curBound = null;
            }
            else
            {
                if (!progRes.compiled)
                {
                    progRes.Compile();
                }

                if (progRes.glProgramId == 0)
                {
                    throw new ArgumentException("Specified shader program has no valid OpenGL program Id! Maybe it hasn't been loaded / initialized properly?", "prog");
                }
                if (progRes.Disposed)
                {
                    throw new ArgumentException("Specified shader program has already been deleted!", "prog");
                }

                GL.UseProgram(progRes.glProgramId);
                curBound = progRes;
            }
        }
All Usage Examples Of Duality.Resources.ShaderProgram::Compile