UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

171 lines (170 loc) 4.95 kB
import Base from "./core/Base.mjs"; import glenum from "./core/glenum.mjs"; import Cache from "./core/Cache.mjs"; var Texture = Base.extend( { width: 512, height: 512, type: glenum.UNSIGNED_BYTE, format: glenum.RGBA, wrapS: glenum.REPEAT, wrapT: glenum.REPEAT, minFilter: glenum.LINEAR_MIPMAP_LINEAR, magFilter: glenum.LINEAR, useMipmap: true, anisotropic: 1, flipY: true, sRGB: true, unpackAlignment: 4, premultiplyAlpha: false, dynamic: false, NPOT: false, __used: 0 }, function() { this._cache = new Cache(); }, { getWebGLTexture: function(renderer) { var _gl = renderer.gl; var cache = this._cache; cache.use(renderer.__uid__); if (cache.miss("webgl_texture")) { cache.put("webgl_texture", _gl.createTexture()); } if (this.dynamic) { this.update(renderer); } else if (cache.isDirty()) { this.update(renderer); cache.fresh(); } return cache.get("webgl_texture"); }, bind: function() { }, unbind: function() { }, dirty: function() { if (this._cache) { this._cache.dirtyAll(); } }, update: function(renderer) { }, updateCommon: function(renderer) { var _gl = renderer.gl; _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, this.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, this.unpackAlignment); if (this.format === glenum.DEPTH_COMPONENT) { this.useMipmap = false; } var sRGBExt = renderer.getGLExtension("EXT_sRGB"); if (this.format === Texture.SRGB && !sRGBExt) { this.format = Texture.RGB; } if (this.format === Texture.SRGB_ALPHA && !sRGBExt) { this.format = Texture.RGBA; } this.NPOT = !this.isPowerOfTwo(); }, getAvailableWrapS: function() { if (this.NPOT) { return glenum.CLAMP_TO_EDGE; } return this.wrapS; }, getAvailableWrapT: function() { if (this.NPOT) { return glenum.CLAMP_TO_EDGE; } return this.wrapT; }, getAvailableMinFilter: function() { var minFilter = this.minFilter; if (this.NPOT || !this.useMipmap) { if (minFilter === glenum.NEAREST_MIPMAP_NEAREST || minFilter === glenum.NEAREST_MIPMAP_LINEAR) { return glenum.NEAREST; } else if (minFilter === glenum.LINEAR_MIPMAP_LINEAR || minFilter === glenum.LINEAR_MIPMAP_NEAREST) { return glenum.LINEAR; } else { return minFilter; } } else { return minFilter; } }, getAvailableMagFilter: function() { return this.magFilter; }, nextHighestPowerOfTwo: function(x) { --x; for (var i = 1; i < 32; i <<= 1) { x = x | x >> i; } return x + 1; }, dispose: function(renderer) { var cache = this._cache; cache.use(renderer.__uid__); var webglTexture = cache.get("webgl_texture"); if (webglTexture) { renderer.gl.deleteTexture(webglTexture); } cache.deleteContext(renderer.__uid__); }, isRenderable: function() { }, isPowerOfTwo: function() { } } ); Object.defineProperty(Texture.prototype, "width", { get: function() { return this._width; }, set: function(value) { this._width = value; } }); Object.defineProperty(Texture.prototype, "height", { get: function() { return this._height; }, set: function(value) { this._height = value; } }); Texture.BYTE = glenum.BYTE; Texture.UNSIGNED_BYTE = glenum.UNSIGNED_BYTE; Texture.SHORT = glenum.SHORT; Texture.UNSIGNED_SHORT = glenum.UNSIGNED_SHORT; Texture.INT = glenum.INT; Texture.UNSIGNED_INT = glenum.UNSIGNED_INT; Texture.FLOAT = glenum.FLOAT; Texture.HALF_FLOAT = 36193; Texture.UNSIGNED_INT_24_8_WEBGL = 34042; Texture.DEPTH_COMPONENT = glenum.DEPTH_COMPONENT; Texture.DEPTH_STENCIL = glenum.DEPTH_STENCIL; Texture.ALPHA = glenum.ALPHA; Texture.RGB = glenum.RGB; Texture.RGBA = glenum.RGBA; Texture.LUMINANCE = glenum.LUMINANCE; Texture.LUMINANCE_ALPHA = glenum.LUMINANCE_ALPHA; Texture.SRGB = 35904; Texture.SRGB_ALPHA = 35906; Texture.COMPRESSED_RGB_S3TC_DXT1_EXT = 33776; Texture.COMPRESSED_RGBA_S3TC_DXT1_EXT = 33777; Texture.COMPRESSED_RGBA_S3TC_DXT3_EXT = 33778; Texture.COMPRESSED_RGBA_S3TC_DXT5_EXT = 33779; Texture.NEAREST = glenum.NEAREST; Texture.LINEAR = glenum.LINEAR; Texture.NEAREST_MIPMAP_NEAREST = glenum.NEAREST_MIPMAP_NEAREST; Texture.LINEAR_MIPMAP_NEAREST = glenum.LINEAR_MIPMAP_NEAREST; Texture.NEAREST_MIPMAP_LINEAR = glenum.NEAREST_MIPMAP_LINEAR; Texture.LINEAR_MIPMAP_LINEAR = glenum.LINEAR_MIPMAP_LINEAR; Texture.REPEAT = glenum.REPEAT; Texture.CLAMP_TO_EDGE = glenum.CLAMP_TO_EDGE; Texture.MIRRORED_REPEAT = glenum.MIRRORED_REPEAT; var Texture$1 = Texture; export { Texture$1 as default };