Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html WebGL:EnableVertexAttributeArray索引超出范围_Html_Opengl Es_Webgl - Fatal编程技术网

Html WebGL:EnableVertexAttributeArray索引超出范围

Html WebGL:EnableVertexAttributeArray索引超出范围,html,opengl-es,webgl,Html,Opengl Es,Webgl,这里是我的顶点和片段着色器: <script id="shader-fs" type="x-shader/x-fragment"> precision mediump float; uniform sampler2D uSampler; varying vec4 vColor; varying vec2 vTextureCoord; void main(void) {

这里是我的顶点和片段着色器:

    <script id="shader-fs" type="x-shader/x-fragment">
        precision mediump float;

        uniform sampler2D uSampler;

        varying vec4 vColor;
        varying vec2 vTextureCoord;

        void main(void) {
            gl_FragColor = vColor;
            // gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
        }
    </script>
    <script id="shader-vs" type="x-shader/x-vertex">
        attribute vec3 aVertexPosition;
        attribute vec4 aVertexColor;
        attribute vec2 aTextureCoord;

        uniform mat4 uMVMatrix;
        uniform mat4 uPMatrix;

        varying vec4 vColor;
        varying vec2 vTextureCoord;

        void main(void) {
          gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
          vColor = aVertexColor;
          // vTextureCoord = aTextureCoord;
        }
    </script>
错误来自以下行:

  gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
  >> enablevertexattribarray index out of range

我该如何处理它呢?

这仅仅是因为您在vertex程序中没有使用
ATexturecord
,所以GLSL编译器通过删除它来优化它。您确实应该检查gl.getAttributeLocation()的结果是否有错误,并且只启用程序中存在的属性。在缺少属性的情况下发出警告就足够了,我不知道如何区分着色器编写错误和编译器的优化

  gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
  >> enablevertexattribarray index out of range