Clean up shader error detection

This commit is contained in:
Stefanos A. 2013-12-17 12:09:00 +01:00
parent 3ee6d1dbbd
commit 809799aa90

View file

@ -80,8 +80,8 @@ namespace Examples.Tutorial
ShaderFilenames[0] = "Data/Shaders/JuliaSet_SM3_FS.glsl";
ShaderFilenames[1] = "Data/Shaders/JuliaSet_SM2_FS.glsl";
byte CurrentOption = 0;
string LogInfo;
int status = 0;
#region Shaders
// Load&Compile Vertex Shader
@ -99,34 +99,31 @@ namespace Examples.Tutorial
Trace.WriteLine("Vertex Shader compiled without complaint.");
// Load&Compile Fragment Shader
FragmentShaderObject = GL.CreateShader(ShaderType.FragmentShader);
do
foreach (var shader in ShaderFilenames)
{
using (StreamReader sr = new StreamReader(ShaderFilenames[CurrentOption]))
using (StreamReader sr = new StreamReader(shader))
{
GL.ShaderSource(FragmentShaderObject, sr.ReadToEnd());
GL.CompileShader(FragmentShaderObject);
}
GL.GetShaderInfoLog(FragmentShaderObject, out LogInfo);
if (LogInfo.Length > 0 && !LogInfo.Contains("hardware"))
Trace.WriteLine("Compiling " + ShaderFilenames[CurrentOption] + " failed!\nLog:\n" + LogInfo);
GL.GetShader(FragmentShaderObject, ShaderParameter.CompileStatus, out status);
if (status != 1)
{
GL.GetShaderInfoLog(FragmentShaderObject, out LogInfo);
Trace.WriteLine("Compiling " + shader + " failed!\nLog:\n" + LogInfo);
}
else
{
Trace.WriteLine("Fragment Shader compiled without complaint.");
break;
}
if (++CurrentOption > 1)
{
MessageBox.Show("Neither SM2 nor SM3 Fragment Shader compiled successfully. Aborting.",
"Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Exit();
}
} while (true);
}
if (status != 1)
{
MessageBox.Show("Shader compilation failed");
Exit();
}
// Link the Shaders to a usable Program
ProgramObject = GL.CreateProgram();