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 2D batch buffer error #2257

Merged
merged 2 commits into from
Jul 23, 2024
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
2 changes: 1 addition & 1 deletion packages/core/src/RenderPipeline/BatchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export class BatchUtils {
}
chunk.updateIndexLength += length;
chunk.updateVertexStart = Math.min(chunk.updateVertexStart, start);
chunk.updateVertexLength = Math.max(chunk.updateVertexLength, start + size);
chunk.updateVertexEnd = Math.max(chunk.updateVertexEnd, start + size);
}
}
13 changes: 6 additions & 7 deletions packages/core/src/RenderPipeline/PrimitiveChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
VertexElementFormat
} from "../graphic";
import { ReturnableObjectPool } from "../utils/ReturnableObjectPool";
import { VertexArea } from "./VertexArea";
import { SubPrimitiveChunk } from "./SubPrimitiveChunk";
import { VertexArea } from "./VertexArea";

/**
* @internal
Expand All @@ -30,7 +30,7 @@ export class PrimitiveChunk {
indices: Uint16Array;

updateVertexStart = Number.MAX_SAFE_INTEGER;
updateVertexLength = Number.MIN_SAFE_INTEGER;
updateVertexEnd = Number.MIN_SAFE_INTEGER;
updateIndexLength = 0;

vertexFreeAreas: Array<VertexArea>;
Expand Down Expand Up @@ -90,18 +90,18 @@ export class PrimitiveChunk {
uploadBuffer(): void {
// Set data option use Discard, or will resulted in performance slowdown when open antialias and cross-rendering of 3D and 2D elements.
// Device: iphone X(16.7.2)、iphone 15 pro max(17.1.1)、iphone XR(17.1.2) etc.
const { primitive, updateVertexStart, updateVertexLength } = this;
if (updateVertexStart !== Number.MAX_SAFE_INTEGER && updateVertexLength !== Number.MIN_SAFE_INTEGER) {
const { primitive, updateVertexStart, updateVertexEnd } = this;
if (updateVertexStart !== Number.MAX_SAFE_INTEGER && updateVertexEnd !== Number.MIN_SAFE_INTEGER) {
primitive.vertexBufferBindings[0].buffer.setData(
this.vertices,
updateVertexStart * 4,
updateVertexStart,
updateVertexLength,
updateVertexEnd - updateVertexStart,
SetDataOptions.Discard
);

this.updateVertexStart = Number.MAX_SAFE_INTEGER;
this.updateVertexLength = Number.MIN_SAFE_INTEGER;
this.updateVertexEnd = Number.MIN_SAFE_INTEGER;
}

primitive.indexBufferBinding.buffer.setData(this.indices, 0, 0, this.updateIndexLength, SetDataOptions.Discard);
Expand Down Expand Up @@ -131,7 +131,6 @@ export class PrimitiveChunk {
return newArea;
} else if (size === needSize) {
areas.splice(i, 1);
pool.return(area);
return area;
}
}
Expand Down
Loading