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);
}
}