diff --git a/src/graphics/graphics-library/helper/stopwatch.ts b/src/graphics/graphics-library/helper/stopwatch.ts index a3843ad..9b73e19 100644 --- a/src/graphics/graphics-library/helper/stopwatch.ts +++ b/src/graphics/graphics-library/helper/stopwatch.ts @@ -49,7 +49,6 @@ export class WebGlStopwatch { this.gl.QUERY_RESULT_AVAILABLE ); const disjoint = this.gl.getParameter(this.timerExtension.GPU_DISJOINT_EXT); - if (available && !disjoint) { this.resultsInNanoSeconds = this.gl.getQueryParameter( this.timerQuery!, @@ -70,6 +69,10 @@ export class WebGlStopwatch { return this.state == StopwatchState.running; } + public get isWaitingForResults(): boolean { + return this.state == StopwatchState.waitingForResults; + } + public get resultsInMilliSeconds(): number { return this.resultsInNanoSeconds! / 1000 / 1000; } diff --git a/src/graphics/rendering/renderer/renderer-implementation.ts b/src/graphics/rendering/renderer/renderer-implementation.ts index e806662..f361bed 100644 --- a/src/graphics/rendering/renderer/renderer-implementation.ts +++ b/src/graphics/rendering/renderer/renderer-implementation.ts @@ -139,10 +139,12 @@ export class RendererImplementation implements Renderer { await compiler.compilePrograms(); await Promise.all(promises); - try { - this.stopwatch = new WebGlStopwatch(this.gl); - } catch { - // no problem + if (settings.enableStopwatch) { + try { + this.stopwatch = new WebGlStopwatch(this.gl); + } catch { + // no problem + } } } diff --git a/src/graphics/rendering/settings/default-startup-settings.ts b/src/graphics/rendering/settings/default-startup-settings.ts index 5400c08..d9e2aeb 100644 --- a/src/graphics/rendering/settings/default-startup-settings.ts +++ b/src/graphics/rendering/settings/default-startup-settings.ts @@ -7,4 +7,5 @@ export const defaultStartupSettings: StartupSettings = { shadowTraceCount: 16, paletteSize: 256, ignoreWebGL2: false, + enableStopwatch: true, }; diff --git a/src/graphics/rendering/settings/startup-settings.ts b/src/graphics/rendering/settings/startup-settings.ts index cee656a..ca85185 100644 --- a/src/graphics/rendering/settings/startup-settings.ts +++ b/src/graphics/rendering/settings/startup-settings.ts @@ -5,6 +5,14 @@ * The default values for StartupSettings can be found in [[defaultStartupSettings]]. */ export interface StartupSettings { + /** + * Creates a stopwatch used for measuring the GPU render time + * when its required extension is available. + * + * You should only have one renderer with enabled stopwatch. + */ + enableStopwatch: boolean; + /** * The raytracing algorithm used for shadows requires a step count. * Sensible values for this are between 8 and 32.