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

WebGLRenderer: Add initial support for multi draw BatchedMesh #27111

Merged
merged 2 commits into from
Nov 5, 2023

Conversation

gkjohnson
Copy link
Collaborator

@gkjohnson gkjohnson commented Nov 3, 2023

Related issue: #22376, #27078 (comment)

Description

Add support for the multi draw extension to WebGLRenderer via WebGLIndexedBufferRenderer and WebGLBufferRenderer for BatchedMesh. The buffers to pass to the multi draw functions are generated in the onBeforeRender function. With this PR non-visible meshes will no longer be rendered at all with the multi draw extension and BatchedMesh will no longer be supported in browsers that do not support the WebGL_multi_draw extension (firefox, opera mobile).

Upcoming PR Plans

  • Add built-in USE_BATCHING define to WebGLRenderer
  • Add built in support for batching texture
  • Reduce redundant storage of data in arrays
  • Add support for toJSON, copy
  • Add support for frustum culling, sorting, raycasting

Copy link

github-actions bot commented Nov 3, 2023

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
652.7 kB (161.7 kB) 653.4 kB (161.9 kB) +755 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
445.3 kB (107.7 kB) 446 kB (107.9 kB) +755 B

Comment on lines +66 to +71
let elementCount = 0;
for ( let i = 0; i < drawCount; i ++ ) {

elementCount += counts[ i ];

}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This part is a bit awkward - in order to correctly report the primitive counts drawn we have tally up all the values in the array.

@gkjohnson gkjohnson added this to the r159 milestone Nov 3, 2023
@gkjohnson gkjohnson requested review from Mugen87 and mrdoob November 3, 2023 14:15
Copy link
Collaborator

@Mugen87 Mugen87 left a comment

Choose a reason for hiding this comment

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

LGTM!

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 4, 2023

Regarding your future PR plans, we might want to consider to move BatchedMesh into the core at some point (next to InstancedMesh).

@gkjohnson
Copy link
Collaborator Author

Regarding your future PR plans, we might want to consider to move BatchedMesh into the core at some point (next to InstancedMesh).

Yup! Once I'm finished with the implementation in examples I'll move it.

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.

2 participants