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
Keywords: InRadar
Depends on:
Reported: 2019-05-04 02:18 PDT by Gregg Tavares
Modified: 2020-02-23 21:12 PST (History)
4 users (show)

See Also:


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


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);
  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.clearColor(0, 0, 1, 1);
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

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
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.