@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
54 lines • 2.59 kB
JavaScript
/** This file must only contain pure code and pure imports */
import { InternalTexture } from "../../../Materials/Textures/internalTexture.js";
import { WebGPUEngine } from "../../webgpuEngine.pure.js";
import { GetExponentOfTwo } from "../../../Misc/tools.functions.js";
let _Registered = false;
/**
* Register side effects for enginesWebGPUExtensionsEngineDynamicTexture.
* Safe to call multiple times; only the first call has an effect.
*/
export function RegisterEnginesWebGPUExtensionsEngineDynamicTexture() {
if (_Registered) {
return;
}
_Registered = true;
WebGPUEngine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode) {
const texture = new InternalTexture(this, 4 /* InternalTextureSource.Dynamic */);
texture.baseWidth = width;
texture.baseHeight = height;
if (generateMipMaps) {
width = this.needPOTTextures ? GetExponentOfTwo(width, this._caps.maxTextureSize) : width;
height = this.needPOTTextures ? GetExponentOfTwo(height, this._caps.maxTextureSize) : height;
}
texture.width = width;
texture.height = height;
texture.isReady = false;
texture.generateMipMaps = generateMipMaps;
texture.samplingMode = samplingMode;
this.updateTextureSamplingMode(samplingMode, texture);
this._internalTexturesCache.push(texture);
if (width && height) {
this._textureHelper.createGPUTextureForInternalTexture(texture, width, height);
}
return texture;
};
WebGPUEngine.prototype.updateDynamicTexture = function (texture, source, invertY, premulAlpha = false, format, forceBindTexture, allowGPUOptimization) {
if (!texture) {
return;
}
const width = source.width, height = source.height;
let gpuTextureWrapper = texture._hardwareTexture;
if (!texture._hardwareTexture?.underlyingResource) {
gpuTextureWrapper = this._textureHelper.createGPUTextureForInternalTexture(texture, width, height);
}
this._textureHelper.updateTexture(source, texture, width, height, texture.depth, gpuTextureWrapper.format, 0, 0, invertY, premulAlpha, 0, 0, allowGPUOptimization);
if (texture.generateMipMaps) {
this._generateMipmaps(texture);
}
texture._dynamicTextureSource = source;
texture._premulAlpha = premulAlpha;
texture.invertY = invertY || false;
texture.isReady = true;
};
}
//# sourceMappingURL=engine.dynamicTexture.pure.js.map