thinEngine.d.ts 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. import type { IEffectCreationOptions, IShaderPath } from "../Materials/effect";
  2. import type { ShaderProcessingContext } from "./Processors/shaderProcessingOptions";
  3. import type { Nullable, DataArray, IndicesArray, FloatArray, DeepImmutable } from "../types";
  4. import type { IColor4Like } from "../Maths/math.like";
  5. import type { DataBuffer } from "../Buffers/dataBuffer";
  6. import type { IPipelineContext } from "./IPipelineContext";
  7. import type { VertexBuffer } from "../Buffers/buffer";
  8. import type { InstancingAttributeInfo } from "./instancingAttributeInfo";
  9. import type { ThinTexture } from "../Materials/Textures/thinTexture";
  10. import type { IEffectFallbacks } from "../Materials/iEffectFallbacks";
  11. import type { HardwareTextureWrapper } from "../Materials/Textures/hardwareTextureWrapper";
  12. import type { DrawWrapper } from "../Materials/drawWrapper";
  13. import type { IMaterialContext } from "./IMaterialContext";
  14. import type { IDrawContext } from "./IDrawContext";
  15. import type { ICanvas, ICanvasRenderingContext } from "./ICanvas";
  16. import type { IStencilState } from "../States/IStencilState";
  17. import type { InternalTextureCreationOptions, TextureSize } from "../Materials/Textures/textureCreationOptions";
  18. import type { RenderTargetWrapper } from "./renderTargetWrapper";
  19. import type { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
  20. import type { AbstractEngineOptions, ISceneLike } from "./abstractEngine";
  21. import type { PostProcess } from "../PostProcesses/postProcess";
  22. import type { PerformanceMonitor } from "../Misc/performanceMonitor";
  23. import { AbstractEngine } from "./abstractEngine";
  24. import { ShaderLanguage } from "../Materials/shaderLanguage";
  25. import { WebGLPipelineContext } from "./WebGL/webGLPipelineContext";
  26. import { InternalTexture, InternalTextureSource } from "../Materials/Textures/internalTexture";
  27. import { Effect } from "../Materials/effect";
  28. /** Interface defining initialization parameters for Engine class */
  29. export interface EngineOptions extends AbstractEngineOptions, WebGLContextAttributes {
  30. /**
  31. * Defines if webgl2 should be turned off even if supported
  32. * @see https://doc.babylonjs.com/setup/support/webGL2
  33. */
  34. disableWebGL2Support?: boolean;
  35. /**
  36. * Defines that engine should compile shaders with high precision floats (if supported). True by default
  37. */
  38. useHighPrecisionFloats?: boolean;
  39. /**
  40. * Make the canvas XR Compatible for XR sessions
  41. */
  42. xrCompatible?: boolean;
  43. /**
  44. * Will prevent the system from falling back to software implementation if a hardware device cannot be created
  45. */
  46. failIfMajorPerformanceCaveat?: boolean;
  47. /**
  48. * If sRGB Buffer support is not set during construction, use this value to force a specific state
  49. * This is added due to an issue when processing textures in chrome/edge/firefox
  50. * This will not influence NativeEngine and WebGPUEngine which set the behavior to true during construction.
  51. */
  52. forceSRGBBufferSupportState?: boolean;
  53. /**
  54. * Defines if the gl context should be released.
  55. * It's false by default for backward compatibility, but you should probably pass true (see https://registry.khronos.org/webgl/extensions/WEBGL_lose_context/)
  56. */
  57. loseContextOnDispose?: boolean;
  58. }
  59. /**
  60. * The base engine class (root of all engines)
  61. */
  62. export declare class ThinEngine extends AbstractEngine {
  63. private static _TempClearColorUint32;
  64. private static _TempClearColorInt32;
  65. /** Use this array to turn off some WebGL2 features on known buggy browsers version */
  66. static ExceptionList: ({
  67. key: string;
  68. capture: string;
  69. captureConstraint: number;
  70. targets: string[];
  71. } | {
  72. key: string;
  73. capture: null;
  74. captureConstraint: null;
  75. targets: string[];
  76. })[];
  77. /** @internal */
  78. protected _creationOptions: EngineOptions;
  79. /** @internal */
  80. protected _name: string;
  81. /**
  82. * Gets or sets the name of the engine
  83. */
  84. get name(): string;
  85. set name(value: string);
  86. /**
  87. * Returns the version of the engine
  88. */
  89. get version(): number;
  90. /**
  91. * Gets or sets the epsilon value used by collision engine
  92. */
  93. static CollisionsEpsilon: number;
  94. /**
  95. * Gets or sets the relative url used to load shaders if using the engine in non-minified mode
  96. */
  97. static get ShadersRepository(): string;
  98. static set ShadersRepository(value: string);
  99. /**
  100. * Gets or sets a boolean that indicates if textures must be forced to power of 2 size even if not required
  101. */
  102. forcePOTTextures: boolean;
  103. /** Gets or sets a boolean indicating if the engine should validate programs after compilation */
  104. validateShaderPrograms: boolean;
  105. /**
  106. * Gets or sets a boolean indicating that uniform buffers must be disabled even if they are supported
  107. */
  108. disableUniformBuffers: boolean;
  109. /**
  110. * Gets a boolean indicating that the engine supports uniform buffers
  111. * @see https://doc.babylonjs.com/setup/support/webGL2#uniform-buffer-objets
  112. */
  113. get supportsUniformBuffers(): boolean;
  114. /** @internal */
  115. _gl: WebGL2RenderingContext;
  116. /** @internal */
  117. _webGLVersion: number;
  118. /** @internal */
  119. _glSRGBExtensionValues: {
  120. SRGB: typeof WebGL2RenderingContext.SRGB;
  121. SRGB8: typeof WebGL2RenderingContext.SRGB8 | EXT_sRGB["SRGB_ALPHA_EXT"];
  122. SRGB8_ALPHA8: typeof WebGL2RenderingContext.SRGB8_ALPHA8 | EXT_sRGB["SRGB_ALPHA_EXT"];
  123. };
  124. /**
  125. * Gets the options used for engine creation
  126. * @returns EngineOptions object
  127. */
  128. getCreationOptions(): EngineOptions;
  129. /**
  130. * Gets a boolean indicating that only power of 2 textures are supported
  131. * Please note that you can still use non power of 2 textures but in this case the engine will forcefully convert them
  132. */
  133. get needPOTTextures(): boolean;
  134. private _glVersion;
  135. private _glRenderer;
  136. private _glVendor;
  137. /** @internal */
  138. _currentMaterialContext: IMaterialContext;
  139. /** @internal */
  140. protected _currentProgram: Nullable<WebGLProgram>;
  141. private _vertexAttribArraysEnabled;
  142. private _cachedVertexArrayObject;
  143. private _uintIndicesCurrentlySet;
  144. protected _currentBoundBuffer: Nullable<DataBuffer>[];
  145. /** @internal */
  146. _currentFramebuffer: Nullable<WebGLFramebuffer>;
  147. /** @internal */
  148. _dummyFramebuffer: Nullable<WebGLFramebuffer>;
  149. private _currentBufferPointers;
  150. private _currentInstanceLocations;
  151. private _currentInstanceBuffers;
  152. private _textureUnits;
  153. /** @internal */
  154. _workingCanvas: Nullable<ICanvas>;
  155. /** @internal */
  156. _workingContext: Nullable<ICanvasRenderingContext>;
  157. private _vaoRecordInProgress;
  158. private _mustWipeVertexAttributes;
  159. private _nextFreeTextureSlots;
  160. private _maxSimultaneousTextures;
  161. private _maxMSAASamplesOverride;
  162. protected get _supportsHardwareTextureRescaling(): boolean;
  163. protected _framebufferDimensionsObject: Nullable<{
  164. framebufferWidth: number;
  165. framebufferHeight: number;
  166. }>;
  167. /**
  168. * sets the object from which width and height will be taken from when getting render width and height
  169. * Will fallback to the gl object
  170. * @param dimensions the framebuffer width and height that will be used.
  171. */
  172. set framebufferDimensionsObject(dimensions: Nullable<{
  173. framebufferWidth: number;
  174. framebufferHeight: number;
  175. }>);
  176. /**
  177. * Creates a new snapshot at the next frame using the current snapshotRenderingMode
  178. */
  179. snapshotRenderingReset(): void;
  180. /**
  181. * Creates a new engine
  182. * @param canvasOrContext defines the canvas or WebGL context to use for rendering. If you provide a WebGL context, Babylon.js will not hook events on the canvas (like pointers, keyboards, etc...) so no event observables will be available. This is mostly used when Babylon.js is used as a plugin on a system which already used the WebGL context
  183. * @param antialias defines enable antialiasing (default: false)
  184. * @param options defines further options to be sent to the getContext() function
  185. * @param adaptToDeviceRatio defines whether to adapt to the device's viewport characteristics (default: false)
  186. */
  187. constructor(canvasOrContext: Nullable<HTMLCanvasElement | OffscreenCanvas | WebGLRenderingContext | WebGL2RenderingContext>, antialias?: boolean, options?: EngineOptions, adaptToDeviceRatio?: boolean);
  188. protected _clearEmptyResources(): void;
  189. /**
  190. * @internal
  191. */
  192. _getShaderProcessingContext(shaderLanguage: ShaderLanguage): Nullable<ShaderProcessingContext>;
  193. /**
  194. * Gets a boolean indicating if all created effects are ready
  195. * @returns true if all effects are ready
  196. */
  197. areAllEffectsReady(): boolean;
  198. protected _initGLContext(): void;
  199. protected _initFeatures(): void;
  200. /**
  201. * Gets version of the current webGL context
  202. * Keep it for back compat - use version instead
  203. */
  204. get webGLVersion(): number;
  205. /**
  206. * Gets a string identifying the name of the class
  207. * @returns "Engine" string
  208. */
  209. getClassName(): string;
  210. /** @internal */
  211. _prepareWorkingCanvas(): void;
  212. /**
  213. * Gets an object containing information about the current engine context
  214. * @returns an object containing the vendor, the renderer and the version of the current engine context
  215. */
  216. getInfo(): {
  217. vendor: string;
  218. renderer: string;
  219. version: string;
  220. };
  221. /**
  222. * Gets an object containing information about the current webGL context
  223. * @returns an object containing the vendor, the renderer and the version of the current webGL context
  224. */
  225. getGlInfo(): {
  226. vendor: string;
  227. renderer: string;
  228. version: string;
  229. };
  230. /**Gets driver info if available */
  231. extractDriverInfo(): string;
  232. /**
  233. * Gets the current render width
  234. * @param useScreen defines if screen size must be used (or the current render target if any)
  235. * @returns a number defining the current render width
  236. */
  237. getRenderWidth(useScreen?: boolean): number;
  238. /**
  239. * Gets the current render height
  240. * @param useScreen defines if screen size must be used (or the current render target if any)
  241. * @returns a number defining the current render height
  242. */
  243. getRenderHeight(useScreen?: boolean): number;
  244. /**
  245. * Clear the current render buffer or the current render target (if any is set up)
  246. * @param color defines the color to use
  247. * @param backBuffer defines if the back buffer must be cleared
  248. * @param depth defines if the depth buffer must be cleared
  249. * @param stencil defines if the stencil buffer must be cleared
  250. */
  251. clear(color: Nullable<IColor4Like>, backBuffer: boolean, depth: boolean, stencil?: boolean): void;
  252. /**
  253. * @internal
  254. */
  255. _viewport(x: number, y: number, width: number, height: number): void;
  256. /**
  257. * End the current frame
  258. */
  259. endFrame(): void;
  260. /**
  261. * Gets the performance monitor attached to this engine
  262. * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimize_your_scene#engineinstrumentation
  263. */
  264. get performanceMonitor(): PerformanceMonitor;
  265. /**
  266. * Binds the frame buffer to the specified texture.
  267. * @param rtWrapper The render target wrapper to render to
  268. * @param faceIndex The face of the texture to render to in case of cube texture and if the render target wrapper is not a multi render target
  269. * @param requiredWidth The width of the target to render to
  270. * @param requiredHeight The height of the target to render to
  271. * @param forceFullscreenViewport Forces the viewport to be the entire texture/screen if true
  272. * @param lodLevel Defines the lod level to bind to the frame buffer
  273. * @param layer Defines the 2d array index to bind to the frame buffer if the render target wrapper is not a multi render target
  274. */
  275. bindFramebuffer(rtWrapper: RenderTargetWrapper, faceIndex?: number, requiredWidth?: number, requiredHeight?: number, forceFullscreenViewport?: boolean, lodLevel?: number, layer?: number): void;
  276. /**
  277. * Set various states to the webGL context
  278. * @param culling defines culling state: true to enable culling, false to disable it
  279. * @param zOffset defines the value to apply to zOffset (0 by default)
  280. * @param force defines if states must be applied even if cache is up to date
  281. * @param reverseSide defines if culling must be reversed (CCW if false, CW if true)
  282. * @param cullBackFaces true to cull back faces, false to cull front faces (if culling is enabled)
  283. * @param stencil stencil states to set
  284. * @param zOffsetUnits defines the value to apply to zOffsetUnits (0 by default)
  285. */
  286. setState(culling: boolean, zOffset?: number, force?: boolean, reverseSide?: boolean, cullBackFaces?: boolean, stencil?: IStencilState, zOffsetUnits?: number): void;
  287. /**
  288. * @internal
  289. */
  290. _bindUnboundFramebuffer(framebuffer: Nullable<WebGLFramebuffer>): void;
  291. /** @internal */
  292. _currentFrameBufferIsDefaultFrameBuffer(): boolean;
  293. /**
  294. * Generates the mipmaps for a texture
  295. * @param texture texture to generate the mipmaps for
  296. */
  297. generateMipmaps(texture: InternalTexture): void;
  298. /**
  299. * Unbind the current render target texture from the webGL context
  300. * @param texture defines the render target wrapper to unbind
  301. * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated
  302. * @param onBeforeUnbind defines a function which will be called before the effective unbind
  303. */
  304. unBindFramebuffer(texture: RenderTargetWrapper, disableGenerateMipMaps?: boolean, onBeforeUnbind?: () => void): void;
  305. /**
  306. * Force a webGL flush (ie. a flush of all waiting webGL commands)
  307. */
  308. flushFramebuffer(): void;
  309. /**
  310. * Unbind the current render target and bind the default framebuffer
  311. */
  312. restoreDefaultFramebuffer(): void;
  313. /** @internal */
  314. protected _resetVertexBufferBinding(): void;
  315. /**
  316. * Creates a vertex buffer
  317. * @param data the data or size for the vertex buffer
  318. * @param _updatable whether the buffer should be created as updatable
  319. * @param _label defines the label of the buffer (for debug purpose)
  320. * @returns the new WebGL static buffer
  321. */
  322. createVertexBuffer(data: DataArray | number, _updatable?: boolean, _label?: string): DataBuffer;
  323. private _createVertexBuffer;
  324. /**
  325. * Creates a dynamic vertex buffer
  326. * @param data the data for the dynamic vertex buffer
  327. * @param _label defines the label of the buffer (for debug purpose)
  328. * @returns the new WebGL dynamic buffer
  329. */
  330. createDynamicVertexBuffer(data: DataArray | number, _label?: string): DataBuffer;
  331. protected _resetIndexBufferBinding(): void;
  332. /**
  333. * Creates a new index buffer
  334. * @param indices defines the content of the index buffer
  335. * @param updatable defines if the index buffer must be updatable
  336. * @param _label defines the label of the buffer (for debug purpose)
  337. * @returns a new webGL buffer
  338. */
  339. createIndexBuffer(indices: IndicesArray, updatable?: boolean, _label?: string): DataBuffer;
  340. protected _normalizeIndexData(indices: IndicesArray): Uint16Array | Uint32Array;
  341. /**
  342. * Bind a webGL buffer to the webGL context
  343. * @param buffer defines the buffer to bind
  344. */
  345. bindArrayBuffer(buffer: Nullable<DataBuffer>): void;
  346. protected bindIndexBuffer(buffer: Nullable<DataBuffer>): void;
  347. private _bindBuffer;
  348. /**
  349. * update the bound buffer with the given data
  350. * @param data defines the data to update
  351. */
  352. updateArrayBuffer(data: Float32Array): void;
  353. private _vertexAttribPointer;
  354. /**
  355. * @internal
  356. */
  357. _bindIndexBufferWithCache(indexBuffer: Nullable<DataBuffer>): void;
  358. private _bindVertexBuffersAttributes;
  359. /**
  360. * Records a vertex array object
  361. * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects
  362. * @param vertexBuffers defines the list of vertex buffers to store
  363. * @param indexBuffer defines the index buffer to store
  364. * @param effect defines the effect to store
  365. * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers
  366. * @returns the new vertex array object
  367. */
  368. recordVertexArrayObject(vertexBuffers: {
  369. [key: string]: VertexBuffer;
  370. }, indexBuffer: Nullable<DataBuffer>, effect: Effect, overrideVertexBuffers?: {
  371. [kind: string]: Nullable<VertexBuffer>;
  372. }): WebGLVertexArrayObject;
  373. /**
  374. * Bind a specific vertex array object
  375. * @see https://doc.babylonjs.com/setup/support/webGL2#vertex-array-objects
  376. * @param vertexArrayObject defines the vertex array object to bind
  377. * @param indexBuffer defines the index buffer to bind
  378. */
  379. bindVertexArrayObject(vertexArrayObject: WebGLVertexArrayObject, indexBuffer: Nullable<DataBuffer>): void;
  380. /**
  381. * Bind webGl buffers directly to the webGL context
  382. * @param vertexBuffer defines the vertex buffer to bind
  383. * @param indexBuffer defines the index buffer to bind
  384. * @param vertexDeclaration defines the vertex declaration to use with the vertex buffer
  385. * @param vertexStrideSize defines the vertex stride of the vertex buffer
  386. * @param effect defines the effect associated with the vertex buffer
  387. */
  388. bindBuffersDirectly(vertexBuffer: DataBuffer, indexBuffer: DataBuffer, vertexDeclaration: number[], vertexStrideSize: number, effect: Effect): void;
  389. private _unbindVertexArrayObject;
  390. /**
  391. * Bind a list of vertex buffers to the webGL context
  392. * @param vertexBuffers defines the list of vertex buffers to bind
  393. * @param indexBuffer defines the index buffer to bind
  394. * @param effect defines the effect associated with the vertex buffers
  395. * @param overrideVertexBuffers defines optional list of avertex buffers that overrides the entries in vertexBuffers
  396. */
  397. bindBuffers(vertexBuffers: {
  398. [key: string]: Nullable<VertexBuffer>;
  399. }, indexBuffer: Nullable<DataBuffer>, effect: Effect, overrideVertexBuffers?: {
  400. [kind: string]: Nullable<VertexBuffer>;
  401. }): void;
  402. /**
  403. * Unbind all instance attributes
  404. */
  405. unbindInstanceAttributes(): void;
  406. /**
  407. * Release and free the memory of a vertex array object
  408. * @param vao defines the vertex array object to delete
  409. */
  410. releaseVertexArrayObject(vao: WebGLVertexArrayObject): void;
  411. /**
  412. * @internal
  413. */
  414. _releaseBuffer(buffer: DataBuffer): boolean;
  415. protected _deleteBuffer(buffer: DataBuffer): void;
  416. /**
  417. * Update the content of a webGL buffer used with instantiation and bind it to the webGL context
  418. * @param instancesBuffer defines the webGL buffer to update and bind
  419. * @param data defines the data to store in the buffer
  420. * @param offsetLocations defines the offsets or attributes information used to determine where data must be stored in the buffer
  421. */
  422. updateAndBindInstancesBuffer(instancesBuffer: DataBuffer, data: Float32Array, offsetLocations: number[] | InstancingAttributeInfo[]): void;
  423. /**
  424. * Bind the content of a webGL buffer used with instantiation
  425. * @param instancesBuffer defines the webGL buffer to bind
  426. * @param attributesInfo defines the offsets or attributes information used to determine where data must be stored in the buffer
  427. * @param computeStride defines Whether to compute the strides from the info or use the default 0
  428. */
  429. bindInstancesBuffer(instancesBuffer: DataBuffer, attributesInfo: InstancingAttributeInfo[], computeStride?: boolean): void;
  430. /**
  431. * Disable the instance attribute corresponding to the name in parameter
  432. * @param name defines the name of the attribute to disable
  433. */
  434. disableInstanceAttributeByName(name: string): void;
  435. /**
  436. * Disable the instance attribute corresponding to the location in parameter
  437. * @param attributeLocation defines the attribute location of the attribute to disable
  438. */
  439. disableInstanceAttribute(attributeLocation: number): void;
  440. /**
  441. * Disable the attribute corresponding to the location in parameter
  442. * @param attributeLocation defines the attribute location of the attribute to disable
  443. */
  444. disableAttributeByIndex(attributeLocation: number): void;
  445. /**
  446. * Send a draw order
  447. * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
  448. * @param indexStart defines the starting index
  449. * @param indexCount defines the number of index to draw
  450. * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
  451. */
  452. draw(useTriangles: boolean, indexStart: number, indexCount: number, instancesCount?: number): void;
  453. /**
  454. * Draw a list of points
  455. * @param verticesStart defines the index of first vertex to draw
  456. * @param verticesCount defines the count of vertices to draw
  457. * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
  458. */
  459. drawPointClouds(verticesStart: number, verticesCount: number, instancesCount?: number): void;
  460. /**
  461. * Draw a list of unindexed primitives
  462. * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
  463. * @param verticesStart defines the index of first vertex to draw
  464. * @param verticesCount defines the count of vertices to draw
  465. * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
  466. */
  467. drawUnIndexed(useTriangles: boolean, verticesStart: number, verticesCount: number, instancesCount?: number): void;
  468. /**
  469. * Draw a list of indexed primitives
  470. * @param fillMode defines the primitive to use
  471. * @param indexStart defines the starting index
  472. * @param indexCount defines the number of index to draw
  473. * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
  474. */
  475. drawElementsType(fillMode: number, indexStart: number, indexCount: number, instancesCount?: number): void;
  476. /**
  477. * Draw a list of unindexed primitives
  478. * @param fillMode defines the primitive to use
  479. * @param verticesStart defines the index of first vertex to draw
  480. * @param verticesCount defines the count of vertices to draw
  481. * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
  482. */
  483. drawArraysType(fillMode: number, verticesStart: number, verticesCount: number, instancesCount?: number): void;
  484. private _drawMode;
  485. /**
  486. * @internal
  487. */
  488. _releaseEffect(effect: Effect): void;
  489. /**
  490. * @internal
  491. */
  492. _deletePipelineContext(pipelineContext: IPipelineContext): void;
  493. /**
  494. * Create a new effect (used to store vertex/fragment shaders)
  495. * @param baseName defines the base name of the effect (The name of file without .fragment.fx or .vertex.fx)
  496. * @param attributesNamesOrOptions defines either a list of attribute names or an IEffectCreationOptions object
  497. * @param uniformsNamesOrEngine defines either a list of uniform names or the engine to use
  498. * @param samplers defines an array of string used to represent textures
  499. * @param defines defines the string containing the defines to use to compile the shaders
  500. * @param fallbacks defines the list of potential fallbacks to use if shader compilation fails
  501. * @param onCompiled defines a function to call when the effect creation is successful
  502. * @param onError defines a function to call when the effect creation has failed
  503. * @param indexParameters defines an object containing the index values to use to compile shaders (like the maximum number of simultaneous lights)
  504. * @param shaderLanguage the language the shader is written in (default: GLSL)
  505. * @returns the new Effect
  506. */
  507. createEffect(baseName: string | (IShaderPath & {
  508. vertexToken?: string;
  509. fragmentToken?: string;
  510. }), attributesNamesOrOptions: string[] | IEffectCreationOptions, uniformsNamesOrEngine: string[] | ThinEngine, samplers?: string[], defines?: string, fallbacks?: IEffectFallbacks, onCompiled?: Nullable<(effect: Effect) => void>, onError?: Nullable<(effect: Effect, errors: string) => void>, indexParameters?: any, shaderLanguage?: ShaderLanguage): Effect;
  511. protected static _ConcatenateShader(source: string, defines: Nullable<string>, shaderVersion?: string): string;
  512. private _compileShader;
  513. private _compileRawShader;
  514. /**
  515. * @internal
  516. */
  517. _getShaderSource(shader: WebGLShader): Nullable<string>;
  518. /**
  519. * Directly creates a webGL program
  520. * @param pipelineContext defines the pipeline context to attach to
  521. * @param vertexCode defines the vertex shader code to use
  522. * @param fragmentCode defines the fragment shader code to use
  523. * @param context defines the webGL context to use (if not set, the current one will be used)
  524. * @param transformFeedbackVaryings defines the list of transform feedback varyings to use
  525. * @returns the new webGL program
  526. */
  527. createRawShaderProgram(pipelineContext: IPipelineContext, vertexCode: string, fragmentCode: string, context?: WebGLRenderingContext, transformFeedbackVaryings?: Nullable<string[]>): WebGLProgram;
  528. /**
  529. * Creates a webGL program
  530. * @param pipelineContext defines the pipeline context to attach to
  531. * @param vertexCode defines the vertex shader code to use
  532. * @param fragmentCode defines the fragment shader code to use
  533. * @param defines defines the string containing the defines to use to compile the shaders
  534. * @param context defines the webGL context to use (if not set, the current one will be used)
  535. * @param transformFeedbackVaryings defines the list of transform feedback varyings to use
  536. * @returns the new webGL program
  537. */
  538. createShaderProgram(pipelineContext: IPipelineContext, vertexCode: string, fragmentCode: string, defines: Nullable<string>, context?: WebGLRenderingContext, transformFeedbackVaryings?: Nullable<string[]>): WebGLProgram;
  539. /**
  540. * Inline functions in shader code that are marked to be inlined
  541. * @param code code to inline
  542. * @returns inlined code
  543. */
  544. inlineShaderCode(code: string): string;
  545. /**
  546. * Creates a new pipeline context
  547. * @param shaderProcessingContext defines the shader processing context used during the processing if available
  548. * @returns the new pipeline
  549. */
  550. createPipelineContext(shaderProcessingContext: Nullable<ShaderProcessingContext>): IPipelineContext;
  551. /**
  552. * Creates a new material context
  553. * @returns the new context
  554. */
  555. createMaterialContext(): IMaterialContext | undefined;
  556. /**
  557. * Creates a new draw context
  558. * @returns the new context
  559. */
  560. createDrawContext(): IDrawContext | undefined;
  561. protected _createShaderProgram(pipelineContext: WebGLPipelineContext, vertexShader: WebGLShader, fragmentShader: WebGLShader, context: WebGLRenderingContext, transformFeedbackVaryings?: Nullable<string[]>): WebGLProgram;
  562. protected _finalizePipelineContext(pipelineContext: WebGLPipelineContext): void;
  563. /**
  564. * @internal
  565. */
  566. _preparePipelineContext(pipelineContext: IPipelineContext, vertexSourceCode: string, fragmentSourceCode: string, createAsRaw: boolean, rawVertexSourceCode: string, rawFragmentSourceCode: string, rebuildRebind: any, defines: Nullable<string>, transformFeedbackVaryings: Nullable<string[]>, key: string): void;
  567. /**
  568. * @internal
  569. */
  570. _isRenderingStateCompiled(pipelineContext: IPipelineContext): boolean;
  571. /**
  572. * @internal
  573. */
  574. _executeWhenRenderingStateIsCompiled(pipelineContext: IPipelineContext, action: () => void): void;
  575. /**
  576. * Gets the list of webGL uniform locations associated with a specific program based on a list of uniform names
  577. * @param pipelineContext defines the pipeline context to use
  578. * @param uniformsNames defines the list of uniform names
  579. * @returns an array of webGL uniform locations
  580. */
  581. getUniforms(pipelineContext: IPipelineContext, uniformsNames: string[]): Nullable<WebGLUniformLocation>[];
  582. /**
  583. * Gets the list of active attributes for a given webGL program
  584. * @param pipelineContext defines the pipeline context to use
  585. * @param attributesNames defines the list of attribute names to get
  586. * @returns an array of indices indicating the offset of each attribute
  587. */
  588. getAttributes(pipelineContext: IPipelineContext, attributesNames: string[]): number[];
  589. /**
  590. * Activates an effect, making it the current one (ie. the one used for rendering)
  591. * @param effect defines the effect to activate
  592. */
  593. enableEffect(effect: Nullable<Effect | DrawWrapper>): void;
  594. /**
  595. * Set the value of an uniform to a number (int)
  596. * @param uniform defines the webGL uniform location where to store the value
  597. * @param value defines the int number to store
  598. * @returns true if the value was set
  599. */
  600. setInt(uniform: Nullable<WebGLUniformLocation>, value: number): boolean;
  601. /**
  602. * Set the value of an uniform to a int2
  603. * @param uniform defines the webGL uniform location where to store the value
  604. * @param x defines the 1st component of the value
  605. * @param y defines the 2nd component of the value
  606. * @returns true if the value was set
  607. */
  608. setInt2(uniform: Nullable<WebGLUniformLocation>, x: number, y: number): boolean;
  609. /**
  610. * Set the value of an uniform to a int3
  611. * @param uniform defines the webGL uniform location where to store the value
  612. * @param x defines the 1st component of the value
  613. * @param y defines the 2nd component of the value
  614. * @param z defines the 3rd component of the value
  615. * @returns true if the value was set
  616. */
  617. setInt3(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number): boolean;
  618. /**
  619. * Set the value of an uniform to a int4
  620. * @param uniform defines the webGL uniform location where to store the value
  621. * @param x defines the 1st component of the value
  622. * @param y defines the 2nd component of the value
  623. * @param z defines the 3rd component of the value
  624. * @param w defines the 4th component of the value
  625. * @returns true if the value was set
  626. */
  627. setInt4(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number, w: number): boolean;
  628. /**
  629. * Set the value of an uniform to an array of int32
  630. * @param uniform defines the webGL uniform location where to store the value
  631. * @param array defines the array of int32 to store
  632. * @returns true if the value was set
  633. */
  634. setIntArray(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): boolean;
  635. /**
  636. * Set the value of an uniform to an array of int32 (stored as vec2)
  637. * @param uniform defines the webGL uniform location where to store the value
  638. * @param array defines the array of int32 to store
  639. * @returns true if the value was set
  640. */
  641. setIntArray2(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): boolean;
  642. /**
  643. * Set the value of an uniform to an array of int32 (stored as vec3)
  644. * @param uniform defines the webGL uniform location where to store the value
  645. * @param array defines the array of int32 to store
  646. * @returns true if the value was set
  647. */
  648. setIntArray3(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): boolean;
  649. /**
  650. * Set the value of an uniform to an array of int32 (stored as vec4)
  651. * @param uniform defines the webGL uniform location where to store the value
  652. * @param array defines the array of int32 to store
  653. * @returns true if the value was set
  654. */
  655. setIntArray4(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): boolean;
  656. /**
  657. * Set the value of an uniform to a number (unsigned int)
  658. * @param uniform defines the webGL uniform location where to store the value
  659. * @param value defines the unsigned int number to store
  660. * @returns true if the value was set
  661. */
  662. setUInt(uniform: Nullable<WebGLUniformLocation>, value: number): boolean;
  663. /**
  664. * Set the value of an uniform to a unsigned int2
  665. * @param uniform defines the webGL uniform location where to store the value
  666. * @param x defines the 1st component of the value
  667. * @param y defines the 2nd component of the value
  668. * @returns true if the value was set
  669. */
  670. setUInt2(uniform: Nullable<WebGLUniformLocation>, x: number, y: number): boolean;
  671. /**
  672. * Set the value of an uniform to a unsigned int3
  673. * @param uniform defines the webGL uniform location where to store the value
  674. * @param x defines the 1st component of the value
  675. * @param y defines the 2nd component of the value
  676. * @param z defines the 3rd component of the value
  677. * @returns true if the value was set
  678. */
  679. setUInt3(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number): boolean;
  680. /**
  681. * Set the value of an uniform to a unsigned int4
  682. * @param uniform defines the webGL uniform location where to store the value
  683. * @param x defines the 1st component of the value
  684. * @param y defines the 2nd component of the value
  685. * @param z defines the 3rd component of the value
  686. * @param w defines the 4th component of the value
  687. * @returns true if the value was set
  688. */
  689. setUInt4(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number, w: number): boolean;
  690. /**
  691. * Set the value of an uniform to an array of unsigned int32
  692. * @param uniform defines the webGL uniform location where to store the value
  693. * @param array defines the array of unsigned int32 to store
  694. * @returns true if the value was set
  695. */
  696. setUIntArray(uniform: Nullable<WebGLUniformLocation>, array: Uint32Array): boolean;
  697. /**
  698. * Set the value of an uniform to an array of unsigned int32 (stored as vec2)
  699. * @param uniform defines the webGL uniform location where to store the value
  700. * @param array defines the array of unsigned int32 to store
  701. * @returns true if the value was set
  702. */
  703. setUIntArray2(uniform: Nullable<WebGLUniformLocation>, array: Uint32Array): boolean;
  704. /**
  705. * Set the value of an uniform to an array of unsigned int32 (stored as vec3)
  706. * @param uniform defines the webGL uniform location where to store the value
  707. * @param array defines the array of unsigned int32 to store
  708. * @returns true if the value was set
  709. */
  710. setUIntArray3(uniform: Nullable<WebGLUniformLocation>, array: Uint32Array): boolean;
  711. /**
  712. * Set the value of an uniform to an array of unsigned int32 (stored as vec4)
  713. * @param uniform defines the webGL uniform location where to store the value
  714. * @param array defines the array of unsigned int32 to store
  715. * @returns true if the value was set
  716. */
  717. setUIntArray4(uniform: Nullable<WebGLUniformLocation>, array: Uint32Array): boolean;
  718. /**
  719. * Set the value of an uniform to an array of number
  720. * @param uniform defines the webGL uniform location where to store the value
  721. * @param array defines the array of number to store
  722. * @returns true if the value was set
  723. */
  724. setArray(uniform: Nullable<WebGLUniformLocation>, array: number[] | Float32Array): boolean;
  725. /**
  726. * Set the value of an uniform to an array of number (stored as vec2)
  727. * @param uniform defines the webGL uniform location where to store the value
  728. * @param array defines the array of number to store
  729. * @returns true if the value was set
  730. */
  731. setArray2(uniform: Nullable<WebGLUniformLocation>, array: number[] | Float32Array): boolean;
  732. /**
  733. * Set the value of an uniform to an array of number (stored as vec3)
  734. * @param uniform defines the webGL uniform location where to store the value
  735. * @param array defines the array of number to store
  736. * @returns true if the value was set
  737. */
  738. setArray3(uniform: Nullable<WebGLUniformLocation>, array: number[] | Float32Array): boolean;
  739. /**
  740. * Set the value of an uniform to an array of number (stored as vec4)
  741. * @param uniform defines the webGL uniform location where to store the value
  742. * @param array defines the array of number to store
  743. * @returns true if the value was set
  744. */
  745. setArray4(uniform: Nullable<WebGLUniformLocation>, array: number[] | Float32Array): boolean;
  746. /**
  747. * Set the value of an uniform to an array of float32 (stored as matrices)
  748. * @param uniform defines the webGL uniform location where to store the value
  749. * @param matrices defines the array of float32 to store
  750. * @returns true if the value was set
  751. */
  752. setMatrices(uniform: Nullable<WebGLUniformLocation>, matrices: DeepImmutable<FloatArray>): boolean;
  753. /**
  754. * Set the value of an uniform to a matrix (3x3)
  755. * @param uniform defines the webGL uniform location where to store the value
  756. * @param matrix defines the Float32Array representing the 3x3 matrix to store
  757. * @returns true if the value was set
  758. */
  759. setMatrix3x3(uniform: Nullable<WebGLUniformLocation>, matrix: Float32Array): boolean;
  760. /**
  761. * Set the value of an uniform to a matrix (2x2)
  762. * @param uniform defines the webGL uniform location where to store the value
  763. * @param matrix defines the Float32Array representing the 2x2 matrix to store
  764. * @returns true if the value was set
  765. */
  766. setMatrix2x2(uniform: Nullable<WebGLUniformLocation>, matrix: Float32Array): boolean;
  767. /**
  768. * Set the value of an uniform to a number (float)
  769. * @param uniform defines the webGL uniform location where to store the value
  770. * @param value defines the float number to store
  771. * @returns true if the value was transferred
  772. */
  773. setFloat(uniform: Nullable<WebGLUniformLocation>, value: number): boolean;
  774. /**
  775. * Set the value of an uniform to a vec2
  776. * @param uniform defines the webGL uniform location where to store the value
  777. * @param x defines the 1st component of the value
  778. * @param y defines the 2nd component of the value
  779. * @returns true if the value was set
  780. */
  781. setFloat2(uniform: Nullable<WebGLUniformLocation>, x: number, y: number): boolean;
  782. /**
  783. * Set the value of an uniform to a vec3
  784. * @param uniform defines the webGL uniform location where to store the value
  785. * @param x defines the 1st component of the value
  786. * @param y defines the 2nd component of the value
  787. * @param z defines the 3rd component of the value
  788. * @returns true if the value was set
  789. */
  790. setFloat3(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number): boolean;
  791. /**
  792. * Set the value of an uniform to a vec4
  793. * @param uniform defines the webGL uniform location where to store the value
  794. * @param x defines the 1st component of the value
  795. * @param y defines the 2nd component of the value
  796. * @param z defines the 3rd component of the value
  797. * @param w defines the 4th component of the value
  798. * @returns true if the value was set
  799. */
  800. setFloat4(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number, w: number): boolean;
  801. /**
  802. * Apply all cached states (depth, culling, stencil and alpha)
  803. */
  804. applyStates(): void;
  805. /**
  806. * Force the entire cache to be cleared
  807. * You should not have to use this function unless your engine needs to share the webGL context with another engine
  808. * @param bruteForce defines a boolean to force clearing ALL caches (including stencil, detoh and alpha states)
  809. */
  810. wipeCaches(bruteForce?: boolean): void;
  811. setTextureFromPostProcess(channel: number, postProcess: Nullable<PostProcess>, name: string): void;
  812. setTextureFromPostProcessOutput(channel: number, postProcess: Nullable<PostProcess>, name: string): void;
  813. setDepthStencilTexture(channel: number, uniform: Nullable<WebGLUniformLocation>, texture: Nullable<RenderTargetTexture>, name?: string): void;
  814. /**
  815. * @internal
  816. */
  817. _getSamplingParameters(samplingMode: number, generateMipMaps: boolean): {
  818. min: number;
  819. mag: number;
  820. };
  821. /** @internal */
  822. protected _createTexture(): WebGLTexture;
  823. /** @internal */
  824. _createHardwareTexture(): HardwareTextureWrapper;
  825. /**
  826. * Creates an internal texture without binding it to a framebuffer
  827. * @internal
  828. * @param size defines the size of the texture
  829. * @param options defines the options used to create the texture
  830. * @param delayGPUTextureCreation true to delay the texture creation the first time it is really needed. false to create it right away
  831. * @param source source type of the texture
  832. * @returns a new internal texture
  833. */
  834. _createInternalTexture(size: TextureSize, options: boolean | InternalTextureCreationOptions, delayGPUTextureCreation?: boolean, source?: InternalTextureSource): InternalTexture;
  835. /**
  836. * @internal
  837. */
  838. _getUseSRGBBuffer(useSRGBBuffer: boolean, noMipmap: boolean): boolean;
  839. /**
  840. * Usually called from Texture.ts.
  841. * Passed information to create a WebGLTexture
  842. * @param url defines a value which contains one of the following:
  843. * * A conventional http URL, e.g. 'http://...' or 'file://...'
  844. * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...'
  845. * * An indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg'
  846. * @param noMipmap defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file
  847. * @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)
  848. * @param scene needed for loading to the correct scene
  849. * @param samplingMode mode with should be used sample / access the texture (Default: Texture.TRILINEAR_SAMPLINGMODE)
  850. * @param onLoad optional callback to be called upon successful completion
  851. * @param onError optional callback to be called upon failure
  852. * @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
  853. * @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities
  854. * @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures
  855. * @param forcedExtension defines the extension to use to pick the right loader
  856. * @param mimeType defines an optional mime type
  857. * @param loaderOptions options to be passed to the loader
  858. * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg)
  859. * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).
  860. * @returns a InternalTexture for assignment back into BABYLON.Texture
  861. */
  862. 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;
  863. /**
  864. * Calls to the GL texImage2D and texImage3D functions require three arguments describing the pixel format of the texture.
  865. * createTexture derives these from the babylonFormat and useSRGBBuffer arguments and also the file extension of the URL it's working with.
  866. * This function encapsulates that derivation for easy unit testing.
  867. * @param babylonFormat Babylon's format enum, as specified in ITextureCreationOptions.
  868. * @param fileExtension The file extension including the dot, e.g. .jpg.
  869. * @param useSRGBBuffer Use SRGB not linear.
  870. * @returns The options to pass to texImage2D or texImage3D calls.
  871. * @internal
  872. */
  873. _getTexImageParametersForCreateTexture(babylonFormat: Nullable<number>, fileExtension: string, useSRGBBuffer: boolean): TexImageParameters;
  874. /**
  875. * @internal
  876. */
  877. _rescaleTexture(source: InternalTexture, destination: InternalTexture, scene: Nullable<any>, internalFormat: number, onComplete: () => void): void;
  878. private _unpackFlipYCached;
  879. /**
  880. * In case you are sharing the context with other applications, it might
  881. * be interested to not cache the unpack flip y state to ensure a consistent
  882. * value would be set.
  883. */
  884. enableUnpackFlipYCached: boolean;
  885. /**
  886. * @internal
  887. */
  888. _unpackFlipY(value: boolean): void;
  889. /** @internal */
  890. _getUnpackAlignement(): number;
  891. private _getTextureTarget;
  892. /**
  893. * Update the sampling mode of a given texture
  894. * @param samplingMode defines the required sampling mode
  895. * @param texture defines the texture to update
  896. * @param generateMipMaps defines whether to generate mipmaps for the texture
  897. */
  898. updateTextureSamplingMode(samplingMode: number, texture: InternalTexture, generateMipMaps?: boolean): void;
  899. /**
  900. * Update the dimensions of a texture
  901. * @param texture texture to update
  902. * @param width new width of the texture
  903. * @param height new height of the texture
  904. * @param depth new depth of the texture
  905. */
  906. updateTextureDimensions(texture: InternalTexture, width: number, height: number, depth?: number): void;
  907. /**
  908. * Update the sampling mode of a given texture
  909. * @param texture defines the texture to update
  910. * @param wrapU defines the texture wrap mode of the u coordinates
  911. * @param wrapV defines the texture wrap mode of the v coordinates
  912. * @param wrapR defines the texture wrap mode of the r coordinates
  913. */
  914. updateTextureWrappingMode(texture: InternalTexture, wrapU: Nullable<number>, wrapV?: Nullable<number>, wrapR?: Nullable<number>): void;
  915. /**
  916. * @internal
  917. */
  918. _setupDepthStencilTexture(internalTexture: InternalTexture, size: TextureSize, generateStencil: boolean, bilinearFiltering: boolean, comparisonFunction: number, samples?: number): void;
  919. /**
  920. * @internal
  921. */
  922. _uploadCompressedDataToTextureDirectly(texture: InternalTexture, internalFormat: number, width: number, height: number, data: ArrayBufferView, faceIndex?: number, lod?: number): void;
  923. /**
  924. * @internal
  925. */
  926. _uploadDataToTextureDirectly(texture: InternalTexture, imageData: ArrayBufferView, faceIndex?: number, lod?: number, babylonInternalFormat?: number, useTextureWidthAndHeight?: boolean): void;
  927. /**
  928. * Update a portion of an internal texture
  929. * @param texture defines the texture to update
  930. * @param imageData defines the data to store into the texture
  931. * @param xOffset defines the x coordinates of the update rectangle
  932. * @param yOffset defines the y coordinates of the update rectangle
  933. * @param width defines the width of the update rectangle
  934. * @param height defines the height of the update rectangle
  935. * @param faceIndex defines the face index if texture is a cube (0 by default)
  936. * @param lod defines the lod level to update (0 by default)
  937. * @param generateMipMaps defines whether to generate mipmaps or not
  938. */
  939. updateTextureData(texture: InternalTexture, imageData: ArrayBufferView, xOffset: number, yOffset: number, width: number, height: number, faceIndex?: number, lod?: number, generateMipMaps?: boolean): void;
  940. /**
  941. * @internal
  942. */
  943. _uploadArrayBufferViewToTexture(texture: InternalTexture, imageData: ArrayBufferView, faceIndex?: number, lod?: number): void;
  944. protected _prepareWebGLTextureContinuation(texture: InternalTexture, scene: Nullable<ISceneLike>, noMipmap: boolean, isCompressed: boolean, samplingMode: number): void;
  945. private _prepareWebGLTexture;
  946. /**
  947. * @internal
  948. */
  949. _setupFramebufferDepthAttachments(generateStencilBuffer: boolean, generateDepthBuffer: boolean, width: number, height: number, samples?: number): Nullable<WebGLRenderbuffer>;
  950. /**
  951. * @internal
  952. */
  953. _createRenderBuffer(width: number, height: number, samples: number, internalFormat: number, msInternalFormat: number, attachment: number, unbindBuffer?: boolean): Nullable<WebGLRenderbuffer>;
  954. _updateRenderBuffer(renderBuffer: Nullable<WebGLRenderbuffer>, width: number, height: number, samples: number, internalFormat: number, msInternalFormat: number, attachment: number, unbindBuffer?: boolean): Nullable<WebGLRenderbuffer>;
  955. /**
  956. * @internal
  957. */
  958. _releaseTexture(texture: InternalTexture): void;
  959. protected _deleteTexture(texture: Nullable<WebGLTexture>): void;
  960. protected _setProgram(program: WebGLProgram): void;
  961. protected _boundUniforms: {
  962. [key: number]: WebGLUniformLocation;
  963. };
  964. /**
  965. * Binds an effect to the webGL context
  966. * @param effect defines the effect to bind
  967. */
  968. bindSamplers(effect: Effect): void;
  969. private _activateCurrentTexture;
  970. /**
  971. * @internal
  972. */
  973. _bindTextureDirectly(target: number, texture: Nullable<InternalTexture>, forTextureDataUpdate?: boolean, force?: boolean): boolean;
  974. /**
  975. * @internal
  976. */
  977. _bindTexture(channel: number, texture: Nullable<InternalTexture>, name: string): void;
  978. /**
  979. * Unbind all textures from the webGL context
  980. */
  981. unbindAllTextures(): void;
  982. /**
  983. * Sets a texture to the according uniform.
  984. * @param channel The texture channel
  985. * @param uniform The uniform to set
  986. * @param texture The texture to apply
  987. * @param name The name of the uniform in the effect
  988. */
  989. setTexture(channel: number, uniform: Nullable<WebGLUniformLocation>, texture: Nullable<ThinTexture>, name: string): void;
  990. private _bindSamplerUniformToChannel;
  991. private _getTextureWrapMode;
  992. protected _setTexture(channel: number, texture: Nullable<ThinTexture>, isPartOfTextureArray?: boolean, depthStencilTexture?: boolean, name?: string): boolean;
  993. /**
  994. * Sets an array of texture to the webGL context
  995. * @param channel defines the channel where the texture array must be set
  996. * @param uniform defines the associated uniform location
  997. * @param textures defines the array of textures to bind
  998. * @param name name of the channel
  999. */
  1000. setTextureArray(channel: number, uniform: Nullable<WebGLUniformLocation>, textures: ThinTexture[], name: string): void;
  1001. /**
  1002. * @internal
  1003. */
  1004. _setAnisotropicLevel(target: number, internalTexture: InternalTexture, anisotropicFilteringLevel: number): void;
  1005. private _setTextureParameterFloat;
  1006. private _setTextureParameterInteger;
  1007. /**
  1008. * Unbind all vertex attributes from the webGL context
  1009. */
  1010. unbindAllAttributes(): void;
  1011. /**
  1012. * Force the engine to release all cached effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled
  1013. */
  1014. releaseEffects(): void;
  1015. /**
  1016. * Dispose and release all associated resources
  1017. */
  1018. dispose(): void;
  1019. /**
  1020. * Attach a new callback raised when context lost event is fired
  1021. * @param callback defines the callback to call
  1022. */
  1023. attachContextLostEvent(callback: (event: WebGLContextEvent) => void): void;
  1024. /**
  1025. * Attach a new callback raised when context restored event is fired
  1026. * @param callback defines the callback to call
  1027. */
  1028. attachContextRestoredEvent(callback: (event: WebGLContextEvent) => void): void;
  1029. /**
  1030. * Get the current error code of the webGL context
  1031. * @returns the error code
  1032. * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getError
  1033. */
  1034. getError(): number;
  1035. private _canRenderToFloatFramebuffer;
  1036. private _canRenderToHalfFloatFramebuffer;
  1037. private _canRenderToFramebuffer;
  1038. /**
  1039. * @internal
  1040. */
  1041. _getWebGLTextureType(type: number): number;
  1042. /**
  1043. * @internal
  1044. */
  1045. _getInternalFormat(format: number, useSRGBBuffer?: boolean): number;
  1046. /**
  1047. * @internal
  1048. */
  1049. _getRGBABufferInternalSizedFormat(type: number, format?: number, useSRGBBuffer?: boolean): number;
  1050. /**
  1051. * Reads pixels from the current frame buffer. Please note that this function can be slow
  1052. * @param x defines the x coordinate of the rectangle where pixels must be read
  1053. * @param y defines the y coordinate of the rectangle where pixels must be read
  1054. * @param width defines the width of the rectangle where pixels must be read
  1055. * @param height defines the height of the rectangle where pixels must be read
  1056. * @param hasAlpha defines whether the output should have alpha or not (defaults to true)
  1057. * @param flushRenderer true to flush the renderer from the pending commands before reading the pixels
  1058. * @returns a ArrayBufferView promise (Uint8Array) containing RGBA colors
  1059. */
  1060. readPixels(x: number, y: number, width: number, height: number, hasAlpha?: boolean, flushRenderer?: boolean): Promise<ArrayBufferView>;
  1061. /**
  1062. * Force the mipmap generation for the given render target texture
  1063. * @param texture defines the render target texture to use
  1064. * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.
  1065. */
  1066. generateMipMapsForCubemap(texture: InternalTexture, unbind: boolean): void;
  1067. private static _IsSupported;
  1068. private static _HasMajorPerformanceCaveat;
  1069. /**
  1070. * Gets a Promise<boolean> indicating if the engine can be instantiated (ie. if a webGL context can be found)
  1071. */
  1072. static get IsSupportedAsync(): Promise<boolean>;
  1073. /**
  1074. * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)
  1075. */
  1076. static get IsSupported(): boolean;
  1077. /**
  1078. * Gets a boolean indicating if the engine can be instantiated (ie. if a webGL context can be found)
  1079. * @returns true if the engine can be created
  1080. * @ignorenaming
  1081. */
  1082. static isSupported(): boolean;
  1083. /**
  1084. * Gets a boolean indicating if the engine can be instantiated on a performant device (ie. if a webGL context can be found and it does not use a slow implementation)
  1085. */
  1086. static get HasMajorPerformanceCaveat(): boolean;
  1087. /**
  1088. * Find the next highest power of two.
  1089. * @param x Number to start search from.
  1090. * @returns Next highest power of two.
  1091. */
  1092. static CeilingPOT: (x: number) => number;
  1093. /**
  1094. * Find the next lowest power of two.
  1095. * @param x Number to start search from.
  1096. * @returns Next lowest power of two.
  1097. */
  1098. static FloorPOT: (x: number) => number;
  1099. /**
  1100. * Find the nearest power of two.
  1101. * @param x Number to start search from.
  1102. * @returns Next nearest power of two.
  1103. */
  1104. static NearestPOT: (x: number) => number;
  1105. /**
  1106. * Get the closest exponent of two
  1107. * @param value defines the value to approximate
  1108. * @param max defines the maximum value to return
  1109. * @param mode defines how to define the closest value
  1110. * @returns closest exponent of two of the given value
  1111. */
  1112. static GetExponentOfTwo: (value: number, max: number, mode: number) => number;
  1113. /**
  1114. * 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)
  1115. * @param func - the function to be called
  1116. * @param requester - the object that will request the next frame. Falls back to window.
  1117. * @returns frame number
  1118. */
  1119. static QueueNewFrame: (func: () => void, requester?: any) => number;
  1120. }
  1121. interface TexImageParameters {
  1122. internalFormat: number;
  1123. format: number;
  1124. type: number;
  1125. }
  1126. export {};