Skip to content

Avoid unnecessary texture copies and fix flipped webcams in WebGL#8572

Open
davepagurek wants to merge 1 commit intodev-2.0from
fix/mediaelement-texture-perf
Open

Avoid unnecessary texture copies and fix flipped webcams in WebGL#8572
davepagurek wants to merge 1 commit intodev-2.0from
fix/mediaelement-texture-perf

Conversation

@davepagurek
Copy link
Contributor

Resolves #8571

Changes

  • Now only calls _ensureCanvas in WebGL when dealing with a flipped createCapture, regular videos do not need this
  • When using a flipped createCapture, it now actually uses the .canvas property (which is flipped) instead of the .elt property (which is not)
  • For all other media elements, there is a new _checkIfTextureNeedsUpdate method that gets called instead, which does only the necessary parts of _ensureCanvas for WebGL: marking the texture as needing updating if the time has changed and the video feed needs an update.

Screenshots of the change

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

The test sketch has a flag to toggle between testing webcam feeds and video files. There's an additional flag to toggle between drawing the textures to the canvas and showing them as HTML elements. I've manually tested all combinations of these for perf and correctness.

Note that the flipped webcam feed still has slightly worse perf due to it requiring the extra canvas draw.

PR Checklist

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

Successfully merging this pull request may close these issues.

1 participant