abstractEngine.d.ts 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688
  1. import type { DataArray, FloatArray, ImageSource, IndicesArray, Nullable } from "../types";
  2. import type { PerfCounter } from "../Misc/perfCounter";
  3. import type { PostProcess } from "../PostProcesses/postProcess";
  4. import type { Scene } from "../scene";
  5. import type { IColor4Like, IViewportLike } from "../Maths/math.like";
  6. import type { ICanvas, IImage } from "./ICanvas";
  7. import type { HardwareTextureWrapper } from "../Materials/Textures/hardwareTextureWrapper";
  8. import type { EngineCapabilities } from "./engineCapabilities";
  9. import type { DataBuffer } from "../Buffers/dataBuffer";
  10. import type { RenderTargetWrapper } from "./renderTargetWrapper";
  11. import type { IShaderProcessor } from "./Processors/iShaderProcessor";
  12. import type { ShaderLanguage } from "../Materials/shaderLanguage";
  13. import type { IAudioEngineOptions } from "../Audio/Interfaces/IAudioEngineOptions";
  14. import type { EngineFeatures } from "./engineFeatures";
  15. import type { UniformBuffer } from "../Materials/uniformBuffer";
  16. import type { StorageBuffer } from "../Buffers/storageBuffer";
  17. import type { IEffectCreationOptions, IShaderPath } from "../Materials/effect";
  18. import type { IOfflineProvider } from "../Offline/IOfflineProvider";
  19. import type { IWebRequest } from "../Misc/interfaces/iWebRequest";
  20. import type { IFileRequest } from "../Misc/fileRequest";
  21. import type { Texture } from "../Materials/Textures/texture";
  22. import type { LoadFileError } from "../Misc/fileTools";
  23. import type { ShaderProcessingContext } from "./Processors/shaderProcessingOptions";
  24. import type { IPipelineContext } from "./IPipelineContext";
  25. import type { ThinTexture } from "../Materials/Textures/thinTexture";
  26. import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
  27. import type { IInternalTextureLoader } from "../Materials/Textures/internalTextureLoader";
  28. import type { ExternalTexture } from "../Materials/Textures/externalTexture";
  29. import type { TextureSampler } from "../Materials/Textures/textureSampler";
  30. import type { DepthTextureCreationOptions, InternalTextureCreationOptions, RenderTargetCreationOptions, TextureSize } from "../Materials/Textures/textureCreationOptions";
  31. import type { IMultiRenderTargetOptions } from "../Materials/Textures/multiRenderTarget";
  32. import type { EffectFallbacks } from "../Materials/effectFallbacks";
  33. import type { IMaterialContext } from "./IMaterialContext";
  34. import type { IStencilState } from "../States/IStencilState";
  35. import type { DrawWrapper } from "../Materials/drawWrapper";
  36. import type { IDrawContext } from "./IDrawContext";
  37. import type { VertexBuffer } from "../Meshes/buffer";
  38. import type { IAudioEngine } from "../Audio/Interfaces/IAudioEngine";
  39. import type { WebRequest } from "../Misc/webRequest.js";
  40. import type { PerformanceMonitor } from "../Misc/performanceMonitor.js";
  41. import type { ILoadingScreen } from "../Loading/loadingScreen";
  42. import { Effect } from "../Materials/effect";
  43. import { DepthCullingState } from "../States/depthCullingState";
  44. import { StencilStateComposer } from "../States/stencilStateComposer";
  45. import { StencilState } from "../States/stencilState";
  46. import { AlphaState } from "../States/alphaCullingState";
  47. import { InternalTexture, InternalTextureSource } from "../Materials/Textures/internalTexture";
  48. import { Observable } from "../Misc/observable";
  49. /**
  50. * Defines the interface used by objects working like Scene
  51. * @internal
  52. */
  53. export interface ISceneLike {
  54. /** Add pending data (to load) */
  55. addPendingData(data: any): void;
  56. /** Remove pending data */
  57. removePendingData(data: any): void;
  58. /** Offline provider */
  59. offlineProvider: IOfflineProvider;
  60. }
  61. /**
  62. * Queue a new function into the requested animation frame pool (ie. this function will be executed by the browser (or the javascript engine) for the next frame)
  63. * @param func - the function to be called
  64. * @param requester - the object that will request the next frame. Falls back to window.
  65. * @returns frame number
  66. */
  67. export declare function QueueNewFrame(func: () => void, requester?: any): number;
  68. /** Interface defining initialization parameters for AbstractEngine class */
  69. export interface AbstractEngineOptions {
  70. /**
  71. * Defines if the engine should no exceed a specified device ratio
  72. * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio
  73. */
  74. limitDeviceRatio?: number;
  75. /**
  76. * Defines if webaudio should be initialized as well
  77. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  78. */
  79. audioEngine?: boolean;
  80. /**
  81. * Specifies options for the audio engine
  82. */
  83. audioEngineOptions?: IAudioEngineOptions;
  84. /**
  85. * Defines if animations should run using a deterministic lock step
  86. * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep
  87. */
  88. deterministicLockstep?: boolean;
  89. /** Defines the maximum steps to use with deterministic lock step mode */
  90. lockstepMaxSteps?: number;
  91. /** Defines the seconds between each deterministic lock step */
  92. timeStep?: number;
  93. /**
  94. * Defines that engine should ignore context lost events
  95. * If this event happens when this parameter is true, you will have to reload the page to restore rendering
  96. */
  97. doNotHandleContextLost?: boolean;
  98. /**
  99. * Defines that engine should ignore modifying touch action attribute and style
  100. * If not handle, you might need to set it up on your side for expected touch devices behavior.
  101. */
  102. doNotHandleTouchAction?: boolean;
  103. /**
  104. * Make the matrix computations to be performed in 64 bits instead of 32 bits. False by default
  105. */
  106. useHighPrecisionMatrix?: boolean;
  107. /**
  108. * Defines whether to adapt to the device's viewport characteristics (default: false)
  109. */
  110. adaptToDeviceRatio?: boolean;
  111. /**
  112. * Defines whether MSAA is enabled on the canvas.
  113. */
  114. antialias?: boolean;
  115. /**
  116. * Defines whether the stencil buffer should be enabled.
  117. */
  118. stencil?: boolean;
  119. /**
  120. * Defines whether the canvas should be created in "premultiplied" mode (if false, the canvas is created in the "opaque" mode) (true by default)
  121. */
  122. premultipliedAlpha?: boolean;
  123. /**
  124. * True if the more expensive but exact conversions should be used for transforming colors to and from linear space within shaders.
  125. * Otherwise, the default is to use a cheaper approximation.
  126. */
  127. useExactSrgbConversions?: boolean;
  128. }
  129. /**
  130. * Information about the current host
  131. */
  132. export interface HostInformation {
  133. /**
  134. * Defines if the current host is a mobile
  135. */
  136. isMobile: boolean;
  137. }
  138. /**
  139. * The parent class for specialized engines (WebGL, WebGPU)
  140. */
  141. export declare abstract class AbstractEngine {
  142. /** @internal */
  143. static _TextureLoaders: IInternalTextureLoader[];
  144. /** @internal */
  145. protected _colorWrite: boolean;
  146. /** @internal */
  147. protected _colorWriteChanged: boolean;
  148. /** @internal */
  149. _depthCullingState: DepthCullingState;
  150. /** @internal */
  151. protected _stencilStateComposer: StencilStateComposer;
  152. /** @internal */
  153. _stencilState: StencilState;
  154. /** @internal */
  155. _alphaState: AlphaState;
  156. /** @internal */
  157. _alphaMode: number;
  158. /** @internal */
  159. _alphaEquation: number;
  160. /** @internal */
  161. _badOS: boolean;
  162. /** @internal */
  163. _badDesktopOS: boolean;
  164. /** @internal */
  165. _videoTextureSupported: boolean;
  166. protected _compatibilityMode: boolean;
  167. /** @internal */
  168. _pointerLockRequested: boolean;
  169. /** @internal */
  170. _loadingScreen: ILoadingScreen;
  171. /** @internal */
  172. _renderingCanvas: Nullable<HTMLCanvasElement>;
  173. /** @internal */
  174. _internalTexturesCache: InternalTexture[];
  175. private _activeRequests;
  176. protected _currentEffect: Nullable<Effect>;
  177. /** @internal */
  178. protected _cachedVertexBuffers: any;
  179. /** @internal */
  180. protected _cachedIndexBuffer: Nullable<DataBuffer>;
  181. /** @internal */
  182. protected _cachedEffectForVertexBuffers: Nullable<Effect>;
  183. /** @internal */
  184. _currentRenderTarget: Nullable<RenderTargetWrapper>;
  185. /** @internal */
  186. _caps: EngineCapabilities;
  187. /** @internal */
  188. protected _cachedViewport: Nullable<IViewportLike>;
  189. /** @internal */
  190. _currentDrawContext: IDrawContext;
  191. /** @internal */
  192. protected _boundTexturesCache: {
  193. [key: string]: Nullable<InternalTexture>;
  194. };
  195. /** @internal */
  196. protected _activeChannel: number;
  197. /** @internal */
  198. protected _currentTextureChannel: number;
  199. /** @internal */
  200. protected _viewportCached: {
  201. x: number;
  202. y: number;
  203. z: number;
  204. w: number;
  205. };
  206. /** @internal */
  207. protected _isWebGPU: boolean;
  208. /** @internal */
  209. _onFocus: () => void;
  210. /** @internal */
  211. _onBlur: () => void;
  212. /** @internal */
  213. _onCanvasPointerOut: (event: PointerEvent) => void;
  214. /** @internal */
  215. _onCanvasBlur: () => void;
  216. /** @internal */
  217. _onCanvasFocus: () => void;
  218. /** @internal */
  219. _onCanvasContextMenu: (evt: Event) => void;
  220. /** @internal */
  221. _onFullscreenChange: () => void;
  222. /**
  223. * Observable event triggered each time the canvas loses focus
  224. */
  225. onCanvasBlurObservable: Observable<AbstractEngine>;
  226. /**
  227. * Observable event triggered each time the canvas gains focus
  228. */
  229. onCanvasFocusObservable: Observable<AbstractEngine>;
  230. /**
  231. * Event raised when a new scene is created
  232. */
  233. onNewSceneAddedObservable: Observable<Scene>;
  234. /**
  235. * Observable event triggered each time the rendering canvas is resized
  236. */
  237. onResizeObservable: Observable<AbstractEngine>;
  238. /**
  239. * Observable event triggered each time the canvas receives pointerout event
  240. */
  241. onCanvasPointerOutObservable: Observable<PointerEvent>;
  242. /**
  243. * Turn this value on if you want to pause FPS computation when in background
  244. */
  245. disablePerformanceMonitorInBackground: boolean;
  246. /**
  247. * Gets or sets a boolean indicating that vertex array object must be disabled even if they are supported
  248. */
  249. disableVertexArrayObjects: boolean;
  250. /** @internal */
  251. protected _frameId: number;
  252. /**
  253. * Gets the current frame id
  254. */
  255. get frameId(): number;
  256. /**
  257. * Gets a boolean indicating if the engine runs in WebGPU or not.
  258. */
  259. get isWebGPU(): boolean;
  260. protected _shaderProcessor: Nullable<IShaderProcessor>;
  261. /**
  262. * @internal
  263. */
  264. _getShaderProcessor(shaderLanguage: ShaderLanguage): Nullable<IShaderProcessor>;
  265. /**
  266. * Gets a boolean indicating if all created effects are ready
  267. * @returns true if all effects are ready
  268. */
  269. abstract areAllEffectsReady(): boolean;
  270. /**
  271. * @internal
  272. */
  273. abstract _executeWhenRenderingStateIsCompiled(pipelineContext: IPipelineContext, action: () => void): void;
  274. /**
  275. * Sets a texture to the according uniform.
  276. * @param channel The texture channel
  277. * @param unused unused parameter
  278. * @param texture The texture to apply
  279. * @param name The name of the uniform in the effect
  280. */
  281. abstract setTexture(channel: number, unused: Nullable<WebGLUniformLocation>, texture: Nullable<ThinTexture>, name: string): void;
  282. /**
  283. * Binds an effect to the webGL context
  284. * @param effect defines the effect to bind
  285. */
  286. abstract bindSamplers(effect: Effect): void;
  287. /**
  288. * Creates an external texture
  289. * @param video video element
  290. * @returns the external texture, or null if external textures are not supported by the engine
  291. */
  292. abstract createExternalTexture(video: HTMLVideoElement): Nullable<ExternalTexture>;
  293. /**
  294. * Sets an internal texture to the according uniform.
  295. * @param name The name of the uniform in the effect
  296. * @param texture The texture to apply
  297. */
  298. abstract setExternalTexture(name: string, texture: Nullable<ExternalTexture>): void;
  299. /**
  300. * @internal
  301. */
  302. abstract _bindTexture(channel: number, texture: Nullable<InternalTexture>, name: string): void;
  303. /**
  304. * @internal
  305. */
  306. abstract _deletePipelineContext(pipelineContext: IPipelineContext): void;
  307. /**
  308. * @internal
  309. */
  310. abstract _preparePipelineContext(pipelineContext: IPipelineContext, vertexSourceCode: string, fragmentSourceCode: string, createAsRaw: boolean, rawVertexSourceCode: string, rawFragmentSourceCode: string, rebuildRebind: any, defines: Nullable<string>, transformFeedbackVaryings: Nullable<string[]>, key: string): void;
  311. /** @internal */
  312. protected _shaderPlatformName: string;
  313. /**
  314. * Gets the shader platform name used by the effects.
  315. */
  316. get shaderPlatformName(): string;
  317. /**
  318. * Gets information about the current host
  319. */
  320. hostInformation: HostInformation;
  321. /**
  322. * Gets a boolean indicating if the engine is currently rendering in fullscreen mode
  323. */
  324. isFullscreen: boolean;
  325. /**
  326. * Gets or sets a boolean to enable/disable IndexedDB support and avoid XHR on .manifest
  327. **/
  328. enableOfflineSupport: boolean;
  329. /**
  330. * Gets or sets a boolean to enable/disable checking manifest if IndexedDB support is enabled (js will always consider the database is up to date)
  331. **/
  332. disableManifestCheck: boolean;
  333. /**
  334. * Gets or sets a boolean to enable/disable the context menu (right-click) from appearing on the main canvas
  335. */
  336. disableContextMenu: boolean;
  337. /**
  338. * Gets or sets the current render pass id
  339. */
  340. currentRenderPassId: number;
  341. /**
  342. * Gets a boolean indicating if the pointer is currently locked
  343. */
  344. isPointerLock: boolean;
  345. /**
  346. * Gets the list of created postprocesses
  347. */
  348. postProcesses: PostProcess[];
  349. /** Gets or sets the tab index to set to the rendering canvas. 1 is the minimum value to set to be able to capture keyboard events */
  350. canvasTabIndex: number;
  351. /** @internal */
  352. protected _onContextLost: (evt: Event) => void;
  353. /** @internal */
  354. protected _onContextRestored: (evt: Event) => void;
  355. /** @internal */
  356. protected _contextWasLost: boolean;
  357. private _emptyTexture;
  358. private _emptyCubeTexture;
  359. private _emptyTexture3D;
  360. private _emptyTexture2DArray;
  361. protected _clearEmptyResources(): void;
  362. abstract wipeCaches(bruteForce?: boolean): void;
  363. private _useReverseDepthBuffer;
  364. /**
  365. * Gets or sets a boolean indicating if depth buffer should be reverse, going from far to near.
  366. * This can provide greater z depth for distant objects.
  367. */
  368. get useReverseDepthBuffer(): boolean;
  369. set useReverseDepthBuffer(useReverse: boolean);
  370. /**
  371. * Enable or disable color writing
  372. * @param enable defines the state to set
  373. */
  374. setColorWrite(enable: boolean): void;
  375. /**
  376. * Gets a boolean indicating if color writing is enabled
  377. * @returns the current color writing state
  378. */
  379. getColorWrite(): boolean;
  380. /**
  381. * Gets the depth culling state manager
  382. */
  383. get depthCullingState(): DepthCullingState;
  384. /**
  385. * Gets the alpha state manager
  386. */
  387. get alphaState(): AlphaState;
  388. /**
  389. * Gets the stencil state manager
  390. */
  391. get stencilState(): StencilState;
  392. /**
  393. * Gets the stencil state composer
  394. */
  395. get stencilStateComposer(): StencilStateComposer;
  396. /**
  397. * Indicates if the z range in NDC space is 0..1 (value: true) or -1..1 (value: false)
  398. */
  399. readonly isNDCHalfZRange: boolean;
  400. /**
  401. * Indicates that the origin of the texture/framebuffer space is the bottom left corner. If false, the origin is top left
  402. */
  403. readonly hasOriginBottomLeft: boolean;
  404. /**
  405. * Gets a boolean indicating if the exact sRGB conversions or faster approximations are used for converting to and from linear space.
  406. */
  407. readonly useExactSrgbConversions: boolean;
  408. /** @internal */
  409. _getGlobalDefines(defines?: {
  410. [key: string]: string;
  411. }): string | undefined;
  412. /** @internal */
  413. _renderTargetWrapperCache: RenderTargetWrapper[];
  414. /** @internal */
  415. protected _compiledEffects: {
  416. [key: string]: Effect;
  417. };
  418. private _rebuildInternalTextures;
  419. private _rebuildRenderTargetWrappers;
  420. private _rebuildEffects;
  421. protected _rebuildGraphicsResources(): void;
  422. protected _flagContextRestored(): void;
  423. protected _restoreEngineAfterContextLost(initEngine: () => void): void;
  424. /** @internal */
  425. protected _isDisposed: boolean;
  426. /** Gets a boolean indicating if the engine was disposed */
  427. get isDisposed(): boolean;
  428. /**
  429. * Gets the list of created scenes
  430. */
  431. scenes: Scene[];
  432. /** @internal */
  433. _virtualScenes: Scene[];
  434. /** @internal */
  435. _features: EngineFeatures;
  436. /**
  437. * Enables or disables the snapshot rendering mode
  438. * Note that the WebGL engine does not support snapshot rendering so setting the value won't have any effect for this engine
  439. */
  440. get snapshotRendering(): boolean;
  441. set snapshotRendering(activate: boolean);
  442. /**
  443. * Gets or sets the snapshot rendering mode
  444. */
  445. get snapshotRenderingMode(): number;
  446. set snapshotRenderingMode(mode: number);
  447. /**
  448. * Observable event triggered before each texture is initialized
  449. */
  450. onBeforeTextureInitObservable: Observable<Texture>;
  451. /**
  452. * Gets or sets a boolean indicating if the engine must keep rendering even if the window is not in foreground
  453. */
  454. renderEvenInBackground: boolean;
  455. /**
  456. * Gets or sets a boolean indicating that cache can be kept between frames
  457. */
  458. preventCacheWipeBetweenFrames: boolean;
  459. /**
  460. * Returns the string "AbstractEngine"
  461. * @returns "AbstractEngine"
  462. */
  463. getClassName(): string;
  464. /**
  465. * Gets the default empty texture
  466. */
  467. get emptyTexture(): InternalTexture;
  468. /**
  469. * Gets the default empty 3D texture
  470. */
  471. get emptyTexture3D(): InternalTexture;
  472. /**
  473. * Gets the default empty 2D array texture
  474. */
  475. get emptyTexture2DArray(): InternalTexture;
  476. /**
  477. * Gets the default empty cube texture
  478. */
  479. get emptyCubeTexture(): InternalTexture;
  480. /** @internal */
  481. _frameHandler: number;
  482. /** @internal */
  483. protected _activeRenderLoops: (() => void)[];
  484. /**
  485. * Gets the list of current active render loop functions
  486. * @returns a read only array with the current render loop functions
  487. */
  488. get activeRenderLoops(): ReadonlyArray<() => void>;
  489. /**
  490. * stop executing a render loop function and remove it from the execution array
  491. * @param renderFunction defines the function to be removed. If not provided all functions will be removed.
  492. */
  493. stopRenderLoop(renderFunction?: () => void): void;
  494. protected _cancelFrame(): void;
  495. /** @internal */
  496. _windowIsBackground: boolean;
  497. /**
  498. * Begin a new frame
  499. */
  500. beginFrame(): void;
  501. /**
  502. * End the current frame
  503. */
  504. endFrame(): void;
  505. /**
  506. * Gets the performance monitor attached to this engine
  507. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#engineinstrumentation
  508. */
  509. abstract get performanceMonitor(): PerformanceMonitor;
  510. /** @internal */
  511. _boundRenderFunction: any;
  512. /** @internal */
  513. _renderLoop(): void;
  514. /**
  515. * Can be used to override the current requestAnimationFrame requester.
  516. * @internal
  517. */
  518. protected _queueNewFrame(bindedRenderFunction: any, requester?: any): number;
  519. /**
  520. * Register and execute a render loop. The engine can have more than one render function
  521. * @param renderFunction defines the function to continuously execute
  522. */
  523. runRenderLoop(renderFunction: () => void): void;
  524. /**
  525. * Gets a boolean indicating if depth testing is enabled
  526. * @returns the current state
  527. */
  528. getDepthBuffer(): boolean;
  529. /**
  530. * Enable or disable depth buffering
  531. * @param enable defines the state to set
  532. */
  533. setDepthBuffer(enable: boolean): void;
  534. /**
  535. * Set the z offset Factor to apply to current rendering
  536. * @param value defines the offset to apply
  537. */
  538. setZOffset(value: number): void;
  539. /**
  540. * Gets the current value of the zOffset Factor
  541. * @returns the current zOffset Factor state
  542. */
  543. getZOffset(): number;
  544. /**
  545. * Set the z offset Units to apply to current rendering
  546. * @param value defines the offset to apply
  547. */
  548. setZOffsetUnits(value: number): void;
  549. /**
  550. * Gets the current value of the zOffset Units
  551. * @returns the current zOffset Units state
  552. */
  553. getZOffsetUnits(): number;
  554. /**
  555. * Gets host window
  556. * @returns the host window object
  557. */
  558. getHostWindow(): Nullable<Window>;
  559. /**
  560. * (WebGPU only) True (default) to be in compatibility mode, meaning rendering all existing scenes without artifacts (same rendering than WebGL).
  561. * Setting the property to false will improve performances but may not work in some scenes if some precautions are not taken.
  562. * See https://doc.babylonjs.com/setup/support/webGPU/webGPUOptimization/webGPUNonCompatibilityMode for more details
  563. */
  564. get compatibilityMode(): boolean;
  565. set compatibilityMode(mode: boolean);
  566. /**
  567. * Observable raised when the engine is about to compile a shader
  568. */
  569. onBeforeShaderCompilationObservable: Observable<AbstractEngine>;
  570. /**
  571. * Observable raised when the engine has just compiled a shader
  572. */
  573. onAfterShaderCompilationObservable: Observable<AbstractEngine>;
  574. /**
  575. * Observable raised when the engine begins a new frame
  576. */
  577. onBeginFrameObservable: Observable<AbstractEngine>;
  578. /**
  579. * Observable raised when the engine ends the current frame
  580. */
  581. onEndFrameObservable: Observable<AbstractEngine>;
  582. protected _rebuildTextures(): void;
  583. /**
  584. * @internal
  585. */
  586. abstract _setCubeMapTextureParams(texture: InternalTexture, loadMipmap: boolean, maxLevel?: number): void;
  587. /**
  588. * @internal
  589. */
  590. abstract _getRGBABufferInternalSizedFormat(type: number, format?: number, useSRGBBuffer?: boolean): number;
  591. /** @internal */
  592. abstract _getUnpackAlignement(): number;
  593. /**
  594. * @internal
  595. */
  596. abstract _uploadCompressedDataToTextureDirectly(texture: InternalTexture, internalFormat: number, width: number, height: number, data: ArrayBufferView, faceIndex: number, lod?: number): void;
  597. /**
  598. * @internal
  599. */
  600. abstract _bindTextureDirectly(target: number, texture: Nullable<InternalTexture>, forTextureDataUpdate?: boolean, force?: boolean): boolean;
  601. /**
  602. * @internal
  603. */
  604. abstract _uploadDataToTextureDirectly(texture: InternalTexture, imageData: ArrayBufferView, faceIndex?: number, lod?: number, babylonInternalFormat?: number, useTextureWidthAndHeight?: boolean): void;
  605. /** @internal */
  606. abstract _readTexturePixels(texture: InternalTexture, width: number, height: number, faceIndex?: number, level?: number, buffer?: Nullable<ArrayBufferView>, flushRenderer?: boolean, noDataConversion?: boolean, x?: number, y?: number): Promise<ArrayBufferView>;
  607. /** @internal */
  608. abstract _readTexturePixelsSync(texture: InternalTexture, width: number, height: number, faceIndex?: number, level?: number, buffer?: Nullable<ArrayBufferView>, flushRenderer?: boolean, noDataConversion?: boolean, x?: number, y?: number): ArrayBufferView;
  609. /**
  610. * Reads pixels from the current frame buffer. Please note that this function can be slow
  611. * @param x defines the x coordinate of the rectangle where pixels must be read
  612. * @param y defines the y coordinate of the rectangle where pixels must be read
  613. * @param width defines the width of the rectangle where pixels must be read
  614. * @param height defines the height of the rectangle where pixels must be read
  615. * @param hasAlpha defines whether the output should have alpha or not (defaults to true)
  616. * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels
  617. * @returns a ArrayBufferView promise (Uint8Array) containing RGBA colors
  618. */
  619. abstract readPixels(x: number, y: number, width: number, height: number, hasAlpha?: boolean, flushRenderer?: boolean): Promise<ArrayBufferView>;
  620. /**
  621. * Force a WebGPU flush (ie. a flush of all waiting commands)
  622. */
  623. abstract flushFramebuffer(): void;
  624. /** @internal */
  625. abstract _currentFrameBufferIsDefaultFrameBuffer(): boolean;
  626. /**
  627. * Creates an internal texture without binding it to a framebuffer
  628. * @internal
  629. * @param size defines the size of the texture
  630. * @param options defines the options used to create the texture
  631. * @param delayGPUTextureCreation true to delay the texture creation the first time it is really needed. false to create it right away
  632. * @param source source type of the texture
  633. * @returns a new internal texture
  634. */
  635. abstract _createInternalTexture(size: TextureSize, options: boolean | InternalTextureCreationOptions, delayGPUTextureCreation?: boolean, source?: InternalTextureSource): InternalTexture;
  636. /** @internal */
  637. abstract applyStates(): void;
  638. /**
  639. * Binds the frame buffer to the specified texture.
  640. * @param texture The render target wrapper to render to
  641. * @param faceIndex The face of the texture to render to in case of cube texture
  642. * @param requiredWidth The width of the target to render to
  643. * @param requiredHeight The height of the target to render to
  644. * @param forceFullscreenViewport Forces the viewport to be the entire texture/screen if true
  645. * @param lodLevel defines the lod level to bind to the frame buffer
  646. * @param layer defines the 2d array index to bind to frame buffer to
  647. */
  648. abstract bindFramebuffer(texture: RenderTargetWrapper, faceIndex?: number, requiredWidth?: number, requiredHeight?: number, forceFullscreenViewport?: boolean, lodLevel?: number, layer?: number): void;
  649. /**
  650. * Update the sampling mode of a given texture
  651. * @param texture defines the texture to update
  652. * @param wrapU defines the texture wrap mode of the u coordinates
  653. * @param wrapV defines the texture wrap mode of the v coordinates
  654. * @param wrapR defines the texture wrap mode of the r coordinates
  655. */
  656. abstract updateTextureWrappingMode(texture: InternalTexture, wrapU: Nullable<number>, wrapV?: Nullable<number>, wrapR?: Nullable<number>): void;
  657. /**
  658. * Update a video texture
  659. * @param texture defines the texture to update
  660. * @param video defines the video element to use
  661. * @param invertY defines if data must be stored with Y axis inverted
  662. */
  663. abstract updateVideoTexture(texture: Nullable<InternalTexture>, video: HTMLVideoElement | Nullable<ExternalTexture>, invertY: boolean): void;
  664. /**
  665. * Unbind the current render target and bind the default framebuffer
  666. */
  667. abstract restoreDefaultFramebuffer(): void;
  668. /**
  669. * Update a raw texture
  670. * @param texture defines the texture to update
  671. * @param data defines the data to store in the texture
  672. * @param format defines the format of the data
  673. * @param invertY defines if data must be stored with Y axis inverted
  674. * @param compression defines the compression used (null by default)
  675. * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
  676. * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).
  677. */
  678. abstract updateRawTexture(texture: Nullable<InternalTexture>, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression?: Nullable<string>, type?: number, useSRGBBuffer?: boolean): void;
  679. /**
  680. * Creates a storage buffer
  681. * @param data the data for the storage buffer or the size of the buffer
  682. * @param creationFlags flags to use when creating the buffer (see Constants.BUFFER_CREATIONFLAG_XXX). The BUFFER_CREATIONFLAG_STORAGE flag will be automatically added
  683. * @param label defines the label of the buffer (for debug purpose)
  684. * @returns the new buffer
  685. */
  686. abstract createStorageBuffer(data: DataArray | number, creationFlags: number, label?: string): DataBuffer;
  687. /**
  688. * Updates a storage buffer
  689. * @param buffer the storage buffer to update
  690. * @param data the data used to update the storage buffer
  691. * @param byteOffset the byte offset of the data
  692. * @param byteLength the byte length of the data
  693. */
  694. abstract updateStorageBuffer(buffer: DataBuffer, data: DataArray, byteOffset?: number, byteLength?: number): void;
  695. /**
  696. * Read data from a storage buffer
  697. * @param storageBuffer The storage buffer to read from
  698. * @param offset The offset in the storage buffer to start reading from (default: 0)
  699. * @param size The number of bytes to read from the storage buffer (default: capacity of the buffer)
  700. * @param buffer The buffer to write the data we have read from the storage buffer to (optional)
  701. * @param noDelay If true, a call to flushFramebuffer will be issued so that the data can be read back immediately and not in engine.onEndFrameObservable. This can speed up data retrieval, at the cost of a small perf penalty (default: false).
  702. * @returns If not undefined, returns the (promise) buffer (as provided by the 4th parameter) filled with the data, else it returns a (promise) Uint8Array with the data read from the storage buffer
  703. */
  704. abstract readFromStorageBuffer(storageBuffer: DataBuffer, offset?: number, size?: number, buffer?: ArrayBufferView, noDelay?: boolean): Promise<ArrayBufferView>;
  705. /**
  706. * Draw a list of indexed primitives
  707. * @param fillMode defines the primitive to use
  708. * @param indexStart defines the starting index
  709. * @param indexCount defines the number of index to draw
  710. * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
  711. */
  712. abstract drawElementsType(fillMode: number, indexStart: number, indexCount: number, instancesCount?: number): void;
  713. /**
  714. * Unbind the current render target texture from the webGL context
  715. * @param texture defines the render target wrapper to unbind
  716. * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated
  717. * @param onBeforeUnbind defines a function which will be called before the effective unbind
  718. */
  719. abstract unBindFramebuffer(texture: RenderTargetWrapper, disableGenerateMipMaps?: boolean, onBeforeUnbind?: () => void): void;
  720. /**Gets driver info if available */
  721. abstract extractDriverInfo(): string;
  722. /**
  723. * Creates a layout object to draw/clear on specific textures in a MRT
  724. * @param textureStatus textureStatus[i] indicates if the i-th is active
  725. * @returns A layout to be fed to the engine, calling `bindAttachments`.
  726. */
  727. abstract buildTextureLayout(textureStatus: boolean[]): number[];
  728. /**
  729. * Restores the webgl state to only draw on the main color attachment
  730. * when the frame buffer associated is the canvas frame buffer
  731. */
  732. abstract restoreSingleAttachment(): void;
  733. /**
  734. * Select a subsets of attachments to draw to.
  735. * @param attachments gl attachments
  736. */
  737. abstract bindAttachments(attachments: number[]): void;
  738. /**
  739. * Bind a list of vertex buffers to the webGL context
  740. * @param vertexBuffers defines the list of vertex buffers to bind
  741. * @param indexBuffer defines the index buffer to bind
  742. * @param effect defines the effect associated with the vertex buffers
  743. * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers
  744. */
  745. abstract bindBuffers(vertexBuffers: {
  746. [key: string]: Nullable<VertexBuffer>;
  747. }, indexBuffer: Nullable<DataBuffer>, effect: Effect, overrideVertexBuffers?: {
  748. [kind: string]: Nullable<VertexBuffer>;
  749. }): void;
  750. /**
  751. * @internal
  752. */
  753. _releaseRenderTargetWrapper(rtWrapper: RenderTargetWrapper): void;
  754. /**
  755. * Activates an effect, making it the current one (ie. the one used for rendering)
  756. * @param effect defines the effect to activate
  757. */
  758. abstract enableEffect(effect: Nullable<Effect | DrawWrapper>): void;
  759. /**
  760. * Set various states to the webGL context
  761. * @param culling defines culling state: true to enable culling, false to disable it
  762. * @param zOffset defines the value to apply to zOffset (0 by default)
  763. * @param force defines if states must be applied even if cache is up to date
  764. * @param reverseSide defines if culling must be reversed (CCW if false, CW if true)
  765. * @param cullBackFaces true to cull back faces, false to cull front faces (if culling is enabled)
  766. * @param stencil stencil states to set
  767. * @param zOffsetUnits defines the value to apply to zOffsetUnits (0 by default)
  768. */
  769. abstract setState(culling: boolean, zOffset?: number, force?: boolean, reverseSide?: boolean, cullBackFaces?: boolean, stencil?: IStencilState, zOffsetUnits?: number): void;
  770. /**
  771. * Creates a new material context
  772. * @returns the new context
  773. */
  774. abstract createMaterialContext(): IMaterialContext | undefined;
  775. /**
  776. * Creates a new draw context
  777. * @returns the new context
  778. */
  779. abstract createDrawContext(): IDrawContext | undefined;
  780. /**
  781. * Create a new effect (used to store vertex/fragment shaders)
  782. * @param baseName defines the base name of the effect (The name of file without .fragment.fx or .vertex.fx)
  783. * @param attributesNamesOrOptions defines either a list of attribute names or an IEffectCreationOptions object
  784. * @param uniformsNamesOrEngine defines either a list of uniform names or the engine to use
  785. * @param samplers defines an array of string used to represent textures
  786. * @param defines defines the string containing the defines to use to compile the shaders
  787. * @param fallbacks defines the list of potential fallbacks to use if shader compilation fails
  788. * @param onCompiled defines a function to call when the effect creation is successful
  789. * @param onError defines a function to call when the effect creation has failed
  790. * @param indexParameters defines an object containing the index values to use to compile shaders (like the maximum number of simultaneous lights)
  791. * @param shaderLanguage the language the shader is written in (default: GLSL)
  792. * @returns the new Effect
  793. */
  794. abstract createEffect(baseName: string | (IShaderPath & {
  795. vertexToken?: string;
  796. fragmentToken?: string;
  797. }), attributesNamesOrOptions: string[] | IEffectCreationOptions, uniformsNamesOrEngine: string[] | AbstractEngine, samplers?: string[], defines?: string, fallbacks?: EffectFallbacks, onCompiled?: Nullable<(effect: Effect) => void>, onError?: Nullable<(effect: Effect, errors: string) => void>, indexParameters?: any, shaderLanguage?: ShaderLanguage): Effect;
  798. /**
  799. * Clear the current render buffer or the current render target (if any is set up)
  800. * @param color defines the color to use
  801. * @param backBuffer defines if the back buffer must be cleared
  802. * @param depth defines if the depth buffer must be cleared
  803. * @param stencil defines if the stencil buffer must be cleared
  804. */
  805. abstract clear(color: Nullable<IColor4Like>, backBuffer: boolean, depth: boolean, stencil?: boolean): void;
  806. /**
  807. * Sets the current alpha mode
  808. * @param mode defines the mode to use (one of the Engine.ALPHA_XXX)
  809. * @param noDepthWriteChange defines if depth writing state should remains unchanged (false by default)
  810. * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/transparent_rendering
  811. */
  812. abstract setAlphaMode(mode: number, noDepthWriteChange?: boolean): void;
  813. /**
  814. * Gets a boolean indicating that only power of 2 textures are supported
  815. * Please note that you can still use non power of 2 textures but in this case the engine will forcefully convert them
  816. */
  817. abstract get needPOTTextures(): boolean;
  818. /**
  819. * Creates a new index buffer
  820. * @param indices defines the content of the index buffer
  821. * @param _updatable defines if the index buffer must be updatable
  822. * @param label defines the label of the buffer (for debug purpose)
  823. * @returns a new buffer
  824. */
  825. abstract createIndexBuffer(indices: IndicesArray, _updatable?: boolean, label?: string): DataBuffer;
  826. /**
  827. * Creates a new render target texture
  828. * @param size defines the size of the texture
  829. * @param options defines the options used to create the texture
  830. * @returns a new render target wrapper ready to render texture
  831. */
  832. abstract createRenderTargetTexture(size: TextureSize, options: boolean | RenderTargetCreationOptions): RenderTargetWrapper;
  833. /**
  834. * Creates a new render target cube wrapper
  835. * @param size defines the size of the texture
  836. * @param options defines the options used to create the texture
  837. * @returns a new render target cube wrapper
  838. */
  839. abstract createRenderTargetCubeTexture(size: number, options?: RenderTargetCreationOptions): RenderTargetWrapper;
  840. /**
  841. * Create a multi render target texture
  842. * @see https://doc.babylonjs.com/setup/support/webGL2#multiple-render-target
  843. * @param size defines the size of the texture
  844. * @param options defines the creation options
  845. * @param initializeBuffers if set to true, the engine will make an initializing call of drawBuffers
  846. * @returns a new render target wrapper ready to render textures
  847. */
  848. abstract createMultipleRenderTarget(size: TextureSize, options: IMultiRenderTargetOptions, initializeBuffers?: boolean): RenderTargetWrapper;
  849. /** @internal */
  850. abstract _createDepthStencilTexture(size: TextureSize, options: DepthTextureCreationOptions, rtWrapper: RenderTargetWrapper): InternalTexture;
  851. /**
  852. * Creates a depth stencil cube texture.
  853. * This is only available in WebGL 2.
  854. * @param size The size of face edge in the cube texture.
  855. * @param options The options defining the cube texture.
  856. * @returns The cube texture
  857. */
  858. abstract _createDepthStencilCubeTexture(size: number, options: DepthTextureCreationOptions): InternalTexture;
  859. /**
  860. * Update the sample count for a given multiple render target texture
  861. * @see https://doc.babylonjs.com/setup/support/webGL2#multisample-render-targets
  862. * @param rtWrapper defines the render target wrapper to update
  863. * @param samples defines the sample count to set
  864. * @param initializeBuffers if set to true, the engine will make an initializing call of drawBuffers
  865. * @returns the effective sample count (could be 0 if multisample render targets are not supported)
  866. */
  867. abstract updateMultipleRenderTargetTextureSampleCount(rtWrapper: Nullable<RenderTargetWrapper>, samples: number, initializeBuffers?: boolean): number;
  868. /**
  869. * Updates the sample count of a render target texture
  870. * @see https://doc.babylonjs.com/setup/support/webGL2#multisample-render-targets
  871. * @param rtWrapper defines the render target wrapper to update
  872. * @param samples defines the sample count to set
  873. * @returns the effective sample count (could be 0 if multisample render targets are not supported)
  874. */
  875. abstract updateRenderTargetTextureSampleCount(rtWrapper: Nullable<RenderTargetWrapper>, samples: number): number;
  876. /**
  877. * Draw a list of unindexed primitives
  878. * @param fillMode defines the primitive to use
  879. * @param verticesStart defines the index of first vertex to draw
  880. * @param verticesCount defines the count of vertices to draw
  881. * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
  882. */
  883. abstract drawArraysType(fillMode: number, verticesStart: number, verticesCount: number, instancesCount?: number): void;
  884. /**
  885. * @internal
  886. */
  887. abstract _viewport(x: number, y: number, width: number, height: number): void;
  888. /**
  889. * Gets the current viewport
  890. */
  891. get currentViewport(): Nullable<IViewportLike>;
  892. /**
  893. * Set the WebGL's viewport
  894. * @param viewport defines the viewport element to be used
  895. * @param requiredWidth defines the width required for rendering. If not provided the rendering canvas' width is used
  896. * @param requiredHeight defines the height required for rendering. If not provided the rendering canvas' height is used
  897. */
  898. setViewport(viewport: IViewportLike, requiredWidth?: number, requiredHeight?: number): void;
  899. /**
  900. * Sets a storage buffer in the shader
  901. * @param name Defines the name of the storage buffer as defined in the shader
  902. * @param buffer Defines the value to give to the uniform
  903. */
  904. abstract setStorageBuffer(name: string, buffer: Nullable<StorageBuffer>): void;
  905. /**
  906. * Sets a texture sampler to the according uniform.
  907. * @param name The name of the uniform in the effect
  908. * @param sampler The sampler to apply
  909. */
  910. abstract setTextureSampler(name: string, sampler: Nullable<TextureSampler>): void;
  911. /**
  912. * Update the sampling mode of a given texture
  913. * @param samplingMode defines the required sampling mode
  914. * @param texture defines the texture to update
  915. * @param generateMipMaps defines whether to generate mipmaps for the texture
  916. */
  917. abstract updateTextureSamplingMode(samplingMode: number, texture: InternalTexture, generateMipMaps?: boolean): void;
  918. /**
  919. * Sets a texture to the context from a postprocess
  920. * @param channel defines the channel to use
  921. * @param postProcess defines the source postprocess
  922. * @param name name of the channel
  923. */
  924. abstract setTextureFromPostProcess(channel: number, postProcess: Nullable<PostProcess>, name: string): void;
  925. /**
  926. * Binds the output of the passed in post process to the texture channel specified
  927. * @param channel The channel the texture should be bound to
  928. * @param postProcess The post process which's output should be bound
  929. * @param name name of the channel
  930. */
  931. abstract setTextureFromPostProcessOutput(channel: number, postProcess: Nullable<PostProcess>, name: string): void;
  932. /**
  933. * Sets an array of texture to the webGL context
  934. * @param channel defines the channel where the texture array must be set
  935. * @param uniform defines the associated uniform location
  936. * @param textures defines the array of textures to bind
  937. * @param name name of the channel
  938. */
  939. abstract setTextureArray(channel: number, uniform: Nullable<WebGLUniformLocation>, textures: ThinTexture[], name: string): void;
  940. /** @internal */
  941. _transformTextureUrl: Nullable<(url: string) => string>;
  942. /**
  943. * Unbind all instance attributes
  944. */
  945. abstract unbindInstanceAttributes(): void;
  946. /**
  947. * @internal
  948. */
  949. abstract _getUseSRGBBuffer(useSRGBBuffer: boolean, noMipmap: boolean): boolean;
  950. /**
  951. * Create an image to use with canvas
  952. * @returns IImage interface
  953. */
  954. createCanvasImage(): IImage;
  955. /**
  956. * Returns a string describing the current engine
  957. */
  958. get description(): string;
  959. protected _createTextureBase(url: Nullable<string>, noMipmap: boolean, invertY: boolean, scene: Nullable<ISceneLike>, samplingMode: number | undefined, onLoad: Nullable<(texture: InternalTexture) => void> | undefined, onError: Nullable<(message: string, exception: any) => void> | undefined, prepareTexture: (texture: InternalTexture, extension: string, scene: Nullable<ISceneLike>, img: HTMLImageElement | ImageBitmap | {
  960. width: number;
  961. height: number;
  962. }, invertY: boolean, noMipmap: boolean, isCompressed: boolean, processFunction: (width: number, height: number, img: HTMLImageElement | ImageBitmap | {
  963. width: number;
  964. height: number;
  965. }, extension: string, texture: InternalTexture, continuationCallback: () => void) => boolean, samplingMode: number) => void, prepareTextureProcessFunction: (width: number, height: number, img: HTMLImageElement | ImageBitmap | {
  966. width: number;
  967. height: number;
  968. }, extension: string, texture: InternalTexture, continuationCallback: () => void) => boolean, buffer?: Nullable<string | ArrayBuffer | ArrayBufferView | HTMLImageElement | Blob | ImageBitmap>, fallback?: Nullable<InternalTexture>, format?: Nullable<number>, forcedExtension?: Nullable<string>, mimeType?: string, loaderOptions?: any, useSRGBBuffer?: boolean): InternalTexture;
  969. /**
  970. * Creates a new pipeline context
  971. * @param shaderProcessingContext defines the shader processing context used during the processing if available
  972. * @returns the new pipeline
  973. */
  974. abstract createPipelineContext(shaderProcessingContext: Nullable<ShaderProcessingContext>): IPipelineContext;
  975. /**
  976. * Inline functions in shader code that are marked to be inlined
  977. * @param code code to inline
  978. * @returns inlined code
  979. */
  980. abstract inlineShaderCode(code: string): string;
  981. /**
  982. * Gets a boolean indicating that the engine supports uniform buffers
  983. */
  984. abstract get supportsUniformBuffers(): boolean;
  985. /**
  986. * Returns the version of the engine
  987. */
  988. abstract get version(): number;
  989. /**
  990. * @internal
  991. */
  992. abstract _releaseEffect(effect: Effect): void;
  993. /**
  994. * Bind a buffer to the current draw context
  995. * @param buffer defines the buffer to bind
  996. * @param _location not used in WebGPU
  997. * @param name Name of the uniform variable to bind
  998. */
  999. abstract bindUniformBufferBase(buffer: DataBuffer, _location: number, name: string): void;
  1000. /**
  1001. * Bind a specific block at a given index in a specific shader program
  1002. * @param pipelineContext defines the pipeline context to use
  1003. * @param blockName defines the block name
  1004. * @param index defines the index where to bind the block
  1005. */
  1006. abstract bindUniformBlock(pipelineContext: IPipelineContext, blockName: string, index: number): void;
  1007. /**
  1008. * Sets a depth stencil texture from a render target to the according uniform.
  1009. * @param channel The texture channel
  1010. * @param uniform The uniform to set
  1011. * @param texture The render target texture containing the depth stencil texture to apply
  1012. * @param name The texture name
  1013. */
  1014. abstract setDepthStencilTexture(channel: number, uniform: Nullable<WebGLUniformLocation>, texture: Nullable<RenderTargetTexture>, name?: string): void;
  1015. /** @internal */
  1016. _uniformBuffers: UniformBuffer[];
  1017. /** @internal */
  1018. _storageBuffers: StorageBuffer[];
  1019. protected _rebuildBuffers(): void;
  1020. protected _highPrecisionShadersAllowed: boolean;
  1021. /** @internal */
  1022. get _shouldUseHighPrecisionShader(): boolean;
  1023. /**
  1024. * @internal
  1025. */
  1026. abstract _getShaderProcessingContext(shaderLanguage: ShaderLanguage): Nullable<ShaderProcessingContext>;
  1027. /**
  1028. * Gets host document
  1029. * @returns the host document object
  1030. */
  1031. getHostDocument(): Nullable<Document>;
  1032. /**
  1033. * Observable signaled when a context lost event is raised
  1034. */
  1035. onContextLostObservable: Observable<AbstractEngine>;
  1036. /**
  1037. * Observable signaled when a context restored event is raised
  1038. */
  1039. onContextRestoredObservable: Observable<AbstractEngine>;
  1040. /**
  1041. * Gets the list of loaded textures
  1042. * @returns an array containing all loaded textures
  1043. */
  1044. getLoadedTexturesCache(): InternalTexture[];
  1045. /**
  1046. * Clears the list of texture accessible through engine.
  1047. * This can help preventing texture load conflict due to name collision.
  1048. */
  1049. clearInternalTexturesCache(): void;
  1050. /**
  1051. * @internal
  1052. */
  1053. abstract _releaseTexture(texture: InternalTexture): void;
  1054. /**
  1055. * Gets the object containing all engine capabilities
  1056. * @returns the EngineCapabilities object
  1057. */
  1058. getCaps(): EngineCapabilities;
  1059. /**
  1060. * Reset the texture cache to empty state
  1061. */
  1062. resetTextureCache(): void;
  1063. /** @internal */
  1064. protected _name: string;
  1065. /**
  1066. * Gets or sets the name of the engine
  1067. */
  1068. get name(): string;
  1069. set name(value: string);
  1070. /**
  1071. * Returns the current npm package of the sdk
  1072. */
  1073. static get NpmPackage(): string;
  1074. /**
  1075. * Returns the current version of the framework
  1076. */
  1077. static get Version(): string;
  1078. /**
  1079. * The time (in milliseconds elapsed since the current page has been loaded) when the engine was initialized
  1080. */
  1081. readonly startTime: number;
  1082. /** @internal */
  1083. protected _audioContext: Nullable<AudioContext>;
  1084. /** @internal */
  1085. protected _audioDestination: Nullable<AudioDestinationNode | MediaStreamAudioDestinationNode>;
  1086. /**
  1087. * Gets the HTML canvas attached with the current webGL context
  1088. * @returns a HTML canvas
  1089. */
  1090. getRenderingCanvas(): Nullable<HTMLCanvasElement>;
  1091. /**
  1092. * Gets the audio context specified in engine initialization options
  1093. * @returns an Audio Context
  1094. */
  1095. getAudioContext(): Nullable<AudioContext>;
  1096. /**
  1097. * Gets the audio destination specified in engine initialization options
  1098. * @returns an audio destination node
  1099. */
  1100. getAudioDestination(): Nullable<AudioDestinationNode | MediaStreamAudioDestinationNode>;
  1101. /**
  1102. * Defines whether the engine has been created with the premultipliedAlpha option on or not.
  1103. */
  1104. premultipliedAlpha: boolean;
  1105. /**
  1106. * If set to true zooming in and out in the browser will rescale the hardware-scaling correctly.
  1107. */
  1108. adaptToDeviceRatio: boolean;
  1109. /** @internal */
  1110. protected _lastDevicePixelRatio: number;
  1111. /** @internal */
  1112. _hardwareScalingLevel: number;
  1113. /**
  1114. * Defines the hardware scaling level.
  1115. * By default the hardware scaling level is computed from the window device ratio.
  1116. * if level = 1 then the engine will render at the exact resolution of the canvas. If level = 0.5 then the engine will render at twice the size of the canvas.
  1117. * @param level defines the level to use
  1118. */
  1119. setHardwareScalingLevel(level: number): void;
  1120. /**
  1121. * Gets the current hardware scaling level.
  1122. * By default the hardware scaling level is computed from the window device ratio.
  1123. * if level = 1 then the engine will render at the exact resolution of the canvas. If level = 0.5 then the engine will render at twice the size of the canvas.
  1124. * @returns a number indicating the current hardware scaling level
  1125. */
  1126. getHardwareScalingLevel(): number;
  1127. /** @internal */
  1128. _doNotHandleContextLost: boolean;
  1129. /**
  1130. * Gets or sets a boolean indicating if resources should be retained to be able to handle context lost events
  1131. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#handling-webgl-context-lost
  1132. */
  1133. get doNotHandleContextLost(): boolean;
  1134. set doNotHandleContextLost(value: boolean);
  1135. /** @internal */
  1136. protected _isStencilEnable: boolean;
  1137. /**
  1138. * Returns true if the stencil buffer has been enabled through the creation option of the context.
  1139. */
  1140. get isStencilEnable(): boolean;
  1141. /**
  1142. * Creates a new engine
  1143. * @param antialias defines enable antialiasing (default: false)
  1144. * @param options defines further options to be sent to the creation context
  1145. * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)
  1146. */
  1147. constructor(antialias: boolean, options: AbstractEngineOptions, adaptToDeviceRatio?: boolean);
  1148. /**
  1149. * Resize the view according to the canvas' size
  1150. * @param forceSetSize true to force setting the sizes of the underlying canvas
  1151. */
  1152. resize(forceSetSize?: boolean): void;
  1153. /**
  1154. * Force a specific size of the canvas
  1155. * @param width defines the new canvas' width
  1156. * @param height defines the new canvas' height
  1157. * @param forceSetSize true to force setting the sizes of the underlying canvas
  1158. * @returns true if the size was changed
  1159. */
  1160. setSize(width: number, height: number, forceSetSize?: boolean): boolean;
  1161. /**
  1162. * @internal
  1163. */
  1164. abstract _releaseBuffer(buffer: DataBuffer): boolean;
  1165. /**
  1166. * Create a dynamic uniform buffer
  1167. * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets
  1168. * @param elements defines the content of the uniform buffer
  1169. * @param label defines a name for the buffer (for debugging purpose)
  1170. * @returns the webGL uniform buffer
  1171. */
  1172. abstract createDynamicUniformBuffer(elements: FloatArray, label?: string): DataBuffer;
  1173. /**
  1174. * Create an uniform buffer
  1175. * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets
  1176. * @param elements defines the content of the uniform buffer
  1177. * @param label defines a name for the buffer (for debugging purpose)
  1178. * @returns the webGL uniform buffer
  1179. */
  1180. abstract createUniformBuffer(elements: FloatArray, label?: string): DataBuffer;
  1181. /**
  1182. * Update an existing uniform buffer
  1183. * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets
  1184. * @param uniformBuffer defines the target uniform buffer
  1185. * @param elements defines the content to update
  1186. * @param offset defines the offset in the uniform buffer where update should start
  1187. * @param count defines the size of the data to update
  1188. */
  1189. abstract updateUniformBuffer(uniformBuffer: DataBuffer, elements: FloatArray, offset?: number, count?: number): void;
  1190. /**
  1191. * Update a dynamic index buffer
  1192. * @param indexBuffer defines the target index buffer
  1193. * @param indices defines the data to update
  1194. * @param offset defines the offset in the target index buffer where update should start
  1195. */
  1196. abstract updateDynamicIndexBuffer(indexBuffer: DataBuffer, indices: IndicesArray, offset?: number): void;
  1197. /**
  1198. * Updates a dynamic vertex buffer.
  1199. * @param vertexBuffer the vertex buffer to update
  1200. * @param data the data used to update the vertex buffer
  1201. * @param byteOffset the byte offset of the data
  1202. * @param byteLength the byte length of the data
  1203. */
  1204. abstract updateDynamicVertexBuffer(vertexBuffer: DataBuffer, data: DataArray, byteOffset?: number, byteLength?: number): void;
  1205. /**
  1206. * Creates a dynamic vertex buffer
  1207. * @param data the data for the dynamic vertex buffer
  1208. * @param _label defines the label of the buffer (for debug purpose)
  1209. * @returns the new WebGL dynamic buffer
  1210. */
  1211. abstract createDynamicVertexBuffer(data: DataArray | number, _label?: string): DataBuffer;
  1212. /**
  1213. * Creates a vertex buffer
  1214. * @param data the data or size for the vertex buffer
  1215. * @param _updatable whether the buffer should be created as updatable
  1216. * @param _label defines the label of the buffer (for debug purpose)
  1217. * @returns the new WebGL static buffer
  1218. */
  1219. abstract createVertexBuffer(data: DataArray | number, _updatable?: boolean, _label?: string): DataBuffer;
  1220. /**
  1221. * Update the dimensions of a texture
  1222. * @param texture texture to update
  1223. * @param width new width of the texture
  1224. * @param height new height of the texture
  1225. * @param depth new depth of the texture
  1226. */
  1227. abstract updateTextureDimensions(texture: InternalTexture, width: number, height: number, depth: number): void;
  1228. /**
  1229. * Usually called from Texture.ts.
  1230. * Passed information to create a WebGLTexture
  1231. * @param url defines a value which contains one of the following:
  1232. * * A conventional http URL, e.g. 'http://...' or 'file://...'
  1233. * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
  1234. * * An indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg'
  1235. * @param noMipmap defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file
  1236. * @param invertY when true, image is flipped when loaded. You probably want true. Certain compressed textures may invert this if their default is inverted (eg. ktx)
  1237. * @param scene needed for loading to the correct scene
  1238. * @param samplingMode mode with should be used sample / access the texture (Default: Texture.TRILINEAR_SAMPLINGMODE)
  1239. * @param onLoad optional callback to be called upon successful completion
  1240. * @param onError optional callback to be called upon failure
  1241. * @param buffer a source of a file previously fetched as either a base64 string, an ArrayBuffer (compressed or image format), HTMLImageElement (image format), or a Blob
  1242. * @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities
  1243. * @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures
  1244. * @param forcedExtension defines the extension to use to pick the right loader
  1245. * @param mimeType defines an optional mime type
  1246. * @param loaderOptions options to be passed to the loader
  1247. * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)
  1248. * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).
  1249. * @returns a InternalTexture for assignment back into BABYLON.Texture
  1250. */
  1251. abstract createTexture(url: Nullable<string>, noMipmap: boolean, invertY: boolean, scene: Nullable<ISceneLike>, samplingMode?: number, onLoad?: Nullable<(texture: InternalTexture) => void>, onError?: Nullable<(message: string, exception: any) => void>, buffer?: Nullable<string | ArrayBuffer | ArrayBufferView | HTMLImageElement | Blob | ImageBitmap>, fallback?: Nullable<InternalTexture>, format?: Nullable<number>, forcedExtension?: Nullable<string>, mimeType?: string, loaderOptions?: any, creationFlags?: number, useSRGBBuffer?: boolean): InternalTexture;
  1252. /**
  1253. * @internal
  1254. */
  1255. abstract _setupDepthStencilTexture(internalTexture: InternalTexture, size: number | {
  1256. width: number;
  1257. height: number;
  1258. layers?: number;
  1259. }, generateStencil: boolean, bilinearFiltering: boolean, comparisonFunction: number, samples?: number): void;
  1260. /**
  1261. * Creates a raw texture
  1262. * @param data defines the data to store in the texture
  1263. * @param width defines the width of the texture
  1264. * @param height defines the height of the texture
  1265. * @param format defines the format of the data
  1266. * @param generateMipMaps defines if the engine should generate the mip levels
  1267. * @param invertY defines if data must be stored with Y axis inverted
  1268. * @param samplingMode defines the required sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
  1269. * @param compression defines the compression used (null by default)
  1270. * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
  1271. * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)
  1272. * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).
  1273. * @returns the raw texture inside an InternalTexture
  1274. */
  1275. abstract createRawTexture(data: Nullable<ArrayBufferView>, width: number, height: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression?: Nullable<string>, type?: number, creationFlags?: number, useSRGBBuffer?: boolean): InternalTexture;
  1276. /**
  1277. * Create a cube texture from prefiltered data (ie. the mipmaps contain ready to use data for PBR reflection)
  1278. * @param rootUrl defines the url where the file to load is located
  1279. * @param scene defines the current scene
  1280. * @param lodScale defines scale to apply to the mip map selection
  1281. * @param lodOffset defines offset to apply to the mip map selection
  1282. * @param onLoad defines an optional callback raised when the texture is loaded
  1283. * @param onError defines an optional callback raised if there is an issue to load the texture
  1284. * @param format defines the format of the data
  1285. * @param forcedExtension defines the extension to use to pick the right loader
  1286. * @param createPolynomials defines wheter or not to create polynomails harmonics for the texture
  1287. * @returns the cube texture as an InternalTexture
  1288. */
  1289. abstract createPrefilteredCubeTexture(rootUrl: string, scene: Nullable<Scene>, lodScale: number, lodOffset: number, onLoad?: Nullable<(internalTexture: Nullable<InternalTexture>) => void>, onError?: Nullable<(message?: string, exception?: any) => void>, format?: number, forcedExtension?: any, createPolynomials?: boolean): InternalTexture;
  1290. /**
  1291. * Creates a dynamic texture
  1292. * @param width defines the width of the texture
  1293. * @param height defines the height of the texture
  1294. * @param generateMipMaps defines if the engine should generate the mip levels
  1295. * @param samplingMode defines the required sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
  1296. * @returns the dynamic texture inside an InternalTexture
  1297. */
  1298. abstract createDynamicTexture(width: number, height: number, generateMipMaps: boolean, samplingMode: number): InternalTexture;
  1299. /**
  1300. * Update the content of a dynamic texture
  1301. * @param texture defines the texture to update
  1302. * @param source defines the source containing the data
  1303. * @param invertY defines if data must be stored with Y axis inverted
  1304. * @param premulAlpha defines if alpha is stored as premultiplied
  1305. * @param format defines the format of the data
  1306. * @param forceBindTexture if the texture should be forced to be bound eg. after a graphics context loss (Default: false)
  1307. * @param allowGPUOptimization true to allow some specific GPU optimizations (subject to engine feature "allowGPUOptimizationsForGUI" being true)
  1308. */
  1309. abstract updateDynamicTexture(texture: Nullable<InternalTexture>, source: ImageSource | ICanvas, invertY?: boolean, premulAlpha?: boolean, format?: number, forceBindTexture?: boolean, allowGPUOptimization?: boolean): void;
  1310. /**
  1311. * Creates a cube texture
  1312. * @param rootUrl defines the url where the files to load is located
  1313. * @param scene defines the current scene
  1314. * @param files defines the list of files to load (1 per face)
  1315. * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
  1316. * @param onLoad defines an optional callback raised when the texture is loaded
  1317. * @param onError defines an optional callback raised if there is an issue to load the texture
  1318. * @param format defines the format of the data
  1319. * @param forcedExtension defines the extension to use to pick the right loader
  1320. * @param createPolynomials if a polynomial sphere should be created for the cube texture
  1321. * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness
  1322. * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness
  1323. * @param fallback defines texture to use while falling back when (compressed) texture file not found.
  1324. * @param loaderOptions options to be passed to the loader
  1325. * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).
  1326. * @returns the cube texture as an InternalTexture
  1327. */
  1328. abstract createCubeTexture(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean | undefined, onLoad: Nullable<(data?: any) => void>, onError: Nullable<(message?: string, exception?: any) => void>, format: number | undefined, forcedExtension: any, createPolynomials: boolean, lodScale: number, lodOffset: number, fallback: Nullable<InternalTexture>, loaderOptions: any, useSRGBBuffer: boolean): InternalTexture;
  1329. /**
  1330. * Creates a cube texture
  1331. * @param rootUrl defines the url where the files to load is located
  1332. * @param scene defines the current scene
  1333. * @param files defines the list of files to load (1 per face)
  1334. * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
  1335. * @param onLoad defines an optional callback raised when the texture is loaded
  1336. * @param onError defines an optional callback raised if there is an issue to load the texture
  1337. * @param format defines the format of the data
  1338. * @param forcedExtension defines the extension to use to pick the right loader
  1339. * @returns the cube texture as an InternalTexture
  1340. */
  1341. abstract createCubeTexture(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean, onLoad: Nullable<(data?: any) => void>, onError: Nullable<(message?: string, exception?: any) => void>, format: number | undefined, forcedExtension: any): InternalTexture;
  1342. /**
  1343. * Creates a cube texture
  1344. * @param rootUrl defines the url where the files to load is located
  1345. * @param scene defines the current scene
  1346. * @param files defines the list of files to load (1 per face)
  1347. * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default)
  1348. * @param onLoad defines an optional callback raised when the texture is loaded
  1349. * @param onError defines an optional callback raised if there is an issue to load the texture
  1350. * @param format defines the format of the data
  1351. * @param forcedExtension defines the extension to use to pick the right loader
  1352. * @param createPolynomials if a polynomial sphere should be created for the cube texture
  1353. * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness
  1354. * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness
  1355. * @returns the cube texture as an InternalTexture
  1356. */
  1357. abstract createCubeTexture(rootUrl: string, scene: Nullable<Scene>, files: Nullable<string[]>, noMipmap: boolean, onLoad: Nullable<(data?: any) => void>, onError: Nullable<(message?: string, exception?: any) => void>, format: number | undefined, forcedExtension: any, createPolynomials: boolean, lodScale: number, lodOffset: number): InternalTexture;
  1358. /**
  1359. * Creates a new raw cube texture
  1360. * @param data defines the array of data to use to create each face
  1361. * @param size defines the size of the textures
  1362. * @param format defines the format of the data
  1363. * @param type defines the type of the data (like Engine.TEXTURETYPE_UNSIGNED_INT)
  1364. * @param generateMipMaps defines if the engine should generate the mip levels
  1365. * @param invertY defines if data must be stored with Y axis inverted
  1366. * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)
  1367. * @param compression defines the compression used (null by default)
  1368. * @returns the cube texture as an InternalTexture
  1369. */
  1370. abstract createRawCubeTexture(data: Nullable<ArrayBufferView[]>, size: number, format: number, type: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression?: Nullable<string>): InternalTexture;
  1371. /**
  1372. * Update a raw cube texture
  1373. * @param texture defines the texture to update
  1374. * @param data defines the data to store
  1375. * @param format defines the data format
  1376. * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
  1377. * @param invertY defines if data must be stored with Y axis inverted
  1378. */
  1379. abstract updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean): void;
  1380. /**
  1381. * Update a raw cube texture
  1382. * @param texture defines the texture to update
  1383. * @param data defines the data to store
  1384. * @param format defines the data format
  1385. * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
  1386. * @param invertY defines if data must be stored with Y axis inverted
  1387. * @param compression defines the compression used (null by default)
  1388. */
  1389. abstract updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean, compression: Nullable<string>): void;
  1390. /**
  1391. * Update a raw cube texture
  1392. * @param texture defines the texture to update
  1393. * @param data defines the data to store
  1394. * @param format defines the data format
  1395. * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
  1396. * @param invertY defines if data must be stored with Y axis inverted
  1397. * @param compression defines the compression used (null by default)
  1398. * @param level defines which level of the texture to update
  1399. */
  1400. abstract updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean, compression: Nullable<string>, level: number): void;
  1401. /**
  1402. * Creates a new raw cube texture from a specified url
  1403. * @param url defines the url where the data is located
  1404. * @param scene defines the current scene
  1405. * @param size defines the size of the textures
  1406. * @param format defines the format of the data
  1407. * @param type defines the type fo the data (like Engine.TEXTURETYPE_UNSIGNED_INT)
  1408. * @param noMipmap defines if the engine should avoid generating the mip levels
  1409. * @param callback defines a callback used to extract texture data from loaded data
  1410. * @param mipmapGenerator defines to provide an optional tool to generate mip levels
  1411. * @param onLoad defines a callback called when texture is loaded
  1412. * @param onError defines a callback called if there is an error
  1413. * @returns the cube texture as an InternalTexture
  1414. */
  1415. abstract createRawCubeTextureFromUrl(url: string, scene: Nullable<Scene>, size: number, format: number, type: number, noMipmap: boolean, callback: (ArrayBuffer: ArrayBuffer) => Nullable<ArrayBufferView[]>, mipmapGenerator: Nullable<(faces: ArrayBufferView[]) => ArrayBufferView[][]>, onLoad: Nullable<() => void>, onError: Nullable<(message?: string, exception?: any) => void>): InternalTexture;
  1416. /**
  1417. * Creates a new raw cube texture from a specified url
  1418. * @param url defines the url where the data is located
  1419. * @param scene defines the current scene
  1420. * @param size defines the size of the textures
  1421. * @param format defines the format of the data
  1422. * @param type defines the type fo the data (like Engine.TEXTURETYPE_UNSIGNED_INT)
  1423. * @param noMipmap defines if the engine should avoid generating the mip levels
  1424. * @param callback defines a callback used to extract texture data from loaded data
  1425. * @param mipmapGenerator defines to provide an optional tool to generate mip levels
  1426. * @param onLoad defines a callback called when texture is loaded
  1427. * @param onError defines a callback called if there is an error
  1428. * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)
  1429. * @param invertY defines if data must be stored with Y axis inverted
  1430. * @returns the cube texture as an InternalTexture
  1431. */
  1432. abstract createRawCubeTextureFromUrl(url: string, scene: Nullable<Scene>, size: number, format: number, type: number, noMipmap: boolean, callback: (ArrayBuffer: ArrayBuffer) => Nullable<ArrayBufferView[]>, mipmapGenerator: Nullable<(faces: ArrayBufferView[]) => ArrayBufferView[][]>, onLoad: Nullable<() => void>, onError: Nullable<(message?: string, exception?: any) => void>, samplingMode: number, invertY: boolean): InternalTexture;
  1433. /**
  1434. * Creates a new raw 3D texture
  1435. * @param data defines the data used to create the texture
  1436. * @param width defines the width of the texture
  1437. * @param height defines the height of the texture
  1438. * @param depth defines the depth of the texture
  1439. * @param format defines the format of the texture
  1440. * @param generateMipMaps defines if the engine must generate mip levels
  1441. * @param invertY defines if data must be stored with Y axis inverted
  1442. * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)
  1443. * @param compression defines the compressed used (can be null)
  1444. * @param textureType defines the compressed used (can be null)
  1445. * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)
  1446. * @returns a new raw 3D texture (stored in an InternalTexture)
  1447. */
  1448. abstract createRawTexture3D(data: Nullable<ArrayBufferView>, width: number, height: number, depth: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression?: Nullable<string>, textureType?: number, creationFlags?: number): InternalTexture;
  1449. /**
  1450. * Update a raw 3D texture
  1451. * @param texture defines the texture to update
  1452. * @param data defines the data to store
  1453. * @param format defines the data format
  1454. * @param invertY defines if data must be stored with Y axis inverted
  1455. */
  1456. abstract updateRawTexture3D(texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean): void;
  1457. /**
  1458. * Update a raw 3D texture
  1459. * @param texture defines the texture to update
  1460. * @param data defines the data to store
  1461. * @param format defines the data format
  1462. * @param invertY defines if data must be stored with Y axis inverted
  1463. * @param compression defines the used compression (can be null)
  1464. * @param textureType defines the texture Type (Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT...)
  1465. */
  1466. abstract updateRawTexture3D(texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string>, textureType: number): void;
  1467. /**
  1468. * Creates a new raw 2D array texture
  1469. * @param data defines the data used to create the texture
  1470. * @param width defines the width of the texture
  1471. * @param height defines the height of the texture
  1472. * @param depth defines the number of layers of the texture
  1473. * @param format defines the format of the texture
  1474. * @param generateMipMaps defines if the engine must generate mip levels
  1475. * @param invertY defines if data must be stored with Y axis inverted
  1476. * @param samplingMode defines the required sampling mode (like Texture.NEAREST_SAMPLINGMODE)
  1477. * @param compression defines the compressed used (can be null)
  1478. * @param textureType defines the compressed used (can be null)
  1479. * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)
  1480. * @returns a new raw 2D array texture (stored in an InternalTexture)
  1481. */
  1482. abstract createRawTexture2DArray(data: Nullable<ArrayBufferView>, width: number, height: number, depth: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression?: Nullable<string>, textureType?: number, creationFlags?: number): InternalTexture;
  1483. /**
  1484. * Update a raw 2D array texture
  1485. * @param texture defines the texture to update
  1486. * @param data defines the data to store
  1487. * @param format defines the data format
  1488. * @param invertY defines if data must be stored with Y axis inverted
  1489. */
  1490. abstract updateRawTexture2DArray(texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean): void;
  1491. /**
  1492. * Update a raw 2D array texture
  1493. * @param texture defines the texture to update
  1494. * @param data defines the data to store
  1495. * @param format defines the data format
  1496. * @param invertY defines if data must be stored with Y axis inverted
  1497. * @param compression defines the used compression (can be null)
  1498. * @param textureType defines the texture Type (Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT...)
  1499. */
  1500. abstract updateRawTexture2DArray(texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string>, textureType: number): void;
  1501. /**
  1502. * Gets or sets a boolean indicating if back faces must be culled. If false, front faces are culled instead (true by default)
  1503. * If non null, this takes precedence over the value from the material
  1504. */
  1505. cullBackFaces: Nullable<boolean>;
  1506. /**
  1507. * Gets the current render width
  1508. * @param useScreen defines if screen size must be used (or the current render target if any)
  1509. * @returns a number defining the current render width
  1510. */
  1511. abstract getRenderWidth(useScreen?: boolean): number;
  1512. /**
  1513. * Gets the current render height
  1514. * @param useScreen defines if screen size must be used (or the current render target if any)
  1515. * @returns a number defining the current render height
  1516. */
  1517. abstract getRenderHeight(useScreen?: boolean): number;
  1518. /**
  1519. * Shared initialization across engines types.
  1520. * @param canvas The canvas associated with this instance of the engine.
  1521. */
  1522. protected _sharedInit(canvas: HTMLCanvasElement): void;
  1523. private _checkForMobile;
  1524. protected _setupMobileChecks(): void;
  1525. /** @internal */
  1526. static _RenderPassIdCounter: number;
  1527. /** @internal */
  1528. _renderPassNames: string[];
  1529. /** @internal */
  1530. abstract _createHardwareTexture(): HardwareTextureWrapper;
  1531. /**
  1532. * creates and returns a new video element
  1533. * @param constraints video constraints
  1534. * @returns video element
  1535. */
  1536. createVideoElement(constraints: MediaTrackConstraints): any;
  1537. protected _fps: number;
  1538. protected _deltaTime: number;
  1539. /** @internal */
  1540. _drawCalls: PerfCounter;
  1541. /**
  1542. * @internal
  1543. */
  1544. _reportDrawCall(numDrawCalls?: number): void;
  1545. /**
  1546. * Gets the current framerate
  1547. * @returns a number representing the framerate
  1548. */
  1549. getFps(): number;
  1550. /**
  1551. * Gets the time spent between current and previous frame
  1552. * @returns a number representing the delta time in ms
  1553. */
  1554. getDeltaTime(): number;
  1555. /** @internal */
  1556. _deterministicLockstep: boolean;
  1557. /** @internal */
  1558. _lockstepMaxSteps: number;
  1559. /** @internal */
  1560. _timeStep: number;
  1561. /**
  1562. * Gets a boolean indicating that the engine is running in deterministic lock step mode
  1563. * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep
  1564. * @returns true if engine is in deterministic lock step mode
  1565. */
  1566. isDeterministicLockStep(): boolean;
  1567. /**
  1568. * Gets the max steps when engine is running in deterministic lock step
  1569. * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep
  1570. * @returns the max steps
  1571. */
  1572. getLockstepMaxSteps(): number;
  1573. /**
  1574. * Returns the time in ms between steps when using deterministic lock step.
  1575. * @returns time step in (ms)
  1576. */
  1577. getTimeStep(): number;
  1578. /**
  1579. * Force the mipmap generation for the given render target texture
  1580. * @param texture defines the render target texture to use
  1581. * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.
  1582. */
  1583. abstract generateMipMapsForCubemap(texture: InternalTexture, unbind: boolean): void;
  1584. /**
  1585. * Engine abstraction for loading and creating an image bitmap from a given source string.
  1586. * @param imageSource source to load the image from.
  1587. * @param options An object that sets options for the image's extraction.
  1588. */
  1589. _createImageBitmapFromSource(imageSource: string, options?: ImageBitmapOptions): Promise<ImageBitmap>;
  1590. /**
  1591. * Engine abstraction for createImageBitmap
  1592. * @param image source for image
  1593. * @param options An object that sets options for the image's extraction.
  1594. * @returns ImageBitmap
  1595. */
  1596. createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
  1597. /**
  1598. * Resize an image and returns the image data as an uint8array
  1599. * @param image image to resize
  1600. * @param bufferWidth destination buffer width
  1601. * @param bufferHeight destination buffer height
  1602. */
  1603. resizeImageBitmap(image: HTMLImageElement | ImageBitmap, bufferWidth: number, bufferHeight: number): Uint8Array;
  1604. /**
  1605. * Get the current error code of the webGL context
  1606. * @returns the error code
  1607. */
  1608. abstract getError(): number;
  1609. /**
  1610. * Get Font size information
  1611. * @param font font name
  1612. */
  1613. getFontOffset(font: string): {
  1614. ascent: number;
  1615. height: number;
  1616. descent: number;
  1617. };
  1618. protected static _CreateCanvas(width: number, height: number): ICanvas;
  1619. /**
  1620. * Create a canvas. This method is overridden by other engines
  1621. * @param width width
  1622. * @param height height
  1623. * @returns ICanvas interface
  1624. */
  1625. createCanvas(width: number, height: number): ICanvas;
  1626. /**
  1627. * Loads an image as an HTMLImageElement.
  1628. * @param input url string, ArrayBuffer, or Blob to load
  1629. * @param onLoad callback called when the image successfully loads
  1630. * @param onError callback called when the image fails to load
  1631. * @param offlineProvider offline provider for caching
  1632. * @param mimeType optional mime type
  1633. * @param imageBitmapOptions optional the options to use when creating an ImageBitmap
  1634. * @returns the HTMLImageElement of the loaded image
  1635. * @internal
  1636. */
  1637. static _FileToolsLoadImage(input: string | ArrayBuffer | ArrayBufferView | Blob, onLoad: (img: HTMLImageElement | ImageBitmap) => void, onError: (message?: string, exception?: any) => void, offlineProvider: Nullable<IOfflineProvider>, mimeType?: string, imageBitmapOptions?: ImageBitmapOptions): Nullable<HTMLImageElement>;
  1638. /**
  1639. * Loads a file from a url
  1640. * @param url url to load
  1641. * @param onSuccess callback called when the file successfully loads
  1642. * @param onProgress callback called while file is loading (if the server supports this mode)
  1643. * @param offlineProvider defines the offline provider for caching
  1644. * @param useArrayBuffer defines a boolean indicating that date must be returned as ArrayBuffer
  1645. * @param onError callback called when the file fails to load
  1646. * @returns a file request object
  1647. * @internal
  1648. */
  1649. static _FileToolsLoadFile(url: string, onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void, onProgress?: (ev: ProgressEvent) => void, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean, onError?: (request?: WebRequest, exception?: LoadFileError) => void): IFileRequest;
  1650. /**
  1651. * @internal
  1652. */
  1653. _loadFile(url: string, onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void, onProgress?: (data: any) => void, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean, onError?: (request?: IWebRequest, exception?: any) => void): IFileRequest;
  1654. /**
  1655. * An event triggered when the engine is disposed.
  1656. */
  1657. readonly onDisposeObservable: Observable<AbstractEngine>;
  1658. /**
  1659. * Dispose and release all associated resources
  1660. */
  1661. dispose(): void;
  1662. /**
  1663. * Method called to create the default rescale post process on each engine.
  1664. */
  1665. static _RescalePostProcessFactory: Nullable<(engine: AbstractEngine) => PostProcess>;
  1666. /**
  1667. * Method called to create the default loading screen.
  1668. * This can be overridden in your own app.
  1669. * @param canvas The rendering canvas element
  1670. */
  1671. static DefaultLoadingScreenFactory(canvas: HTMLCanvasElement): ILoadingScreen;
  1672. /**
  1673. * Gets the audio engine
  1674. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  1675. * @ignorenaming
  1676. */
  1677. static audioEngine: Nullable<IAudioEngine>;
  1678. /**
  1679. * Default AudioEngine factory responsible of creating the Audio Engine.
  1680. * By default, this will create a BabylonJS Audio Engine if the workload has been embedded.
  1681. */
  1682. static AudioEngineFactory: (hostElement: Nullable<HTMLElement>, audioContext: Nullable<AudioContext>, audioDestination: Nullable<AudioDestinationNode | MediaStreamAudioDestinationNode>) => IAudioEngine;
  1683. /**
  1684. * Default offline support factory responsible of creating a tool used to store data locally.
  1685. * By default, this will create a Database object if the workload has been embedded.
  1686. */
  1687. static OfflineProviderFactory: (urlToScene: string, callbackManifestChecked: (checked: boolean) => any, disableManifestCheck: boolean) => IOfflineProvider;
  1688. }