diff --git a/cocos/core/gfx/webgl/webgl-commands.ts b/cocos/core/gfx/webgl/webgl-commands.ts index 7b28562813..d1d5c73f33 100644 --- a/cocos/core/gfx/webgl/webgl-commands.ts +++ b/cocos/core/gfx/webgl/webgl-commands.ts @@ -2625,17 +2625,21 @@ export function WebGLCmdFuncDraw (device: WebGLDevice, drawInfo: GFXDrawInfo) { const subDrawInfo = gpuInputAssembler.gpuIndirectBuffer.indirects[j]; const gpuBuffer = gpuInputAssembler.gpuIndexBuffer; if (subDrawInfo.instanceCount && ia) { - if (gpuBuffer && subDrawInfo.indexCount > 0) { - const offset = subDrawInfo.firstIndex * gpuBuffer.stride; - ia.drawElementsInstancedANGLE(glPrimitive, subDrawInfo.indexCount, - gpuInputAssembler.glIndexType, offset, subDrawInfo.instanceCount); + if (gpuBuffer) { + if (subDrawInfo.indexCount > 0) { + const offset = subDrawInfo.firstIndex * gpuBuffer.stride; + ia.drawElementsInstancedANGLE(glPrimitive, subDrawInfo.indexCount, + gpuInputAssembler.glIndexType, offset, subDrawInfo.instanceCount); + } } else { ia.drawArraysInstancedANGLE(glPrimitive, subDrawInfo.firstVertex, subDrawInfo.vertexCount, subDrawInfo.instanceCount); } } else { - if (gpuBuffer && subDrawInfo.indexCount > 0) { - const offset = subDrawInfo.firstIndex * gpuBuffer.stride; - gl.drawElements(glPrimitive, subDrawInfo.indexCount, gpuInputAssembler.glIndexType, offset); + if (gpuBuffer) { + if (subDrawInfo.indexCount > 0) { + const offset = subDrawInfo.firstIndex * gpuBuffer.stride; + gl.drawElements(glPrimitive, subDrawInfo.indexCount, gpuInputAssembler.glIndexType, offset); + } } else { gl.drawArrays(glPrimitive, subDrawInfo.firstVertex, subDrawInfo.vertexCount); } @@ -2644,17 +2648,21 @@ export function WebGLCmdFuncDraw (device: WebGLDevice, drawInfo: GFXDrawInfo) { } else { const gpuBuffer = gpuInputAssembler.gpuIndexBuffer; if (drawInfo.instanceCount && ia) { - if (gpuBuffer && drawInfo.indexCount > 0) { - const offset = drawInfo.firstIndex * gpuBuffer.stride; - ia.drawElementsInstancedANGLE(glPrimitive, drawInfo.indexCount, - gpuInputAssembler.glIndexType, offset, drawInfo.instanceCount); + if (gpuBuffer) { + if (drawInfo.indexCount > 0) { + const offset = drawInfo.firstIndex * gpuBuffer.stride; + ia.drawElementsInstancedANGLE(glPrimitive, drawInfo.indexCount, + gpuInputAssembler.glIndexType, offset, drawInfo.instanceCount); + } } else { ia.drawArraysInstancedANGLE(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount, drawInfo.instanceCount); } } else { - if (gpuBuffer && drawInfo.indexCount > 0) { - const offset = drawInfo.firstIndex * gpuBuffer.stride; - gl.drawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler.glIndexType, offset); + if (gpuBuffer) { + if (drawInfo.indexCount > 0) { + const offset = drawInfo.firstIndex * gpuBuffer.stride; + gl.drawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler.glIndexType, offset); + } } else { gl.drawArrays(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount); } diff --git a/cocos/core/gfx/webgl2/webgl2-commands.ts b/cocos/core/gfx/webgl2/webgl2-commands.ts index 23b73124c2..f3bdca7fba 100644 --- a/cocos/core/gfx/webgl2/webgl2-commands.ts +++ b/cocos/core/gfx/webgl2/webgl2-commands.ts @@ -2621,17 +2621,21 @@ export function WebGL2CmdFuncDraw (device: WebGL2Device, drawInfo: GFXDrawInfo) const subDrawInfo = indirects[k]; const gpuBuffer = gpuInputAssembler.gpuIndexBuffer; if (subDrawInfo.instanceCount) { - if (gpuBuffer && subDrawInfo.indexCount > 0) { - const offset = subDrawInfo.firstIndex * gpuBuffer.stride; - gl.drawElementsInstanced(glPrimitive, subDrawInfo.indexCount, - gpuInputAssembler.glIndexType, offset, subDrawInfo.instanceCount); + if (gpuBuffer) { + if (subDrawInfo.indexCount > 0) { + const offset = subDrawInfo.firstIndex * gpuBuffer.stride; + gl.drawElementsInstanced(glPrimitive, subDrawInfo.indexCount, + gpuInputAssembler.glIndexType, offset, subDrawInfo.instanceCount); + } } else { gl.drawArraysInstanced(glPrimitive, subDrawInfo.firstVertex, subDrawInfo.vertexCount, subDrawInfo.instanceCount); } } else { - if (gpuBuffer && subDrawInfo.indexCount > 0) { - const offset = subDrawInfo.firstIndex * gpuBuffer.stride; - gl.drawElements(glPrimitive, subDrawInfo.indexCount, gpuInputAssembler.glIndexType, offset); + if (gpuBuffer) { + if (subDrawInfo.indexCount > 0) { + const offset = subDrawInfo.firstIndex * gpuBuffer.stride; + gl.drawElements(glPrimitive, subDrawInfo.indexCount, gpuInputAssembler.glIndexType, offset); + } } else { gl.drawArrays(glPrimitive, subDrawInfo.firstVertex, subDrawInfo.vertexCount); } @@ -2639,17 +2643,21 @@ export function WebGL2CmdFuncDraw (device: WebGL2Device, drawInfo: GFXDrawInfo) } } else { if (drawInfo.instanceCount) { - if (gpuInputAssembler.gpuIndexBuffer && drawInfo.indexCount > 0) { - const offset = drawInfo.firstIndex * gpuInputAssembler.gpuIndexBuffer.stride; - gl.drawElementsInstanced(glPrimitive, drawInfo.indexCount, - gpuInputAssembler.glIndexType, offset, drawInfo.instanceCount); + if (gpuInputAssembler.gpuIndexBuffer) { + if (drawInfo.indexCount > 0) { + const offset = drawInfo.firstIndex * gpuInputAssembler.gpuIndexBuffer.stride; + gl.drawElementsInstanced(glPrimitive, drawInfo.indexCount, + gpuInputAssembler.glIndexType, offset, drawInfo.instanceCount); + } } else { gl.drawArraysInstanced(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount, drawInfo.instanceCount); } } else { - if (gpuInputAssembler.gpuIndexBuffer && drawInfo.indexCount > 0) { - const offset = drawInfo.firstIndex * gpuInputAssembler.gpuIndexBuffer.stride; - gl.drawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler.glIndexType, offset); + if (gpuInputAssembler.gpuIndexBuffer) { + if (drawInfo.indexCount > 0) { + const offset = drawInfo.firstIndex * gpuInputAssembler.gpuIndexBuffer.stride; + gl.drawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler.glIndexType, offset); + } } else { gl.drawArrays(glPrimitive, drawInfo.firstVertex, drawInfo.vertexCount); }