WebGL: gl.getExtension('OES_standard_derivatives') 没有响应

WebGL: gl.getExtension('OES_standard_derivatives') doesn' t respond

我是 webgl 的新手,现在正在尝试进行平面着色。我试过 Gouraud 着色,效果很好。因此,作为实现平面着色的第一步,我将 #extension GL_OES_standard_derivatives : enable 在我的片段着色器和
if (!gl.getExtension('OES_standard_derivatives')) throw 'extension not support';
在我的 initGL 函数中,代码的其余部分保持不变。

然而,canvas 没有出现,消息也没有出现。通过在上述代码前后添加一些警告消息,我猜测问题是 gl.getExtension('OES_standard_derivatives')) 没有响应,所以此后的任何代码都不起作用(包括 canvas 部分)。

我搜索了一下,没有发现类似的问题。
如有任何帮助,我们将不胜感激。

如果您可以包含有关您的环境的更多信息,这将有助于理解问题。具体这些问题:

  • 您使用的是什么浏览器?
  • 您使用的是哪个版本的 WebGL?
  • 您使用的是纯 WebGL 还是库(例如 Three.js)?
  • 你能post你所有的上下文设置代码吗?

这是一个自包含的脚本,它向控制台报告此特定扩展是否可用:

<html>
<head>
<script>

  function test() {
    var canvas = document.getElementById("sandbox");
    gl = canvas.getContext("webgl");

    if (!gl)
      console.error("WebGL failed to initialize");
    else
      console.debug("WebGL initialization successful");

    var extension = gl.getExtension("OES_standard_derivatives");

    if (!extension)
      console.error("Extension 'OES_standard_derivatives' was not found");
    else
      console.debug("Extension 'OES_standard_derivatives' was found");
  }

</script>
</head>
<body onload="test();">
  <canvas id="sandbox" width="500" height="500" />
</body>
</html>

将其保存到文件中,在您使用的浏览器中将其打开,然后检查控制台以查看发生了什么。

请注意,在 WebGL2 中,此扩展已提升为核心配置文件。来自 WebGL OES_standard_derivatives specification:

Promoted to core and no longer available as an extension in WebGL API 2.0 specification. Requires GLSL #version 300 es.