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

Performance improvements for WebGL shape drawing #7287

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

davepagurek
Copy link
Contributor

Resolves #7237

This makes two changes:

  • We no longer create edges on models that don't have any, meaning if you never create strokes, you never have to incur the cost of calculating them.
  • Fixes a shape drawing special case: we can draw individual triangles without tessellation, but what should have been an = was an === so it wasn't being applied, oops 😬

I tested with this https://editor.p5js.org/davepagurek/sketches/vmiMgGi5s which makes a new geometry and draws it each frame. The perf I got was:

Chrome

  • No stroke changes: 5fps
  • Skip strokes: 11fps
  • Add triangle check: 12fps

Firefox

  • No changes: 4fps
  • Skip strokes: 8fps
  • Add triangle check: 9fps

I didn't make the other change requested in the issue to make buildGeometry update the line vertex data when you add a new shape. This is because when we add it, we have to transform every vertex anyway. This is probably not less work than just recreating it, and if you do any other operation (e.g. add this geometry into another geometry), you'd be doing more work overall by transforming twice.

PR Checklist

@@ -214,7 +214,7 @@ p5.RendererGL.prototype.endShape = function(
if (this.immediateMode.geometry.vertices.length === 3 &&
this.immediateMode.shapeMode === constants.TESS
) {
this.immediateMode.shapeMode === constants.TRIANGLES;
this.immediateMode.shapeMode = constants.TRIANGLES;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@davepagurek davepagurek merged commit f54069c into processing:main Sep 24, 2024
2 checks passed
@davepagurek davepagurek deleted the model-perf branch September 24, 2024 23:31
@perminder-17
Copy link
Contributor

This PR also fixes issue: #6318. Thanks;)

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.

Long time spent in _edgesToVertices when assembling shapes into composite models
2 participants