Skip to content

Stencil tests are automatically disabled every frame inside draw loops #7554

Closed
@inaridarkfox4231

Description

@inaridarkfox4231

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

1.8.0

Web browser and version

Chrome

Operating system

Windows

Steps to reproduce this

Steps:

  1. Enable the stencil test in setup().
  2. I don't enable the stencil test, inside draw loop.
  3. When drawing with a stencil inside a drawloop, the stencil is not taken into account.

Snippet:

function setup() {
  createCanvas(400, 400, WEBGL);
  noStroke();

  const gl = this._renderer.GL;

  // enable
  gl.enable(gl.STENCIL_TEST);
}

function draw(){
  background(0);

  const gl = this._renderer.GL;
  //gl.enable(gl.STENCIL_TEST);

  // initialize 0
  gl.clear(gl.STENCIL_BUFFER_BIT);

  // set 1
  gl.stencilFunc(gl.ALWAYS, 1, ~0);
  gl.stencilOp(gl.KEEP, gl.REPLACE, gl.REPLACE);

  fill(255, 0, 0);
  plane(200, 400);

  // if stencil value is 1, draw plane
  gl.stencilFunc(gl.EQUAL, 1, ~0);
  gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);

  fill(0, 0, 255);
  plane(400, 200);

  noLoop();
}

version 1.7.0

Image

version 1.8.0

Image

Of course, if you enable the stencil test inside the draw loop, you will get the desired drawing result.

Image

However, some users may not like it when the stencil test is disabled regardless of their intentions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions