【问题标题】:WebGL not rendering may be related to warningWebGL 不渲染可能与警告有关
【发布时间】:2015-07-04 07:12:52
【问题描述】:

我对 OpenGL 比较陌生,并尝试学习一点 WebGl。我遇到了a tutorial,虽然很棒,但似乎有点过时了。我实现了我自己的example in a Plunkr 版本。我故意省略了正方形,然而,一旦我把所有东西都连接好,我就看不到三角形了。我在控制台中发现了一个警告...

WARNING: Attribute 0 is disabled. This has signficant performance penalty

还有另一个SO question 似乎很相似,但通过差异查看我无法让它工作,我无法得到他所说的点击。这是我的绘图代码供参考...

drawScene() {
    this.gl.viewport(0, 0, this.gl.viewportWidth, this.gl.viewportHeight);
    this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
    mat4.perspective(45, this.gl.viewportWidth / this.gl.viewportHeight, 0.1, 100.0, this.pMatrix);
    mat4.identity(this.mvMatrix);
    mat4.translate(this.mvMatrix, this.mvMatrix, [-1.5, 0.0, -7.0]);
    this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.triangleVertexPositionBuffer);
    this.gl.vertexAttribPointer(this.shaderProgram.vertexPositionAttribute, this.triangleVertexPositionBuffer.itemSize, this.gl.FLOAT, false, 0, 0);
    this.setMatrixUniforms();
    this.gl.drawArrays(this.gl.TRIANGLES, 0, this.triangleVertexPositionBuffer.numItems);
  }

有没有人有经验可以帮助指导新手?

【问题讨论】:

标签: webgl


【解决方案1】:

所以回过头来this link 帮助很大。要考虑的一件事是它没有谈论他们导入的 glUtils js 文件,所以是的,这是需要的。似乎警告消息所指的是在较新版本中需要明确说明着色器的参数。这是example plnkr,您会注意到这是不同的...

// NEEDED to prevent warning
    this.vertexPositionAttribute = this.gl.getAttribLocation(this.shaderProgram, "aVertexPosition");
    this.gl.enableVertexAttribArray(this.vertexPositionAttribute);

当我以这种方式设置我的着色器属性时,我避免了警告!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    相关资源
    最近更新 更多