static CreateShaderResult CreateShader( WebGLRenderingContext gl, string tvs, string tfs, bool nativeDebug ) { //new IHTMLPre { "enter CreateShader" }.AttachToDocument(); //var p = gl.createProgram(); var vs = new WebGLShader(gl, gl.VERTEX_SHADER); var fs = new WebGLShader(gl, gl.FRAGMENT_SHADER); gl.shaderSource(vs, tvs); gl.shaderSource(fs, tfs); gl.compileShader(vs); var ok = new CreateShaderResult { mSuccess = true }; // https://www.khronos.org/registry/webgl/extensions/WEBGL_debug_shaders/ new WebGLDebugShaders(gl).With(x => ok.vsTranslatedShaderSource = x.getTranslatedShaderSource(vs)); //gl.getExtension("WEBGL_debug_shaders").With( //(dynamic WEBGL_debug_shaders) => // { // ok.vsTranslatedShaderSource = WEBGL_debug_shaders.getTranslatedShaderSource((WebGLShader)vs); // } //); gl.compileShader(fs); // ipad wont have it available new WebGLDebugShaders(gl).With(x => ok.fsTranslatedShaderSource = x.getTranslatedShaderSource(fs)); //gl.getExtension("WEBGL_debug_shaders").With( // (dynamic WEBGL_debug_shaders) => // { // ok.fsTranslatedShaderSource = WEBGL_debug_shaders.getTranslatedShaderSource((WebGLShader)fs); // } //); if (gl.getShaderParameter(vs, gl.COMPILE_STATUS) == null) { var infoLog = gl.getShaderInfoLog(vs); // does our async rewriter throw async exceptions yet? throw new Exception(message: new { infoLog }.ToString()); //new IHTMLPre { "error CreateShader " + new { infoLog } }.AttachToDocument(); //return new CreateShaderResult { mSuccess = false, mInfo = infoLog }; } var fsCOMPILE_STATUS = (bool)gl.getShaderParameter(fs, gl.COMPILE_STATUS); //new IHTMLPre { "CreateShader " + new { fsCOMPILE_STATUS } }.AttachToDocument(); if (!fsCOMPILE_STATUS) { var infoLog = gl.getShaderInfoLog(fs); throw new Exception(message: new { infoLog }.ToString()); //new IHTMLPre { "error CreateShader " + new { infoLog } }.AttachToDocument(); //return new CreateShaderResult { mSuccess = false, mInfo = infoLog }; } var p = new WebGLProgram(gl); gl.attachShader(p, vs); gl.attachShader(p, fs); // using dispose? gl.deleteShader(vs); gl.deleteShader(fs); gl.linkProgram(p); var linkResult = (bool)gl.getProgramParameter(p, gl.LINK_STATUS); //new IHTMLPre { "CreateShader " + new { linkResult } }.AttachToDocument(); if (!linkResult) { var infoLog = gl.getProgramInfoLog(p); gl.deleteProgram(p); throw new Exception(message: new { infoLog }.ToString()); //new IHTMLPre { "error CreateShader " + new { infoLog } }.AttachToDocument(); //return new CreateShaderResult { mSuccess = false, mInfo = infoLog }; } // https://msdn.microsoft.com/en-us/library/ie/dn302415(v=vs.85).aspx //new IHTMLPre { "exit CreateShader" }.AttachToDocument(); ok.mProgram = p; return ok; }