Engine

The engine class is responsible for interfacing with all lower-level APIs such as WebGL and Audio

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Engine(canvasOrContext: Nullable<HTMLCanvasElement | WebGLRenderingContext>, antialias?: boolean, options?: EngineOptions, adaptToDeviceRatio?: boolean): Engine
  • Creates a new engine

    Parameters

    • canvasOrContext: Nullable<HTMLCanvasElement | WebGLRenderingContext>

      defines the canvas or WebGL context to use for rendering

    • Optional antialias: boolean

      defines enable antialiasing (default: false)

    • Optional options: EngineOptions

      defines further options to be sent to the getContext() function

    • Optional adaptToDeviceRatio: boolean

      defines whether to adapt to the device's viewport characteristics (default: false)

    Returns Engine

Properties

cullBackFaces

cullBackFaces: boolean

Gets or sets a boolean indicating if back faces must be culled (true by default)

currentViewport

currentViewport: Nullable<Viewport>

Gets the current viewport

disableManifestCheck

disableManifestCheck: boolean

Gets or sets a boolean to enable/disable checking manifest if IndexedDB support is enabled (Babylon.js will always consider the database is up to date)

disablePerformanceMonitorInBackground

disablePerformanceMonitorInBackground: boolean

Turn this value on if you want to pause FPS computation when in background

disableTextureBindingOptimization

disableTextureBindingOptimization: boolean

Gets or sets a value indicating if we want to disable texture binding optmization. This could be required on some buggy drivers which wants to have textures bound in a progressive order. By default Babylon.js will try to let textures bound where they are and only update the samplers to point where the texture is

disableUniformBuffers

disableUniformBuffers: boolean

Gets or sets a boolean indicating that uniform buffers must be disabled even if they are supported

doNotHandleContextLost

doNotHandleContextLost: boolean

Gets or sets a boolean indicating if resources should be retained to be able to handle context lost events

see

http://doc.babylonjs.com/how_to/optimizing_your_scene#handling-webgl-context-lost

emptyCubeTexture

emptyCubeTexture: InternalTexture

Gets the default empty cube texture

emptyTexture

emptyTexture: InternalTexture

Gets the default empty texture

emptyTexture3D

emptyTexture3D: InternalTexture

Gets the default empty 3D texture

enableOfflineSupport

enableOfflineSupport: boolean

Gets or sets a boolean to enable/disable IndexedDB support and avoid XHR on .manifest

forcePOTTextures

forcePOTTextures: boolean

Gets or sets a boolean that indicates if textures must be forced to power of 2 size even if not required

isFullscreen

isFullscreen: boolean

Gets a boolean indicating if the engine is currently rendering in fullscreen mode

isInVRExclusivePointerMode

isInVRExclusivePointerMode: boolean

Gets a boolean indicating that the engine is currently in VR exclusive mode for the pointers

see

https://docs.microsoft.com/en-us/microsoft-edge/webvr/essentials#mouse-input

isPointerLock

isPointerLock: boolean

Gets a boolean indicating if the pointer is currently locked

isStencilEnable

isStencilEnable: boolean

Returns true if the stencil buffer has been enabled through the creation option of the context.

loadingScreen

loadingScreen: ILoadingScreen

Sets the current loading screen object

see

http://doc.babylonjs.com/how_to/creating_a_custom_loading_screen

loadingUIBackgroundColor

loadingUIBackgroundColor: string

Sets the current loading screen background color

see

http://doc.babylonjs.com/how_to/creating_a_custom_loading_screen

loadingUIText

loadingUIText: string

Sets the current loading screen text

see

http://doc.babylonjs.com/how_to/creating_a_custom_loading_screen

needPOTTextures

needPOTTextures: boolean

Gets a boolean indicating that only power of 2 textures are supported Please note that you can still use non power of 2 textures but in this case the engine will forcefully convert them

onAfterShaderCompilationObservable

onAfterShaderCompilationObservable: Observable<Engine>

Observable raised when the engine has jsut compiled a shader

onBeforeShaderCompilationObservable

onBeforeShaderCompilationObservable: Observable<Engine>

Observable raised when the engine is about to compile a shader

onBeforeTextureInitObservable

onBeforeTextureInitObservable: Observable<Texture>

Observable event triggered before each texture is initialized

onBeginFrameObservable

onBeginFrameObservable: Observable<Engine>

Observable raised when the engine begins a new frame

onCanvasBlurObservable

onCanvasBlurObservable: Observable<Engine>

Observable event triggered each time the canvas loses focus

onCanvasFocusObservable

onCanvasFocusObservable: Observable<Engine>

Observable event triggered each time the canvas gains focus

onCanvasPointerOutObservable

onCanvasPointerOutObservable: Observable<PointerEvent>

Observable event triggered each time the canvas receives pointerout event

onContextLostObservable

onContextLostObservable: Observable<Engine>

Observable signaled when a context lost event is raised

onContextRestoredObservable

onContextRestoredObservable: Observable<Engine>

Observable signaled when a context restored event is raised

onEndFrameObservable

onEndFrameObservable: Observable<Engine>

Observable raised when the engine ends the current frame

onResizeObservable

onResizeObservable: Observable<Engine>

Observable event triggered each time the rendering canvas is resized

onVRDisplayChangedObservable

onVRDisplayChangedObservable: Observable<IDisplayChangedEventArgs>

Observable signaled when VR display mode changes

onVRRequestPresentComplete

onVRRequestPresentComplete: Observable<boolean>

Observable signaled when VR request present is complete

onVRRequestPresentStart

onVRRequestPresentStart: Observable<Engine>

Observable signaled when VR request present starts

performanceMonitor

performanceMonitor: PerformanceMonitor

Gets the performance monitor attached to this engine

see

http://doc.babylonjs.com/how_to/optimizing_your_scene#engineinstrumentation

postProcesses

postProcesses: PostProcess[]

Gets the list of created postprocesses

preventCacheWipeBetweenFrames

preventCacheWipeBetweenFrames: boolean

Gets or sets a boolean indicating that cache can be kept between frames

renderEvenInBackground

renderEvenInBackground: boolean

Gets or sets a boolean indicating if the engine must keep rendering even if the window is not in foregroun

scenes

scenes: Scene[]

Gets the list of created scenes

supportsUniformBuffers

supportsUniformBuffers: boolean

Gets a boolean indicating that the engine supports uniform buffers

see

http://doc.babylonjs.com/features/webgl2#uniform-buffer-objets

textureFormatInUse

textureFormatInUse: Nullable<string>

Gets the list of texture formats in use

texturesSupported

texturesSupported: Array<string>

Gets the list of texture formats supported

webGLVersion

webGLVersion: number

Gets version of the current webGL context

Static ALPHA_ADD

ALPHA_ADD: number

Defines that alpha blending to SRC ALPHA * SRC + DEST

Static ALPHA_COMBINE

ALPHA_COMBINE: number

Defines that alpha blending to SRC ALPHA SRC + (1 - SRC ALPHA) DEST

Static ALPHA_DISABLE

ALPHA_DISABLE: number

Defines that alpha blending is disabled

Static ALPHA_INTERPOLATE

ALPHA_INTERPOLATE: number

Defines that alpha blending to CST SRC + (1 - CST) DEST

Static ALPHA_MAXIMIZED

ALPHA_MAXIMIZED: number

Defines that alpha blending to SRC ALPHA SRC + (1 - SRC) DEST

Static ALPHA_MULTIPLY

ALPHA_MULTIPLY: number

Defines that alpha blending to SRC * DEST

Static ALPHA_ONEONE

ALPHA_ONEONE: number

Defines that alpha blending to SRC + DEST

Static ALPHA_PREMULTIPLIED

ALPHA_PREMULTIPLIED: number

Defines that alpha blending to SRC + (1 - SRC ALPHA) * DEST

Static ALPHA_PREMULTIPLIED_PORTERDUFF

ALPHA_PREMULTIPLIED_PORTERDUFF: number

Defines that alpha blending to SRC + (1 - SRC ALPHA) DEST Alpha will be set to (1 - SRC ALPHA) DEST ALPHA

Static ALPHA_SCREENMODE

ALPHA_SCREENMODE: number

Defines that alpha blending to SRC + (1 - SRC) DEST Alpha will be set to SRC ALPHA + (1 - SRC ALPHA) DEST ALPHA

Static ALPHA_SUBTRACT

ALPHA_SUBTRACT: number

Defines that alpha blending to DEST - SRC * DEST

Static ALWAYS

ALWAYS: number

Passed to depthFunction or stencilFunction to specify depth or stencil tests will always pass. i.e. Pixels will be drawn in the order they are drawn

Static CodeRepository

CodeRepository: string

Gets or sets the relative url used to load code if using the engine in non-minified mode

Static CollisionsEpsilon

CollisionsEpsilon: number

Gets or sets the epsilon value used by collision engine

Static DECR

DECR: number

Passed to stencilOperation to specify that stencil value must be decremented

Static DECR_WRAP

DECR_WRAP: number

Passed to stencilOperation to specify that stencil value must be decremented with wrapping

Static DELAYLOADSTATE_LOADED

DELAYLOADSTATE_LOADED: number

Defines that the ressource was successfully delay loaded

Static DELAYLOADSTATE_LOADING

DELAYLOADSTATE_LOADING: number

Defines that the ressource is currently delay loading

Static DELAYLOADSTATE_NONE

DELAYLOADSTATE_NONE: number

Defines that the ressource is not delayed

Static DELAYLOADSTATE_NOTLOADED

DELAYLOADSTATE_NOTLOADED: number

Defines that the ressource is delayed and has not started loading

Static EQUAL

EQUAL: number

Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is equals to the stored value

Static ExceptionList

ExceptionList: (object | object)[]

Use this array to turn off some WebGL2 features on known buggy browsers version

Static GEQUAL

GEQUAL: number

Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than or equal to the stored value

Static GREATER

GREATER: number

Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is greater than the stored value

Static INCR

INCR: number

Passed to stencilOperation to specify that stencil value must be incremented

Static INCR_WRAP

INCR_WRAP: number

Passed to stencilOperation to specify that stencil value must be incremented with wrapping

Static INVERT

INVERT: number

Passed to stencilOperation to specify that stencil value must be inverted

Static Instances

Instances: Engine[]

Gets the list of created engines

Static KEEP

KEEP: number

Passed to stencilOperation to specify that stencil value must be kept

Static LEQUAL

LEQUAL: number

Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than or equal to the stored value

Static LESS

LESS: number

Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is less than the stored value

Static LastCreatedEngine

LastCreatedEngine: Nullable<Engine>

Gets the latest created engine

Static LastCreatedScene

LastCreatedScene: Nullable<Scene>

Gets the latest created scene

Static NEVER

NEVER: number

Passed to depthFunction or stencilFunction to specify depth or stencil tests will never pass. i.e. Nothing will be drawn

Static NOTEQUAL

NOTEQUAL: number

Passed to depthFunction or stencilFunction to specify depth or stencil tests will pass if the new depth value is not equal to the stored value

Static REPLACE

REPLACE: number

Passed to stencilOperation to specify that stencil value must be replaced

Static SCALEMODE_CEILING

SCALEMODE_CEILING: number

Defines that texture rescaling will use a ceil to find the closer power of 2 size

Static SCALEMODE_FLOOR

SCALEMODE_FLOOR: number

Defines that texture rescaling will use a floor to find the closer power of 2 size

Static SCALEMODE_NEAREST

SCALEMODE_NEAREST: number

Defines that texture rescaling will look for the nearest power of 2 size

Static ShadersRepository

ShadersRepository: string

Gets or sets the relative url used to load shaders if using the engine in non-minified mode

Static TEXTUREFORMAT_ALPHA

TEXTUREFORMAT_ALPHA: number

ALPHA

Static TEXTUREFORMAT_LUMINANCE

TEXTUREFORMAT_LUMINANCE: number

LUMINANCE

Static TEXTUREFORMAT_LUMINANCE_ALPHA

TEXTUREFORMAT_LUMINANCE_ALPHA: number

LUMINANCE_ALPHA

Static TEXTUREFORMAT_R

TEXTUREFORMAT_R: number

R

Static TEXTUREFORMAT_RG

TEXTUREFORMAT_RG: number

RG

Static TEXTUREFORMAT_RGB

TEXTUREFORMAT_RGB: number

RGB

Static TEXTUREFORMAT_RGBA

TEXTUREFORMAT_RGBA: number

RGBA

Static TEXTURETYPE_FLOAT

TEXTURETYPE_FLOAT: number

FLOAT

Static TEXTURETYPE_HALF_FLOAT

TEXTURETYPE_HALF_FLOAT: number

HALF_FLOAT

Static TEXTURETYPE_UNSIGNED_INT

TEXTURETYPE_UNSIGNED_INT: number

UNSIGNED_INT

Static Version

Version: string

Returns the current version of the framework

Static audioEngine

audioEngine: AudioEngine

Gets the audio engine

see

http://doc.babylonjs.com/how_to/playing_sounds_and_music

ignorenaming

Methods

addExternalData

  • addExternalData<T>(key: string, data: T): boolean
  • Add an externaly attached data from its key. This method call will fail and return false, if such key already exists. If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.

    Type parameters

    • T

    Parameters

    • key: string

      the unique key that identifies the data

    • data: T

      the data object to associate to the key for this Engine instance

    Returns boolean

    true if no such key were already present and the data was added successfully, false otherwise

applyStates

  • applyStates(): void
  • Apply all cached states (depth, culling, stencil and alpha)

    Returns void

attachContextLostEvent

  • attachContextLostEvent(callback: function): void
  • Attach a new callback raised when context lost event is fired

    Parameters

    • callback: function

      defines the callback to call

        • (event: WebGLContextEvent): void
        • Parameters

          • event: WebGLContextEvent

          Returns void

    Returns void

attachContextRestoredEvent

  • attachContextRestoredEvent(callback: function): void
  • Attach a new callback raised when context restored event is fired

    Parameters

    • callback: function

      defines the callback to call

        • (event: WebGLContextEvent): void
        • Parameters

          • event: WebGLContextEvent

          Returns void

    Returns void

beginFrame

  • beginFrame(): void
  • Begin a new frame

    Returns void

beginOcclusionQuery

beginTransformFeedback

  • beginTransformFeedback(usePoints?: boolean): void
  • Begins a transform feedback operation

    Parameters

    • Optional usePoints: boolean

      defines if points or triangles must be used

    Returns void

bindArrayBuffer

  • bindArrayBuffer(buffer: Nullable<WebGLBuffer>): void
  • Bind a webGL buffer to the webGL context

    Parameters

    • buffer: Nullable<WebGLBuffer>

      defines the buffer to bind

    Returns void

bindBuffers

  • bindBuffers(vertexBuffers: object, indexBuffer: Nullable<WebGLBuffer>, effect: Effect): void
  • Bind a list of vertex buffers to the webGL context

    Parameters

    • vertexBuffers: object

      defines the list of vertex buffers to bind

    • indexBuffer: Nullable<WebGLBuffer>

      defines the index buffer to bind

    • effect: Effect

      defines the effect associated with the vertex buffers

    Returns void

bindBuffersDirectly

  • bindBuffersDirectly(vertexBuffer: WebGLBuffer, indexBuffer: WebGLBuffer, vertexDeclaration: number[], vertexStrideSize: number, effect: Effect): void
  • Bind webGl buffers directly to the webGL context

    Parameters

    • vertexBuffer: WebGLBuffer

      defines the vertex buffer to bind

    • indexBuffer: WebGLBuffer

      defines the index buffer to bind

    • vertexDeclaration: number[]

      defines the vertex declaration to use with the vertex buffer

    • vertexStrideSize: number

      defines the vertex stride of the vertex buffer

    • effect: Effect

      defines the effect associated with the vertex buffer

    Returns void

bindFramebuffer

  • bindFramebuffer(texture: InternalTexture, faceIndex?: number, requiredWidth?: number, requiredHeight?: number, forceFullscreenViewport?: boolean, depthStencilTexture?: InternalTexture): void
  • Binds the frame buffer to the specified texture.

    Parameters

    • texture: InternalTexture

      The texture to render to or null for the default canvas

    • Optional faceIndex: number

      The face of the texture to render to in case of cube texture

    • Optional requiredWidth: number

      The width of the target to render to

    • Optional requiredHeight: number

      The height of the target to render to

    • Optional forceFullscreenViewport: boolean

      Forces the viewport to be the entire texture/screen if true

    • Optional depthStencilTexture: InternalTexture

      The depth stencil texture to use to render

    Returns void

bindSamplers

  • bindSamplers(effect: Effect): void
  • Binds an effect to the webGL context

    Parameters

    • effect: Effect

      defines the effect to bind

    Returns void

bindTransformFeedback

  • Bind a webGL transform feedback object to the webgl context

    Parameters

    Returns void

bindTransformFeedbackBuffer

  • bindTransformFeedbackBuffer(value: Nullable<WebGLBuffer>): void
  • Bind a webGL buffer for a transform feedback operation

    Parameters

    • value: Nullable<WebGLBuffer>

      defines the webGL buffer to bind

    Returns void

bindUniformBlock

  • bindUniformBlock(shaderProgram: WebGLProgram, blockName: string, index: number): void
  • Bind a specific block at a given index in a specific shader program

    Parameters

    • shaderProgram: WebGLProgram

      defines the shader program

    • blockName: string

      defines the block name

    • index: number

      defines the index where to bind the block

    Returns void

bindUniformBuffer

  • bindUniformBuffer(buffer: Nullable<WebGLBuffer>): void
  • Bind an uniform buffer to the current webGL context

    Parameters

    • buffer: Nullable<WebGLBuffer>

      defines the buffer to bind

    Returns void

bindUniformBufferBase

  • bindUniformBufferBase(buffer: WebGLBuffer, location: number): void
  • Bind a buffer to the current webGL context at a given location

    Parameters

    • buffer: WebGLBuffer

      defines the buffer to bind

    • location: number

      defines the index where to bind the buffer

    Returns void

bindVertexArrayObject

clear

  • clear(color: Nullable<Color4>, backBuffer: boolean, depth: boolean, stencil?: boolean): void
  • Clear the current render buffer or the current render target (if any is set up)

    Parameters

    • color: Nullable<Color4>

      defines the color to use

    • backBuffer: boolean

      defines if the back buffer must be cleared

    • depth: boolean

      defines if the depth buffer must be cleared

    • Optional stencil: boolean

      defines if the stencil buffer must be cleared

    Returns void

createCubeTexture

  • Creates a cube texture

    Parameters

    • rootUrl: string

      defines the url where the files to load is located

    • scene: Nullable<Scene>

      defines the current scene

    • files: Nullable<string[]>

      defines the list of files to load (1 per face)

    • Optional noMipmap: boolean

      defines a boolean indicating that no mipmaps shall be generated (false by default)

    • Optional onLoad: Nullable<function>

      defines an optional callback raised when the texture is loaded

    • Optional onError: Nullable<function>

      defines an optional callback raised if there is an issue to load the texture

    • Optional format: number

      defines the format of the data

    • Optional forcedExtension: any

      defines the extension to use to pick the right loader

    • Optional createPolynomials: boolean

      if a polynomial sphere should be created for the cube texture

    Returns InternalTexture

    the cube texture as an InternalTexture

createDepthStencilTexture

  • Creates a depth stencil texture. This is only available in WebGL 2 or with the depth texture extension available.

    Parameters

    Returns InternalTexture

    The texture

createDynamicTexture

  • createDynamicTexture(width: number, height: number, generateMipMaps: boolean, samplingMode: number): InternalTexture
  • Creates a dynamic texture

    Parameters

    • width: number

      defines the width of the texture

    • height: number

      defines the height of the texture

    • generateMipMaps: boolean

      defines if the engine should generate the mip levels

    • samplingMode: number

      defines the required sampling mode (BABYLON.Texture.NEAREST_SAMPLINGMODE by default)

    Returns InternalTexture

    the dynamic texture inside an InternalTexture

createDynamicUniformBuffer

  • createDynamicUniformBuffer(elements: FloatArray): WebGLBuffer

createDynamicVertexBuffer

  • createDynamicVertexBuffer(data: DataArray): WebGLBuffer
  • Creates a dynamic vertex buffer

    Parameters

    • data: DataArray

      the data for the dynamic vertex buffer

    Returns WebGLBuffer

    the new WebGL dynamic buffer

createEffect

  • createEffect(baseName: any, attributesNamesOrOptions: string[] | EffectCreationOptions, uniformsNamesOrEngine: string[] | Engine, samplers?: string[], defines?: string, fallbacks?: EffectFallbacks, onCompiled?: function, onError?: function, indexParameters?: any): Effect
  • Create a new effect (used to store vertex/fragment shaders)

    Parameters

    • baseName: any

      defines the base name of the effect (The name of file without .fragment.fx or .vertex.fx)

    • attributesNamesOrOptions: string[] | EffectCreationOptions

      defines either a list of attribute names or an EffectCreationOptions object

    • uniformsNamesOrEngine: string[] | Engine

      defines either a list of uniform names or the engine to use

    • Optional samplers: string[]

      defines an array of string used to represent textures

    • Optional defines: string

      defines the string containing the defines to use to compile the shaders

    • Optional fallbacks: EffectFallbacks

      defines the list of potential fallbacks to use if shader conmpilation fails

    • Optional onCompiled: function

      defines a function to call when the effect creation is successful

        • Parameters

          Returns void

    • Optional onError: function

      defines a function to call when the effect creation has failed

        • (effect: Effect, errors: string): void
        • Parameters

          • effect: Effect
          • errors: string

          Returns void

    • Optional indexParameters: any

      defines an object containing the index values to use to compile shaders (like the maximum number of simultaneous lights)

    Returns Effect

    the new Effect

createEffectForParticles

  • createEffectForParticles(fragmentName: string, uniformsNames?: string[], samplers?: string[], defines?: string, fallbacks?: EffectFallbacks, onCompiled?: function, onError?: function): Effect
  • Create an effect to use with particle systems

    Parameters

    • fragmentName: string

      defines the base name of the effect (The name of file without .fragment.fx)

    • Optional uniformsNames: string[]

      defines a list of attribute names

    • Optional samplers: string[]

      defines an array of string used to represent textures

    • Optional defines: string

      defines the string containing the defines to use to compile the shaders

    • Optional fallbacks: EffectFallbacks

      defines the list of potential fallbacks to use if shader conmpilation fails

    • Optional onCompiled: function

      defines a function to call when the effect creation is successful

        • Parameters

          Returns void

    • Optional onError: function

      defines a function to call when the effect creation has failed

        • (effect: Effect, errors: string): void
        • Parameters

          • effect: Effect
          • errors: string

          Returns void

    Returns Effect

    the new Effect

createIndexBuffer

  • createIndexBuffer(indices: IndicesArray, updatable?: boolean): WebGLBuffer
  • Creates a new index buffer

    Parameters

    • indices: IndicesArray

      defines the content of the index buffer

    • Optional updatable: boolean

      defines if the index buffer must be updatable

    Returns WebGLBuffer

    a new webGL buffer

createInstancesBuffer

  • createInstancesBuffer(capacity: number): WebGLBuffer
  • Creates a webGL buffer to use with instanciation

    Parameters

    • capacity: number

      defines the size of the buffer

    Returns WebGLBuffer

    the webGL buffer

createMultipleRenderTarget

createPrefilteredCubeTexture

  • createPrefilteredCubeTexture(rootUrl: string, scene: Nullable<Scene>, scale: number, offset: number, onLoad?: Nullable<function>, onError?: Nullable<function>, format?: number, forcedExtension?: any, createPolynomials?: boolean): InternalTexture
  • Create a cube texture from prefiltered data (ie. the mipmaps contain ready to use data for PBR reflection)

    Parameters

    • rootUrl: string

      defines the url where the file to load is located

    • scene: Nullable<Scene>

      defines the current scene

    • scale: number

      defines scale to apply to the mip map selection

    • offset: number

      defines offset to apply to the mip map selection

    • Optional onLoad: Nullable<function>

      defines an optional callback raised when the texture is loaded

    • Optional onError: Nullable<function>

      defines an optional callback raised if there is an issue to load the texture

    • Optional format: number

      defines the format of the data

    • Optional forcedExtension: any

      defines the extension to use to pick the right loader

    • Optional createPolynomials: boolean

      defines wheter or not to create polynomails harmonics for the texture

    Returns InternalTexture

    the cube texture as an InternalTexture

createQuery

  • Create a new webGL query (you must be sure that queries are supported by checking getCaps() function)

    Returns WebGLQuery

    the new query

createRawCubeTexture

  • createRawCubeTexture(data: Nullable<ArrayBufferView[]>, size: number, format: number, type: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression?: Nullable<string>): InternalTexture
  • Creates a new raw cube texture

    Parameters

    • data: Nullable<ArrayBufferView[]>

      defines the array of data to use to create each face

    • size: number

      defines the size of the textures

    • format: number

      defines the format of the data

    • type: number

      defines the type fo the data (like BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT)

    • generateMipMaps: boolean

      defines if the engine should generate the mip levels

    • invertY: boolean

      defines if data must be stored with Y axis inverted

    • samplingMode: number

      defines the required sampling mode (like BABYLON.Texture.NEAREST_SAMPLINGMODE)

    • Optional compression: Nullable<string>

      defines the compression used (null by default)

    Returns InternalTexture

    the cube texture as an InternalTexture

createRawCubeTextureFromUrl

  • createRawCubeTextureFromUrl(url: string, scene: Scene, size: number, format: number, type: number, noMipmap: boolean, callback: function, mipmapGenerator: Nullable<function>, onLoad?: Nullable<function>, onError?: Nullable<function>, samplingMode?: number, invertY?: boolean): InternalTexture
  • Creates a new raw cube texture from a specified url

    Parameters

    • url: string

      defines the url where the data is located

    • scene: Scene

      defines the current scene

    • size: number

      defines the size of the textures

    • format: number

      defines the format of the data

    • type: number

      defines the type fo the data (like BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT)

    • noMipmap: boolean

      defines if the engine should avoid generating the mip levels

    • callback: function

      defines a callback used to extract texture data from loaded data

        • (ArrayBuffer: ArrayBuffer): Nullable<ArrayBufferView[]>
        • Parameters

          • ArrayBuffer: ArrayBuffer

          Returns Nullable<ArrayBufferView[]>

    • mipmapGenerator: Nullable<function>

      defines to provide an optional tool to generate mip levels

    • Optional onLoad: Nullable<function>

      defines a callback called when texture is loaded

    • Optional onError: Nullable<function>

      defines a callback called if there is an error

    • Optional samplingMode: number

      defines the required sampling mode (like BABYLON.Texture.NEAREST_SAMPLINGMODE)

    • Optional invertY: boolean

      defines if data must be stored with Y axis inverted

    Returns InternalTexture

    the cube texture as an InternalTexture

createRawShaderProgram

  • createRawShaderProgram(vertexCode: string, fragmentCode: string, context?: WebGLRenderingContext, transformFeedbackVaryings?: Nullable<string[]>): WebGLProgram
  • Directly creates a webGL program

    Parameters

    • vertexCode: string

      defines the vertex shader code to use

    • fragmentCode: string

      defines the fragment shader code to use

    • Optional context: WebGLRenderingContext

      defines the webGL context to use (if not set, the current one will be used)

    • Optional transformFeedbackVaryings: Nullable<string[]>

      defines the list of transform feedback varyings to use

    Returns WebGLProgram

    the new webGL program

createRawTexture

  • createRawTexture(data: Nullable<ArrayBufferView>, width: number, height: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression?: Nullable<string>, type?: number): InternalTexture
  • Creates a raw texture

    Parameters

    • data: Nullable<ArrayBufferView>

      defines the data to store in the texture

    • width: number

      defines the width of the texture

    • height: number

      defines the height of the texture

    • format: number

      defines the format of the data

    • generateMipMaps: boolean

      defines if the engine should generate the mip levels

    • invertY: boolean

      defines if data must be stored with Y axis inverted

    • samplingMode: number

      defines the required sampling mode (BABYLON.Texture.NEAREST_SAMPLINGMODE by default)

    • Optional compression: Nullable<string>

      defines the compression used (null by default)

    • Optional type: number

      defines the type fo the data (BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT by default)

    Returns InternalTexture

    the raw texture inside an InternalTexture

createRawTexture3D

  • createRawTexture3D(data: Nullable<ArrayBufferView>, width: number, height: number, depth: number, format: number, generateMipMaps: boolean, invertY: boolean, samplingMode: number, compression?: Nullable<string>, textureType?: number): InternalTexture
  • Creates a new raw 3D texture

    Parameters

    • data: Nullable<ArrayBufferView>

      defines the data used to create the texture

    • width: number

      defines the width of the texture

    • height: number

      defines the height of the texture

    • depth: number

      defines the depth of the texture

    • format: number

      defines the format of the texture

    • generateMipMaps: boolean

      defines if the engine must generate mip levels

    • invertY: boolean

      defines if data must be stored with Y axis inverted

    • samplingMode: number

      defines the required sampling mode (like BABYLON.Texture.NEAREST_SAMPLINGMODE)

    • Optional compression: Nullable<string>

      defines the compressed used (can be null)

    • Optional textureType: number

      defines the compressed used (can be null)

    Returns InternalTexture

    a new raw 3D texture (stored in an InternalTexture)

createRenderTargetCubeTexture

  • Creates a new render target cube texture

    Parameters

    • size: number

      defines the size of the texture

    • Optional options: Partial<RenderTargetCreationOptions>

      defines the options used to create the texture

    Returns InternalTexture

    a new render target cube texture stored in an InternalTexture

createRenderTargetTexture

  • Creates a new render target texture

    Parameters

    • size: number | object

      defines the size of the texture

    • options: boolean | RenderTargetCreationOptions

      defines the options used to create the texture

    Returns InternalTexture

    a new render target texture stored in an InternalTexture

createShaderProgram

  • createShaderProgram(vertexCode: string, fragmentCode: string, defines: Nullable<string>, context?: WebGLRenderingContext, transformFeedbackVaryings?: Nullable<string[]>): WebGLProgram
  • Creates a webGL program

    Parameters

    • vertexCode: string

      defines the vertex shader code to use

    • fragmentCode: string

      defines the fragment shader code to use

    • defines: Nullable<string>

      defines the string containing the defines to use to compile the shaders

    • Optional context: WebGLRenderingContext

      defines the webGL context to use (if not set, the current one will be used)

    • Optional transformFeedbackVaryings: Nullable<string[]>

      defines the list of transform feedback varyings to use

    Returns WebGLProgram

    the new webGL program

createTexture

  • Usually called from BABYLON.Texture.ts. Passed information to create a WebGLTexture

    Parameters

    • urlArg: Nullable<string>

      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'
    • noMipmap: boolean

      defines a boolean indicating that no mipmaps shall be generated. Ignored for compressed textures. They must be in the file

    • invertY: boolean

      when true, image is flipped when loaded. You probably want true. Ignored for compressed textures. Must be flipped in the file

    • scene: Nullable<Scene>

      needed for loading to the correct scene

    • Optional samplingMode: number

      mode with should be used sample / access the texture (Default: BABYLON.Texture.TRILINEAR_SAMPLINGMODE)

    • Optional onLoad: Nullable<function>

      optional callback to be called upon successful completion

    • Optional onError: Nullable<function>

      optional callback to be called upon failure

    • Optional buffer: Nullable<string | ArrayBuffer | HTMLImageElement | Blob>

      a source of a file previously fetched as either a base64 string, an ArrayBuffer (compressed or image format), HTMLImageElement (image format), or a Blob

    • Optional fallback: Nullable<InternalTexture>

      an internal argument in case the function must be called again, due to etc1 not having alpha capabilities

    • Optional format: Nullable<number>

      internal format. Default: RGB when extension is '.jpg' else RGBA. Ignored for compressed textures

    Returns InternalTexture

    a InternalTexture for assignment back into BABYLON.Texture

createTransformFeedback

  • Creates a webGL transform feedback object Please makes sure to check webGLVersion property to check if you are running webGL 2+

    Returns WebGLTransformFeedback

    the webGL transform feedback object

createUniformBuffer

  • createUniformBuffer(elements: FloatArray): WebGLBuffer

createVertexBuffer

  • createVertexBuffer(data: DataArray): WebGLBuffer
  • Creates a vertex buffer

    Parameters

    • data: DataArray

      the data for the vertex buffer

    Returns WebGLBuffer

    the new WebGL static buffer

deleteInstancesBuffer

  • deleteInstancesBuffer(buffer: WebGLBuffer): void
  • Delete a webGL buffer used with instanciation

    Parameters

    • buffer: WebGLBuffer

      defines the webGL buffer to delete

    Returns void

deleteQuery

  • Delete and release a webGL query

    Parameters

    Returns Engine

    the current engine

deleteTransformFeedback

  • Delete a webGL transform feedback object

    Parameters

    Returns void

disableVR

  • disableVR(): void

displayLoadingUI

  • displayLoadingUI(): void

dispose

  • dispose(): void
  • Dispose and release all associated resources

    Returns void

draw

  • draw(useTriangles: boolean, indexStart: number, indexCount: number, instancesCount?: number): void
  • Send a draw order

    Parameters

    • useTriangles: boolean

      defines if triangles must be used to draw (else wireframe will be used)

    • indexStart: number

      defines the starting index

    • indexCount: number

      defines the number of index to draw

    • Optional instancesCount: number

      defines the number of instances to draw (if instanciation is enabled)

    Returns void

drawArraysType

  • drawArraysType(fillMode: number, verticesStart: number, verticesCount: number, instancesCount?: number): void
  • Draw a list of unindexed primitives

    Parameters

    • fillMode: number

      defines the primitive to use

    • verticesStart: number

      defines the index of first vertex to draw

    • verticesCount: number

      defines the count of vertices to draw

    • Optional instancesCount: number

      defines the number of instances to draw (if instanciation is enabled)

    Returns void

drawElementsType

  • drawElementsType(fillMode: number, indexStart: number, indexCount: number, instancesCount?: number): void
  • Draw a list of indexed primitives

    Parameters

    • fillMode: number

      defines the primitive to use

    • indexStart: number

      defines the starting index

    • indexCount: number

      defines the number of index to draw

    • Optional instancesCount: number

      defines the number of instances to draw (if instanciation is enabled)

    Returns void

drawPointClouds

  • drawPointClouds(verticesStart: number, verticesCount: number, instancesCount?: number): void
  • Draw a list of points

    Parameters

    • verticesStart: number

      defines the index of first vertex to draw

    • verticesCount: number

      defines the count of vertices to draw

    • Optional instancesCount: number

      defines the number of instances to draw (if instanciation is enabled)

    Returns void

drawUnIndexed

  • drawUnIndexed(useTriangles: boolean, verticesStart: number, verticesCount: number, instancesCount?: number): void
  • Draw a list of unindexed primitives

    Parameters

    • useTriangles: boolean

      defines if triangles must be used to draw (else wireframe will be used)

    • verticesStart: number

      defines the index of first vertex to draw

    • verticesCount: number

      defines the count of vertices to draw

    • Optional instancesCount: number

      defines the number of instances to draw (if instanciation is enabled)

    Returns void

enableEffect

  • Activates an effect, mkaing it the current one (ie. the one used for rendering)

    Parameters

    Returns void

enableVR

  • enableVR(): void

endFrame

  • endFrame(): void
  • Enf the current frame

    Returns void

endOcclusionQuery

  • endOcclusionQuery(algorithmType: number): Engine

endTimeQuery

  • endTimeQuery(token: _TimeToken): int
  • Ends a time query

    Parameters

    • token: _TimeToken

      defines the token used to measure the time span

    Returns int

    the time spent (in ns)

endTransformFeedback

  • endTransformFeedback(): void
  • Ends a transform feedback operation

    Returns void

flushFramebuffer

  • flushFramebuffer(): void
  • Force a webGL flush (ie. a flush of all waiting webGL commands)

    Returns void

generateMipMapsForCubemap

  • Force the mipmap generation for the given render target texture

    Parameters

    Returns void

getAlphaMode

  • getAlphaMode(): number

getAspectRatio

  • getAspectRatio(camera: Camera, useScreen?: boolean): number
  • Gets current aspect ratio

    Parameters

    • camera: Camera

      defines the camera to use to get the aspect ratio

    • Optional useScreen: boolean

      defines if screen size must be used (or the current render target if any)

    Returns number

    a number defining the aspect ratio

getAttributes

  • getAttributes(shaderProgram: WebGLProgram, attributesNames: string[]): number[]
  • Gets the lsit of active attributes for a given webGL program

    Parameters

    • shaderProgram: WebGLProgram

      defines the webGL program to use

    • attributesNames: string[]

      defines the list of attribute names to get

    Returns number[]

    an array of indices indicating the offset of each attribute

getCaps

  • Gets the object containing all engine capabilities

    Returns EngineCapabilities

    the EngineCapabilities object

getColorWrite

  • getColorWrite(): boolean
  • Gets a boolean indicating if color writing is enabled

    Returns boolean

    the current color writing state

getDeltaTime

  • getDeltaTime(): number
  • Gets the time spent between current and previous frame

    Returns number

    a number representing the delta time in ms

getDepthFunction

  • Gets the current depth function

    Returns Nullable<number>

    a number defining the depth function

getDepthWrite

  • getDepthWrite(): boolean
  • Gets a boolean indicating if depth writing is enabled

    Returns boolean

    the current depth writing state

getError

  • getError(): number

getExternalData

  • getExternalData<T>(key: string): T
  • Get an externaly attached data from its key

    Type parameters

    • T

    Parameters

    • key: string

      the unique key that identifies the data

    Returns T

    the associated data, if present (can be null), or undefined if not present

getFps

  • getFps(): number
  • Gets the current framerate

    Returns number

    a number representing the framerate

getFragmentShaderSource

  • getFragmentShaderSource(program: WebGLProgram): Nullable<string>
  • Gets the source code of the fragment shader associated with a specific webGL program

    Parameters

    • program: WebGLProgram

      defines the program to use

    Returns Nullable<string>

    a string containing the source code of the fragment shader associated with the program

getGlInfo

  • getGlInfo(): object
  • Gets an object containing information about the current webGL context

    Returns object

    an object containing the vender, the renderer and the version of the current webGL context

    • renderer: string
    • vendor: string
    • version: string

getHardwareScalingLevel

  • getHardwareScalingLevel(): number
  • Gets the current hardware scaling level. By default the hardware scaling level is computed from the window device ratio. 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.

    Returns number

    a number indicating the current hardware scaling level

getLoadedTexturesCache

  • Gets the list of loaded textures

    Returns InternalTexture[]

    an array containing all loaded textures

getLockstepMaxSteps

  • getLockstepMaxSteps(): number

getOrAddExternalDataWithFactory

  • getOrAddExternalDataWithFactory<T>(key: string, factory: function): T
  • Get an externaly attached data from its key, create it using a factory if it's not already present

    Type parameters

    • T

    Parameters

    • key: string

      the unique key that identifies the data

    • factory: function

      the factory that will be called to create the instance if and only if it doesn't exists

        • (k: string): T
        • Parameters

          • k: string

          Returns T

    Returns T

    the associated data, can be null if the factory returned null.

getQueryResult

  • Gets the value of a given query

    Parameters

    Returns number

    the value of the query

getRenderHeight

  • getRenderHeight(useScreen?: boolean): number
  • Gets the current render height

    Parameters

    • Optional useScreen: boolean

      defines if screen size must be used (or the current render target if any)

    Returns number

    a number defining the current render height

getRenderWidth

  • getRenderWidth(useScreen?: boolean): number
  • Gets the current render width

    Parameters

    • Optional useScreen: boolean

      defines if screen size must be used (or the current render target if any)

    Returns number

    a number defining the current render width

getRenderingCanvas

  • getRenderingCanvas(): Nullable<HTMLCanvasElement>
  • Gets the HTML canvas attached with the current webGL context

    Returns Nullable<HTMLCanvasElement>

    a HTML canvas

getRenderingCanvasClientRect

  • getRenderingCanvasClientRect(): Nullable<ClientRect>
  • Gets the client rect of the HTML canvas attached with the current webGL context

    Returns Nullable<ClientRect>

    a client rectanglee

getScreenAspectRatio

  • getScreenAspectRatio(): number
  • Gets current screen aspect ratio

    Returns number

    a number defining the aspect ratio

getStencilBuffer

  • getStencilBuffer(): boolean
  • Gets a boolean indicating if stencil buffer is enabled

    Returns boolean

    the current stencil buffer state

getStencilFunction

  • getStencilFunction(): number
  • Gets the current stencil function

    Returns number

    a number defining the stencil function to use

getStencilFunctionMask

  • getStencilFunctionMask(): number
  • Gets the current stencil mask

    Returns number

    a number defining the stencil mask to use

getStencilFunctionReference

  • getStencilFunctionReference(): number
  • Gets the current stencil reference value

    Returns number

    a number defining the stencil reference value to use

getStencilMask

  • getStencilMask(): number
  • Gets the current stencil mask

    Returns number

    a number defining the new stencil mask to use

getStencilOperationDepthFail

  • getStencilOperationDepthFail(): number
  • Gets the current stencil operation when depth fails

    Returns number

    a number defining stencil operation to use when depth fails

getStencilOperationFail

  • getStencilOperationFail(): number
  • Gets the current stencil operation when stencil fails

    Returns number

    a number defining stencil operation to use when stencil fails

getStencilOperationPass

  • getStencilOperationPass(): number
  • Gets the current stencil operation when stencil passes

    Returns number

    a number defining stencil operation to use when stencil passes

getUniforms

  • getUniforms(shaderProgram: WebGLProgram, uniformsNames: string[]): Nullable<WebGLUniformLocation>[]
  • Gets the list of webGL uniform locations associated with a specific program based on a list of uniform names

    Parameters

    • shaderProgram: WebGLProgram

      defines the webGL program to use

    • uniformsNames: string[]

      defines the list of uniform names

    Returns Nullable<WebGLUniformLocation>[]

    an array of webGL uniform locations

getVRDevice

  • getVRDevice(): any
  • Gets the current webVR device

    Returns any

    the current webVR device (or null)

getVertexShaderSource

  • getVertexShaderSource(program: WebGLProgram): Nullable<string>
  • Gets the source code of the vertex shader associated with a specific webGL program

    Parameters

    • program: WebGLProgram

      defines the program to use

    Returns Nullable<string>

    a string containing the source code of the vertex shader associated with the program

getZOffset

  • getZOffset(): number
  • Gets the current value of the zOffset

    Returns number

    the current zOffset state

hideLoadingUI

  • hideLoadingUI(): void

initWebVR

  • Initializes a webVR display and starts listening to display change events The onVRDisplayChangedObservable will be notified upon these changes

    Returns Observable<IDisplayChangedEventArgs>

    The onVRDisplayChangedObservable

initWebVRAsync

  • Initializes a webVR display and starts listening to display change events The onVRDisplayChangedObservable will be notified upon these changes

    Returns Promise<IDisplayChangedEventArgs>

    A promise containing a VRDisplay and if vr is supported

isDeterministicLockStep

  • isDeterministicLockStep(): boolean

isQueryResultAvailable

  • isQueryResultAvailable(query: WebGLQuery): boolean
  • Check if a given query has resolved and got its value

    Parameters

    Returns boolean

    true if the query got its value

isVRDevicePresent

  • isVRDevicePresent(): boolean
  • Gets a boolean indicating if a webVR device was detected

    Returns boolean

    true if a webVR device was detected

readPixels

  • readPixels(x: number, y: number, width: number, height: number): Uint8Array
  • Reads pixels from the current frame buffer. Please note that this function can be slow

    Parameters

    • x: number

      defines the x coordinate of the rectangle where pixels must be read

    • y: number

      defines the y coordinate of the rectangle where pixels must be read

    • width: number

      defines the width of the rectangle where pixels must be read

    • height: number

      defines the height of the rectangle where pixels must be read

    Returns Uint8Array

    a Uint8Array containing RGBA colors

recordVertexArrayObject

releaseEffects

  • releaseEffects(): void
  • 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

    Returns void

releaseVertexArrayObject

  • Release and free the memory of a vertex array object

    Parameters

    Returns void

removeExternalData

  • removeExternalData(key: string): boolean
  • Remove an externaly attached data from the Engine instance

    Parameters

    • key: string

      the unique key that identifies the data

    Returns boolean

    true if the data was successfully removed, false if it doesn't exist

resetTextureCache

  • resetTextureCache(): void
  • Reset the texture cache to empty state

    Returns void

resize

  • resize(): void
  • Resize the view according to the canvas' size

    Returns void

restoreDefaultFramebuffer

  • restoreDefaultFramebuffer(): void
  • Unbind the current render target and bind the default framebuffer

    Returns void

runRenderLoop

  • runRenderLoop(renderFunction: function): void
  • Register and execute a render loop. The engine can have more than one render function

    Parameters

    • renderFunction: function

      defines the function to continuously execute

        • (): void
        • Returns void

    Returns void

scissorClear

  • scissorClear(x: number, y: number, width: number, height: number, clearColor: Color4): void
  • Executes a scissor clear (ie. a clear on a specific portion of the screen)

    Parameters

    • x: number

      defines the x-coordinate of the top left corner of the clear rectangle

    • y: number

      defines the y-coordinate of the corner of the clear rectangle

    • width: number

      defines the width of the clear rectangle

    • height: number

      defines the height of the clear rectangle

    • clearColor: Color4

      defines the clear color

    Returns void

setAlphaConstants

  • setAlphaConstants(r: number, g: number, b: number, a: number): void
  • Sets alpha constants used by some alpha blending modes

    Parameters

    • r: number

      defines the red component

    • g: number

      defines the green component

    • b: number

      defines the blue component

    • a: number

      defines the alpha component

    Returns void

setAlphaMode

  • setAlphaMode(mode: number, noDepthWriteChange?: boolean): void

setArray

  • setArray(uniform: Nullable<WebGLUniformLocation>, array: number[]): void
  • Set the value of an uniform to an array of number

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: number[]

      defines the array of number to store

    Returns void

setArray2

  • setArray2(uniform: Nullable<WebGLUniformLocation>, array: number[]): void
  • Set the value of an uniform to an array of number (stored as vec2)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: number[]

      defines the array of number to store

    Returns void

setArray3

  • setArray3(uniform: Nullable<WebGLUniformLocation>, array: number[]): void
  • Set the value of an uniform to an array of number (stored as vec3)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: number[]

      defines the array of number to store

    Returns void

setArray4

  • setArray4(uniform: Nullable<WebGLUniformLocation>, array: number[]): void
  • Set the value of an uniform to an array of number (stored as vec4)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: number[]

      defines the array of number to store

    Returns void

setBool

  • setBool(uniform: Nullable<WebGLUniformLocation>, bool: number): void
  • Set the value of an uniform to a boolean

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • bool: number

      defines the boolean to store

    Returns void

setColor3

  • setColor3(uniform: Nullable<WebGLUniformLocation>, color3: Color3): void
  • Set the value of an uniform to a Color3

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • color3: Color3

      defines the color to store

    Returns void

setColor4

  • setColor4(uniform: Nullable<WebGLUniformLocation>, color3: Color3, alpha: number): void
  • Set the value of an uniform to a Color3 and an alpha value

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • color3: Color3

      defines the color to store

    • alpha: number

      defines the alpha component to store

    Returns void

setColorWrite

  • setColorWrite(enable: boolean): void
  • Enable or disable color writing

    Parameters

    • enable: boolean

      defines the state to set

    Returns void

setDepthBuffer

  • setDepthBuffer(enable: boolean): void
  • Enable or disable depth buffering

    Parameters

    • enable: boolean

      defines the state to set

    Returns void

setDepthFunction

  • setDepthFunction(depthFunc: number): void
  • Sets the current depth function

    Parameters

    • depthFunc: number

      defines the function to use

    Returns void

setDepthFunctionToGreater

  • setDepthFunctionToGreater(): void
  • Sets the current depth function to GREATER

    Returns void

setDepthFunctionToGreaterOrEqual

  • setDepthFunctionToGreaterOrEqual(): void
  • Sets the current depth function to GEQUAL

    Returns void

setDepthFunctionToLess

  • setDepthFunctionToLess(): void
  • Sets the current depth function to LESS

    Returns void

setDepthFunctionToLessOrEqual

  • setDepthFunctionToLessOrEqual(): void
  • Sets the current depth function to LEQUAL

    Returns void

setDepthStencilTexture

  • Sets a depth stencil texture from a render target to the according uniform.

    Parameters

    • channel: number

      The texture channel

    • uniform: Nullable<WebGLUniformLocation>

      The uniform to set

    • texture: Nullable<RenderTargetTexture>

      The render target texture containing the depth stencil texture to apply

    Returns void

setDepthWrite

  • setDepthWrite(enable: boolean): void
  • Enable or disable depth writing

    Parameters

    • enable: boolean

      defines the state to set

    Returns void

setDirectColor4

  • setDirectColor4(uniform: Nullable<WebGLUniformLocation>, color4: Color4): void
  • Sets a Color4 on a uniform variable

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the uniform location

    • color4: Color4

      defines the value to be set

    Returns void

setDirectViewport

  • setDirectViewport(x: number, y: number, width: number, height: number): Nullable<Viewport>
  • Directly set the WebGL Viewport

    Parameters

    • x: number

      defines the x coordinate of the viewport (in screen space)

    • y: number

      defines the y coordinate of the viewport (in screen space)

    • width: number

      defines the width of the viewport (in screen space)

    • height: number

      defines the height of the viewport (in screen space)

    Returns Nullable<Viewport>

    the current viewport Object (if any) that is being replaced by this call. You can restore this viewport later on to go back to the original state

setDitheringState

  • setDitheringState(value: boolean): void
  • Sets a boolean indicating if the dithering state is enabled or disabled

    Parameters

    • value: boolean

      defines the dithering state

    Returns void

setFloat

  • setFloat(uniform: Nullable<WebGLUniformLocation>, value: number): void
  • Set the value of an uniform to a number (float)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • value: number

      defines the float number to store

    Returns void

setFloat2

  • setFloat2(uniform: Nullable<WebGLUniformLocation>, x: number, y: number): void
  • Set the value of an uniform to a vec2

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • x: number

      defines the 1st component of the value

    • y: number

      defines the 2nd component of the value

    Returns void

setFloat3

  • setFloat3(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number): void
  • Set the value of an uniform to a vec3

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • x: number

      defines the 1st component of the value

    • y: number

      defines the 2nd component of the value

    • z: number

      defines the 3rd component of the value

    Returns void

setFloat4

  • setFloat4(uniform: Nullable<WebGLUniformLocation>, x: number, y: number, z: number, w: number): void
  • Set the value of an uniform to a vec4

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • x: number

      defines the 1st component of the value

    • y: number

      defines the 2nd component of the value

    • z: number

      defines the 3rd component of the value

    • w: number

      defines the 4th component of the value

    Returns void

setFloatArray

  • setFloatArray(uniform: Nullable<WebGLUniformLocation>, array: Float32Array): void
  • Set the value of an uniform to an array of float32

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: Float32Array

      defines the array of float32 to store

    Returns void

setFloatArray2

  • setFloatArray2(uniform: Nullable<WebGLUniformLocation>, array: Float32Array): void
  • Set the value of an uniform to an array of float32 (stored as vec2)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: Float32Array

      defines the array of float32 to store

    Returns void

setFloatArray3

  • setFloatArray3(uniform: Nullable<WebGLUniformLocation>, array: Float32Array): void
  • Set the value of an uniform to an array of float32 (stored as vec3)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: Float32Array

      defines the array of float32 to store

    Returns void

setFloatArray4

  • setFloatArray4(uniform: Nullable<WebGLUniformLocation>, array: Float32Array): void
  • Set the value of an uniform to an array of float32 (stored as vec4)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: Float32Array

      defines the array of float32 to store

    Returns void

setFrameBufferDepthStencilTexture

  • Sets the frame buffer Depth / Stencil attachement of the render target to the defined depth stencil texture.

    Parameters

    Returns void

setHardwareScalingLevel

  • setHardwareScalingLevel(level: number): void
  • Defines the hardware scaling level. By default the hardware scaling level is computed from the window device ratio. 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.

    Parameters

    • level: number

      defines the level to use

    Returns void

setInt

  • setInt(uniform: Nullable<WebGLUniformLocation>, value: number): void
  • Set the value of an uniform to a number (int)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • value: number

      defines the int number to store

    Returns void

setIntArray

  • setIntArray(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): void
  • Set the value of an uniform to an array of int32

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: Int32Array

      defines the array of int32 to store

    Returns void

setIntArray2

  • setIntArray2(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): void
  • Set the value of an uniform to an array of int32 (stored as vec2)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: Int32Array

      defines the array of int32 to store

    Returns void

setIntArray3

  • setIntArray3(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): void
  • Set the value of an uniform to an array of int32 (stored as vec3)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: Int32Array

      defines the array of int32 to store

    Returns void

setIntArray4

  • setIntArray4(uniform: Nullable<WebGLUniformLocation>, array: Int32Array): void
  • Set the value of an uniform to an array of int32 (stored as vec4)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • array: Int32Array

      defines the array of int32 to store

    Returns void

setMatrices

  • setMatrices(uniform: Nullable<WebGLUniformLocation>, matrices: Float32Array): void
  • Set the value of an uniform to an array of float32 (stored as matrices)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • matrices: Float32Array

      defines the array of float32 to store

    Returns void

setMatrix

  • setMatrix(uniform: Nullable<WebGLUniformLocation>, matrix: Matrix): void
  • Set the value of an uniform to a matrix

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • matrix: Matrix

      defines the matrix to store

    Returns void

setMatrix2x2

  • setMatrix2x2(uniform: Nullable<WebGLUniformLocation>, matrix: Float32Array): void
  • Set the value of an uniform to a matrix (2x2)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • matrix: Float32Array

      defines the Float32Array representing the 2x2 matrix to store

    Returns void

setMatrix3x3

  • setMatrix3x3(uniform: Nullable<WebGLUniformLocation>, matrix: Float32Array): void
  • Set the value of an uniform to a matrix (3x3)

    Parameters

    • uniform: Nullable<WebGLUniformLocation>

      defines the webGL uniform location where to store the value

    • matrix: Float32Array

      defines the Float32Array representing the 3x3 matrix to store

    Returns void

setRasterizerState

  • setRasterizerState(value: boolean): void
  • Sets a boolean indicating if the rasterizer state is enabled or disabled

    Parameters

    • value: boolean

      defines the rasterizer state

    Returns void

setSize

  • setSize(width: number, height: number): void
  • Force a specific size of the canvas

    Parameters

    • width: number

      defines the new canvas' width

    • height: number

      defines the new canvas' height

    Returns void

setState

  • setState(culling: boolean, zOffset?: number, force?: boolean, reverseSide?: boolean): void
  • Set various states to the webGL context

    Parameters

    • culling: boolean

      defines backface culling state

    • Optional zOffset: number

      defines the value to apply to zOffset (0 by default)

    • Optional force: boolean

      defines if states must be applied even if cache is up to date

    • Optional reverseSide: boolean

      defines if culling must be reversed (CCW instead of CW and CW instead of CCW)

    Returns void

setStencilBuffer

  • setStencilBuffer(enable: boolean): void
  • Enable or disable the stencil buffer

    Parameters

    • enable: boolean

      defines if the stencil buffer must be enabled or disabled

    Returns void

setStencilFunction

  • setStencilFunction(stencilFunc: number): void
  • Sets the current stencil function

    Parameters

    • stencilFunc: number

      defines the new stencil function to use

    Returns void

setStencilFunctionMask

  • setStencilFunctionMask(mask: number): void
  • Sets the current stencil mask

    Parameters

    • mask: number

      defines the new stencil mask to use

    Returns void

setStencilFunctionReference

  • setStencilFunctionReference(reference: number): void
  • Sets the current stencil reference

    Parameters

    • reference: number

      defines the new stencil reference to use

    Returns void

setStencilMask

  • setStencilMask(mask: number): void
  • Sets the current stencil mask

    Parameters

    • mask: number

      defines the new stencil mask to use

    Returns void

setStencilOperationDepthFail

  • setStencilOperationDepthFail(operation: number): void
  • Sets the stencil operation to use when depth fails

    Parameters

    • operation: number

      defines the stencil operation to use when depth fails

    Returns void

setStencilOperationFail

  • setStencilOperationFail(operation: number): void
  • Sets the stencil operation to use when stencil fails

    Parameters

    • operation: number

      defines the stencil operation to use when stencil fails

    Returns void

setStencilOperationPass

  • setStencilOperationPass(operation: number): void
  • Sets the stencil operation to use when stencil passes

    Parameters

    • operation: number

      defines the stencil operation to use when stencil passes

    Returns void

setTexture

  • Sets a texture to the according uniform.

    Parameters

    • channel: number

      The texture channel

    • uniform: Nullable<WebGLUniformLocation>

      The uniform to set

    • texture: Nullable<BaseTexture>

      The texture to apply

    Returns void

setTextureArray

  • setTextureArray(channel: number, uniform: Nullable<WebGLUniformLocation>, textures: BaseTexture[]): void
  • Sets an array of texture to the webGL context

    Parameters

    • channel: number

      defines the channel where the texture array must be set

    • uniform: Nullable<WebGLUniformLocation>

      defines the associated uniform location

    • textures: BaseTexture[]

      defines the array of textures to bind

    Returns void

setTextureFormatToUse

  • setTextureFormatToUse(formatsAvailable: Array<string>): Nullable<string>
  • Set the compressed texture format to use, based on the formats you have, and the formats supported by the hardware / browser.

    Khronos Texture Container (.ktx) files are used to support this. This format has the advantage of being specifically designed for OpenGL. Header elements directly correspond to API arguments needed to compressed textures. This puts the burden on the container generator to house the arcane code for determining these for current & future formats.

    for description see https://www.khronos.org/opengles/sdk/tools/KTX/ for file layout see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/

    Note: The result of this call is not taken into account when a texture is base64.

    Parameters

    • formatsAvailable: Array<string>

      defines the list of those format families you have created on your server. Syntax: '-' + format family + '.ktx'. (Case and order do not matter.)

      Current families are astc, dxt, pvrtc, etc2, & etc1.

    Returns Nullable<string>

    The extension selected.

setTextureFromPostProcess

  • Sets a texture to the webGL context from a postprocess

    Parameters

    • channel: number

      defines the channel to use

    • postProcess: Nullable<PostProcess>

      defines the source postprocess

    Returns void

setTextureFromPostProcessOutput

  • Binds the output of the passed in post process to the texture channel specified

    Parameters

    • channel: number

      The channel the texture should be bound to

    • postProcess: Nullable<PostProcess>

      The post process which's output should be bound

    Returns void

setTranformFeedbackVaryings

  • setTranformFeedbackVaryings(program: WebGLProgram, value: string[]): void
  • Specify the varyings to use with transform feedback

    Parameters

    • program: WebGLProgram

      defines the associated webGL program

    • value: string[]

      defines the list of strings representing the varying names

    Returns void

setViewport

  • setViewport(viewport: Viewport, requiredWidth?: number, requiredHeight?: number): void
  • Set the WebGL's viewport

    Parameters

    • viewport: Viewport

      defines the viewport element to be used

    • Optional requiredWidth: number

      defines the width required for rendering. If not provided the rendering canvas' width is used

    • Optional requiredHeight: number

      defines the height required for rendering. If not provided the rendering canvas' height is used

    Returns void

setZOffset

  • setZOffset(value: number): void
  • Set the z offset to apply to current rendering

    Parameters

    • value: number

      defines the offset to apply

    Returns void

startTimeQuery

  • startTimeQuery(): Nullable<_TimeToken>
  • Starts a time query (used to measure time spent by the GPU on a specific frame) Please note that only one query can be issued at a time

    Returns Nullable<_TimeToken>

    a time token used to track the time span

stopRenderLoop

  • stopRenderLoop(renderFunction?: function): void
  • stop executing a render loop function and remove it from the execution array

    Parameters

    • Optional renderFunction: function

      defines the function to be removed. If not provided all functions will be removed.

        • (): void
        • Returns void

    Returns void

switchFullscreen

  • switchFullscreen(requestPointerLock: boolean): void
  • Toggle full screen mode

    Parameters

    • requestPointerLock: boolean

      defines if a pointer lock should be requested from the user

    Returns void

unBindFramebuffer

  • unBindFramebuffer(texture: InternalTexture, disableGenerateMipMaps?: boolean, onBeforeUnbind?: function): void
  • Unbind the current render target texture from the webGL context

    Parameters

    • texture: InternalTexture

      defines the render target texture to unbind

    • Optional disableGenerateMipMaps: boolean

      defines a boolean indicating that mipmaps must not be generated

    • Optional onBeforeUnbind: function

      defines a function which will be called before the effective unbind

        • (): void
        • Returns void

    Returns void

unBindMultiColorAttachmentFramebuffer

  • unBindMultiColorAttachmentFramebuffer(textures: InternalTexture[], disableGenerateMipMaps?: boolean, onBeforeUnbind?: function): void
  • Unbind a list of render target textures from the webGL context This is used only when drawBuffer extension or webGL2 are active

    Parameters

    • textures: InternalTexture[]

      defines the render target textures to unbind

    • Optional disableGenerateMipMaps: boolean

      defines a boolean indicating that mipmaps must not be generated

    • Optional onBeforeUnbind: function

      defines a function which will be called before the effective unbind

        • (): void
        • Returns void

    Returns void

unbindAllAttributes

  • unbindAllAttributes(): void
  • Unbind all vertex attributes from the webGL context

    Returns void

unbindAllTextures

  • unbindAllTextures(): void
  • Unbind all textures from the webGL context

    Returns void

unbindInstanceAttributes

  • unbindInstanceAttributes(): void
  • Unbind all instance attributes

    Returns void

updateAndBindInstancesBuffer

  • updateAndBindInstancesBuffer(instancesBuffer: WebGLBuffer, data: Float32Array, offsetLocations: number[] | InstancingAttributeInfo[]): void
  • Update the content of a webGL buffer used with instanciation and bind it to the webGL context

    Parameters

    • instancesBuffer: WebGLBuffer

      defines the webGL buffer to update and bind

    • data: Float32Array

      defines the data to store in the buffer

    • offsetLocations: number[] | InstancingAttributeInfo[]

      defines the offsets or attributes information used to determine where data must be stored in the buffer

    Returns void

updateArrayBuffer

  • updateArrayBuffer(data: Float32Array): void
  • update the bound buffer with the given data

    Parameters

    • data: Float32Array

      defines the data to update

    Returns void

updateDynamicIndexBuffer

  • updateDynamicIndexBuffer(indexBuffer: WebGLBuffer, indices: IndicesArray, offset?: number): void
  • Update a dynamic index buffer

    Parameters

    • indexBuffer: WebGLBuffer

      defines the target index buffer

    • indices: IndicesArray

      defines the data to update

    • Optional offset: number

      defines the offset in the target index buffer where update should start

    Returns void

updateDynamicTexture

  • updateDynamicTexture(texture: Nullable<InternalTexture>, canvas: HTMLCanvasElement, invertY: boolean, premulAlpha?: boolean, format?: number): void
  • Update the content of a dynamic texture

    Parameters

    • texture: Nullable<InternalTexture>

      defines the texture to update

    • canvas: HTMLCanvasElement

      defines the canvas containing the source

    • invertY: boolean

      defines if data must be stored with Y axis inverted

    • Optional premulAlpha: boolean

      defines if alpha is stored as premultiplied

    • Optional format: number

      defines the format of the data

    Returns void

updateDynamicVertexBuffer

  • updateDynamicVertexBuffer(vertexBuffer: WebGLBuffer, data: DataArray, byteOffset?: number, byteLength?: number): void
  • Updates a dynamic vertex buffer.

    Parameters

    • vertexBuffer: WebGLBuffer

      the vertex buffer to update

    • data: DataArray

      the data used to update the vertex buffer

    • Optional byteOffset: number

      the byte offset of the data

    • Optional byteLength: number

      the byte length of the data

    Returns void

updateMultipleRenderTargetTextureSampleCount

updateRawCubeTexture

  • updateRawCubeTexture(texture: InternalTexture, data: ArrayBufferView[], format: number, type: number, invertY: boolean, compression?: Nullable<string>, level?: number): void
  • Update a raw cube texture

    Parameters

    • texture: InternalTexture

      defines the texture to udpdate

    • data: ArrayBufferView[]

      defines the data to store

    • format: number

      defines the data format

    • type: number

      defines the type fo the data (BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT by default)

    • invertY: boolean

      defines if data must be stored with Y axis inverted

    • Optional compression: Nullable<string>

      defines the compression used (null by default)

    • Optional level: number

      defines which level of the texture to update

    Returns void

updateRawTexture

  • Update a raw texture

    Parameters

    • texture: Nullable<InternalTexture>

      defines the texture to update

    • data: Nullable<ArrayBufferView>

      defines the data to store in the texture

    • format: number

      defines the format of the data

    • invertY: boolean

      defines if data must be stored with Y axis inverted

    • Optional compression: Nullable<string>

      defines the compression used (null by default)

    • Optional type: number

      defines the type fo the data (BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT by default)

    Returns void

updateRawTexture3D

  • updateRawTexture3D(texture: InternalTexture, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression?: Nullable<string>, textureType?: number): void
  • Update a raw 3D texture

    Parameters

    • texture: InternalTexture

      defines the texture to update

    • data: Nullable<ArrayBufferView>

      defines the data to store

    • format: number

      defines the data format

    • invertY: boolean

      defines if data must be stored with Y axis inverted

    • Optional compression: Nullable<string>

      defines the used compression (can be null)

    • Optional textureType: number

      defines the texture Type (Engine.TEXTURETYPE_UNSIGNED_INT, Engine.TEXTURETYPE_FLOAT...)

    Returns void

updateRenderTargetTextureSampleCount

updateTextureComparisonFunction

  • updateTextureComparisonFunction(texture: InternalTexture, comparisonFunction: number): void
  • Updates a depth texture Comparison Mode and Function. If the comparison Function is equal to 0, the mode will be set to none. Otherwise, this only works in webgl 2 and requires a shadow sampler in the shader.

    Parameters

    • texture: InternalTexture

      The texture to set the comparison function for

    • comparisonFunction: number

      The comparison function to set, 0 if no comparison required

    Returns void

updateTextureSamplingMode

  • updateTextureSamplingMode(samplingMode: number, texture: InternalTexture): void
  • Update the sampling mode of a given texture

    Parameters

    • samplingMode: number

      defines the required sampling mode

    • texture: InternalTexture

      defines the texture to update

    Returns void

updateUniformBuffer

  • updateUniformBuffer(uniformBuffer: WebGLBuffer, elements: FloatArray, offset?: number, count?: number): void
  • Parameters

    • uniformBuffer: WebGLBuffer

      defines the target uniform buffer

    • elements: FloatArray

      defines the content to update

    • Optional offset: number

      defines the offset in the uniform buffer where update should start

    • Optional count: number

      defines the size of the data to update

    Returns void

updateVideoTexture

  • Update a video texture

    Parameters

    • texture: Nullable<InternalTexture>

      defines the texture to update

    • video: HTMLVideoElement

      defines the video element to use

    • invertY: boolean

      defines if data must be stored with Y axis inverted

    Returns void

wipeCaches

  • wipeCaches(bruteForce?: boolean): void
  • Force the entire cache to be cleared You should not have to use this function unless your engine needs to share the webGL context with another engine

    Parameters

    • Optional bruteForce: boolean

      defines a boolean to force clearing ALL caches (including stencil, detoh and alpha states)

    Returns void

Static MarkAllMaterialsAsDirty

  • MarkAllMaterialsAsDirty(flag: number, predicate?: function): void
  • Will flag all materials in all scenes in all engines as dirty to trigger new shader compilation

    Parameters

    • flag: number

      defines which part of the materials must be marked as dirty

    • Optional predicate: function

      defines a predicate used to filter which materials should be affected

    Returns void

Static isSupported

  • isSupported(): boolean
  • Gets a boolean indicating if the engine can be instanciated (ie. if a webGL context can be found)

    ignorenaming

    Returns boolean

    true if the engine can be created

Generated using TypeDoc