123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872 |
- import { Logger } from "../Misc/logger";
- import { Nullable, FloatArray, IndicesArray } from "../types";
- import { Engine } from "../Engines/engine";
- import { RenderTargetCreationOptions } from "../Materials/Textures/renderTargetCreationOptions";
- import { VertexBuffer } from "../Meshes/buffer";
- import { InternalTexture, InternalTextureSource } from "../Materials/Textures/internalTexture";
- import { Effect } from "../Materials/effect";
- import { Constants } from "./constants";
- import { IPipelineContext } from './IPipelineContext';
- import { DataBuffer } from '../Meshes/dataBuffer';
- import { IColor4Like, IViewportLike } from '../Maths/math.like';
- import { ISceneLike } from './thinEngine';
- import { PerformanceConfigurator } from './performanceConfigurator';
- declare const global: any;
- /**
- * Options to create the null engine
- */
- export class NullEngineOptions {
- /**
- * Render width (Default: 512)
- */
- public renderWidth = 512;
- /**
- * Render height (Default: 256)
- */
- public renderHeight = 256;
- /**
- * Texture size (Default: 512)
- */
- public textureSize = 512;
- /**
- * If delta time between frames should be constant
- * @see https://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
- */
- public deterministicLockstep = false;
- /**
- * Maximum about of steps between frames (Default: 4)
- * @see https://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
- */
- public lockstepMaxSteps = 4;
- /**
- * Make the matrix computations to be performed in 64 bits instead of 32 bits. False by default
- */
- useHighPrecisionMatrix?: boolean;
- }
- /**
- * The null engine class provides support for headless version of babylon.js.
- * This can be used in server side scenario or for testing purposes
- */
- export class NullEngine extends Engine {
- private _options: NullEngineOptions;
- /**
- * Gets a boolean indicating that the engine is running in deterministic lock step mode
- * @see https://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
- * @returns true if engine is in deterministic lock step mode
- */
- public isDeterministicLockStep(): boolean {
- return this._options.deterministicLockstep;
- }
- /**
- * Gets the max steps when engine is running in deterministic lock step
- * @see https://doc.babylonjs.com/babylon101/animations#deterministic-lockstep
- * @returns the max steps
- */
- public getLockstepMaxSteps(): number {
- return this._options.lockstepMaxSteps;
- }
- /**
- * 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 a number indicating the current hardware scaling level
- */
- public getHardwareScalingLevel(): number {
- return 1.0;
- }
- public constructor(options: NullEngineOptions = new NullEngineOptions()) {
- super(null);
- Engine.Instances.push(this);
- if (options.deterministicLockstep === undefined) {
- options.deterministicLockstep = false;
- }
- if (options.lockstepMaxSteps === undefined) {
- options.lockstepMaxSteps = 4;
- }
- this._options = options;
- PerformanceConfigurator.SetMatrixPrecision(!!options.useHighPrecisionMatrix);
- // Init caps
- // We consider we are on a webgl1 capable device
- this._caps = {
- maxTexturesImageUnits: 16,
- maxVertexTextureImageUnits: 16,
- maxCombinedTexturesImageUnits: 32,
- maxTextureSize: 512,
- maxCubemapTextureSize: 512,
- maxRenderTextureSize: 512,
- maxVertexAttribs: 16,
- maxVaryingVectors: 16,
- maxFragmentUniformVectors: 16,
- maxVertexUniformVectors: 16,
- standardDerivatives: false,
- astc: null,
- pvrtc: null,
- etc1: null,
- etc2: null,
- bptc: null,
- maxAnisotropy: 0,
- uintIndices: false,
- fragmentDepthSupported: false,
- highPrecisionShaderSupported: true,
- colorBufferFloat: false,
- textureFloat: false,
- textureFloatLinearFiltering: false,
- textureFloatRender: false,
- textureHalfFloat: false,
- textureHalfFloatLinearFiltering: false,
- textureHalfFloatRender: false,
- textureLOD: false,
- drawBuffersExtension: false,
- depthTextureExtension: false,
- vertexArrayObject: false,
- instancedArrays: false,
- canUseTimestampForTimerQuery: false,
- maxMSAASamples: 1,
- blendMinMax: false,
- canUseGLInstanceID: false,
- };
- this._features = {
- forceBitmapOverHTMLImageElement: false,
- supportRenderAndCopyToLodForFloatTextures: false,
- supportDepthStencilTexture: false,
- supportShadowSamplers: false,
- uniformBufferHardCheckMatrix: false,
- allowTexturePrefiltering: false,
- trackUbosInFrame: false,
- supportCSM: false,
- basisNeedsPOT: false,
- support3DTextures: false,
- needTypeSuffixInShaderConstants: false,
- supportMSAA: false,
- supportSSAO2: false,
- supportExtendedTextureFormats: false,
- supportSwitchCaseInShader: false,
- supportSyncTextureRead: false,
- _collectUbosUpdatedInFrame: false,
- };
- Logger.Log(`Babylon.js v${Engine.Version} - Null engine`);
- // Wrappers
- const theCurrentGlobal = (typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : window);
- if (typeof URL === "undefined") {
- theCurrentGlobal.URL = {
- createObjectURL: function() { },
- revokeObjectURL: function() { }
- };
- }
- if (typeof Blob === "undefined") {
- theCurrentGlobal.Blob = function() { };
- }
- }
- /**
- * Creates a vertex buffer
- * @param vertices the data for the vertex buffer
- * @returns the new WebGL static buffer
- */
- public createVertexBuffer(vertices: FloatArray): DataBuffer {
- let buffer = new DataBuffer();
- buffer.references = 1;
- return buffer;
- }
- /**
- * Creates a new index buffer
- * @param indices defines the content of the index buffer
- * @param updatable defines if the index buffer must be updatable
- * @returns a new webGL buffer
- */
- public createIndexBuffer(indices: IndicesArray): DataBuffer {
- let buffer = new DataBuffer();
- buffer.references = 1;
- return buffer;
- }
- /**
- * Clear the current render buffer or the current render target (if any is set up)
- * @param color defines the color to use
- * @param backBuffer defines if the back buffer must be cleared
- * @param depth defines if the depth buffer must be cleared
- * @param stencil defines if the stencil buffer must be cleared
- */
- public clear(color: IColor4Like, backBuffer: boolean, depth: boolean, stencil: boolean = false): void {
- }
- /**
- * Gets the current render width
- * @param useScreen defines if screen size must be used (or the current render target if any)
- * @returns a number defining the current render width
- */
- public getRenderWidth(useScreen = false): number {
- if (!useScreen && this._currentRenderTarget) {
- return this._currentRenderTarget.width;
- }
- return this._options.renderWidth;
- }
- /**
- * Gets the current render height
- * @param useScreen defines if screen size must be used (or the current render target if any)
- * @returns a number defining the current render height
- */
- public getRenderHeight(useScreen = false): number {
- if (!useScreen && this._currentRenderTarget) {
- return this._currentRenderTarget.height;
- }
- return this._options.renderHeight;
- }
- /**
- * Set the WebGL's viewport
- * @param viewport defines the viewport element to be used
- * @param requiredWidth defines the width required for rendering. If not provided the rendering canvas' width is used
- * @param requiredHeight defines the height required for rendering. If not provided the rendering canvas' height is used
- */
- public setViewport(viewport: IViewportLike, requiredWidth?: number, requiredHeight?: number): void {
- this._cachedViewport = viewport;
- }
- public createShaderProgram(pipelineContext: IPipelineContext, vertexCode: string, fragmentCode: string, defines: string, context?: WebGLRenderingContext): WebGLProgram {
- return {
- __SPECTOR_rebuildProgram: null,
- };
- }
- /**
- * Gets the list of webGL uniform locations associated with a specific program based on a list of uniform names
- * @param pipelineContext defines the pipeline context to use
- * @param uniformsNames defines the list of uniform names
- * @returns an array of webGL uniform locations
- */
- public getUniforms(pipelineContext: IPipelineContext, uniformsNames: string[]): Nullable<WebGLUniformLocation>[] {
- return [];
- }
- /**
- * Gets the lsit of active attributes for a given webGL program
- * @param pipelineContext defines the pipeline context to use
- * @param attributesNames defines the list of attribute names to get
- * @returns an array of indices indicating the offset of each attribute
- */
- public getAttributes(pipelineContext: IPipelineContext, attributesNames: string[]): number[] {
- return [];
- }
- /**
- * Binds an effect to the webGL context
- * @param effect defines the effect to bind
- */
- public bindSamplers(effect: Effect): void {
- this._currentEffect = null;
- }
- /**
- * Activates an effect, mkaing it the current one (ie. the one used for rendering)
- * @param effect defines the effect to activate
- */
- public enableEffect(effect: Effect): void {
- this._currentEffect = effect;
- if (effect.onBind) {
- effect.onBind(effect);
- }
- if (effect._onBindObservable) {
- effect._onBindObservable.notifyObservers(effect);
- }
- }
- /**
- * Set various states to the webGL context
- * @param culling defines backface culling state
- * @param zOffset defines the value to apply to zOffset (0 by default)
- * @param force defines if states must be applied even if cache is up to date
- * @param reverseSide defines if culling must be reversed (CCW instead of CW and CW instead of CCW)
- */
- public setState(culling: boolean, zOffset: number = 0, force?: boolean, reverseSide = false): void {
- }
- /**
- * Set the value of an uniform to an array of int32
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of int32 to store
- * @returns true if value was set
- */
- public setIntArray(uniform: WebGLUniformLocation, array: Int32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of int32 (stored as vec2)
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of int32 to store
- * @returns true if value was set
- */
- public setIntArray2(uniform: WebGLUniformLocation, array: Int32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of int32 (stored as vec3)
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of int32 to store
- * @returns true if value was set
- */
- public setIntArray3(uniform: WebGLUniformLocation, array: Int32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of int32 (stored as vec4)
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of int32 to store
- * @returns true if value was set
- */
- public setIntArray4(uniform: WebGLUniformLocation, array: Int32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of float32
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of float32 to store
- * @returns true if value was set
- */
- public setFloatArray(uniform: WebGLUniformLocation, array: Float32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of float32 (stored as vec2)
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of float32 to store
- * @returns true if value was set
- */
- public setFloatArray2(uniform: WebGLUniformLocation, array: Float32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of float32 (stored as vec3)
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of float32 to store
- * @returns true if value was set
- */
- public setFloatArray3(uniform: WebGLUniformLocation, array: Float32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of float32 (stored as vec4)
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of float32 to store
- * @returns true if value was set
- */
- public setFloatArray4(uniform: WebGLUniformLocation, array: Float32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of number
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of number to store
- * @returns true if value was set
- */
- public setArray(uniform: WebGLUniformLocation, array: number[]): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of number (stored as vec2)
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of number to store
- * @returns true if value was set
- */
- public setArray2(uniform: WebGLUniformLocation, array: number[]): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of number (stored as vec3)
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of number to store
- * @returns true if value was set
- */
- public setArray3(uniform: WebGLUniformLocation, array: number[]): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of number (stored as vec4)
- * @param uniform defines the webGL uniform location where to store the value
- * @param array defines the array of number to store
- * @returns true if value was set
- */
- public setArray4(uniform: WebGLUniformLocation, array: number[]): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to an array of float32 (stored as matrices)
- * @param uniform defines the webGL uniform location where to store the value
- * @param matrices defines the array of float32 to store
- * @returns true if value was set
- */
- public setMatrices(uniform: WebGLUniformLocation, matrices: Float32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to a matrix (3x3)
- * @param uniform defines the webGL uniform location where to store the value
- * @param matrix defines the Float32Array representing the 3x3 matrix to store
- * @returns true if value was set
- */
- public setMatrix3x3(uniform: WebGLUniformLocation, matrix: Float32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to a matrix (2x2)
- * @param uniform defines the webGL uniform location where to store the value
- * @param matrix defines the Float32Array representing the 2x2 matrix to store
- * @returns true if value was set
- */
- public setMatrix2x2(uniform: WebGLUniformLocation, matrix: Float32Array): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to a number (float)
- * @param uniform defines the webGL uniform location where to store the value
- * @param value defines the float number to store
- * @returns true if value was set
- */
- public setFloat(uniform: WebGLUniformLocation, value: number): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to a vec2
- * @param uniform defines the webGL uniform location where to store the value
- * @param x defines the 1st component of the value
- * @param y defines the 2nd component of the value
- * @returns true if value was set
- */
- public setFloat2(uniform: WebGLUniformLocation, x: number, y: number): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to a vec3
- * @param uniform defines the webGL uniform location where to store the value
- * @param x defines the 1st component of the value
- * @param y defines the 2nd component of the value
- * @param z defines the 3rd component of the value
- * @returns true if value was set
- */
- public setFloat3(uniform: WebGLUniformLocation, x: number, y: number, z: number): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to a boolean
- * @param uniform defines the webGL uniform location where to store the value
- * @param bool defines the boolean to store
- * @returns true if value was set
- */
- public setBool(uniform: WebGLUniformLocation, bool: number): boolean {
- return true;
- }
- /**
- * Set the value of an uniform to a vec4
- * @param uniform defines the webGL uniform location where to store the value
- * @param x defines the 1st component of the value
- * @param y defines the 2nd component of the value
- * @param z defines the 3rd component of the value
- * @param w defines the 4th component of the value
- * @returns true if value was set
- */
- public setFloat4(uniform: WebGLUniformLocation, x: number, y: number, z: number, w: number): boolean {
- return true;
- }
- /**
- * Sets the current alpha mode
- * @param mode defines the mode to use (one of the Engine.ALPHA_XXX)
- * @param noDepthWriteChange defines if depth writing state should remains unchanged (false by default)
- * @see https://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered
- */
- public setAlphaMode(mode: number, noDepthWriteChange: boolean = false): void {
- if (this._alphaMode === mode) {
- return;
- }
- this.alphaState.alphaBlend = (mode !== Constants.ALPHA_DISABLE);
- if (!noDepthWriteChange) {
- this.setDepthWrite(mode === Constants.ALPHA_DISABLE);
- }
- this._alphaMode = mode;
- }
- /**
- * Bind webGl buffers directly to the webGL context
- * @param vertexBuffers defines the vertex buffer to bind
- * @param indexBuffer defines the index buffer to bind
- * @param vertexDeclaration defines the vertex declaration to use with the vertex buffer
- * @param vertexStrideSize defines the vertex stride of the vertex buffer
- * @param effect defines the effect associated with the vertex buffer
- */
- public bindBuffers(vertexBuffers: { [key: string]: VertexBuffer; }, indexBuffer: DataBuffer, effect: Effect): 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
- * @param bruteForce defines a boolean to force clearing ALL caches (including stencil, detoh and alpha states)
- */
- public wipeCaches(bruteForce?: boolean): void {
- if (this.preventCacheWipeBetweenFrames) {
- return;
- }
- this.resetTextureCache();
- this._currentEffect = null;
- if (bruteForce) {
- this._currentProgram = null;
- this.stencilState.reset();
- this.depthCullingState.reset();
- this.alphaState.reset();
- }
- this._cachedVertexBuffers = null;
- this._cachedIndexBuffer = null;
- this._cachedEffectForVertexBuffers = null;
- }
- /**
- * Send a draw order
- * @param useTriangles defines if triangles must be used to draw (else wireframe will be used)
- * @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 instanciation is enabled)
- */
- public draw(useTriangles: boolean, indexStart: number, indexCount: number, instancesCount?: number): void {
- }
- /**
- * 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 instanciation is enabled)
- */
- public 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 instanciation is enabled)
- */
- public drawArraysType(fillMode: number, verticesStart: number, verticesCount: number, instancesCount?: number): void {
- }
- /** @hidden */
- protected _createTexture(): WebGLTexture {
- return {};
- }
- /** @hidden */
- public _releaseTexture(texture: InternalTexture): void {
- }
- /**
- * Usually called from Texture.ts.
- * Passed information to create a WebGLTexture
- * @param urlArg 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
- * @returns a InternalTexture for assignment back into BABYLON.Texture
- */
- public createTexture(urlArg: Nullable<string>, noMipmap: boolean, invertY: boolean, scene: Nullable<ISceneLike>, samplingMode: number = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,
- onLoad: Nullable<() => void> = null, onError: Nullable<(message: string, exception: any) => void> = null,
- buffer: Nullable<string | ArrayBuffer | ArrayBufferView | HTMLImageElement | Blob | ImageBitmap> = null, fallback: Nullable<InternalTexture> = null, format: Nullable<number> = null,
- forcedExtension: Nullable<string> = null, mimeType?: string): InternalTexture {
- var texture = new InternalTexture(this, InternalTextureSource.Url);
- var url = String(urlArg);
- texture.url = url;
- texture.generateMipMaps = !noMipmap;
- texture.samplingMode = samplingMode;
- texture.invertY = invertY;
- texture.baseWidth = this._options.textureSize;
- texture.baseHeight = this._options.textureSize;
- texture.width = this._options.textureSize;
- texture.height = this._options.textureSize;
- if (format) {
- texture.format = format;
- }
- texture.isReady = true;
- if (onLoad) {
- onLoad();
- }
- this._internalTexturesCache.push(texture);
- return texture;
- }
- /**
- * Creates a new render target texture
- * @param size defines the size of the texture
- * @param options defines the options used to create the texture
- * @returns a new render target texture stored in an InternalTexture
- */
- public createRenderTargetTexture(size: any, options: boolean | RenderTargetCreationOptions): InternalTexture {
- let fullOptions = new RenderTargetCreationOptions();
- if (options !== undefined && typeof options === "object") {
- fullOptions.generateMipMaps = options.generateMipMaps;
- fullOptions.generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
- fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && options.generateStencilBuffer;
- fullOptions.type = options.type === undefined ? Constants.TEXTURETYPE_UNSIGNED_INT : options.type;
- fullOptions.samplingMode = options.samplingMode === undefined ? Constants.TEXTURE_TRILINEAR_SAMPLINGMODE : options.samplingMode;
- } else {
- fullOptions.generateMipMaps = <boolean>options;
- fullOptions.generateDepthBuffer = true;
- fullOptions.generateStencilBuffer = false;
- fullOptions.type = Constants.TEXTURETYPE_UNSIGNED_INT;
- fullOptions.samplingMode = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;
- }
- var texture = new InternalTexture(this, InternalTextureSource.RenderTarget);
- var width = size.width || size;
- var height = size.height || size;
- texture._depthStencilBuffer = {};
- texture._framebuffer = {};
- texture.baseWidth = width;
- texture.baseHeight = height;
- texture.width = width;
- texture.height = height;
- texture.isReady = true;
- texture.samples = 1;
- texture.generateMipMaps = fullOptions.generateMipMaps ? true : false;
- texture.samplingMode = fullOptions.samplingMode;
- texture.type = fullOptions.type;
- texture._generateDepthBuffer = fullOptions.generateDepthBuffer;
- texture._generateStencilBuffer = fullOptions.generateStencilBuffer ? true : false;
- this._internalTexturesCache.push(texture);
- return texture;
- }
- /**
- * Update the sampling mode of a given texture
- * @param samplingMode defines the required sampling mode
- * @param texture defines the texture to update
- */
- public updateTextureSamplingMode(samplingMode: number, texture: InternalTexture): void {
- texture.samplingMode = samplingMode;
- }
- /**
- * Binds the frame buffer to the specified texture.
- * @param texture The texture to render to or null for the default canvas
- * @param faceIndex The face of the texture to render to in case of cube texture
- * @param requiredWidth The width of the target to render to
- * @param requiredHeight The height of the target to render to
- * @param forceFullscreenViewport Forces the viewport to be the entire texture/screen if true
- * @param lodLevel defines le lod level to bind to the frame buffer
- */
- public bindFramebuffer(texture: InternalTexture, faceIndex?: number, requiredWidth?: number, requiredHeight?: number, forceFullscreenViewport?: boolean): void {
- if (this._currentRenderTarget) {
- this.unBindFramebuffer(this._currentRenderTarget);
- }
- this._currentRenderTarget = texture;
- this._currentFramebuffer = texture._MSAAFramebuffer ? texture._MSAAFramebuffer : texture._framebuffer;
- if (this._cachedViewport && !forceFullscreenViewport) {
- this.setViewport(this._cachedViewport, requiredWidth, requiredHeight);
- }
- }
- /**
- * Unbind the current render target texture from the webGL context
- * @param texture defines the render target texture to unbind
- * @param disableGenerateMipMaps defines a boolean indicating that mipmaps must not be generated
- * @param onBeforeUnbind defines a function which will be called before the effective unbind
- */
- public unBindFramebuffer(texture: InternalTexture, disableGenerateMipMaps = false, onBeforeUnbind?: () => void): void {
- this._currentRenderTarget = null;
- if (onBeforeUnbind) {
- if (texture._MSAAFramebuffer) {
- this._currentFramebuffer = texture._framebuffer;
- }
- onBeforeUnbind();
- }
- this._currentFramebuffer = null;
- }
- /**
- * Creates a dynamic vertex buffer
- * @param vertices the data for the dynamic vertex buffer
- * @returns the new WebGL dynamic buffer
- */
- public createDynamicVertexBuffer(vertices: FloatArray): DataBuffer {
- let buffer = new DataBuffer();
- buffer.references = 1;
- buffer.capacity = 1;
- return buffer;
- }
- /**
- * 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
- * @param forceBindTexture if the texture should be forced to be bound eg. after a graphics context loss (Default: false)
- */
- public updateDynamicTexture(texture: Nullable<InternalTexture>, canvas: HTMLCanvasElement, invertY: boolean, premulAlpha: boolean = false, format?: number): void {
- }
- /**
- * Gets a boolean indicating if all created effects are ready
- * @returns true if all effects are ready
- */
- public areAllEffectsReady(): boolean {
- return true;
- }
- /**
- * @hidden
- * Get the current error code of the webGL context
- * @returns the error code
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getError
- */
- public getError(): number {
- return 0;
- }
- /** @hidden */
- public _getUnpackAlignement(): number {
- return 1;
- }
- /** @hidden */
- public _unpackFlipY(value: boolean) {
- }
- /**
- * Update a dynamic index buffer
- * @param indexBuffer defines the target index buffer
- * @param indices defines the data to update
- * @param offset defines the offset in the target index buffer where update should start
- */
- public updateDynamicIndexBuffer(indexBuffer: WebGLBuffer, indices: IndicesArray, offset: number = 0): void {
- }
- /**
- * Updates a dynamic vertex buffer.
- * @param vertexBuffer the vertex buffer to update
- * @param vertices the data used to update the vertex buffer
- * @param byteOffset the byte offset of the data (optional)
- * @param byteLength the byte length of the data (optional)
- */
- public updateDynamicVertexBuffer(vertexBuffer: WebGLBuffer, vertices: FloatArray, byteOffset?: number, byteLength?: number): void {
- }
- /** @hidden */
- public _bindTextureDirectly(target: number, texture: InternalTexture): boolean {
- if (this._boundTexturesCache[this._activeChannel] !== texture) {
- this._boundTexturesCache[this._activeChannel] = texture;
- return true;
- }
- return false;
- }
- /** @hidden */
- public _bindTexture(channel: number, texture: InternalTexture): void {
- if (channel < 0) {
- return;
- }
- this._bindTextureDirectly(0, texture);
- }
- protected _deleteBuffer(buffer: WebGLBuffer): 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
- */
- public releaseEffects() {
- }
- public displayLoadingUI(): void {
- }
- public hideLoadingUI(): void {
- }
- /** @hidden */
- public _uploadCompressedDataToTextureDirectly(texture: InternalTexture, internalFormat: number, width: number, height: number, data: ArrayBufferView, faceIndex: number = 0, lod: number = 0) {
- }
- /** @hidden */
- public _uploadDataToTextureDirectly(texture: InternalTexture, imageData: ArrayBufferView, faceIndex: number = 0, lod: number = 0): void {
- }
- /** @hidden */
- public _uploadArrayBufferViewToTexture(texture: InternalTexture, imageData: ArrayBufferView, faceIndex: number = 0, lod: number = 0): void {
- }
- /** @hidden */
- public _uploadImageToTexture(texture: InternalTexture, image: HTMLImageElement, faceIndex: number = 0, lod: number = 0) {
- }
- }
|