regl
regl copied to clipboard
Incorrect state management after VAO emulation
In this notebook: https://observablehq.com/@rreusser/strange-attractors-on-the-gpu-part-2
The particles use a VAO. It should look like this:
![Screen Shot 2021-11-22 at 08 05 02](https://user-images.githubusercontent.com/572717/142895179-a5d0b62a-c230-4c1b-9e90-db80712dfdfb.png)
but when I disable the VAO extension, causing the particles to fall back to VAO emulation, the particles render correctly but the grid is incorrect:
![Screen Shot 2021-11-22 at 08 05 29](https://user-images.githubusercontent.com/572717/142895271-49989595-97c5-4758-84b1-d9f9a852b942.png)
~~I'll see if I can, but I don't yet have a more focused reproduction of the bug.~~ See below for reproduction.
Attribute 0 of particle rendering has divisor 0, all others have divisor 1. That could potentially be a cause.
Confirmed, here is a notebook which reproduces the issue: https://observablehq.com/d/243a0f078d6865bd
To reproduce:
- draw geometry with divisors set in a vao
- draw geometry without instancing or vaos
If the OES_vertex_array_object
is present, this will produce the expected result. If not, then emulation will render the second (unfancy) triangle incorrectly but throw no errors or warnings.
const regl = createREGL({
extensions: ['ANGLE_instanced_arrays', 'OES_vertex_array_object']
});
const vao = regl.vao([
{ divisor: 0, buffer: regl.buffer([[-0.1, -0.1], [0.1, -0.1], [0, 0.1]]) },
{ divisor: 1, buffer: regl.buffer([[-0.2, 0.4], [0.2, .4]]) }
]);
const drawTrianglesWithVAO = regl({
vert: `
precision highp float;
attribute vec2 xy, tri;
void main () {
gl_Position = vec4(xy + tri, 0, 1);
}`,
frag: `
precision highp float;
void main () {
gl_FragColor = vec4(0,0,0,1);
}`,
attributes: { tri: 0, xy: 1 },
vao,
count: 3,
instances: 2
});
const drawTriangle = regl({
vert: `
precision highp float;
attribute vec2 xy;
attribute vec3 color;
varying vec3 vColor;
void main () {
vColor = color;
gl_Position = vec4(xy, 0, 1);
}`,
frag: `
precision highp float;
varying vec3 vColor;
void main () {
gl_FragColor = vec4(pow(vColor, vec3(0.454)),1);
}`,
attributes: {
xy: [[-0.1, -0.5], [0.1, -0.5], [0, -0.3]],
color: [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
},
count: 3
});
regl.poll();
drawTrianglesWithVAO();
drawTriangle();
Can still reproduce this issue.