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

Default fill shader texture stays bound even when not used #5921

Closed
2 of 17 tasks
davepagurek opened this issue Dec 30, 2022 · 0 comments · Fixed by #5923
Closed
2 of 17 tasks

Default fill shader texture stays bound even when not used #5921

davepagurek opened this issue Dec 30, 2022 · 0 comments · Fixed by #5923

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

1.5.0

Web browser and version

Firefox 107.0

Operating System

MacOS 12.5.1

Steps to reproduce this

If one calls texture() in between a push and a pop, after the pop, the texture is still bound to the shader's uSampler uniform.

Normally, this isn't a problem, since we pass false to isTexture, and the shader doesn't try to read the texture. However, if you draw to one texture, then use that texture on a plane onto the main canvas, the browser complains that there is illegal feedback and does not render any fill. This is avoided if you use multiple canvases instead of framebuffers (the default in p5), but this becomes an issue if using framebuffers within the same WebGL context for performance reasons.

e.g. on Chrome:

GL_INVALID_OPERATION: Feedback loop formed between Framebuffer and active Texture.

e.g. on Firefox:

WebGL warning: drawElementsInstanced: Texture level 0 would be read by TEXTURE_2D unit 0, but written by framebuffer attachment COLOR_ATTACHMENT0, which would be illegal feedback.

Here's some code that renders to a framebuffer and triggers this issue (calling lights() results in the above warning and no fills rendered):

let obj

function setup() {
  createCanvas(windowWidth, windowHeight, WEBGL)
  obj = createFramebuffer()
}

function draw() {
  obj.draw(() => {
    clear()
    background(90)
    push()
      lights()
      stroke(0)
      fill(255, 0, 0)
      rotateX(frameCount * 0.01)
      rotateY(frameCount * 0.01)
      box(150)
    pop()
  })  

  // DISPLAY FRAMEBUFFER
  push()
  texture(obj.color)
  noStroke()
  plane(width, -height)
  pop()
}

Live: https://editor.p5js.org/davepagurek/sketches/3Qmz-9PZx

Because this doesn't affect vanilla p5, it isn't a huge issue, but unbinding the texture is a small change that lets us move towards potentially using framebuffers in the future for WebGL filters.

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