| title | WebGLRenderingContext: shaderSource() method |
|---|---|
| short-title | shaderSource() |
| slug | Web/API/WebGLRenderingContext/shaderSource |
| page-type | web-api-instance-method |
| browser-compat | api.WebGLRenderingContext.shaderSource |
{{APIRef("WebGL")}}{{AvailableInWorkers}}
The WebGLRenderingContext.shaderSource() method of the WebGL API sets the source code of a
{{domxref("WebGLShader")}}.
shaderSource(shader, source)
shader- : A {{domxref("WebGLShader")}} object in which to set the source code.
source- : A string containing the GLSL source code to set.
None ({{jsxref("undefined")}}).
- {{jsxref("TypeError")}}
- : Thrown if the specified
shaderis not of typeWebGLShader.
- : Thrown if the specified
const shader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(shader, originalSource);
const source = gl.getShaderSource(shader);{{Specifications}}
{{Compat}}
- {{domxref("WebGLRenderingContext.createShader()")}}
- {{domxref("WebGLRenderingContext.isShader()")}}
- {{domxref("WebGLRenderingContext.deleteShader()")}}
- {{domxref("WebGLRenderingContext.getShaderSource()")}}