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

Add attribute.divisor field for instanced rendering #10396

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/rendering/renderers/gl/geometry/GlGeometrySystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,11 @@ export class GlGeometrySystem implements System
// TODO calculate instance count based of this...
if (this.hasInstance)
{
gl.vertexAttribDivisor(location, 1);// attribute.divisor);
// Can't use truthiness check to determine if divisor is set,
// since 0 is a valid value for divisor
const divisor = 'divisor' in attribute ? attribute.divisor : 1;
codedpalette marked this conversation as resolved.
Show resolved Hide resolved

gl.vertexAttribDivisor(location, divisor);
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions src/rendering/renderers/shared/geometry/Geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ export interface Attribute
offset?: number;
/** is this an instanced buffer? (defaults to false) */
instance?: boolean;
/** The number of elements to be rendered. If not specified, all vertices after the starting vertex will be drawn. */
/** the number of elements to be rendered. If not specified, all vertices after the starting vertex will be drawn. */
size?: number;
/** the type of attribute */
type?: number;
/**
* The starting vertex in the geometry to start drawing from. If not specified,
* the starting vertex in the geometry to start drawing from. If not specified,
* drawing will start from the first vertex.
*/
start?: number;
/** attribute divisor for instanced rendering */
divisor?: number;
}

/**
Expand Down Expand Up @@ -268,4 +270,3 @@ export class Geometry extends EventEmitter<{
(this._bounds as null) = null;
}
}