Bug 197592

Summary: [WebGL] Safari doesn't handle common no attribute use case
Product: WebKit Reporter: Gregg Tavares <gman>
Component: WebGLAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: dino, justin_fan, nchase, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   

Description Gregg Tavares 2019-05-04 02:18:51 PDT
When debugging WebGL or when explaining to discussing a feature it's best to make a "MINIMAL, Complete, Verifiable, Example"

For WebGL this often means using no attributes and just drawing a single POINT

Example:

-------
const gl = document.querySelector('canvas').getContext('webgl');

const vsrc = `
void main() {
  gl_PointSize = 128.0;
  gl_Position = vec4(0, 0, 0, 1);
}
`;

const fsrc = `
precision highp float;
void main() {
  gl_FragColor = vec4(1, 0, 0, 1);
}
`;

function createShader(gl, type, src) {
  const s = gl.createShader(type);
  gl.shaderSource(s, src);
  gl.compileShader(s);
  return s;
}

const prg = gl.createProgram();
gl.attachShader(prg, createShader(gl, gl.VERTEX_SHADER, vsrc));
gl.attachShader(prg, createShader(gl, gl.FRAGMENT_SHADER, fsrc));
gl.linkProgram(prg);

gl.useProgram(prg);
gl.clearColor(0, 0, 1, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.POINTS, 0, 1);
-----

No attributes needed. This is great as it keeps the sample minimal so is perfect as a starting point for fragment shader based examples. I've used it 100s of times on Stack Overflow and other places to demonstrate WebGL solutions.

It incorrectly fails on Safari only

Here's the relevant conformance test

https://www.khronos.org/registry/webgl/sdk/tests/conformance/rendering/point-no-attributes.html?webglVersion=1&quiet=0
Comment 1 Gregg Tavares 2019-05-04 02:23:16 PDT
Note that changing the vertex shader to this

attribute vec4 position
void main() {
  gl_PointSize = 128.0;
  gl_Position = position;
}


also fails but is perfectly valid WebGL with no attributes. Attributes have a default value of 0,0,0,1 so this will produce the same result as the previous example. Similarly you can set the attribute's constant value with `gl.vertexAttrib4f(...)` and draw points around the canvas.
Comment 2 Radar WebKit Bug Importer 2019-05-04 23:59:15 PDT
<rdar://problem/50477704>
Comment 3 Noah Chase 2020-02-23 21:12:45 PST
I’d love to see this fixed. I wish I knew where to start with a patch, but WebGL implementation is an intimidating black box to me.