@luma.gl/webgl 9.0.0-alpha.10 → 9.0.0-alpha.12
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/dist/adapter/converters/device-parameters.js +1 -12
- package/dist/adapter/converters/device-parameters.js.map +1 -1
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +0 -9
- package/dist/adapter/converters/texture-formats.js.map +1 -1
- package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
- package/dist/adapter/converters/vertex-formats.js +3 -0
- package/dist/adapter/converters/vertex-formats.js.map +1 -1
- package/dist/adapter/device-helpers/device-features.d.ts.map +1 -1
- package/dist/adapter/device-helpers/device-features.js.map +1 -1
- package/dist/adapter/device-helpers/get-device-info.js +4 -0
- package/dist/adapter/device-helpers/get-device-info.js.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
- package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
- package/dist/adapter/helpers/get-shader-layout.js +2 -4
- package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
- package/dist/adapter/helpers/set-uniform.js +1 -1
- package/dist/adapter/helpers/set-uniform.js.map +1 -1
- package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
- package/dist/adapter/objects/constants-to-keys.js.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +1 -1
- package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
- package/dist/adapter/objects/webgl-resource.d.ts +2 -4
- package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-resource.js +1 -7
- package/dist/adapter/objects/webgl-resource.js.map +1 -1
- package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
- package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts +0 -1
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +0 -2
- package/dist/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.d.ts +0 -1
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +2 -2
- package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +4 -32
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgl-sampler.d.ts +1 -0
- package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-sampler.js +4 -0
- package/dist/adapter/resources/webgl-sampler.js.map +1 -1
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js.map +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +2 -2
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +1 -3
- package/dist/adapter/resources/webgl-texture.js.map +1 -1
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +4 -3
- package/dist/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +34 -29
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +37 -28
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/classic/buffer.d.ts.map +1 -1
- package/dist/classic/buffer.js.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +1 -7
- package/dist/context/debug/webgl-developer-tools.js.map +1 -1
- package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
- package/dist/context/parameters/unified-parameter-api.js.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.d.ts +103 -103
- package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
- package/dist/context/parameters/webgl-parameter-tables.js +15 -14
- package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
- package/dist/context/polyfill/context-data.d.ts +13 -0
- package/dist/context/polyfill/context-data.d.ts.map +1 -0
- package/dist/context/polyfill/context-data.js +14 -0
- package/dist/context/polyfill/context-data.js.map +1 -0
- package/dist/context/polyfill/get-parameter-polyfill.d.ts +1 -1
- package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +1 -1
- package/dist/context/polyfill/get-parameter-polyfill.js.map +1 -1
- package/dist/context/polyfill/polyfill-context.js +4 -4
- package/dist/context/polyfill/polyfill-context.js.map +1 -1
- package/dist/context/polyfill/polyfill-table.d.ts +7 -7
- package/dist/context/polyfill/polyfill-table.d.ts.map +1 -1
- package/dist/context/polyfill/polyfill-table.js +5 -4
- package/dist/context/polyfill/polyfill-table.js.map +1 -1
- package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
- package/dist/context/state-tracker/track-context-state.js +0 -1
- package/dist/context/state-tracker/track-context-state.js.map +1 -1
- package/dist/context/state-tracker/with-parameters.js +1 -1
- package/dist/context/state-tracker/with-parameters.js.map +1 -1
- package/dist/es5/adapter/converters/device-parameters.js +1 -12
- package/dist/es5/adapter/converters/device-parameters.js.map +1 -1
- package/dist/es5/adapter/converters/texture-formats.js +1 -10
- package/dist/es5/adapter/converters/texture-formats.js.map +1 -1
- package/dist/es5/adapter/converters/vertex-formats.js +3 -0
- package/dist/es5/adapter/converters/vertex-formats.js.map +1 -1
- package/dist/es5/adapter/device-helpers/device-features.js.map +1 -1
- package/dist/es5/adapter/device-helpers/get-device-info.js +4 -0
- package/dist/es5/adapter/device-helpers/get-device-info.js.map +1 -1
- package/dist/es5/adapter/helpers/get-shader-layout.js +2 -4
- package/dist/es5/adapter/helpers/get-shader-layout.js.map +1 -1
- package/dist/es5/adapter/helpers/set-uniform.js +1 -1
- package/dist/es5/adapter/helpers/set-uniform.js.map +1 -1
- package/dist/es5/adapter/objects/constants-to-keys.js.map +1 -1
- package/dist/es5/adapter/objects/webgl-renderbuffer.js +1 -1
- package/dist/es5/adapter/objects/webgl-renderbuffer.js.map +1 -1
- package/dist/es5/adapter/objects/webgl-resource.js +1 -6
- package/dist/es5/adapter/objects/webgl-resource.js.map +1 -1
- package/dist/es5/adapter/objects/webgl-vertex-array-object.js.map +1 -1
- package/dist/es5/adapter/resources/webgl-buffer.js +0 -1
- package/dist/es5/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/es5/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/es5/adapter/resources/webgl-framebuffer.js +2 -1
- package/dist/es5/adapter/resources/webgl-framebuffer.js.map +1 -1
- package/dist/es5/adapter/resources/webgl-render-pipeline.js +2 -38
- package/dist/es5/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/es5/adapter/resources/webgl-sampler.js +5 -0
- package/dist/es5/adapter/resources/webgl-sampler.js.map +1 -1
- package/dist/es5/adapter/resources/webgl-shader.js.map +1 -1
- package/dist/es5/adapter/resources/webgl-texture.js +1 -7
- package/dist/es5/adapter/resources/webgl-texture.js.map +1 -1
- package/dist/es5/adapter/webgl-canvas-context.js +3 -4
- package/dist/es5/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/es5/adapter/webgl-device.js +38 -27
- package/dist/es5/adapter/webgl-device.js.map +1 -1
- package/dist/es5/classic/buffer.js.map +1 -1
- package/dist/es5/context/debug/webgl-developer-tools.js +1 -7
- package/dist/es5/context/debug/webgl-developer-tools.js.map +1 -1
- package/dist/es5/context/parameters/unified-parameter-api.js.map +1 -1
- package/dist/es5/context/parameters/webgl-parameter-tables.js +10 -9
- package/dist/es5/context/parameters/webgl-parameter-tables.js.map +1 -1
- package/dist/es5/context/polyfill/context-data.js +21 -0
- package/dist/es5/context/polyfill/context-data.js.map +1 -0
- package/dist/es5/context/polyfill/get-parameter-polyfill.js.map +1 -1
- package/dist/es5/context/polyfill/polyfill-context.js +4 -4
- package/dist/es5/context/polyfill/polyfill-context.js.map +1 -1
- package/dist/es5/context/polyfill/polyfill-table.js +5 -4
- package/dist/es5/context/polyfill/polyfill-table.js.map +1 -1
- package/dist/es5/context/state-tracker/track-context-state.js +0 -1
- package/dist/es5/context/state-tracker/track-context-state.js.map +1 -1
- package/dist/es5/context/state-tracker/with-parameters.js +4 -2
- package/dist/es5/context/state-tracker/with-parameters.js.map +1 -1
- package/dist/es5/index.js +0 -14
- package/dist/es5/index.js.map +1 -1
- package/dist/esm/adapter/converters/device-parameters.js +1 -12
- package/dist/esm/adapter/converters/device-parameters.js.map +1 -1
- package/dist/esm/adapter/converters/texture-formats.js +0 -9
- package/dist/esm/adapter/converters/texture-formats.js.map +1 -1
- package/dist/esm/adapter/converters/vertex-formats.js +3 -0
- package/dist/esm/adapter/converters/vertex-formats.js.map +1 -1
- package/dist/esm/adapter/device-helpers/device-features.js.map +1 -1
- package/dist/esm/adapter/device-helpers/get-device-info.js +4 -0
- package/dist/esm/adapter/device-helpers/get-device-info.js.map +1 -1
- package/dist/esm/adapter/helpers/get-shader-layout.js +2 -4
- package/dist/esm/adapter/helpers/get-shader-layout.js.map +1 -1
- package/dist/esm/adapter/helpers/set-uniform.js +1 -1
- package/dist/esm/adapter/helpers/set-uniform.js.map +1 -1
- package/dist/esm/adapter/objects/constants-to-keys.js.map +1 -1
- package/dist/esm/adapter/objects/webgl-renderbuffer.js +1 -1
- package/dist/esm/adapter/objects/webgl-renderbuffer.js.map +1 -1
- package/dist/esm/adapter/objects/webgl-resource.js +1 -7
- package/dist/esm/adapter/objects/webgl-resource.js.map +1 -1
- package/dist/esm/adapter/objects/webgl-vertex-array-object.js.map +1 -1
- package/dist/esm/adapter/resources/webgl-buffer.js +0 -2
- package/dist/esm/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/esm/adapter/resources/webgl-command-encoder.js.map +1 -1
- package/dist/esm/adapter/resources/webgl-framebuffer.js +2 -2
- package/dist/esm/adapter/resources/webgl-framebuffer.js.map +1 -1
- package/dist/esm/adapter/resources/webgl-render-pipeline.js +4 -32
- package/dist/esm/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/esm/adapter/resources/webgl-sampler.js +4 -0
- package/dist/esm/adapter/resources/webgl-sampler.js.map +1 -1
- package/dist/esm/adapter/resources/webgl-shader.js.map +1 -1
- package/dist/esm/adapter/resources/webgl-texture.js +1 -3
- package/dist/esm/adapter/resources/webgl-texture.js.map +1 -1
- package/dist/esm/adapter/webgl-canvas-context.js +4 -3
- package/dist/esm/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/esm/adapter/webgl-device.js +37 -28
- package/dist/esm/adapter/webgl-device.js.map +1 -1
- package/dist/esm/classic/buffer.js.map +1 -1
- package/dist/esm/context/debug/webgl-developer-tools.js +1 -7
- package/dist/esm/context/debug/webgl-developer-tools.js.map +1 -1
- package/dist/esm/context/parameters/unified-parameter-api.js.map +1 -1
- package/dist/esm/context/parameters/webgl-parameter-tables.js +15 -14
- package/dist/esm/context/parameters/webgl-parameter-tables.js.map +1 -1
- package/dist/esm/context/polyfill/context-data.js +14 -0
- package/dist/esm/context/polyfill/context-data.js.map +1 -0
- package/dist/esm/context/polyfill/get-parameter-polyfill.js.map +1 -1
- package/dist/esm/context/polyfill/polyfill-context.js +4 -4
- package/dist/esm/context/polyfill/polyfill-context.js.map +1 -1
- package/dist/esm/context/polyfill/polyfill-table.js +5 -4
- package/dist/esm/context/polyfill/polyfill-table.js.map +1 -1
- package/dist/esm/context/state-tracker/track-context-state.js +0 -1
- package/dist/esm/context/state-tracker/track-context-state.js.map +1 -1
- package/dist/esm/context/state-tracker/with-parameters.js +1 -1
- package/dist/esm/context/state-tracker/with-parameters.js.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/adapter/converters/device-parameters.ts +11 -11
- package/src/adapter/converters/texture-formats.ts +12 -12
- package/src/adapter/converters/vertex-formats.ts +1 -0
- package/src/adapter/device-helpers/device-features.ts +0 -1
- package/src/adapter/device-helpers/get-device-info.ts +5 -1
- package/src/adapter/helpers/get-shader-layout.ts +18 -15
- package/src/adapter/helpers/set-uniform.ts +1 -1
- package/src/adapter/objects/constants-to-keys.ts +4 -1
- package/src/adapter/objects/webgl-renderbuffer.ts +5 -5
- package/src/adapter/objects/webgl-resource.ts +7 -12
- package/src/adapter/objects/webgl-vertex-array-object.ts +4 -4
- package/src/adapter/resources/webgl-buffer.ts +4 -4
- package/src/adapter/resources/webgl-command-encoder.ts +4 -4
- package/src/adapter/resources/webgl-framebuffer.ts +6 -5
- package/src/adapter/resources/webgl-render-pipeline.ts +24 -23
- package/src/adapter/resources/webgl-sampler.ts +5 -1
- package/src/adapter/resources/webgl-shader.ts +1 -1
- package/src/adapter/resources/webgl-texture.ts +5 -7
- package/src/adapter/webgl-canvas-context.ts +2 -3
- package/src/adapter/webgl-device.ts +69 -59
- package/src/classic/buffer.ts +7 -4
- package/src/context/debug/webgl-developer-tools.ts +7 -7
- package/src/context/parameters/unified-parameter-api.ts +1 -1
- package/src/context/parameters/webgl-parameter-tables.ts +113 -94
- package/src/context/polyfill/context-data.ts +27 -0
- package/src/context/polyfill/get-parameter-polyfill.ts +7 -6
- package/src/context/polyfill/polyfill-context.ts +5 -5
- package/src/context/polyfill/polyfill-table.ts +14 -13
- package/src/context/state-tracker/track-context-state.ts +0 -1
- package/src/context/state-tracker/with-parameters.ts +2 -1
- package/src/index.ts +0 -3
- package/dist/context/context/context-state.d.ts +0 -18
- package/dist/context/context/context-state.d.ts.map +0 -1
- package/dist/context/context/context-state.js +0 -26
- package/dist/context/context/context-state.js.map +0 -1
- package/dist/context/context/device-pixels.d.ts +0 -25
- package/dist/context/context/device-pixels.d.ts.map +0 -1
- package/dist/context/context/device-pixels.js +0 -103
- package/dist/context/context/device-pixels.js.map +0 -1
- package/dist/es5/context/context/context-state.js +0 -31
- package/dist/es5/context/context/context-state.js.map +0 -1
- package/dist/es5/context/context/device-pixels.js +0 -121
- package/dist/es5/context/context/device-pixels.js.map +0 -1
- package/dist/esm/context/context/context-state.js +0 -26
- package/dist/esm/context/context/context-state.js.map +0 -1
- package/dist/esm/context/context/device-pixels.js +0 -103
- package/dist/esm/context/context/device-pixels.js.map +0 -1
- package/src/context/context/context-state.ts +0 -41
- package/src/context/context/device-pixels.ts +0 -158
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adapter/webgl-device.ts"],"names":["Device","CanvasContext","log","isBrowser","polyfillContext","trackContextState","createBrowserContext","createHeadlessContext","isHeadlessGLRegistered","getDeviceInfo","getDeviceFeatures","getDeviceLimits","getWebGLLimits","WebGLCanvasContext","loadSpectorJS","initializeSpectorJS","loadWebGLDeveloperTools","makeDebugContext","isTextureFormatSupported","isTextureFormatRenderable","isTextureFormatFilterable","ClassicBuffer","WEBGLShader","WEBGLSampler","WEBGLTexture","WEBGLFramebuffer","WEBGLRenderPass","WEBGLRenderPipeline","LOG_LEVEL","counter","WebGLDevice","isSupported","WebGLRenderingContext","features","_features","gl","limits","_limits","webglLimits","_webglLimits","attach","device","isWebGL","Error","create","props","groupCollapsed","canvas","pageLoaded","debug","spector","probe","constructor","clientWidth","clientHeight","devicePixelRatio","id","canvasContext","lost","Promise","resolve","_resolveContextLost","onContextLost","event","reason","message","handle","gl2","isWebGL2","isWebGL1","info","_version","enable","copyState","args","webgl2","throwOnError","level","Math","max","warn","type","vendor","renderer","groupEnd","destroy","ext","getExtension","loseDevice","loseContext","isLost","isContextLost","getSize","drawingBufferWidth","drawingBufferHeight","format","assertWebGL2","createCanvasContext","_createBuffer","_createTexture","createExternalTexture","createSampler","createShader","createFramebuffer","createRenderPipeline","beginRenderPass","createComputePipeline","beginComputePass","getDefaultRenderPass","renderPass","framebuffer","getCurrentFramebuffer","submit","endPass","WebGL2RenderingContext","Boolean","Number","isFinite"],"mappings":";AASA,SAAQA,MAAR,EAAgBC,aAAhB,EAA+BC,GAA/B,QAAiD,cAAjD;AACA,SAAQC,SAAR,QAAwB,eAAxB;AACA,SAAQC,eAAR,QAA8B,sCAA9B;AACA,SAAQC,iBAAR,QAAgC,8CAAhC;AAEA,SAAQC,oBAAR,QAAmC,2CAAnC;AACA,SACEC,qBADF,EAEEC,sBAFF,QAGO,4CAHP;AAIA,SAAQC,aAAR,QAA4B,kCAA5B;AACA,SAAQC,iBAAR,QAAgC,kCAAhC;AACA,SAAQC,eAAR,EAAyBC,cAAzB,QAA2D,gCAA3D;AACA,OAAOC,kBAAP,MAA+B,wBAA/B;AACA,SAAQC,aAAR,EAAuBC,mBAAvB,QAAiD,0BAAjD;AACA,SAAQC,uBAAR,EAAiCC,gBAAjC,QAAwD,wCAAxD;AACA,SACEC,wBADF,EAEEC,yBAFF,EAGEC,yBAHF,QAIO,8BAJP;AA0BA,OAAOC,aAAP,MAA0B,mBAA1B;AAEA,OAAOC,WAAP,MAAwB,0BAAxB;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,OAAOC,YAAP,MAAyB,2BAAzB;AACA,OAAOC,gBAAP,MAA6B,+BAA7B;AACA,OAAOC,eAAP,MAA4B,+BAA5B;AACA,OAAOC,mBAAP,MAAgC,mCAAhC;AAEA,MAAMC,SAAS,GAAG,CAAlB;AAEA,IAAIC,OAAO,GAAG,CAAd;AAGA,eAAe,MAAMC,WAAN,SAA0B9B,MAA1B,CAAyD;AAOpD,SAAX+B,WAAW,GAAY;AAC5B,WAAO,OAAOC,qBAAP,KAAiC,WAAjC,IAAgDxB,sBAAsB,EAA7E;AACD;;AAOW,MAARyB,QAAQ,GAAuB;AACjC,SAAKC,SAAL,GAAiB,KAAKA,SAAL,IAAkBxB,iBAAiB,CAAC,KAAKyB,EAAN,CAApD;AACA,WAAO,KAAKD,SAAZ;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AAYH,qBAAlE,EAAyF;AACvF,WAAO,IAAP;AACD;;AACD,MAAI,OAAOkF,sBAAP,KAAkC,WAAlC,IAAiD/E,EAAE,YAAY+E,sBAAnE,EAA2F;AACzF,WAAO,IAAP;AACD;;AAED,SAAOC,OAAO,CAAChF,EAAE,IAAIiF,MAAM,CAACC,QAAP,CAAgBlF,EAAE,CAACoC,QAAnB,CAAP,CAAd;AACD;;AAGD,SAASH,QAAT,CAAkBjC,EAAlB,EAAoC;AAClC,MAAI,OAAO+E,sBAAP,KAAkC,WAAlC,IAAiD/E,EAAE,YAAY+E,sBAAnE,EAA2F;AACzF,WAAO,IAAP;AACD;;AAED,SAAOC,OAAO,CAAChF,EAAE,IAAIA,EAAE,CAACoC,QAAH,KAAgB,CAAvB,CAAd;AACD","sourcesContent":["// luma.gl, MIT license\nimport type {\n DeviceProps,\n DeviceInfo,\n DeviceLimits,\n DeviceFeature,\n CanvasContextProps,\n TextureFormat\n} from '@luma.gl/api';\nimport {Device, CanvasContext, log, assert} from '@luma.gl/api';\nimport {isBrowser} from '@probe.gl/env';\nimport {polyfillContext} from '../context/polyfill/polyfill-context';\nimport {trackContextState} from '../context/state-tracker/track-context-state';\nimport {ContextState} from '../context/context/context-state';\nimport {createBrowserContext} from '../context/context/create-browser-context';\nimport {\n createHeadlessContext,\n isHeadlessGLRegistered\n} from '../context/context/create-headless-context';\nimport {getDeviceInfo} from './device-helpers/get-device-info';\nimport {getDeviceFeatures} from './device-helpers/device-features';\nimport {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';\nimport WebGLCanvasContext from './webgl-canvas-context';\nimport {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';\nimport {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';\nimport {\n isTextureFormatSupported,\n isTextureFormatRenderable,\n isTextureFormatFilterable\n} from './converters/texture-formats';\n\n// WebGL classes\nimport type {\n BufferProps,\n ShaderProps,\n Sampler,\n SamplerProps,\n TextureProps,\n ExternalTexture,\n ExternalTextureProps,\n FramebufferProps,\n RenderPipeline,\n RenderPipelineProps,\n ComputePipeline,\n ComputePipelineProps,\n RenderPass,\n RenderPassProps,\n ComputePass,\n ComputePassProps\n} from '@luma.gl/api';\n\nimport ClassicBuffer from '../classic/buffer';\nimport WEBGLBuffer from './resources/webgl-buffer';\nimport WEBGLShader from './resources/webgl-shader';\nimport WEBGLSampler from './resources/webgl-sampler';\nimport WEBGLTexture from './resources/webgl-texture';\nimport WEBGLFramebuffer from './resources/webgl-framebuffer';\nimport WEBGLRenderPass from './resources/webgl-render-pass';\nimport WEBGLRenderPipeline from './resources/webgl-render-pipeline';\n\nconst LOG_LEVEL = 1;\n\nlet counter = 0;\n\n/** WebGPU style Device API for a WebGL context */\nexport default class WebGLDevice extends Device implements ContextState {\n //\n // Public `Device` API\n //\n\n static type: string = 'webgl';\n\n static isSupported(): boolean {\n return typeof WebGLRenderingContext !== 'undefined' || isHeadlessGLRegistered();\n }\n\n readonly info: DeviceInfo;\n readonly canvasContext: WebGLCanvasContext;\n\n readonly handle: WebGLRenderingContext;\n\n get features(): Set<DeviceFeature> {\n this._features = this._features || getDeviceFeatures(this.gl);\n return this._features;\n }\n\n get limits(): DeviceLimits {\n this._limits = this._limits || getDeviceLimits(this.gl);\n return this._limits;\n }\n\n readonly lost: Promise<{reason: 'destroyed'; message: string}>;\n\n private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;\n private _features?: Set<DeviceFeature>;\n private _limits?: DeviceLimits;\n\n //\n // WebGL-only API (not part of `Device` API)\n //\n\n /** WebGL1 typed context. Can always be used. */\n readonly gl: WebGLRenderingContext;\n /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */\n readonly gl2: WebGL2RenderingContext | null = null;\n readonly debug: boolean = false;\n\n /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */\n readonly isWebGL1: boolean;\n /** `true` if this is a WebGL2 context. @note `false` if WebGL1 */\n readonly isWebGL2: boolean;\n\n get webglLimits(): WebGLLimits {\n this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);\n return this._webglLimits;\n }\n\n private _webglLimits?: WebGLLimits;\n\n /** State used by luma.gl classes: TODO - move to canvasContext*/\n readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};\n /** State used by luma.gl classes */\n readonly _extensions: Record<string, any> = {};\n _polyfilled: boolean = false;\n\n /** Instance of Spector.js (if initialized) */\n spector;\n\n //\n // Static methods, expected to be present by `luma.createDevice()`\n //\n\n /**\n * Get a device instance from a GL context\n * Creates and instruments the device if not already created\n * @param gl\n * @returns\n */\n static attach(gl: Device | WebGLRenderingContext | WebGL2RenderingContext): WebGLDevice {\n if (gl instanceof WebGLDevice) {\n return gl;\n }\n // @ts-expect-error\n if (gl?.device instanceof Device) {\n // @ts-expect-error\n return gl.device as WebGLDevice;\n }\n if (!isWebGL(gl)) {\n throw new Error('Invalid WebGLRenderingContext');\n }\n return new WebGLDevice({gl: gl as WebGLRenderingContext});\n }\n\n static async create(props: DeviceProps = {}): Promise<WebGLDevice> {\n log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created');\n\n // Wait for page to load. Only wait when props. canvas is string\n // to avoid setting page onload callback unless necessary\n if (typeof props.canvas === 'string') {\n await CanvasContext.pageLoaded;\n }\n\n // Load webgl and spector debug scripts from CDN if requested\n if (props.debug) {\n await loadWebGLDeveloperTools();\n }\n // @ts-expect-error spector not on props\n if (props.spector) {\n await loadSpectorJS();\n }\n\n log.probe(LOG_LEVEL + 1, 'DOM is loaded')();\n\n // @ts-expect-error\n if (props.gl && props.gl.device) {\n return WebGLDevice.attach(props.gl);\n }\n\n return new WebGLDevice(props);\n }\n\n //\n // Public API\n //\n\n constructor(props: DeviceProps) {\n super(props);\n\n // If attaching to an already attached context, return the attached device\n // @ts-expect-error device is attached to context\n const device: WebGLDevice | undefined = props.gl?.device;\n if (device) {\n throw new Error(`WebGL context already attached to device ${device.id}`);\n }\n\n // Create and instrument context\n this.canvasContext = new WebGLCanvasContext(this, props);\n\n this.lost = new Promise<{reason: 'destroyed'; message: string}>((resolve) => {\n this._resolveContextLost = resolve;\n });\n\n const onContextLost = (event: Event) =>\n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'\n });\n\n let gl: WebGLRenderingContext | WebGL2RenderingContext | null = props.gl;\n gl =\n gl ||\n (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {...props, onContextLost}) : null);\n gl = gl || (!isBrowser() ? createHeadlessContext({...props, onContextLost}) : null);\n\n if (!gl) {\n throw new Error('WebGL context creation failed');\n }\n\n this.handle = gl;\n this.gl = this.handle;\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.isWebGL2 = isWebGL2(this.gl);\n this.isWebGL1 = !this.isWebGL2;\n\n // luma Device fields\n this.info = getDeviceInfo(this.gl);\n\n // @ts-expect-error Link webgl context back to device\n this.gl.device = this;\n // @ts-expect-error Annotate webgl context to handle\n this.gl._version = this.isWebGL2 ? 2 : 1;\n\n // Add subset of WebGL2 methods to WebGL1 context\n polyfillContext(this.gl);\n\n // Install context state tracking\n // @ts-expect-error - hidden parameters\n const {enable = true, copyState = false} = props;\n trackContextState(this.gl, {\n enable,\n copyState,\n log: (...args: any[]) => log.log(1, ...args)()\n });\n\n // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1\n if (isBrowser() && props.debug) {\n this.gl = makeDebugContext(this.gl, {...props, webgl2: this.isWebGL2, throwOnError: true});\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.debug = true;\n log.level = Math.max(log.level, 1);\n log.warn('WebGL debug mode activated. Performance reduced.')();\n }\n\n // @ts-expect-error spector not on props\n if (isBrowser() && props.spector) {\n const canvas = this.handle.canvas || (props.canvas as HTMLCanvasElement);\n this.spector = initializeSpectorJS({...this.props, canvas});\n }\n\n // Log some debug info about the newly created context\n const message = `\\\nCreated ${this.info.type}${this.debug ? ' debug' : ''} context: \\\n${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`;\n log.probe(LOG_LEVEL, message)();\n\n log.groupEnd(LOG_LEVEL)();\n }\n\n /**\n * Destroys the context\n * @note Has no effect for browser contexts, there is no browser API for destroying contexts\n */\n destroy() {\n const ext = this.gl.getExtension('STACKGL_destroy_context');\n if (ext) {\n ext.destroy();\n }\n }\n\n /**\n * Loses the context\n * @note Triggers context loss, mainly for testing\n */\n loseDevice() {\n const ext = this.gl.getExtension('WEBGL_lose_context');\n if (ext) {\n ext.loseContext();\n }\n // loseContext should trigger context loss callback but \n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Application triggered context loss'\n });\n }\n\n get isLost(): boolean {\n return this.gl.isContextLost();\n }\n\n getSize(): [number, number] {\n return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];\n }\n\n isTextureFormatSupported(format: TextureFormat): boolean {\n return isTextureFormatSupported(this.gl, format);\n }\n\n isTextureFormatFilterable(format: TextureFormat): boolean {\n return isTextureFormatFilterable(this.gl, format);\n }\n\n isTextureFormatRenderable(format: TextureFormat): boolean {\n return isTextureFormatRenderable(this.gl, format);\n }\n\n // WEBGL SPECIFIC METHODS\n\n /** Returns a WebGL2RenderingContext or throws an error */\n assertWebGL2(): WebGL2RenderingContext {\n if (!this.gl2) {\n throw new Error('Requires WebGL2');\n }\n return this.gl2;\n }\n\n // IMPLEMENTATION OF ABSTRACT DEVICE\n\n createCanvasContext(props?: CanvasContextProps): CanvasContext {\n throw new Error('WebGL only supports a single canvas');\n }\n\n _createBuffer(props: BufferProps): WEBGLBuffer {\n return new ClassicBuffer(this, props);\n }\n\n _createTexture(props: TextureProps): WEBGLTexture {\n return new WEBGLTexture(this, props);\n }\n\n createExternalTexture(props: ExternalTextureProps): ExternalTexture {\n throw new Error('createExternalTexture() not implemented'); // return new Program(props);\n }\n\n createSampler(props: SamplerProps): WEBGLSampler {\n return new WEBGLSampler(this, props);\n }\n\n createShader(props: ShaderProps): WEBGLShader {\n return new WEBGLShader(this, props);\n }\n\n createFramebuffer(props: FramebufferProps): WEBGLFramebuffer {\n return new WEBGLFramebuffer(this, props);\n }\n\n createRenderPipeline(props: RenderPipelineProps): WEBGLRenderPipeline {\n return new WEBGLRenderPipeline(this, props);\n }\n\n beginRenderPass(props: RenderPassProps): WEBGLRenderPass {\n return new WEBGLRenderPass(this, props);\n }\n\n createComputePipeline(props?: ComputePipelineProps): ComputePipeline {\n throw new Error('ComputePipeline not supported in WebGL');\n }\n\n beginComputePass(props: ComputePassProps): ComputePass {\n throw new Error('compute shaders not supported in WebGL');\n }\n\n private renderPass: WEBGLRenderPass | null = null;\n\n getDefaultRenderPass(): WEBGLRenderPass {\n this.renderPass =\n this.renderPass ||\n this.beginRenderPass({\n framebuffer: this.canvasContext.getCurrentFramebuffer()\n });\n return this.renderPass;\n }\n\n /**\n * Offscreen Canvas Support: Commit the frame\n * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit\n * Chrome's offscreen canvas does not require gl.commit\n */\n submit(): void {\n this.renderPass?.endPass();\n this.renderPass = null;\n // this.canvasContext.commit();\n }\n}\n\n/** Check if supplied parameter is a WebGLRenderingContext */\nfunction isWebGL(gl: any): boolean {\n if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {\n return true;\n }\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && Number.isFinite(gl._version));\n}\n\n/** Check if supplied parameter is a WebGL2RenderingContext */\nfunction isWebGL2(gl: any): boolean {\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && gl._version === 2);\n}\n"],"file":"webgl-device.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/adapter/webgl-device.ts"],"names":["Device","CanvasContext","log","uid","isBrowser","polyfillContext","popContextState","pushContextState","trackContextState","createBrowserContext","createHeadlessContext","isHeadlessGLRegistered","getDeviceInfo","getDeviceFeatures","getDeviceLimits","getWebGLLimits","WebGLCanvasContext","loadSpectorJS","initializeSpectorJS","loadWebGLDeveloperTools","makeDebugContext","isTextureFormatSupported","isTextureFormatRenderable","isTextureFormatFilterable","ClassicBuffer","WEBGLShader","WEBGLSampler","WEBGLTexture","WEBGLFramebuffer","WEBGLRenderPass","WEBGLRenderPipeline","LOG_LEVEL","WebGLDevice","isSupported","WebGLRenderingContext","features","_features","gl","limits","_limits","attach","device","isWebGL","Error","create","props","groupCollapsed","canvas","pageLoaded","debug","spector","probe","constructor","id","clientWidth","clientHeight","devicePixelRatio","canvasContext","lost","Promise","resolve","_resolveContextLost","onContextLost","event","reason","message","handle","gl2","isWebGL2","isWebGL1","info","_version","enable","copyState","args","webgl2","throwOnError","level","Math","max","warn","type","vendor","renderer","groupEnd","destroy","ext","getExtension","isLost","isContextLost","getSize","drawingBufferWidth","drawingBufferHeight","format","assertWebGL2","createCanvasContext","_createBuffer","_createTexture","createExternalTexture","createSampler","createShader","createFramebuffer","createRenderPipeline","beginRenderPass","createComputePipeline","beginComputePass","getDefaultRenderPass","renderPass","framebuffer","getCurrentFramebuffer","submit","endPass","webglLimits","_webglLimits","loseDevice","loseContext","pushState","popState","WebGL2RenderingContext","Boolean","Number","isFinite"],"mappings":";AASA,SAAQA,MAAR,EAAgBC,aAAhB,EAA+BC,GAA/B,EAAoCC,GAApC,QAA8C,cAA9C;AACA,SAAQC,SAAR,QAAwB,eAAxB;AACA,SAAQC,eAAR,QAA8B,sCAA9B;AACA,SAAQC,eAAR,EAAyBC,gBAAzB,EAA2CC,iBAA3C,QAAmE,8CAAnE;AACA,SAAQC,oBAAR,QAAmC,2CAAnC;AACA,SACEC,qBADF,EAEEC,sBAFF,QAGO,4CAHP;AAIA,SAAQC,aAAR,QAA4B,kCAA5B;AACA,SAAQC,iBAAR,QAAgC,kCAAhC;AACA,SAAQC,eAAR,EAAyBC,cAAz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,IAAImF,MAAM,CAACC,QAAP,CAAgBpF,EAAE,CAACkC,QAAnB,CAAP,CAAd;AACD;;AAGD,SAASH,QAAT,CAAkB/B,EAAlB,EAAoC;AAClC,MAAI,OAAOiF,sBAAP,KAAkC,WAAlC,IAAiDjF,EAAE,YAAYiF,sBAAnE,EAA2F;AACzF,WAAO,IAAP;AACD;;AAED,SAAOC,OAAO,CAAClF,EAAE,IAAIA,EAAE,CAACkC,QAAH,KAAgB,CAAvB,CAAd;AACD","sourcesContent":["// luma.gl, MIT license\nimport type {\n DeviceProps,\n DeviceInfo,\n DeviceLimits,\n DeviceFeature,\n CanvasContextProps,\n TextureFormat\n} from '@luma.gl/api';\nimport {Device, CanvasContext, log, uid} from '@luma.gl/api';\nimport {isBrowser} from '@probe.gl/env';\nimport {polyfillContext} from '../context/polyfill/polyfill-context';\nimport {popContextState, pushContextState, trackContextState} from '../context/state-tracker/track-context-state';\nimport {createBrowserContext} from '../context/context/create-browser-context';\nimport {\n createHeadlessContext,\n isHeadlessGLRegistered\n} from '../context/context/create-headless-context';\nimport {getDeviceInfo} from './device-helpers/get-device-info';\nimport {getDeviceFeatures} from './device-helpers/device-features';\nimport {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';\nimport WebGLCanvasContext from './webgl-canvas-context';\nimport {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';\nimport {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';\nimport {\n isTextureFormatSupported,\n isTextureFormatRenderable,\n isTextureFormatFilterable\n} from './converters/texture-formats';\n\n// WebGL classes\nimport type {\n BufferProps,\n ShaderProps,\n // Sampler,\n SamplerProps,\n TextureProps,\n ExternalTexture,\n ExternalTextureProps,\n FramebufferProps,\n // RenderPipeline,\n RenderPipelineProps,\n ComputePipeline,\n ComputePipelineProps,\n // RenderPass,\n RenderPassProps,\n ComputePass,\n ComputePassProps\n} from '@luma.gl/api';\n\nimport ClassicBuffer from '../classic/buffer';\nimport WEBGLBuffer from './resources/webgl-buffer';\nimport WEBGLShader from './resources/webgl-shader';\nimport WEBGLSampler from './resources/webgl-sampler';\nimport WEBGLTexture from './resources/webgl-texture';\nimport WEBGLFramebuffer from './resources/webgl-framebuffer';\nimport WEBGLRenderPass from './resources/webgl-render-pass';\nimport WEBGLRenderPipeline from './resources/webgl-render-pipeline';\n\nconst LOG_LEVEL = 1;\n\n/** WebGPU style Device API for a WebGL context */\nexport default class WebGLDevice extends Device {\n //\n // Public `Device` API\n //\n\n static type: string = 'webgl';\n\n static isSupported(): boolean {\n return typeof WebGLRenderingContext !== 'undefined' || isHeadlessGLRegistered();\n }\n\n readonly info: DeviceInfo;\n readonly canvasContext: WebGLCanvasContext;\n\n readonly handle: WebGLRenderingContext;\n\n get features(): Set<DeviceFeature> {\n this._features = this._features || getDeviceFeatures(this.gl);\n return this._features;\n }\n\n get limits(): DeviceLimits {\n this._limits = this._limits || getDeviceLimits(this.gl);\n return this._limits;\n }\n\n readonly lost: Promise<{reason: 'destroyed'; message: string}>;\n\n private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;\n private _features?: Set<DeviceFeature>;\n private _limits?: DeviceLimits;\n\n //\n // Static methods, expected to be present by `luma.createDevice()`\n //\n\n /**\n * Get a device instance from a GL context\n * Creates and instruments the device if not already created\n * @param gl\n * @returns\n */\n static attach(gl: Device | WebGLRenderingContext | WebGL2RenderingContext): WebGLDevice {\n if (gl instanceof WebGLDevice) {\n return gl;\n }\n // @ts-expect-error\n if (gl?.device instanceof Device) {\n // @ts-expect-error\n return gl.device as WebGLDevice;\n }\n if (!isWebGL(gl)) {\n throw new Error('Invalid WebGLRenderingContext');\n }\n return new WebGLDevice({gl: gl as WebGLRenderingContext});\n }\n\n static async create(props: DeviceProps = {}): Promise<WebGLDevice> {\n log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created');\n\n // Wait for page to load. Only wait when props. canvas is string\n // to avoid setting page onload callback unless necessary\n if (typeof props.canvas === 'string') {\n await CanvasContext.pageLoaded;\n }\n\n // Load webgl and spector debug scripts from CDN if requested\n if (props.debug) {\n await loadWebGLDeveloperTools();\n }\n // @ts-expect-error spector not on props\n if (props.spector) {\n await loadSpectorJS();\n }\n\n log.probe(LOG_LEVEL + 1, 'DOM is loaded')();\n\n // @ts-expect-error\n if (props.gl && props.gl.device) {\n return WebGLDevice.attach(props.gl);\n }\n\n return new WebGLDevice(props);\n }\n\n //\n // Public API\n //\n\n constructor(props: DeviceProps) {\n super({...props, id: props.id || uid('webgl-device')});\n\n // If attaching to an already attached context, return the attached device\n // @ts-expect-error device is attached to context\n const device: WebGLDevice | undefined = props.gl?.device;\n if (device) {\n throw new Error(`WebGL context already attached to device ${device.id}`);\n }\n\n // Create and instrument context\n this.canvasContext = new WebGLCanvasContext(this, props);\n\n this.lost = new Promise<{reason: 'destroyed'; message: string}>((resolve) => {\n this._resolveContextLost = resolve;\n });\n\n const onContextLost = (event: Event) =>\n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'\n });\n\n let gl: WebGLRenderingContext | WebGL2RenderingContext | null = props.gl || null;\n gl =\n gl ||\n (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {...props, onContextLost}) : null);\n gl = gl || (!isBrowser() ? createHeadlessContext({...props, onContextLost}) : null);\n\n if (!gl) {\n throw new Error('WebGL context creation failed');\n }\n\n this.handle = gl;\n this.gl = this.handle;\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.isWebGL2 = isWebGL2(this.gl);\n this.isWebGL1 = !this.isWebGL2;\n\n // luma Device fields\n this.info = getDeviceInfo(this.gl);\n\n // @ts-expect-error Link webgl context back to device\n this.gl.device = this;\n // @ts-expect-error Annotate webgl context to handle\n this.gl._version = this.isWebGL2 ? 2 : 1;\n\n // Add subset of WebGL2 methods to WebGL1 context\n polyfillContext(this.gl);\n\n // Install context state tracking\n // @ts-expect-error - hidden parameters\n const {enable = true, copyState = false} = props;\n trackContextState(this.gl, {\n enable,\n copyState,\n log: (...args: any[]) => log.log(1, ...args)()\n });\n\n // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1\n if (isBrowser() && props.debug) {\n this.gl = makeDebugContext(this.gl, {...props, webgl2: this.isWebGL2, throwOnError: true});\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.debug = true;\n log.level = Math.max(log.level, 1);\n log.warn('WebGL debug mode activated. Performance reduced.')();\n }\n\n // @ts-expect-error spector not on props\n if (isBrowser() && props.spector) {\n const canvas = this.handle.canvas || (props.canvas as HTMLCanvasElement);\n this.spector = initializeSpectorJS({...this.props, canvas});\n }\n\n // Log some debug info about the newly created context\n const message = `\\\nCreated ${this.info.type}${this.debug ? ' debug' : ''} context: \\\n${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`;\n log.probe(LOG_LEVEL, message)();\n\n log.groupEnd(LOG_LEVEL)();\n }\n\n /**\n * Destroys the context\n * @note Has no effect for browser contexts, there is no browser API for destroying contexts\n */\n destroy(): void {\n const ext = this.gl.getExtension('STACKGL_destroy_context');\n if (ext) {\n ext.destroy();\n }\n }\n\n get isLost(): boolean {\n return this.gl.isContextLost();\n }\n\n getSize(): [number, number] {\n return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];\n }\n\n isTextureFormatSupported(format: TextureFormat): boolean {\n return isTextureFormatSupported(this.gl, format);\n }\n\n isTextureFormatFilterable(format: TextureFormat): boolean {\n return isTextureFormatFilterable(this.gl, format);\n }\n\n isTextureFormatRenderable(format: TextureFormat): boolean {\n return isTextureFormatRenderable(this.gl, format);\n }\n\n // WEBGL SPECIFIC METHODS\n\n /** Returns a WebGL2RenderingContext or throws an error */\n assertWebGL2(): WebGL2RenderingContext {\n if (!this.gl2) {\n throw new Error('Requires WebGL2');\n }\n return this.gl2;\n }\n\n // IMPLEMENTATION OF ABSTRACT DEVICE\n\n createCanvasContext(props?: CanvasContextProps): CanvasContext {\n throw new Error('WebGL only supports a single canvas');\n }\n\n _createBuffer(props: BufferProps): WEBGLBuffer {\n return new ClassicBuffer(this, props);\n }\n\n _createTexture(props: TextureProps): WEBGLTexture {\n return new WEBGLTexture(this, props);\n }\n\n createExternalTexture(props: ExternalTextureProps): ExternalTexture {\n throw new Error('createExternalTexture() not implemented'); // return new Program(props);\n }\n\n createSampler(props: SamplerProps): WEBGLSampler {\n return new WEBGLSampler(this, props);\n }\n\n createShader(props: ShaderProps): WEBGLShader {\n return new WEBGLShader(this, props);\n }\n\n createFramebuffer(props: FramebufferProps): WEBGLFramebuffer {\n return new WEBGLFramebuffer(this, props);\n }\n\n createRenderPipeline(props: RenderPipelineProps): WEBGLRenderPipeline {\n return new WEBGLRenderPipeline(this, props);\n }\n\n beginRenderPass(props: RenderPassProps): WEBGLRenderPass {\n return new WEBGLRenderPass(this, props);\n }\n\n createComputePipeline(props?: ComputePipelineProps): ComputePipeline {\n throw new Error('ComputePipeline not supported in WebGL');\n }\n\n beginComputePass(props: ComputePassProps): ComputePass {\n throw new Error('compute shaders not supported in WebGL');\n }\n\n private renderPass: WEBGLRenderPass | null = null;\n\n getDefaultRenderPass(): WEBGLRenderPass {\n this.renderPass =\n this.renderPass ||\n this.beginRenderPass({\n framebuffer: this.canvasContext.getCurrentFramebuffer()\n });\n return this.renderPass;\n }\n\n /**\n * Offscreen Canvas Support: Commit the frame\n * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit\n * Chrome's offscreen canvas does not require gl.commit\n */\n submit(): void {\n this.renderPass?.endPass();\n this.renderPass = null;\n // this.canvasContext.commit();\n }\n\n //\n // WebGL-only API (not part of `Device` API)\n //\n\n /** WebGL1 typed context. Can always be used. */\n readonly gl: WebGLRenderingContext;\n /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */\n readonly gl2: WebGL2RenderingContext | null = null;\n readonly debug: boolean = false;\n\n /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */\n readonly isWebGL1: boolean;\n /** `true` if this is a WebGL2 context. @note `false` if WebGL1 */\n readonly isWebGL2: boolean;\n\n /** State used by luma.gl classes: TODO - move to canvasContext*/\n readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};\n\n /** State used by luma.gl classes - TODO - not used? */\n readonly _extensions: Record<string, any> = {};\n _polyfilled: boolean = false;\n\n /** Instance of Spector.js (if initialized) */\n spector;\n\n private _webglLimits?: WebGLLimits;\n\n /** Return WebGL specific limits */\n get webglLimits() : WebGLLimits {\n this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);\n return this._webglLimits;\n }\n\n /**\n * Loses the context\n * @note Triggers context loss, mainly for testing\n * @todo Promote to `Device` API?\n */\n loseDevice(): void {\n const ext = this.gl.getExtension('WEBGL_lose_context');\n if (ext) {\n ext.loseContext();\n }\n // loseContext should trigger context loss callback but \n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Application triggered context loss'\n });\n }\n\n /** Save current WebGL context state onto an internal stack */\n pushState(): void {\n pushContextState(this.gl);\n }\n\n /** Restores previously saved context state */\n popState(): void {\n popContextState(this.gl);\n }\n}\n\n/** Check if supplied parameter is a WebGLRenderingContext */\nfunction isWebGL(gl: any): boolean {\n if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {\n return true;\n }\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && Number.isFinite(gl._version));\n}\n\n/** Check if supplied parameter is a WebGL2RenderingContext */\nfunction isWebGL2(gl: any): boolean {\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && gl._version === 2);\n}\n"],"file":"webgl-device.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../src/classic/buffer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buffer.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GAAG,CAAA;KAAC,GAAG,IAAI;IAcnD,YAAY,IAAI;QACd,IAAI,EAAE,GAAG,CAAC;QACV,OAAO,EAAE,OAAO,CAAC;KAClB;IAQD,mBAAmB;IAOnB,QAAQ,CAAC,IAAI,KAAA,EAAE,MAAM,GAAE,MAAU,EAAE,UAAU,GAAE,MAAiC,GAAG,IAAI;IAwBvF,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,SAAkB,GAAG,IAAI;IA8BtE,UAAU;IAKV,yBAAyB,CAAC,aAAa,EAAE,MAAM;IAQ/C,UAAU,CAAC,IAAI,KAAA;IAQf,YAAY,CAAC,KAAK,EAAE,EAAE,GAAG,GAAG;IAQ5B,2CAA2C;IAC3C,IAAI,IAAI,WAEP;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/classic/buffer.ts"],"names":["assert","checkProps","GL","assertWebGL2Context","Accessor","getGLTypeFromTypedArray","getTypedArrayFromGLType","WebGLDevice","WEBGLBuffer","DEBUG_DATA_LENGTH","DEPRECATED_PROPS","offset","stride","type","size","divisor","normalized","integer","instanced","isInstanced","PROP_CHECKS_INITIALIZE","removedProps","replacedProps","bytes","deprecatedProps","PROP_CHECKS_SET_PROPS","getWEBGLBufferProps","props","ArrayBuffer","isView","data","byteLength","bufferProps","byteOffset","ClassicBuffer","constructor","device","attach","setAccessor","Object","assign","accessor","seal","destroy","handle","removeStats","trackDeallocatedMemory","gl","deleteBuffer","destroyed","write","subData","getElementCount","Math","round","getBytesPerElement","getVertexCount","getBytesPerVertex","initialize","Number","isFinite","webglUsage","STATIC_DRAW","debugData","_setData","_setByteLength","setProps","buffer","reallocate","bytesUsed","setData","options","srcOffset","length","target","webgl2","COPY_WRITE_BUFFER","bindBuffer","undefined","bufferSubData","_inferType","copyData","sourceBuffer","readOffset","writeOffset","gl2","COPY_READ_BUFFER","copyBufferSubData","getData","dstData","srcByteOffset","dstOffset","ArrayType","FLOAT","clamped","sourceAvailableElementCount","_getAvailableElementCount","dstElementOffset","dstAvailableElementCount","dstElementCount","min","copyElementCount","getBufferSubData","bind","index","UNIFORM_BUFFER","TRANSFORM_FEEDBACK_BUFFER","bindBufferRange","bindBufferBase","unbind","isIndexedBuffer","getDebugData","changed","invalidateDebugData","_getTarget","bufferData","slice","trackAllocatedMemory","Float32Array","sourceElementOffset","BYTES_PER_ELEMENT","getParameter","pname","value","getBufferParameter"],"mappings":";AACA,SAAqBA,MAArB,EAA6BC,UAA7B,QAA8C,cAA9C;AACA,OAAOC,EAAP,MAAe,oBAAf;AACA,SAAQC,mBAAR,QAAkC,iCAAlC;AAEA,OAAOC,QAAP,MAAqB,YAArB;AACA,SAAQC,uBAAR,EAAiCC,uBAAjC,QAA+D,qBAA/D;AAEA,OAAOC,WAAP,MAAwB,yBAAxB;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AAEA,MAAMC,iBAAiB,GAAG,EAA1B;AAGA,MAAMC,gBAAgB,GAAG;AACvBC,EAAAA,MAAM,EAAE,iBADe;AAEvBC,EAAAA,MAAM,EAAE,iBAFe;AAGvBC,EAAAA,IAAI,EAAE,eAHiB;AAIvBC,EAAAA,IAAI,EAAE,eAJiB;AAKvBC,EAAAA,OAAO,EAAE,kBALc;AAMvBC,EAAAA,UAAU,EAAE,qBANW;AAOvBC,EAAAA,OAAO,EAAE,kBAPc;AAQvBC,EAAAA,SAAS,EAAE,kBARY;AASvBC,EAAAA,WAAW,EAAE;AATU,CAAzB;AAaA,MAAMC,sBAAsB,GAAG;AAC7BC,EAAAA,YAAY,EAAE,EADe;AAE7BC,EAAAA,aAAa,EAAE;AACbC,IAAAA,KAAK,EAAE;AADM,GAFc;AAM7BC,EAAAA,eAAe,EAAEd;AANY,CAA/B;AAUA,MAAMe,qBAAqB,GAAG;AAE5BJ,EAAAA,YAAY,EAAEX;AAFc,CAA9B;;AAKA,SAASgB,mBAAT,CAA6BC,KAA7B,EAAgG;AAE9F,MAAIC,WAAW,CAACC,MAAZ,CAAmBF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IAAD,EAAO;AACf,QAAI,CAAC,KAAKW,QAAL,CAAc5B,IAAnB,EAAyB;AACvB,WAAKyB,WAAL,CAAiB,IAAIlC,QAAJ,CAAa,KAAKqC,QAAlB,EAA4B;AAAC5B,QAAAA,IAAI,EAAER,uBAAuB,CAACyB,IAAD;AAA9B,OAA5B,CAAjB;AACD;AACF;;AAID2F,EAAAA,YAAY,CAACC,KAAD,EAAiB;AAC3B,SAAK3E,EAAL,CAAQ8B,UAAR,CAAmB,KAAKH,MAAxB,EAAgC,KAAK9B,MAArC;AACA,UAAM+E,KAAK,GAAG,KAAK5E,EAAL,CAAQ6E,kBAAR,CAA2B,KAAKlD,MAAhC,EAAwCgD,KAAxC,CAAd;AACA,SAAK3E,EAAL,CAAQ8B,UAAR,CAAmB,KAAKH,MAAxB,EAAgC,IAAhC;AACA,WAAOiD,KAAP;AACD;;AAIO,MAAJ9G,IAAI,GAAG;AACT,WAAO,KAAK4B,QAAL,CAAc5B,IAArB;AACD;;AAvYoD","sourcesContent":["import type {Device, BufferProps, TypedArray} from '@luma.gl/api';\nimport {Buffer, log, assert, checkProps} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\nimport {assertWebGL2Context} from '../context/context/webgl-checks';\nimport {AccessorObject} from '../types';\nimport Accessor from './accessor';\nimport {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';\n\nimport WebGLDevice from '../adapter/webgl-device';\nimport WEBGLBuffer from '../adapter/resources/webgl-buffer';\n\nconst DEBUG_DATA_LENGTH = 10;\n\n// Shared prop checks for constructor and setProps\nconst DEPRECATED_PROPS = {\n offset: 'accessor.offset',\n stride: 'accessor.stride',\n type: 'accessor.type',\n size: 'accessor.size',\n divisor: 'accessor.divisor',\n normalized: 'accessor.normalized',\n integer: 'accessor.integer',\n instanced: 'accessor.divisor',\n isInstanced: 'accessor.divisor'\n};\n\n// Prop checks for constructor\nconst PROP_CHECKS_INITIALIZE = {\n removedProps: {},\n replacedProps: {\n bytes: 'byteLength'\n },\n // new Buffer() with individual accessor props is still used in apps, emit warnings\n deprecatedProps: DEPRECATED_PROPS\n};\n\n// Prop checks for setProps\nconst PROP_CHECKS_SET_PROPS = {\n // Buffer.setProps() with individual accessor props is rare => emit errors\n removedProps: DEPRECATED_PROPS\n};\n\nfunction getWEBGLBufferProps(props: ClassicBufferProps | ArrayBufferView | number): BufferProps {\n // Signature `new Buffer(gl, new Float32Array(...)`\n if (ArrayBuffer.isView(props)) {\n return {data: props};\n }\n\n // Signature: `new Buffer(gl, 100)`\n else if (typeof props === 'number') {\n return {byteLength: props as number};\n }\n\n props = checkProps('Buffer', props, PROP_CHECKS_INITIALIZE);\n const bufferProps = {...props as ClassicBufferProps};\n if (bufferProps.offset) {\n bufferProps.byteOffset = bufferProps.offset;\n }\n return bufferProps;\n}\n\n/** WebGL Buffer interface */\nexport type ClassicBufferProps = BufferProps & {\n handle?: WebGLBuffer;\n\n target?: number;\n webglUsage?: number;\n\n accessor?: AccessorObject;\n\n /** @deprecated */\n index?: number;\n /** @deprecated */\n offset?: number;\n /** @deprecated */\n size?: number;\n /** @deprecated */\n type?: number\n}\n\n/** WebGL Buffer interface */\nexport default class ClassicBuffer extends WEBGLBuffer {\n usage: number;\n accessor: Accessor;\n\n constructor(device: Device | WebGLRenderingContext, props?: ClassicBufferProps);\n constructor(device: Device | WebGLRenderingContext, data: ArrayBufferView | number[]);\n constructor(device: Device | WebGLRenderingContext, byteLength: number);\n\n constructor(device: Device | WebGLRenderingContext, props = {}) {\n super(WebGLDevice.attach(device), getWEBGLBufferProps(props));\n\n // Base class initializes\n // this.initialize(props);\n\n // Deprecated: Merge main props and accessor\n this.setAccessor(Object.assign({}, props, (props as ClassicBufferProps).accessor));\n\n // infer GL type from supplied typed array\n if (this.props.data) {\n const type = getGLTypeFromTypedArray(this.props.data as TypedArray);\n assert(type);\n this.setAccessor(new Accessor(this.accessor, {type}));\n }\n\n Object.seal(this);\n }\n\n destroy(): void {\n if (this.handle) {\n this.removeStats();\n this.trackDeallocatedMemory();\n this.gl.deleteBuffer(this.handle);\n // this.handle = null;\n this.destroyed = true;\n }\n }\n\n write(data: TypedArray, byteOffset?: number): void {\n this.subData({data, offset: byteOffset});\n }\n // returns number of elements in the buffer (assuming that the full buffer is used)\n getElementCount(accessor: AccessorObject = this.accessor): number {\n return Math.round(this.byteLength / Accessor.getBytesPerElement(accessor));\n }\n\n // returns number of vertices in the buffer (assuming that the full buffer is used)\n getVertexCount(accessor: AccessorObject = this.accessor): number {\n return Math.round(this.byteLength / Accessor.getBytesPerVertex(accessor));\n }\n\n // Creates and initializes the buffer object's data store.\n // Signature: `new Buffer(gl, {data: new Float32Array(...)})`\n // Signature: `new Buffer(gl, new Float32Array(...))`\n // Signature: `new Buffer(gl, 100)`\n initialize(props: ClassicBufferProps = {}): this {\n // Signature `new Buffer(gl, new Float32Array(...)`\n if (ArrayBuffer.isView(props)) {\n props = {data: props};\n }\n\n // Signature: `new Buffer(gl, 100)`\n if (Number.isFinite(props)) {\n // @ts-expect-error\n props = {byteLength: props};\n }\n\n props = checkProps('Buffer', props, PROP_CHECKS_INITIALIZE);\n\n // Initialize member fields\n this.webglUsage = props.webglUsage || GL.STATIC_DRAW;\n this.debugData = null;\n\n // Deprecated: Merge main props and accessor\n this.setAccessor(Object.assign({}, props, props.accessor));\n\n // Set data: (re)initializes the buffer\n if (props.data) {\n this._setData(props.data, props.offset, props.byteLength);\n } else {\n this._setByteLength(props.byteLength || 0);\n }\n\n return this;\n }\n\n setProps(props: ClassicBufferProps): this {\n props = checkProps('Buffer', props, PROP_CHECKS_SET_PROPS);\n\n if ('accessor' in props) {\n this.setAccessor(props.accessor);\n }\n\n return this;\n }\n\n // Optionally stores an accessor with the buffer, makes it easier to use it as an attribute later\n // {type, size = 1, offset = 0, stride = 0, normalized = false, integer = false, divisor = 0}\n setAccessor(accessor: AccessorObject | Accessor): this {\n // NOTE: From luma.gl v7.0, Accessors have an optional `buffer `field\n // (mainly to support \"interleaving\")\n // To avoid confusion, ensure `buffer.accessor` does not have a `buffer.accessor.buffer` field:\n accessor = Object.assign({}, accessor);\n // @ts-expect-error\n delete accessor.buffer;\n\n // This new statement ensures that an \"accessor object\" is re-packaged as an Accessor instance\n this.accessor = new Accessor(accessor);\n return this;\n }\n\n // Allocate a bigger GPU buffer (if the current buffer is not big enough).\n // If a reallocation is triggered it clears the buffer\n // Returns:\n // `true`: buffer was reallocated, data was cleared\n // `false`: buffer was big enough, data is intact\n reallocate(byteLength: number): boolean {\n if (byteLength > this.byteLength) {\n this._setByteLength(byteLength);\n return true;\n }\n this.bytesUsed = byteLength;\n return false;\n }\n\n // Update with new data. Reinitializes the buffer\n setData(props: ClassicBufferProps) {\n return this.initialize(props);\n }\n\n // Updates a subset of a buffer object's data store.\n // Data (Typed Array or ArrayBuffer), length is inferred unless provided\n // Offset into buffer\n // WebGL2 only: Offset into srcData\n // WebGL2 only: Number of bytes to be copied\n subData(options: TypedArray | {data: TypedArray, offset?: number; srcOffset?: number; byteLength?: number, length?: number}) {\n // Signature: buffer.subData(new Float32Array([...]))\n if (ArrayBuffer.isView(options)) {\n options = {data: options};\n }\n\n const {data, offset = 0, srcOffset = 0} = options;\n const byteLength = options.byteLength || options.length;\n\n assert(data);\n\n // Create the buffer - binding it here for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n // @ts-expect-error\n const target = this.gl.webgl2 ? GL.COPY_WRITE_BUFFER : this.target;\n this.gl.bindBuffer(target, this.handle);\n // WebGL2: subData supports additional srcOffset and length parameters\n if (srcOffset !== 0 || byteLength !== undefined) {\n assertWebGL2Context(this.gl);\n // @ts-expect-error\n this.gl.bufferSubData(this.target, offset, data, srcOffset, byteLength);\n } else {\n this.gl.bufferSubData(target, offset, data);\n }\n this.gl.bindBuffer(target, null);\n\n // TODO - update local `data` if offsets are right\n this.debugData = null;\n\n this._inferType(data);\n\n return this;\n }\n\n /**\n * Copies part of the data of another buffer into this buffer\n * @note WEBGL2 ONLY\n */\n copyData(options: {\n sourceBuffer: any;\n readOffset?: number;\n writeOffset?: number;\n size: any;\n }): this {\n const {sourceBuffer, readOffset = 0, writeOffset = 0, size} = options;\n const {gl, gl2} = this;\n assertWebGL2Context(gl);\n\n // Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type\n gl.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);\n gl.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);\n gl2?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);\n gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n gl.bindBuffer(GL.COPY_WRITE_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n this.debugData = null;\n\n return this;\n }\n\n /**\n * Reads data from buffer into an ArrayBufferView or SharedArrayBuffer.\n * @note WEBGL2 ONLY\n */\n getData(options?: {\n dstData?: any;\n srcByteOffset?: number;\n dstOffset?: number;\n length?: number;\n }): any {\n let {dstData = null, length = 0} = options || {};\n const {srcByteOffset = 0, dstOffset = 0} = options || {};\n assertWebGL2Context(this.gl);\n\n const ArrayType = getTypedArrayFromGLType(this.accessor.type || GL.FLOAT, {clamped: false});\n const sourceAvailableElementCount = this._getAvailableElementCount(srcByteOffset);\n\n const dstElementOffset = dstOffset;\n\n let dstAvailableElementCount;\n let dstElementCount;\n if (dstData) {\n dstElementCount = dstData.length;\n dstAvailableElementCount = dstElementCount - dstElementOffset;\n } else {\n // Allocate ArrayBufferView with enough size to copy all eligible data.\n dstAvailableElementCount = Math.min(\n sourceAvailableElementCount,\n length || sourceAvailableElementCount\n );\n dstElementCount = dstElementOffset + dstAvailableElementCount;\n }\n\n const copyElementCount = Math.min(sourceAvailableElementCount, dstAvailableElementCount);\n length = length || copyElementCount;\n assert(length <= copyElementCount);\n dstData = dstData || new ArrayType(dstElementCount);\n\n // Use GL.COPY_READ_BUFFER to avoid disturbing other targets and locking type\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);\n this.gl2?.getBufferSubData(GL.COPY_READ_BUFFER, srcByteOffset, dstData, dstOffset, length);\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n return dstData;\n }\n\n /**\n * Binds a buffer to a given binding point (target).\n * GL.TRANSFORM_FEEDBACK_BUFFER and GL.UNIFORM_BUFFER take an index, and optionally a range.\n * - GL.TRANSFORM_FEEDBACK_BUFFER and GL.UNIFORM_BUFFER need an index to affect state\n * - GL.UNIFORM_BUFFER: `offset` must be aligned to GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT.\n * - GL.UNIFORM_BUFFER: `size` must be a minimum of GL.UNIFORM_BLOCK_SIZE_DATA.\n */\n bind(options?: {target?: number; index?: any; offset?: number; size: any}): this {\n const {\n target = this.target, // target for the bind operation\n index = this.accessor && this.accessor.index, // index = index of target (indexed bind point)\n offset = 0,\n size\n } = options || {};\n // NOTE: While GL.TRANSFORM_FEEDBACK_BUFFER and GL.UNIFORM_BUFFER could\n // be used as direct binding points, they will not affect transform feedback or\n // uniform buffer state. Instead indexed bindings need to be made.\n if (target === GL.UNIFORM_BUFFER || target === GL.TRANSFORM_FEEDBACK_BUFFER) {\n if (size !== undefined) {\n this.gl2?.bindBufferRange(target, index, this.handle, offset, size);\n } else {\n assert(offset === 0); // Make sure offset wasn't supplied\n this.gl2?.bindBufferBase(target, index, this.handle);\n }\n } else {\n this.gl.bindBuffer(target, this.handle);\n }\n\n return this;\n }\n\n unbind(options?: {target?: any; index?: any}): this {\n const {target = this.target, index = this.accessor && this.accessor.index} = options || {};\n const isIndexedBuffer = target === GL.UNIFORM_BUFFER || target === GL.TRANSFORM_FEEDBACK_BUFFER;\n if (isIndexedBuffer) {\n this.gl2?.bindBufferBase(target, index, null);\n } else {\n this.gl.bindBuffer(target, null);\n }\n return this;\n }\n\n // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)\n\n // Returns a short initial data array\n getDebugData(): {\n data: any;\n changed: boolean;\n } {\n if (!this.debugData) {\n this.debugData = this.getData({length: Math.min(DEBUG_DATA_LENGTH, this.byteLength)});\n return {data: this.debugData, changed: true};\n }\n return {data: this.debugData, changed: false};\n }\n\n invalidateDebugData() {\n this.debugData = null;\n }\n\n // PRIVATE METHODS\n\n // Allocate a new buffer and initialize to contents of typed array\n _setData(data, offset: number = 0, byteLength: number = data.byteLength + offset): this {\n assert(ArrayBuffer.isView(data));\n\n this.trackDeallocatedMemory();\n\n const target = this._getTarget();\n this.gl.bindBuffer(target, this.handle);\n this.gl.bufferData(target, byteLength, this.webglUsage);\n this.gl.bufferSubData(target, offset, data);\n this.gl.bindBuffer(target, null);\n\n this.debugData = data.slice(0, DEBUG_DATA_LENGTH);\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n this.trackAllocatedMemory(byteLength);\n\n // infer GL type from supplied typed array\n const type = getGLTypeFromTypedArray(data);\n assert(type);\n this.setAccessor(new Accessor(this.accessor, {type}));\n return this;\n }\n\n // Allocate a GPU buffer of specified size.\n _setByteLength(byteLength: number, webglUsage = this.webglUsage): this {\n assert(byteLength >= 0);\n\n this.trackDeallocatedMemory();\n\n // Workaround needed for Safari (#291):\n // gl.bufferData with size equal to 0 crashes. Instead create zero sized array.\n let data = byteLength;\n if (byteLength === 0) {\n // @ts-expect-error\n data = new Float32Array(0);\n }\n\n const target = this._getTarget();\n this.gl.bindBuffer(target, this.handle);\n this.gl.bufferData(target, data, webglUsage);\n this.gl.bindBuffer(target, null);\n\n this.webglUsage = webglUsage;\n this.debugData = null;\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n this.trackAllocatedMemory(byteLength);\n\n return this;\n }\n\n // Binding a buffer for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n _getTarget() {\n // @ts-expect-error\n return this.gl.webgl2 ? GL.COPY_WRITE_BUFFER : this.target;\n }\n\n _getAvailableElementCount(srcByteOffset: number) {\n const ArrayType = getTypedArrayFromGLType(this.accessor.type || GL.FLOAT, {clamped: false});\n const sourceElementOffset = srcByteOffset / ArrayType.BYTES_PER_ELEMENT;\n return this.getElementCount() - sourceElementOffset;\n }\n\n // Automatically infers type from typed array passed to setData\n // Note: No longer that useful, since type is now autodeduced from the compiled shaders\n _inferType(data) {\n if (!this.accessor.type) {\n this.setAccessor(new Accessor(this.accessor, {type: getGLTypeFromTypedArray(data)}));\n }\n }\n\n // RESOURCE METHODS\n\n getParameter(pname: GL): any {\n this.gl.bindBuffer(this.target, this.handle);\n const value = this.gl.getBufferParameter(this.target, pname);\n this.gl.bindBuffer(this.target, null);\n return value;\n }\n\n // DEPRECATIONS - v7.0\n /** @deprecated Use Buffer.accessor.type */\n get type() {\n return this.accessor.type;\n }\n}\n"],"file":"buffer.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/classic/buffer.ts"],"names":["assert","checkProps","GL","assertWebGL2Context","Accessor","getGLTypeFromTypedArray","getTypedArrayFromGLType","WebGLDevice","WEBGLBuffer","DEBUG_DATA_LENGTH","DEPRECATED_PROPS","offset","stride","type","size","divisor","normalized","integer","instanced","isInstanced","PROP_CHECKS_INITIALIZE","removedProps","replacedProps","bytes","deprecatedProps","PROP_CHECKS_SET_PROPS","getWEBGLBufferProps","props","ArrayBuffer","isView","data","byteLength","bufferProps","byteOffset","ClassicBuffer","constructor","device","attach","setAccessor","Object","assign","accessor","seal","destroy","handle","removeStats","trackDeallocatedMemory","gl","deleteBuffer","destroyed","write","subData","getElementCount","Math","round","getBytesPerElement","getVertexCount","getBytesPerVertex","initialize","Number","isFinite","webglUsage","STATIC_DRAW","debugData","_setData","_setByteLength","setProps","buffer","reallocate","bytesUsed","setData","options","srcOffset","length","target","webgl2","COPY_WRITE_BUFFER","bindBuffer","undefined","bufferSubData","_inferType","copyData","sourceBuffer","readOffset","writeOffset","gl2","COPY_READ_BUFFER","copyBufferSubData","getData","dstData","srcByteOffset","dstOffset","ArrayType","FLOAT","clamped","sourceAvailableElementCount","_getAvailableElementCount","dstElementOffset","dstAvailableElementCount","dstElementCount","min","copyElementCount","getBufferSubData","bind","index","UNIFORM_BUFFER","TRANSFORM_FEEDBACK_BUFFER","bindBufferRange","bindBufferBase","unbind","isIndexedBuffer","getDebugData","changed","invalidateDebugData","_getTarget","bufferData","slice","trackAllocatedMemory","Float32Array","sourceElementOffset","BYTES_PER_ELEMENT","getParameter","pname","value","getBufferParameter"],"mappings":";AAGA,SAAQA,MAAR,EAAgBC,UAAhB,QAAiC,cAAjC;AACA,OAAOC,EAAP,MAAe,oBAAf;AACA,SAAQC,mBAAR,QAAkC,iCAAlC;AAEA,OAAOC,QAAP,MAAqB,YAArB;AACA,SAAQC,uBAAR,EAAiCC,uBAAjC,QAA+D,qBAA/D;AAEA,OAAOC,WAAP,MAAwB,yBAAxB;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AAEA,MAAMC,iBAAiB,GAAG,EAA1B;AAGA,MAAMC,gBAAgB,GAAG;AACvBC,EAAAA,MAAM,EAAE,iBADe;AAEvBC,EAAAA,MAAM,EAAE,iBAFe;AAGvBC,EAAAA,IAAI,EAAE,eAHiB;AAIvBC,EAAAA,IAAI,EAAE,eAJiB;AAKvBC,EAAAA,OAAO,EAAE,kBALc;AAMvBC,EAAAA,UAAU,EAAE,qBANW;AAOvBC,EAAAA,OAAO,EAAE,kBAPc;AAQvBC,EAAAA,SAAS,EAAE,kBARY;AASvBC,EAAAA,WAAW,EAAE;AATU,CAAzB;AAaA,MAAMC,sBAAsB,GAAG;AAC7BC,EAAAA,YAAY,EAAE,EADe;AAE7BC,EAAAA,aAAa,EAAE;AACbC,IAAAA,KAAK,EAAE;AADM,GAFc;AAM7BC,EAAAA,eAAe,EAAEd;AANY,CAA/B;AAUA,MAAMe,qBAAqB,GAAG;AAE5BJ,EAAAA,YAAY,EAAEX;AAFc,CAA9B;;AAKA,SAASgB,mBAAT,CAA6BC,KAA7B,EAAgG;AAE9F,MAAIC,WAAW,CAACC,MAAZ,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U,CAAClD,IAAD,EAAO;AACf,QAAI,CAAC,KAAKW,QAAL,CAAc5B,IAAnB,EAAyB;AACvB,WAAKyB,WAAL,CAAiB,IAAIlC,QAAJ,CAAa,KAAKqC,QAAlB,EAA4B;AAAC5B,QAAAA,IAAI,EAAER,uBAAuB,CAACyB,IAAD;AAA9B,OAA5B,CAAjB;AACD;AACF;;AAID2F,EAAAA,YAAY,CAACC,KAAD,EAAiB;AAC3B,SAAK3E,EAAL,CAAQ8B,UAAR,CAAmB,KAAKH,MAAxB,EAAgC,KAAK9B,MAArC;AACA,UAAM+E,KAAK,GAAG,KAAK5E,EAAL,CAAQ6E,kBAAR,CAA2B,KAAKlD,MAAhC,EAAwCgD,KAAxC,CAAd;AACA,SAAK3E,EAAL,CAAQ8B,UAAR,CAAmB,KAAKH,MAAxB,EAAgC,IAAhC;AACA,WAAOiD,KAAP;AACD;;AAIO,MAAJ9G,IAAI,GAAG;AACT,WAAO,KAAK4B,QAAL,CAAc5B,IAArB;AACD;;AAxYoD","sourcesContent":["// luma.gl, MIT license\n\nimport type {Device, BufferProps, TypedArray} from '@luma.gl/api';\nimport {assert, checkProps} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\nimport {assertWebGL2Context} from '../context/context/webgl-checks';\nimport {AccessorObject} from '../types';\nimport Accessor from './accessor';\nimport {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';\n\nimport WebGLDevice from '../adapter/webgl-device';\nimport WEBGLBuffer from '../adapter/resources/webgl-buffer';\n\nconst DEBUG_DATA_LENGTH = 10;\n\n// Shared prop checks for constructor and setProps\nconst DEPRECATED_PROPS = {\n offset: 'accessor.offset',\n stride: 'accessor.stride',\n type: 'accessor.type',\n size: 'accessor.size',\n divisor: 'accessor.divisor',\n normalized: 'accessor.normalized',\n integer: 'accessor.integer',\n instanced: 'accessor.divisor',\n isInstanced: 'accessor.divisor'\n};\n\n// Prop checks for constructor\nconst PROP_CHECKS_INITIALIZE = {\n removedProps: {},\n replacedProps: {\n bytes: 'byteLength'\n },\n // new Buffer() with individual accessor props is still used in apps, emit warnings\n deprecatedProps: DEPRECATED_PROPS\n};\n\n// Prop checks for setProps\nconst PROP_CHECKS_SET_PROPS = {\n // Buffer.setProps() with individual accessor props is rare => emit errors\n removedProps: DEPRECATED_PROPS\n};\n\nfunction getWEBGLBufferProps(props: ClassicBufferProps | ArrayBufferView | number): BufferProps {\n // Signature `new Buffer(gl, new Float32Array(...)`\n if (ArrayBuffer.isView(props)) {\n return {data: props};\n }\n\n // Signature: `new Buffer(gl, 100)`\n else if (typeof props === 'number') {\n return {byteLength: props as number};\n }\n\n props = checkProps('Buffer', props, PROP_CHECKS_INITIALIZE);\n const bufferProps = {...props as ClassicBufferProps};\n if (bufferProps.offset) {\n bufferProps.byteOffset = bufferProps.offset;\n }\n return bufferProps;\n}\n\n/** WebGL Buffer interface */\nexport type ClassicBufferProps = BufferProps & {\n handle?: WebGLBuffer;\n\n target?: number;\n webglUsage?: number;\n\n accessor?: AccessorObject;\n\n /** @deprecated */\n index?: number;\n /** @deprecated */\n offset?: number;\n /** @deprecated */\n size?: number;\n /** @deprecated */\n type?: number\n}\n\n/** WebGL Buffer interface */\nexport default class ClassicBuffer extends WEBGLBuffer {\n usage: number;\n accessor: Accessor;\n\n constructor(device: Device | WebGLRenderingContext, props?: ClassicBufferProps);\n constructor(device: Device | WebGLRenderingContext, data: ArrayBufferView | number[]);\n constructor(device: Device | WebGLRenderingContext, byteLength: number);\n\n constructor(device: Device | WebGLRenderingContext, props = {}) {\n super(WebGLDevice.attach(device), getWEBGLBufferProps(props));\n\n // Base class initializes\n // this.initialize(props);\n\n // Deprecated: Merge main props and accessor\n this.setAccessor(Object.assign({}, props, (props as ClassicBufferProps).accessor));\n\n // infer GL type from supplied typed array\n if (this.props.data) {\n const type = getGLTypeFromTypedArray(this.props.data as TypedArray);\n assert(type);\n this.setAccessor(new Accessor(this.accessor, {type}));\n }\n\n Object.seal(this);\n }\n\n override destroy(): void {\n if (this.handle) {\n this.removeStats();\n this.trackDeallocatedMemory();\n this.gl.deleteBuffer(this.handle);\n // this.handle = null;\n this.destroyed = true;\n }\n }\n\n override write(data: TypedArray, byteOffset?: number): void {\n this.subData({data, offset: byteOffset});\n }\n\n // returns number of elements in the buffer (assuming that the full buffer is used)\n getElementCount(accessor: AccessorObject = this.accessor): number {\n return Math.round(this.byteLength / Accessor.getBytesPerElement(accessor));\n }\n\n // returns number of vertices in the buffer (assuming that the full buffer is used)\n getVertexCount(accessor: AccessorObject = this.accessor): number {\n return Math.round(this.byteLength / Accessor.getBytesPerVertex(accessor));\n }\n\n // Creates and initializes the buffer object's data store.\n // Signature: `new Buffer(gl, {data: new Float32Array(...)})`\n // Signature: `new Buffer(gl, new Float32Array(...))`\n // Signature: `new Buffer(gl, 100)`\n initialize(props: ClassicBufferProps = {}): this {\n // Signature `new Buffer(gl, new Float32Array(...)`\n if (ArrayBuffer.isView(props)) {\n props = {data: props};\n }\n\n // Signature: `new Buffer(gl, 100)`\n if (Number.isFinite(props)) {\n // @ts-expect-error\n props = {byteLength: props};\n }\n\n props = checkProps('Buffer', props, PROP_CHECKS_INITIALIZE);\n\n // Initialize member fields\n this.webglUsage = props.webglUsage || GL.STATIC_DRAW;\n this.debugData = null;\n\n // Deprecated: Merge main props and accessor\n this.setAccessor(Object.assign({}, props, props.accessor));\n\n // Set data: (re)initializes the buffer\n if (props.data) {\n this._setData(props.data, props.offset, props.byteLength);\n } else {\n this._setByteLength(props.byteLength || 0);\n }\n\n return this;\n }\n\n setProps(props: ClassicBufferProps): this {\n props = checkProps('Buffer', props, PROP_CHECKS_SET_PROPS);\n\n if ('accessor' in props) {\n this.setAccessor(props.accessor);\n }\n\n return this;\n }\n\n // Optionally stores an accessor with the buffer, makes it easier to use it as an attribute later\n // {type, size = 1, offset = 0, stride = 0, normalized = false, integer = false, divisor = 0}\n setAccessor(accessor: AccessorObject | Accessor): this {\n // NOTE: From luma.gl v7.0, Accessors have an optional `buffer `field\n // (mainly to support \"interleaving\")\n // To avoid confusion, ensure `buffer.accessor` does not have a `buffer.accessor.buffer` field:\n accessor = Object.assign({}, accessor);\n // @ts-expect-error\n delete accessor.buffer;\n\n // This new statement ensures that an \"accessor object\" is re-packaged as an Accessor instance\n this.accessor = new Accessor(accessor);\n return this;\n }\n\n // Allocate a bigger GPU buffer (if the current buffer is not big enough).\n // If a reallocation is triggered it clears the buffer\n // Returns:\n // `true`: buffer was reallocated, data was cleared\n // `false`: buffer was big enough, data is intact\n reallocate(byteLength: number): boolean {\n if (byteLength > this.byteLength) {\n this._setByteLength(byteLength);\n return true;\n }\n this.bytesUsed = byteLength;\n return false;\n }\n\n // Update with new data. Reinitializes the buffer\n setData(props: ClassicBufferProps) {\n return this.initialize(props);\n }\n\n // Updates a subset of a buffer object's data store.\n // Data (Typed Array or ArrayBuffer), length is inferred unless provided\n // Offset into buffer\n // WebGL2 only: Offset into srcData\n // WebGL2 only: Number of bytes to be copied\n subData(options: TypedArray | {data: TypedArray, offset?: number; srcOffset?: number; byteLength?: number, length?: number}) {\n // Signature: buffer.subData(new Float32Array([...]))\n if (ArrayBuffer.isView(options)) {\n options = {data: options};\n }\n\n const {data, offset = 0, srcOffset = 0} = options;\n const byteLength = options.byteLength || options.length;\n\n assert(data);\n\n // Create the buffer - binding it here for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n // @ts-expect-error\n const target = this.gl.webgl2 ? GL.COPY_WRITE_BUFFER : this.target;\n this.gl.bindBuffer(target, this.handle);\n // WebGL2: subData supports additional srcOffset and length parameters\n if (srcOffset !== 0 || byteLength !== undefined) {\n assertWebGL2Context(this.gl);\n // @ts-expect-error\n this.gl.bufferSubData(this.target, offset, data, srcOffset, byteLength);\n } else {\n this.gl.bufferSubData(target, offset, data);\n }\n this.gl.bindBuffer(target, null);\n\n // TODO - update local `data` if offsets are right\n this.debugData = null;\n\n this._inferType(data);\n\n return this;\n }\n\n /**\n * Copies part of the data of another buffer into this buffer\n * @note WEBGL2 ONLY\n */\n copyData(options: {\n sourceBuffer: any;\n readOffset?: number;\n writeOffset?: number;\n size: any;\n }): this {\n const {sourceBuffer, readOffset = 0, writeOffset = 0, size} = options;\n const {gl, gl2} = this;\n assertWebGL2Context(gl);\n\n // Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type\n gl.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);\n gl.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);\n gl2?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);\n gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n gl.bindBuffer(GL.COPY_WRITE_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n this.debugData = null;\n\n return this;\n }\n\n /**\n * Reads data from buffer into an ArrayBufferView or SharedArrayBuffer.\n * @note WEBGL2 ONLY\n */\n override getData(options?: {\n dstData?: any;\n srcByteOffset?: number;\n dstOffset?: number;\n length?: number;\n }): any {\n let {dstData = null, length = 0} = options || {};\n const {srcByteOffset = 0, dstOffset = 0} = options || {};\n assertWebGL2Context(this.gl);\n\n const ArrayType = getTypedArrayFromGLType(this.accessor.type || GL.FLOAT, {clamped: false});\n const sourceAvailableElementCount = this._getAvailableElementCount(srcByteOffset);\n\n const dstElementOffset = dstOffset;\n\n let dstAvailableElementCount;\n let dstElementCount;\n if (dstData) {\n dstElementCount = dstData.length;\n dstAvailableElementCount = dstElementCount - dstElementOffset;\n } else {\n // Allocate ArrayBufferView with enough size to copy all eligible data.\n dstAvailableElementCount = Math.min(\n sourceAvailableElementCount,\n length || sourceAvailableElementCount\n );\n dstElementCount = dstElementOffset + dstAvailableElementCount;\n }\n\n const copyElementCount = Math.min(sourceAvailableElementCount, dstAvailableElementCount);\n length = length || copyElementCount;\n assert(length <= copyElementCount);\n dstData = dstData || new ArrayType(dstElementCount);\n\n // Use GL.COPY_READ_BUFFER to avoid disturbing other targets and locking type\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);\n this.gl2?.getBufferSubData(GL.COPY_READ_BUFFER, srcByteOffset, dstData, dstOffset, length);\n this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);\n\n // TODO - update local `data` if offsets are 0\n return dstData;\n }\n\n /**\n * Binds a buffer to a given binding point (target).\n * GL.TRANSFORM_FEEDBACK_BUFFER and GL.UNIFORM_BUFFER take an index, and optionally a range.\n * - GL.TRANSFORM_FEEDBACK_BUFFER and GL.UNIFORM_BUFFER need an index to affect state\n * - GL.UNIFORM_BUFFER: `offset` must be aligned to GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT.\n * - GL.UNIFORM_BUFFER: `size` must be a minimum of GL.UNIFORM_BLOCK_SIZE_DATA.\n */\n bind(options?: {target?: number; index?: any; offset?: number; size: any}): this {\n const {\n target = this.target, // target for the bind operation\n index = this.accessor && this.accessor.index, // index = index of target (indexed bind point)\n offset = 0,\n size\n } = options || {};\n // NOTE: While GL.TRANSFORM_FEEDBACK_BUFFER and GL.UNIFORM_BUFFER could\n // be used as direct binding points, they will not affect transform feedback or\n // uniform buffer state. Instead indexed bindings need to be made.\n if (target === GL.UNIFORM_BUFFER || target === GL.TRANSFORM_FEEDBACK_BUFFER) {\n if (size !== undefined) {\n this.gl2?.bindBufferRange(target, index, this.handle, offset, size);\n } else {\n assert(offset === 0); // Make sure offset wasn't supplied\n this.gl2?.bindBufferBase(target, index, this.handle);\n }\n } else {\n this.gl.bindBuffer(target, this.handle);\n }\n\n return this;\n }\n\n unbind(options?: {target?: any; index?: any}): this {\n const {target = this.target, index = this.accessor && this.accessor.index} = options || {};\n const isIndexedBuffer = target === GL.UNIFORM_BUFFER || target === GL.TRANSFORM_FEEDBACK_BUFFER;\n if (isIndexedBuffer) {\n this.gl2?.bindBufferBase(target, index, null);\n } else {\n this.gl.bindBuffer(target, null);\n }\n return this;\n }\n\n // PROTECTED METHODS (INTENDED FOR USE BY OTHER FRAMEWORK CODE ONLY)\n\n // Returns a short initial data array\n getDebugData(): {\n data: any;\n changed: boolean;\n } {\n if (!this.debugData) {\n this.debugData = this.getData({length: Math.min(DEBUG_DATA_LENGTH, this.byteLength)});\n return {data: this.debugData, changed: true};\n }\n return {data: this.debugData, changed: false};\n }\n\n invalidateDebugData() {\n this.debugData = null;\n }\n\n // PRIVATE METHODS\n\n // Allocate a new buffer and initialize to contents of typed array\n _setData(data, offset: number = 0, byteLength: number = data.byteLength + offset): this {\n assert(ArrayBuffer.isView(data));\n\n this.trackDeallocatedMemory();\n\n const target = this._getTarget();\n this.gl.bindBuffer(target, this.handle);\n this.gl.bufferData(target, byteLength, this.webglUsage);\n this.gl.bufferSubData(target, offset, data);\n this.gl.bindBuffer(target, null);\n\n this.debugData = data.slice(0, DEBUG_DATA_LENGTH);\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n this.trackAllocatedMemory(byteLength);\n\n // infer GL type from supplied typed array\n const type = getGLTypeFromTypedArray(data);\n assert(type);\n this.setAccessor(new Accessor(this.accessor, {type}));\n return this;\n }\n\n // Allocate a GPU buffer of specified size.\n _setByteLength(byteLength: number, webglUsage = this.webglUsage): this {\n assert(byteLength >= 0);\n\n this.trackDeallocatedMemory();\n\n // Workaround needed for Safari (#291):\n // gl.bufferData with size equal to 0 crashes. Instead create zero sized array.\n let data = byteLength;\n if (byteLength === 0) {\n // @ts-expect-error\n data = new Float32Array(0);\n }\n\n const target = this._getTarget();\n this.gl.bindBuffer(target, this.handle);\n this.gl.bufferData(target, data, webglUsage);\n this.gl.bindBuffer(target, null);\n\n this.webglUsage = webglUsage;\n this.debugData = null;\n this.bytesUsed = byteLength;\n this.byteLength = byteLength;\n\n this.trackAllocatedMemory(byteLength);\n\n return this;\n }\n\n // Binding a buffer for the first time locks the type\n // In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type\n _getTarget() {\n // @ts-expect-error\n return this.gl.webgl2 ? GL.COPY_WRITE_BUFFER : this.target;\n }\n\n _getAvailableElementCount(srcByteOffset: number) {\n const ArrayType = getTypedArrayFromGLType(this.accessor.type || GL.FLOAT, {clamped: false});\n const sourceElementOffset = srcByteOffset / ArrayType.BYTES_PER_ELEMENT;\n return this.getElementCount() - sourceElementOffset;\n }\n\n // Automatically infers type from typed array passed to setData\n // Note: No longer that useful, since type is now autodeduced from the compiled shaders\n _inferType(data) {\n if (!this.accessor.type) {\n this.setAccessor(new Accessor(this.accessor, {type: getGLTypeFromTypedArray(data)}));\n }\n }\n\n // RESOURCE METHODS\n\n getParameter(pname: GL): any {\n this.gl.bindBuffer(this.target, this.handle);\n const value = this.gl.getBufferParameter(this.target, pname);\n this.gl.bindBuffer(this.target, null);\n return value;\n }\n\n // DEPRECATIONS - v7.0\n /** @deprecated Use Buffer.accessor.type */\n get type() {\n return this.accessor.type;\n }\n}\n"],"file":"buffer.js"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { log, loadScript } from '@luma.gl/api
|
|
1
|
+
import { log, loadScript } from '@luma.gl/api';
|
|
2
2
|
import GL from '@luma.gl/constants';
|
|
3
3
|
const WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';
|
|
4
|
-
const DEFAULT_DEBUG_CONTEXT_PROPS = {
|
|
5
|
-
debug: true,
|
|
6
|
-
throwOnError: false,
|
|
7
|
-
break: [],
|
|
8
|
-
webgl2: false
|
|
9
|
-
};
|
|
10
4
|
|
|
11
5
|
function getContextData(gl) {
|
|
12
6
|
gl.luma = gl.luma || {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/debug/webgl-developer-tools.ts"],"names":["log","loadScript","GL","WEBGL_DEBUG_CDN_URL","DEFAULT_DEBUG_CONTEXT_PROPS","debug","throwOnError","break","webgl2","getContextData","gl","luma","loadWebGLDeveloperTools","globalThis","WebGLDebugUtils","global","module","makeDebugContext","props","getDebugContext","getRealContext","data","realContext","warn","debugContext","init","glDebug","onGLError","bind","onValidateGLFunc","key","WebGLDebugContext","Object","setPrototypeOf","getPrototypeOf","create","getFunctionString","functionName","functionArgs","Array","from","map","arg","undefined","args","glFunctionArgsToString","slice","length","err","errorMessage","glEnumToString","glName","message","error","Error","functionString","level","isBreakpoint","every","breakOn","indexOf"],"mappings":"AACA,SAAQA,GAAR,EAAaC,UAAb,QAA8B,eAA9B;AACA,OAAOC,EAAP,MAAe,oBAAf;AAEA,MAAMC,mBAAmB,GAAG,8CAA5B;AASA,MAAMC,2BAAwD,GAAG;AAC/DC,EAAAA,KAAK,EAAE,IADwD;AAE/DC,EAAAA,YAAY,EAAE,KAFiD;AAG/DC,EAAAA,KAAK,EAAE,EAHwD;AAI/DC,EAAAA,MAAM,EAAE;AAJuD,CAAjE;;AAQA,SAASC,cAAT,CAAwBC,EAAxB,EAAiC;AAC/BA,EAAAA,EAAE,CAACC,IAAH,GAAUD,EAAE,CAACC,IAAH,IAAW,EAArB;AACA,SAAOD,EAAE,CAACC,IAAV;AACD;;AAYD,OAAO,eAAeC,uBAAf,GAAwD;AAC7D,MAAI,CAACC,UAAU,CAACC,eAAhB,EAAiC;AAE/BD,IAAAA,UAAU,CAACE,MAAX,GAAoBF,UAAU,CAACE,MAAX,IAAqBF,UAAzC;AAEAA,IAAAA,UAAU,CAACE,MAAX,CAAkBC,MAAlB,GAA2B,EAA3B;AACA,UAAMf,UAAU,CAACE,mBAAD,CAAhB;AACD;AACF;AAID,OAAO,SAASc,gBAAT,CAA0BP,EAA1B,EAAqDQ,KAAwB,GAAG,EAAhF,EAAkH;AAEvH,MAAI,CAACR,EAAL,EAAS;AACP,WAAO,IAAP;AACD;;AAED,SAAOQ,KAAK,CAACb,KAAN,GAAcc,eAAe,CAACT,EAAD,EAAKQ,KAAL,CAA7B,GAA2CE,cAAc,CAACV,EAAD,CAAhE;AACD;;AAGD,SAASU,cAAT,CAAwBV,EAAxB,EAA0E;AACxE,QAAMW,IAAI,GAAGZ,cAAc,CAACC,EAAD,CAA3B;AAEA,SAAOW,IAA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D,OAAV;AACA;;AACA,MAAIlC,KAAK,CAACZ,YAAV,EAAwB;AACtB,UAAM,IAAIgD,KAAJ,CAAUF,OAAV,CAAN;AACD;AACF;;AAGD,SAASvB,gBAAT,CAA0BX,KAA1B,EAAoDmB,YAApD,EAA0EC,YAA1E,EAAqG;AACnG,MAAIiB,cAAsB,GAAG,EAA7B;;AACA,MAAIvD,GAAG,CAACwD,KAAJ,IAAa,CAAjB,EAAoB;AAClBD,IAAAA,cAAc,GAAGnB,iBAAiB,CAACC,YAAD,EAAeC,YAAf,CAAlC;AACAtC,IAAAA,GAAG,CAACA,GAAJ,CAAQ,CAAR,EAAWuD,cAAX;AACD;;AAED,MAAIrC,KAAK,CAACX,KAAV,EAAiB;AACfgD,IAAAA,cAAc,GAAGA,cAAc,IAAInB,iBAAiB,CAACC,YAAD,EAAeC,YAAf,CAApD;AACA,UAAMmB,YAAY,GAChBvC,KAAK,CAACX,KAAN,IAAeW,KAAK,CAACX,KAAN,CAAYmD,KAAZ,CAAmBC,OAAD,IAAqBJ,cAAc,CAACK,OAAf,CAAuBD,OAAvB,MAAoC,CAAC,CAA5E,CADjB;;AAEA,QAAIF,YAAJ,EAAkB;AAChB;AACD;AACF;;AAED,OAAK,MAAMf,GAAX,IAAkBJ,YAAlB,EAAgC;AAC9B,QAAII,GAAG,KAAKC,SAAZ,EAAuB;AACrBY,MAAAA,cAAc,GAAGA,cAAc,IAAInB,iBAAiB,CAACC,YAAD,EAAeC,YAAf,CAApD;;AACA,UAAIpB,KAAK,CAACZ,YAAV,EAAwB;AACtB,cAAM,IAAIgD,KAAJ,+BAAiCC,cAAjC,EAAN;AACD,OAFD,MAEO;AACLvD,QAAAA,GAAG,CAACqD,KAAJ,+BAAiCE,cAAjC;AACA;AACD;AACF;AACF;AACF","sourcesContent":["// luma.gl, MIT license\nimport {log, loadScript} from '@luma.gl/api/';\nimport GL from '@luma.gl/constants';\n\nconst WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';\n\ntype DebugContextProps = {\n debug?: boolean;\n throwOnError?: boolean;\n break?: string[];\n webgl2?: boolean;\n};\n\nconst DEFAULT_DEBUG_CONTEXT_PROPS: Required<DebugContextProps> = {\n debug: true,\n throwOnError: false,\n break: [],\n webgl2: false,\n}\n\n// Helper to get shared context data\nfunction getContextData(gl: any) {\n gl.luma = gl.luma || {};\n return gl.luma;\n}\n\ndeclare global {\n var WebGLDebugUtils: any;\n}\n\n/**\n * Loads Khronos WebGLDeveloperTools from CDN if not already installed \n * const WebGLDebugUtils = require('webgl-debug');\n * @see https://github.com/KhronosGroup/WebGLDeveloperTools\n * @see https://github.com/vorg/webgl-debug\n */\nexport async function loadWebGLDeveloperTools(): Promise<void> {\n if (!globalThis.WebGLDebugUtils) {\n // @ts-expect-error Developer tools expects global to be set\n globalThis.global = globalThis.global || globalThis;\n // @ts-expect-error Developer tools expects global to be set\n globalThis.global.module = {};\n await loadScript(WEBGL_DEBUG_CDN_URL);\n }\n}\n\n// Returns (a potentially new) context with debug instrumentation turned off or on.\n// Note that this actually returns a new context\nexport function makeDebugContext(gl: WebGLRenderingContext, props: DebugContextProps = {}): WebGLRenderingContext | null {\n // Return null to ensure we don't try to create a context in this case (TODO what case is that?)\n if (!gl) {\n return null;\n }\n\n return props.debug ? getDebugContext(gl, props) : getRealContext(gl);\n}\n\n// Returns the real context from either of the real/debug contexts\nfunction getRealContext(gl: WebGLRenderingContext): WebGLRenderingContext {\n const data = getContextData(gl);\n // If the context has a realContext member, it is a debug context so return the realContext\n return data.realContext ? data.realContext : gl;\n}\n\n// Returns the debug context from either of the real/debug contexts\nfunction getDebugContext(gl: WebGLRenderingContext, props: DebugContextProps): WebGLRenderingContext {\n if (!globalThis.WebGLDebugUtils) {\n log.warn('webgl-debug not loaded')();\n return gl;\n }\n\n const data = getContextData(gl);\n\n // If this already has a debug context, return it.\n if (data.debugContext) {\n return data.debugContext;\n }\n\n // Create a new debug context\n globalThis.WebGLDebugUtils.init({...GL, ...gl});\n const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(\n gl,\n onGLError.bind(null, props),\n onValidateGLFunc.bind(null, props)\n );\n\n // Make sure we have all WebGL2 and extension constants (todo dynamic import to circumvent minification?)\n for (const key in GL) {\n if (!(key in glDebug) && typeof GL[key] === 'number') {\n glDebug[key] = GL[key];\n }\n }\n \n // Ensure we have a clean prototype on the instrumented object\n // Note: setPrototypeOf does come with perf warnings, but we already take a bigger perf reduction\n // by synchronizing the WebGL errors after each WebGL call.\n class WebGLDebugContext {}\n Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));\n Object.setPrototypeOf(WebGLDebugContext, glDebug);\n const debugContext = Object.create(WebGLDebugContext);\n // Store the debug context\n data.realContext = gl;\n data.debugContext = debugContext;\n debugContext.debug = true;\n\n // Return it\n return debugContext;\n}\n\n// DEBUG TRACING\n\nfunction getFunctionString(functionName: string, functionArgs): string {\n // Cover bug in webgl-debug-tools\n functionArgs = Array.from(functionArgs).map(arg => arg === undefined ? 'undefined' : arg);\n let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);\n args = `${args.slice(0, 100)}${args.length > 100 ? '...' : ''}`;\n return `gl.${functionName}(${args})`;\n}\n\nfunction onGLError(props: DebugContextProps, err, functionName: string, args: any[]): void {\n // Cover bug in webgl-debug-tools\n args = Array.from(args).map(arg => arg === undefined ? 'undefined' : arg);\n const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);\n const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);\n const glName = props.webgl2 ? 'gl2' : 'gl1';\n const message = `${errorMessage} in ${glName}.${functionName}(${functionArgs})`;\n log.error(message)();\n debugger; // eslint-disable-line\n if (props.throwOnError) {\n throw new Error(message);\n }\n}\n\n// Don't generate function string until it is needed\nfunction onValidateGLFunc(props: DebugContextProps, functionName: string, functionArgs: any[]): void {\n let functionString: string = '';\n if (log.level >= 1) {\n functionString = getFunctionString(functionName, functionArgs);\n log.log(1, functionString)();\n }\n\n if (props.break) {\n functionString = functionString || getFunctionString(functionName, functionArgs);\n const isBreakpoint =\n props.break && props.break.every((breakOn: string) => functionString.indexOf(breakOn) !== -1);\n if (isBreakpoint) {\n debugger; // eslint-disable-line\n }\n }\n\n for (const arg of functionArgs) {\n if (arg === undefined) {\n functionString = functionString || getFunctionString(functionName, functionArgs);\n if (props.throwOnError) {\n throw new Error(`Undefined argument: ${functionString}`);\n } else {\n log.error(`Undefined argument: ${functionString}`)();\n debugger; // eslint-disable-line\n }\n }\n }\n}\n"],"file":"webgl-developer-tools.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/context/debug/webgl-developer-tools.ts"],"names":["log","loadScript","GL","WEBGL_DEBUG_CDN_URL","getContextData","gl","luma","loadWebGLDeveloperTools","globalThis","WebGLDebugUtils","global","module","makeDebugContext","props","debug","getDebugContext","getRealContext","data","realContext","warn","debugContext","init","glDebug","onGLError","bind","onValidateGLFunc","key","WebGLDebugContext","Object","setPrototypeOf","getPrototypeOf","create","getFunctionString","functionName","functionArgs","Array","from","map","arg","undefined","args","glFunctionArgsToString","slice","length","err","errorMessage","glEnumToString","glName","webgl2","message","error","throwOnError","Error","functionString","level","break","isBreakpoint","every","breakOn","indexOf"],"mappings":"AACA,SAAQA,GAAR,EAAaC,UAAb,QAA8B,cAA9B;AACA,OAAOC,EAAP,MAAe,oBAAf;AAEA,MAAMC,mBAAmB,GAAG,8CAA5B;;AAiBA,SAASC,cAAT,CAAwBC,EAAxB,EAAiC;AAC/BA,EAAAA,EAAE,CAACC,IAAH,GAAUD,EAAE,CAACC,IAAH,IAAW,EAArB;AACA,SAAOD,EAAE,CAACC,IAAV;AACD;;AAYD,OAAO,eAAeC,uBAAf,GAAwD;AAC7D,MAAI,CAACC,UAAU,CAACC,eAAhB,EAAiC;AAE/BD,IAAAA,UAAU,CAACE,MAAX,GAAoBF,UAAU,CAACE,MAAX,IAAqBF,UAAzC;AAEAA,IAAAA,UAAU,CAACE,MAAX,CAAkBC,M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II,GAAG,KAAKC,SAAZ,EAAuB;AACrBc,MAAAA,cAAc,GAAGA,cAAc,IAAIrB,iBAAiB,CAACC,YAAD,EAAeC,YAAf,CAApD;;AACA,UAAIrB,KAAK,CAACsC,YAAV,EAAwB;AACtB,cAAM,IAAIC,KAAJ,+BAAiCC,cAAjC,EAAN;AACD,OAFD,MAEO;AACLrD,QAAAA,GAAG,CAACkD,KAAJ,+BAAiCG,cAAjC;AACA;AACD;AACF;AACF;AACF","sourcesContent":["// luma.gl, MIT license\nimport {log, loadScript} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\n\nconst WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';\n\ntype DebugContextProps = {\n debug?: boolean;\n throwOnError?: boolean;\n break?: string[];\n webgl2?: boolean;\n};\n\n// const DEFAULT_DEBUG_CONTEXT_PROPS: Required<DebugContextProps> = {\n// debug: true,\n// throwOnError: false,\n// break: [],\n// webgl2: false,\n// }\n\n// Helper to get shared context data\nfunction getContextData(gl: any) {\n gl.luma = gl.luma || {};\n return gl.luma;\n}\n\ndeclare global {\n var WebGLDebugUtils: any;\n}\n\n/**\n * Loads Khronos WebGLDeveloperTools from CDN if not already installed \n * const WebGLDebugUtils = require('webgl-debug');\n * @see https://github.com/KhronosGroup/WebGLDeveloperTools\n * @see https://github.com/vorg/webgl-debug\n */\nexport async function loadWebGLDeveloperTools(): Promise<void> {\n if (!globalThis.WebGLDebugUtils) {\n // @ts-expect-error Developer tools expects global to be set\n globalThis.global = globalThis.global || globalThis;\n // @ts-expect-error Developer tools expects global to be set\n globalThis.global.module = {};\n await loadScript(WEBGL_DEBUG_CDN_URL);\n }\n}\n\n// Returns (a potentially new) context with debug instrumentation turned off or on.\n// Note that this actually returns a new context\nexport function makeDebugContext(gl: WebGLRenderingContext, props: DebugContextProps = {}): WebGLRenderingContext | null {\n // Return null to ensure we don't try to create a context in this case (TODO what case is that?)\n if (!gl) {\n return null;\n }\n\n return props.debug ? getDebugContext(gl, props) : getRealContext(gl);\n}\n\n// Returns the real context from either of the real/debug contexts\nfunction getRealContext(gl: WebGLRenderingContext): WebGLRenderingContext {\n const data = getContextData(gl);\n // If the context has a realContext member, it is a debug context so return the realContext\n return data.realContext ? data.realContext : gl;\n}\n\n// Returns the debug context from either of the real/debug contexts\nfunction getDebugContext(gl: WebGLRenderingContext, props: DebugContextProps): WebGLRenderingContext {\n if (!globalThis.WebGLDebugUtils) {\n log.warn('webgl-debug not loaded')();\n return gl;\n }\n\n const data = getContextData(gl);\n\n // If this already has a debug context, return it.\n if (data.debugContext) {\n return data.debugContext;\n }\n\n // Create a new debug context\n globalThis.WebGLDebugUtils.init({...GL, ...gl});\n const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(\n gl,\n onGLError.bind(null, props),\n onValidateGLFunc.bind(null, props)\n );\n\n // Make sure we have all WebGL2 and extension constants (todo dynamic import to circumvent minification?)\n for (const key in GL) {\n if (!(key in glDebug) && typeof GL[key] === 'number') {\n glDebug[key] = GL[key];\n }\n }\n \n // Ensure we have a clean prototype on the instrumented object\n // Note: setPrototypeOf does come with perf warnings, but we already take a bigger perf reduction\n // by synchronizing the WebGL errors after each WebGL call.\n class WebGLDebugContext {}\n Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));\n Object.setPrototypeOf(WebGLDebugContext, glDebug);\n const debugContext = Object.create(WebGLDebugContext);\n // Store the debug context\n data.realContext = gl;\n data.debugContext = debugContext;\n debugContext.debug = true;\n\n // Return it\n return debugContext;\n}\n\n// DEBUG TRACING\n\nfunction getFunctionString(functionName: string, functionArgs): string {\n // Cover bug in webgl-debug-tools\n functionArgs = Array.from(functionArgs).map(arg => arg === undefined ? 'undefined' : arg);\n let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);\n args = `${args.slice(0, 100)}${args.length > 100 ? '...' : ''}`;\n return `gl.${functionName}(${args})`;\n}\n\nfunction onGLError(props: DebugContextProps, err, functionName: string, args: any[]): void {\n // Cover bug in webgl-debug-tools\n args = Array.from(args).map(arg => arg === undefined ? 'undefined' : arg);\n const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);\n const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);\n const glName = props.webgl2 ? 'gl2' : 'gl1';\n const message = `${errorMessage} in ${glName}.${functionName}(${functionArgs})`;\n log.error(message)();\n debugger; // eslint-disable-line\n if (props.throwOnError) {\n throw new Error(message);\n }\n}\n\n// Don't generate function string until it is needed\nfunction onValidateGLFunc(props: DebugContextProps, functionName: string, functionArgs: any[]): void {\n let functionString: string = '';\n if (log.level >= 1) {\n functionString = getFunctionString(functionName, functionArgs);\n log.log(1, functionString)();\n }\n\n if (props.break) {\n functionString = functionString || getFunctionString(functionName, functionArgs);\n const isBreakpoint =\n props.break && props.break.every((breakOn: string) => functionString.indexOf(breakOn) !== -1);\n if (isBreakpoint) {\n debugger; // eslint-disable-line\n }\n }\n\n for (const arg of functionArgs) {\n if (arg === undefined) {\n functionString = functionString || getFunctionString(functionName, functionArgs);\n if (props.throwOnError) {\n throw new Error(`Undefined argument: ${functionString}`);\n } else {\n log.error(`Undefined argument: ${functionString}`)();\n debugger; // eslint-disable-line\n }\n }\n }\n}\n"],"file":"webgl-developer-tools.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified-parameter-api.d.ts","sourceRoot":"","sources":["../../../src/context/parameters/unified-parameter-api.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"unified-parameter-api.d.ts","sourceRoot":"","sources":["../../../src/context/parameters/unified-parameter-api.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAUpD,YAAY,EAAC,YAAY,EAAC,CAAC;AAE3B;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,GAAG,qBAAqB,EACtC,UAAU,EAAE,YAAY,GACvB,IAAI,CAiDN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,GAAG,qBAAqB,EACtC,UAAU,GAAE,MAAM,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,EAAE,GAAG,YAAoC,GAC7F,YAAY,CAqBd;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,GAAG,IAAI,CAE5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/parameters/unified-parameter-api.ts"],"names":["GL_PARAMETER_DEFAULTS","GL_PARAMETER_SETTERS","GL_COMPOSITE_PARAMETER_SETTERS","GL_PARAMETER_GETTERS","WebGLDevice","setParameters","device","parameters","webglDevice","attach","gl","isObjectEmpty","compositeSetters","key","glConstant","Number","setter","cache","state","compositeSetter","getParameters","getter","getParameter","parameterKeys","Array","isArray","Object","keys","resetParameters","object"],"mappings":"AAKA,SACEA,qBADF,EAEEC,oBAFF,EAGEC,8BAHF,EAIEC,oBAJF,QAKO,0BALP;
|
|
1
|
+
{"version":3,"sources":["../../../src/context/parameters/unified-parameter-api.ts"],"names":["GL_PARAMETER_DEFAULTS","GL_PARAMETER_SETTERS","GL_COMPOSITE_PARAMETER_SETTERS","GL_PARAMETER_GETTERS","WebGLDevice","setParameters","device","parameters","webglDevice","attach","gl","isObjectEmpty","compositeSetters","key","glConstant","Number","setter","cache","state","compositeSetter","getParameters","getter","getParameter","parameterKeys","Array","isArray","Object","keys","resetParameters","object"],"mappings":"AAKA,SACEA,qBADF,EAEEC,oBAFF,EAGEC,8BAHF,EAIEC,oBAJF,QAKO,0BALP;AAOA,OAAOC,WAAP,MAAwB,4BAAxB;AAUA,OAAO,SAASC,aAA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lB,oBAAoB,CAACU,GAAD,CAAnC;AACA,WAAOQ,MAAM,GAAGA,MAAM,CAACX,EAAD,EAAKG,GAAL,CAAT,GAAqBH,EAAE,CAACY,YAAH,CAAgBT,GAAhB,CAAlC;AACD;;AAED,QAAMU,aAAa,GAAGC,KAAK,CAACC,OAAN,CAAclB,UAAd,IAA4BA,UAA5B,GAAyCmB,MAAM,CAACC,IAAP,CAAYpB,UAAZ,CAA/D;AAEA,QAAMW,KAAK,GAAG,EAAd;;AACA,OAAK,MAAML,GAAX,IAAkBU,aAAlB,EAAiC;AAC/B,UAAMF,MAAM,GAAGlB,oBAAoB,CAACU,GAAD,CAAnC;AACAK,IAAAA,KAAK,CAACL,GAAD,CAAL,GAAaQ,MAAM,GAAGA,MAAM,CAACX,EAAD,EAAKK,MAAM,CAACF,GAAD,CAAX,CAAT,GAA6BH,EAAE,CAACY,YAAH,CAAgBP,MAAM,CAACF,GAAD,CAAtB,CAAhD;AACD;;AACD,SAAOK,KAAP;AACD;AAQD,OAAO,SAASU,eAAT,CAAyBtB,MAAzB,EAAuE;AAC5ED,EAAAA,aAAa,CAACC,MAAD,EAASN,qBAAT,CAAb;AACD;;AAKD,SAASW,aAAT,CAAuBkB,MAAvB,EAA+B;AAE7B,OAAK,MAAMhB,GAAX,IAAkBgB,MAAlB,EAA0B;AACxB,WAAO,KAAP;AACD;;AACD,SAAO,IAAP;AACD","sourcesContent":["// Provides a unified API for getting and setting any WebGL parameter\n// Also knows default values of all parameters, enabling fast cache initialization\n// Provides base functionality for the state caching.\nimport {Device} from '@luma.gl/api';\nimport type {GLParameters} from '../../types/webgl';\nimport {\n GL_PARAMETER_DEFAULTS,\n GL_PARAMETER_SETTERS,\n GL_COMPOSITE_PARAMETER_SETTERS,\n GL_PARAMETER_GETTERS\n} from './webgl-parameter-tables';\n\nimport WebGLDevice from '../../adapter/webgl-device';\n\nexport type {GLParameters};\n\n/**\n * Sets any GL parameter regardless of function (gl.blendMode, ...)\n *\n * @note requires a `cache` object to be set on the context (gl.state.cache)\n * This object is used to fill in any missing values for composite setter functions\n */\nexport function setParameters(\n device: Device | WebGLRenderingContext,\n parameters: GLParameters\n): void {\n const webglDevice = WebGLDevice.attach(device);\n const gl = webglDevice.gl;\n\n if (isObjectEmpty(parameters)) {\n return;\n }\n\n const compositeSetters = {};\n\n // HANDLE PRIMITIVE SETTERS (and make note of any composite setters)\n\n for (const key in parameters) {\n const glConstant = Number(key);\n const setter = GL_PARAMETER_SETTERS[key];\n if (setter) {\n // Composite setters should only be called once, so save them\n if (typeof setter === 'string') {\n compositeSetters[setter] = true;\n } else {\n // if (gl[glConstant] !== undefined) {\n // TODO - added above check since this is being called on WebGL2 parameters in WebGL1...\n // TODO - deep equal on values? only call setter if value has changed?\n // NOTE - the setter will automatically update this.state\n setter(gl, parameters[key], glConstant);\n }\n }\n }\n\n // HANDLE COMPOSITE SETTERS\n\n // NOTE: any non-provided values needed by composite setters are filled in from state cache\n // The cache parameter is automatically retrieved from the context\n // This depends on `trackContextState`, which is technically a \"circular\" dependency.\n // But it is too inconvenient to always require a cache parameter here.\n // This is the ONLY external dependency in this module/\n // @ts-expect-error\n const cache = gl.state && gl.state.cache;\n if (cache) {\n for (const key in compositeSetters) {\n // TODO - avoid calling composite setters if values have not changed.\n const compositeSetter = GL_COMPOSITE_PARAMETER_SETTERS[key];\n // Note - if `trackContextState` has been called,\n // the setter will automatically update this.state.cache\n compositeSetter(gl, parameters, cache);\n }\n }\n\n // Add a log for the else case?\n}\n\n/**\n * Reads the entire WebGL state from a context\n\n // default to querying all parameters\n\n * @returns - a newly created map, with values keyed by GL parameters\n *\n * @note Copies the state from a context (gl.getParameter should not be overriden)\n * Reads the entire WebGL state from a context\n *\n * @note This can generates a huge amount of synchronous driver roundtrips and should be\n * considered a very slow operation, to be used only if/when a context already manipulated\n * by external code needs to be synchronized for the first time\n */\nexport function getParameters(\n device: Device | WebGLRenderingContext,\n parameters: keyof GLParameters | (keyof GLParameters)[] | GLParameters = GL_PARAMETER_DEFAULTS\n): GLParameters {\n const webglDevice = WebGLDevice.attach(device);\n const gl = webglDevice.gl;\n\n // support both arrays of parameters and objects (keys represent parameters)\n\n if (typeof parameters === 'number') {\n // single GL enum\n const key = parameters;\n const getter = GL_PARAMETER_GETTERS[key];\n return getter ? getter(gl, key) : gl.getParameter(key);\n }\n\n const parameterKeys = Array.isArray(parameters) ? parameters : Object.keys(parameters);\n\n const state = {};\n for (const key of parameterKeys) {\n const getter = GL_PARAMETER_GETTERS[key];\n state[key] = getter ? getter(gl, Number(key)) : gl.getParameter(Number(key));\n }\n return state;\n}\n\n/**\n * Reset all parameters to a (almost) pure context state\n * @note viewport and scissor will be set to the values in GL_PARAMETER_DEFAULTS,\n * NOT the canvas size dimensions, so they will have to be properly set after\n * calling this function.\n */\nexport function resetParameters(device: Device | WebGLRenderingContext): void {\n setParameters(device, GL_PARAMETER_DEFAULTS);\n}\n\n// Helpers\n\n// Returns true if given object is empty, false otherwise.\nfunction isObjectEmpty(object) {\n // @ts-ignore dummy key variable\n for (const key in object) {\n return false;\n }\n return true;\n}\n"],"file":"unified-parameter-api.js"}
|