statisticsTabComponent.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import * as React from "react";
  2. import { PaneComponent, IPaneComponentProps } from "../paneComponent";
  3. import { TextLineComponent } from "../lines/textLineComponent";
  4. import { LineContainerComponent } from "../lineContainerComponent";
  5. import { SceneInstrumentation, EngineInstrumentation, Nullable } from "babylonjs";
  6. import { ValueLineComponent } from "../lines/valueLineComponent";
  7. import { BooleanLineComponent } from "../lines/booleanLineComponent";
  8. export class StatisticsTabComponent extends PaneComponent {
  9. private _sceneInstrumentation: Nullable<SceneInstrumentation>;
  10. private _engineInstrumentation: Nullable<EngineInstrumentation>;
  11. private _timerIntervalId: number;
  12. constructor(props: IPaneComponentProps) {
  13. super(props);
  14. }
  15. componentWillMount() {
  16. const scene = this.props.scene;
  17. if (!scene) {
  18. return;
  19. }
  20. this._sceneInstrumentation = new BABYLON.SceneInstrumentation(scene);
  21. this._sceneInstrumentation.captureActiveMeshesEvaluationTime = true;
  22. this._sceneInstrumentation.captureRenderTargetsRenderTime = true;
  23. this._sceneInstrumentation.captureFrameTime = true;
  24. this._sceneInstrumentation.captureRenderTime = true;
  25. this._sceneInstrumentation.captureInterFrameTime = true;
  26. this._sceneInstrumentation.captureParticlesRenderTime = true;
  27. this._sceneInstrumentation.captureSpritesRenderTime = true;
  28. this._sceneInstrumentation.capturePhysicsTime = true;
  29. this._sceneInstrumentation.captureAnimationsTime = true;
  30. this._engineInstrumentation = new BABYLON.EngineInstrumentation(scene.getEngine());
  31. this._engineInstrumentation.captureGPUFrameTime = true;
  32. this._timerIntervalId = window.setInterval(() => this.forceUpdate(), 500);
  33. }
  34. componentWillUnmount() {
  35. if (this._sceneInstrumentation) {
  36. this._sceneInstrumentation.dispose();
  37. this._sceneInstrumentation = null;
  38. }
  39. if (this._engineInstrumentation) {
  40. this._engineInstrumentation.dispose();
  41. this._engineInstrumentation = null;
  42. }
  43. window.clearInterval(this._timerIntervalId);
  44. }
  45. render() {
  46. const scene = this.props.scene;
  47. if (!scene || !this._sceneInstrumentation || !this._engineInstrumentation) {
  48. return null;
  49. }
  50. const engine = scene.getEngine();
  51. const sceneInstrumentation = this._sceneInstrumentation;
  52. const engineInstrumentation = this._engineInstrumentation;
  53. const caps = engine.getCaps();
  54. return (
  55. <div className="pane">
  56. <TextLineComponent label="Version" value={BABYLON.Engine.Version} color="rgb(113, 159, 255)" />
  57. <ValueLineComponent label="FPS" value={engine.getFps()} fractionDigits={0} />
  58. <LineContainerComponent title="COUNT">
  59. <TextLineComponent label="Total meshes" value={scene.meshes.length.toString()} />
  60. <TextLineComponent label="Active meshes" value={scene.getActiveMeshes().length.toString()} />
  61. <TextLineComponent label="Active indices" value={scene.getActiveIndices().toString()} />
  62. <TextLineComponent label="Active faces" value={(scene.getActiveIndices() / 3).toString()} />
  63. <TextLineComponent label="Active bones" value={scene.getActiveBones().toString()} />
  64. <TextLineComponent label="Active particles" value={scene.getActiveParticles().toString()} />
  65. <TextLineComponent label="Draw calls" value={sceneInstrumentation.drawCallsCounter.current.toString()} />
  66. <TextLineComponent label="Texture collisions" value={sceneInstrumentation.textureCollisionsCounter.current.toString()} />
  67. <TextLineComponent label="Total lights" value={scene.lights.length.toString()} />
  68. <TextLineComponent label="Total vertices" value={scene.getTotalVertices().toString()} />
  69. <TextLineComponent label="Total materials" value={scene.materials.length.toString()} />
  70. <TextLineComponent label="Total textures" value={scene.textures.length.toString()} />
  71. </LineContainerComponent>
  72. <LineContainerComponent title="FRAME STEPS DURATION">
  73. <ValueLineComponent label="Absolute FPS" value={1000.0 / this._sceneInstrumentation!.frameTimeCounter.current} fractionDigits={0} />
  74. <ValueLineComponent label="Meshes selection" value={sceneInstrumentation.activeMeshesEvaluationTimeCounter.current} units="ms" />
  75. <ValueLineComponent label="Render targets" value={sceneInstrumentation.renderTargetsRenderTimeCounter.current} units="ms" />
  76. <ValueLineComponent label="Particles" value={sceneInstrumentation.particlesRenderTimeCounter.current} units="ms" />
  77. <ValueLineComponent label="Sprites" value={sceneInstrumentation.spritesRenderTimeCounter.current} units="ms" />
  78. <ValueLineComponent label="Animations" value={sceneInstrumentation.animationsTimeCounter.current} units="ms" />
  79. <ValueLineComponent label="Physics" value={sceneInstrumentation.physicsTimeCounter.current} units="ms" />
  80. <ValueLineComponent label="Render" value={sceneInstrumentation.renderTimeCounter.current} units="ms" />
  81. <ValueLineComponent label="Frame total" value={sceneInstrumentation.frameTimeCounter.current} units="ms" />
  82. <ValueLineComponent label="Inter-frame" value={sceneInstrumentation.interFrameTimeCounter.current} units="ms" />
  83. <ValueLineComponent label="GPU Frame time" value={engineInstrumentation.gpuFrameTimeCounter.current * 0.000001} units="ms" />
  84. <ValueLineComponent label="GPU Frame time (average)" value={engineInstrumentation.gpuFrameTimeCounter.average * 0.000001} units="ms" />
  85. </LineContainerComponent>
  86. <LineContainerComponent title="SYSTEM INFO">
  87. <TextLineComponent label="Resolution" value={engine.getRenderWidth() + "x" + engine.getRenderHeight()} />
  88. <TextLineComponent label="WebGL version" value={engine.webGLVersion.toString()} />
  89. <BooleanLineComponent label="Std derivatives" value={caps.standardDerivatives} />
  90. <BooleanLineComponent label="Compressed textures" value={caps.s3tc !== undefined} />
  91. <BooleanLineComponent label="Hardware instances" value={caps.instancedArrays} />
  92. <BooleanLineComponent label="Texture float" value={caps.textureFloat} />
  93. <BooleanLineComponent label="Texture half-float" value={caps.textureHalfFloat} />
  94. <BooleanLineComponent label="Render to texture float" value={caps.textureFloatRender} />
  95. <BooleanLineComponent label="Render to texture half-float" value={caps.textureHalfFloatRender} />
  96. <BooleanLineComponent label="32bits indices" value={caps.uintIndices} />
  97. <BooleanLineComponent label="Fragment depth" value={caps.fragmentDepthSupported} />
  98. <BooleanLineComponent label="High precision shaders" value={caps.highPrecisionShaderSupported} />
  99. <BooleanLineComponent label="Draw buffers" value={caps.drawBuffersExtension} />
  100. <BooleanLineComponent label="Vertex array object" value={caps.vertexArrayObject} />
  101. <BooleanLineComponent label="Timer query" value={caps.timerQuery !== undefined} />
  102. <BooleanLineComponent label="Stencil" value={engine.isStencilEnable} />
  103. <ValueLineComponent label="Max textures units" value={caps.maxTexturesImageUnits} fractionDigits={0} />
  104. <ValueLineComponent label="Max textures size" value={caps.maxTextureSize} fractionDigits={0} />
  105. <ValueLineComponent label="Max anisotropy" value={caps.maxAnisotropy} fractionDigits={0} />
  106. <TextLineComponent label="Driver" value={engine.getGlInfo().renderer} />
  107. </LineContainerComponent>
  108. </div>
  109. );
  110. }
  111. }