rayshon-cesium-expander 1.5.2 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,802 +0,0 @@
1
- (self["webpackChunkroot"] = self["webpackChunkroot"] || []).push([["packages_cesium-expander_src_Workers_LayerPNG_worker_js"],{
2
-
3
- /***/ "./packages/cesium-expander/src/Workers/LayerPNG_worker.js":
4
- /*!*****************************************************************!*\
5
- !*** ./packages/cesium-expander/src/Workers/LayerPNG_worker.js ***!
6
- \*****************************************************************/
7
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8
-
9
- __webpack_require__.r(__webpack_exports__);
10
- /* harmony import */ var regenerator_runtime_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! regenerator-runtime/runtime */ "./node_modules/regenerator-runtime/runtime.js");
11
- /* harmony import */ var regenerator_runtime_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(regenerator_runtime_runtime__WEBPACK_IMPORTED_MODULE_0__);
12
- /* harmony import */ var _Worker_Utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Worker_Utils */ "./packages/cesium-expander/src/Workers/Worker_Utils.js");
13
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
14
-
15
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
16
-
17
-
18
-
19
-
20
- self.onmessage = /*#__PURE__*/function () {
21
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(event) {
22
- var data;
23
- return regeneratorRuntime.wrap(function _callee$(_context) {
24
- while (1) {
25
- switch (_context.prev = _context.next) {
26
- case 0:
27
- // const {url,minColorValue, maxColorValue} = event.data;
28
- try {
29
- // const data = new Cartesian3(1.0, 1.0, 1.0);
30
- data = (0,_Worker_Utils__WEBPACK_IMPORTED_MODULE_1__.calculateSomething)(1);
31
- self.postMessage({
32
- success: true,
33
- data: data
34
- });
35
- } catch (error) {
36
- self.postMessage({
37
- success: false,
38
- error: error.message
39
- });
40
- }
41
-
42
- case 1:
43
- case "end":
44
- return _context.stop();
45
- }
46
- }
47
- }, _callee);
48
- }));
49
-
50
- return function (_x) {
51
- return _ref.apply(this, arguments);
52
- };
53
- }();
54
-
55
- /***/ }),
56
-
57
- /***/ "./packages/cesium-expander/src/Workers/Worker_Utils.js":
58
- /*!**************************************************************!*\
59
- !*** ./packages/cesium-expander/src/Workers/Worker_Utils.js ***!
60
- \**************************************************************/
61
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
62
-
63
- __webpack_require__.r(__webpack_exports__);
64
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
65
- /* harmony export */ "calculateSomething": () => (/* binding */ calculateSomething),
66
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
67
- /* harmony export */ });
68
- function calculateSomething(input) {
69
- return input * 2;
70
- } // 将 Cesium.Texture 相关的内容复制进来. 目标: 可以在 worker 里面 创建 Texture 实例
71
- // Texture 需要的其他 Cesium 文件
72
-
73
- /*
74
- import Cartesian2 from "../Core/Cartesian2.js";
75
- import Check from "../Core/Check.js";
76
- import createGuid from "../Core/createGuid.js";
77
- import defaultValue from "../Core/defaultValue.js";
78
- import defined from "../Core/defined.js";
79
- import destroyObject from "../Core/destroyObject.js";
80
- import DeveloperError from "../Core/DeveloperError.js";
81
- import CesiumMath from "../Core/Math.js";
82
- import PixelFormat from "../Core/PixelFormat.js";
83
- import ContextLimits from "./ContextLimits.js";
84
- import MipmapHint from "./MipmapHint.js";
85
- import PixelDatatype from "./PixelDatatype.js";
86
- import Sampler from "./Sampler.js";
87
- import TextureMagnificationFilter from "./TextureMagnificationFilter.js";
88
- import TextureMinificationFilter from "./TextureMinificationFilter.js";
89
- */
90
- // Texture 本身
91
-
92
- /**
93
- * @private
94
- */
95
-
96
- function Texture(options) {
97
- options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug);
98
-
99
- Check.defined("options.context", options.context); //>>includeEnd('debug');
100
-
101
- var context = options.context;
102
- var width = options.width;
103
- var height = options.height;
104
- var source = options.source;
105
-
106
- if (defined(source)) {
107
- if (!defined(width)) {
108
- width = defaultValue(source.videoWidth, source.width);
109
- }
110
-
111
- if (!defined(height)) {
112
- height = defaultValue(source.videoHeight, source.height);
113
- }
114
- }
115
-
116
- var pixelFormat = defaultValue(options.pixelFormat, PixelFormat.RGBA);
117
- var pixelDatatype = defaultValue(options.pixelDatatype, PixelDatatype.UNSIGNED_BYTE);
118
- var internalFormat = PixelFormat.toInternalFormat(pixelFormat, pixelDatatype, context);
119
- var isCompressed = PixelFormat.isCompressedFormat(internalFormat); //>>includeStart('debug', pragmas.debug);
120
-
121
- if (!defined(width) || !defined(height)) {
122
- throw new DeveloperError("options requires a source field to create an initialized texture or width and height fields to create a blank texture.");
123
- }
124
-
125
- Check.typeOf.number.greaterThan("width", width, 0);
126
-
127
- if (width > ContextLimits.maximumTextureSize) {
128
- throw new DeveloperError("Width must be less than or equal to the maximum texture size (".concat(ContextLimits.maximumTextureSize, "). Check maximumTextureSize."));
129
- }
130
-
131
- Check.typeOf.number.greaterThan("height", height, 0);
132
-
133
- if (height > ContextLimits.maximumTextureSize) {
134
- throw new DeveloperError("Height must be less than or equal to the maximum texture size (".concat(ContextLimits.maximumTextureSize, "). Check maximumTextureSize."));
135
- }
136
-
137
- if (!PixelFormat.validate(pixelFormat)) {
138
- throw new DeveloperError("Invalid options.pixelFormat.");
139
- }
140
-
141
- if (!isCompressed && !PixelDatatype.validate(pixelDatatype)) {
142
- throw new DeveloperError("Invalid options.pixelDatatype.");
143
- }
144
-
145
- if (pixelFormat === PixelFormat.DEPTH_COMPONENT && pixelDatatype !== PixelDatatype.UNSIGNED_SHORT && pixelDatatype !== PixelDatatype.UNSIGNED_INT) {
146
- throw new DeveloperError("When options.pixelFormat is DEPTH_COMPONENT, options.pixelDatatype must be UNSIGNED_SHORT or UNSIGNED_INT.");
147
- }
148
-
149
- if (pixelFormat === PixelFormat.DEPTH_STENCIL && pixelDatatype !== PixelDatatype.UNSIGNED_INT_24_8) {
150
- throw new DeveloperError("When options.pixelFormat is DEPTH_STENCIL, options.pixelDatatype must be UNSIGNED_INT_24_8.");
151
- }
152
-
153
- if (pixelDatatype === PixelDatatype.FLOAT && !context.floatingPointTexture) {
154
- throw new DeveloperError("When options.pixelDatatype is FLOAT, this WebGL implementation must support the OES_texture_float extension. Check context.floatingPointTexture.");
155
- }
156
-
157
- if (pixelDatatype === PixelDatatype.HALF_FLOAT && !context.halfFloatingPointTexture) {
158
- throw new DeveloperError("When options.pixelDatatype is HALF_FLOAT, this WebGL implementation must support the OES_texture_half_float extension. Check context.halfFloatingPointTexture.");
159
- }
160
-
161
- if (PixelFormat.isDepthFormat(pixelFormat)) {
162
- if (defined(source)) {
163
- throw new DeveloperError("When options.pixelFormat is DEPTH_COMPONENT or DEPTH_STENCIL, source cannot be provided.");
164
- }
165
-
166
- if (!context.depthTexture) {
167
- throw new DeveloperError("When options.pixelFormat is DEPTH_COMPONENT or DEPTH_STENCIL, this WebGL implementation must support WEBGL_depth_texture. Check context.depthTexture.");
168
- }
169
- }
170
-
171
- if (isCompressed) {
172
- if (!defined(source) || !defined(source.arrayBufferView)) {
173
- throw new DeveloperError("When options.pixelFormat is compressed, options.source.arrayBufferView must be defined.");
174
- }
175
-
176
- if (PixelFormat.isDXTFormat(internalFormat) && !context.s3tc) {
177
- throw new DeveloperError("When options.pixelFormat is S3TC compressed, this WebGL implementation must support the WEBGL_compressed_texture_s3tc extension. Check context.s3tc.");
178
- } else if (PixelFormat.isPVRTCFormat(internalFormat) && !context.pvrtc) {
179
- throw new DeveloperError("When options.pixelFormat is PVRTC compressed, this WebGL implementation must support the WEBGL_compressed_texture_pvrtc extension. Check context.pvrtc.");
180
- } else if (PixelFormat.isASTCFormat(internalFormat) && !context.astc) {
181
- throw new DeveloperError("When options.pixelFormat is ASTC compressed, this WebGL implementation must support the WEBGL_compressed_texture_astc extension. Check context.astc.");
182
- } else if (PixelFormat.isETC2Format(internalFormat) && !context.etc) {
183
- throw new DeveloperError("When options.pixelFormat is ETC2 compressed, this WebGL implementation must support the WEBGL_compressed_texture_etc extension. Check context.etc.");
184
- } else if (PixelFormat.isETC1Format(internalFormat) && !context.etc1) {
185
- throw new DeveloperError("When options.pixelFormat is ETC1 compressed, this WebGL implementation must support the WEBGL_compressed_texture_etc1 extension. Check context.etc1.");
186
- } else if (PixelFormat.isBC7Format(internalFormat) && !context.bc7) {
187
- throw new DeveloperError("When options.pixelFormat is BC7 compressed, this WebGL implementation must support the EXT_texture_compression_bptc extension. Check context.bc7.");
188
- }
189
-
190
- if (PixelFormat.compressedTextureSizeInBytes(internalFormat, width, height) !== source.arrayBufferView.byteLength) {
191
- throw new DeveloperError("The byte length of the array buffer is invalid for the compressed texture with the given width and height.");
192
- }
193
- } //>>includeEnd('debug');
194
- // Use premultiplied alpha for opaque textures should perform better on Chrome:
195
- // http://media.tojicode.com/webglCamp4/#20
196
-
197
-
198
- var preMultiplyAlpha = options.preMultiplyAlpha || pixelFormat === PixelFormat.RGB || pixelFormat === PixelFormat.LUMINANCE;
199
- var flipY = defaultValue(options.flipY, true);
200
- var skipColorSpaceConversion = defaultValue(options.skipColorSpaceConversion, false);
201
- var initialized = true;
202
- var gl = context._gl;
203
- var textureTarget = gl.TEXTURE_2D;
204
- var texture = gl.createTexture();
205
- gl.activeTexture(gl.TEXTURE0);
206
- gl.bindTexture(textureTarget, texture);
207
- var unpackAlignment = 4;
208
-
209
- if (defined(source) && defined(source.arrayBufferView) && !isCompressed) {
210
- unpackAlignment = PixelFormat.alignmentInBytes(pixelFormat, pixelDatatype, width);
211
- }
212
-
213
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);
214
-
215
- if (skipColorSpaceConversion) {
216
- gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
217
- } else {
218
- gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL);
219
- }
220
-
221
- if (defined(source)) {
222
- if (defined(source.arrayBufferView)) {
223
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
224
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); // Source: typed array
225
-
226
- var arrayBufferView = source.arrayBufferView;
227
- var i, mipWidth, mipHeight;
228
-
229
- if (isCompressed) {
230
- gl.compressedTexImage2D(textureTarget, 0, internalFormat, width, height, 0, arrayBufferView);
231
-
232
- if (defined(source.mipLevels)) {
233
- mipWidth = width;
234
- mipHeight = height;
235
-
236
- for (i = 0; i < source.mipLevels.length; ++i) {
237
- mipWidth = Math.floor(mipWidth / 2) | 0;
238
-
239
- if (mipWidth < 1) {
240
- mipWidth = 1;
241
- }
242
-
243
- mipHeight = Math.floor(mipHeight / 2) | 0;
244
-
245
- if (mipHeight < 1) {
246
- mipHeight = 1;
247
- }
248
-
249
- gl.compressedTexImage2D(textureTarget, i + 1, internalFormat, mipWidth, mipHeight, 0, source.mipLevels[i]);
250
- }
251
- }
252
- } else {
253
- if (flipY) {
254
- arrayBufferView = PixelFormat.flipY(arrayBufferView, pixelFormat, pixelDatatype, width, height);
255
- }
256
-
257
- gl.texImage2D(textureTarget, 0, internalFormat, width, height, 0, pixelFormat, PixelDatatype.toWebGLConstant(pixelDatatype, context), arrayBufferView);
258
-
259
- if (defined(source.mipLevels)) {
260
- mipWidth = width;
261
- mipHeight = height;
262
-
263
- for (i = 0; i < source.mipLevels.length; ++i) {
264
- mipWidth = Math.floor(mipWidth / 2) | 0;
265
-
266
- if (mipWidth < 1) {
267
- mipWidth = 1;
268
- }
269
-
270
- mipHeight = Math.floor(mipHeight / 2) | 0;
271
-
272
- if (mipHeight < 1) {
273
- mipHeight = 1;
274
- }
275
-
276
- gl.texImage2D(textureTarget, i + 1, internalFormat, mipWidth, mipHeight, 0, pixelFormat, PixelDatatype.toWebGLConstant(pixelDatatype, context), source.mipLevels[i]);
277
- }
278
- }
279
- }
280
- } else if (defined(source.framebuffer)) {
281
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
282
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); // Source: framebuffer
283
-
284
- if (source.framebuffer !== context.defaultFramebuffer) {
285
- source.framebuffer._bind();
286
- }
287
-
288
- gl.copyTexImage2D(textureTarget, 0, internalFormat, source.xOffset, source.yOffset, width, height, 0);
289
-
290
- if (source.framebuffer !== context.defaultFramebuffer) {
291
- source.framebuffer._unBind();
292
- }
293
- } else {
294
- // Only valid for DOM-Element uploads
295
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
296
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); // Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement
297
-
298
- gl.texImage2D(textureTarget, 0, internalFormat, pixelFormat, PixelDatatype.toWebGLConstant(pixelDatatype, context), source);
299
- }
300
- } else {
301
- gl.texImage2D(textureTarget, 0, internalFormat, width, height, 0, pixelFormat, PixelDatatype.toWebGLConstant(pixelDatatype, context), null);
302
- initialized = false;
303
- }
304
-
305
- gl.bindTexture(textureTarget, null);
306
- var sizeInBytes;
307
-
308
- if (isCompressed) {
309
- sizeInBytes = PixelFormat.compressedTextureSizeInBytes(pixelFormat, width, height);
310
- } else {
311
- sizeInBytes = PixelFormat.textureSizeInBytes(pixelFormat, pixelDatatype, width, height);
312
- }
313
-
314
- this._id = createGuid();
315
- this._context = context;
316
- this._textureFilterAnisotropic = context._textureFilterAnisotropic;
317
- this._textureTarget = textureTarget;
318
- this._texture = texture;
319
- this._internalFormat = internalFormat;
320
- this._pixelFormat = pixelFormat;
321
- this._pixelDatatype = pixelDatatype;
322
- this._width = width;
323
- this._height = height;
324
- this._dimensions = new Cartesian2(width, height);
325
- this._hasMipmap = false;
326
- this._sizeInBytes = sizeInBytes;
327
- this._preMultiplyAlpha = preMultiplyAlpha;
328
- this._flipY = flipY;
329
- this._initialized = initialized;
330
- this._sampler = undefined;
331
- this.sampler = defined(options.sampler) ? options.sampler : new Sampler();
332
- }
333
- /**
334
- * This function is identical to using the Texture constructor except that it can be
335
- * replaced with a mock/spy in tests.
336
- * @private
337
- */
338
-
339
-
340
- Texture.create = function (options) {
341
- return new Texture(options);
342
- };
343
- /**
344
- * Creates a texture, and copies a subimage of the framebuffer to it. When called without arguments,
345
- * the texture is the same width and height as the framebuffer and contains its contents.
346
- *
347
- * @param {object} options Object with the following properties:
348
- * @param {Context} options.context The context in which the Texture gets created.
349
- * @param {PixelFormat} [options.pixelFormat=PixelFormat.RGB] The texture's internal pixel format.
350
- * @param {number} [options.framebufferXOffset=0] An offset in the x direction in the framebuffer where copying begins from.
351
- * @param {number} [options.framebufferYOffset=0] An offset in the y direction in the framebuffer where copying begins from.
352
- * @param {number} [options.width=canvas.clientWidth] The width of the texture in texels.
353
- * @param {number} [options.height=canvas.clientHeight] The height of the texture in texels.
354
- * @param {Framebuffer} [options.framebuffer=defaultFramebuffer] The framebuffer from which to create the texture. If this
355
- * parameter is not specified, the default framebuffer is used.
356
- * @returns {Texture} A texture with contents from the framebuffer.
357
- *
358
- * @exception {DeveloperError} Invalid pixelFormat.
359
- * @exception {DeveloperError} pixelFormat cannot be DEPTH_COMPONENT, DEPTH_STENCIL or a compressed format.
360
- * @exception {DeveloperError} framebufferXOffset must be greater than or equal to zero.
361
- * @exception {DeveloperError} framebufferYOffset must be greater than or equal to zero.
362
- * @exception {DeveloperError} framebufferXOffset + width must be less than or equal to canvas.clientWidth.
363
- * @exception {DeveloperError} framebufferYOffset + height must be less than or equal to canvas.clientHeight.
364
- *
365
- *
366
- * @example
367
- * // Create a texture with the contents of the framebuffer.
368
- * const t = Texture.fromFramebuffer({
369
- * context : context
370
- * });
371
- *
372
- * @see Sampler
373
- *
374
- * @private
375
- */
376
-
377
-
378
- Texture.fromFramebuffer = function (options) {
379
- options = defaultValue(options, defaultValue.EMPTY_OBJECT); //>>includeStart('debug', pragmas.debug);
380
-
381
- Check.defined("options.context", options.context); //>>includeEnd('debug');
382
-
383
- var context = options.context;
384
- var gl = context._gl;
385
- var pixelFormat = defaultValue(options.pixelFormat, PixelFormat.RGB);
386
- var framebufferXOffset = defaultValue(options.framebufferXOffset, 0);
387
- var framebufferYOffset = defaultValue(options.framebufferYOffset, 0);
388
- var width = defaultValue(options.width, gl.drawingBufferWidth);
389
- var height = defaultValue(options.height, gl.drawingBufferHeight);
390
- var framebuffer = options.framebuffer; //>>includeStart('debug', pragmas.debug);
391
-
392
- if (!PixelFormat.validate(pixelFormat)) {
393
- throw new DeveloperError("Invalid pixelFormat.");
394
- }
395
-
396
- if (PixelFormat.isDepthFormat(pixelFormat) || PixelFormat.isCompressedFormat(pixelFormat)) {
397
- throw new DeveloperError("pixelFormat cannot be DEPTH_COMPONENT, DEPTH_STENCIL or a compressed format.");
398
- }
399
-
400
- Check.defined("options.context", options.context);
401
- Check.typeOf.number.greaterThanOrEquals("framebufferXOffset", framebufferXOffset, 0);
402
- Check.typeOf.number.greaterThanOrEquals("framebufferYOffset", framebufferYOffset, 0);
403
-
404
- if (framebufferXOffset + width > gl.drawingBufferWidth) {
405
- throw new DeveloperError("framebufferXOffset + width must be less than or equal to drawingBufferWidth");
406
- }
407
-
408
- if (framebufferYOffset + height > gl.drawingBufferHeight) {
409
- throw new DeveloperError("framebufferYOffset + height must be less than or equal to drawingBufferHeight.");
410
- } //>>includeEnd('debug');
411
-
412
-
413
- var texture = new Texture({
414
- context: context,
415
- width: width,
416
- height: height,
417
- pixelFormat: pixelFormat,
418
- source: {
419
- framebuffer: defined(framebuffer) ? framebuffer : context.defaultFramebuffer,
420
- xOffset: framebufferXOffset,
421
- yOffset: framebufferYOffset,
422
- width: width,
423
- height: height
424
- }
425
- });
426
- return texture;
427
- };
428
-
429
- Object.defineProperties(Texture.prototype, {
430
- /**
431
- * A unique id for the texture
432
- * @memberof Texture.prototype
433
- * @type {string}
434
- * @readonly
435
- * @private
436
- */
437
- id: {
438
- get: function get() {
439
- return this._id;
440
- }
441
- },
442
-
443
- /**
444
- * The sampler to use when sampling this texture.
445
- * Create a sampler by calling {@link Sampler}. If this
446
- * parameter is not specified, a default sampler is used. The default sampler clamps texture
447
- * coordinates in both directions, uses linear filtering for both magnification and minification,
448
- * and uses a maximum anisotropy of 1.0.
449
- * @memberof Texture.prototype
450
- * @type {object}
451
- */
452
- sampler: {
453
- get: function get() {
454
- return this._sampler;
455
- },
456
- set: function set(sampler) {
457
- var minificationFilter = sampler.minificationFilter;
458
- var magnificationFilter = sampler.magnificationFilter;
459
- var context = this._context;
460
- var pixelFormat = this._pixelFormat;
461
- var pixelDatatype = this._pixelDatatype;
462
- var mipmap = minificationFilter === TextureMinificationFilter.NEAREST_MIPMAP_NEAREST || minificationFilter === TextureMinificationFilter.NEAREST_MIPMAP_LINEAR || minificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_NEAREST || minificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_LINEAR; // float textures only support nearest filtering unless the linear extensions are supported, so override the sampler's settings
463
-
464
- if (pixelDatatype === PixelDatatype.FLOAT && !context.textureFloatLinear || pixelDatatype === PixelDatatype.HALF_FLOAT && !context.textureHalfFloatLinear) {
465
- minificationFilter = mipmap ? TextureMinificationFilter.NEAREST_MIPMAP_NEAREST : TextureMinificationFilter.NEAREST;
466
- magnificationFilter = TextureMagnificationFilter.NEAREST;
467
- } // WebGL 2 depth texture only support nearest filtering. See section 3.8.13 OpenGL ES 3 spec
468
-
469
-
470
- if (context.webgl2) {
471
- if (PixelFormat.isDepthFormat(pixelFormat)) {
472
- minificationFilter = TextureMinificationFilter.NEAREST;
473
- magnificationFilter = TextureMagnificationFilter.NEAREST;
474
- }
475
- }
476
-
477
- var gl = context._gl;
478
- var target = this._textureTarget;
479
- gl.activeTexture(gl.TEXTURE0);
480
- gl.bindTexture(target, this._texture);
481
- gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, minificationFilter);
482
- gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, magnificationFilter);
483
- gl.texParameteri(target, gl.TEXTURE_WRAP_S, sampler.wrapS);
484
- gl.texParameteri(target, gl.TEXTURE_WRAP_T, sampler.wrapT);
485
-
486
- if (defined(this._textureFilterAnisotropic)) {
487
- gl.texParameteri(target, this._textureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT, sampler.maximumAnisotropy);
488
- }
489
-
490
- gl.bindTexture(target, null);
491
- this._sampler = sampler;
492
- }
493
- },
494
- pixelFormat: {
495
- get: function get() {
496
- return this._pixelFormat;
497
- }
498
- },
499
- pixelDatatype: {
500
- get: function get() {
501
- return this._pixelDatatype;
502
- }
503
- },
504
- dimensions: {
505
- get: function get() {
506
- return this._dimensions;
507
- }
508
- },
509
- preMultiplyAlpha: {
510
- get: function get() {
511
- return this._preMultiplyAlpha;
512
- }
513
- },
514
- flipY: {
515
- get: function get() {
516
- return this._flipY;
517
- }
518
- },
519
- width: {
520
- get: function get() {
521
- return this._width;
522
- }
523
- },
524
- height: {
525
- get: function get() {
526
- return this._height;
527
- }
528
- },
529
- sizeInBytes: {
530
- get: function get() {
531
- if (this._hasMipmap) {
532
- return Math.floor(this._sizeInBytes * 4 / 3);
533
- }
534
-
535
- return this._sizeInBytes;
536
- }
537
- },
538
- _target: {
539
- get: function get() {
540
- return this._textureTarget;
541
- }
542
- }
543
- });
544
- /**
545
- * Copy new image data into this texture, from a source {@link ImageData}, {@link HTMLImageElement}, {@link HTMLCanvasElement}, or {@link HTMLVideoElement}.
546
- * or an object with width, height, and arrayBufferView properties.
547
- * @param {object} options Object with the following properties:
548
- * @param {object} options.source The source {@link ImageData}, {@link HTMLImageElement}, {@link HTMLCanvasElement}, or {@link HTMLVideoElement},
549
- * or an object with width, height, and arrayBufferView properties.
550
- * @param {number} [options.xOffset=0] The offset in the x direction within the texture to copy into.
551
- * @param {number} [options.yOffset=0] The offset in the y direction within the texture to copy into.
552
- * @param {boolean} [options.skipColorSpaceConversion=false] If true, any custom gamma or color profiles in the texture will be ignored.
553
- *
554
- * @exception {DeveloperError} Cannot call copyFrom when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.
555
- * @exception {DeveloperError} Cannot call copyFrom with a compressed texture pixel format.
556
- * @exception {DeveloperError} xOffset must be greater than or equal to zero.
557
- * @exception {DeveloperError} yOffset must be greater than or equal to zero.
558
- * @exception {DeveloperError} xOffset + source.width must be less than or equal to width.
559
- * @exception {DeveloperError} yOffset + source.height must be less than or equal to height.
560
- * @exception {DeveloperError} This texture was destroyed, i.e., destroy() was called.
561
- *
562
- * @example
563
- * texture.copyFrom({
564
- * source: {
565
- * width : 1,
566
- * height : 1,
567
- * arrayBufferView : new Uint8Array([255, 0, 0, 255])
568
- * }
569
- * });
570
- */
571
-
572
- Texture.prototype.copyFrom = function (options) {
573
- //>>includeStart('debug', pragmas.debug);
574
- Check.defined("options", options); //>>includeEnd('debug');
575
-
576
- var xOffset = defaultValue(options.xOffset, 0);
577
- var yOffset = defaultValue(options.yOffset, 0); //>>includeStart('debug', pragmas.debug);
578
-
579
- Check.defined("options.source", options.source);
580
-
581
- if (PixelFormat.isDepthFormat(this._pixelFormat)) {
582
- throw new DeveloperError("Cannot call copyFrom when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.");
583
- }
584
-
585
- if (PixelFormat.isCompressedFormat(this._pixelFormat)) {
586
- throw new DeveloperError("Cannot call copyFrom with a compressed texture pixel format.");
587
- }
588
-
589
- Check.typeOf.number.greaterThanOrEquals("xOffset", xOffset, 0);
590
- Check.typeOf.number.greaterThanOrEquals("yOffset", yOffset, 0);
591
- Check.typeOf.number.lessThanOrEquals("xOffset + options.source.width", xOffset + options.source.width, this._width);
592
- Check.typeOf.number.lessThanOrEquals("yOffset + options.source.height", yOffset + options.source.height, this._height); //>>includeEnd('debug');
593
-
594
- var source = options.source;
595
- var context = this._context;
596
- var gl = context._gl;
597
- var target = this._textureTarget;
598
- gl.activeTexture(gl.TEXTURE0);
599
- gl.bindTexture(target, this._texture);
600
- var width = source.width;
601
- var height = source.height;
602
- var arrayBufferView = source.arrayBufferView;
603
- var textureWidth = this._width;
604
- var textureHeight = this._height;
605
- var internalFormat = this._internalFormat;
606
- var pixelFormat = this._pixelFormat;
607
- var pixelDatatype = this._pixelDatatype;
608
- var preMultiplyAlpha = this._preMultiplyAlpha;
609
- var flipY = this._flipY;
610
- var skipColorSpaceConversion = defaultValue(options.skipColorSpaceConversion, false);
611
- var unpackAlignment = 4;
612
-
613
- if (defined(arrayBufferView)) {
614
- unpackAlignment = PixelFormat.alignmentInBytes(pixelFormat, pixelDatatype, width);
615
- }
616
-
617
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);
618
-
619
- if (skipColorSpaceConversion) {
620
- gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
621
- } else {
622
- gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL);
623
- }
624
-
625
- var uploaded = false;
626
-
627
- if (!this._initialized) {
628
- if (xOffset === 0 && yOffset === 0 && width === textureWidth && height === textureHeight) {
629
- // initialize the entire texture
630
- if (defined(arrayBufferView)) {
631
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
632
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
633
-
634
- if (flipY) {
635
- arrayBufferView = PixelFormat.flipY(arrayBufferView, pixelFormat, pixelDatatype, textureWidth, textureHeight);
636
- }
637
-
638
- gl.texImage2D(target, 0, internalFormat, textureWidth, textureHeight, 0, pixelFormat, PixelDatatype.toWebGLConstant(pixelDatatype, context), arrayBufferView);
639
- } else {
640
- // Only valid for DOM-Element uploads
641
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
642
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
643
- gl.texImage2D(target, 0, internalFormat, pixelFormat, PixelDatatype.toWebGLConstant(pixelDatatype, context), source);
644
- }
645
-
646
- uploaded = true;
647
- } else {
648
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
649
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); // initialize the entire texture to zero
650
-
651
- var bufferView = PixelFormat.createTypedArray(pixelFormat, pixelDatatype, textureWidth, textureHeight);
652
- gl.texImage2D(target, 0, internalFormat, textureWidth, textureHeight, 0, pixelFormat, PixelDatatype.toWebGLConstant(pixelDatatype, context), bufferView);
653
- }
654
-
655
- this._initialized = true;
656
- }
657
-
658
- if (!uploaded) {
659
- if (defined(arrayBufferView)) {
660
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
661
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
662
-
663
- if (flipY) {
664
- arrayBufferView = PixelFormat.flipY(arrayBufferView, pixelFormat, pixelDatatype, width, height);
665
- }
666
-
667
- gl.texSubImage2D(target, 0, xOffset, yOffset, width, height, pixelFormat, PixelDatatype.toWebGLConstant(pixelDatatype, context), arrayBufferView);
668
- } else {
669
- // Only valid for DOM-Element uploads
670
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
671
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
672
- gl.texSubImage2D(target, 0, xOffset, yOffset, pixelFormat, PixelDatatype.toWebGLConstant(pixelDatatype, context), source);
673
- }
674
- }
675
-
676
- gl.bindTexture(target, null);
677
- };
678
- /**
679
- * @param {number} [xOffset=0] The offset in the x direction within the texture to copy into.
680
- * @param {number} [yOffset=0] The offset in the y direction within the texture to copy into.
681
- * @param {number} [framebufferXOffset=0] optional
682
- * @param {number} [framebufferYOffset=0] optional
683
- * @param {number} [width=width] optional
684
- * @param {number} [height=height] optional
685
- *
686
- * @exception {DeveloperError} Cannot call copyFromFramebuffer when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.
687
- * @exception {DeveloperError} Cannot call copyFromFramebuffer when the texture pixel data type is FLOAT.
688
- * @exception {DeveloperError} Cannot call copyFromFramebuffer when the texture pixel data type is HALF_FLOAT.
689
- * @exception {DeveloperError} Cannot call copyFrom with a compressed texture pixel format.
690
- * @exception {DeveloperError} This texture was destroyed, i.e., destroy() was called.
691
- * @exception {DeveloperError} xOffset must be greater than or equal to zero.
692
- * @exception {DeveloperError} yOffset must be greater than or equal to zero.
693
- * @exception {DeveloperError} framebufferXOffset must be greater than or equal to zero.
694
- * @exception {DeveloperError} framebufferYOffset must be greater than or equal to zero.
695
- * @exception {DeveloperError} xOffset + width must be less than or equal to width.
696
- * @exception {DeveloperError} yOffset + height must be less than or equal to height.
697
- */
698
-
699
-
700
- Texture.prototype.copyFromFramebuffer = function (xOffset, yOffset, framebufferXOffset, framebufferYOffset, width, height) {
701
- xOffset = defaultValue(xOffset, 0);
702
- yOffset = defaultValue(yOffset, 0);
703
- framebufferXOffset = defaultValue(framebufferXOffset, 0);
704
- framebufferYOffset = defaultValue(framebufferYOffset, 0);
705
- width = defaultValue(width, this._width);
706
- height = defaultValue(height, this._height); //>>includeStart('debug', pragmas.debug);
707
-
708
- if (PixelFormat.isDepthFormat(this._pixelFormat)) {
709
- throw new DeveloperError("Cannot call copyFromFramebuffer when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.");
710
- }
711
-
712
- if (this._pixelDatatype === PixelDatatype.FLOAT) {
713
- throw new DeveloperError("Cannot call copyFromFramebuffer when the texture pixel data type is FLOAT.");
714
- }
715
-
716
- if (this._pixelDatatype === PixelDatatype.HALF_FLOAT) {
717
- throw new DeveloperError("Cannot call copyFromFramebuffer when the texture pixel data type is HALF_FLOAT.");
718
- }
719
-
720
- if (PixelFormat.isCompressedFormat(this._pixelFormat)) {
721
- throw new DeveloperError("Cannot call copyFrom with a compressed texture pixel format.");
722
- }
723
-
724
- Check.typeOf.number.greaterThanOrEquals("xOffset", xOffset, 0);
725
- Check.typeOf.number.greaterThanOrEquals("yOffset", yOffset, 0);
726
- Check.typeOf.number.greaterThanOrEquals("framebufferXOffset", framebufferXOffset, 0);
727
- Check.typeOf.number.greaterThanOrEquals("framebufferYOffset", framebufferYOffset, 0);
728
- Check.typeOf.number.lessThanOrEquals("xOffset + width", xOffset + width, this._width);
729
- Check.typeOf.number.lessThanOrEquals("yOffset + height", yOffset + height, this._height); //>>includeEnd('debug');
730
-
731
- var gl = this._context._gl;
732
- var target = this._textureTarget;
733
- gl.activeTexture(gl.TEXTURE0);
734
- gl.bindTexture(target, this._texture);
735
- gl.copyTexSubImage2D(target, 0, xOffset, yOffset, framebufferXOffset, framebufferYOffset, width, height);
736
- gl.bindTexture(target, null);
737
- this._initialized = true;
738
- };
739
- /**
740
- * @param {MipmapHint} [hint=MipmapHint.DONT_CARE] optional.
741
- *
742
- * @exception {DeveloperError} Cannot call generateMipmap when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.
743
- * @exception {DeveloperError} Cannot call generateMipmap when the texture pixel format is a compressed format.
744
- * @exception {DeveloperError} hint is invalid.
745
- * @exception {DeveloperError} This texture's width must be a power of two to call generateMipmap() in a WebGL1 context.
746
- * @exception {DeveloperError} This texture's height must be a power of two to call generateMipmap() in a WebGL1 context.
747
- * @exception {DeveloperError} This texture was destroyed, i.e., destroy() was called.
748
- */
749
-
750
-
751
- Texture.prototype.generateMipmap = function (hint) {
752
- hint = defaultValue(hint, MipmapHint.DONT_CARE); //>>includeStart('debug', pragmas.debug);
753
-
754
- if (PixelFormat.isDepthFormat(this._pixelFormat)) {
755
- throw new DeveloperError("Cannot call generateMipmap when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL.");
756
- }
757
-
758
- if (PixelFormat.isCompressedFormat(this._pixelFormat)) {
759
- throw new DeveloperError("Cannot call generateMipmap with a compressed pixel format.");
760
- }
761
-
762
- if (!this._context.webgl2) {
763
- if (this._width > 1 && !CesiumMath.isPowerOfTwo(this._width)) {
764
- throw new DeveloperError("width must be a power of two to call generateMipmap() in a WebGL1 context.");
765
- }
766
-
767
- if (this._height > 1 && !CesiumMath.isPowerOfTwo(this._height)) {
768
- throw new DeveloperError("height must be a power of two to call generateMipmap() in a WebGL1 context.");
769
- }
770
- }
771
-
772
- if (!MipmapHint.validate(hint)) {
773
- throw new DeveloperError("hint is invalid.");
774
- } //>>includeEnd('debug');
775
-
776
-
777
- this._hasMipmap = true;
778
- var gl = this._context._gl;
779
- var target = this._textureTarget;
780
- gl.hint(gl.GENERATE_MIPMAP_HINT, hint);
781
- gl.activeTexture(gl.TEXTURE0);
782
- gl.bindTexture(target, this._texture);
783
- gl.generateMipmap(target);
784
- gl.bindTexture(target, null);
785
- };
786
-
787
- Texture.prototype.isDestroyed = function () {
788
- return false;
789
- };
790
-
791
- Texture.prototype.destroy = function () {
792
- this._context._gl.deleteTexture(this._texture);
793
-
794
- return destroyObject(this);
795
- };
796
-
797
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Texture);
798
-
799
- /***/ })
800
-
801
- }])
802
- //# sourceMappingURL=packages_cesium-expander_src_Workers_LayerPNG_worker_js.index.dev.js.map