/// <summary> /// read all information of object (color, texcoord,shader...) /// </summary> /// <param name="VerticesPath"> Location of vertices file </param> public void ReadObject(string VerticesPath) { string VertexShaderSource; vertices = new List <float>(); Indicate = new List <int>(); ColorList = new List <float>(); TextCoord = new List <float>(); ArrayListTexture = new List <Texture>(); ShadersList = new List <string>(); // // using (StreamReader reader = new StreamReader(VerticesPath, Encoding.UTF8)) { VertexShaderSource = reader.ReadToEnd(); string[] stringSeparators = new string[] { "\r\n" }; string[] lines = VertexShaderSource.Split(stringSeparators, StringSplitOptions.None); //begin #information of object ReadHeader(lines.Skip(0).Take(Array.IndexOf(lines, "//end header") + 1).ToArray()); ReadVertex(lines.Skip(Array.IndexOf(lines, "//vertex")).Take((Array.IndexOf(lines, "//end vertex") - Array.IndexOf(lines, "//vertex")) + 1).ToArray()); //get shader ReadShaders(lines.Skip(Array.IndexOf(lines, "//shader")).Take((Array.IndexOf(lines, "//end shader") - Array.IndexOf(lines, "//vertex")) + 1).ToArray()); //watching shader here WatchingShader(getShader()); // if (UseIndicate) { //Read indicate ReadIndicate(lines.Skip(Array.IndexOf(lines, "//indicate")).Take((Array.IndexOf(lines, "//end indicate") - Array.IndexOf(lines, "//indicate")) + 1).ToArray()); } if (UseColor) { ReadColor(lines.Skip(Array.IndexOf(lines, "//color")).Take((Array.IndexOf(lines, "//end color") - Array.IndexOf(lines, "//color")) + 1).ToArray()); } if (UseTextCoord) { ReadTextCoord(lines.Skip(Array.IndexOf(lines, "//textcoord")).Take((Array.IndexOf(lines, "//end textcoord") - Array.IndexOf(lines, "//textcoord")) + 1).ToArray()); } //end #information of object } }
private ShaderBlob BuildProgramInternal(ShaderCreationArguments args) { try { StaticLogger.Logger.DebugFormat("Starting Creation of {0}", args.ConvenientName()); PngTexture texture = null; if (args.Type.UseTexture) { texture = new PngTexture(args.TexturePath); texture.Load(); texture.Create(); GlErrorLogger.Check(); // Do I even need this? Gl.BindTexture(TextureTarget.Texture2d, texture.TextureName); GlErrorLogger.Check(); } var vertexSource = VertexShaderSource.VertexSourceLookup(args.Type.VertexFormat, args.Type.VertexShaderVersion); var _Program = new ShaderProgram(args.FragmentShaderSource, vertexSource, args.Type.Uniforms, args.Type.VertexFormat); GlErrorLogger.Check(); _Program.Link(); GlErrorLogger.Check(); IVertexArray _VertexArray = BuildVertexArray(_Program.VertexLocations, args); GlErrorLogger.Check(); return(new ShaderBlob() { DisplayName = args.ConvenientName(), CreationArguments = args, TreatAsGood = true, Program = _Program, VertexArray = _VertexArray, TextureName = !args.Type.UseTexture ? 0 : texture.TextureName, }); } catch (Exception e) { StaticLogger.Logger.ErrorFormat("{1} - Shader Error {0}", args.SimpleName, e.ToString()); if (BadShader == null) { throw new InvalidOperationException("Could not build BadShader!"); } return(new ShaderBlob() { DisplayName = args.ConvenientName(), CreationArguments = BadShader.CreationArguments, TreatAsGood = false, ErrorMessage = e.ToString(), Program = BadShader.Program, VertexArray = BadShader.VertexArray }); } }