Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions src/extras/mini-stats/render2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Render2d {
type: PRIMITIVE_TRIANGLES,
indexed: true,
base: 0,
baseVertex: 0,
count: 0
};
this.quads = 0;
Expand Down
1 change: 1 addition & 0 deletions src/platform/graphics/transform-feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class TransformFeedback {
device.draw({
type: PRIMITIVE_POINTS,
base: 0,
baseVertex: 0,
count: this._inputBuffer.numVertices,
indexed: false
});
Expand Down
1 change: 1 addition & 0 deletions src/platform/graphics/webgpu/webgpu-clear-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DepthState } from '../depth-state.js';
const primitive = {
type: PRIMITIVE_TRISTRIP,
base: 0,
baseVertex: 0,
count: 4,
indexed: false
};
Expand Down
2 changes: 1 addition & 1 deletion src/platform/graphics/webgpu/webgpu-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
// draw
if (indexBuffer) {
passEncoder.setIndexBuffer(indexBuffer.impl.buffer, indexBuffer.impl.format);
passEncoder.drawIndexed(primitive.count, numInstances, primitive.base, 0, 0);
passEncoder.drawIndexed(primitive.count, numInstances, primitive.base, primitive.baseVertex ?? 0, 0);
} else {
passEncoder.draw(primitive.count, numInstances, primitive.base, 0);
}
Expand Down
7 changes: 5 additions & 2 deletions src/scene/batching/batch-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ class BatchManager {
batch = new Batch(meshInstances, dynamic, batchGroupId);
this._batchList.push(batch);

let indexBase, numIndices, indexData;
let indexBase, indexBaseVertex, numIndices, indexData;
let verticesOffset = 0;
let indexOffset = 0;
let transform;
Expand Down Expand Up @@ -760,6 +760,7 @@ class BatchManager {
// index buffer
if (mesh.primitive[0].indexed) {
indexBase = mesh.primitive[0].base;
indexBaseVertex = mesh.primitive[0].baseVertex || 0;
numIndices = mesh.primitive[0].count;

// source index buffer data mapped to its format
Expand All @@ -768,6 +769,8 @@ class BatchManager {

} else { // non-indexed

indexBaseVertex = 0;

const primitiveType = mesh.primitive[0].type;
if (primitiveType === PRIMITIVE_TRIFAN || primitiveType === PRIMITIVE_TRISTRIP) {
if (mesh.primitive[0].count === 4) {
Expand All @@ -782,7 +785,7 @@ class BatchManager {
}

for (let j = 0; j < numIndices; j++) {
indices[j + indexOffset] = indexData[indexBase + j] + verticesOffset;
indices[j + indexOffset] = indexData[indexBase + j] + indexBaseVertex + verticesOffset;
}

indexOffset += numIndices;
Expand Down
1 change: 1 addition & 0 deletions src/scene/graphics/quad-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ShaderUtils } from '../shader-lib/shader-utils.js';
const _quadPrimitive = {
type: PRIMITIVE_TRISTRIP,
base: 0,
baseVertex: 0,
count: 4,
indexed: false
};
Expand Down
6 changes: 5 additions & 1 deletion src/scene/mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,17 @@ class Mesh extends RefCountedObject {
* - {@link PRIMITIVE_TRIFAN}
*
* - `base` is the offset of the first index or vertex to dispatch in the draw call.
* - `baseVertex` is the number added to each index value before indexing into the vertex buffers. (available only for WebGPU and Batching)
* - `count` is the number of indices or vertices to dispatch in the draw call.
* - `indexed` specifies whether to interpret the primitive as indexed, thereby using the
* currently set index buffer.
*
* @type {{type: number, base: number, count: number, indexed?: boolean}[]}
* @type {{type: number, base: number, baseVertex: number, count: number, indexed?: boolean}[]}
*/
primitive = [{
type: 0,
base: 0,
baseVertex: 0,
count: 0
}];

Expand Down Expand Up @@ -1044,6 +1046,7 @@ class Mesh extends RefCountedObject {
this.primitive[RENDERSTYLE_POINTS] = {
type: PRIMITIVE_POINTS,
base: 0,
baseVertex: 0,
count: this.vertexBuffer ? this.vertexBuffer.numVertices : 0,
indexed: false
};
Expand Down Expand Up @@ -1108,6 +1111,7 @@ class Mesh extends RefCountedObject {
this.primitive[RENDERSTYLE_WIREFRAME] = {
type: PRIMITIVE_LINES,
base: 0,
baseVertex: 0,
count: lines.length,
indexed: true
};
Expand Down