TypeError: Failed to execute 'shaderSource' on 'WebGLRenderingContext': parameter 1 is not of type 'WebGLShader'.
时间: 2023-12-23 08:06:16 浏览: 49
This error occurs when the first parameter passed to the `shaderSource()` method is not a valid WebGLShader object. The `shaderSource()` method is used to set the source code for a WebGL shader program.
To resolve this error, ensure that the shader object passed as the first parameter to the `shaderSource()` method is created using the `createShader()` method of the WebGLRenderingContext. Here's an example:
```
var gl = canvas.getContext('webgl');
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
// Set the source code for the vertex shader
gl.shaderSource(vertexShader, `
attribute vec4 a_Position;
uniform mat4 u_ModelViewMatrix;
void main() {
gl_Position = u_ModelViewMatrix * a_Position;
}
`);
```
In this example, `vertexShader` is a valid WebGLShader object created using the `createShader()` method, and the source code for the shader is set using the `shaderSource()` method.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)