compile static method
Program
compile(})
Compiles and links a program. Throws on compile/link errors.
Implementation
static Program compile(
RenderingContext gl, {
required String vertexSource,
required String fragmentSource,
Map<String, String> defines = const {},
Map<String, int> attribBindings = const {},
}) {
final vsText = _injectDefines(vertexSource, defines);
final fsText = _injectDefines(fragmentSource, defines);
final vs = gl.createShader(WebGL.VERTEX_SHADER);
gl
..shaderSource(vs, vsText)
..compileShader(vs); // throws with info log on failure
final fs = gl.createShader(WebGL.FRAGMENT_SHADER);
gl
..shaderSource(fs, fsText)
..compileShader(fs);
final program = gl.createProgram();
// Attach shaders, bind attributes (stable locations), then link.
gl
..attachShader(program, vs)
..attachShader(program, fs);
if (attribBindings.isNotEmpty) {
attribBindings.forEach((name, index) {
gl.bindAttribLocation(program, index, name);
});
}
gl
..linkProgram(program)
// Shaders no longer needed after a successful link.
..deleteShader(vs)
..deleteShader(fs);
return program;
}