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

clip() on a framebuffer while there is a clip() on the main canvas invalidates the main canvas's clip #6375

Closed
1 of 17 tasks
davepagurek opened this issue Aug 23, 2023 · 0 comments · Fixed by #6376
Closed
1 of 17 tasks
Assignees

Comments

@davepagurek
Copy link
Contributor

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
  • Internalization
  • Friendly Errors
  • Other (specify if possible)

p5.js version

main branch

Web browser and version

Firefox 114

Operating System

MacOS 12.5.1

Steps to reproduce this

Steps:

  1. Make a WebGL canvas
  2. Make a framebuffer
  3. Add a clip to the main canvas
  4. Between the framebuffer's begin/end, apply a different clip
  5. After the end of the framebuffer, draw something else to the main canvas

After (5), the main canvas's clip is no longer active. We intentionally only support one clip at a time per draw target for now (because saving + restoring a stencil buffer might be slow) but we should be able to support switching between framebuffers like this.

Snippet:

let fbo

function setup() {
  createCanvas(400, 400, WEBGL)
  fbo = createFramebuffer()
  noLoop()
}

function draw() {
  rectMode(CENTER)
  background('red')
  push()
  beginClip()
  rect(-25, -25, 100, 100)
  endClip()
  
  fbo.begin()
  beginClip()
  rect(25, 25, 100, 100)
  endClip()
  fill('blue')
  rect(0, 0, width, height)
  fbo.end()
  
  imageMode(CENTER)
  image(fbo, 0, 0)
  pop()
  
  // Visualize outlines of masks
  noFill()
  rect(-25, -25, 100, 100)
  rect(25, 25, 100, 100)
}

Live: https://editor.p5js.org/davepagurek/sketches/ZfeKjEE0I

Expected:
image

Actual:
image

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

Successfully merging a pull request may close this issue.

1 participant