public void CheckAndFixInvalidDefaultPrecisionError(string message) { string precisionQualifierErrorString = ": 'Default Precision Qualifier' : invalid type Type for default precision qualifier can be only float or int"; string[] los = source.Split('\n'); var linesOfSource = new List <string>(los); if (message.Contains(precisionQualifierErrorString)) { LogManager.Instance.Write("Fixing invalid type Type fore default precision qualifier by deleting bad lines then re-compiling"); //remove releavant lines from source string[] errors = message.Split('\n'); //going from the end so when we delete a line the numbers of the lines beforew will not change for (int i = errors.Length - 1; i >= 0; i--) { string curError = errors[i]; int foundPos = curError.IndexOf(precisionQualifierErrorString); if (foundPos != -1) { string lineNumber = curError.Substring(0, foundPos); int posOfStartOfNumber = lineNumber.LastIndexOf(':'); if (posOfStartOfNumber != -1) { lineNumber = lineNumber.Substring(posOfStartOfNumber + 1, lineNumber.Length - (posOfStartOfNumber + 1)); int numLine = -1; if (int.TryParse(lineNumber, out numLine)) { linesOfSource.RemoveAt(numLine - 1); } } } } //rebuild source var newSource = new StringBuilder(); for (int i = 0; i < linesOfSource.Count; i++) { newSource.AppendLine(linesOfSource[i]); } source = newSource.ToString(); int r = 0; var sourceArray = new string[] { source }; GL.ShaderSource(this.glShaderHandle, 1, sourceArray, ref r); GLES2Config.GlCheckError(this); if (this.Compile()) { LogManager.Instance.Write("The removing of the lines fixed the invalid type Type for default precision qualifier error."); } else { LogManager.Instance.Write("The removing of the lines didn't help."); } } }
/// <summary> /// Build the shaders /// </summary> private int LoadShader(All20 type, string source) { int shader = GL20.CreateShader(type); if (shader == 0) { throw new InvalidOperationException("Unable to create shader"); } // Load the shader source int length = 0; GL20.ShaderSource(shader, 1, new string[] { source }, new int[] { source.Length }); // Compile the shader GL20.CompileShader(shader); int[] compiled = new int[1]; GL20.GetShader(shader, All20.CompileStatus, compiled); if (compiled[0] == 0) { length = 0; GL20.GetShader(shader, All20.InfoLogLength, ref length); var log = new StringBuilder(length); GL20.GetShaderInfoLog(shader, length, ref length, log); Console.WriteLine("GL2" + log.ToString()); GL20.DeleteShader(shader); //length = 0; //GL20.GetShader(shader, All20.InfoLogLength, ref length); //if (length > 0) //{ // var log = new StringBuilder(length); // GL20.GetShaderInfoLog(shader, length, ref length, log); // Console.WriteLine("GL2" + log.ToString()); //} //GL20.DeleteShader(shader); throw new InvalidOperationException("Unable to compile shader of type : " + type.ToString()); } return(shader); }
/// <summary> /// Build the shaders /// </summary> private int LoadShader(ALL20 type, string source) { int shader = GL20.CreateShader(type); if (shader == 0) { throw new InvalidOperationException(string.Format( "Unable to create shader: {0}", GL20.GetError())); } // Load the shader source int length = 0; GL20.ShaderSource(shader, 1, new string[] { source }, (int[])null); // Compile the shader GL20.CompileShader(shader); int compiled = 0; GL20.GetShader(shader, ALL20.CompileStatus, ref compiled); if (compiled == 0) { length = 0; GL20.GetShader(shader, ALL20.InfoLogLength, ref length); if (length > 0) { var log = new StringBuilder(length); GL20.GetShaderInfoLog(shader, length, ref length, log); #if DEBUG Console.WriteLine("GL2" + log.ToString()); #endif } GL20.DeleteShader(shader); throw new InvalidOperationException("Unable to compile shader of type : " + type.ToString()); } return(shader); }
public bool Compile(bool checkErrors) { if (this.compiled == 1) { return(true); } //ONly creaet a shader object if glsl es is supported if (IsSupported) { //Create shader object GLenum shaderType = GLenum.None; if (type == GpuProgramType.Vertex) { shaderType = GLenum.VertexShader; } else { shaderType = GLenum.FragmentShader; } this.glShaderHandle = GL.CreateShader(shaderType); GLES2Config.GlCheckError(this); //TODO : Root.Instance.RenderSystem.Capabilities.HasCapability(Capabilities.SeperateShaderObjects)) if (false) { this.glProgramHandle = GL.CreateProgram(); GLES2Config.GlCheckError(this); } } //Add preprocessor extras and main source if (source.Length > 0) { var sourceArray = new string[] { source }; int r = 0; GL.ShaderSource(this.glShaderHandle, 1, sourceArray, ref r); GLES2Config.GlCheckError(this); } if (checkErrors) { LogManager.Instance.Write("GLSL ES compiling: " + Name); } GL.CompileShader(this.glShaderHandle); GLES2Config.GlCheckError(this); //check for compile errors GL.GetShader(this.glShaderHandle, GLenum.CompileStatus, ref this.compiled); GLES2Config.GlCheckError(this); if (this.compiled == 0 && checkErrors) { string message = "GLSL ES compile log: " + Name; this.CheckAndFixInvalidDefaultPrecisionError(message); } //Log a message that the shader compiled successfully. if (this.compiled == 1 && checkErrors) { LogManager.Instance.Write("GLSL ES compiled: " + Name); } return(this.compiled == 1); }