Bug 197592 - [WebGL] Safari doesn't handle common no attribute use case
Summary: [WebGL] Safari doesn't handle common no attribute use case
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-05-04 02:18 PDT by Gregg Tavares
Modified: 2019-05-04 23:59 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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>