Get draw calls num from WebGLRenderer

Hello,

Is there any way to get draw calls number for WebGLRenderer?
For Phaser 2 I was able to get it like this this.game.renderer.renderSession.drawCount so I wonder if we have something like this in v3.

Thanks in advance!

I’ve generally seen Rich recommend using https://spector.babylonjs.com/ to debug webgl related issues. I think it will have the information you need.

2 Likes

Thanks for the tip. I have been using this tool before. But it is not quite what I need.
I just wanted to make very basic panel with FPS and Draw Calls to quick so I can quickly evaluate which scenes needs to be optimized.

So I have ended up with solution below (Typescript). Phaser uses drawArrays to render so I’ve replaced original WebGLRenderingContext method with my hook. And I reset draw calls counter on POST_STEP event which is last event before rendering starts.

let renderer = this.scene.sys.renderer
if (renderer instanceof Phaser.Renderer.WebGL.WebGLRenderer) {
	this.scene.game.events.on(Phaser.Core.Events.POST_STEP, this.resetDrawCalls, this)

	let gl = WebGLRenderingContext.prototype
	gl.updateDrawCallsNum = this.incrementDrawCalls.bind(this)
	gl.realDrawArrays = WebGLRenderingContext.prototype.drawArrays
	gl.drawArrays = function(mode: GLenum, first: GLint, count: GLsizei) {
	    this.updateDrawCallsNum()
	    this.realDrawArrays(mode, first, count)
	}

}

UPD: This approach doesn’t work when Spector extension is enabled. I didn’t check it thoroughly but my guess is that Spector use hooks like these under the hood and they conflict with each other.

Hello, I tried your approach, but no matter how many display objects with different textures I add to the scene, the dc display is always 1, I don’t know where the problem is?