From fc645bd8dc8662eacd94c0b258324ef1933828ae Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Tue, 2 Apr 2019 18:16:16 +0800 Subject: [PATCH] add fps calc --- cocos/core/root.ts | 18 ++++++++++++++++++ cocos/gfx/webgl/webgl-commands.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 200023c092..ee81017df1 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -56,6 +56,14 @@ export class Root { return this._frameTime; } + public get frameCount (): number { + return this._frameCount; + } + + public get fps (): number { + return this._fps; + } + public _createSceneFun; public _createViewFun; @@ -68,6 +76,9 @@ export class Root { private _scenes: RenderScene[] = []; private _views: RenderView[] = []; private _frameTime: number = 0; + private _fpsTime: number = 0; + private _frameCount: number = 0; + private _fps: number = 0; constructor (device: GFXDevice) { this._device = device; @@ -152,6 +163,13 @@ export class Root { public frameMove (deltaTime: number) { this._frameTime = deltaTime; + ++this._frameCount; + this._fpsTime += this._frameTime; + if (this._fpsTime > 1.0) { + this._fps = this._frameCount; + this._frameCount = 0; + this._fpsTime = 0.0; + } for (const view of this._views) { if (view.isEnable && view.window === this._mainWindow) { diff --git a/cocos/gfx/webgl/webgl-commands.ts b/cocos/gfx/webgl/webgl-commands.ts index 227b32646e..a3179804de 100644 --- a/cocos/gfx/webgl/webgl-commands.ts +++ b/cocos/gfx/webgl/webgl-commands.ts @@ -1441,7 +1441,7 @@ export function WebGLCmdFuncExecuteCmds (device: WebGLGFXDevice, cmdPackage: Web switch (curGPURenderPass.depthStencilAttachment.stencilLoadOp) { case GFXLoadOp.LOAD: break; // GL default behaviour case GFXLoadOp.CLEAR: { - if (cmd0.clearFlag & GFXClearFlag.DEPTH) { + if (cmd0.clearFlag & GFXClearFlag.STENCIL) { if (!cache.dss.stencilWriteMaskFront) { gl.stencilMaskSeparate(WebGLRenderingContext.FRONT, 0xFFFFFFFF); }