mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
fix instanced buffers hashing (#7240)
This commit is contained in:
@@ -1604,7 +1604,13 @@ export function WebGLCmdFuncBeginRenderPass (
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, gpuFramebuffer.glFramebuffer);
|
||||
cache.glFramebuffer = gpuFramebuffer.glFramebuffer;
|
||||
// render targets are drawn with flipped-Y
|
||||
gfxStateCache.reverseCW = !!gpuFramebuffer.glFramebuffer;
|
||||
const reverseCW = !!gpuFramebuffer.glFramebuffer;
|
||||
if (reverseCW !== gfxStateCache.reverseCW) {
|
||||
gfxStateCache.reverseCW = reverseCW;
|
||||
const isCCW = !device.stateCache.rs.isFrontFaceCCW;
|
||||
gl.frontFace(isCCW ? gl.CCW : gl.CW);
|
||||
device.stateCache.rs.isFrontFaceCCW = isCCW;
|
||||
}
|
||||
}
|
||||
|
||||
if (cache.viewport.left !== renderArea.x ||
|
||||
|
||||
@@ -1830,7 +1830,13 @@ export function WebGL2CmdFuncBeginRenderPass (
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, gpuFramebuffer.glFramebuffer);
|
||||
cache.glFramebuffer = gpuFramebuffer.glFramebuffer;
|
||||
// render targets are drawn with flipped-Y
|
||||
gfxStateCache.reverseCW = !!gpuFramebuffer.glFramebuffer;
|
||||
const reverseCW = !!gpuFramebuffer.glFramebuffer;
|
||||
if (reverseCW !== gfxStateCache.reverseCW) {
|
||||
gfxStateCache.reverseCW = reverseCW;
|
||||
const isCCW = !device.stateCache.rs.isFrontFaceCCW;
|
||||
gl.frontFace(isCCW ? gl.CCW : gl.CW);
|
||||
device.stateCache.rs.isFrontFaceCCW = isCCW;
|
||||
}
|
||||
}
|
||||
|
||||
if (cache.viewport.left !== renderArea.x ||
|
||||
@@ -2045,7 +2051,7 @@ export function WebGL2CmdFuncBindStates (
|
||||
device.stateCache.rs.cullMode = rs.cullMode;
|
||||
}
|
||||
|
||||
const isFrontFaceCCW = gfxStateCache.reverseCW ? !rs.isFrontFaceCCW : rs.isFrontFaceCCW;
|
||||
const isFrontFaceCCW = rs.isFrontFaceCCW !== gfxStateCache.reverseCW; // boolean XOR
|
||||
if (device.stateCache.rs.isFrontFaceCCW !== isFrontFaceCCW) {
|
||||
gl.frontFace(isFrontFaceCCW ? gl.CCW : gl.CW);
|
||||
device.stateCache.rs.isFrontFaceCCW = isFrontFaceCCW;
|
||||
|
||||
@@ -26,21 +26,15 @@ export interface IBatchedItem {
|
||||
hShader: ShaderHandle;
|
||||
}
|
||||
|
||||
const _localBatched = new UBOLocalBatched();
|
||||
|
||||
export class BatchedBuffer {
|
||||
|
||||
private static _buffers = new Map<Pass | number, BatchedBuffer>();
|
||||
private static _buffers = new Map<Pass, Record<number, BatchedBuffer>>();
|
||||
|
||||
public static get (pass: Pass, extraKey?: number) {
|
||||
const hash = extraKey ? pass.hash ^ extraKey : pass.hash;
|
||||
public static get (pass: Pass, extraKey = 0) {
|
||||
const buffers = BatchedBuffer._buffers;
|
||||
if (!buffers.has(hash)) {
|
||||
const buffer = new BatchedBuffer(pass);
|
||||
buffers.set(hash, buffer);
|
||||
return buffer;
|
||||
}
|
||||
return buffers.get(hash)!;
|
||||
if (!buffers.has(pass)) buffers.set(pass, {});
|
||||
const record = buffers.get(pass)!;
|
||||
return record[extraKey] || (record[extraKey] = new BatchedBuffer(pass));
|
||||
}
|
||||
|
||||
public batches: IBatchedItem[] = [];
|
||||
|
||||
@@ -27,17 +27,13 @@ const MAX_CAPACITY = 1024;
|
||||
|
||||
export class InstancedBuffer {
|
||||
|
||||
private static _buffers = new Map<Pass | number, InstancedBuffer>();
|
||||
private static _buffers = new Map<Pass, Record<number, InstancedBuffer>>();
|
||||
|
||||
public static get (pass: Pass, extraKey?: number) {
|
||||
const hash = extraKey ? pass.hash ^ extraKey : pass.hash;
|
||||
public static get (pass: Pass, extraKey = 0) {
|
||||
const buffers = InstancedBuffer._buffers;
|
||||
if (!buffers.has(hash)) {
|
||||
const buffer = new InstancedBuffer(pass);
|
||||
buffers.set(hash, buffer);
|
||||
return buffer;
|
||||
}
|
||||
return buffers.get(hash)!;
|
||||
if (!buffers.has(pass)) buffers.set(pass, {});
|
||||
const record = buffers.get(pass)!;
|
||||
return record[extraKey] || (record[extraKey] = new InstancedBuffer(pass));
|
||||
}
|
||||
|
||||
public instances: IInstancedItem[] = [];
|
||||
|
||||
Reference in New Issue
Block a user