@openglobus/og 0.17.1 → 0.18.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/README.md +75 -46
- package/dist/@openglobus/og.esm.js +1 -20
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +1 -20
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/dist/@openglobus/res/fonts/Karla-Bold.json +5252 -0
- package/dist/@openglobus/res/fonts/Karla-Bold.ttf.cfg +920 -0
- package/dist/@openglobus/res/fonts/Karla-Bold.ttf.png +0 -0
- package/dist/@openglobus/res/fonts/Karla-Light.json +5252 -0
- package/dist/@openglobus/res/fonts/Karla-Light.ttf.cfg +830 -0
- package/dist/@openglobus/res/fonts/Karla-Light.ttf.png +0 -0
- package/dist/@openglobus/res/fonts/Karla-Medium.json +5252 -0
- package/dist/@openglobus/res/fonts/Karla-Medium.ttf.cfg +1196 -0
- package/dist/@openglobus/res/fonts/Karla-Medium.ttf.png +0 -0
- package/dist/@openglobus/res/fonts/NotoSansArabic-Regular.json +3332 -0
- package/dist/@openglobus/res/fonts/NotoSansArabic-Regular.ttf.cfg +1370 -0
- package/dist/@openglobus/res/fonts/NotoSansArabic-Regular.ttf.png +0 -0
- package/dist/@openglobus/res/fonts/Roboto-Regular.json +37147 -0
- package/dist/@openglobus/res/fonts/Roboto-Regular.ttf.cfg +1340 -0
- package/dist/@openglobus/res/fonts/Roboto-Regular.ttf.png +0 -0
- package/dist/@openglobus/res/fonts/arial.json +4321 -0
- package/dist/@openglobus/res/fonts/arial.ttf.cfg +1570 -0
- package/dist/@openglobus/res/fonts/arial.ttf.png +0 -0
- package/dist/@openglobus/res/night-4326.png +0 -0
- package/dist/@openglobus/res/night.png +0 -0
- package/dist/@openglobus/res/spec.png +0 -0
- package/package.json +25 -23
- package/src/{og/Clock.js → Clock.ts} +100 -78
- package/src/Deferred.ts +17 -0
- package/src/Events.ts +200 -0
- package/src/{og/Extent.js → Extent.ts} +324 -352
- package/src/Globe.ts +363 -0
- package/src/{og/ImageCanvas.js → ImageCanvas.ts} +244 -236
- package/src/Lock.ts +41 -0
- package/src/{og/LonLat.js → LonLat.ts} +50 -47
- package/src/{og/Object3d.js → Object3d.ts} +89 -55
- package/src/Popup.ts +228 -0
- package/src/{og/QueueArray.js → QueueArray.ts} +76 -75
- package/src/{og/Rectangle.js → Rectangle.ts} +115 -111
- package/src/Stack.ts +58 -0
- package/src/{og/astro/astro.js → astro/astro.ts} +49 -51
- package/src/{og/astro/earth.js → astro/earth.ts} +8 -9
- package/src/{og/astro/jd.js → astro/jd.ts} +92 -111
- package/src/{og/astro/orbit.js → astro/orbit.ts} +35 -37
- package/src/{og/astro/rotation.js → astro/rotation.ts} +4 -6
- package/src/{og/bv/Box.js → bv/Box.ts} +21 -17
- package/src/{og/bv/Sphere.js → bv/Sphere.ts} +21 -19
- package/src/bv/index.ts +4 -0
- package/src/{og/camera/Camera.js → camera/Camera.ts} +254 -197
- package/src/{og/camera/Frustum.js → camera/Frustum.ts} +137 -111
- package/src/{og/camera/PlanetCamera.js → camera/PlanetCamera.ts} +248 -185
- package/src/camera/index.ts +4 -0
- package/src/{og/cons.js → cons.ts} +14 -18
- package/src/{og/control/Atmosphere.js → control/Atmosphere.ts} +50 -50
- package/src/{og/control/CompassButton.js → control/CompassButton.ts} +27 -30
- package/src/{og/control/Control.js → control/Control.ts} +76 -70
- package/src/{og/control/DebugInfo.js → control/DebugInfo.ts} +130 -62
- package/src/{og/control/DrawingSwitcher.js → control/DrawingSwitcher.ts} +16 -22
- package/src/control/EarthCoordinates.ts +222 -0
- package/src/control/EarthNavigation.ts +293 -0
- package/src/{og/control/GeoImageDragControl.js → control/GeoImageDragControl.ts} +37 -29
- package/src/control/KeyboardNavigation.ts +168 -0
- package/src/{og/control/LayerAnimation.js → control/LayerAnimation.ts} +74 -90
- package/src/control/LayerSwitcher.ts +76 -0
- package/src/{og/control/Lighting.js → control/Lighting.ts} +158 -120
- package/src/control/MouseNavigation.ts +468 -0
- package/src/control/MouseWheelZoomControl.ts +269 -0
- package/src/{og/control/RulerSwitcher.js → control/RulerSwitcher.ts} +18 -20
- package/src/control/ScaleControl.ts +131 -0
- package/src/control/SegmentBoundVisualization.ts +50 -0
- package/src/control/ShowFps.ts +28 -0
- package/src/control/SimpleNavigation.ts +118 -0
- package/src/{og/control/SimpleSkyBackground.js → control/SimpleSkyBackground.ts} +36 -38
- package/src/{og/control/Sun.js → control/Sun.ts} +56 -64
- package/src/control/ToggleWireframe.ts +35 -0
- package/src/control/TouchNavigation.ts +368 -0
- package/src/control/ZoomControl.ts +111 -0
- package/src/control/drawing/DrawingControl.ts +45 -0
- package/src/{og/control/drawing/LineStringDrawingScene.js → control/drawing/LineStringDrawingScene.ts} +28 -35
- package/src/{og/control/drawing/PolygonDrawingScene.js → control/drawing/PolygonDrawingScene.ts} +148 -201
- package/src/{og/control/elevationProfile/ElevationProfile.js → control/elevationProfile/ElevationProfile.ts} +70 -36
- package/src/control/heightRuler/HeightRuler.ts +16 -0
- package/src/{og/control/heightRuler/HeightRulerScene.js → control/heightRuler/HeightRulerScene.ts} +92 -87
- package/src/{og/control/heightRuler/HeightRulerSwitcher.js → control/heightRuler/HeightRulerSwitcher.ts} +3 -3
- package/src/control/index.ts +45 -0
- package/src/control/ruler/Ruler.ts +35 -0
- package/src/{og/control/ruler/RulerScene.js → control/ruler/RulerScene.ts} +163 -121
- package/src/{og/control/selection/Selection.js → control/selection/Selection.ts} +23 -21
- package/src/{og/control/selection/SelectionScene.js → control/selection/SelectionScene.ts} +64 -50
- package/src/{og/control/timeline/TimelineControl.js → control/timeline/TimelineControl.ts} +37 -28
- package/src/{og/control/timeline/TimelineModel.js → control/timeline/TimelineModel.ts} +50 -35
- package/src/{og/control/timeline/TimelineView.js → control/timeline/TimelineView.ts} +162 -113
- package/src/{og/control/timeline/timelineUtils.js → control/timeline/timelineUtils.ts} +11 -10
- package/src/{og/control → control}/visibleExtent/Segment.js +5 -5
- package/src/{og/control → control}/visibleExtent/VisibleExtent.js +8 -15
- package/src/{og/control/visibleExtent/drawnode.js → control/visibleExtent/drawnode.ts} +1 -3
- package/src/{og/ellipsoid/Ellipsoid.js → ellipsoid/Ellipsoid.ts} +113 -59
- package/src/ellipsoid/index.ts +4 -0
- package/src/{og/ellipsoid/wgs84.js → ellipsoid/wgs84.ts} +1 -3
- package/src/{og/entity/BaseBillboard.js → entity/BaseBillboard.ts} +128 -102
- package/src/entity/BaseBillboardHandler.ts +772 -0
- package/src/{og/entity/Billboard.js → entity/Billboard.ts} +77 -47
- package/src/entity/BillboardHandler.ts +135 -0
- package/src/{og/entity/Entity.js → entity/Entity.ts} +285 -226
- package/src/{og/entity/EntityCollection.js → entity/EntityCollection.ts} +340 -247
- package/src/{og/entity/GeoObject.js → entity/GeoObject.ts} +122 -67
- package/src/{og/entity/GeoObjectHandler.js → entity/GeoObjectHandler.ts} +273 -198
- package/src/entity/Geometry.ts +486 -0
- package/src/{og/entity/GeometryHandler.js → entity/GeometryHandler.ts} +383 -541
- package/src/{og/entity/Label.js → entity/Label.ts} +131 -83
- package/src/{og/entity/LabelHandler.js → entity/LabelHandler.ts} +289 -255
- package/src/{og/entity/LabelWorker.js → entity/LabelWorker.ts} +26 -36
- package/src/{og/entity/PointCloud.js → entity/PointCloud.ts} +200 -164
- package/src/entity/PointCloudHandler.ts +125 -0
- package/src/{og/entity/Polyline.js → entity/Polyline.ts} +517 -539
- package/src/{og/entity/PolylineHandler.js → entity/PolylineHandler.ts} +29 -31
- package/src/{og/entity/Ray.js → entity/Ray.ts} +89 -60
- package/src/{og/entity/RayHandler.js → entity/RayHandler.ts} +201 -306
- package/src/{og/entity/Strip.js → entity/Strip.ts} +143 -100
- package/src/{og/entity/StripHandler.js → entity/StripHandler.ts} +76 -72
- package/src/entity/index.ts +12 -0
- package/src/index.ts +173 -0
- package/src/input/KeyboardHandler.ts +196 -0
- package/src/{og/input/MouseHandler.js → input/MouseHandler.ts} +46 -35
- package/src/input/TouchHandler.ts +54 -0
- package/src/{og/input/input.js → input/input.ts} +1 -3
- package/src/{og/layer/BaseGeoImage.js → layer/BaseGeoImage.ts} +174 -107
- package/src/{og/layer/CanvasTiles.js → layer/CanvasTiles.ts} +139 -105
- package/src/{og/layer/GeoImage.js → layer/GeoImage.ts} +62 -52
- package/src/layer/GeoTexture2d.ts +56 -0
- package/src/{og/layer/GeoVideo.js → layer/GeoVideo.ts} +53 -53
- package/src/{og/layer/KML.js → layer/KML.ts} +63 -74
- package/src/{og/layer/Layer.js → layer/Layer.ts} +399 -223
- package/src/{og/layer/Material.js → layer/Material.ts} +40 -35
- package/src/{og/layer/Vector.js → layer/Vector.ts} +319 -267
- package/src/{og/layer/WMS.js → layer/WMS.ts} +76 -64
- package/src/{og/layer/XYZ.js → layer/XYZ.ts} +123 -98
- package/src/layer/index.ts +12 -0
- package/src/{og/light/LightSource.js → light/LightSource.ts} +132 -93
- package/src/{og/math/Line2.js → math/Line2.ts} +11 -8
- package/src/{og/math/Line3.js → math/Line3.ts} +49 -27
- package/src/{og/math/Mat3.js → math/Mat3.ts} +43 -27
- package/src/{og/math/Mat4.js → math/Mat4.ts} +110 -77
- package/src/{og/math/Plane.js → math/Plane.ts} +28 -23
- package/src/{og/math/Quat.js → math/Quat.ts} +238 -222
- package/src/{og/math/Ray.js → math/Ray.ts} +59 -63
- package/src/{og/math/Vec2.js → math/Vec2.ts} +85 -76
- package/src/{og/math/Vec3.js → math/Vec3.ts} +141 -140
- package/src/{og/math/Vec4.js → math/Vec4.ts} +64 -53
- package/src/{og/math/coder.js → math/coder.ts} +30 -27
- package/src/math/index.ts +26 -0
- package/src/{og/math.js → math.ts} +46 -49
- package/src/{og/mercator.js → mercator.ts} +143 -149
- package/src/{og/proj/EPSG3857.js → proj/EPSG3857.ts} +1 -3
- package/src/{og/proj/EPSG4326.js → proj/EPSG4326.ts} +11 -13
- package/src/{og/proj/Proj.js → proj/Proj.ts} +27 -23
- package/src/{og/quadTree/EPSG4326QuadTreeStrategy.js → quadTree/EPSG4326QuadTreeStrategy.ts} +10 -13
- package/src/{og/quadTree/EarthQuadTreeStrategy.js → quadTree/EarthQuadTreeStrategy.ts} +11 -13
- package/src/quadTree/EntityCollectionNode.ts +395 -0
- package/src/{og/quadTree/MarsQuadTreeStrategy.js → quadTree/MarsQuadTreeStrategy.ts} +10 -13
- package/src/{og/quadTree/Node.js → quadTree/Node.ts} +283 -191
- package/src/{og/quadTree/QuadTreeStrategy.js → quadTree/QuadTreeStrategy.ts} +35 -29
- package/src/quadTree/Wgs84QuadTreeStrategy.ts +22 -0
- package/src/quadTree/index.ts +14 -0
- package/src/{og/quadTree/quadTree.js → quadTree/quadTree.ts} +75 -77
- package/src/{og/renderer/Renderer.js → renderer/Renderer.ts} +454 -298
- package/src/{og/renderer/RendererEvents.js → renderer/RendererEvents.ts} +347 -270
- package/src/{og/scene/Axes.js → scene/Axes.ts} +26 -22
- package/src/{og/scene/BaseNode.js → scene/BaseNode.ts} +53 -47
- package/src/{og/scene/Planet.js → scene/Planet.ts} +777 -595
- package/src/{og/scene/RenderNode.js → scene/RenderNode.ts} +105 -91
- package/src/{og/scene/SkyBox.js → scene/SkyBox.ts} +29 -25
- package/src/scene/index.ts +6 -0
- package/src/{og/segment/Segment.js → segment/Segment.ts} +497 -371
- package/src/{og/segment/SegmentLonLat.js → segment/SegmentLonLat.ts} +81 -87
- package/src/{og/segment/SegmentLonLatWgs84.js → segment/SegmentLonLatWgs84.ts} +9 -16
- package/src/{og/segment/Slice.js → segment/Slice.ts} +15 -9
- package/src/{og/segment/segmentHelper.js → segment/segmentHelper.ts} +57 -49
- package/src/{og/shaders/atmos.js → shaders/atmos.ts} +4 -6
- package/src/{og/shaders/billboard.js → shaders/billboard.ts} +3 -5
- package/src/{og/shaders/bloom.js → shaders/bloom.ts} +2 -4
- package/src/{og/shaders/blur.js → shaders/blur.ts} +4 -7
- package/src/{og/shaders/depth.js → shaders/depth.ts} +1 -3
- package/src/{og/shaders/drawnode.js → shaders/drawnode.ts} +19 -21
- package/src/{og/shaders/geoObject.js → shaders/geoObject.ts} +17 -19
- package/src/{og/shaders/label.js → shaders/label.ts} +4 -6
- package/src/{og/shaders/lumFilter.js → shaders/lumFilter.ts} +2 -4
- package/src/{og/shaders/pickingMask.js → shaders/pickingMask.ts} +2 -4
- package/src/{og/shaders/pointCloud.js → shaders/pointCloud.ts} +7 -10
- package/src/{og/shaders/polyline.js → shaders/polyline.ts} +3 -200
- package/src/{og/shaders/ray.js → shaders/ray.ts} +2 -4
- package/src/{og/shaders/screenFrame.js → shaders/screenFrame.ts} +2 -4
- package/src/{og/shaders/skybox.js → shaders/skybox.ts} +7 -9
- package/src/{og/shaders/toneMapping.js → shaders/toneMapping.ts} +2 -4
- package/src/{og/shaders/utils.js → shaders/utils.ts} +0 -2
- package/src/{og/terrain/BilTerrain.js → terrain/BilTerrain.ts} +38 -32
- package/src/terrain/EmptyTerrain.ts +230 -0
- package/src/{og/terrain/Geoid.js → terrain/Geoid.ts} +67 -41
- package/src/{og/terrain/GlobusTerrain.js → terrain/GlobusTerrain.ts} +159 -153
- package/src/{og/terrain/MapboxTerrain.js → terrain/MapboxTerrain.ts} +58 -61
- package/src/terrain/index.ts +6 -0
- package/src/ui/Button.ts +121 -0
- package/src/ui/ButtonGroup.ts +63 -0
- package/src/ui/Dialog.ts +244 -0
- package/src/ui/Slider.ts +188 -0
- package/src/ui/ToggleButton.ts +68 -0
- package/src/{og/ui/View.js → ui/View.ts} +66 -59
- package/src/utils/BaseWorker.ts +60 -0
- package/src/utils/FontAtlas.ts +356 -0
- package/src/{og/utils/GeoImageCreator.js → utils/GeoImageCreator.ts} +45 -29
- package/src/{og/utils/ImagesCacheManager.js → utils/ImagesCacheManager.ts} +85 -70
- package/src/utils/Loader.ts +247 -0
- package/src/{og/utils/NormalMapCreator.js → utils/NormalMapCreator.ts} +114 -77
- package/src/{og/utils/PlainSegmentWorker.js → utils/PlainSegmentWorker.ts} +41 -24
- package/src/{og/utils/TerrainWorker.js → utils/TerrainWorker.ts} +51 -36
- package/src/utils/TextureAtlas.ts +322 -0
- package/src/{og/utils/VectorTileCreator.js → utils/VectorTileCreator.ts} +67 -52
- package/src/{og/utils/colorTable.js → utils/colorTable.ts} +142 -144
- package/src/{og/utils/earcut.js → utils/earcut.ts} +664 -661
- package/src/{og/utils/objParser.js → utils/objParser.ts} +66 -37
- package/src/{og/utils/shared.js → utils/shared.ts} +267 -206
- package/src/utils/units.ts +78 -0
- package/src/webgl/BaseFramebuffer.ts +125 -0
- package/src/webgl/Framebuffer.ts +206 -0
- package/src/webgl/Handler.ts +1414 -0
- package/src/webgl/Multisample.ts +153 -0
- package/src/webgl/Program.ts +451 -0
- package/src/{og/webgl/ProgramController.js → webgl/ProgramController.ts} +44 -43
- package/src/webgl/index.ts +13 -0
- package/src/{og/webgl/types.js → webgl/types.ts} +29 -31
- package/src/webgl/variableHandlers.ts +114 -0
- package/src/og/Deferred.js +0 -11
- package/src/og/Events.js +0 -185
- package/src/og/Globe.js +0 -342
- package/src/og/Lock.js +0 -44
- package/src/og/Popup.js +0 -187
- package/src/og/Stack.js +0 -49
- package/src/og/bv/index.js +0 -4
- package/src/og/camera/index.js +0 -4
- package/src/og/control/EarthCoordinates.js +0 -214
- package/src/og/control/EarthNavigation.js +0 -258
- package/src/og/control/KeyboardNavigation.js +0 -149
- package/src/og/control/LayerSwitcher.js +0 -424
- package/src/og/control/MouseNavigation.js +0 -436
- package/src/og/control/MouseWheelZoomControl.js +0 -253
- package/src/og/control/ScaleControl.js +0 -119
- package/src/og/control/SegmentBoundVisualization.js +0 -54
- package/src/og/control/ShowFps.js +0 -40
- package/src/og/control/SimpleNavigation.js +0 -123
- package/src/og/control/ToggleWireframe.js +0 -35
- package/src/og/control/TouchNavigation.js +0 -350
- package/src/og/control/ZoomControl.js +0 -115
- package/src/og/control/drawing/DrawingControl.js +0 -51
- package/src/og/control/heightRuler/HeightRuler.js +0 -12
- package/src/og/control/index.js +0 -56
- package/src/og/control/ruler/Ruler.js +0 -39
- package/src/og/ellipsoid/index.js +0 -4
- package/src/og/entity/BillboardHandler.js +0 -883
- package/src/og/entity/Geometry.js +0 -320
- package/src/og/entity/PointCloudHandler.js +0 -122
- package/src/og/entity/index.js +0 -9
- package/src/og/index.js +0 -112
- package/src/og/input/KeyboardHandler.js +0 -128
- package/src/og/input/TouchHandler.js +0 -59
- package/src/og/layer/GeoTexture2d.js +0 -50
- package/src/og/layer/index.js +0 -11
- package/src/og/math/index.js +0 -23
- package/src/og/quadTree/EntityCollectionNode.js +0 -391
- package/src/og/quadTree/Wgs84QuadTreeStrategy.js +0 -27
- package/src/og/quadTree/index.js +0 -14
- package/src/og/res/images.js +0 -8
- package/src/og/scene/index.js +0 -5
- package/src/og/terrain/EmptyTerrain.js +0 -174
- package/src/og/terrain/index.js +0 -6
- package/src/og/ui/Button.js +0 -107
- package/src/og/ui/ButtonGroup.js +0 -57
- package/src/og/ui/Dialog.js +0 -239
- package/src/og/ui/Slider.js +0 -170
- package/src/og/ui/ToggleButton.js +0 -51
- package/src/og/ui/UIhelpers.js +0 -155
- package/src/og/utils/BaseWorker.js +0 -46
- package/src/og/utils/FontAtlas.js +0 -218
- package/src/og/utils/Loader.js +0 -188
- package/src/og/utils/TextureAtlas.js +0 -291
- package/src/og/utils/functionComposition.js +0 -13
- package/src/og/utils/units.js +0 -78
- package/src/og/webgl/Framebuffer.js +0 -311
- package/src/og/webgl/Handler.js +0 -1168
- package/src/og/webgl/Multisample.js +0 -275
- package/src/og/webgl/Program.js +0 -407
- package/src/og/webgl/callbacks.js +0 -98
- package/src/og/webgl/index.js +0 -13
- package/src/og.jsdoc +0 -3
- package/types/Clock.d.ts +0 -99
- package/types/Deferred.d.ts +0 -6
- package/types/Events.d.ts +0 -78
- package/types/Extent.d.ts +0 -166
- package/types/Globe.d.ts +0 -108
- package/types/ImageCanvas.d.ts +0 -128
- package/types/Lock.d.ts +0 -12
- package/types/LonLat.d.ts +0 -127
- package/types/Object3d.d.ts +0 -35
- package/types/Popup.d.ts +0 -29
- package/types/QueueArray.d.ts +0 -19
- package/types/Rectangle.d.ts +0 -80
- package/types/Stack.d.ts +0 -19
- package/types/arial.d.ts +0 -49
- package/types/astro/astro.d.ts +0 -38
- package/types/astro/earth.d.ts +0 -7
- package/types/astro/jd.d.ts +0 -254
- package/types/bv/Box.d.ts +0 -30
- package/types/bv/Sphere.d.ts +0 -38
- package/types/bv/index.d.ts +0 -3
- package/types/camera/Camera.d.ts +0 -314
- package/types/camera/Frustum.d.ts +0 -133
- package/types/camera/PlanetCamera.d.ts +0 -219
- package/types/camera/index.d.ts +0 -3
- package/types/cons.d.ts +0 -40
- package/types/control/Atmosphere.d.ts +0 -15
- package/types/control/CompassButton.d.ts +0 -16
- package/types/control/Control.d.ts +0 -104
- package/types/control/DebugInfo.d.ts +0 -19
- package/types/control/DrawingSwitcher.d.ts +0 -13
- package/types/control/EarthCoordinates.d.ts +0 -44
- package/types/control/EarthNavigation.d.ts +0 -43
- package/types/control/GeoImageDragControl.d.ts +0 -14
- package/types/control/KeyboardNavigation.d.ts +0 -24
- package/types/control/LayerAnimation.d.ts +0 -73
- package/types/control/LayerSwitcher.d.ts +0 -64
- package/types/control/Lighting.d.ts +0 -41
- package/types/control/MouseNavigation.d.ts +0 -49
- package/types/control/MouseWheelZoomControl.d.ts +0 -46
- package/types/control/ScaleControl.d.ts +0 -23
- package/types/control/ShowFps.d.ts +0 -11
- package/types/control/SimpleNavigation.d.ts +0 -26
- package/types/control/SimpleSkyBackground.d.ts +0 -15
- package/types/control/Sun.d.ts +0 -53
- package/types/control/ToggleWireframe.d.ts +0 -12
- package/types/control/TouchNavigation.d.ts +0 -54
- package/types/control/ZoomControl.d.ts +0 -26
- package/types/control/drawing/DrawingControl.d.ts +0 -14
- package/types/control/drawing/LineStringDrawingScene.d.ts +0 -5
- package/types/control/drawing/PolygonDrawingScene.d.ts +0 -99
- package/types/control/heightRuler/HeightRuler.d.ts +0 -6
- package/types/control/heightRuler/HeightRulerScene.d.ts +0 -23
- package/types/control/index.d.ts +0 -27
- package/types/control/ruler/Ruler.d.ts +0 -13
- package/types/control/ruler/RulerScene.d.ts +0 -51
- package/types/control/selection/Selection.d.ts +0 -49
- package/types/control/selection/SelectionScene.d.ts +0 -32
- package/types/control/timeline/TimelineControl.d.ts +0 -10
- package/types/control/timeline/TimelineModel.d.ts +0 -33
- package/types/control/timeline/TimelineView.d.ts +0 -57
- package/types/control/timeline/timelineUtils.d.ts +0 -9
- package/types/ellipsoid/Ellipsoid.d.ts +0 -170
- package/types/ellipsoid/index.d.ts +0 -3
- package/types/ellipsoid/wgs84.d.ts +0 -6
- package/types/entity/BaseBillboard.d.ts +0 -215
- package/types/entity/Billboard.d.ts +0 -94
- package/types/entity/BillboardHandler.d.ts +0 -75
- package/types/entity/Entity.d.ts +0 -340
- package/types/entity/EntityCollection.d.ts +0 -303
- package/types/entity/GeoObject.d.ts +0 -117
- package/types/entity/GeoObjectHandler.d.ts +0 -41
- package/types/entity/Geometry.d.ts +0 -79
- package/types/entity/GeometryHandler.d.ts +0 -76
- package/types/entity/Label.d.ts +0 -190
- package/types/entity/LabelHandler.d.ts +0 -31
- package/types/entity/LabelWorker.d.ts +0 -9
- package/types/entity/PointCloud.d.ts +0 -174
- package/types/entity/PointCloudHandler.d.ts +0 -38
- package/types/entity/Polyline.d.ts +0 -307
- package/types/entity/PolylineHandler.d.ts +0 -18
- package/types/entity/Ray.d.ts +0 -122
- package/types/entity/RayHandler.d.ts +0 -63
- package/types/entity/Strip.d.ts +0 -119
- package/types/entity/StripHandler.d.ts +0 -38
- package/types/entity/index.d.ts +0 -8
- package/types/index.d.ts +0 -53
- package/types/input/KeyboardHandler.d.ts +0 -10
- package/types/input/MouseHandler.d.ts +0 -5
- package/types/input/TouchHandler.d.ts +0 -5
- package/types/input/input.d.ts +0 -42
- package/types/layer/BaseGeoImage.d.ts +0 -116
- package/types/layer/CanvasTiles.d.ts +0 -73
- package/types/layer/GeoImage.d.ts +0 -51
- package/types/layer/GeoTexture2d.d.ts +0 -7
- package/types/layer/GeoVideo.d.ts +0 -47
- package/types/layer/KML.d.ts +0 -93
- package/types/layer/Layer.d.ts +0 -320
- package/types/layer/Material.d.ts +0 -45
- package/types/layer/Vector.d.ts +0 -211
- package/types/layer/WMS.d.ts +0 -66
- package/types/layer/XYZ.d.ts +0 -122
- package/types/layer/index.d.ts +0 -10
- package/types/light/LightSource.d.ts +0 -178
- package/types/math/Line2.d.ts +0 -11
- package/types/math/Line3.d.ts +0 -10
- package/types/math/Mat3.d.ts +0 -65
- package/types/math/Mat4.d.ts +0 -176
- package/types/math/Plane.d.ts +0 -18
- package/types/math/Quat.d.ts +0 -379
- package/types/math/Ray.d.ts +0 -82
- package/types/math/Vec2.d.ts +0 -309
- package/types/math/Vec3.d.ts +0 -472
- package/types/math/Vec4.d.ts +0 -161
- package/types/math/coder.d.ts +0 -43
- package/types/math/index.d.ts +0 -11
- package/types/math.d.ts +0 -268
- package/types/mercator.d.ts +0 -92
- package/types/proj/EPSG3857.d.ts +0 -6
- package/types/proj/EPSG4326.d.ts +0 -6
- package/types/proj/Proj.d.ts +0 -42
- package/types/quadTree/EPSG4326QuadTreeStrategy.d.ts +0 -3
- package/types/quadTree/EarthQuadTreeStrategy.d.ts +0 -3
- package/types/quadTree/EntityCollectionNode.d.ts +0 -41
- package/types/quadTree/MarsQuadTreeStrategy.d.ts +0 -3
- package/types/quadTree/Node.d.ts +0 -58
- package/types/quadTree/QuadTreeStrategy.d.ts +0 -21
- package/types/quadTree/Wgs84QuadTreeStrategy.d.ts +0 -3
- package/types/quadTree/index.d.ts +0 -12
- package/types/quadTree/quadTree.d.ts +0 -40
- package/types/renderer/Renderer.d.ts +0 -291
- package/types/renderer/RendererEvents.d.ts +0 -255
- package/types/res/images.d.ts +0 -2
- package/types/scene/Axes.d.ts +0 -10
- package/types/scene/BaseNode.d.ts +0 -60
- package/types/scene/Planet.d.ts +0 -595
- package/types/scene/RenderNode.d.ts +0 -152
- package/types/scene/SkyBox.d.ts +0 -9
- package/types/scene/index.d.ts +0 -4
- package/types/segment/Segment.d.ts +0 -273
- package/types/segment/SegmentLonLat.d.ts +0 -22
- package/types/segment/SegmentLonLatWgs84.d.ts +0 -4
- package/types/segment/Slice.d.ts +0 -10
- package/types/segment/segmentHelper.d.ts +0 -13
- package/types/shaders/atmos.d.ts +0 -4
- package/types/shaders/billboard.d.ts +0 -3
- package/types/shaders/depth.d.ts +0 -2
- package/types/shaders/drawnode.d.ts +0 -8
- package/types/shaders/geoObject.d.ts +0 -3
- package/types/shaders/label.d.ts +0 -4
- package/types/shaders/pickingMask.d.ts +0 -2
- package/types/shaders/pointCloud.d.ts +0 -2
- package/types/shaders/polyline.d.ts +0 -3
- package/types/shaders/ray.d.ts +0 -2
- package/types/shaders/screenFrame.d.ts +0 -2
- package/types/shaders/skybox.d.ts +0 -2
- package/types/shaders/toneMapping.d.ts +0 -2
- package/types/shaders/utils.d.ts +0 -1
- package/types/terrain/BilTerrain.d.ts +0 -14
- package/types/terrain/EmptyTerrain.d.ts +0 -87
- package/types/terrain/Geoid.d.ts +0 -17
- package/types/terrain/GlobusTerrain.d.ts +0 -122
- package/types/terrain/MapboxTerrain.d.ts +0 -14
- package/types/terrain/index.d.ts +0 -5
- package/types/ui/Button.d.ts +0 -21
- package/types/ui/ButtonGroup.d.ts +0 -12
- package/types/ui/Dialog.d.ts +0 -41
- package/types/ui/Slider.d.ts +0 -33
- package/types/ui/ToggleButton.d.ts +0 -10
- package/types/ui/UIhelpers.d.ts +0 -13
- package/types/ui/View.d.ts +0 -33
- package/types/ui/icons.d.ts +0 -1
- package/types/utils/BaseWorker.d.ts +0 -14
- package/types/utils/FontAtlas.d.ts +0 -16
- package/types/utils/GeoImageCreator.d.ts +0 -30
- package/types/utils/ImagesCacheManager.d.ts +0 -10
- package/types/utils/Loader.d.ts +0 -31
- package/types/utils/NormalMapCreator.d.ts +0 -39
- package/types/utils/PlainSegmentWorker.d.ts +0 -8
- package/types/utils/TerrainWorker.d.ts +0 -7
- package/types/utils/TextureAtlas.d.ts +0 -113
- package/types/utils/VectorTileCreator.d.ts +0 -14
- package/types/utils/colorTable.d.ts +0 -143
- package/types/utils/earcut.d.ts +0 -6
- package/types/utils/functionComposition.d.ts +0 -5
- package/types/utils/objParser.d.ts +0 -8
- package/types/utils/shared.d.ts +0 -241
- package/types/utils/units.d.ts +0 -20
- package/types/webgl/Framebuffer.d.ts +0 -134
- package/types/webgl/Handler.d.ts +0 -403
- package/types/webgl/Multisample.d.ts +0 -91
- package/types/webgl/Program.d.ts +0 -163
- package/types/webgl/ProgramController.d.ts +0 -89
- package/types/webgl/callbacks.d.ts +0 -1
- package/types/webgl/index.d.ts +0 -6
- package/types/webgl/types.d.ts +0 -2
- /package/{src/og → dist/@openglobus/res/fonts}/arial.js +0 -0
- /package/src/{og/ui/icons.js → ui/icons.ts} +0 -0
|
@@ -0,0 +1,1414 @@
|
|
|
1
|
+
import {BaseFramebuffer} from "./BaseFramebuffer";
|
|
2
|
+
import {Clock} from "../Clock";
|
|
3
|
+
import {cons} from "../cons";
|
|
4
|
+
import {EventsHandler, createEvents} from "../Events";
|
|
5
|
+
import {getUrlParam, isEmpty, TypedArray} from "../utils/shared";
|
|
6
|
+
import {ImageCanvas} from "../ImageCanvas";
|
|
7
|
+
import {NumberArray2, Vec2} from "../math/Vec2";
|
|
8
|
+
import {ProgramController} from "./ProgramController";
|
|
9
|
+
import {Program} from "./Program";
|
|
10
|
+
import {Stack} from "../Stack";
|
|
11
|
+
|
|
12
|
+
export type WebGLContextExt = { type: string } & WebGL2RenderingContext;
|
|
13
|
+
export type WebGLBufferExt = { numItems: number; itemSize: number } & WebGLBuffer;
|
|
14
|
+
export type WebGLTextureExt = { default?: boolean } & WebGLTexture;
|
|
15
|
+
export type ImageSource = HTMLCanvasElement | ImageBitmap | ImageData | HTMLImageElement | HTMLVideoElement;
|
|
16
|
+
type CreateTextureFunc = (image: ImageSource, internalFormat?: number, texture?: WebGLTextureExt) => WebGLTextureExt | null;
|
|
17
|
+
|
|
18
|
+
export interface IHandlerParameters {
|
|
19
|
+
anisotropy?: number;
|
|
20
|
+
width?: number;
|
|
21
|
+
height?: number;
|
|
22
|
+
pixelRatio?: number;
|
|
23
|
+
context?: {
|
|
24
|
+
stencil?: boolean;
|
|
25
|
+
alpha?: boolean;
|
|
26
|
+
antialias?: boolean;
|
|
27
|
+
premultipliedAlpha?: boolean;
|
|
28
|
+
},
|
|
29
|
+
extensions?: string[];
|
|
30
|
+
autoActivate?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface Texture3DParams {
|
|
34
|
+
nx: string,
|
|
35
|
+
px: string,
|
|
36
|
+
py: string,
|
|
37
|
+
ny: string,
|
|
38
|
+
pz: string,
|
|
39
|
+
nz: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IDefaultTextureParams {
|
|
43
|
+
color?: string;
|
|
44
|
+
url?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const vendorPrefixes = ["", "WEBKIT_", "MOZ_"];
|
|
48
|
+
const CONTEXT_TYPE = ["webgl2", "webgl"];
|
|
49
|
+
|
|
50
|
+
// Maximal mipmap levels
|
|
51
|
+
const MAX_LEVELS = 2;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A WebGL handler for accessing low-level WebGL capabilities.
|
|
55
|
+
* @class
|
|
56
|
+
* @param {string | HTMLCanvasElement} canvasTarget - Canvas element target.
|
|
57
|
+
* or undefined creates hidden canvas and handler becomes hidden.
|
|
58
|
+
* @param {Object} [params] - Handler options:
|
|
59
|
+
* @param {number} [params.anisotropy] - Anisotropy filter degree. 8 is default.
|
|
60
|
+
* @param {number} [params.width] - Hidden handler width. 256 is default.
|
|
61
|
+
* @param {number} [params.height] - Hidden handler height. 256 is default.
|
|
62
|
+
* @param {Array.<string>} [params.extensions] - Additional WebGL extension list. Available by default: EXT_texture_filter_anisotropic.
|
|
63
|
+
*/
|
|
64
|
+
class Handler {
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Events.
|
|
68
|
+
* @public
|
|
69
|
+
* @type {EventsHandler<["visibilitychange", "resize"]>}
|
|
70
|
+
*/
|
|
71
|
+
public events: EventsHandler<["visibilitychange", "resize"]>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Application default timer.
|
|
75
|
+
* @public
|
|
76
|
+
* @type {Clock}
|
|
77
|
+
*/
|
|
78
|
+
public defaultClock: Clock;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Custom timers.
|
|
82
|
+
* @protected
|
|
83
|
+
* @type{Clock[]}
|
|
84
|
+
*/
|
|
85
|
+
protected _clocks: Clock[];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Draw frame time in milliseconds.
|
|
89
|
+
* @public
|
|
90
|
+
* @type {number}
|
|
91
|
+
*/
|
|
92
|
+
public deltaTime: number;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* WebGL rendering canvas element.
|
|
96
|
+
* @public
|
|
97
|
+
* @type {HTMLCanvasElement | null}
|
|
98
|
+
*/
|
|
99
|
+
public canvas: HTMLCanvasElement | null;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* WebGL context.
|
|
103
|
+
* @public
|
|
104
|
+
* @type {WebGLContextExt | null}
|
|
105
|
+
*/
|
|
106
|
+
public gl: WebGLContextExt | null;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Shader program controller list.
|
|
110
|
+
* @public
|
|
111
|
+
* @type {Record<string, ProgramController>}
|
|
112
|
+
*/
|
|
113
|
+
public programs: Record<string, ProgramController>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Current active shader program controller.
|
|
117
|
+
* @public
|
|
118
|
+
* @type {ProgramController}
|
|
119
|
+
*/
|
|
120
|
+
public activeProgram: ProgramController | null;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Handler parameters.
|
|
124
|
+
* @private
|
|
125
|
+
* @type {Object}
|
|
126
|
+
*/
|
|
127
|
+
protected _params: {
|
|
128
|
+
anisotropy: number;
|
|
129
|
+
width: number;
|
|
130
|
+
height: number;
|
|
131
|
+
pixelRatio: number;
|
|
132
|
+
context: {
|
|
133
|
+
stencil?: boolean;
|
|
134
|
+
alpha?: boolean;
|
|
135
|
+
antialias?: boolean;
|
|
136
|
+
premultipliedAlpha?: boolean;
|
|
137
|
+
};
|
|
138
|
+
extensions: string[];
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
public _oneByHeight: number;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Current WebGL extensions. Becomes here after context initialization.
|
|
145
|
+
* @public
|
|
146
|
+
* @type {Record<string, any>}
|
|
147
|
+
*/
|
|
148
|
+
public extensions: Record<string, any>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* HTML Canvas target.
|
|
152
|
+
* @private
|
|
153
|
+
* @type {string | HTMLCanvasElement | undefined}
|
|
154
|
+
*/
|
|
155
|
+
protected _canvasTarget: string | HTMLCanvasElement | undefined;
|
|
156
|
+
|
|
157
|
+
protected _lastAnimationFrameTime: number;
|
|
158
|
+
|
|
159
|
+
protected _initialized: boolean;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Animation frame function assigned from outside(Ex. from Renderer).
|
|
163
|
+
* @private
|
|
164
|
+
* @type {Function}
|
|
165
|
+
*/
|
|
166
|
+
protected _frameCallback: Function;
|
|
167
|
+
|
|
168
|
+
protected _canvasSize: NumberArray2;
|
|
169
|
+
|
|
170
|
+
public transparentTexture: WebGLTextureExt | null;
|
|
171
|
+
|
|
172
|
+
public defaultTexture: WebGLTextureExt | null;
|
|
173
|
+
|
|
174
|
+
public framebufferStack = new Stack<BaseFramebuffer>();
|
|
175
|
+
|
|
176
|
+
public createTexture: Record<string, CreateTextureFunc>;
|
|
177
|
+
|
|
178
|
+
public createTextureDefault: CreateTextureFunc;
|
|
179
|
+
|
|
180
|
+
public ONCANVASRESIZE: Function | null;
|
|
181
|
+
|
|
182
|
+
public createTexture_n: CreateTextureFunc;
|
|
183
|
+
public createTexture_l: CreateTextureFunc;
|
|
184
|
+
public createTexture_mm: CreateTextureFunc;
|
|
185
|
+
public createTexture_a: CreateTextureFunc;
|
|
186
|
+
|
|
187
|
+
public intersectionObserver?: IntersectionObserver;
|
|
188
|
+
public resizeObserver?: ResizeObserver;
|
|
189
|
+
|
|
190
|
+
protected _requestAnimationFrameId: number = 0;
|
|
191
|
+
|
|
192
|
+
constructor(canvasTarget: string | HTMLCanvasElement | undefined, params: IHandlerParameters = {}) {
|
|
193
|
+
|
|
194
|
+
this.events = createEvents<["visibilitychange", "resize"]>(["visibilitychange", "resize"]);
|
|
195
|
+
|
|
196
|
+
this.defaultClock = new Clock();
|
|
197
|
+
|
|
198
|
+
this._clocks = [];
|
|
199
|
+
|
|
200
|
+
this.deltaTime = 0;
|
|
201
|
+
|
|
202
|
+
this.canvas = null;
|
|
203
|
+
|
|
204
|
+
this.gl = null;
|
|
205
|
+
|
|
206
|
+
this.programs = {};
|
|
207
|
+
|
|
208
|
+
this.activeProgram = null;
|
|
209
|
+
|
|
210
|
+
this._canvasSize = [0, 0];
|
|
211
|
+
|
|
212
|
+
this._params = {
|
|
213
|
+
anisotropy: params.anisotropy || 4,
|
|
214
|
+
width: params.width || 256,
|
|
215
|
+
height: params.height || 256,
|
|
216
|
+
pixelRatio: getUrlParam('og_dpi') || params.pixelRatio || 1.0,
|
|
217
|
+
extensions: params.extensions || [],
|
|
218
|
+
context: params.context || {}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this._oneByHeight = 1.0 / (this._params.height * this._params.pixelRatio);
|
|
222
|
+
|
|
223
|
+
this.extensions = {};
|
|
224
|
+
|
|
225
|
+
this._canvasTarget = canvasTarget;
|
|
226
|
+
|
|
227
|
+
this._lastAnimationFrameTime = 0;
|
|
228
|
+
|
|
229
|
+
this._initialized = false;
|
|
230
|
+
|
|
231
|
+
this._frameCallback = function () {
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
this.transparentTexture = null;
|
|
235
|
+
|
|
236
|
+
this.defaultTexture = null;
|
|
237
|
+
|
|
238
|
+
this.framebufferStack = new Stack();
|
|
239
|
+
|
|
240
|
+
this.createTexture_n = this.createTexture_n_webgl2.bind(this);
|
|
241
|
+
this.createTexture_l = this.createTexture_l_webgl2.bind(this);
|
|
242
|
+
this.createTexture_mm = this.createTexture_mm_webgl2.bind(this);
|
|
243
|
+
this.createTexture_a = this.createTexture_a_webgl2.bind(this);
|
|
244
|
+
|
|
245
|
+
this.createTexture = {
|
|
246
|
+
"NEAREST": this.createTexture_n,
|
|
247
|
+
"LINEAR": this.createTexture_l,
|
|
248
|
+
"MIPMAP": this.createTexture_mm,
|
|
249
|
+
"ANISOTROPIC": this.createTexture_a
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
this.createTextureDefault = this.createTexture_n;
|
|
253
|
+
|
|
254
|
+
this.ONCANVASRESIZE = null;
|
|
255
|
+
|
|
256
|
+
this._createCanvas();
|
|
257
|
+
|
|
258
|
+
if (params.autoActivate || isEmpty(params.autoActivate)) {
|
|
259
|
+
this.initialize();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
public isInitialized(): boolean {
|
|
264
|
+
return this._initialized;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
protected _createCanvas() {
|
|
268
|
+
if (this._canvasTarget) {
|
|
269
|
+
if (this._canvasTarget instanceof HTMLElement) {
|
|
270
|
+
this.canvas = this._canvasTarget;
|
|
271
|
+
} else {
|
|
272
|
+
this.canvas = (document.getElementById(this._canvasTarget) || document.querySelector(this._canvasTarget)) as HTMLCanvasElement;
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
this.canvas = document.createElement("canvas");
|
|
276
|
+
this.canvas.width = this._params.width;
|
|
277
|
+
this.canvas.height = this._params.height;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The return value is null if the extension is not supported, or an extension object otherwise.
|
|
283
|
+
* @param {WebGLRenderingContext | WebGL2RenderingContext | null} gl - WebGl context pointer.
|
|
284
|
+
* @param {string} name - Extension name.
|
|
285
|
+
* @returns {any} -
|
|
286
|
+
*/
|
|
287
|
+
static getExtension(gl: WebGLRenderingContext | WebGL2RenderingContext | null, name: string): any | undefined {
|
|
288
|
+
|
|
289
|
+
if (!gl) return;
|
|
290
|
+
|
|
291
|
+
let i, ext;
|
|
292
|
+
for (i in vendorPrefixes) {
|
|
293
|
+
ext = gl.getExtension(vendorPrefixes[i] + name);
|
|
294
|
+
if (ext) {
|
|
295
|
+
return ext;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Returns a drawing context on the canvas, or null if the context identifier is not supported.
|
|
302
|
+
* @param {HTMLCanvasElement} canvas - HTML canvas object.
|
|
303
|
+
* @param {any} [contextAttributes] - See canvas.getContext contextAttributes.
|
|
304
|
+
* @returns {WebGLContextExt | null} -
|
|
305
|
+
*/
|
|
306
|
+
static getContext(canvas: HTMLCanvasElement, contextAttributes?: any): WebGLContextExt | null {
|
|
307
|
+
let ctx: WebGLContextExt | null = null;
|
|
308
|
+
|
|
309
|
+
try {
|
|
310
|
+
let urlParams = new URLSearchParams(location.search);
|
|
311
|
+
let ver = urlParams.get('og_ver');
|
|
312
|
+
if (ver) {
|
|
313
|
+
ctx = canvas.getContext(ver, contextAttributes) as WebGLContextExt;
|
|
314
|
+
if (ctx) {
|
|
315
|
+
ctx.type = ver;
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
for (let i = 0; i < CONTEXT_TYPE.length; i++) {
|
|
319
|
+
ctx = canvas.getContext(CONTEXT_TYPE[i], contextAttributes) as WebGLContextExt;
|
|
320
|
+
if (ctx) {
|
|
321
|
+
ctx.type = CONTEXT_TYPE[i];
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} catch (ex) {
|
|
327
|
+
cons.logErr("exception during the GL context initialization");
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (!ctx) {
|
|
331
|
+
cons.logErr("could not initialise WebGL");
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return ctx;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Sets animation frame function.
|
|
339
|
+
* @public
|
|
340
|
+
* @param {Function} callback - Frame callback.
|
|
341
|
+
*/
|
|
342
|
+
public setFrameCallback(callback: Function) {
|
|
343
|
+
callback && (this._frameCallback = callback);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Creates empty texture.
|
|
348
|
+
* @public
|
|
349
|
+
* @param {number} [width=1] - Specifies the width of the texture image.
|
|
350
|
+
* @param {number} [height=1] - Specifies the width of the texture image.
|
|
351
|
+
* @param {string} [filter="NEAREST"] - Specifies GL_TEXTURE_MIN(MAX)_FILTER texture value.
|
|
352
|
+
* @param {string} [internalFormat="RGBA"] - Specifies the color components in the texture.
|
|
353
|
+
* @param {string} [format="RGBA"] - Specifies the format of the texel data.
|
|
354
|
+
* @param {string} [type="UNSIGNED_BYTE"] - Specifies the data type of the texel data.
|
|
355
|
+
* @param {number} [level=0] - Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
|
|
356
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
357
|
+
*/
|
|
358
|
+
public createEmptyTexture2DExt(
|
|
359
|
+
width: number = 1,
|
|
360
|
+
height: number = 1,
|
|
361
|
+
filter: string = "NEAREST",
|
|
362
|
+
internalFormat: string = "RGBA",
|
|
363
|
+
format: string = "RGBA",
|
|
364
|
+
type: string = "UNSIGNED_BYTE",
|
|
365
|
+
level: number = 0
|
|
366
|
+
): WebGLTexture | null {
|
|
367
|
+
|
|
368
|
+
let gl = this.gl!;
|
|
369
|
+
|
|
370
|
+
let texture = gl.createTexture();
|
|
371
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
372
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
373
|
+
gl.texImage2D(
|
|
374
|
+
gl.TEXTURE_2D,
|
|
375
|
+
level,
|
|
376
|
+
(gl as any)[internalFormat.toUpperCase()],
|
|
377
|
+
width,
|
|
378
|
+
height,
|
|
379
|
+
0,
|
|
380
|
+
(gl as any)[format.toUpperCase()],
|
|
381
|
+
(gl as any)[type.toUpperCase()],
|
|
382
|
+
null!
|
|
383
|
+
);
|
|
384
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, (gl as any)[filter.toUpperCase()]);
|
|
385
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, (gl as any)[filter.toUpperCase()]);
|
|
386
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
387
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
388
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
389
|
+
|
|
390
|
+
return texture;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Creates Empty NEAREST filtered texture.
|
|
395
|
+
* @public
|
|
396
|
+
* @param {number} width - Empty texture width.
|
|
397
|
+
* @param {number} height - Empty texture height.
|
|
398
|
+
* @param {number} [internalFormat]
|
|
399
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
400
|
+
*/
|
|
401
|
+
public createEmptyTexture_n(
|
|
402
|
+
width: number,
|
|
403
|
+
height: number,
|
|
404
|
+
internalFormat?: number): WebGLTexture | null {
|
|
405
|
+
|
|
406
|
+
let gl = this.gl!;
|
|
407
|
+
|
|
408
|
+
let texture = gl.createTexture();
|
|
409
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
410
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
411
|
+
gl.texImage2D(
|
|
412
|
+
gl.TEXTURE_2D,
|
|
413
|
+
0,
|
|
414
|
+
internalFormat || gl.RGBA,
|
|
415
|
+
width,
|
|
416
|
+
height,
|
|
417
|
+
0,
|
|
418
|
+
gl.RGBA,
|
|
419
|
+
gl.UNSIGNED_BYTE,
|
|
420
|
+
null!
|
|
421
|
+
);
|
|
422
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
423
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
424
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
425
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
426
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
427
|
+
|
|
428
|
+
return texture;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Creates empty LINEAR filtered texture.
|
|
433
|
+
* @public
|
|
434
|
+
* @param {number} width - Empty texture width.
|
|
435
|
+
* @param {number} height - Empty texture height.
|
|
436
|
+
* @param {number} [internalFormat]
|
|
437
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
438
|
+
*/
|
|
439
|
+
public createEmptyTexture_l(
|
|
440
|
+
width: number,
|
|
441
|
+
height: number,
|
|
442
|
+
internalFormat?: number): WebGLTexture | null {
|
|
443
|
+
|
|
444
|
+
let gl = this.gl!;
|
|
445
|
+
|
|
446
|
+
let texture = gl.createTexture();
|
|
447
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
448
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
449
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null!);
|
|
450
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
451
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
452
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
453
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
454
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
455
|
+
|
|
456
|
+
return texture;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Creates NEAREST filter texture.
|
|
461
|
+
* @public
|
|
462
|
+
* @param {HTMLCanvasElement | Image} image - Image or Canvas object.
|
|
463
|
+
* @param {number} [internalFormat]
|
|
464
|
+
* @param {WebGLTexture | null} [texture=null]
|
|
465
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
466
|
+
*/
|
|
467
|
+
public createTexture_n_webgl1(
|
|
468
|
+
image: ImageSource,
|
|
469
|
+
internalFormat?: number,
|
|
470
|
+
texture: WebGLTexture | null = null): WebGLTexture | null {
|
|
471
|
+
|
|
472
|
+
let gl = this.gl!;
|
|
473
|
+
|
|
474
|
+
texture = texture || gl.createTexture();
|
|
475
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
476
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
477
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
478
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
479
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
480
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
481
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
482
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
483
|
+
|
|
484
|
+
return texture;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Creates LINEAR filter texture.
|
|
489
|
+
* @public
|
|
490
|
+
* @param {ImageSource} image - Image or Canvas object.
|
|
491
|
+
* @param {number} [internalFormat]
|
|
492
|
+
* @param {WebGLTexture | null} [texture]
|
|
493
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
494
|
+
*/
|
|
495
|
+
public createTexture_l_webgl1(
|
|
496
|
+
image: ImageSource,
|
|
497
|
+
internalFormat?: number,
|
|
498
|
+
texture: WebGLTexture | null = null): WebGLTexture | null {
|
|
499
|
+
|
|
500
|
+
let gl = this.gl!;
|
|
501
|
+
|
|
502
|
+
texture = texture || gl.createTexture();
|
|
503
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
504
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
505
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
506
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
507
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
508
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
509
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
510
|
+
|
|
511
|
+
return texture;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Creates MIPMAP filter texture.
|
|
516
|
+
* @public
|
|
517
|
+
* @param {ImageSource} image - Image or Canvas object.
|
|
518
|
+
* @param {number} [internalFormat]
|
|
519
|
+
* @param {WebGLTexture | null} [texture]
|
|
520
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
521
|
+
*/
|
|
522
|
+
public createTexture_mm_webgl1(
|
|
523
|
+
image: ImageSource,
|
|
524
|
+
internalFormat?: number,
|
|
525
|
+
texture: WebGLTexture | null = null): WebGLTexture | null {
|
|
526
|
+
|
|
527
|
+
let gl = this.gl!;
|
|
528
|
+
|
|
529
|
+
texture = texture || gl.createTexture();
|
|
530
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
531
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
532
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
533
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
534
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
535
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
536
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
537
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
538
|
+
|
|
539
|
+
return texture;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Creates ANISOTROPY filter texture.
|
|
544
|
+
* @public
|
|
545
|
+
* @param {ImageSource} image - Image or Canvas object.
|
|
546
|
+
* @param {number} [internalFormat]
|
|
547
|
+
* @param {WebGLTexture | null} [texture]
|
|
548
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
549
|
+
*/
|
|
550
|
+
public createTexture_a_webgl1(
|
|
551
|
+
image: ImageSource,
|
|
552
|
+
internalFormat?: number,
|
|
553
|
+
texture: WebGLTexture | null = null): WebGLTexture | null {
|
|
554
|
+
|
|
555
|
+
let gl = this.gl!;
|
|
556
|
+
|
|
557
|
+
texture = texture || gl.createTexture();
|
|
558
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
559
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
560
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat || gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
561
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
562
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
563
|
+
gl.texParameterf(gl.TEXTURE_2D, this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT, this._params.anisotropy);
|
|
564
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
565
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
566
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
567
|
+
|
|
568
|
+
return texture;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Creates NEAREST filter texture.
|
|
573
|
+
* @public
|
|
574
|
+
* @param {ImageSource} image - Image or Canvas object.
|
|
575
|
+
* @param {number} [internalFormat]
|
|
576
|
+
* @param {WebGLTexture | null} [texture]
|
|
577
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
578
|
+
*/
|
|
579
|
+
public createTexture_n_webgl2(
|
|
580
|
+
image: ImageSource,
|
|
581
|
+
internalFormat?: number,
|
|
582
|
+
texture: WebGLTexture | null = null): WebGLTexture | null {
|
|
583
|
+
|
|
584
|
+
let gl = this.gl!;
|
|
585
|
+
|
|
586
|
+
texture = texture || gl.createTexture();
|
|
587
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
588
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
589
|
+
//gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
590
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, internalFormat || gl.RGBA8, image.width, image.height);
|
|
591
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
592
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
593
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
594
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
595
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
596
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
597
|
+
|
|
598
|
+
return texture;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Creates LINEAR filter texture.
|
|
603
|
+
* @public
|
|
604
|
+
* @param {ImageSource} image - Image or Canvas object.
|
|
605
|
+
* @param {number} [internalFormat]
|
|
606
|
+
* @param {WebGLTexture | null} [texture]
|
|
607
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
608
|
+
*/
|
|
609
|
+
public createTexture_l_webgl2(
|
|
610
|
+
image: ImageSource,
|
|
611
|
+
internalFormat?: number,
|
|
612
|
+
texture: WebGLTexture | null = null): WebGLTexture | null {
|
|
613
|
+
|
|
614
|
+
let gl = this.gl!;
|
|
615
|
+
|
|
616
|
+
texture = texture || gl.createTexture();
|
|
617
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
618
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
619
|
+
//gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
620
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, internalFormat || gl.RGBA8, image.width, image.height);
|
|
621
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
622
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
623
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
624
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
625
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
626
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
627
|
+
|
|
628
|
+
return texture;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Creates MIPMAP filter texture.
|
|
633
|
+
* @public
|
|
634
|
+
* @param {ImageSource} image - Image or Canvas object.
|
|
635
|
+
* @param {number} [internalFormat]
|
|
636
|
+
* @param {WebGLTexture | null} [texture]
|
|
637
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
638
|
+
*/
|
|
639
|
+
public createTexture_mm_webgl2(
|
|
640
|
+
image: ImageSource,
|
|
641
|
+
internalFormat?: number,
|
|
642
|
+
texture: WebGLTexture | null = null): WebGLTexture | null {
|
|
643
|
+
|
|
644
|
+
let gl = this.gl!;
|
|
645
|
+
|
|
646
|
+
texture = texture || gl.createTexture();
|
|
647
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
648
|
+
//gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
649
|
+
gl.texStorage2D(gl.TEXTURE_2D, MAX_LEVELS, internalFormat || gl.RGBA8, image.width, image.height);
|
|
650
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
651
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
652
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
653
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
654
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
655
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
656
|
+
|
|
657
|
+
return texture;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Creates ANISOTROPY filter texture.
|
|
662
|
+
* @public
|
|
663
|
+
* @param {ImageSource} image - Image or Canvas object.
|
|
664
|
+
* @param {number} [internalFormat]
|
|
665
|
+
* @param {WebGLTexture | null} [texture]
|
|
666
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
667
|
+
*/
|
|
668
|
+
public createTexture_a_webgl2(
|
|
669
|
+
image: ImageSource,
|
|
670
|
+
internalFormat?: number,
|
|
671
|
+
texture: WebGLTexture | null = null): WebGLTexture | null {
|
|
672
|
+
|
|
673
|
+
let gl = this.gl!;
|
|
674
|
+
|
|
675
|
+
texture = texture || gl.createTexture();
|
|
676
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
677
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
678
|
+
//gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
679
|
+
gl.texStorage2D(gl.TEXTURE_2D, MAX_LEVELS, internalFormat || gl.RGBA8, image.width, image.height);
|
|
680
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
681
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
682
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
683
|
+
gl.texParameterf(gl.TEXTURE_2D, this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT, this._params.anisotropy);
|
|
684
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
685
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
686
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
687
|
+
return texture;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Creates cube texture.
|
|
692
|
+
* @public
|
|
693
|
+
* @param {Texture3DParams} params - Face image urls:
|
|
694
|
+
* @param {string} params.px - Positive X or right image url.
|
|
695
|
+
* @param {string} params.nx - Negative X or left image url.
|
|
696
|
+
* @param {string} params.py - Positive Y or up image url.
|
|
697
|
+
* @param {string} params.ny - Negative Y or bottom image url.
|
|
698
|
+
* @param {string} params.pz - Positive Z or face image url.
|
|
699
|
+
* @param {string} params.nz - Negative Z or back image url.
|
|
700
|
+
* @returns {WebGLTexture | null} - WebGL texture object.
|
|
701
|
+
*/
|
|
702
|
+
public loadCubeMapTexture(params: Texture3DParams): WebGLTexture | null {
|
|
703
|
+
|
|
704
|
+
let gl = this.gl!;
|
|
705
|
+
|
|
706
|
+
let texture = gl.createTexture();
|
|
707
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
|
708
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
709
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
710
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
711
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
712
|
+
|
|
713
|
+
let faces: [string, number][] = [
|
|
714
|
+
[params.px, gl.TEXTURE_CUBE_MAP_POSITIVE_X],
|
|
715
|
+
[params.nx, gl.TEXTURE_CUBE_MAP_NEGATIVE_X],
|
|
716
|
+
[params.py, gl.TEXTURE_CUBE_MAP_POSITIVE_Y],
|
|
717
|
+
[params.ny, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y],
|
|
718
|
+
[params.pz, gl.TEXTURE_CUBE_MAP_POSITIVE_Z],
|
|
719
|
+
[params.nz, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]
|
|
720
|
+
];
|
|
721
|
+
|
|
722
|
+
let imageCanvas = new ImageCanvas();
|
|
723
|
+
imageCanvas.fillEmpty();
|
|
724
|
+
let emptyImage = imageCanvas.getImage();
|
|
725
|
+
|
|
726
|
+
for (let i = 0; i < faces.length; i++) {
|
|
727
|
+
let face = faces[i][1];
|
|
728
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
|
729
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
730
|
+
gl.texImage2D(face, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, emptyImage);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
for (let i = 0; i < faces.length; i++) {
|
|
734
|
+
let face = faces[i][1];
|
|
735
|
+
let image = new Image();
|
|
736
|
+
image.crossOrigin = "";
|
|
737
|
+
image.onload = (function (texture: WebGLTexture | null, face: number, image: HTMLImageElement) {
|
|
738
|
+
return function () {
|
|
739
|
+
if (gl && texture) {
|
|
740
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
|
741
|
+
//gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
742
|
+
gl.texImage2D(face, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
})(texture, face, image);
|
|
746
|
+
|
|
747
|
+
image.src = faces[i][0];
|
|
748
|
+
}
|
|
749
|
+
return texture;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Adds shader program to the handler.
|
|
754
|
+
* @public
|
|
755
|
+
* @param {Program} program - Shader program.
|
|
756
|
+
* @param {boolean} [notActivate] - If it's true program will not compile.
|
|
757
|
+
* @return {Program} -
|
|
758
|
+
*/
|
|
759
|
+
public addProgram(program: Program, notActivate: boolean = false): Program {
|
|
760
|
+
if (!this.programs[program.name]) {
|
|
761
|
+
let sc = new ProgramController(this, program);
|
|
762
|
+
this.programs[program.name] = sc;
|
|
763
|
+
this._initProgramController(sc);
|
|
764
|
+
if (notActivate) {
|
|
765
|
+
sc._activated = false;
|
|
766
|
+
}
|
|
767
|
+
} else {
|
|
768
|
+
console.warn(`Shader program: "${program.name}" already exists.`);
|
|
769
|
+
}
|
|
770
|
+
return program;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Removes shader program from handler.
|
|
775
|
+
* @public
|
|
776
|
+
* @param {string} name - Shader program name.
|
|
777
|
+
*/
|
|
778
|
+
public removeProgram(name: string) {
|
|
779
|
+
this.programs[name] && this.programs[name].remove();
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Adds shader programs to the handler.
|
|
784
|
+
* @public
|
|
785
|
+
* @param {Array.<Program>} programsArr - Shader program array.
|
|
786
|
+
*/
|
|
787
|
+
public addPrograms(programsArr: Program[]) {
|
|
788
|
+
for (let i = 0; i < programsArr.length; i++) {
|
|
789
|
+
this.addProgram(programsArr[i]);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Used in addProgram
|
|
795
|
+
* @protected
|
|
796
|
+
* @param {ProgramController} sc - Program controller
|
|
797
|
+
*/
|
|
798
|
+
protected _initProgramController(sc: ProgramController) {
|
|
799
|
+
if (this._initialized) {
|
|
800
|
+
sc.initialize();
|
|
801
|
+
if (!this.activeProgram) {
|
|
802
|
+
this.activeProgram = sc;
|
|
803
|
+
sc.activate();
|
|
804
|
+
} else {
|
|
805
|
+
sc.deactivate();
|
|
806
|
+
this.activeProgram._program.enableAttribArrays();
|
|
807
|
+
this.activeProgram._program.use();
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Used in init function.
|
|
814
|
+
* @private
|
|
815
|
+
*/
|
|
816
|
+
protected _initPrograms() {
|
|
817
|
+
for (let p in this.programs) {
|
|
818
|
+
this._initProgramController(this.programs[p]);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Initialize additional WebGL extensions.
|
|
824
|
+
* @public
|
|
825
|
+
* @param {string} extensionStr - Extension name.
|
|
826
|
+
* @param {boolean} showLog - Show logging.
|
|
827
|
+
* @return {any} -
|
|
828
|
+
*/
|
|
829
|
+
public initializeExtension(extensionStr: string, showLog: boolean = false): any {
|
|
830
|
+
if (!(this.extensions && this.extensions[extensionStr])) {
|
|
831
|
+
let ext = Handler.getExtension(this.gl, extensionStr);
|
|
832
|
+
if (ext) {
|
|
833
|
+
this.extensions[extensionStr] = ext;
|
|
834
|
+
} else if (showLog) {
|
|
835
|
+
console.warn(
|
|
836
|
+
"og.webgl.Handler: extension '" + extensionStr + "' doesn't initialize."
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return this.extensions && this.extensions[extensionStr];
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Main function that initialize handler.
|
|
845
|
+
* @public
|
|
846
|
+
*/
|
|
847
|
+
public initialize() {
|
|
848
|
+
|
|
849
|
+
if (this._initialized) return;
|
|
850
|
+
|
|
851
|
+
if (!this.canvas) return;
|
|
852
|
+
|
|
853
|
+
this.gl = Handler.getContext(this.canvas, this._params.context);
|
|
854
|
+
|
|
855
|
+
if (!this.gl) return;
|
|
856
|
+
|
|
857
|
+
this._initialized = true;
|
|
858
|
+
|
|
859
|
+
/** Sets default extensions */
|
|
860
|
+
this._params.extensions.push("EXT_texture_filter_anisotropic");
|
|
861
|
+
|
|
862
|
+
if (this.gl.type === "webgl") {
|
|
863
|
+
this._params.extensions.push("OES_standard_derivatives");
|
|
864
|
+
this._params.extensions.push("OES_element_index_uint");
|
|
865
|
+
this._params.extensions.push("WEBGL_depth_texture");
|
|
866
|
+
this._params.extensions.push("ANGLE_instanced_arrays");
|
|
867
|
+
//this._params.extensions.push("WEBGL_draw_buffers");
|
|
868
|
+
//this._params.extensions.push("EXT_frag_depth");
|
|
869
|
+
} else {
|
|
870
|
+
this._params.extensions.push("EXT_color_buffer_float");
|
|
871
|
+
this._params.extensions.push("OES_texture_float_linear");
|
|
872
|
+
//this._params.extensions.push("WEBGL_draw_buffers");
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
let i = this._params.extensions.length;
|
|
876
|
+
while (i--) {
|
|
877
|
+
this.initializeExtension(this._params.extensions[i], true);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
if (this.gl.type === "webgl") {
|
|
881
|
+
this.createTexture_n = this.createTexture_n_webgl1.bind(this);
|
|
882
|
+
this.createTexture_l = this.createTexture_l_webgl1.bind(this);
|
|
883
|
+
this.createTexture_mm = this.createTexture_mm_webgl1.bind(this);
|
|
884
|
+
this.createTexture_a = this.createTexture_a_webgl1.bind(this);
|
|
885
|
+
} else {
|
|
886
|
+
this.createTexture_n = this.createTexture_n_webgl2.bind(this);
|
|
887
|
+
this.createTexture_l = this.createTexture_l_webgl2.bind(this);
|
|
888
|
+
this.createTexture_mm = this.createTexture_mm_webgl2.bind(this);
|
|
889
|
+
this.createTexture_a = this.createTexture_a_webgl2.bind(this);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
this.createTexture["NEAREST"] = this.createTexture_n;
|
|
893
|
+
this.createTexture["LINEAR"] = this.createTexture_l;
|
|
894
|
+
this.createTexture["MIPMAP"] = this.createTexture_mm;
|
|
895
|
+
this.createTexture["ANISOTROPIC"] = this.createTexture_a;
|
|
896
|
+
|
|
897
|
+
if (!this.extensions.EXT_texture_filter_anisotropic) {
|
|
898
|
+
this.createTextureDefault = this.createTexture_mm;
|
|
899
|
+
} else {
|
|
900
|
+
this.createTextureDefault = this.createTexture_a;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/** Initializing shaders and rendering parameters*/
|
|
904
|
+
this._initPrograms();
|
|
905
|
+
this._setDefaults();
|
|
906
|
+
|
|
907
|
+
this.intersectionObserver = new IntersectionObserver((entries) => {
|
|
908
|
+
this._toggleVisibilityChange(entries[0].isIntersecting);
|
|
909
|
+
}, {threshold: 0});
|
|
910
|
+
|
|
911
|
+
this.intersectionObserver.observe(this.canvas);
|
|
912
|
+
|
|
913
|
+
this.resizeObserver = new ResizeObserver(entries => {
|
|
914
|
+
this._toggleVisibilityChange(entries[0].contentRect.width !== 0 && entries[0].contentRect.height !== 0);
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
this.resizeObserver.observe(this.canvas);
|
|
918
|
+
|
|
919
|
+
document.addEventListener("visibilitychange", () => {
|
|
920
|
+
this._toggleVisibilityChange(document.visibilityState === 'visible');
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
protected _toggleVisibilityChange(visibility: boolean) {
|
|
925
|
+
if (visibility) {
|
|
926
|
+
this.start();
|
|
927
|
+
this.ONCANVASRESIZE && this.ONCANVASRESIZE();
|
|
928
|
+
this.events.dispatch(this.events.visibilitychange, true);
|
|
929
|
+
} else {
|
|
930
|
+
this.events.dispatch(this.events.visibilitychange, false);
|
|
931
|
+
this.stop();
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* Sets default gl render parameters. Used in init function.
|
|
937
|
+
* @protected
|
|
938
|
+
*/
|
|
939
|
+
protected _setDefaults() {
|
|
940
|
+
|
|
941
|
+
let gl = this.gl;
|
|
942
|
+
|
|
943
|
+
if (!gl) return;
|
|
944
|
+
if (!this.canvas) return;
|
|
945
|
+
|
|
946
|
+
gl.depthFunc(gl.LESS);
|
|
947
|
+
gl.enable(gl.DEPTH_TEST);
|
|
948
|
+
this.setSize(
|
|
949
|
+
this.canvas.clientWidth || this._params.width,
|
|
950
|
+
this.canvas.clientHeight || this._params.height
|
|
951
|
+
);
|
|
952
|
+
gl.frontFace(gl.CCW);
|
|
953
|
+
gl.cullFace(gl.BACK);
|
|
954
|
+
gl.enable(gl.CULL_FACE);
|
|
955
|
+
gl.disable(gl.BLEND);
|
|
956
|
+
this.createDefaultTexture({color: "rgba(0,0,0,0.0)"}, (t: WebGLTextureExt) => {
|
|
957
|
+
this.transparentTexture = t;
|
|
958
|
+
});
|
|
959
|
+
this.createDefaultTexture({color: "rgba(255, 255, 255, 1.0)"}, (t: WebGLTextureExt) => {
|
|
960
|
+
this.defaultTexture = t;
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
public getCanvasSize(): NumberArray2 {
|
|
965
|
+
return this._canvasSize;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Creates STREAM_DRAW ARRAY buffer.
|
|
970
|
+
* @public
|
|
971
|
+
* @param {number} itemSize - Array item size.
|
|
972
|
+
* @param {number} numItems - Items quantity.
|
|
973
|
+
* @param {number} [usage=STATIC_DRAW] - Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
|
|
974
|
+
* @param {number} [bytes=4] -
|
|
975
|
+
* @return {WebGLBufferExt} -
|
|
976
|
+
*/
|
|
977
|
+
public createStreamArrayBuffer(itemSize: number, numItems: number, usage?: number, bytes: number = 4): WebGLBufferExt {
|
|
978
|
+
let gl = this.gl!;
|
|
979
|
+
let buffer: WebGLBufferExt = gl.createBuffer() as WebGLBufferExt;
|
|
980
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
981
|
+
gl.bufferData(
|
|
982
|
+
gl.ARRAY_BUFFER,
|
|
983
|
+
numItems * itemSize * bytes,
|
|
984
|
+
usage || gl.STREAM_DRAW
|
|
985
|
+
);
|
|
986
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null!);
|
|
987
|
+
buffer.itemSize = itemSize;
|
|
988
|
+
buffer.numItems = numItems;
|
|
989
|
+
return buffer;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Sets stream buffer.
|
|
994
|
+
* @public
|
|
995
|
+
* @param {WebGLBufferExt} buffer -
|
|
996
|
+
* @param {TypedArray} array -
|
|
997
|
+
* @param {number} [offset=0] -
|
|
998
|
+
* @return {WebGLBufferExt} -
|
|
999
|
+
*/
|
|
1000
|
+
public setStreamArrayBuffer(buffer: WebGLBufferExt, array: TypedArray, offset: number = 0): WebGLBufferExt {
|
|
1001
|
+
let gl = this.gl!;
|
|
1002
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
1003
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, array);
|
|
1004
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null!);
|
|
1005
|
+
return buffer;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* Creates ARRAY buffer.
|
|
1010
|
+
* @public
|
|
1011
|
+
* @param {TypedArray} array - Input array.
|
|
1012
|
+
* @param {number} itemSize - Array item size.
|
|
1013
|
+
* @param {number} numItems - Items quantity.
|
|
1014
|
+
* @param {number} [usage=STATIC_DRAW] - Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
|
|
1015
|
+
* @return {WebGLBufferExt} -
|
|
1016
|
+
*/
|
|
1017
|
+
public createArrayBuffer(array: TypedArray, itemSize: number, numItems: number, usage?: number): WebGLBufferExt {
|
|
1018
|
+
let gl = this.gl!;
|
|
1019
|
+
let buffer: WebGLBufferExt = gl.createBuffer() as WebGLBufferExt;
|
|
1020
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
1021
|
+
gl.bufferData(gl.ARRAY_BUFFER, array, usage || gl.STATIC_DRAW);
|
|
1022
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null!);
|
|
1023
|
+
buffer.itemSize = itemSize;
|
|
1024
|
+
buffer.numItems = numItems;
|
|
1025
|
+
return buffer;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Creates ARRAY buffer specific length.
|
|
1030
|
+
* @public
|
|
1031
|
+
* @param {number} size -
|
|
1032
|
+
* @param {number} [usage=STATIC_DRAW] - Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
|
|
1033
|
+
* @return {WebGLBufferExt} -
|
|
1034
|
+
*/
|
|
1035
|
+
public createArrayBufferLength(size: number, usage?: number): WebGLBufferExt {
|
|
1036
|
+
let gl = this.gl!;
|
|
1037
|
+
let buffer: WebGLBufferExt = gl.createBuffer() as WebGLBufferExt;
|
|
1038
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
1039
|
+
gl.bufferData(gl.ARRAY_BUFFER, size, usage || gl.STATIC_DRAW);
|
|
1040
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null!);
|
|
1041
|
+
buffer.itemSize = 1;
|
|
1042
|
+
buffer.numItems = size;
|
|
1043
|
+
return buffer;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* Creates ELEMENT ARRAY buffer.
|
|
1048
|
+
* @public
|
|
1049
|
+
* @param {TypedArray} array - Input array.
|
|
1050
|
+
* @param {number} itemSize - Array item size.
|
|
1051
|
+
* @param {number} numItems - Items quantity.
|
|
1052
|
+
* @param {number} [usage=STATIC_DRAW] - Parameter of the bufferData call can be one of STATIC_DRAW, DYNAMIC_DRAW, or STREAM_DRAW.
|
|
1053
|
+
* @return {Object} -
|
|
1054
|
+
*/
|
|
1055
|
+
public createElementArrayBuffer(array: TypedArray, itemSize: number, numItems?: number, usage?: number): WebGLBufferExt {
|
|
1056
|
+
let gl = this.gl!;
|
|
1057
|
+
let buffer = gl.createBuffer() as WebGLBufferExt;
|
|
1058
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);
|
|
1059
|
+
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, array, usage || gl.STATIC_DRAW);
|
|
1060
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null!);
|
|
1061
|
+
buffer.itemSize = itemSize;
|
|
1062
|
+
buffer.numItems = numItems || array.length;
|
|
1063
|
+
return buffer;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
/**
|
|
1067
|
+
* Sets handler canvas size.
|
|
1068
|
+
* @public
|
|
1069
|
+
* @param {number} w - Canvas width.
|
|
1070
|
+
* @param {number} h - Canvas height.
|
|
1071
|
+
*/
|
|
1072
|
+
public setSize(w: number, h: number) {
|
|
1073
|
+
this._params.width = w;
|
|
1074
|
+
this._params.height = h;
|
|
1075
|
+
if (this.canvas) {
|
|
1076
|
+
this.canvas.width = w * this._params.pixelRatio;
|
|
1077
|
+
this.canvas.height = h * this._params.pixelRatio;
|
|
1078
|
+
|
|
1079
|
+
this._canvasSize[0] = this.canvas.width;
|
|
1080
|
+
this._canvasSize[1] = this.canvas.height;
|
|
1081
|
+
|
|
1082
|
+
this._oneByHeight = 1.0 / this.canvas.height;
|
|
1083
|
+
|
|
1084
|
+
this.gl && this.gl.viewport(0, 0, w, h);
|
|
1085
|
+
this.ONCANVASRESIZE && this.ONCANVASRESIZE(this.canvas);
|
|
1086
|
+
this.events.dispatch(this.events.resize, this);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
public get pixelRatio(): number {
|
|
1091
|
+
return this._params.pixelRatio;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
public set pixelRatio(pr: number) {
|
|
1095
|
+
this._params.pixelRatio = pr;
|
|
1096
|
+
this.setSize(this._params.width, this._params.height);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
* Returns context screen width.
|
|
1101
|
+
* @public
|
|
1102
|
+
* @returns {number} -
|
|
1103
|
+
*/
|
|
1104
|
+
public getWidth(): number {
|
|
1105
|
+
return this.canvas ? this.canvas.width : 0;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* Returns context screen height.
|
|
1110
|
+
* @public
|
|
1111
|
+
* @returns {number} -
|
|
1112
|
+
*/
|
|
1113
|
+
public getHeight(): number {
|
|
1114
|
+
return this.canvas ? this.canvas.height : 0;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* Returns canvas aspect ratio.
|
|
1119
|
+
* @public
|
|
1120
|
+
* @returns {number} -
|
|
1121
|
+
*/
|
|
1122
|
+
public getClientAspect(): number {
|
|
1123
|
+
return this.canvas ? this.canvas.clientWidth / this.canvas.clientHeight : 0;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
/**
|
|
1127
|
+
* Returns canvas center coordinates.
|
|
1128
|
+
* @public
|
|
1129
|
+
* @returns {number} -
|
|
1130
|
+
*/
|
|
1131
|
+
public getCenter(): Vec2 {
|
|
1132
|
+
let c = this.canvas;
|
|
1133
|
+
return c ? new Vec2(Math.round(c.width * 0.5), Math.round(c.height * 0.5)) : new Vec2();
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* Draw single frame.
|
|
1138
|
+
* @public
|
|
1139
|
+
*/
|
|
1140
|
+
public drawFrame() {
|
|
1141
|
+
/** Calculating frame time */
|
|
1142
|
+
let now = window.performance.now();
|
|
1143
|
+
this.deltaTime = now - this._lastAnimationFrameTime;
|
|
1144
|
+
this._lastAnimationFrameTime = now;
|
|
1145
|
+
|
|
1146
|
+
this.defaultClock.tick(this.deltaTime);
|
|
1147
|
+
|
|
1148
|
+
for (let i = 0; i < this._clocks.length; i++) {
|
|
1149
|
+
this._clocks[i].tick(this.deltaTime);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
/** Canvas resize checking */
|
|
1153
|
+
let canvas = this.canvas!;
|
|
1154
|
+
|
|
1155
|
+
if (Math.floor(canvas.clientWidth * this._params.pixelRatio) !== canvas.width || Math.floor(canvas.clientHeight * this._params.pixelRatio) !== canvas.height) {
|
|
1156
|
+
if (canvas.clientWidth === 0 || canvas.clientHeight === 0) {
|
|
1157
|
+
this.stop();
|
|
1158
|
+
} else if (!document.hidden) {
|
|
1159
|
+
this.start();
|
|
1160
|
+
this.setSize(canvas.clientWidth, canvas.clientHeight);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
/** Draw frame */
|
|
1165
|
+
this._frameCallback();
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* Clearing gl frame.
|
|
1170
|
+
* @public
|
|
1171
|
+
*/
|
|
1172
|
+
public clearFrame() {
|
|
1173
|
+
let gl = this.gl!;
|
|
1174
|
+
gl.clearColor(0.0, 0.0, 0.0, 1.0);
|
|
1175
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* Starts animation loop.
|
|
1180
|
+
* @public
|
|
1181
|
+
*/
|
|
1182
|
+
public start() {
|
|
1183
|
+
if (!this._requestAnimationFrameId && this._initialized) {
|
|
1184
|
+
this._animationFrameCallback();
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
public stop() {
|
|
1189
|
+
if (this._requestAnimationFrameId) {
|
|
1190
|
+
window.cancelAnimationFrame(this._requestAnimationFrameId);
|
|
1191
|
+
this._requestAnimationFrameId = 0;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
public isStopped(): boolean {
|
|
1196
|
+
return !this._requestAnimationFrameId;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Check is gl context type equals webgl2
|
|
1201
|
+
* @public
|
|
1202
|
+
*/
|
|
1203
|
+
public isWebGl2(): boolean {
|
|
1204
|
+
return this.gl ? this.gl.type === "webgl2" : false;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* Make animation.
|
|
1209
|
+
* @protected
|
|
1210
|
+
*/
|
|
1211
|
+
protected _animationFrameCallback() {
|
|
1212
|
+
this._requestAnimationFrameId = window.requestAnimationFrame(() => {
|
|
1213
|
+
this.drawFrame();
|
|
1214
|
+
this._requestAnimationFrameId && this._animationFrameCallback();
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* Creates default texture object
|
|
1220
|
+
* @public
|
|
1221
|
+
* @param {IDefaultTextureParams | null} params - Texture parameters:
|
|
1222
|
+
* @param {(texture: WebGLTextureExt) => void} [success] - Creation callback
|
|
1223
|
+
*/
|
|
1224
|
+
public createDefaultTexture(params: IDefaultTextureParams | null, success: (texture: WebGLTextureExt) => void) {
|
|
1225
|
+
|
|
1226
|
+
let imgCnv;
|
|
1227
|
+
let texture;
|
|
1228
|
+
|
|
1229
|
+
if (params && params.color) {
|
|
1230
|
+
imgCnv = new ImageCanvas(2, 2);
|
|
1231
|
+
imgCnv.fillColor(params.color);
|
|
1232
|
+
texture = this.createTexture_n(imgCnv.getCanvas())!;
|
|
1233
|
+
texture.default = true;
|
|
1234
|
+
success(texture);
|
|
1235
|
+
} else if (params && params.url) {
|
|
1236
|
+
let img = new Image();
|
|
1237
|
+
let that = this;
|
|
1238
|
+
img.onload = function () {
|
|
1239
|
+
texture = that.createTextureDefault(img)!;
|
|
1240
|
+
texture.default = true;
|
|
1241
|
+
success(texture);
|
|
1242
|
+
};
|
|
1243
|
+
img.src = params.url;
|
|
1244
|
+
} else {
|
|
1245
|
+
imgCnv = new ImageCanvas(2, 2);
|
|
1246
|
+
imgCnv.fillColor("#C5C5C5");
|
|
1247
|
+
texture = this.createTexture_n(imgCnv.getCanvas())!;
|
|
1248
|
+
texture.default = true;
|
|
1249
|
+
success(texture);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
public deleteTexture(texture: WebGLTextureExt | null | undefined) {
|
|
1254
|
+
if (texture && !texture.default) {
|
|
1255
|
+
this.gl!.deleteTexture(texture);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
/**
|
|
1260
|
+
* @public
|
|
1261
|
+
*/
|
|
1262
|
+
public destroy() {
|
|
1263
|
+
|
|
1264
|
+
this.resizeObserver?.disconnect();
|
|
1265
|
+
this.intersectionObserver?.disconnect();
|
|
1266
|
+
|
|
1267
|
+
this.stop();
|
|
1268
|
+
|
|
1269
|
+
//
|
|
1270
|
+
// Dispose shaders
|
|
1271
|
+
//
|
|
1272
|
+
for (let p in this.programs) {
|
|
1273
|
+
this.removeProgram(p);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
//
|
|
1277
|
+
// Clear WebGL context
|
|
1278
|
+
//
|
|
1279
|
+
let gl = this.gl;
|
|
1280
|
+
|
|
1281
|
+
if (gl) {
|
|
1282
|
+
gl.deleteTexture(this.transparentTexture as WebGLTexture);
|
|
1283
|
+
this.transparentTexture = null;
|
|
1284
|
+
|
|
1285
|
+
gl.deleteTexture(this.defaultTexture as WebGLTexture);
|
|
1286
|
+
this.defaultTexture = null;
|
|
1287
|
+
|
|
1288
|
+
this.framebufferStack = new Stack();
|
|
1289
|
+
|
|
1290
|
+
//
|
|
1291
|
+
// Clear attrib pointers
|
|
1292
|
+
//
|
|
1293
|
+
let numAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
1294
|
+
let tmp = gl.createBuffer();
|
|
1295
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, tmp);
|
|
1296
|
+
for (let ii = 0; ii < numAttribs; ++ii) {
|
|
1297
|
+
gl.disableVertexAttribArray(ii);
|
|
1298
|
+
gl.vertexAttribPointer(ii, 4, gl.FLOAT, false, 0, 0);
|
|
1299
|
+
gl.vertexAttrib1f(ii, 0);
|
|
1300
|
+
}
|
|
1301
|
+
gl.deleteBuffer(tmp);
|
|
1302
|
+
|
|
1303
|
+
//
|
|
1304
|
+
// Clear all possible textures
|
|
1305
|
+
//
|
|
1306
|
+
let numTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
|
|
1307
|
+
for (let ii = 0; ii < numTextureUnits; ++ii) {
|
|
1308
|
+
gl.activeTexture(gl.TEXTURE0 + ii);
|
|
1309
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, null!);
|
|
1310
|
+
gl.bindTexture(gl.TEXTURE_2D, null!);
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
//
|
|
1314
|
+
// Hard reset
|
|
1315
|
+
//
|
|
1316
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
1317
|
+
gl.useProgram(null!);
|
|
1318
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null!);
|
|
1319
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null!);
|
|
1320
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null!);
|
|
1321
|
+
gl.bindRenderbuffer(gl.RENDERBUFFER, null!);
|
|
1322
|
+
gl.disable(gl.BLEND);
|
|
1323
|
+
gl.disable(gl.CULL_FACE);
|
|
1324
|
+
gl.disable(gl.DEPTH_TEST);
|
|
1325
|
+
gl.disable(gl.DITHER);
|
|
1326
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
1327
|
+
gl.blendColor(0, 0, 0, 0);
|
|
1328
|
+
gl.blendEquation(gl.FUNC_ADD);
|
|
1329
|
+
gl.blendFunc(gl.ONE, gl.ZERO);
|
|
1330
|
+
gl.clearColor(0, 0, 0, 0);
|
|
1331
|
+
gl.clearDepth(1);
|
|
1332
|
+
gl.clearStencil(-1);
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
//
|
|
1336
|
+
// Destroy canvas
|
|
1337
|
+
//
|
|
1338
|
+
if (this.canvas) {
|
|
1339
|
+
if (this.canvas.parentNode) {
|
|
1340
|
+
this.canvas.parentNode.removeChild(this.canvas);
|
|
1341
|
+
}
|
|
1342
|
+
this.canvas.width = 1;
|
|
1343
|
+
this.canvas.height = 1;
|
|
1344
|
+
this.canvas = null;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
this.gl = null;
|
|
1348
|
+
|
|
1349
|
+
this._initialized = false;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
public addClock(clock: Clock) {
|
|
1353
|
+
if (!clock.__handler) {
|
|
1354
|
+
clock.__handler = this;
|
|
1355
|
+
this._clocks.push(clock);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
public addClocks(clockArr: Clock[]) {
|
|
1360
|
+
for (let i = 0; i < clockArr.length; i++) {
|
|
1361
|
+
this.addClock(clockArr[i]);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
public removeClock(clock: Clock) {
|
|
1366
|
+
if (clock.__handler) {
|
|
1367
|
+
let c = this._clocks;
|
|
1368
|
+
let i = c.length;
|
|
1369
|
+
while (i--) {
|
|
1370
|
+
if (c[i].isEqual(clock)) {
|
|
1371
|
+
clock.__handler = null;
|
|
1372
|
+
c.splice(i, 1);
|
|
1373
|
+
break;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// var loadTextureData = function(textureName, callback) {
|
|
1380
|
+
// const xhr = new XMLHttpRequest();
|
|
1381
|
+
// xhr.open('GET', textureName);
|
|
1382
|
+
// xhr.responseType = 'arraybuffer';
|
|
1383
|
+
// xhr.onload = (event) => {
|
|
1384
|
+
// const data = new DataView(xhr.response);
|
|
1385
|
+
// const array =
|
|
1386
|
+
// new Float32Array(data.byteLength / Float32Array.BYTES_PER_ELEMENT);
|
|
1387
|
+
// for (let i = 0; i < array.length; ++i) {
|
|
1388
|
+
// array[i] = data.getFloat32(i * Float32Array.BYTES_PER_ELEMENT, true);
|
|
1389
|
+
// }
|
|
1390
|
+
// callback(array);
|
|
1391
|
+
// };
|
|
1392
|
+
// xhr.send();
|
|
1393
|
+
// }
|
|
1394
|
+
|
|
1395
|
+
// loadTextureData('transmittance.dat', (data) => {
|
|
1396
|
+
//
|
|
1397
|
+
// let gl = this.renderer.handler.gl;
|
|
1398
|
+
//
|
|
1399
|
+
// const texture = gl.createTexture();
|
|
1400
|
+
// gl.activeTexture(gl.TEXTURE0);
|
|
1401
|
+
// gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
1402
|
+
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
1403
|
+
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
1404
|
+
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
1405
|
+
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
1406
|
+
// gl.texImage2D(gl.TEXTURE_2D, 0, gl.getExtension('OES_texture_float_linear') ? gl.RGBA32F : gl.RGBA16F,
|
|
1407
|
+
// TRANSMITTANCE_TEXTURE_WIDTH, TRANSMITTANCE_TEXTURE_HEIGHT, 0, gl.RGBA,
|
|
1408
|
+
// gl.FLOAT, data);
|
|
1409
|
+
//
|
|
1410
|
+
// this.transmittanceTextureBrn = texture;
|
|
1411
|
+
// });
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
export {Handler};
|