Skip to content

Commit

Permalink
docs(WebGL API): enhance createShader(), compileShader(), and shaderS…
Browse files Browse the repository at this point in the history
…ource() methods (#38008)

* docs(WebGL API): enhance createShader(), compileShader(), and shaderSource() methods

The WebGL documentation did not previously indicate the [`createShader()`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/createShader) method may return `null` or that both [`compileShader()`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/compileShader) and [`shaderSource()`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/shaderSource) can throw `TypeError` exceptions.

This commit improves clarity and accuracy, ensuring developers are better informed about potential failure cases.

- Added amplifying information to the `type` parameter and details about possible `null` return value to [`createShader()`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/createShader) method.
- Added an Exceptions section for [`compileShader()`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/compileShader) and [`shaderSource()`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/shaderSource) methods to document potential `TypeError` exception.

* Update files/en-us/web/api/webglrenderingcontext/createshader/index.md

---------

Co-authored-by: wbamberg <[email protected]>
  • Loading branch information
jobansd and wbamberg authored Feb 15, 2025
1 parent a850ca8 commit bcff6fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ compileShader(shader)

None ({{jsxref("undefined")}}).

### Exceptions

- {{jsxref("TypeError")}}
- : Thrown if the specified `shader` is not of type `WebGLShader`.

## Examples

```js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ createShader(type)
### Parameters

- `type`
- : Either `gl.VERTEX_SHADER` or `gl.FRAGMENT_SHADER`
- : Either `gl.VERTEX_SHADER` or `gl.FRAGMENT_SHADER`. The {{domxref("WebGLRenderingContext")}} will set the `gl.INVALID_ENUM` error flag if an unacceptable value has been specified.

### Return value

A new ({{domxref("WebGLShader")}}).
A new {{domxref("WebGLShader")}} instance, or `null` if an error occurs creating the shader (for example, because `type` was an invalid value).

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ shaderSource(shader, source)

None ({{jsxref("undefined")}}).

### Exceptions

- {{jsxref("TypeError")}}
- : Thrown if the specified `shader` is not of type `WebGLShader`.

## Examples

```js
Expand Down

0 comments on commit bcff6fc

Please sign in to comment.