protected internal bool Compile( bool checkErrors = true )
{
if (isCompiled)
{
return true;
}
if (checkErrors)
{
GLSLHelper.LogObjectInfo( "GLSL compiling: " + Name, GLHandle );
}
if (IsSupported)
{
GLSLHelper.CheckForGLSLError("GL Errors before creating shader object", 0);
var shaderType = 0;
switch ( Type )
{
case GpuProgramType.Vertex:
shaderType = Gl.GL_VERTEX_SHADER_ARB;
break;
case GpuProgramType.Fragment:
shaderType = Gl.GL_FRAGMENT_SHADER_ARB;
break;
case GpuProgramType.Geometry:
shaderType = Gl.GL_GEOMETRY_SHADER_EXT;
break;
}
GLHandle = Gl.glCreateShaderObjectARB(shaderType);
GLSLHelper.CheckForGLSLError("Error creating GLSL shader object", 0);
}
// Preprocess the GLSL shader in order to get a clean source
// CPreprocessor cpp;
// TODO: preprocessor not supported yet in axiom
// Add preprocessor extras and main source
if (!string.IsNullOrEmpty(source))
{
Gl.glShaderSourceARB(GLHandle, 1, new []{ source }, new []{ source.Length });
// check for load errors
GLSLHelper.CheckForGLSLError("Cannot load GLSL high-level shader source : " + Name, 0);
}
Gl.glCompileShaderARB(GLHandle);
int compiled;
// check for compile errors
Gl.glGetObjectParameterivARB(GLHandle, Gl.GL_OBJECT_COMPILE_STATUS_ARB, out compiled);
isCompiled = ( compiled != 0 );
// force exception if not compiled
if ( checkErrors )
{
GLSLHelper.CheckForGLSLError("GLSL : Cannot compile GLSL high-level shader: " + Name + ".", GLHandle, !isCompiled, !isCompiled);
if ( isCompiled )
{
GLSLHelper.LogObjectInfo("GLSL : " + Name + " : compiled.", GLHandle);
}
}
return isCompiled;
}