private async Task <WebGLProgram> InitProgramAsync(WebGLContext gl, string vsSource, string fsSource) { var vertexShader = await this.LoadShaderAsync(gl, ShaderType.VERTEX_SHADER, vsSource); var fragmentShader = await this.LoadShaderAsync(gl, ShaderType.FRAGMENT_SHADER, fsSource); var program = await gl.CreateProgramAsync(); await gl.AttachShaderAsync(program, vertexShader); await gl.AttachShaderAsync(program, fragmentShader); await gl.LinkProgramAsync(program); await gl.DeleteShaderAsync(vertexShader); await gl.DeleteShaderAsync(fragmentShader); if (!await gl.GetProgramParameterAsync <bool>(program, ProgramParameter.LINK_STATUS)) { string info = await gl.GetProgramInfoLogAsync(program); throw new Exception("An error occured while linking the program: " + info); } u_matrix_location = await _context.GetUniformLocationAsync(program, "u_matrix"); return(program); }
private async Task InitProgramAsync(WebGLContext gl, string vsSource, string fsSource) { var vertexShader = await LoadShaderAsync(gl, ShaderType.VERTEX_SHADER, vsSource); var fragmentShader = await LoadShaderAsync(gl, ShaderType.FRAGMENT_SHADER, fsSource); var program = await gl.CreateProgramAsync(); await gl.AttachShaderAsync(program, vertexShader); await gl.AttachShaderAsync(program, fragmentShader); await gl.LinkProgramAsync(program); await gl.DeleteShaderAsync(vertexShader); await gl.DeleteShaderAsync(fragmentShader); if (!await gl.GetProgramParameterAsync <bool>(program, ProgramParameter.LINK_STATUS)) { string info = await gl.GetProgramInfoLogAsync(program); throw new Exception("An error occured while linking the program: " + info); } Console.WriteLine($"shader program : id = {program.Id} , type = {program.WebGLType}"); ShaderProgram = program; }
public async Task <GLProgram> CreateAsync() { ResetObject(); var program = await _context.CreateProgramAsync(); await BindShadersToProgramAsync(program); await _context.LinkProgramAsync(program); if (!await _context.GetProgramParameterAsync <bool>(program, ProgramParameter.LINK_STATUS)) { LastState = LastStateType.Failed; LastError = await _context.GetProgramInfoLogAsync(program); return(this); } await _context.ValidateProgramAsync(program); if (!await _context.GetProgramParameterAsync <bool>(program, ProgramParameter.VALIDATE_STATUS)) { LastState = LastStateType.Failed; LastError = await _context.GetProgramInfoLogAsync(program); return(this); } await BindDataToProgramAsync(program); await _context.UseProgramAsync(program); LastState = LastStateType.Success; GLObjectValue = program; return(this); }
public static async Task <ShaderProgram> InitShaderProgram(WebGLContext gl, string vsSource, string fsSource, List <string> attributesNames = null, List <string> uniformsNames = null) { var vertexShader = await LoadShaderAsync(gl, ShaderType.VERTEX_SHADER, vsSource); var fragmentShader = await LoadShaderAsync(gl, ShaderType.FRAGMENT_SHADER, fsSource); var program = await gl.CreateProgramAsync(); await gl.AttachShaderAsync(program, vertexShader); await gl.AttachShaderAsync(program, fragmentShader); await gl.LinkProgramAsync(program); await gl.DeleteShaderAsync(vertexShader); await gl.DeleteShaderAsync(fragmentShader); if (!await gl.GetProgramParameterAsync <bool>(program, ProgramParameter.LINK_STATUS)) { string info = await gl.GetProgramInfoLogAsync(program); throw new Exception("An error occured while linking the program: " + info); } attributesNames ??= new List <string>(); var attributesDict = new Dictionary <string, int>(); foreach (var attribute in attributesNames) { attributesDict.Add(attribute, await gl.GetAttribLocationAsync(program, attribute)); } uniformsNames ??= new List <string>(); var uniformsDict = new Dictionary <string, WebGLUniformLocation>(); foreach (var uniform in uniformsNames) { uniformsDict.Add(uniform, await gl.GetUniformLocationAsync(program, uniform)); } return(new ShaderProgram(program, gl, attributesDict, uniformsDict)); }