Skip to content

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

Closed
@davepagurek

Description

@davepagurek

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions