@cesium/engine 10.0.0 → 11.0.0
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.
- package/Build/Workers/{chunk-AA4GZKOT.js → chunk-2EDC3QGH.js} +1 -1
- package/Build/Workers/{chunk-DKVHRNFY.js → chunk-2MKRG7L7.js} +5 -5
- package/Build/Workers/{chunk-X23FRWHJ.js → chunk-2RZYNSMR.js} +6 -6
- package/Build/Workers/{chunk-TO2PVHKI.js → chunk-4NBRIKB3.js} +2 -2
- package/Build/Workers/{chunk-GRAT5GE7.js → chunk-4TK5YR6Q.js} +5 -5
- package/Build/Workers/{chunk-XD445VDH.js → chunk-54VC7SCM.js} +7 -7
- package/Build/Workers/{chunk-G3YR53LY.js → chunk-5IY5BXCT.js} +13 -13
- package/Build/Workers/{chunk-O3JCMSS3.js → chunk-6FFGOENI.js} +54 -7
- package/Build/Workers/{chunk-7XGC6YB2.js → chunk-6PJIHPQB.js} +13 -13
- package/Build/Workers/{chunk-GR3CDLCP.js → chunk-6ZREIBKS.js} +7 -7
- package/Build/Workers/{chunk-4MSUJ4I7.js → chunk-AI3O7UN2.js} +6 -6
- package/Build/Workers/{chunk-COYFZ5VA.js → chunk-AS7P4BHI.js} +6 -6
- package/Build/Workers/{chunk-JYAHOGGL.js → chunk-AUM45VEG.js} +16 -15
- package/Build/Workers/{chunk-BDFNKFOE.js → chunk-BBO6BGLC.js} +13 -13
- package/Build/Workers/{chunk-AVI4IUWC.js → chunk-BH5ZEN4I.js} +10 -10
- package/Build/Workers/{chunk-4BAE4PWO.js → chunk-BJ3WF5RW.js} +6 -6
- package/Build/Workers/{chunk-Q55ECN3Y.js → chunk-BUOFSNFW.js} +1 -1
- package/Build/Workers/{chunk-QX5XS4LC.js → chunk-BZXF3GNX.js} +2 -2
- package/Build/Workers/{chunk-PYHLO636.js → chunk-DJXXI7UF.js} +5 -5
- package/Build/Workers/{chunk-LCLJJ2MZ.js → chunk-DVAIU7A4.js} +17 -17
- package/Build/Workers/{chunk-SYCPRK3D.js → chunk-FJT3ERV7.js} +9 -9
- package/Build/Workers/{chunk-L6RTJ3RE.js → chunk-GOHDOWU5.js} +14 -14
- package/Build/Workers/{chunk-MSKXMXJI.js → chunk-HA6TZ3XT.js} +4 -4
- package/Build/Workers/{chunk-PCP4YQST.js → chunk-HBZSCVZC.js} +11 -11
- package/Build/Workers/{chunk-5S7OLEPK.js → chunk-HC7RYWPZ.js} +12 -12
- package/Build/Workers/{chunk-VE7BFUIX.js → chunk-HFMJM3SX.js} +1 -1
- package/Build/Workers/{chunk-OOK53QUQ.js → chunk-HFPMX5L2.js} +1 -1
- package/Build/Workers/{chunk-VFBNELXB.js → chunk-HO2NTC7I.js} +6 -6
- package/Build/Workers/{chunk-DOXCPOG4.js → chunk-HZPMWR4H.js} +7 -7
- package/Build/Workers/{chunk-I2RC4XVN.js → chunk-IBG5FVXC.js} +4 -4
- package/Build/Workers/{chunk-LEABCTLP.js → chunk-IXLNNST6.js} +4 -4
- package/Build/Workers/{chunk-4YSNMHZ4.js → chunk-JYUCC5NV.js} +6 -6
- package/Build/Workers/{chunk-BCL4PHHT.js → chunk-KFW4UNQH.js} +10 -10
- package/Build/Workers/{chunk-R6B7UCQB.js → chunk-KKAEXHDY.js} +2 -2
- package/Build/Workers/{chunk-BJF5LOWE.js → chunk-L6FARMF6.js} +7 -7
- package/Build/Workers/{chunk-C2CGMAIU.js → chunk-N3BIL6WA.js} +13 -13
- package/Build/Workers/{chunk-STBBMQGG.js → chunk-O5SSW3B3.js} +6 -6
- package/Build/Workers/{chunk-S3PI2KFM.js → chunk-OC4MYPVW.js} +2 -2
- package/Build/Workers/{chunk-MDHQR3ZS.js → chunk-OOA6GXKD.js} +7 -7
- package/Build/Workers/{chunk-AD5HBJ2F.js → chunk-OSCHEWSG.js} +7 -7
- package/Build/Workers/{chunk-NTXTUNEF.js → chunk-QGT2GMOK.js} +4 -4
- package/Build/Workers/{chunk-VO3ACQB2.js → chunk-RFQYEYAL.js} +17 -17
- package/Build/Workers/{chunk-KUN2ZA5X.js → chunk-RJF5ZP76.js} +4 -4
- package/Build/Workers/{chunk-QD4KM3GO.js → chunk-SIZXFNJY.js} +6 -5
- package/Build/Workers/{chunk-FXIHSF7O.js → chunk-SRZJCF7G.js} +9 -9
- package/Build/Workers/{chunk-T77JILCU.js → chunk-T4MB73MC.js} +2 -2
- package/Build/Workers/{chunk-3WUV74WM.js → chunk-TTI2SUWJ.js} +2 -2
- package/Build/Workers/{chunk-QMLTCCYG.js → chunk-VHJ5ESXF.js} +1 -1
- package/Build/Workers/{chunk-2J3JKXCP.js → chunk-VSFFJGTA.js} +9 -5
- package/Build/Workers/{chunk-DGS5QNIO.js → chunk-WQRXRDCZ.js} +11 -11
- package/Build/Workers/{chunk-OORVMGDU.js → chunk-WXDGOYTT.js} +12 -7
- package/Build/Workers/{chunk-RJYML24O.js → chunk-XLCZE6DD.js} +423 -448
- package/Build/Workers/combineGeometry.js +22 -22
- package/Build/Workers/createBoxGeometry.js +16 -16
- package/Build/Workers/createBoxOutlineGeometry.js +14 -14
- package/Build/Workers/createCircleGeometry.js +24 -24
- package/Build/Workers/createCircleOutlineGeometry.js +17 -17
- package/Build/Workers/createCoplanarPolygonGeometry.js +31 -31
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
- package/Build/Workers/createCorridorGeometry.js +27 -27
- package/Build/Workers/createCorridorOutlineGeometry.js +26 -26
- package/Build/Workers/createCylinderGeometry.js +18 -18
- package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
- package/Build/Workers/createEllipseGeometry.js +24 -24
- package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
- package/Build/Workers/createEllipsoidGeometry.js +17 -17
- package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
- package/Build/Workers/createFrustumGeometry.js +16 -16
- package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
- package/Build/Workers/createGeometry.js +22 -22
- package/Build/Workers/createGroundPolylineGeometry.js +20 -20
- package/Build/Workers/createPlaneGeometry.js +14 -14
- package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
- package/Build/Workers/createPolygonGeometry.js +30 -30
- package/Build/Workers/createPolygonOutlineGeometry.js +28 -28
- package/Build/Workers/createPolylineGeometry.js +23 -23
- package/Build/Workers/createPolylineVolumeGeometry.js +29 -29
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -25
- package/Build/Workers/createRectangleGeometry.js +25 -25
- package/Build/Workers/createRectangleOutlineGeometry.js +18 -18
- package/Build/Workers/createSimplePolylineGeometry.js +21 -21
- package/Build/Workers/createSphereGeometry.js +17 -17
- package/Build/Workers/createSphereOutlineGeometry.js +16 -16
- package/Build/Workers/createTaskProcessorWorker.js +3 -3
- package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
- package/Build/Workers/createVectorTileGeometries.js +22 -22
- package/Build/Workers/createVectorTilePoints.js +12 -12
- package/Build/Workers/createVectorTilePolygons.js +20 -20
- package/Build/Workers/createVectorTilePolylines.js +13 -13
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
- package/Build/Workers/createVerticesFromHeightmap.js +24 -20
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
- package/Build/Workers/createWallGeometry.js +22 -22
- package/Build/Workers/createWallOutlineGeometry.js +21 -21
- package/Build/Workers/decodeDraco.js +11 -11
- package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +28 -5
- package/Build/Workers/decodeI3S.js +10 -10
- package/Build/Workers/transcodeKTX2.js +20 -22
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
- package/Source/Core/CompressedTextureBuffer.js +11 -0
- package/Source/Core/Ion.js +1 -1
- package/Source/Core/KTX2Transcoder.js +9 -16
- package/Source/Core/PixelFormat.js +1 -15
- package/Source/Core/Simon1994PlanetaryPositions.js +2 -1
- package/Source/Core/Transforms.js +137 -2
- package/Source/DataSources/BillboardGraphics.js +16 -0
- package/Source/DataSources/BillboardVisualizer.js +7 -0
- package/Source/DataSources/CallbackProperty.js +8 -2
- package/Source/DataSources/CheckerboardMaterialProperty.js +7 -1
- package/Source/DataSources/ColorMaterialProperty.js +7 -1
- package/Source/DataSources/CompositeMaterialProperty.js +5 -4
- package/Source/DataSources/CompositePositionProperty.js +7 -1
- package/Source/DataSources/CompositeProperty.js +5 -5
- package/Source/DataSources/ConstantPositionProperty.js +7 -1
- package/Source/DataSources/Entity.js +1 -1
- package/Source/DataSources/GridMaterialProperty.js +7 -1
- package/Source/DataSources/ImageMaterialProperty.js +8 -1
- package/Source/DataSources/MaterialProperty.js +7 -1
- package/Source/DataSources/NodeTransformationProperty.js +7 -1
- package/Source/DataSources/PathVisualizer.js +4 -4
- package/Source/DataSources/PointGraphics.js +17 -0
- package/Source/DataSources/PointVisualizer.js +12 -0
- package/Source/DataSources/PolylineArrowMaterialProperty.js +7 -1
- package/Source/DataSources/PolylineDashMaterialProperty.js +7 -1
- package/Source/DataSources/PolylineGlowMaterialProperty.js +7 -1
- package/Source/DataSources/PolylineOutlineMaterialProperty.js +7 -1
- package/Source/DataSources/PositionProperty.js +5 -8
- package/Source/DataSources/PositionPropertyArray.js +7 -1
- package/Source/DataSources/Property.js +1 -1
- package/Source/DataSources/PropertyArray.js +5 -5
- package/Source/DataSources/PropertyBag.js +5 -4
- package/Source/DataSources/ReferenceProperty.js +7 -1
- package/Source/DataSources/SampledPositionProperty.js +7 -1
- package/Source/DataSources/SampledProperty.js +6 -4
- package/Source/DataSources/ScaledPositionProperty.js +6 -0
- package/Source/DataSources/StripeMaterialProperty.js +7 -1
- package/Source/DataSources/TerrainOffsetProperty.js +9 -0
- package/Source/DataSources/TimeIntervalCollectionPositionProperty.js +7 -1
- package/Source/DataSources/TimeIntervalCollectionProperty.js +5 -5
- package/Source/DataSources/VelocityOrientationProperty.js +6 -1
- package/Source/DataSources/VelocityVectorProperty.js +3 -5
- package/Source/Renderer/AutomaticUniforms.js +3 -18
- package/Source/Renderer/Context.js +15 -0
- package/Source/Renderer/CubeMap.js +326 -348
- package/Source/Renderer/CubeMapFace.js +26 -48
- package/Source/Renderer/PixelDatatype.js +23 -0
- package/Source/Renderer/Sampler.js +7 -13
- package/Source/Renderer/ShaderProgram.js +7 -0
- package/Source/Renderer/Texture.js +396 -332
- package/Source/Renderer/UniformState.js +8 -33
- package/Source/Renderer/demodernizeShader.js +2 -0
- package/Source/Renderer/loadCubeMap.js +3 -8
- package/Source/Scene/ArcGisMapService.js +1 -1
- package/Source/Scene/Billboard.js +29 -2
- package/Source/Scene/BillboardCollection.js +49 -0
- package/Source/Scene/BingMapsImageryProvider.js +10 -1
- package/Source/Scene/CameraEventAggregator.js +49 -5
- package/Source/Scene/Globe.js +1 -1
- package/Source/Scene/GlobeSurfaceShaderSet.js +29 -24
- package/Source/Scene/GlobeSurfaceTileProvider.js +5 -3
- package/Source/Scene/ImageBasedLighting.js +36 -36
- package/Source/Scene/Label.js +2 -2
- package/Source/Scene/Material.js +24 -2
- package/Source/Scene/Model/ImageBasedLightingPipelineStage.js +7 -15
- package/Source/Scene/Model/Model.js +1 -1
- package/Source/Scene/PointPrimitive.js +28 -2
- package/Source/Scene/PointPrimitiveCollection.js +22 -9
- package/Source/Scene/PostProcessStageCollection.js +45 -15
- package/Source/Scene/PostProcessStageLibrary.js +26 -0
- package/Source/Scene/Scene.js +20 -22
- package/Source/Scene/SceneTransforms.js +0 -62
- package/Source/Scene/ScreenSpaceCameraController.js +11 -4
- package/Source/Scene/SkyBox.js +13 -19
- package/Source/Scene/SpecularEnvironmentCubeMap.js +240 -0
- package/Source/Scene/Tonemapper.js +35 -23
- package/Source/Scene/VoxelPrimitive.js +0 -29
- package/Source/Scene/VoxelRenderResources.js +0 -3
- package/Source/Shaders/BillboardCollectionFS.glsl +4 -0
- package/Source/Shaders/BillboardCollectionFS.js +4 -0
- package/Source/Shaders/BillboardCollectionVS.glsl +3 -1
- package/Source/Shaders/BillboardCollectionVS.js +3 -1
- package/Source/Shaders/BrdfLutGeneratorFS.glsl +30 -13
- package/Source/Shaders/BrdfLutGeneratorFS.js +30 -13
- package/Source/Shaders/Builtin/CzmBuiltins.js +2 -2
- package/Source/Shaders/Builtin/Functions/pbrLighting.glsl +42 -41
- package/Source/Shaders/Builtin/Functions/pbrLighting.js +42 -41
- package/Source/Shaders/Builtin/Functions/pbrNeutralTonemapping.glsl +23 -0
- package/Source/Shaders/Builtin/Functions/pbrNeutralTonemapping.js +25 -0
- package/Source/Shaders/Builtin/Functions/textureCube.glsl +21 -2
- package/Source/Shaders/Builtin/Functions/textureCube.js +21 -2
- package/Source/Shaders/Builtin/Structs/materialInput.glsl +2 -0
- package/Source/Shaders/Builtin/Structs/materialInput.js +2 -0
- package/Source/Shaders/GlobeFS.glsl +10 -4
- package/Source/Shaders/GlobeFS.js +10 -4
- package/Source/Shaders/Materials/WaterMaskMaterial.glsl +15 -0
- package/Source/Shaders/Materials/WaterMaskMaterial.js +17 -0
- package/Source/Shaders/Model/AtmosphereStageFS.glsl +1 -1
- package/Source/Shaders/Model/AtmosphereStageFS.js +1 -1
- package/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +57 -46
- package/Source/Shaders/Model/ImageBasedLightingStageFS.js +57 -46
- package/Source/Shaders/Model/LightingStageFS.glsl +8 -7
- package/Source/Shaders/Model/LightingStageFS.js +8 -7
- package/Source/Shaders/Model/MaterialStageFS.glsl +10 -14
- package/Source/Shaders/Model/MaterialStageFS.js +10 -14
- package/Source/Shaders/PointPrimitiveCollectionFS.glsl +4 -0
- package/Source/Shaders/PointPrimitiveCollectionFS.js +4 -0
- package/Source/Shaders/PointPrimitiveCollectionVS.glsl +9 -7
- package/Source/Shaders/PointPrimitiveCollectionVS.js +9 -7
- package/Source/Shaders/PostProcessStages/AcesTonemappingStage.glsl +4 -0
- package/Source/Shaders/PostProcessStages/AcesTonemappingStage.js +4 -0
- package/Source/Shaders/PostProcessStages/FilmicTonemapping.glsl +4 -0
- package/Source/Shaders/PostProcessStages/FilmicTonemapping.js +4 -0
- package/Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.glsl +4 -0
- package/Source/Shaders/PostProcessStages/ModifiedReinhardTonemapping.js +4 -0
- package/Source/Shaders/PostProcessStages/PbrNeutralTonemapping.glsl +25 -0
- package/Source/Shaders/PostProcessStages/PbrNeutralTonemapping.js +27 -0
- package/Source/Shaders/PostProcessStages/ReinhardTonemapping.glsl +4 -0
- package/Source/Shaders/PostProcessStages/ReinhardTonemapping.js +4 -0
- package/Source/Shaders/SkyAtmosphereFS.glsl +1 -1
- package/Source/Shaders/SkyAtmosphereFS.js +1 -1
- package/Source/Widget/CesiumWidget.js +1 -1
- package/index.d.ts +191 -106
- package/index.js +133 -134
- package/package.json +4 -4
- package/Source/Scene/OctahedralProjectedCubeMap.js +0 -445
- package/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.glsl +0 -78
- package/Source/Shaders/Builtin/Functions/sampleOctahedralProjection.js +0 -80
- package/Source/Shaders/OctahedralProjectionAtlasFS.glsl +0 -89
- package/Source/Shaders/OctahedralProjectionAtlasFS.js +0 -91
- package/Source/Shaders/OctahedralProjectionFS.glsl +0 -14
- package/Source/Shaders/OctahedralProjectionFS.js +0 -16
- package/Source/Shaders/OctahedralProjectionVS.glsl +0 -10
- package/Source/Shaders/OctahedralProjectionVS.js +0 -12
|
@@ -15,6 +15,30 @@ import TextureMagnificationFilter from "./TextureMagnificationFilter.js";
|
|
|
15
15
|
import TextureMinificationFilter from "./TextureMinificationFilter.js";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
+
* @typedef {object} Texture.ConstructorOptions
|
|
19
|
+
*
|
|
20
|
+
* @property {Context} context
|
|
21
|
+
* @property {object} [source] The source for texel values to be loaded into the texture.
|
|
22
|
+
* @property {PixelFormat} [pixelFormat=PixelFormat.RGBA] The format of each pixel, i.e., the number of components it has and what they represent.
|
|
23
|
+
* @property {PixelDatatype} [pixelDatatype=PixelDatatype.UNSIGNED_BYTE] The data type of each pixel.
|
|
24
|
+
* @property {boolean} [flipY=true] If true, the source values will be read as if the y-axis is inverted (y=0 at the top).
|
|
25
|
+
* @property {boolean} [skipColorSpaceConversion=false] If true, color space conversions will be skipped when reading the texel values.
|
|
26
|
+
* @property {Sampler} [sampler] Information about how to sample the cubemap texture.
|
|
27
|
+
* @property {number} [width] The pixel width of the texture. If not supplied, must be available from the source.
|
|
28
|
+
* @property {number} [height] The pixel height of the texture. If not supplied, must be available from the source.
|
|
29
|
+
* @property {boolean} [preMultiplyAlpha] If true, the alpha channel will be multiplied into the other channels.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A wrapper for a {@link https://developer.mozilla.org/en-US/docs/Web/API/WebGLTexture|WebGLTexture}
|
|
36
|
+
* to abstract away the verbose GL calls associated with setting up a texture.
|
|
37
|
+
*
|
|
38
|
+
* @alias Texture
|
|
39
|
+
* @constructor
|
|
40
|
+
*
|
|
41
|
+
* @param {Texture.ConstructorOptions} options
|
|
18
42
|
* @private
|
|
19
43
|
*/
|
|
20
44
|
function Texture(options) {
|
|
@@ -24,11 +48,17 @@ function Texture(options) {
|
|
|
24
48
|
Check.defined("options.context", options.context);
|
|
25
49
|
//>>includeEnd('debug');
|
|
26
50
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
const {
|
|
52
|
+
context,
|
|
53
|
+
source,
|
|
54
|
+
pixelFormat = PixelFormat.RGBA,
|
|
55
|
+
pixelDatatype = PixelDatatype.UNSIGNED_BYTE,
|
|
56
|
+
flipY = true,
|
|
57
|
+
skipColorSpaceConversion = false,
|
|
58
|
+
sampler = new Sampler(),
|
|
59
|
+
} = options;
|
|
60
|
+
|
|
61
|
+
let { width, height } = options;
|
|
32
62
|
if (defined(source)) {
|
|
33
63
|
if (!defined(width)) {
|
|
34
64
|
width = defaultValue(source.videoWidth, source.width);
|
|
@@ -38,11 +68,13 @@ function Texture(options) {
|
|
|
38
68
|
}
|
|
39
69
|
}
|
|
40
70
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
71
|
+
// Use premultiplied alpha for opaque textures should perform better on Chrome:
|
|
72
|
+
// http://media.tojicode.com/webglCamp4/#20
|
|
73
|
+
const preMultiplyAlpha =
|
|
74
|
+
options.preMultiplyAlpha ||
|
|
75
|
+
pixelFormat === PixelFormat.RGB ||
|
|
76
|
+
pixelFormat === PixelFormat.LUMINANCE;
|
|
77
|
+
|
|
46
78
|
const internalFormat = PixelFormat.toInternalFormat(
|
|
47
79
|
pixelFormat,
|
|
48
80
|
pixelDatatype,
|
|
@@ -177,225 +209,278 @@ function Texture(options) {
|
|
|
177
209
|
}
|
|
178
210
|
//>>includeEnd('debug');
|
|
179
211
|
|
|
180
|
-
// Use premultiplied alpha for opaque textures should perform better on Chrome:
|
|
181
|
-
// http://media.tojicode.com/webglCamp4/#20
|
|
182
|
-
const preMultiplyAlpha =
|
|
183
|
-
options.preMultiplyAlpha ||
|
|
184
|
-
pixelFormat === PixelFormat.RGB ||
|
|
185
|
-
pixelFormat === PixelFormat.LUMINANCE;
|
|
186
|
-
const flipY = defaultValue(options.flipY, true);
|
|
187
|
-
const skipColorSpaceConversion = defaultValue(
|
|
188
|
-
options.skipColorSpaceConversion,
|
|
189
|
-
false
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
let initialized = true;
|
|
193
|
-
|
|
194
212
|
const gl = context._gl;
|
|
195
|
-
const textureTarget = gl.TEXTURE_2D;
|
|
196
|
-
const texture = gl.createTexture();
|
|
197
213
|
|
|
198
|
-
|
|
199
|
-
|
|
214
|
+
const sizeInBytes = isCompressed
|
|
215
|
+
? PixelFormat.compressedTextureSizeInBytes(pixelFormat, width, height)
|
|
216
|
+
: PixelFormat.textureSizeInBytes(pixelFormat, pixelDatatype, width, height);
|
|
200
217
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
218
|
+
this._id = createGuid();
|
|
219
|
+
this._context = context;
|
|
220
|
+
this._textureFilterAnisotropic = context._textureFilterAnisotropic;
|
|
221
|
+
this._textureTarget = gl.TEXTURE_2D;
|
|
222
|
+
this._texture = gl.createTexture();
|
|
223
|
+
this._internalFormat = internalFormat;
|
|
224
|
+
this._pixelFormat = pixelFormat;
|
|
225
|
+
this._pixelDatatype = pixelDatatype;
|
|
226
|
+
this._width = width;
|
|
227
|
+
this._height = height;
|
|
228
|
+
this._dimensions = new Cartesian2(width, height);
|
|
229
|
+
this._hasMipmap = false;
|
|
230
|
+
this._sizeInBytes = sizeInBytes;
|
|
231
|
+
this._preMultiplyAlpha = preMultiplyAlpha;
|
|
232
|
+
this._flipY = flipY;
|
|
233
|
+
this._initialized = false;
|
|
234
|
+
this._sampler = undefined;
|
|
209
235
|
|
|
210
|
-
|
|
236
|
+
this._sampler = sampler;
|
|
237
|
+
setupSampler(this, sampler);
|
|
211
238
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
} else {
|
|
215
|
-
gl.pixelStorei(
|
|
216
|
-
gl.UNPACK_COLORSPACE_CONVERSION_WEBGL,
|
|
217
|
-
gl.BROWSER_DEFAULT_WEBGL
|
|
218
|
-
);
|
|
219
|
-
}
|
|
239
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
240
|
+
gl.bindTexture(this._textureTarget, this._texture);
|
|
220
241
|
|
|
221
242
|
if (defined(source)) {
|
|
243
|
+
if (skipColorSpaceConversion) {
|
|
244
|
+
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
|
|
245
|
+
} else {
|
|
246
|
+
gl.pixelStorei(
|
|
247
|
+
gl.UNPACK_COLORSPACE_CONVERSION_WEBGL,
|
|
248
|
+
gl.BROWSER_DEFAULT_WEBGL
|
|
249
|
+
);
|
|
250
|
+
}
|
|
222
251
|
if (defined(source.arrayBufferView)) {
|
|
223
|
-
|
|
224
|
-
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
225
|
-
|
|
226
|
-
// Source: typed array
|
|
227
|
-
let arrayBufferView = source.arrayBufferView;
|
|
228
|
-
let i, mipWidth, mipHeight;
|
|
252
|
+
const isCompressed = PixelFormat.isCompressedFormat(internalFormat);
|
|
229
253
|
if (isCompressed) {
|
|
230
|
-
|
|
231
|
-
textureTarget,
|
|
232
|
-
0,
|
|
233
|
-
internalFormat,
|
|
234
|
-
width,
|
|
235
|
-
height,
|
|
236
|
-
0,
|
|
237
|
-
arrayBufferView
|
|
238
|
-
);
|
|
239
|
-
if (defined(source.mipLevels)) {
|
|
240
|
-
mipWidth = width;
|
|
241
|
-
mipHeight = height;
|
|
242
|
-
for (i = 0; i < source.mipLevels.length; ++i) {
|
|
243
|
-
mipWidth = Math.floor(mipWidth / 2) | 0;
|
|
244
|
-
if (mipWidth < 1) {
|
|
245
|
-
mipWidth = 1;
|
|
246
|
-
}
|
|
247
|
-
mipHeight = Math.floor(mipHeight / 2) | 0;
|
|
248
|
-
if (mipHeight < 1) {
|
|
249
|
-
mipHeight = 1;
|
|
250
|
-
}
|
|
251
|
-
gl.compressedTexImage2D(
|
|
252
|
-
textureTarget,
|
|
253
|
-
i + 1,
|
|
254
|
-
internalFormat,
|
|
255
|
-
mipWidth,
|
|
256
|
-
mipHeight,
|
|
257
|
-
0,
|
|
258
|
-
source.mipLevels[i]
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
254
|
+
loadCompressedBufferSource(this, source);
|
|
262
255
|
} else {
|
|
263
|
-
|
|
264
|
-
arrayBufferView = PixelFormat.flipY(
|
|
265
|
-
arrayBufferView,
|
|
266
|
-
pixelFormat,
|
|
267
|
-
pixelDatatype,
|
|
268
|
-
width,
|
|
269
|
-
height
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
gl.texImage2D(
|
|
273
|
-
textureTarget,
|
|
274
|
-
0,
|
|
275
|
-
internalFormat,
|
|
276
|
-
width,
|
|
277
|
-
height,
|
|
278
|
-
0,
|
|
279
|
-
pixelFormat,
|
|
280
|
-
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
281
|
-
arrayBufferView
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
if (defined(source.mipLevels)) {
|
|
285
|
-
mipWidth = width;
|
|
286
|
-
mipHeight = height;
|
|
287
|
-
for (i = 0; i < source.mipLevels.length; ++i) {
|
|
288
|
-
mipWidth = Math.floor(mipWidth / 2) | 0;
|
|
289
|
-
if (mipWidth < 1) {
|
|
290
|
-
mipWidth = 1;
|
|
291
|
-
}
|
|
292
|
-
mipHeight = Math.floor(mipHeight / 2) | 0;
|
|
293
|
-
if (mipHeight < 1) {
|
|
294
|
-
mipHeight = 1;
|
|
295
|
-
}
|
|
296
|
-
gl.texImage2D(
|
|
297
|
-
textureTarget,
|
|
298
|
-
i + 1,
|
|
299
|
-
internalFormat,
|
|
300
|
-
mipWidth,
|
|
301
|
-
mipHeight,
|
|
302
|
-
0,
|
|
303
|
-
pixelFormat,
|
|
304
|
-
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
305
|
-
source.mipLevels[i]
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
256
|
+
loadBufferSource(this, source);
|
|
309
257
|
}
|
|
310
258
|
} else if (defined(source.framebuffer)) {
|
|
311
|
-
|
|
312
|
-
|
|
259
|
+
loadFramebufferSource(this, source);
|
|
260
|
+
} else {
|
|
261
|
+
loadImageSource(this, source);
|
|
262
|
+
}
|
|
263
|
+
this._initialized = true;
|
|
264
|
+
} else {
|
|
265
|
+
loadNull(this);
|
|
266
|
+
}
|
|
313
267
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
source.framebuffer._bind();
|
|
317
|
-
}
|
|
268
|
+
gl.bindTexture(this._textureTarget, null);
|
|
269
|
+
}
|
|
318
270
|
|
|
319
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Load compressed texel data from a buffer into a texture.
|
|
273
|
+
*
|
|
274
|
+
* @param {Texture} texture The texture to which texel values will be loaded.
|
|
275
|
+
* @param {object} source The source for texel values to be loaded into the texture.
|
|
276
|
+
*
|
|
277
|
+
* @private
|
|
278
|
+
*/
|
|
279
|
+
function loadCompressedBufferSource(texture, source) {
|
|
280
|
+
const context = texture._context;
|
|
281
|
+
const gl = context._gl;
|
|
282
|
+
const textureTarget = texture._textureTarget;
|
|
283
|
+
const internalFormat = texture._internalFormat;
|
|
284
|
+
|
|
285
|
+
const { width, height } = texture;
|
|
286
|
+
|
|
287
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
|
|
288
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
289
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
290
|
+
|
|
291
|
+
gl.compressedTexImage2D(
|
|
292
|
+
textureTarget,
|
|
293
|
+
0,
|
|
294
|
+
internalFormat,
|
|
295
|
+
width,
|
|
296
|
+
height,
|
|
297
|
+
0,
|
|
298
|
+
source.arrayBufferView
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
if (defined(source.mipLevels)) {
|
|
302
|
+
let mipWidth = width;
|
|
303
|
+
let mipHeight = height;
|
|
304
|
+
for (let i = 0; i < source.mipLevels.length; ++i) {
|
|
305
|
+
mipWidth = nextMipSize(mipWidth);
|
|
306
|
+
mipHeight = nextMipSize(mipHeight);
|
|
307
|
+
gl.compressedTexImage2D(
|
|
320
308
|
textureTarget,
|
|
321
|
-
|
|
309
|
+
i + 1,
|
|
322
310
|
internalFormat,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
0
|
|
311
|
+
mipWidth,
|
|
312
|
+
mipHeight,
|
|
313
|
+
0,
|
|
314
|
+
source.mipLevels[i]
|
|
328
315
|
);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
329
319
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
320
|
+
/**
|
|
321
|
+
* Load texel data from a buffer into a texture.
|
|
322
|
+
*
|
|
323
|
+
* @param {Texture} texture The texture to which texel values will be loaded.
|
|
324
|
+
* @param {object} source The source for texel values to be loaded into the texture.
|
|
325
|
+
*
|
|
326
|
+
* @private
|
|
327
|
+
*/
|
|
328
|
+
function loadBufferSource(texture, source) {
|
|
329
|
+
const context = texture._context;
|
|
330
|
+
const gl = context._gl;
|
|
331
|
+
const textureTarget = texture._textureTarget;
|
|
332
|
+
const internalFormat = texture._internalFormat;
|
|
333
|
+
|
|
334
|
+
const { width, height, pixelFormat, pixelDatatype, flipY } = texture;
|
|
335
|
+
|
|
336
|
+
const unpackAlignment = PixelFormat.alignmentInBytes(
|
|
337
|
+
pixelFormat,
|
|
338
|
+
pixelDatatype,
|
|
339
|
+
width
|
|
340
|
+
);
|
|
341
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);
|
|
342
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
343
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
344
|
+
|
|
345
|
+
let arrayBufferView = source.arrayBufferView;
|
|
346
|
+
if (flipY) {
|
|
347
|
+
arrayBufferView = PixelFormat.flipY(
|
|
348
|
+
arrayBufferView,
|
|
349
|
+
pixelFormat,
|
|
350
|
+
pixelDatatype,
|
|
351
|
+
width,
|
|
352
|
+
height
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
gl.texImage2D(
|
|
356
|
+
textureTarget,
|
|
357
|
+
0,
|
|
358
|
+
internalFormat,
|
|
359
|
+
width,
|
|
360
|
+
height,
|
|
361
|
+
0,
|
|
362
|
+
pixelFormat,
|
|
363
|
+
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
364
|
+
arrayBufferView
|
|
365
|
+
);
|
|
337
366
|
|
|
338
|
-
|
|
367
|
+
if (defined(source.mipLevels)) {
|
|
368
|
+
let mipWidth = width;
|
|
369
|
+
let mipHeight = height;
|
|
370
|
+
for (let i = 0; i < source.mipLevels.length; ++i) {
|
|
371
|
+
mipWidth = nextMipSize(mipWidth);
|
|
372
|
+
mipHeight = nextMipSize(mipHeight);
|
|
339
373
|
gl.texImage2D(
|
|
340
374
|
textureTarget,
|
|
341
|
-
|
|
375
|
+
i + 1,
|
|
342
376
|
internalFormat,
|
|
377
|
+
mipWidth,
|
|
378
|
+
mipHeight,
|
|
379
|
+
0,
|
|
343
380
|
pixelFormat,
|
|
344
381
|
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
345
|
-
source
|
|
382
|
+
source.mipLevels[i]
|
|
346
383
|
);
|
|
347
384
|
}
|
|
348
|
-
} else {
|
|
349
|
-
gl.texImage2D(
|
|
350
|
-
textureTarget,
|
|
351
|
-
0,
|
|
352
|
-
internalFormat,
|
|
353
|
-
width,
|
|
354
|
-
height,
|
|
355
|
-
0,
|
|
356
|
-
pixelFormat,
|
|
357
|
-
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
358
|
-
null
|
|
359
|
-
);
|
|
360
|
-
initialized = false;
|
|
361
385
|
}
|
|
362
|
-
|
|
386
|
+
}
|
|
363
387
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
388
|
+
/**
|
|
389
|
+
* Load texel data from a framebuffer into a texture.
|
|
390
|
+
*
|
|
391
|
+
* @param {Texture} texture The texture to which texel values will be loaded.
|
|
392
|
+
* @param {object} source The source for texel values to be loaded into the texture.
|
|
393
|
+
*
|
|
394
|
+
* @private
|
|
395
|
+
*/
|
|
396
|
+
function loadFramebufferSource(texture, source) {
|
|
397
|
+
const context = texture._context;
|
|
398
|
+
const gl = context._gl;
|
|
399
|
+
|
|
400
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
|
|
401
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
402
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
403
|
+
|
|
404
|
+
if (source.framebuffer !== context.defaultFramebuffer) {
|
|
405
|
+
source.framebuffer._bind();
|
|
378
406
|
}
|
|
379
407
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
408
|
+
gl.copyTexImage2D(
|
|
409
|
+
texture._textureTarget,
|
|
410
|
+
0,
|
|
411
|
+
texture._internalFormat,
|
|
412
|
+
source.xOffset,
|
|
413
|
+
source.yOffset,
|
|
414
|
+
texture.width,
|
|
415
|
+
texture.height,
|
|
416
|
+
0
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
if (source.framebuffer !== context.defaultFramebuffer) {
|
|
420
|
+
source.framebuffer._unBind();
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Load texel data from an Image into a texture.
|
|
426
|
+
*
|
|
427
|
+
* @param {Texture} texture The texture to which texel values will be loaded.
|
|
428
|
+
* @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} source The source for texel values to be loaded into the texture.
|
|
429
|
+
*
|
|
430
|
+
* @private
|
|
431
|
+
*/
|
|
432
|
+
function loadImageSource(texture, source) {
|
|
433
|
+
const context = texture._context;
|
|
434
|
+
const gl = context._gl;
|
|
435
|
+
|
|
436
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
|
|
437
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.preMultiplyAlpha);
|
|
438
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, texture.flipY);
|
|
439
|
+
|
|
440
|
+
gl.texImage2D(
|
|
441
|
+
texture._textureTarget,
|
|
442
|
+
0,
|
|
443
|
+
texture._internalFormat,
|
|
444
|
+
texture.pixelFormat,
|
|
445
|
+
PixelDatatype.toWebGLConstant(texture.pixelDatatype, context),
|
|
446
|
+
source
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Compute a dimension of the image for the next mip level.
|
|
452
|
+
*
|
|
453
|
+
* @param {number} currentSize The size of the current mip level.
|
|
454
|
+
* @returns {number} The size of the next mip level.
|
|
455
|
+
*
|
|
456
|
+
* @private
|
|
457
|
+
*/
|
|
458
|
+
function nextMipSize(currentSize) {
|
|
459
|
+
const nextSize = Math.floor(currentSize / 2) | 0;
|
|
460
|
+
return Math.max(nextSize, 1);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Allocate a texture in GPU memory, without providing any image data.
|
|
465
|
+
*
|
|
466
|
+
* @param {Texture} texture The texture to be initialized with null values.
|
|
467
|
+
*
|
|
468
|
+
* @private
|
|
469
|
+
*/
|
|
470
|
+
function loadNull(texture) {
|
|
471
|
+
const context = texture._context;
|
|
397
472
|
|
|
398
|
-
|
|
473
|
+
context._gl.texImage2D(
|
|
474
|
+
texture._textureTarget,
|
|
475
|
+
0,
|
|
476
|
+
texture._internalFormat,
|
|
477
|
+
texture._width,
|
|
478
|
+
texture._height,
|
|
479
|
+
0,
|
|
480
|
+
texture._pixelFormat,
|
|
481
|
+
PixelDatatype.toWebGLConstant(texture._pixelDatatype, context),
|
|
482
|
+
null
|
|
483
|
+
);
|
|
399
484
|
}
|
|
400
485
|
|
|
401
486
|
/**
|
|
@@ -449,13 +534,14 @@ Texture.fromFramebuffer = function (options) {
|
|
|
449
534
|
|
|
450
535
|
const context = options.context;
|
|
451
536
|
const gl = context._gl;
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
537
|
+
const {
|
|
538
|
+
pixelFormat = PixelFormat.RGB,
|
|
539
|
+
framebufferXOffset = 0,
|
|
540
|
+
framebufferYOffset = 0,
|
|
541
|
+
width = gl.drawingBufferWidth,
|
|
542
|
+
height = gl.drawingBufferHeight,
|
|
543
|
+
framebuffer,
|
|
544
|
+
} = options;
|
|
459
545
|
|
|
460
546
|
//>>includeStart('debug', pragmas.debug);
|
|
461
547
|
if (!PixelFormat.validate(pixelFormat)) {
|
|
@@ -469,7 +555,7 @@ Texture.fromFramebuffer = function (options) {
|
|
|
469
555
|
"pixelFormat cannot be DEPTH_COMPONENT, DEPTH_STENCIL or a compressed format."
|
|
470
556
|
);
|
|
471
557
|
}
|
|
472
|
-
Check.defined("options.context",
|
|
558
|
+
Check.defined("options.context", context);
|
|
473
559
|
Check.typeOf.number.greaterThanOrEquals(
|
|
474
560
|
"framebufferXOffset",
|
|
475
561
|
framebufferXOffset,
|
|
@@ -538,60 +624,7 @@ Object.defineProperties(Texture.prototype, {
|
|
|
538
624
|
return this._sampler;
|
|
539
625
|
},
|
|
540
626
|
set: function (sampler) {
|
|
541
|
-
|
|
542
|
-
let magnificationFilter = sampler.magnificationFilter;
|
|
543
|
-
const context = this._context;
|
|
544
|
-
const pixelFormat = this._pixelFormat;
|
|
545
|
-
const pixelDatatype = this._pixelDatatype;
|
|
546
|
-
|
|
547
|
-
const mipmap =
|
|
548
|
-
minificationFilter ===
|
|
549
|
-
TextureMinificationFilter.NEAREST_MIPMAP_NEAREST ||
|
|
550
|
-
minificationFilter ===
|
|
551
|
-
TextureMinificationFilter.NEAREST_MIPMAP_LINEAR ||
|
|
552
|
-
minificationFilter ===
|
|
553
|
-
TextureMinificationFilter.LINEAR_MIPMAP_NEAREST ||
|
|
554
|
-
minificationFilter === TextureMinificationFilter.LINEAR_MIPMAP_LINEAR;
|
|
555
|
-
|
|
556
|
-
// float textures only support nearest filtering unless the linear extensions are supported, so override the sampler's settings
|
|
557
|
-
if (
|
|
558
|
-
(pixelDatatype === PixelDatatype.FLOAT &&
|
|
559
|
-
!context.textureFloatLinear) ||
|
|
560
|
-
(pixelDatatype === PixelDatatype.HALF_FLOAT &&
|
|
561
|
-
!context.textureHalfFloatLinear)
|
|
562
|
-
) {
|
|
563
|
-
minificationFilter = mipmap
|
|
564
|
-
? TextureMinificationFilter.NEAREST_MIPMAP_NEAREST
|
|
565
|
-
: TextureMinificationFilter.NEAREST;
|
|
566
|
-
magnificationFilter = TextureMagnificationFilter.NEAREST;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
// WebGL 2 depth texture only support nearest filtering. See section 3.8.13 OpenGL ES 3 spec
|
|
570
|
-
if (context.webgl2) {
|
|
571
|
-
if (PixelFormat.isDepthFormat(pixelFormat)) {
|
|
572
|
-
minificationFilter = TextureMinificationFilter.NEAREST;
|
|
573
|
-
magnificationFilter = TextureMagnificationFilter.NEAREST;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
const gl = context._gl;
|
|
578
|
-
const target = this._textureTarget;
|
|
579
|
-
|
|
580
|
-
gl.activeTexture(gl.TEXTURE0);
|
|
581
|
-
gl.bindTexture(target, this._texture);
|
|
582
|
-
gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, minificationFilter);
|
|
583
|
-
gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, magnificationFilter);
|
|
584
|
-
gl.texParameteri(target, gl.TEXTURE_WRAP_S, sampler.wrapS);
|
|
585
|
-
gl.texParameteri(target, gl.TEXTURE_WRAP_T, sampler.wrapT);
|
|
586
|
-
if (defined(this._textureFilterAnisotropic)) {
|
|
587
|
-
gl.texParameteri(
|
|
588
|
-
target,
|
|
589
|
-
this._textureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT,
|
|
590
|
-
sampler.maximumAnisotropy
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
gl.bindTexture(target, null);
|
|
594
|
-
|
|
627
|
+
setupSampler(this, sampler);
|
|
595
628
|
this._sampler = sampler;
|
|
596
629
|
},
|
|
597
630
|
},
|
|
@@ -645,6 +678,66 @@ Object.defineProperties(Texture.prototype, {
|
|
|
645
678
|
},
|
|
646
679
|
});
|
|
647
680
|
|
|
681
|
+
/**
|
|
682
|
+
* Set up a sampler for use with a texture
|
|
683
|
+
* @param {Texture} texture The texture to be sampled by this sampler
|
|
684
|
+
* @param {Sampler} sampler Information about how to sample the texture
|
|
685
|
+
* @private
|
|
686
|
+
*/
|
|
687
|
+
function setupSampler(texture, sampler) {
|
|
688
|
+
let { minificationFilter, magnificationFilter } = sampler;
|
|
689
|
+
|
|
690
|
+
const mipmap = [
|
|
691
|
+
TextureMinificationFilter.NEAREST_MIPMAP_NEAREST,
|
|
692
|
+
TextureMinificationFilter.NEAREST_MIPMAP_LINEAR,
|
|
693
|
+
TextureMinificationFilter.LINEAR_MIPMAP_NEAREST,
|
|
694
|
+
TextureMinificationFilter.LINEAR_MIPMAP_LINEAR,
|
|
695
|
+
].includes(minificationFilter);
|
|
696
|
+
|
|
697
|
+
const context = texture._context;
|
|
698
|
+
const pixelFormat = texture._pixelFormat;
|
|
699
|
+
const pixelDatatype = texture._pixelDatatype;
|
|
700
|
+
|
|
701
|
+
// float textures only support nearest filtering unless the linear extensions are supported
|
|
702
|
+
if (
|
|
703
|
+
(pixelDatatype === PixelDatatype.FLOAT && !context.textureFloatLinear) ||
|
|
704
|
+
(pixelDatatype === PixelDatatype.HALF_FLOAT &&
|
|
705
|
+
!context.textureHalfFloatLinear)
|
|
706
|
+
) {
|
|
707
|
+
// override the sampler's settings
|
|
708
|
+
minificationFilter = mipmap
|
|
709
|
+
? TextureMinificationFilter.NEAREST_MIPMAP_NEAREST
|
|
710
|
+
: TextureMinificationFilter.NEAREST;
|
|
711
|
+
magnificationFilter = TextureMagnificationFilter.NEAREST;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// WebGL 2 depth texture only support nearest filtering. See section 3.8.13 OpenGL ES 3 spec
|
|
715
|
+
if (context.webgl2) {
|
|
716
|
+
if (PixelFormat.isDepthFormat(pixelFormat)) {
|
|
717
|
+
minificationFilter = TextureMinificationFilter.NEAREST;
|
|
718
|
+
magnificationFilter = TextureMagnificationFilter.NEAREST;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
const gl = context._gl;
|
|
723
|
+
const target = texture._textureTarget;
|
|
724
|
+
|
|
725
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
726
|
+
gl.bindTexture(target, texture._texture);
|
|
727
|
+
gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, minificationFilter);
|
|
728
|
+
gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, magnificationFilter);
|
|
729
|
+
gl.texParameteri(target, gl.TEXTURE_WRAP_S, sampler.wrapS);
|
|
730
|
+
gl.texParameteri(target, gl.TEXTURE_WRAP_T, sampler.wrapT);
|
|
731
|
+
if (defined(texture._textureFilterAnisotropic)) {
|
|
732
|
+
gl.texParameteri(
|
|
733
|
+
target,
|
|
734
|
+
texture._textureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT,
|
|
735
|
+
sampler.maximumAnisotropy
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
gl.bindTexture(target, null);
|
|
739
|
+
}
|
|
740
|
+
|
|
648
741
|
/**
|
|
649
742
|
* Copy new image data into this texture, from a source {@link ImageData}, {@link HTMLImageElement}, {@link HTMLCanvasElement}, or {@link HTMLVideoElement}.
|
|
650
743
|
* or an object with width, height, and arrayBufferView properties.
|
|
@@ -677,11 +770,15 @@ Texture.prototype.copyFrom = function (options) {
|
|
|
677
770
|
Check.defined("options", options);
|
|
678
771
|
//>>includeEnd('debug');
|
|
679
772
|
|
|
680
|
-
const
|
|
681
|
-
|
|
773
|
+
const {
|
|
774
|
+
xOffset = 0,
|
|
775
|
+
yOffset = 0,
|
|
776
|
+
source,
|
|
777
|
+
skipColorSpaceConversion = false,
|
|
778
|
+
} = options;
|
|
682
779
|
|
|
683
780
|
//>>includeStart('debug', pragmas.debug);
|
|
684
|
-
Check.defined("options.source",
|
|
781
|
+
Check.defined("options.source", source);
|
|
685
782
|
if (PixelFormat.isDepthFormat(this._pixelFormat)) {
|
|
686
783
|
throw new DeveloperError(
|
|
687
784
|
"Cannot call copyFrom when the texture pixel format is DEPTH_COMPONENT or DEPTH_STENCIL."
|
|
@@ -696,18 +793,16 @@ Texture.prototype.copyFrom = function (options) {
|
|
|
696
793
|
Check.typeOf.number.greaterThanOrEquals("yOffset", yOffset, 0);
|
|
697
794
|
Check.typeOf.number.lessThanOrEquals(
|
|
698
795
|
"xOffset + options.source.width",
|
|
699
|
-
xOffset +
|
|
796
|
+
xOffset + source.width,
|
|
700
797
|
this._width
|
|
701
798
|
);
|
|
702
799
|
Check.typeOf.number.lessThanOrEquals(
|
|
703
800
|
"yOffset + options.source.height",
|
|
704
|
-
yOffset +
|
|
801
|
+
yOffset + source.height,
|
|
705
802
|
this._height
|
|
706
803
|
);
|
|
707
804
|
//>>includeEnd('debug');
|
|
708
805
|
|
|
709
|
-
const source = options.source;
|
|
710
|
-
|
|
711
806
|
const context = this._context;
|
|
712
807
|
const gl = context._gl;
|
|
713
808
|
const target = this._textureTarget;
|
|
@@ -715,9 +810,7 @@ Texture.prototype.copyFrom = function (options) {
|
|
|
715
810
|
gl.activeTexture(gl.TEXTURE0);
|
|
716
811
|
gl.bindTexture(target, this._texture);
|
|
717
812
|
|
|
718
|
-
const width = source
|
|
719
|
-
const height = source.height;
|
|
720
|
-
let arrayBufferView = source.arrayBufferView;
|
|
813
|
+
const { width, height, arrayBufferView } = source;
|
|
721
814
|
|
|
722
815
|
const textureWidth = this._width;
|
|
723
816
|
const textureHeight = this._height;
|
|
@@ -727,10 +820,6 @@ Texture.prototype.copyFrom = function (options) {
|
|
|
727
820
|
|
|
728
821
|
const preMultiplyAlpha = this._preMultiplyAlpha;
|
|
729
822
|
const flipY = this._flipY;
|
|
730
|
-
const skipColorSpaceConversion = defaultValue(
|
|
731
|
-
options.skipColorSpaceConversion,
|
|
732
|
-
false
|
|
733
|
-
);
|
|
734
823
|
|
|
735
824
|
let unpackAlignment = 4;
|
|
736
825
|
if (defined(arrayBufferView)) {
|
|
@@ -740,7 +829,6 @@ Texture.prototype.copyFrom = function (options) {
|
|
|
740
829
|
width
|
|
741
830
|
);
|
|
742
831
|
}
|
|
743
|
-
|
|
744
832
|
gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);
|
|
745
833
|
|
|
746
834
|
if (skipColorSpaceConversion) {
|
|
@@ -754,6 +842,7 @@ Texture.prototype.copyFrom = function (options) {
|
|
|
754
842
|
|
|
755
843
|
let uploaded = false;
|
|
756
844
|
if (!this._initialized) {
|
|
845
|
+
let pixels;
|
|
757
846
|
if (
|
|
758
847
|
xOffset === 0 &&
|
|
759
848
|
yOffset === 0 &&
|
|
@@ -764,108 +853,83 @@ Texture.prototype.copyFrom = function (options) {
|
|
|
764
853
|
if (defined(arrayBufferView)) {
|
|
765
854
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
766
855
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
767
|
-
|
|
768
856
|
if (flipY) {
|
|
769
|
-
|
|
857
|
+
pixels = PixelFormat.flipY(
|
|
770
858
|
arrayBufferView,
|
|
771
859
|
pixelFormat,
|
|
772
860
|
pixelDatatype,
|
|
773
861
|
textureWidth,
|
|
774
862
|
textureHeight
|
|
775
863
|
);
|
|
864
|
+
} else {
|
|
865
|
+
pixels = arrayBufferView;
|
|
776
866
|
}
|
|
777
|
-
gl.texImage2D(
|
|
778
|
-
target,
|
|
779
|
-
0,
|
|
780
|
-
internalFormat,
|
|
781
|
-
textureWidth,
|
|
782
|
-
textureHeight,
|
|
783
|
-
0,
|
|
784
|
-
pixelFormat,
|
|
785
|
-
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
786
|
-
arrayBufferView
|
|
787
|
-
);
|
|
788
867
|
} else {
|
|
789
868
|
// Only valid for DOM-Element uploads
|
|
790
869
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
|
|
791
870
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
|
|
792
|
-
|
|
793
|
-
gl.texImage2D(
|
|
794
|
-
target,
|
|
795
|
-
0,
|
|
796
|
-
internalFormat,
|
|
797
|
-
pixelFormat,
|
|
798
|
-
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
799
|
-
source
|
|
800
|
-
);
|
|
871
|
+
pixels = source;
|
|
801
872
|
}
|
|
802
873
|
uploaded = true;
|
|
803
874
|
} else {
|
|
804
875
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
805
876
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
806
|
-
|
|
807
877
|
// initialize the entire texture to zero
|
|
808
|
-
|
|
878
|
+
pixels = PixelFormat.createTypedArray(
|
|
809
879
|
pixelFormat,
|
|
810
880
|
pixelDatatype,
|
|
811
881
|
textureWidth,
|
|
812
882
|
textureHeight
|
|
813
883
|
);
|
|
814
|
-
gl.texImage2D(
|
|
815
|
-
target,
|
|
816
|
-
0,
|
|
817
|
-
internalFormat,
|
|
818
|
-
textureWidth,
|
|
819
|
-
textureHeight,
|
|
820
|
-
0,
|
|
821
|
-
pixelFormat,
|
|
822
|
-
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
823
|
-
bufferView
|
|
824
|
-
);
|
|
825
884
|
}
|
|
885
|
+
gl.texImage2D(
|
|
886
|
+
target,
|
|
887
|
+
0,
|
|
888
|
+
internalFormat,
|
|
889
|
+
textureWidth,
|
|
890
|
+
textureHeight,
|
|
891
|
+
0,
|
|
892
|
+
pixelFormat,
|
|
893
|
+
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
894
|
+
pixels
|
|
895
|
+
);
|
|
826
896
|
this._initialized = true;
|
|
827
897
|
}
|
|
828
898
|
|
|
829
899
|
if (!uploaded) {
|
|
900
|
+
let pixels;
|
|
830
901
|
if (defined(arrayBufferView)) {
|
|
831
902
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
832
903
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
833
904
|
|
|
834
905
|
if (flipY) {
|
|
835
|
-
|
|
906
|
+
pixels = PixelFormat.flipY(
|
|
836
907
|
arrayBufferView,
|
|
837
908
|
pixelFormat,
|
|
838
909
|
pixelDatatype,
|
|
839
910
|
width,
|
|
840
911
|
height
|
|
841
912
|
);
|
|
913
|
+
} else {
|
|
914
|
+
pixels = arrayBufferView;
|
|
842
915
|
}
|
|
843
|
-
gl.texSubImage2D(
|
|
844
|
-
target,
|
|
845
|
-
0,
|
|
846
|
-
xOffset,
|
|
847
|
-
yOffset,
|
|
848
|
-
width,
|
|
849
|
-
height,
|
|
850
|
-
pixelFormat,
|
|
851
|
-
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
852
|
-
arrayBufferView
|
|
853
|
-
);
|
|
854
916
|
} else {
|
|
855
917
|
// Only valid for DOM-Element uploads
|
|
856
918
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
|
|
857
919
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
|
|
858
|
-
|
|
859
|
-
gl.texSubImage2D(
|
|
860
|
-
target,
|
|
861
|
-
0,
|
|
862
|
-
xOffset,
|
|
863
|
-
yOffset,
|
|
864
|
-
pixelFormat,
|
|
865
|
-
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
866
|
-
source
|
|
867
|
-
);
|
|
920
|
+
pixels = source;
|
|
868
921
|
}
|
|
922
|
+
gl.texSubImage2D(
|
|
923
|
+
target,
|
|
924
|
+
0,
|
|
925
|
+
xOffset,
|
|
926
|
+
yOffset,
|
|
927
|
+
width,
|
|
928
|
+
height,
|
|
929
|
+
pixelFormat,
|
|
930
|
+
PixelDatatype.toWebGLConstant(pixelDatatype, context),
|
|
931
|
+
pixels
|
|
932
|
+
);
|
|
869
933
|
}
|
|
870
934
|
|
|
871
935
|
gl.bindTexture(target, null);
|