Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect state management after VAO emulation #633

Open
rreusser opened this issue Nov 22, 2021 · 2 comments
Open

Incorrect state management after VAO emulation #633

rreusser opened this issue Nov 22, 2021 · 2 comments

Comments

@rreusser
Copy link
Member

rreusser commented Nov 22, 2021

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

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

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.

@rreusser rreusser changed the title State management error when using VAO emulation Incorrect state management after using VAO emulation Nov 22, 2021
@rreusser rreusser changed the title Incorrect state management after using VAO emulation Incorrect state management after VAO emulation Nov 22, 2021
@rreusser
Copy link
Member Author

rreusser commented Nov 23, 2021

Confirmed, here is a notebook which reproduces the issue: https://observablehq.com/d/243a0f078d6865bd

To reproduce:

  1. draw geometry with divisors set in a vao
  2. 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.

vaoissue

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();

@Swoorup
Copy link

Swoorup commented Mar 19, 2023

Can still reproduce this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants