123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881 |
- /* eslint-disable @typescript-eslint/no-unused-vars */
- import { Logger } from "../Misc/logger.js";
- import { Engine } from "../Engines/engine.js";
- import { InternalTexture, InternalTextureSource } from "../Materials/Textures/internalTexture.js";
- import { DataBuffer } from "../Buffers/dataBuffer.js";
- import { PerformanceConfigurator } from "./performanceConfigurator.js";
- import { RenderTargetWrapper } from "./renderTargetWrapper.js";
- import { IsWrapper } from "../Materials/drawWrapper.functions.js";
- /**
- * Options to create the null engine
- */
- export class NullEngineOptions {
- constructor() {
- /**
- * Render width (Default: 512)
- */
- this.renderWidth = 512;
- /**
- * Render height (Default: 256)
- */
- this.renderHeight = 256;
- /**
- * Texture size (Default: 512)
- */
- this.textureSize = 512;
- /**
- * If delta time between frames should be constant
- * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep
- */
- this.deterministicLockstep = false;
- /**
- * Maximum about of steps between frames (Default: 4)
- * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep
- */
- this.lockstepMaxSteps = 4;
- }
- }
- /**
- * 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 {
- /**
- * Gets a boolean indicating that the engine is running in deterministic lock step mode
- * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep
- * @returns true if engine is in deterministic lock step mode
- */
- isDeterministicLockStep() {
- return this._options.deterministicLockstep;
- }
- /**
- * Gets the max steps when engine is running in deterministic lock step
- * @see https://doc.babylonjs.com/features/featuresDeepDive/animation/advanced_animations#deterministic-lockstep
- * @returns the max steps
- */
- getLockstepMaxSteps() {
- 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
- */
- getHardwareScalingLevel() {
- return 1.0;
- }
- constructor(options = new NullEngineOptions()) {
- super(null);
- if (options.deterministicLockstep === undefined) {
- options.deterministicLockstep = false;
- }
- if (options.timeStep !== undefined) {
- this._timeStep = options.timeStep;
- }
- 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,
- supportFloatTexturesResolve: false,
- rg11b10ufColorRenderable: false,
- textureFloat: false,
- textureFloatLinearFiltering: false,
- textureFloatRender: false,
- textureHalfFloat: false,
- textureHalfFloatLinearFiltering: false,
- textureHalfFloatRender: false,
- textureLOD: false,
- texelFetch: false,
- drawBuffersExtension: false,
- depthTextureExtension: false,
- vertexArrayObject: false,
- instancedArrays: false,
- supportOcclusionQuery: false,
- canUseTimestampForTimerQuery: false,
- maxMSAASamples: 1,
- blendMinMax: false,
- canUseGLInstanceID: false,
- canUseGLVertexID: false,
- supportComputeShaders: false,
- supportSRGBBuffers: false,
- supportTransformFeedbacks: false,
- textureMaxLevel: false,
- texture2DArrayMaxLayerCount: 128,
- disableMorphTargetTexture: false,
- };
- this._features = {
- forceBitmapOverHTMLImageElement: false,
- supportRenderAndCopyToLodForFloatTextures: false,
- supportDepthStencilTexture: false,
- supportShadowSamplers: false,
- uniformBufferHardCheckMatrix: false,
- allowTexturePrefiltering: false,
- trackUbosInFrame: false,
- checkUbosContentBeforeUpload: false,
- supportCSM: false,
- basisNeedsPOT: false,
- support3DTextures: false,
- needTypeSuffixInShaderConstants: false,
- supportMSAA: false,
- supportSSAO2: false,
- supportExtendedTextureFormats: false,
- supportSwitchCaseInShader: false,
- supportSyncTextureRead: false,
- needsInvertingBitmap: false,
- useUBOBindingCache: false,
- needShaderCodeInlining: false,
- needToAlwaysBindUniformBuffers: false,
- supportRenderPasses: true,
- supportSpriteInstancing: false,
- forceVertexBufferStrideAndOffsetMultiple4Bytes: 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
- */
- createVertexBuffer(vertices) {
- const buffer = new DataBuffer();
- buffer.references = 1;
- return buffer;
- }
- /**
- * Creates a new index buffer
- * @param indices defines the content of the index buffer
- * @returns a new webGL buffer
- */
- createIndexBuffer(indices) {
- const 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
- */
- clear(color, backBuffer, depth, stencil = false) { }
- /**
- * 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
- */
- getRenderWidth(useScreen = false) {
- 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
- */
- getRenderHeight(useScreen = false) {
- 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
- */
- setViewport(viewport, requiredWidth, requiredHeight) {
- this._cachedViewport = viewport;
- }
- createShaderProgram(pipelineContext, vertexCode, fragmentCode, defines, context) {
- return {
- // eslint-disable-next-line @typescript-eslint/naming-convention
- __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
- */
- getUniforms(pipelineContext, uniformsNames) {
- 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
- */
- getAttributes(pipelineContext, attributesNames) {
- return [];
- }
- /**
- * Binds an effect to the webGL context
- * @param effect defines the effect to bind
- */
- bindSamplers(effect) {
- this._currentEffect = null;
- }
- /**
- * Activates an effect, making it the current one (ie. the one used for rendering)
- * @param effect defines the effect to activate
- */
- enableEffect(effect) {
- effect = effect !== null && IsWrapper(effect) ? effect.effect : effect; // get only the effect, we don't need a Wrapper in the WebGL engine
- this._currentEffect = effect;
- if (!effect) {
- return;
- }
- if (effect.onBind) {
- effect.onBind(effect);
- }
- if (effect._onBindObservable) {
- effect._onBindObservable.notifyObservers(effect);
- }
- }
- /**
- * Set various states to the webGL context
- * @param culling defines culling state: true to enable culling, false to disable it
- * @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 if false, CW if true)
- * @param cullBackFaces true to cull back faces, false to cull front faces (if culling is enabled)
- * @param stencil stencil states to set
- * @param zOffsetUnits defines the value to apply to zOffsetUnits (0 by default)
- */
- setState(culling, zOffset = 0, force, reverseSide = false, cullBackFaces, stencil, zOffsetUnits = 0) { }
- /**
- * 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
- */
- setIntArray(uniform, array) {
- 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
- */
- setIntArray2(uniform, array) {
- 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
- */
- setIntArray3(uniform, array) {
- 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
- */
- setIntArray4(uniform, array) {
- 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
- */
- setFloatArray(uniform, array) {
- 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
- */
- setFloatArray2(uniform, array) {
- 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
- */
- setFloatArray3(uniform, array) {
- 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
- */
- setFloatArray4(uniform, array) {
- 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
- */
- setArray(uniform, array) {
- 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
- */
- setArray2(uniform, array) {
- 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
- */
- setArray3(uniform, array) {
- 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
- */
- setArray4(uniform, array) {
- 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
- */
- setMatrices(uniform, matrices) {
- 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
- */
- setMatrix3x3(uniform, matrix) {
- 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
- */
- setMatrix2x2(uniform, matrix) {
- 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
- */
- setFloat(uniform, value) {
- 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
- */
- setFloat2(uniform, x, y) {
- 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
- */
- setFloat3(uniform, x, y, z) {
- 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
- */
- setBool(uniform, bool) {
- 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
- */
- setFloat4(uniform, x, y, z, w) {
- 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/features/featuresDeepDive/materials/advanced/transparent_rendering
- */
- setAlphaMode(mode, noDepthWriteChange = false) {
- if (this._alphaMode === mode) {
- return;
- }
- this.alphaState.alphaBlend = mode !== 0;
- if (!noDepthWriteChange) {
- this.setDepthWrite(mode === 0);
- }
- 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 effect defines the effect associated with the vertex buffer
- */
- bindBuffers(vertexBuffers, indexBuffer, effect) { }
- /**
- * 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)
- */
- wipeCaches(bruteForce) {
- if (this.preventCacheWipeBetweenFrames) {
- return;
- }
- this.resetTextureCache();
- this._currentEffect = null;
- if (bruteForce) {
- this._currentProgram = null;
- this._stencilStateComposer.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 instantiation is enabled)
- */
- draw(useTriangles, indexStart, indexCount, instancesCount) { }
- /**
- * Draw a list of indexed primitives
- * @param fillMode defines the primitive to use
- * @param indexStart defines the starting index
- * @param indexCount defines the number of index to draw
- * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
- */
- drawElementsType(fillMode, indexStart, indexCount, instancesCount) { }
- /**
- * Draw a list of unindexed primitives
- * @param fillMode defines the primitive to use
- * @param verticesStart defines the index of first vertex to draw
- * @param verticesCount defines the count of vertices to draw
- * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
- */
- drawArraysType(fillMode, verticesStart, verticesCount, instancesCount) { }
- /** @internal */
- _createTexture() {
- return {};
- }
- /**
- * @internal
- */
- _releaseTexture(texture) { }
- /**
- * 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
- */
- createTexture(urlArg, noMipmap, invertY, scene, samplingMode = 3, onLoad = null, onError = null, buffer = null, fallback = null, format = null, forcedExtension = null, mimeType) {
- const texture = new InternalTexture(this, InternalTextureSource.Url);
- const 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) {
- setTimeout(() => {
- onLoad(texture);
- });
- }
- this._internalTexturesCache.push(texture);
- return texture;
- }
- /**
- * @internal
- */
- _createHardwareRenderTargetWrapper(isMulti, isCube, size) {
- const rtWrapper = new RenderTargetWrapper(isMulti, isCube, size, this);
- this._renderTargetWrapperCache.push(rtWrapper);
- return rtWrapper;
- }
- /**
- * Creates a new render target wrapper
- * @param size defines the size of the texture
- * @param options defines the options used to create the texture
- * @returns a new render target wrapper
- */
- createRenderTargetTexture(size, options) {
- const rtWrapper = this._createHardwareRenderTargetWrapper(false, false, size);
- const fullOptions = {};
- 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 ? 0 : options.type;
- fullOptions.samplingMode = options.samplingMode === undefined ? 3 : options.samplingMode;
- }
- else {
- fullOptions.generateMipMaps = options;
- fullOptions.generateDepthBuffer = true;
- fullOptions.generateStencilBuffer = false;
- fullOptions.type = 0;
- fullOptions.samplingMode = 3;
- }
- const texture = new InternalTexture(this, InternalTextureSource.RenderTarget);
- const width = size.width || size;
- const height = size.height || size;
- rtWrapper._generateDepthBuffer = fullOptions.generateDepthBuffer;
- rtWrapper._generateStencilBuffer = fullOptions.generateStencilBuffer ? true : false;
- 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;
- this._internalTexturesCache.push(texture);
- return rtWrapper;
- }
- /**
- * Creates a new render target wrapper
- * @param size defines the size of the texture
- * @param options defines the options used to create the texture
- * @returns a new render target wrapper
- */
- createRenderTargetCubeTexture(size, options) {
- const rtWrapper = this._createHardwareRenderTargetWrapper(false, true, size);
- const fullOptions = {
- generateMipMaps: true,
- generateDepthBuffer: true,
- generateStencilBuffer: false,
- type: 0,
- samplingMode: 3,
- format: 5,
- ...options,
- };
- fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && fullOptions.generateStencilBuffer;
- if (fullOptions.type === 1 && !this._caps.textureFloatLinearFiltering) {
- // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
- fullOptions.samplingMode = 1;
- }
- else if (fullOptions.type === 2 && !this._caps.textureHalfFloatLinearFiltering) {
- // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE
- fullOptions.samplingMode = 1;
- }
- rtWrapper._generateDepthBuffer = fullOptions.generateDepthBuffer;
- rtWrapper._generateStencilBuffer = fullOptions.generateStencilBuffer ? true : false;
- const texture = new InternalTexture(this, InternalTextureSource.RenderTarget);
- texture.baseWidth = size;
- texture.baseHeight = size;
- texture.width = size;
- texture.height = size;
- texture.isReady = true;
- texture.isCube = true;
- texture.samples = 1;
- texture.generateMipMaps = fullOptions.generateMipMaps ? true : false;
- texture.samplingMode = fullOptions.samplingMode;
- texture.type = fullOptions.type;
- this._internalTexturesCache.push(texture);
- return rtWrapper;
- }
- /**
- * Update the sampling mode of a given texture
- * @param samplingMode defines the required sampling mode
- * @param texture defines the texture to update
- */
- updateTextureSamplingMode(samplingMode, texture) {
- texture.samplingMode = samplingMode;
- }
- /**
- * Creates a raw texture
- * @param data defines the data to store in the texture
- * @param width defines the width of the texture
- * @param height defines the height of the texture
- * @param format defines the format of the data
- * @param generateMipMaps defines if the engine should generate the mip levels
- * @param invertY defines if data must be stored with Y axis inverted
- * @param samplingMode defines the required sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
- * @param compression defines the compression used (null by default)
- * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
- * @param creationFlags specific flags to use when creating the texture (1 for storage textures, for eg)
- * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).
- * @returns the raw texture inside an InternalTexture
- */
- createRawTexture(data, width, height, format, generateMipMaps, invertY, samplingMode, compression = null, type = 0, creationFlags = 0, useSRGBBuffer = false) {
- const texture = new InternalTexture(this, InternalTextureSource.Raw);
- texture.baseWidth = width;
- texture.baseHeight = height;
- texture.width = width;
- texture.height = height;
- texture.format = format;
- texture.generateMipMaps = generateMipMaps;
- texture.samplingMode = samplingMode;
- texture.invertY = invertY;
- texture._compression = compression;
- texture.type = type;
- texture._useSRGBBuffer = useSRGBBuffer;
- if (!this._doNotHandleContextLost) {
- texture._bufferView = data;
- }
- return texture;
- }
- /**
- * Update a raw texture
- * @param texture defines the texture to update
- * @param data defines the data to store in the texture
- * @param format defines the format of the data
- * @param invertY defines if data must be stored with Y axis inverted
- * @param compression defines the compression used (null by default)
- * @param type defines the type fo the data (Engine.TEXTURETYPE_UNSIGNED_INT by default)
- * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU).
- */
- updateRawTexture(texture, data, format, invertY, compression = null, type = 0, useSRGBBuffer = false) {
- if (texture) {
- texture._bufferView = data;
- texture.format = format;
- texture.invertY = invertY;
- texture._compression = compression;
- texture.type = type;
- texture._useSRGBBuffer = useSRGBBuffer;
- }
- }
- /**
- * Binds the frame buffer to the specified texture.
- * @param rtWrapper The render target wrapper to render to
- * @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
- */
- bindFramebuffer(rtWrapper, faceIndex, requiredWidth, requiredHeight, forceFullscreenViewport) {
- if (this._currentRenderTarget) {
- this.unBindFramebuffer(this._currentRenderTarget);
- }
- this._currentRenderTarget = rtWrapper;
- this._currentFramebuffer = null;
- if (this._cachedViewport && !forceFullscreenViewport) {
- this.setViewport(this._cachedViewport, requiredWidth, requiredHeight);
- }
- }
- /**
- * Unbind the current render target texture from the webGL context
- * @param rtWrapper defines the render target wrapper 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
- */
- unBindFramebuffer(rtWrapper, disableGenerateMipMaps = false, onBeforeUnbind) {
- this._currentRenderTarget = null;
- if (onBeforeUnbind) {
- onBeforeUnbind();
- }
- this._currentFramebuffer = null;
- }
- /**
- * Creates a dynamic vertex buffer
- * @param vertices the data for the dynamic vertex buffer
- * @returns the new WebGL dynamic buffer
- */
- createDynamicVertexBuffer(vertices) {
- const 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
- */
- updateDynamicTexture(texture, canvas, invertY, premulAlpha = false, format) { }
- /**
- * Gets a boolean indicating if all created effects are ready
- * @returns true if all effects are ready
- */
- areAllEffectsReady() {
- return true;
- }
- /**
- * @internal
- * 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
- */
- getError() {
- return 0;
- }
- /** @internal */
- _getUnpackAlignement() {
- return 1;
- }
- /**
- * @internal
- */
- _unpackFlipY(value) { }
- /**
- * 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
- */
- updateDynamicIndexBuffer(indexBuffer, indices, offset = 0) { }
- /**
- * 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)
- */
- updateDynamicVertexBuffer(vertexBuffer, vertices, byteOffset, byteLength) { }
- /**
- * @internal
- */
- _bindTextureDirectly(target, texture) {
- if (this._boundTexturesCache[this._activeChannel] !== texture) {
- this._boundTexturesCache[this._activeChannel] = texture;
- return true;
- }
- return false;
- }
- /**
- * @internal
- */
- _bindTexture(channel, texture) {
- if (channel < 0) {
- return;
- }
- this._bindTextureDirectly(0, texture);
- }
- _deleteBuffer(buffer) { }
- /**
- * 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
- */
- releaseEffects() { }
- displayLoadingUI() { }
- hideLoadingUI() { }
- set loadingUIText(_) { }
- /**
- * @internal
- */
- _uploadCompressedDataToTextureDirectly(texture, internalFormat, width, height, data, faceIndex = 0, lod = 0) { }
- /**
- * @internal
- */
- _uploadDataToTextureDirectly(texture, imageData, faceIndex = 0, lod = 0) { }
- /**
- * @internal
- */
- _uploadArrayBufferViewToTexture(texture, imageData, faceIndex = 0, lod = 0) { }
- /**
- * @internal
- */
- _uploadImageToTexture(texture, image, faceIndex = 0, lod = 0) { }
- }
- //# sourceMappingURL=nullEngine.js.map
|