Skip to content

Commit

Permalink
Revert "remove useless code (#15682)" (#15683)
Browse files Browse the repository at this point in the history
This reverts commit 9f03504.
  • Loading branch information
SantyWang authored Jul 11, 2023
1 parent 9f03504 commit b318b39
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
2 changes: 2 additions & 0 deletions cocos/2d/assembler/label/ttf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const ttf: IAssembler = {
Color.toArray(vData, WHITE, offset);
offset += 9;
}
renderData.vertexRow = 2;
renderData.vertexCol = 2;
renderData.chunk.setIndexBuffer(QUAD_INDICES);
return renderData;
},
Expand Down
2 changes: 2 additions & 0 deletions cocos/2d/assembler/sprite/bar-filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ export const barFilled: IAssembler = {
// 0-4 for local vertex
renderData.dataLength = 4;
renderData.resize(4, 6);
renderData.vertexRow = 2;
renderData.vertexCol = 2;
renderData.chunk.setIndexBuffer(QUAD_INDICES);

// not need
Expand Down
45 changes: 27 additions & 18 deletions cocos/2d/assembler/sprite/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const simple: IAssembler = {
const renderData = sprite.requestRenderData();
renderData.dataLength = 4;
renderData.resize(4, 6);
renderData.vertexRow = 2;
renderData.vertexCol = 2;
renderData.chunk.setIndexBuffer(QUAD_INDICES);
return renderData;
},
Expand Down Expand Up @@ -104,29 +106,36 @@ export const simple: IAssembler = {
}

// quick version
const bid = chunk.bufferId;
const vidOrigin = chunk.vertexOffset;
const meshBuffer = chunk.meshBuffer;
const ib = chunk.meshBuffer.iData;
let indexOffset = meshBuffer.indexOffset;

const vid = vidOrigin;

// left bottom
ib[indexOffset++] = vid;
// right bottom
ib[indexOffset++] = vid + 1;
// left top
ib[indexOffset++] = vid + 2;

// right bottom
ib[indexOffset++] = vid + 1;
// right top
ib[indexOffset++] = vid + 3;
// left top
ib[indexOffset++] = vid + 2;

// IndexOffset should add 6 when vertices of a rect are visited.
meshBuffer.indexOffset += 6;
// rect count = vertex count - 1
for (let curRow = 0; curRow < renderData.vertexRow - 1; curRow++) {
for (let curCol = 0; curCol < renderData.vertexCol - 1; curCol++) {
// vid is the index of the left bottom vertex in each rect.
const vid = vidOrigin + curRow * renderData.vertexCol + curCol;

// left bottom
ib[indexOffset++] = vid;
// right bottom
ib[indexOffset++] = vid + 1;
// left top
ib[indexOffset++] = vid + renderData.vertexCol;

// right bottom
ib[indexOffset++] = vid + 1;
// right top
ib[indexOffset++] = vid + 1 + renderData.vertexCol;
// left top
ib[indexOffset++] = vid + renderData.vertexCol;

// IndexOffset should add 6 when vertices of a rect are visited.
meshBuffer.indexOffset += 6;
}
}
// slow version
// renderer.switchBufferAccessor().appendIndices(chunk);
},
Expand Down
8 changes: 5 additions & 3 deletions cocos/2d/assembler/sprite/sliced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const sliced: IAssembler = {
// 0-4 for local vertex
renderData.dataLength = 16;
renderData.resize(16, 54);
renderData.vertexRow = 4;
renderData.vertexCol = 4;
this.QUAD_INDICES = new Uint16Array(54);
this.createQuadIndices(4, 4);
renderData.chunk.setIndexBuffer(this.QUAD_INDICES);
Expand Down Expand Up @@ -138,9 +140,9 @@ export const sliced: IAssembler = {
tempRenderData[3].x = width - appX;
tempRenderData[3].y = height - appY;

for (let curRow = 0; curRow < 4; curRow++) {
for (let curCol = 0; curCol < 4; curCol++) {
const curIndex = curRow * 4 + curCol;
for (let curRow = 0; curRow < renderData.vertexRow; curRow++) {
for (let curCol = 0; curCol < renderData.vertexCol; curCol++) {
const curIndex = curRow * renderData.vertexCol + curCol;
if (curIndex < renderData.dataLength
&& curRow < tempRenderData.length
&& curCol < tempRenderData.length) {
Expand Down
3 changes: 3 additions & 0 deletions cocos/2d/renderer/render-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ export class RenderData extends BaseRenderData {
protected _accessor: StaticVBAccessor = null!;
get accessor () { return this._accessor; }

public vertexRow = 1;
public vertexCol = 1;

public constructor (vertexFormat = vfmtPosUvColor, accessor?: StaticVBAccessor) {
super(vertexFormat);
if (!accessor) {
Expand Down

0 comments on commit b318b39

Please sign in to comment.