import { GfxDevice } from "../platform/GfxPlatform" ; import { GfxRenderCache } from "./GfxRenderCache" ; import { GfxRenderDynamicUniformBuffer } from "./GfxRenderDynamicUniformBuffer" ; import { GfxRenderInst , GfxRenderInstManager } from "./GfxRenderInstManager" ; import { GfxrRenderGraph , GfxrRenderGraphImpl } from "./GfxRenderGraph" ; import { DebugThumbnailDrawer , TextDrawer } from "../helpers/DebugThumbnailHelpers" ; class GfxRenderHelperBase { public renderCache : GfxRenderCache ; public renderCacheOwn : GfxRenderCache | null = null ; public renderGraph : GfxrRenderGraph ; public renderInstManager : GfxRenderInstManager ; public uniformBuffer : GfxRenderDynamicUniformBuffer ; public debugThumbnails : DebugThumbnailDrawer ; constructor ( public device , renderCache = null ) { if ( renderCache === null ) { this . renderCacheOwn = new GfxRenderCache ( device ) ; this . renderCache = this . renderCacheOwn ; } else { this . renderCache = renderCache ; } this . renderGraph = new GfxrRenderGraphImpl ( this . device ) ; this . renderInstManager = new GfxRenderInstManager ( this . renderCache ) ; this . uniformBuffer = new GfxRenderDynamicUniformBuffer ( this . device ) ; this . debugThumbnails = new DebugThumbnailDrawer ( this as unknown as GfxRenderHelper ) ; } public pushTemplateRenderInst ( ) { const template = this . renderInstManager . pushTemplateRenderInst ( ) ; template . setUniformBuffer ( this . uniformBuffer ) ; return template ; } public prepareToRender ( ) { this . uniformBuffer . prepareToRender ( ) ; } public destroy ( ) { if ( this . renderCacheOwn !== null ) this . renderCacheOwn . destroy ( ) ; this . uniformBuffer . destroy ( ) ; this . renderInstManager . destroy ( ) ; this . renderGraph . destroy ( ) ; } public getDebugTextDrawer ( ) { return null ; } public getCache ( ) { return this . renderCache ; } } import { SceneContext } from "../../SceneBase" ; import type { DebugTextDrawer } from "../helpers/DebugTextDrawer" ; class PromiseWithSavedValue < T > { public value : T | null = null ; private completed : boolean = false ; private promise : Promise < T > | null = null ; constructor ( private func ) { } public getValueOrStart ( ) { if ( this . completed ) return this . value ; if ( this . promise === null ) { this . promise = this . func ( ) ; this . promise . then ( ( value ) => { this . value = value ; this . promise = null ; this . completed = true ; } ) ; } return null ; } } export class GfxRenderHelper extends GfxRenderHelperBase { private debugTextDrawer : PromiseWithSavedValue < DebugTextDrawer | null > ; constructor ( device , context = null , renderCache = null ) { super ( device , renderCache ) ; this . debugTextDrawer = new PromiseWithSavedValue < DebugTextDrawer | null > ( async ( ) => { const { makeDebugTextDrawer } = await import ( '../helpers/DebugTextDrawer' ) ; return context !== null ? makeDebugTextDrawer ( context ) : null ; } ) ; } public getDebugTextDrawer ( ) { return this . debugTextDrawer . getValueOrStart ( ) ; } public destroy ( ) { super . destroy ( ) ; this . debugThumbnails . destroy ( ) ; } }