mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
fix indirect buffer bug
This commit is contained in:
@@ -394,8 +394,6 @@ export class WebGLCmdDraw extends WebGLCmdObject {
|
||||
firstInstance: 0,
|
||||
};
|
||||
|
||||
public gpuIndirectBuffer: WebGLGPUBuffer | null = null;
|
||||
|
||||
constructor () {
|
||||
super(WebGLCmd.DRAW);
|
||||
}
|
||||
@@ -1886,7 +1884,7 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web
|
||||
case WebGLCmd.DRAW: {
|
||||
const cmd3: WebGLCmdDraw = cmdPackage.drawCmds.array[cmdId];
|
||||
if (gpuInputAssembler && gpuShader) {
|
||||
if (!cmd3.gpuIndirectBuffer) {
|
||||
if (!gpuInputAssembler.gpuIndirectBuffer) {
|
||||
const drawInfo = cmd3.drawInfo as IGFXDrawInfo;
|
||||
|
||||
const gpuBuffer = gpuInputAssembler.gpuIndexBuffer;
|
||||
@@ -1897,8 +1895,8 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web
|
||||
gl.drawArrays(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount);
|
||||
}
|
||||
} else {
|
||||
if (cmd3.gpuIndirectBuffer) {
|
||||
const drawInfos = (cmd3.gpuIndirectBuffer.buffer as IGFXIndirectBuffer).drawInfos;
|
||||
if (gpuInputAssembler.gpuIndirectBuffer) {
|
||||
const drawInfos = (gpuInputAssembler.gpuIndirectBuffer.buffer as IGFXIndirectBuffer).drawInfos;
|
||||
for (const drawInfo of drawInfos) {
|
||||
const gpuBuffer = gpuInputAssembler.gpuIndexBuffer;
|
||||
if (gpuBuffer && drawInfo.indexCount > 0) {
|
||||
|
||||
@@ -973,12 +973,18 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
}
|
||||
}
|
||||
|
||||
let gpuIndirectBuffer: WebGLGPUBuffer | null = null;
|
||||
|
||||
if (info.indirectBuffer !== undefined) {
|
||||
gpuIndirectBuffer = (info.indirectBuffer as WebGLGFXBuffer).gpuBuffer;
|
||||
}
|
||||
|
||||
const gpuInputAssembler: WebGLGPUInputAssembler = {
|
||||
objType: WebGLGPUObjectType.INPUT_ASSEMBLER,
|
||||
attributes: info.attributes,
|
||||
gpuVertexBuffers,
|
||||
gpuIndexBuffer,
|
||||
gpuIndirectBuffers: [],
|
||||
gpuIndirectBuffer,
|
||||
|
||||
glAttribs: [],
|
||||
glIndexType,
|
||||
|
||||
@@ -270,7 +270,7 @@ export class WebGLGPUInputAssembler extends WebGLGPUObject {
|
||||
public attributes: IGFXInputAttribute[] = [];
|
||||
public gpuVertexBuffers: WebGLGPUBuffer[] = [];
|
||||
public gpuIndexBuffer: WebGLGPUBuffer | null = null;
|
||||
public gpuIndirectBuffers: IWebGLIndirectBuffer[] = [];
|
||||
public gpuIndirectBuffer: WebGLGPUBuffer | null = null;
|
||||
|
||||
public glAttribs: WebGLAttrib[] = [];
|
||||
public glIndexType: GLenum = 0;
|
||||
|
||||
@@ -40,6 +40,10 @@ export class WebGLGFXInputAssembler extends GFXInputAssembler {
|
||||
this._vertexCount = vertBuff.size / vertBuff.stride;
|
||||
}
|
||||
|
||||
if (info.indirectBuffer !== undefined) {
|
||||
this._indirectBuffer = info.indirectBuffer;
|
||||
}
|
||||
|
||||
this._gpuInputAssembler = this.webGLDevice.emitCmdCreateGPUInputAssembler(info);
|
||||
this._status = GFXStatus.SUCCESS;
|
||||
|
||||
@@ -55,17 +59,12 @@ export class WebGLGFXInputAssembler extends GFXInputAssembler {
|
||||
}
|
||||
|
||||
public extractCmdDraw (cmd: WebGLCmdDraw) {
|
||||
if (!this._indirectBuffer) {
|
||||
cmd.drawInfo.vertexCount = this._vertexCount;
|
||||
cmd.drawInfo.firstVertex = this._firstVertex;
|
||||
cmd.drawInfo.indexCount = this._indexCount;
|
||||
cmd.drawInfo.firstIndex = this._firstIndex;
|
||||
cmd.drawInfo.vertexOffset = this._vertexOffset;
|
||||
cmd.drawInfo.instanceCount = this._instanceCount;
|
||||
cmd.drawInfo.firstInstance = this._firstInstance;
|
||||
cmd.gpuIndirectBuffer = null;
|
||||
} else {
|
||||
cmd.gpuIndirectBuffer = (this._indirectBuffer as WebGLGFXBuffer).gpuBuffer;
|
||||
}
|
||||
cmd.drawInfo.vertexCount = this._vertexCount;
|
||||
cmd.drawInfo.firstVertex = this._firstVertex;
|
||||
cmd.drawInfo.indexCount = this._indexCount;
|
||||
cmd.drawInfo.firstIndex = this._firstIndex;
|
||||
cmd.drawInfo.vertexOffset = this._vertexOffset;
|
||||
cmd.drawInfo.instanceCount = this._instanceCount;
|
||||
cmd.drawInfo.firstInstance = this._firstInstance;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user