engine.dynamicTexture.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { GetExponentOfTwo } from "../../Misc/tools.functions.js";
  2. import { ThinEngine } from "../../Engines/thinEngine.js";
  3. import { InternalTexture, InternalTextureSource } from "../../Materials/Textures/internalTexture.js";
  4. ThinEngine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode) {
  5. const texture = new InternalTexture(this, InternalTextureSource.Dynamic);
  6. texture.baseWidth = width;
  7. texture.baseHeight = height;
  8. if (generateMipMaps) {
  9. width = this.needPOTTextures ? GetExponentOfTwo(width, this._caps.maxTextureSize) : width;
  10. height = this.needPOTTextures ? GetExponentOfTwo(height, this._caps.maxTextureSize) : height;
  11. }
  12. // this.resetTextureCache();
  13. texture.width = width;
  14. texture.height = height;
  15. texture.isReady = false;
  16. texture.generateMipMaps = generateMipMaps;
  17. texture.samplingMode = samplingMode;
  18. this.updateTextureSamplingMode(samplingMode, texture);
  19. this._internalTexturesCache.push(texture);
  20. return texture;
  21. };
  22. ThinEngine.prototype.updateDynamicTexture = function (texture, source, invertY, premulAlpha = false, format, forceBindTexture = false,
  23. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  24. allowGPUOptimization = false) {
  25. if (!texture) {
  26. return;
  27. }
  28. const gl = this._gl;
  29. const target = gl.TEXTURE_2D;
  30. const wasPreviouslyBound = this._bindTextureDirectly(target, texture, true, forceBindTexture);
  31. this._unpackFlipY(invertY === undefined ? texture.invertY : invertY);
  32. if (premulAlpha) {
  33. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
  34. }
  35. const textureType = this._getWebGLTextureType(texture.type);
  36. const glformat = this._getInternalFormat(format ? format : texture.format);
  37. const internalFormat = this._getRGBABufferInternalSizedFormat(texture.type, glformat);
  38. gl.texImage2D(target, 0, internalFormat, glformat, textureType, source);
  39. if (texture.generateMipMaps) {
  40. gl.generateMipmap(target);
  41. }
  42. if (!wasPreviouslyBound) {
  43. this._bindTextureDirectly(target, null);
  44. }
  45. if (premulAlpha) {
  46. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
  47. }
  48. if (format) {
  49. texture.format = format;
  50. }
  51. texture._dynamicTextureSource = source;
  52. texture._premulAlpha = premulAlpha;
  53. texture.invertY = invertY || false;
  54. texture.isReady = true;
  55. };
  56. //# sourceMappingURL=engine.dynamicTexture.js.map