fix indirect buffer bug

This commit is contained in:
jerrywwl
2019-01-15 17:07:19 +08:00
parent 10a43ae6d1
commit 6d17dbe55a
4 changed files with 22 additions and 19 deletions
+3 -5
View File
@@ -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) {
+7 -1
View File
@@ -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,
+1 -1
View File
@@ -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;
+11 -12
View File
@@ -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;
}
}