Update to use changed modules
This commit is contained in:
parent
f2a7107a67
commit
eaeeebfca2
2 changed files with 42 additions and 40 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { UniversalRenderingContext } from '../universal-rendering-context';
|
||||||
import { enableExtension } from './enable-extension';
|
import { enableExtension } from './enable-extension';
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
|
@ -15,7 +16,7 @@ export class WebGlStopwatch {
|
||||||
private timerExtension: any;
|
private timerExtension: any;
|
||||||
private timerQuery?: WebGLQuery;
|
private timerQuery?: WebGLQuery;
|
||||||
|
|
||||||
constructor(private readonly gl: WebGL2RenderingContext) {
|
constructor(private readonly gl: WebGL2RenderingContext & UniversalRenderingContext) {
|
||||||
this.timerExtension = enableExtension(gl, 'EXT_disjoint_timer_query_webgl2');
|
this.timerExtension = enableExtension(gl, 'EXT_disjoint_timer_query_webgl2');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ import { Drawable } from '../../../drawables/drawable';
|
||||||
import { DrawableDescriptor } from '../../../drawables/drawable-descriptor';
|
import { DrawableDescriptor } from '../../../drawables/drawable-descriptor';
|
||||||
import { LightDrawable } from '../../../drawables/lights/light-drawable';
|
import { LightDrawable } from '../../../drawables/lights/light-drawable';
|
||||||
import { colorToString } from '../../../helper/color-to-string';
|
import { colorToString } from '../../../helper/color-to-string';
|
||||||
import { msToString } from '../../../helper/ms-to-string';
|
|
||||||
import { DefaultFrameBuffer } from '../../graphics-library/frame-buffer/default-frame-buffer';
|
import { DefaultFrameBuffer } from '../../graphics-library/frame-buffer/default-frame-buffer';
|
||||||
import { IntermediateFrameBuffer } from '../../graphics-library/frame-buffer/intermediate-frame-buffer';
|
import { IntermediateFrameBuffer } from '../../graphics-library/frame-buffer/intermediate-frame-buffer';
|
||||||
|
import { getHardwareInfo } from '../../graphics-library/helper/get-hardware-info';
|
||||||
import { WebGlStopwatch } from '../../graphics-library/helper/stopwatch';
|
import { WebGlStopwatch } from '../../graphics-library/helper/stopwatch';
|
||||||
import { ParallelCompiler } from '../../graphics-library/parallel-compiler';
|
import { ParallelCompiler } from '../../graphics-library/parallel-compiler';
|
||||||
import { ColorTexture } from '../../graphics-library/texture/color-texture';
|
import { ColorTexture } from '../../graphics-library/texture/color-texture';
|
||||||
|
|
@ -17,8 +17,6 @@ import {
|
||||||
getUniversalRenderingContext,
|
getUniversalRenderingContext,
|
||||||
UniversalRenderingContext,
|
UniversalRenderingContext,
|
||||||
} from '../../graphics-library/universal-rendering-context';
|
} from '../../graphics-library/universal-rendering-context';
|
||||||
import { FpsAutoscaler } from '../fps-autoscaler';
|
|
||||||
import { Insights } from '../insights';
|
|
||||||
import { DistanceRenderPass } from '../render-pass/distance-render-pass';
|
import { DistanceRenderPass } from '../render-pass/distance-render-pass';
|
||||||
import { LightsRenderPass } from '../render-pass/lights-render-pass';
|
import { LightsRenderPass } from '../render-pass/lights-render-pass';
|
||||||
import { defaultRuntimeSettings } from '../settings/default-runtime-settings';
|
import { defaultRuntimeSettings } from '../settings/default-runtime-settings';
|
||||||
|
|
@ -35,6 +33,7 @@ import lightsVertexShader100 from '../shaders/shading-vs-100.glsl';
|
||||||
import lightsVertexShader from '../shaders/shading-vs.glsl';
|
import lightsVertexShader from '../shaders/shading-vs.glsl';
|
||||||
import { UniformsProvider } from '../uniforms-provider';
|
import { UniformsProvider } from '../uniforms-provider';
|
||||||
import { Renderer } from './renderer';
|
import { Renderer } from './renderer';
|
||||||
|
import { RendererInfo } from './renderer-info';
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export class RendererImplementation implements Renderer {
|
export class RendererImplementation implements Renderer {
|
||||||
|
|
@ -46,7 +45,6 @@ export class RendererImplementation implements Renderer {
|
||||||
private lightingFrameBuffer: DefaultFrameBuffer;
|
private lightingFrameBuffer: DefaultFrameBuffer;
|
||||||
private lightsPass: LightsRenderPass;
|
private lightsPass: LightsRenderPass;
|
||||||
private palette!: PaletteTexture;
|
private palette!: PaletteTexture;
|
||||||
private autoscaler: FpsAutoscaler;
|
|
||||||
|
|
||||||
private textures: Array<Texture> = [];
|
private textures: Array<Texture> = [];
|
||||||
|
|
||||||
|
|
@ -59,26 +57,15 @@ export class RendererImplementation implements Renderer {
|
||||||
},
|
},
|
||||||
tileMultiplier: (v) => (this.distancePass.tileMultiplier = v),
|
tileMultiplier: (v) => (this.distancePass.tileMultiplier = v),
|
||||||
isWorldInverted: (v) => (this.distancePass.isWorldInverted = v),
|
isWorldInverted: (v) => (this.distancePass.isWorldInverted = v),
|
||||||
textures: (v: { [textureName: string]: TexImageSource | TextureWithOptions }) => {
|
distanceRenderScale: (v) => {
|
||||||
this.textures.forEach((t) => t.destroy());
|
this.distanceFieldFrameBuffer.renderScale = v;
|
||||||
this.textures = [];
|
this.gl.insights.renderPasses.distance.renderScale = v;
|
||||||
|
|
||||||
let id = 3;
|
|
||||||
for (const key in v) {
|
|
||||||
this.uniformsProvider.textures[key] = id;
|
|
||||||
let texture: Texture;
|
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(v[key], 'source')) {
|
|
||||||
texture = new Texture(this.gl, id++, (v[key] as TextureWithOptions).overrides);
|
|
||||||
texture.setImage((v[key] as TextureWithOptions).source);
|
|
||||||
} else {
|
|
||||||
texture = new Texture(this.gl, id++);
|
|
||||||
texture.setImage(v[key] as TexImageSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.textures.push(texture);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
lightsRenderScale: (v) => {
|
||||||
|
this.lightingFrameBuffer.renderScale = v;
|
||||||
|
this.gl.insights.renderPasses.lights.renderScale = v;
|
||||||
|
},
|
||||||
|
textures: this.setTextures.bind(this),
|
||||||
ambientLight: (v) => (this.uniformsProvider.ambientLight = v),
|
ambientLight: (v) => (this.uniformsProvider.ambientLight = v),
|
||||||
lightCutoffDistance: (v) => (this.lightsPass.lightCutoffDistance = v),
|
lightCutoffDistance: (v) => (this.lightsPass.lightCutoffDistance = v),
|
||||||
colorPalette: (v) => this.palette.setPalette(v),
|
colorPalette: (v) => this.palette.setPalette(v),
|
||||||
|
|
@ -115,11 +102,9 @@ export class RendererImplementation implements Renderer {
|
||||||
vec2.fromValues(canvas.clientWidth, canvas.clientHeight)
|
vec2.fromValues(canvas.clientWidth, canvas.clientHeight)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.autoscaler = new FpsAutoscaler({
|
const hardwareInfo = getHardwareInfo(this.gl);
|
||||||
distanceRenderScale: (v) =>
|
this.gl.insights.renderer = hardwareInfo?.renderer;
|
||||||
(this.distanceFieldFrameBuffer.renderScale = v as number),
|
this.gl.insights.vendor = hardwareInfo?.vendor;
|
||||||
finalRenderScale: (v) => (this.lightingFrameBuffer.renderScale = v as number),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initialize(settingsOverrides: Partial<StartupSettings>): Promise<void> {
|
public async initialize(settingsOverrides: Partial<StartupSettings>): Promise<void> {
|
||||||
|
|
@ -156,6 +141,7 @@ export class RendererImplementation implements Renderer {
|
||||||
compiler,
|
compiler,
|
||||||
{
|
{
|
||||||
shadowTraceCount: settings.shadowTraceCount.toString(),
|
shadowTraceCount: settings.shadowTraceCount.toString(),
|
||||||
|
intensityInsideRatio: settings.lightPenetrationRatio,
|
||||||
backgroundColor: colorToString(settings.backgroundColor),
|
backgroundColor: colorToString(settings.backgroundColor),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -173,8 +159,29 @@ export class RendererImplementation implements Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get insights(): any {
|
public get insights(): RendererInfo {
|
||||||
return Insights.values;
|
return this.gl.insights;
|
||||||
|
}
|
||||||
|
|
||||||
|
private setTextures(v: { [textureName: string]: TexImageSource | TextureWithOptions }) {
|
||||||
|
this.textures.forEach((t) => t.destroy());
|
||||||
|
this.textures = [];
|
||||||
|
|
||||||
|
let id = 3;
|
||||||
|
for (const key in v) {
|
||||||
|
this.uniformsProvider.textures[key] = id;
|
||||||
|
let texture: Texture;
|
||||||
|
|
||||||
|
if (Object.prototype.hasOwnProperty.call(v[key], 'source')) {
|
||||||
|
texture = new Texture(this.gl, id++, (v[key] as TextureWithOptions).overrides);
|
||||||
|
texture.setImage((v[key] as TextureWithOptions).source);
|
||||||
|
} else {
|
||||||
|
texture = new Texture(this.gl, id++);
|
||||||
|
texture.setImage(v[key] as TexImageSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.textures.push(texture);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static hasSdf(descriptor: DrawableDescriptor) {
|
private static hasSdf(descriptor: DrawableDescriptor) {
|
||||||
|
|
@ -191,20 +198,13 @@ export class RendererImplementation implements Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public autoscaleQuality(deltaTime: DOMHighResTimeStamp) {
|
|
||||||
this.autoscaler.autoscale(deltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public renderDrawables() {
|
public renderDrawables() {
|
||||||
if (this.stopwatch) {
|
if (this.stopwatch) {
|
||||||
if (this.stopwatch.isReady) {
|
if (this.stopwatch.isReady) {
|
||||||
this.stopwatch.start();
|
this.stopwatch.start();
|
||||||
} else {
|
} else {
|
||||||
this.stopwatch.tryGetResults();
|
this.stopwatch.tryGetResults();
|
||||||
Insights.setValue(
|
this.gl.insights.gpuRenderTimeInMilliseconds = this.stopwatch.resultsInMilliSeconds;
|
||||||
'GPU render time',
|
|
||||||
msToString(this.stopwatch.resultsInMilliSeconds)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,7 +255,8 @@ export class RendererImplementation implements Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public get canvasSize(): vec2 {
|
public get canvasSize(): vec2 {
|
||||||
return vec2.fromValues(this.canvas.clientWidth, this.canvas.clientHeight);
|
const { width, height } = this.canvas.getBoundingClientRect();
|
||||||
|
return vec2.fromValues(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy(): void {
|
public destroy(): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue