Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit 0904cc1

Browse files
committed
Added detailed shader validation for OpenTK binding
1 parent 29a6779 commit 0904cc1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

IIS.SLSharp.Bindings.OpenTK/Program.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using IIS.SLSharp.Descriptions;
5+
using IIS.SLSharp.Shaders;
46
using OpenTK.Graphics.OpenGL;
57
using 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

Comments
 (0)