import type { Nullable, IndicesArray, DataArray, FloatArray, DeepImmutable } from "../types"; import { Engine } from "../Engines/engine"; import type { VertexBuffer } from "../Buffers/buffer"; import { InternalTexture, InternalTextureSource } from "../Materials/Textures/internalTexture"; import type { BaseTexture } from "../Materials/Textures/baseTexture"; import type { Effect } from "../Materials/effect"; import { DataBuffer } from "../Buffers/dataBuffer"; import type { Scene } from "../scene"; import type { RenderTargetCreationOptions, TextureSize, DepthTextureCreationOptions, InternalTextureCreationOptions } from "../Materials/Textures/textureCreationOptions"; import type { IPipelineContext } from "./IPipelineContext"; import type { IColor3Like, IColor4Like, IViewportLike } from "../Maths/math.like"; import type { ISceneLike } from "./abstractEngine"; import type { IMaterialContext } from "./IMaterialContext"; import type { IDrawContext } from "./IDrawContext"; import type { ICanvas, IImage } from "./ICanvas"; import type { IStencilState } from "../States/IStencilState"; import type { RenderTargetWrapper } from "./renderTargetWrapper"; import type { NativeData } from "./Native/nativeDataStream"; import { NativeDataStream } from "./Native/nativeDataStream"; import type { INative, NativeFramebuffer, NativeTexture } from "./Native/nativeInterfaces"; import type { HardwareTextureWrapper } from "../Materials/Textures/hardwareTextureWrapper"; /** * Returns _native only after it has been defined by BabylonNative. * @internal */ export declare function AcquireNativeObjectAsync(): Promise; /** * Registers a constructor on the _native object. See NativeXRFrame for an example. * @internal */ export declare function RegisterNativeTypeAsync(typeName: string, constructor: Type): Promise; /** * Container for accessors for natively-stored mesh data buffers. */ declare class NativeDataBuffer extends DataBuffer { /** * Accessor value used to identify/retrieve a natively-stored index buffer. */ nativeIndexBuffer?: NativeData; /** * Accessor value used to identify/retrieve a natively-stored vertex buffer. */ nativeVertexBuffer?: NativeData; } /** * Options to create the Native engine */ export interface NativeEngineOptions { /** * defines whether to adapt to the device's viewport characteristics (default: false) */ adaptToDeviceRatio?: boolean; } /** @internal */ export declare class NativeEngine extends Engine { private static readonly PROTOCOL_VERSION; private readonly _engine; private readonly _camera; private readonly _commandBufferEncoder; private _boundBuffersVertexArray; private _currentDepthTest; private _stencilTest; private _stencilMask; private _stencilFunc; private _stencilFuncRef; private _stencilFuncMask; private _stencilOpStencilFail; private _stencilOpDepthFail; private _stencilOpStencilDepthPass; private _zOffset; private _zOffsetUnits; private _depthWrite; setHardwareScalingLevel(level: number): void; constructor(options?: NativeEngineOptions); dispose(): void; /** @internal */ static _createNativeDataStream(): NativeDataStream; /** * Can be used to override the current requestAnimationFrame requester. * @internal */ protected _queueNewFrame(bindedRenderFunction: any, requester?: any): number; protected _restoreEngineAfterContextLost(): void; /** * Override default engine behavior. * @param framebuffer */ _bindUnboundFramebuffer(framebuffer: Nullable): void; /** * Gets host document * @returns the host document object */ getHostDocument(): Nullable; clear(color: Nullable, backBuffer: boolean, depth: boolean, stencil?: boolean): void; createIndexBuffer(indices: IndicesArray, updateable?: boolean, _label?: string): NativeDataBuffer; createVertexBuffer(vertices: DataArray, updateable?: boolean, _label?: string): NativeDataBuffer; protected _recordVertexArrayObject(vertexArray: any, vertexBuffers: { [key: string]: VertexBuffer; }, indexBuffer: Nullable, effect: Effect, overrideVertexBuffers?: { [kind: string]: Nullable; }): void; bindBuffers(vertexBuffers: { [key: string]: VertexBuffer; }, indexBuffer: Nullable, effect: Effect): void; recordVertexArrayObject(vertexBuffers: { [key: string]: VertexBuffer; }, indexBuffer: Nullable, effect: Effect, overrideVertexBuffers?: { [kind: string]: Nullable; }): WebGLVertexArrayObject; private _deleteVertexArray; bindVertexArrayObject(vertexArray: WebGLVertexArrayObject): void; releaseVertexArrayObject(vertexArray: WebGLVertexArrayObject): void; getAttributes(pipelineContext: IPipelineContext, attributesNames: string[]): number[]; /** * Draw a list of indexed primitives * @param fillMode defines the primitive to use * @param indexStart defines the starting index * @param indexCount defines the number of index to draw * @param instancesCount defines the number of instances to draw (if instantiation is enabled) */ drawElementsType(fillMode: number, indexStart: number, indexCount: number, instancesCount?: number): void; /** * Draw a list of unindexed primitives * @param fillMode defines the primitive to use * @param verticesStart defines the index of first vertex to draw * @param verticesCount defines the count of vertices to draw * @param instancesCount defines the number of instances to draw (if instantiation is enabled) */ drawArraysType(fillMode: number, verticesStart: number, verticesCount: number, instancesCount?: number): void; createPipelineContext(): IPipelineContext; createMaterialContext(): IMaterialContext | undefined; createDrawContext(): IDrawContext | undefined; /** * @internal */ _preparePipelineContext(pipelineContext: IPipelineContext, vertexSourceCode: string, fragmentSourceCode: string, createAsRaw: boolean, _rawVertexSourceCode: string, _rawFragmentSourceCode: string, _rebuildRebind: any, defines: Nullable): void; /** * @internal */ _executeWhenRenderingStateIsCompiled(pipelineContext: IPipelineContext, action: () => void): void; createRawShaderProgram(): WebGLProgram; createShaderProgram(pipelineContext: IPipelineContext, vertexCode: string, fragmentCode: string, defines: Nullable): WebGLProgram; /** * Inline functions in shader code that are marked to be inlined * @param code code to inline * @returns inlined code */ inlineShaderCode(code: string): string; protected _setProgram(program: WebGLProgram): void; _deletePipelineContext(pipelineContext: IPipelineContext): void; getUniforms(pipelineContext: IPipelineContext, uniformsNames: string[]): WebGLUniformLocation[]; bindUniformBlock(pipelineContext: IPipelineContext, blockName: string, index: number): void; bindSamplers(effect: Effect): void; getRenderWidth(useScreen?: boolean): number; getRenderHeight(useScreen?: boolean): number; setViewport(viewport: IViewportLike, requiredWidth?: number, requiredHeight?: number): void; enableScissor(x: number, y: number, width: number, height: number): void; disableScissor(): void; setState(culling: boolean, zOffset?: number, force?: boolean, reverseSide?: boolean, cullBackFaces?: boolean, stencil?: IStencilState, zOffsetUnits?: number): void; /** * Gets the client rect of native canvas. Needed for InputManager. * @returns a client rectangle */ getInputElementClientRect(): Nullable; /** * Set the z offset Factor to apply to current rendering * @param value defines the offset to apply */ setZOffset(value: number): void; /** * Gets the current value of the zOffset Factor * @returns the current zOffset Factor state */ getZOffset(): number; /** * Set the z offset Units to apply to current rendering * @param value defines the offset to apply */ setZOffsetUnits(value: number): void; /** * Gets the current value of the zOffset Units * @returns the current zOffset Units state */ getZOffsetUnits(): number; /** * Enable or disable depth buffering * @param enable defines the state to set */ setDepthBuffer(enable: boolean): void; /** * Gets a boolean indicating if depth writing is enabled * @returns the current depth writing state */ getDepthWrite(): boolean; getDepthFunction(): Nullable; setDepthFunction(depthFunc: number): void; /** * Enable or disable depth writing * @param enable defines the state to set */ setDepthWrite(enable: boolean): void; /** * Enable or disable color writing * @param enable defines the state to set */ setColorWrite(enable: boolean): void; /** * Gets a boolean indicating if color writing is enabled * @returns the current color writing state */ getColorWrite(): boolean; private applyStencil; private _setStencil; /** * Enable or disable the stencil buffer * @param enable defines if the stencil buffer must be enabled or disabled */ setStencilBuffer(enable: boolean): void; /** * Gets a boolean indicating if stencil buffer is enabled * @returns the current stencil buffer state */ getStencilBuffer(): boolean; /** * Gets the current stencil operation when stencil passes * @returns a number defining stencil operation to use when stencil passes */ getStencilOperationPass(): number; /** * Sets the stencil operation to use when stencil passes * @param operation defines the stencil operation to use when stencil passes */ setStencilOperationPass(operation: number): void; /** * Sets the current stencil mask * @param mask defines the new stencil mask to use */ setStencilMask(mask: number): void; /** * Sets the current stencil function * @param stencilFunc defines the new stencil function to use */ setStencilFunction(stencilFunc: number): void; /** * Sets the current stencil reference * @param reference defines the new stencil reference to use */ setStencilFunctionReference(reference: number): void; /** * Sets the current stencil mask * @param mask defines the new stencil mask to use */ setStencilFunctionMask(mask: number): void; /** * Sets the stencil operation to use when stencil fails * @param operation defines the stencil operation to use when stencil fails */ setStencilOperationFail(operation: number): void; /** * Sets the stencil operation to use when depth fails * @param operation defines the stencil operation to use when depth fails */ setStencilOperationDepthFail(operation: number): void; /** * Gets the current stencil mask * @returns a number defining the new stencil mask to use */ getStencilMask(): number; /** * Gets the current stencil function * @returns a number defining the stencil function to use */ getStencilFunction(): number; /** * Gets the current stencil reference value * @returns a number defining the stencil reference value to use */ getStencilFunctionReference(): number; /** * Gets the current stencil mask * @returns a number defining the stencil mask to use */ getStencilFunctionMask(): number; /** * Gets the current stencil operation when stencil fails * @returns a number defining stencil operation to use when stencil fails */ getStencilOperationFail(): number; /** * Gets the current stencil operation when depth fails * @returns a number defining stencil operation to use when depth fails */ getStencilOperationDepthFail(): number; /** * Sets alpha constants used by some alpha blending modes * @param r defines the red component * @param g defines the green component * @param b defines the blue component * @param a defines the alpha component */ setAlphaConstants(r: number, g: number, b: number, a: number): void; /** * Sets the current alpha mode * @param mode defines the mode to use (one of the BABYLON.Constants.ALPHA_XXX) * @param noDepthWriteChange defines if depth writing state should remains unchanged (false by default) * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/transparent_rendering */ setAlphaMode(mode: number, noDepthWriteChange?: boolean): void; /** * Gets the current alpha mode * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/advanced/transparent_rendering * @returns the current alpha mode */ getAlphaMode(): number; setInt(uniform: WebGLUniformLocation, int: number): boolean; setIntArray(uniform: WebGLUniformLocation, array: Int32Array): boolean; setIntArray2(uniform: WebGLUniformLocation, array: Int32Array): boolean; setIntArray3(uniform: WebGLUniformLocation, array: Int32Array): boolean; setIntArray4(uniform: WebGLUniformLocation, array: Int32Array): boolean; setFloatArray(uniform: WebGLUniformLocation, array: Float32Array): boolean; setFloatArray2(uniform: WebGLUniformLocation, array: Float32Array): boolean; setFloatArray3(uniform: WebGLUniformLocation, array: Float32Array): boolean; setFloatArray4(uniform: WebGLUniformLocation, array: Float32Array): boolean; setArray(uniform: WebGLUniformLocation, array: number[]): boolean; setArray2(uniform: WebGLUniformLocation, array: number[]): boolean; setArray3(uniform: WebGLUniformLocation, array: number[]): boolean; setArray4(uniform: WebGLUniformLocation, array: number[]): boolean; setMatrices(uniform: WebGLUniformLocation, matrices: DeepImmutable): boolean; setMatrix3x3(uniform: WebGLUniformLocation, matrix: Float32Array): boolean; setMatrix2x2(uniform: WebGLUniformLocation, matrix: Float32Array): boolean; setFloat(uniform: WebGLUniformLocation, value: number): boolean; setFloat2(uniform: WebGLUniformLocation, x: number, y: number): boolean; setFloat3(uniform: WebGLUniformLocation, x: number, y: number, z: number): boolean; setFloat4(uniform: WebGLUniformLocation, x: number, y: number, z: number, w: number): boolean; setColor3(uniform: WebGLUniformLocation, color3: IColor3Like): boolean; setColor4(uniform: WebGLUniformLocation, color3: IColor3Like, alpha: number): boolean; wipeCaches(bruteForce?: boolean): void; protected _createTexture(): WebGLTexture; protected _deleteTexture(texture: Nullable): void; /** * Update the content of a dynamic texture * @param texture defines the texture to update * @param canvas defines the canvas containing the source * @param invertY defines if data must be stored with Y axis inverted * @param premulAlpha defines if alpha is stored as premultiplied * @param format defines the format of the data */ updateDynamicTexture(texture: Nullable, canvas: any, invertY: boolean, premulAlpha?: boolean, format?: number): void; createDynamicTexture(width: number, height: number, generateMipMaps: boolean, samplingMode: number): InternalTexture; createVideoElement(constraints: MediaTrackConstraints): any; updateVideoTexture(texture: Nullable, video: HTMLVideoElement, invertY: boolean): void; createRawTexture(data: Nullable, width: number, height: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression?: Nullable, type?: number, creationFlags?: number, useSRGBBuffer?: boolean): InternalTexture; createRawTexture2DArray(data: Nullable, width: number, height: number, depth: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression?: Nullable, textureType?: number): InternalTexture; updateRawTexture(texture: Nullable, bufferView: Nullable, format: number, invertY: boolean, compression?: Nullable, type?: number, useSRGBBuffer?: boolean): void; /** * Usually called from Texture.ts. * Passed information to create a NativeTexture * @param url defines a value which contains one of the following: * * A conventional http URL, e.g. 'http://...' or 'file://...' * * A base64 string of in-line texture data, e.g. 'data:image/jpg;base64,/...' * * An indicator that data being passed using the buffer parameter, e.g. 'data:mytexture.jpg' * @param noMipmap defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file * @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) * @param scene needed for loading to the correct scene * @param samplingMode mode with should be used sample / access the texture (Default: Texture.TRILINEAR_SAMPLINGMODE) * @param onLoad optional callback to be called upon successful completion * @param onError optional callback to be called upon failure * @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 * @param fallback an internal argument in case the function must be called again, due to etc1 not having alpha capabilities * @param format internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures * @param forcedExtension defines the extension to use to pick the right loader * @param mimeType defines an optional mime type * @param loaderOptions options to be passed to the loader * @param creationFlags specific flags to use when creating the texture (Constants.TEXTURE_CREATIONFLAG_STORAGE for storage textures, for eg) * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU). * @returns a InternalTexture for assignment back into BABYLON.Texture */ createTexture(url: Nullable, noMipmap: boolean, invertY: boolean, scene: Nullable, samplingMode?: number, onLoad?: Nullable<(texture: InternalTexture) => void>, onError?: Nullable<(message: string, exception: any) => void>, buffer?: Nullable, fallback?: Nullable, format?: Nullable, forcedExtension?: Nullable, mimeType?: string, loaderOptions?: any, creationFlags?: number, useSRGBBuffer?: boolean): InternalTexture; /** * Wraps an external native texture in a Babylon texture. * @param texture defines the external texture * @param hasMipMaps defines whether the external texture has mip maps * @param samplingMode defines the sampling mode for the external texture (default: Constants.TEXTURE_TRILINEAR_SAMPLINGMODE) * @returns the babylon internal texture */ wrapNativeTexture(texture: NativeTexture, hasMipMaps?: boolean, samplingMode?: number): InternalTexture; /** * Wraps an external web gl texture in a Babylon texture. * @returns the babylon internal texture */ wrapWebGLTexture(): InternalTexture; _createDepthStencilTexture(size: TextureSize, options: DepthTextureCreationOptions, rtWrapper: RenderTargetWrapper): InternalTexture; /** * @internal */ _releaseFramebufferObjects(framebuffer: Nullable): void; /** * @internal Engine abstraction for loading and creating an image bitmap from a given source string. * @param imageSource source to load the image from. * @param options An object that sets options for the image's extraction. * @returns ImageBitmap */ _createImageBitmapFromSource(imageSource: string, options?: ImageBitmapOptions): Promise; /** * Engine abstraction for createImageBitmap * @param image source for image * @param options An object that sets options for the image's extraction. * @returns ImageBitmap */ createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise; /** * Resize an image and returns the image data as an uint8array * @param image image to resize * @param bufferWidth destination buffer width * @param bufferHeight destination buffer height * @returns an uint8array containing RGBA values of bufferWidth * bufferHeight size */ resizeImageBitmap(image: ImageBitmap, bufferWidth: number, bufferHeight: number): Uint8Array; /** * Creates a cube texture * @param rootUrl defines the url where the files to load is located * @param scene defines the current scene * @param files defines the list of files to load (1 per face) * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default) * @param onLoad defines an optional callback raised when the texture is loaded * @param onError defines an optional callback raised if there is an issue to load the texture * @param format defines the format of the data * @param forcedExtension defines the extension to use to pick the right loader * @param createPolynomials if a polynomial sphere should be created for the cube texture * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness * @param fallback defines texture to use while falling back when (compressed) texture file not found. * @param loaderOptions options to be passed to the loader * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU). * @returns the cube texture as an InternalTexture */ createCubeTexture(rootUrl: string, scene: Nullable, files: Nullable, noMipmap?: boolean, onLoad?: Nullable<(data?: any) => void>, onError?: Nullable<(message?: string, exception?: any) => void>, format?: number, forcedExtension?: any, createPolynomials?: boolean, lodScale?: number, lodOffset?: number, fallback?: Nullable, loaderOptions?: any, useSRGBBuffer?: boolean): InternalTexture; /** @internal */ _createHardwareTexture(): HardwareTextureWrapper; /** @internal */ _createHardwareRenderTargetWrapper(isMulti: boolean, isCube: boolean, size: TextureSize): RenderTargetWrapper; /** @internal */ _createInternalTexture(size: TextureSize, options: boolean | InternalTextureCreationOptions, _delayGPUTextureCreation?: boolean, source?: InternalTextureSource): InternalTexture; createRenderTargetTexture(size: number | { width: number; height: number; depth: number; }, options: boolean | RenderTargetCreationOptions): RenderTargetWrapper; updateRenderTargetTextureSampleCount(rtWrapper: RenderTargetWrapper, samples: number): number; updateTextureSamplingMode(samplingMode: number, texture: InternalTexture): void; bindFramebuffer(texture: RenderTargetWrapper, faceIndex?: number, requiredWidth?: number, requiredHeight?: number, forceFullscreenViewport?: boolean): void; unBindFramebuffer(texture: RenderTargetWrapper, disableGenerateMipMaps?: boolean, onBeforeUnbind?: () => void): void; createDynamicVertexBuffer(data: DataArray): DataBuffer; updateDynamicIndexBuffer(indexBuffer: DataBuffer, indices: IndicesArray, offset?: number): void; updateDynamicVertexBuffer(vertexBuffer: DataBuffer, data: DataArray, byteOffset?: number, byteLength?: number): void; protected _setTexture(channel: number, texture: Nullable, isPartOfTextureArray?: boolean, depthStencilTexture?: boolean): boolean; private _setTextureSampling; private _setTextureWrapMode; private _setTextureCore; private _updateAnisotropicLevel; /** * @internal */ _bindTexture(channel: number, texture: InternalTexture): void; protected _deleteBuffer(buffer: NativeDataBuffer): void; /** * Create a canvas * @param width width * @param height height * @returns ICanvas interface */ createCanvas(width: number, height: number): ICanvas; /** * Create an image to use with canvas * @returns IImage interface */ createCanvasImage(): IImage; /** * Update a portion of an internal texture * @param texture defines the texture to update * @param imageData defines the data to store into the texture * @param xOffset defines the x coordinates of the update rectangle * @param yOffset defines the y coordinates of the update rectangle * @param width defines the width of the update rectangle * @param height defines the height of the update rectangle * @param faceIndex defines the face index if texture is a cube (0 by default) * @param lod defines the lod level to update (0 by default) * @param generateMipMaps defines whether to generate mipmaps or not */ updateTextureData(texture: InternalTexture, imageData: ArrayBufferView, xOffset: number, yOffset: number, width: number, height: number, faceIndex?: number, lod?: number, generateMipMaps?: boolean): void; /** * @internal */ _uploadCompressedDataToTextureDirectly(texture: InternalTexture, internalFormat: number, width: number, height: number, data: ArrayBufferView, faceIndex?: number, lod?: number): void; /** * @internal */ _uploadDataToTextureDirectly(texture: InternalTexture, imageData: ArrayBufferView, faceIndex?: number, lod?: number): void; /** * @internal */ _uploadArrayBufferViewToTexture(texture: InternalTexture, imageData: ArrayBufferView, faceIndex?: number, lod?: number): void; /** * @internal */ _uploadImageToTexture(texture: InternalTexture, image: HTMLImageElement, faceIndex?: number, lod?: number): void; getFontOffset(font: string): { ascent: number; height: number; descent: number; }; /** * No equivalent for native. Do nothing. */ flushFramebuffer(): void; _readTexturePixels(texture: InternalTexture, width: number, height: number, faceIndex?: number, level?: number, buffer?: Nullable, _flushRenderer?: boolean, _noDataConversion?: boolean, x?: number, y?: number): Promise; } export {};