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

fix(webgl): Support instanceCount=0 in draw() #2070

Merged
merged 5 commits into from
Apr 12, 2024
Merged

fix(webgl): Support instanceCount=0 in draw() #2070

merged 5 commits into from
Apr 12, 2024

Conversation

ibgreen
Copy link
Collaborator

@ibgreen ibgreen commented Apr 10, 2024

For #visgl/deck.gl#8776

Background

  • Setting instanceCount to 0 makes the model draw in non-instanced mode, instead of nothing.

Change List

  • Add Model.props.isInstanced, Model.setInstanced and RenderPipeline.draw({isInstanced})
  • Set isInstanced if instanceCount>0

@ibgreen
Copy link
Collaborator Author

ibgreen commented Apr 10, 2024

I am starting to think that the current API that detects instancing by checking whether instanceCount is a number is perhaps too subtle.

@ibgreen ibgreen marked this pull request as ready for review April 10, 2024 18:27
@@ -489,9 +497,22 @@ export class Model {
*/
setInstanceCount(instanceCount: number): void {
this.instanceCount = instanceCount;
if (instanceCount > 0) {
this.isInstanced = true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would expect this to work the other way, i.e.

if (this.isInstanced) {
  this.instanceCount = instanceCount;
}

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 was added as I didn't wan't to break existing luma.gl examples.

this.vertexCount = vertexCount;
this.setNeedsRedraw('vertexCount');
/** Specify whether instanced rendering should be used */
setInstanced(isInstanced: boolean = true): void {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this? Is there a realistic scenario that switches between instanced/non-instance without changing the attribute layout?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. In fact, I believe that whether the model is instanced should be detectable from the attribute layout, (stepMode: 'instance'). I should to dig into that before landing this.

@ibgreen ibgreen merged commit 9ccd8f5 into master Apr 12, 2024
2 checks passed
@ibgreen ibgreen deleted the ib/instance0 branch April 12, 2024 15:29
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