Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/core/BufferGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ class BufferGeometry extends EventDispatcher {
*/
this.indirect = null;

/**
* The offset, in bytes, into the indirect drawing buffer where the value data begins.
*
* Can only be used with {@link WebGPURenderer} and a WebGPU backend.
*
* @type {number}
* @default 0
*/
this.indirectOffset = 0;

/**
* This dictionary has as id the name of the attribute to be set and as value
* the buffer attribute to set it to. Rather than accessing this property directly,
Expand Down Expand Up @@ -224,11 +234,13 @@ class BufferGeometry extends EventDispatcher {
* Sets the given indirect attribute to this geometry.
*
* @param {BufferAttribute} indirect - The attribute holding indirect draw calls.
* @param {number} [indirectOffset=0] - The offset, in bytes, into the indirect drawing buffer where the value data begins.
* @return {BufferGeometry} A reference to this instance.
*/
setIndirect( indirect ) {
setIndirect( indirect, indirectOffset = 0 ) {

this.indirect = indirect;
this.indirectOffset = indirectOffset;

return this;

Expand Down
12 changes: 12 additions & 0 deletions src/renderers/common/Geometries.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ class Geometries extends DataMap {

}

/**
* Returns the byte offset into the indirect attribute buffer of the given render object.
*
* @param {RenderObject} renderObject - The render object.
* @return {number} The byte offset into the indirect attribute buffer.
*/
getIndirectOffset( renderObject ) {

return renderObject.geometry.indirectOffset;

}

/**
* Returns the index of the given render object's geometry. This is implemented
* in a method to return a wireframe index if necessary.
Expand Down
11 changes: 11 additions & 0 deletions src/renderers/common/RenderObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,17 @@ class RenderObject {

}

/**
* Returns the byte offset into the indirect attribute buffer.
*
* @return {number} The byte offset into the indirect attribute buffer.
*/
getIndirectOffset() {

return this._geometries.getIndirectOffset( this );

}

/**
* Returns an array that acts as a key for identifying the render object in a chain map.
*
Expand Down
6 changes: 4 additions & 2 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -1600,8 +1600,9 @@ class WebGPUBackend extends Backend {
if ( indirect !== null ) {

const buffer = this.get( indirect ).buffer;
const indirectOffset = renderObject.getIndirectOffset();

passEncoderGPU.drawIndexedIndirect( buffer, 0 );
passEncoderGPU.drawIndexedIndirect( buffer, indirectOffset );

} else {

Expand All @@ -1620,8 +1621,9 @@ class WebGPUBackend extends Backend {
if ( indirect !== null ) {

const buffer = this.get( indirect ).buffer;
const indirectOffset = renderObject.getIndirectOffset();

passEncoderGPU.drawIndirect( buffer, 0 );
passEncoderGPU.drawIndirect( buffer, indirectOffset );

} else {

Expand Down