11using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics ;
34using IIS . SLSharp . Descriptions ;
5+ using IIS . SLSharp . Shaders ;
46using OpenTK . Graphics . OpenGL ;
57using System . Linq ;
68
@@ -12,6 +14,33 @@ sealed class Program: IProgram
1214
1315 public List < VariableDescription > VertexIns { get ; private set ; }
1416
17+ private void Validate ( )
18+ {
19+ int linkStatus , validStatus ;
20+ var logCompile = GL . GetProgramInfoLog ( Name ) ;
21+ GL . ValidateProgram ( Name ) ;
22+ var logValidate = GL . GetProgramInfoLog ( Name ) ;
23+
24+ GL . GetProgram ( Name , ProgramParameter . LinkStatus , out linkStatus ) ;
25+ GL . GetProgram ( Name , ProgramParameter . ValidateStatus , out validStatus ) ;
26+
27+ var log = "=== Compilation log ===" + Environment . NewLine +
28+ logCompile + Environment . NewLine +
29+ "=== Validation log ===" + Environment . NewLine + logValidate ;
30+
31+ if ( linkStatus != 1 )
32+ throw new SLSharpException ( "Program linkage failed: " + Environment . NewLine + log ) ;
33+
34+ if ( validStatus != 1 )
35+ {
36+ Debug . WriteLine ( "Program validation failed: " + Environment . NewLine + log ) ;
37+ return ;
38+ }
39+
40+ if ( ! String . IsNullOrEmpty ( logCompile ) || ! String . IsNullOrEmpty ( logValidate ) )
41+ Debug . WriteLine ( "Link info: " + log ) ;
42+ }
43+
1544 public Program ( IEnumerable < Tuple < int , SourceDescription > > units )
1645 {
1746 Name = GL . CreateProgram ( ) ;
@@ -25,6 +54,7 @@ public Program(IEnumerable<Tuple<int, SourceDescription>> units)
2554 VertexIns = merged . VertexIns ;
2655
2756 GL . LinkProgram ( Name ) ;
57+ Validate ( ) ;
2858 Utilities . CheckGL ( ) ;
2959 }
3060
0 commit comments