@luma.gl/core 9.0.0 → 9.0.3
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/resources/render-pipeline.d.ts +3 -1
- package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
- package/dist/dist.dev.js +134 -189
- package/dist/dist.min.js +4 -4
- package/dist/index.cjs +57 -18
- package/dist/index.cjs.map +2 -2
- package/dist/init.js +1 -1
- package/dist/lib/luma.d.ts +13 -2
- package/dist/lib/luma.d.ts.map +1 -1
- package/dist/lib/luma.js +66 -17
- package/dist.min.js +18 -0
- package/package.json +2 -2
- package/src/adapter/resources/render-pipeline.ts +4 -1
- package/src/lib/luma.ts +92 -19
package/dist/init.js
CHANGED
|
@@ -11,7 +11,7 @@ import { lumaStats } from "./utils/stats-manager.js";
|
|
|
11
11
|
function initializeLuma() {
|
|
12
12
|
// Version detection using babel plugin
|
|
13
13
|
// @ts-expect-error
|
|
14
|
-
const VERSION = typeof "9.0.
|
|
14
|
+
const VERSION = typeof "9.0.2" !== 'undefined' ? "9.0.2" : 'running from source';
|
|
15
15
|
const STARTUP_MESSAGE = 'set luma.log.level=1 (or higher) to trace rendering';
|
|
16
16
|
// Assign luma.log.level in console to control logging: \
|
|
17
17
|
// 0: none, 1: minimal, 2: verbose, 3: attribute/uniforms, 4: gl logs
|
package/dist/lib/luma.d.ts
CHANGED
|
@@ -2,9 +2,17 @@ import type { Log } from '@probe.gl/log';
|
|
|
2
2
|
import type { DeviceProps } from "../adapter/device.js";
|
|
3
3
|
import { Device } from "../adapter/device.js";
|
|
4
4
|
import { StatsManager } from "../utils/stats-manager.js";
|
|
5
|
+
/** Properties for creating a new device */
|
|
5
6
|
export type CreateDeviceProps = DeviceProps & {
|
|
6
|
-
/**
|
|
7
|
-
type?: 'webgl' | 'webgpu' | 'best-available';
|
|
7
|
+
/** Selects the type of device. `best-available` uses webgpu if available, then webgl. */
|
|
8
|
+
type?: 'webgl' | 'webgpu' | 'unknown' | 'best-available';
|
|
9
|
+
devices?: any[];
|
|
10
|
+
};
|
|
11
|
+
/** Properties for attaching an existing WebGL context or WebGPU device to a new luma Device */
|
|
12
|
+
export type AttachDeviceProps = DeviceProps & {
|
|
13
|
+
/** Externally created WebGL context or WebGPU device */
|
|
14
|
+
handle: WebGL2RenderingContext;
|
|
15
|
+
devices?: any[];
|
|
8
16
|
};
|
|
9
17
|
/**
|
|
10
18
|
* Entry point to the luma.gl GPU abstraction
|
|
@@ -12,6 +20,7 @@ export type CreateDeviceProps = DeviceProps & {
|
|
|
12
20
|
* Run-time selection of the first available Device
|
|
13
21
|
*/
|
|
14
22
|
export declare class luma {
|
|
23
|
+
static defaultProps: Required<CreateDeviceProps>;
|
|
15
24
|
/** Global stats for all devices */
|
|
16
25
|
static stats: StatsManager;
|
|
17
26
|
/** Global log */
|
|
@@ -20,6 +29,8 @@ export declare class luma {
|
|
|
20
29
|
static getAvailableDevices(): string[];
|
|
21
30
|
static getSupportedDevices(): string[];
|
|
22
31
|
static setDefaultDeviceProps(props: CreateDeviceProps): void;
|
|
32
|
+
/** Attach to an existing GPU API handle (WebGL2RenderingContext or GPUDevice). */
|
|
33
|
+
static attachDevice(props: AttachDeviceProps): Promise<Device>;
|
|
23
34
|
/** Creates a device. Asynchronously. */
|
|
24
35
|
static createDevice(props?: CreateDeviceProps): Promise<Device>;
|
|
25
36
|
}
|
package/dist/lib/luma.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"luma.d.ts","sourceRoot":"","sources":["../../src/lib/luma.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,EAAC,WAAW,EAAC,6BAA0B;AACnD,OAAO,EAAC,MAAM,EAAC,6BAA0B;AACzC,OAAO,EAAC,YAAY,EAAC,kCAA+B;AAOpD,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG;IAC5C,
|
|
1
|
+
{"version":3,"file":"luma.d.ts","sourceRoot":"","sources":["../../src/lib/luma.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,EAAC,WAAW,EAAC,6BAA0B;AACnD,OAAO,EAAC,MAAM,EAAC,6BAA0B;AACzC,OAAO,EAAC,YAAY,EAAC,kCAA+B;AAOpD,2CAA2C;AAC3C,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG;IAC5C,yFAAyF;IACzF,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,gBAAgB,CAAC;IACzD,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;CACjB,CAAC;AAEF,+FAA+F;AAC/F,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG;IAC5C,wDAAwD;IACxD,MAAM,EAAE,sBAAsB,CAAC;IAC/B,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;CACjB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,IAAI;IACf,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAI9C;IAEF,mCAAmC;IACnC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAa;IAEvC,iBAAiB;IACjB,MAAM,CAAC,GAAG,EAAE,GAAG,CAAO;IAEtB,MAAM,CAAC,eAAe,CAAC,aAAa,EAAE,GAAG,EAAE,GAAyB,IAAI;IAOxE,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAKtC,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAUtC,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IAI5D,kFAAkF;WACrE,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAgCpE,wCAAwC;WAC3B,YAAY,CAAC,KAAK,GAAE,iBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;CA6C1E"}
|
package/dist/lib/luma.js
CHANGED
|
@@ -5,13 +5,18 @@ import { Device } from "../adapter/device.js";
|
|
|
5
5
|
import { lumaStats } from "../utils/stats-manager.js";
|
|
6
6
|
import { log } from "../utils/log.js";
|
|
7
7
|
import { assert } from "../utils/assert.js";
|
|
8
|
-
const
|
|
8
|
+
const deviceMap = new Map();
|
|
9
9
|
/**
|
|
10
10
|
* Entry point to the luma.gl GPU abstraction
|
|
11
11
|
* Register WebGPU and/or WebGL devices (controls application bundle size)
|
|
12
12
|
* Run-time selection of the first available Device
|
|
13
13
|
*/
|
|
14
14
|
export class luma {
|
|
15
|
+
static defaultProps = {
|
|
16
|
+
...Device.defaultProps,
|
|
17
|
+
type: 'best-available',
|
|
18
|
+
devices: undefined
|
|
19
|
+
};
|
|
15
20
|
/** Global stats for all devices */
|
|
16
21
|
static stats = lumaStats;
|
|
17
22
|
/** Global log */
|
|
@@ -19,15 +24,15 @@ export class luma {
|
|
|
19
24
|
static registerDevices(deviceClasses /* : typeof Device */) {
|
|
20
25
|
for (const deviceClass of deviceClasses) {
|
|
21
26
|
assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
|
|
22
|
-
|
|
27
|
+
deviceMap.set(deviceClass.type, deviceClass);
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
30
|
static getAvailableDevices() {
|
|
26
31
|
// @ts-expect-error
|
|
27
|
-
return Array.from(
|
|
32
|
+
return Array.from(deviceMap).map(Device => Device.type);
|
|
28
33
|
}
|
|
29
34
|
static getSupportedDevices() {
|
|
30
|
-
return (Array.from(
|
|
35
|
+
return (Array.from(deviceMap)
|
|
31
36
|
// @ts-expect-error
|
|
32
37
|
.filter(Device => Device.isSupported())
|
|
33
38
|
// @ts-expect-error
|
|
@@ -36,37 +41,81 @@ export class luma {
|
|
|
36
41
|
static setDefaultDeviceProps(props) {
|
|
37
42
|
Object.assign(Device.defaultProps, props);
|
|
38
43
|
}
|
|
44
|
+
/** Attach to an existing GPU API handle (WebGL2RenderingContext or GPUDevice). */
|
|
45
|
+
static async attachDevice(props) {
|
|
46
|
+
const devices = getDeviceMap(props.devices) || deviceMap;
|
|
47
|
+
// WebGL
|
|
48
|
+
if (props.handle instanceof WebGL2RenderingContext) {
|
|
49
|
+
const WebGLDevice = devices.get('webgl');
|
|
50
|
+
if (WebGLDevice) {
|
|
51
|
+
return (await WebGLDevice.attach(props.handle));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// TODO - WebGPU does not yet have a stable API
|
|
55
|
+
// if (props.handle instanceof GPUDevice) {
|
|
56
|
+
// const WebGPUDevice = devices.get('webgpu') as any;
|
|
57
|
+
// if (WebGPUDevice) {
|
|
58
|
+
// return (await WebGPUDevice.attach(props.handle)) as Device;
|
|
59
|
+
// }
|
|
60
|
+
// }
|
|
61
|
+
// null
|
|
62
|
+
if (props.handle === null) {
|
|
63
|
+
const UnknownDevice = devices.get('unknown');
|
|
64
|
+
if (UnknownDevice) {
|
|
65
|
+
return (await UnknownDevice.attach(null));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
throw new Error('Failed to attach device. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.');
|
|
69
|
+
}
|
|
39
70
|
/** Creates a device. Asynchronously. */
|
|
40
71
|
static async createDevice(props = {}) {
|
|
41
72
|
props = { ...Device.defaultProps, ...props };
|
|
42
73
|
if (props.gl) {
|
|
43
74
|
props.type = 'webgl';
|
|
44
75
|
}
|
|
45
|
-
|
|
76
|
+
const devices = getDeviceMap(props.devices) || deviceMap;
|
|
46
77
|
switch (props.type) {
|
|
47
78
|
case 'webgpu':
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
return await
|
|
79
|
+
let WebGPUDevice = devices.get('webgpu');
|
|
80
|
+
if (WebGPUDevice) {
|
|
81
|
+
return await WebGPUDevice.create(props);
|
|
51
82
|
}
|
|
52
83
|
break;
|
|
53
84
|
case 'webgl':
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
return await
|
|
85
|
+
let WebGLDevice = devices.get('webgl');
|
|
86
|
+
if (WebGLDevice) {
|
|
87
|
+
return await WebGLDevice.create(props);
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
case 'unknown':
|
|
91
|
+
const UnknownDevice = devices.get('unknown');
|
|
92
|
+
if (UnknownDevice) {
|
|
93
|
+
return await UnknownDevice.create(props);
|
|
57
94
|
}
|
|
58
95
|
break;
|
|
59
96
|
case 'best-available':
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
return await
|
|
97
|
+
WebGPUDevice = devices.get('webgpu');
|
|
98
|
+
if (WebGPUDevice?.isSupported?.()) {
|
|
99
|
+
return await WebGPUDevice.create(props);
|
|
63
100
|
}
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
return await
|
|
101
|
+
WebGLDevice = devices.get('webgl');
|
|
102
|
+
if (WebGLDevice?.isSupported?.()) {
|
|
103
|
+
return await WebGLDevice.create(props);
|
|
67
104
|
}
|
|
68
105
|
break;
|
|
69
106
|
}
|
|
70
107
|
throw new Error('No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.');
|
|
71
108
|
}
|
|
72
109
|
}
|
|
110
|
+
/** Convert a list of devices to a map */
|
|
111
|
+
function getDeviceMap(deviceClasses /* : typeof Device */) {
|
|
112
|
+
if (!deviceClasses || deviceClasses?.length === 0) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const map = new Map();
|
|
116
|
+
for (const deviceClass of deviceClasses) {
|
|
117
|
+
// assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
|
|
118
|
+
map.set(deviceClass.type, deviceClass);
|
|
119
|
+
}
|
|
120
|
+
return map;
|
|
121
|
+
}
|
package/dist.min.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
+
else if (typeof exports === 'object') exports['luma'] = factory();
|
|
6
|
+
else root['luma'] = factory();})(globalThis, function () {
|
|
7
|
+
"use strict";var __exports__=(()=>{var J=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames;var Ft=Object.prototype.hasOwnProperty;var It=(r,e,t)=>e in r?J(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var _t=(r,e)=>{for(var t in e)J(r,t,{get:e[t],enumerable:!0})},Mt=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Lt(e))!Ft.call(r,n)&&n!==t&&J(r,n,{get:()=>e[n],enumerable:!(o=Dt(e,n))||o.enumerable});return r};var Ut=r=>Mt(J({},"__esModule",{value:!0}),r);var u=(r,e,t)=>(It(r,typeof e!="symbol"?e+"":e,t),t);var Br={};_t(Br,{Buffer:()=>f,CanvasContext:()=>U,CommandBuffer:()=>j,CommandEncoder:()=>q,ComputePass:()=>W,ComputePipeline:()=>H,Device:()=>x,DeviceFeatures:()=>me,DeviceLimits:()=>ue,ExternalTexture:()=>k,Framebuffer:()=>O,QuerySet:()=>K,RenderPass:()=>G,RenderPipeline:()=>z,Resource:()=>m,Sampler:()=>$,Shader:()=>N,StatsManager:()=>_,Texture:()=>l,TextureView:()=>V,TransformFeedback:()=>X,UniformBlock:()=>F,UniformBufferLayout:()=>L,UniformStore:()=>ge,VERSION:()=>ae,VertexArray:()=>Y,assert:()=>E,cancelAnimationFrame:()=>Et,cast:()=>yt,checkProps:()=>Pt,decodeShaderAttributeType:()=>fe,decodeShaderUniformType:()=>de,decodeTextureFormat:()=>ot,decodeVertexFormat:()=>Q,deepEqual:()=>he,fillArray:()=>ft,formatCompilerLog:()=>ce,formatValue:()=>Oe,getAttributeInfosFromLayouts:()=>Me,getDataTypeFromTypedArray:()=>Ne,getScratchArray:()=>ct,getScratchArrayBuffer:()=>Z,getTypedArrayFromDataType:()=>bt,getVertexFormatFromAttribute:()=>ht,glsl:()=>Rr,isNumberArray:()=>h,isObjectEmpty:()=>et,isTypedArray:()=>xe,isUniformValue:()=>$e,loadFile:()=>wt,loadImage:()=>At,loadImageBitmap:()=>St,loadScript:()=>Rt,log:()=>c,luma:()=>D,makeRandomNumberGenerator:()=>ze,mergeShaderLayout:()=>mt,random:()=>Bt,requestAnimationFrame:()=>Ct,setPathPrefix:()=>vt,splitUniformsAndBindings:()=>xt,stubRemovedMethods:()=>Tt,uid:()=>P});function ye(r){if(typeof window<"u"&&typeof window.process=="object"&&window.process.type==="renderer"||typeof process<"u"&&typeof process.versions=="object"&&Boolean(process.versions.electron))return!0;let e=typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent,t=r||e;return!!(t&&t.indexOf("Electron")>=0)}function d(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process.browser)||ye()}var Vt=globalThis.self||globalThis.window||globalThis.global,ee=globalThis.window||globalThis.self||globalThis.global,kt=globalThis.document||{},te=globalThis.process||{},Nt=globalThis.console,Fr=globalThis.navigator||{};var re="4.0.6",Mr=d();function $t(r){try{let e=window[r],t="__storage_test__";return e.setItem(t,t),e.removeItem(t),e}catch{return null}}var oe=class{constructor(e,t,o="sessionStorage"){this.storage=$t(o),this.id=e,this.config=t,this._loadConfiguration()}getConfiguration(){return this.config}setConfiguration(e){if(Object.assign(this.config,e),this.storage){let t=JSON.stringify(this.config);this.storage.setItem(this.id,t)}}_loadConfiguration(){let e={};if(this.storage){let t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}};function We(r){let e;return r<10?e=`${r.toFixed(2)}ms`:r<100?e=`${r.toFixed(1)}ms`:r<1e3?e=`${r.toFixed(0)}ms`:e=`${(r/1e3).toFixed(2)}s`,e}function qe(r,e=8){let t=Math.max(e-r.length,0);return`${" ".repeat(t)}${r}`}function ne(r,e,t,o=600){let n=r.src.replace(/\(/g,"%28").replace(/\)/g,"%29");r.width>o&&(t=Math.min(t,o/r.width));let s=r.width*t,a=r.height*t,i=["font-size:1px;",`padding:${Math.floor(a/2)}px ${Math.floor(s/2)}px;`,`line-height:${a}px;`,`background:url(${n});`,`background-size:${s}px ${a}px;`,"color:transparent;"].join("");return[`${e} %c+`,i]}var se;(function(r){r[r.BLACK=30]="BLACK",r[r.RED=31]="RED",r[r.GREEN=32]="GREEN",r[r.YELLOW=33]="YELLOW",r[r.BLUE=34]="BLUE",r[r.MAGENTA=35]="MAGENTA",r[r.CYAN=36]="CYAN",r[r.WHITE=37]="WHITE",r[r.BRIGHT_BLACK=90]="BRIGHT_BLACK",r[r.BRIGHT_RED=91]="BRIGHT_RED",r[r.BRIGHT_GREEN=92]="BRIGHT_GREEN",r[r.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",r[r.BRIGHT_BLUE=94]="BRIGHT_BLUE",r[r.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",r[r.BRIGHT_CYAN=96]="BRIGHT_CYAN",r[r.BRIGHT_WHITE=97]="BRIGHT_WHITE"})(se||(se={}));var Ot=10;function je(r){return typeof r!="string"?r:(r=r.toUpperCase(),se[r]||se.WHITE)}function Qe(r,e,t){return!d&&typeof r=="string"&&(e&&(r=`\x1B[${je(e)}m${r}\x1B[39m`),t&&(r=`\x1B[${je(t)+Ot}m${r}\x1B[49m`)),r}function Ye(r,e=["constructor"]){let t=Object.getPrototypeOf(r),o=Object.getOwnPropertyNames(t),n=r;for(let s of o){let a=n[s];typeof a=="function"&&(e.find(i=>s===i)||(n[s]=a.bind(r)))}}function A(r,e){if(!r)throw new Error(e||"Assertion failed")}function v(){let r;if(d()&&ee.performance)r=ee?.performance?.now?.();else if("hrtime"in te){let e=te?.hrtime?.();r=e[0]*1e3+e[1]/1e6}else r=Date.now();return r}var R={debug:d()&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},zt={enabled:!0,level:0};function g(){}var Xe={},Ke={once:!0},T=class{constructor({id:e}={id:""}){this.VERSION=re,this._startTs=v(),this._deltaTs=v(),this.userData={},this.LOG_THROTTLE_TIMEOUT=0,this.id=e,this.userData={},this._storage=new oe(`__probe-${this.id}__`,zt),this.timeStamp(`${this.id} started`),Ye(this),Object.seal(this)}set level(e){this.setLevel(e)}get level(){return this.getLevel()}isEnabled(){return this._storage.config.enabled}getLevel(){return this._storage.config.level}getTotal(){return Number((v()-this._startTs).toPrecision(10))}getDelta(){return Number((v()-this._deltaTs).toPrecision(10))}set priority(e){this.level=e}get priority(){return this.level}getPriority(){return this.level}enable(e=!0){return this._storage.setConfiguration({enabled:e}),this}setLevel(e){return this._storage.setConfiguration({level:e}),this}get(e){return this._storage.config[e]}set(e,t){this._storage.setConfiguration({[e]:t})}settings(){console.table?console.table(this._storage.config):console.log(this._storage.config)}assert(e,t){A(e,t)}warn(e){return this._getLogFunction(0,e,R.warn,arguments,Ke)}error(e){return this._getLogFunction(0,e,R.error,arguments)}deprecated(e,t){return this.warn(`\`${e}\` is deprecated and will be removed in a later version. Use \`${t}\` instead`)}removed(e,t){return this.error(`\`${e}\` has been removed. Use \`${t}\` instead`)}probe(e,t){return this._getLogFunction(e,t,R.log,arguments,{time:!0,once:!0})}log(e,t){return this._getLogFunction(e,t,R.debug,arguments)}info(e,t){return this._getLogFunction(e,t,console.info,arguments)}once(e,t){return this._getLogFunction(e,t,R.debug||R.info,arguments,Ke)}table(e,t,o){return t?this._getLogFunction(e,t,console.table||g,o&&[o],{tag:qt(t)}):g}image({logLevel:e,priority:t,image:o,message:n="",scale:s=1}){return this._shouldLog(e||t)?d()?Wt({image:o,message:n,scale:s}):Ht({image:o,message:n,scale:s}):g}time(e,t){return this._getLogFunction(e,t,console.time?console.time:console.info)}timeEnd(e,t){return this._getLogFunction(e,t,console.timeEnd?console.timeEnd:console.info)}timeStamp(e,t){return this._getLogFunction(e,t,console.timeStamp||g)}group(e,t,o={collapsed:!1}){let n=Ze({logLevel:e,message:t,opts:o}),{collapsed:s}=o;return n.method=(s?console.groupCollapsed:console.group)||console.info,this._getLogFunction(n)}groupCollapsed(e,t,o={}){return this.group(e,t,Object.assign({},o,{collapsed:!0}))}groupEnd(e){return this._getLogFunction(e,"",console.groupEnd||g)}withGroup(e,t,o){this.group(e,t)();try{o()}finally{this.groupEnd(e)()}}trace(){console.trace&&console.trace()}_shouldLog(e){return this.isEnabled()&&this.getLevel()>=Je(e)}_getLogFunction(e,t,o,n,s){if(this._shouldLog(e)){s=Ze({logLevel:e,message:t,args:n,opts:s}),o=o||s.method,A(o),s.total=this.getTotal(),s.delta=this.getDelta(),this._deltaTs=v();let a=s.tag||s.message;if(s.once&&a)if(!Xe[a])Xe[a]=v();else return g;return t=Gt(this.id,s.message,s),o.bind(console,t,...s.args)}return g}};T.VERSION=re;function Je(r){if(!r)return 0;let e;switch(typeof r){case"number":e=r;break;case"object":e=r.logLevel||r.priority||0;break;default:return 0}return A(Number.isFinite(e)&&e>=0),e}function Ze(r){let{logLevel:e,message:t}=r;r.logLevel=Je(e);let o=r.args?Array.from(r.args):[];for(;o.length&&o.shift()!==t;);switch(typeof e){case"string":case"function":t!==void 0&&o.unshift(t),r.message=e;break;case"object":Object.assign(r,e);break;default:}typeof r.message=="function"&&(r.message=r.message());let n=typeof r.message;return A(n==="string"||n==="object"),Object.assign(r,{args:o},r.opts)}function Gt(r,e,t){if(typeof e=="string"){let o=t.time?qe(We(t.total)):"";e=t.time?`${r}: ${o} ${e}`:`${r}: ${e}`,e=Qe(e,t.color,t.background)}return e}function Ht({image:r,message:e="",scale:t=1}){return console.warn("removed"),g}function Wt({image:r,message:e="",scale:t=1}){if(typeof r=="string"){let n=new Image;return n.onload=()=>{let s=ne(n,e,t);console.log(...s)},n.src=r,g}let o=r.nodeName||"";if(o.toLowerCase()==="img")return console.log(...ne(r,e,t)),g;if(o.toLowerCase()==="canvas"){let n=new Image;return n.onload=()=>console.log(...ne(n,e,t)),n.src=r.toDataURL(),g}return g}function qt(r){for(let e in r)for(let t in r[e])return t||"untitled";return"empty"}globalThis.probe={};var ao=new T({id:"@probe.gl/log"});var c=new T({id:"luma.gl"});function I(){let r;if(typeof window<"u"&&window.performance)r=window.performance.now();else if(typeof process<"u"&&process.hrtime){let e=process.hrtime();r=e[0]*1e3+e[1]/1e6}else r=Date.now();return r}var w=class{constructor(e,t){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=e,this.type=t,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(e){return this.sampleSize=e,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(e){return this._count+=e,this._samples++,this._checkSampling(),this}subtractCount(e){return this._count-=e,this._samples++,this._checkSampling(),this}addTime(e){return this._time+=e,this.lastTiming=e,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=I(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(I()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var B=class{constructor(e){this.stats={},this.id=e.id,this.stats={},this._initializeStats(e.stats),Object.seal(this)}get(e,t="count"){return this._getOrCreate({name:e,type:t})}get size(){return Object.keys(this.stats).length}reset(){for(let e of Object.values(this.stats))e.reset();return this}forEach(e){for(let t of Object.values(this.stats))e(t)}getTable(){let e={};return this.forEach(t=>{e[t.name]={time:t.time||0,count:t.count||0,average:t.getAverageTime()||0,hz:t.getHz()||0}}),e}_initializeStats(e=[]){e.forEach(t=>this._getOrCreate(t))}_getOrCreate(e){let{name:t,type:o}=e,n=this.stats[t];return n||(e instanceof w?n=e:n=new w(t,o),this.stats[t]=n),n}};var _=class{stats=new Map;getStats(e){return this.get(e)}get(e){return this.stats.has(e)||this.stats.set(e,new B({id:e})),this.stats.get(e)}},C=new _;function jt(){let r=typeof __VERSION__<"u"?__VERSION__:"running from source",e="set luma.log.level=1 (or higher) to trace rendering";if(globalThis.luma&&globalThis.luma.VERSION!==r)throw new Error(`luma.gl - multiple VERSIONs detected: ${globalThis.luma.VERSION} vs ${r}`);return globalThis.luma||(d()&&c.log(1,`${r} - ${e}`)(),globalThis.luma=globalThis.luma||{VERSION:r,version:r,log:c,stats:C}),r}var ae=jt();function xe(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)?r:null}function h(r){return Array.isArray(r)?r.length===0||typeof r[0]=="number"?r:null:xe(r)}var Te={};function P(r="id"){Te[r]=Te[r]||1;let e=Te[r]++;return`${r}-${e}`}function et(r){let e=!0;for(let t in r){e=!1;break}return e}var m=class{id;props;userData={};_device;destroyed=!1;allocatedBytes=0;_attachedResources=new Set;constructor(e,t,o){if(!e)throw new Error("no device");this._device=e,this.props=Qt(t,o);let n=this.props.id!=="undefined"?this.props.id:P(this[Symbol.toStringTag]);this.props.id=n,this.id=n,this.userData=this.props.userData||{},this.addStats()}destroy(){this.destroyResource()}delete(){return this.destroy(),this}toString(){return`${this[Symbol.toStringTag]||this.constructor.name}(${this.id})`}getProps(){return this.props}attachResource(e){this._attachedResources.add(e)}detachResource(e){this._attachedResources.delete(e)}destroyAttachedResource(e){this._attachedResources.delete(e)&&e.destroy()}destroyAttachedResources(){for(let e of Object.values(this._attachedResources))e.destroy();this._attachedResources=new Set}destroyResource(){this.destroyAttachedResources(),this.removeStats(),this.destroyed=!0}removeStats(){let e=this._device.statsManager.getStats("Resource Counts"),t=this[Symbol.toStringTag];e.get(`${t}s Active`).decrementCount()}trackAllocatedMemory(e,t=this[Symbol.toStringTag]){let o=this._device.statsManager.getStats("Resource Counts");o.get("GPU Memory").addCount(e),o.get(`${t} Memory`).addCount(e),this.allocatedBytes=e}trackDeallocatedMemory(e=this[Symbol.toStringTag]){let t=this._device.statsManager.getStats("Resource Counts");t.get("GPU Memory").subtractCount(this.allocatedBytes),t.get(`${e} Memory`).subtractCount(this.allocatedBytes),this.allocatedBytes=0}addStats(){let e=this._device.statsManager.getStats("Resource Counts"),t=this[Symbol.toStringTag];e.get("Resources Created").incrementCount(),e.get(`${t}s Created`).incrementCount(),e.get(`${t}s Active`).incrementCount()}};u(m,"defaultProps",{id:"undefined",handle:void 0,userData:void 0});function Qt(r,e){let t={...e};for(let o in r)r[o]!==void 0&&(t[o]=r[o]);return t}var M=class extends m{get[Symbol.toStringTag](){return"Buffer"}usage;indexType;updateTimestamp;constructor(e,t){let o={...t};(t.usage||0)&M.INDEX&&!t.indexType&&(t.data instanceof Uint32Array?o.indexType="uint32":t.data instanceof Uint16Array&&(o.indexType="uint16")),super(e,o,M.defaultProps),this.usage=t.usage||0,this.indexType=o.indexType,this.updateTimestamp=e.incrementTimestamp()}readSyncWebGL(e,t){throw new Error("not implemented")}debugData=new ArrayBuffer(0);_setDebugData(e,t,o){let n=ArrayBuffer.isView(e)?e.buffer:e,s=Math.min(e?e.byteLength:o,M.DEBUG_DATA_MAX_LENGTH);e===null?this.debugData=new ArrayBuffer(s):t===0&&o===e.byteLength?this.debugData=n.slice(0,s):this.debugData=n.slice(t,t+s)}},f=M;u(f,"defaultProps",{...m.defaultProps,usage:0,byteLength:0,byteOffset:0,data:null,indexType:"uint16",mappedAtCreation:!1}),u(f,"MAP_READ",1),u(f,"MAP_WRITE",2),u(f,"COPY_SRC",4),u(f,"COPY_DST",8),u(f,"INDEX",16),u(f,"VERTEX",32),u(f,"UNIFORM",64),u(f,"STORAGE",128),u(f,"INDIRECT",256),u(f,"QUERY_RESOLVE",512),u(f,"DEBUG_DATA_MAX_LENGTH",32);function ie(r){let e=tt[r],t=Yt(e),o=r.includes("norm"),n=!o&&!r.startsWith("float"),s=r.startsWith("s");return{dataType:tt[r],byteLength:t,integer:n,signed:s,normalized:o}}function Yt(r){return Xt[r]}var tt={uint8:"uint8",sint8:"sint8",unorm8:"uint8",snorm8:"sint8",uint16:"uint16",sint16:"sint16",unorm16:"uint16",snorm16:"sint16",float16:"float16",float32:"float32",uint32:"uint32",sint32:"sint32"},Xt={uint8:1,sint8:1,uint16:2,sint16:2,float16:2,float32:4,uint32:4,sint32:4};var Kt=["bc1","bc2","bc3","bc4","bc5","bc6","bc7","etc1","etc2","eac","atc","astc","pvrtc"],Zt=/^(rg?b?a?)([0-9]*)([a-z]*)(-srgb)?(-webgl|-unsized)?$/;function rt(r){return Kt.some(e=>r.startsWith(e))}function ot(r){let e=Zt.exec(r);if(e){let[,t,o,n,s,a]=e;if(t){let i=`${n}${o}`,p=ie(i);return{format:t,components:t.length,srgb:s==="-srgb",unsized:a==="-unsized",webgl:a==="-webgl",...p}}}return er(r)}var Jt={"rgba4unorm-webgl":{format:"rgba",bpp:2},"rgb565unorm-webgl":{format:"rgb",bpp:2},"rgb5a1unorm-webgl":{format:"rgba",bbp:2},rgb9e5ufloat:{format:"rgb",bbp:4},rg11b10ufloat:{format:"rgb",bbp:4},rgb10a2unorm:{format:"rgba",bbp:4},"rgb10a2uint-webgl":{format:"rgba",bbp:4},stencil8:{components:1,bpp:1,a:"stencil"},depth16unorm:{components:1,bpp:2,a:"depth"},depth24plus:{components:1,bpp:3,a:"depth"},depth32float:{components:1,bpp:4,a:"depth"},"depth24plus-stencil8":{components:2,bpp:4,a:"depth-stencil"},"depth24unorm-stencil8":{components:2,bpp:4,a:"depth-stencil"},"depth32float-stencil8":{components:2,bpp:4,a:"depth-stencil"}};function er(r){let e=Jt[r];if(!e)throw new Error(`Unknown format ${r}`);return{format:e.format||"",components:e.components||e.format?.length||1,byteLength:e.bpp||1,srgb:!1,unsized:!1}}var ue=class{},me=class{features;disabledFeatures;constructor(e=[],t){this.features=new Set(e),this.disabledFeatures=t||{}}*[Symbol.iterator](){yield*this.features}has(e){return!this.disabledFeatures[e]&&this.features.has(e)}},Pe=class{get[Symbol.toStringTag](){return"Device"}constructor(e){this.props={...Pe.defaultProps,...e},this.id=this.props.id||P(this[Symbol.toStringTag].toLowerCase())}id;props;userData={};statsManager=C;_lumaData={};isTextureFormatCompressed(e){return rt(e)}loseDevice(){return!1}getCanvasContext(){if(!this.canvasContext)throw new Error("Device has no CanvasContext");return this.canvasContext}createTexture(e){return(e instanceof Promise||typeof e=="string")&&(e={data:e}),this._createTexture(e)}createCommandEncoder(e={}){throw new Error("not implemented")}readPixelsToArrayWebGL(e,t){throw new Error("not implemented")}readPixelsToBufferWebGL(e,t){throw new Error("not implemented")}setParametersWebGL(e){throw new Error("not implemented")}getParametersWebGL(e){throw new Error("not implemented")}withParametersWebGL(e,t){throw new Error("not implemented")}clearWebGL(e){throw new Error("not implemented")}timestamp=0;incrementTimestamp(){return this.timestamp++}onError(e){this.props.onError(e)}_getBufferProps(e){(e instanceof ArrayBuffer||ArrayBuffer.isView(e))&&(e={data:e});let t={...e};return(e.usage||0)&f.INDEX&&!e.indexType&&(e.data instanceof Uint32Array?t.indexType="uint32":e.data instanceof Uint16Array?t.indexType="uint16":c.warn("indices buffer content must be of integer type")()),t}},x=Pe;u(x,"defaultProps",{id:null,canvas:null,container:null,manageState:!0,width:800,height:600,requestMaxLimits:!0,debug:Boolean(c.get("debug")),spector:Boolean(c.get("spector")),break:[],initalizeFeatures:!0,disabledFeatures:{"compilation-status-async-webgl":!0},gl:null,onError:e=>c.error(e.message)}),u(x,"VERSION",ae);function E(r,e){if(!r)throw new Error(e||"luma.gl: assertion failed.")}var S=new Map,D=class{static registerDevices(e){for(let t of e)E(t.type&&t.isSupported&&t.create),S.set(t.type,t)}static getAvailableDevices(){return Array.from(S).map(e=>e.type)}static getSupportedDevices(){return Array.from(S).filter(e=>e.isSupported()).map(e=>e.type)}static setDefaultDeviceProps(e){Object.assign(x.defaultProps,e)}static async createDevice(e={}){e={...x.defaultProps,...e},e.gl&&(e.type="webgl");let t;switch(e.type){case"webgpu":if(t=S.get("webgpu"),t)return await t.create(e);break;case"webgl":if(t=S.get("webgl"),t)return await t.create(e);break;case"best-available":if(t=S.get("webgpu"),t&&t.isSupported())return await t.create(e);if(t=S.get("webgl"),t&&t.isSupported())return await t.create(e);break}throw new Error("No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.")}};u(D,"stats",C),u(D,"log",c);var tr=d()&&typeof document<"u",pe=()=>tr&&document.readyState==="complete",rr={canvas:null,width:800,height:600,useDevicePixels:!0,autoResize:!0,container:null,visible:!0,colorSpace:"srgb",alphaMode:"opaque"},U=class{id;props;canvas;htmlCanvas;offscreenCanvas;type;width=1;height=1;resizeObserver;_canvasSizeInfo={clientWidth:0,clientHeight:0,devicePixelRatio:1};static get isPageLoaded(){return pe()}constructor(e){if(this.props={...rr,...e},e=this.props,!d()){this.id="node-canvas-context",this.type="node",this.width=this.props.width,this.height=this.props.height,this.canvas=null;return}if(e.canvas)typeof e.canvas=="string"?this.canvas=sr(e.canvas):this.canvas=e.canvas;else{let t=ar(e),o=nr(e?.container||null);o.insertBefore(t,o.firstChild),this.canvas=t,e?.visible||(this.canvas.style.visibility="hidden")}this.canvas instanceof HTMLCanvasElement?(this.id=this.canvas.id,this.type="html-canvas",this.htmlCanvas=this.canvas):(this.id="offscreen-canvas",this.type="offscreen-canvas",this.offscreenCanvas=this.canvas),this.canvas instanceof HTMLCanvasElement&&e.autoResize&&(this.resizeObserver=new ResizeObserver(t=>{for(let o of t)o.target===this.canvas&&this.update()}),this.resizeObserver.observe(this.canvas))}getDevicePixelRatio(e){return typeof OffscreenCanvas<"u"&&this.canvas instanceof OffscreenCanvas||(e=e===void 0?this.props.useDevicePixels:e,!e||e<=0)?1:e===!0?typeof window<"u"&&window.devicePixelRatio||1:e}getPixelSize(){switch(this.type){case"node":return[this.width,this.height];case"offscreen-canvas":return[this.canvas.width,this.canvas.height];case"html-canvas":let e=this.getDevicePixelRatio(),t=this.canvas;return t.parentElement?[t.clientWidth*e,t.clientHeight*e]:[this.canvas.width,this.canvas.height];default:throw new Error(this.type)}}getAspect(){let[e,t]=this.getPixelSize();return e/t}cssToDeviceRatio(){try{let[e]=this.getDrawingBufferSize(),{clientWidth:t}=this._canvasSizeInfo;return t?e/t:1}catch{return 1}}cssToDevicePixels(e,t=!0){let o=this.cssToDeviceRatio(),[n,s]=this.getDrawingBufferSize();return ir(e,o,n,s,t)}setDevicePixelRatio(e,t={}){if(!this.htmlCanvas)return;let o="width"in t?t.width:this.htmlCanvas.clientWidth,n="height"in t?t.height:this.htmlCanvas.clientHeight;(!o||!n)&&(c.log(1,"Canvas clientWidth/clientHeight is 0")(),e=1,o=this.htmlCanvas.width||1,n=this.htmlCanvas.height||1);let s=this._canvasSizeInfo;if(s.clientWidth!==o||s.clientHeight!==n||s.devicePixelRatio!==e){let a=e,i=Math.floor(o*a),p=Math.floor(n*a);this.htmlCanvas.width=i,this.htmlCanvas.height=p;let[b,y]=this.getDrawingBufferSize();(b!==i||y!==p)&&(a=Math.min(b/o,y/n),this.htmlCanvas.width=Math.floor(o*a),this.htmlCanvas.height=Math.floor(n*a),c.warn("Device pixel ratio clamped")()),this._canvasSizeInfo.clientWidth=o,this._canvasSizeInfo.clientHeight=n,this._canvasSizeInfo.devicePixelRatio=e}}getDrawingBufferSize(){let e=this.device.gl;if(!e)throw new Error("canvas size");return[e.drawingBufferWidth,e.drawingBufferHeight]}_setAutoCreatedCanvasId(e){this.htmlCanvas?.id==="lumagl-auto-created-canvas"&&(this.htmlCanvas.id=e)}};u(U,"pageLoaded",or());function or(){return pe()||typeof window>"u"?Promise.resolve():new Promise(r=>{window.addEventListener("load",()=>r())})}function nr(r){if(typeof r=="string"){let e=document.getElementById(r);if(!e&&!pe())throw new Error(`Accessing '${r}' before page was loaded`);if(!e)throw new Error(`${r} is not an HTML element`);return e}else if(r)return r;return document.body}function sr(r){let e=document.getElementById(r);if(!e&&!pe())throw new Error(`Accessing '${r}' before page was loaded`);if(!(e instanceof HTMLCanvasElement))throw new Error("Object is not a canvas element");return e}function ar(r){let{width:e,height:t}=r,o=document.createElement("canvas");return o.id="lumagl-auto-created-canvas",o.width=e||1,o.height=t||1,o.style.width=Number.isFinite(e)?`${e}px`:"100%",o.style.height=Number.isFinite(t)?`${t}px`:"100%",o}function ir(r,e,t,o,n){let s=r,a=nt(s[0],e,t),i=st(s[1],e,o,n),p=nt(s[0]+1,e,t),b=p===t-1?p:p-1;p=st(s[1]+1,e,o,n);let y;return n?(p=p===0?p:p+1,y=i,i=p):y=p===o-1?p:p-1,{x:a,y:i,width:Math.max(b-a+1,1),height:Math.max(y-i+1,1)}}function nt(r,e,t){return Math.min(Math.round(r*e),t-1)}function st(r,e,t,o){return o?Math.max(0,t-1-Math.round(r*e)):Math.min(Math.round(r*e),t-1)}var ve=class extends m{get[Symbol.toStringTag](){return"Texture"}dimension;format;width;height;depth;updateTimestamp;constructor(e,t,o=ve.defaultProps){super(e,t,o),this.dimension=this.props.dimension,this.format=this.props.format,this.width=this.props.width,this.height=this.props.height,this.depth=this.props.depth,this.updateTimestamp=e.incrementTimestamp()}},l=ve;u(l,"defaultProps",{...m.defaultProps,data:null,dimension:"2d",format:"rgba8unorm",width:void 0,height:void 0,depth:1,mipmaps:!0,compressed:!1,usage:0,mipLevels:void 0,samples:void 0,type:void 0,sampler:{},view:void 0}),u(l,"COPY_SRC",1),u(l,"COPY_DST",2),u(l,"TEXTURE_BINDING",4),u(l,"STORAGE_BINDING",8),u(l,"RENDER_ATTACHMENT",16);var we=class extends m{get[Symbol.toStringTag](){return"TextureView"}constructor(e,t){super(e,t,we.defaultProps)}},V=we;u(V,"defaultProps",{...m.defaultProps,format:void 0,dimension:void 0,aspect:"all",baseMipLevel:0,mipLevelCount:void 0,baseArrayLayer:0,arrayLayerCount:void 0});var Se=class extends m{get[Symbol.toStringTag](){return"ExternalTexture"}constructor(e,t){super(e,t,Se.defaultProps)}},k=Se;u(k,"defaultProps",{...m.defaultProps,source:null,colorSpace:"srgb"});function ce(r,e,t){let o="",n=e.split(/\r?\n/),s=r.slice().sort((a,i)=>a.lineNum-i.lineNum);switch(t?.showSourceCode||"no"){case"all":let a=0;for(let i=1;i<=n.length;i++)for(o+=it(n[i-1],i,t);s.length>a&&s[a].lineNum===i;){let p=s[a++];o+=at(p,n,p.lineNum,{...t,inlineSource:!1})}return o;case"issues":case"no":for(let i of r)o+=at(i,n,i.lineNum,{inlineSource:t?.showSourceCode!=="no"});return o}}function at(r,e,t,o){if(o?.inlineSource){let n=ur(e,t),s=r.linePos>0?`${" ".repeat(r.linePos+5)}^^^
|
|
8
|
+
`:"";return`
|
|
9
|
+
${n}${s}${r.type.toUpperCase()}: ${r.message}
|
|
10
|
+
|
|
11
|
+
`}return o?.html?`<div class='luma-compiler-log-error' style="color:red;"><b> ${r.type.toUpperCase()}: ${r.message}</b></div>`:`${r.type.toUpperCase()}: ${r.message}`}function ur(r,e,t){let o="";for(let n=e-2;n<=e;n++){let s=r[n-1];s!==void 0&&(o+=it(s,e,t))}return o}function it(r,e,t){let o=t?.html?pr(r):r;return`${mr(String(e),4)}: ${o}${t?.html?"<br/>":`
|
|
12
|
+
`}`}function mr(r,e){let t="";for(let o=r.length;o<e;++o)t+=" ";return t+r}function pr(r){return r.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}function Ae(r,e){return{name:cr(r,e),language:"glsl",version:fr(r)}}function cr(r,e="unnamed"){let o=/#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/.exec(r);return o?o[1]:e}function fr(r){let e=100,t=r.match(/[^\s]+/g);if(t&&t.length>=2&&t[0]==="#version"){let o=parseInt(t[1],10);Number.isFinite(o)&&(e=o)}return e}var Re=class extends m{get[Symbol.toStringTag](){return"Shader"}stage;source;compilationStatus="pending";constructor(e,t){super(e,{id:dr(t),...t},Re.defaultProps),this.stage=this.props.stage,this.source=this.props.source}getCompilationInfoSync(){return null}getTranslatedSource(){return null}async debugShader(e=this.props.debug){switch(e){case"never":return;case"errors":if(this.compilationStatus==="success")return;break;case"warnings":case"always":break}let t=await this.getCompilationInfo();this.props.debug==="warnings"&&t?.length===0||this._displayShaderLog(t)}_displayShaderLog(e){if(typeof document>"u"||!document?.createElement)return;let t=Ae(this.source).name,o=`${this.stage} ${t}`,n=ce(e,this.source,{showSourceCode:"all",html:!0}),s=this.getTranslatedSource();s&&(n+=`<br /><br /><h1>Translated Source</h1><br /><br /><code style="user-select:text;"><pre>${s}</pre></code>`);let a=document.createElement("Button");a.innerHTML=`
|
|
13
|
+
<h1>Shader Compilation Error in ${o}</h1><br /><br />
|
|
14
|
+
<code style="user-select:text;"><pre>
|
|
15
|
+
${n}
|
|
16
|
+
</pre></code>`,a.style.top="10px",a.style.left="10px",a.style.position="absolute",a.style.zIndex="9999",a.style.width="100%",a.style.textAlign="left",document.body.appendChild(a);let i=document.getElementsByClassName("luma-compiler-log-error");i[0]?.scrollIntoView&&i[0].scrollIntoView(),a.onclick=()=>{let p=`data:text/plain,${encodeURIComponent(this.source)}`;navigator.clipboard.writeText(p)}}},N=Re;u(N,"defaultProps",{...m.defaultProps,language:"auto",stage:void 0,source:"",sourceMap:null,entryPoint:"main",debug:"errors"});function dr(r){return Ae(r.source).name||r.id||P(`unnamed ${r.stage}-shader`)}var Be=class extends m{get[Symbol.toStringTag](){return"Sampler"}constructor(e,t){super(e,t,Be.defaultProps)}},$=Be;u($,"defaultProps",{...m.defaultProps,type:"color-sampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"nearest",lodMinClamp:0,lodMaxClamp:32,compare:"less-equal",maxAnisotropy:1});var Ce=class extends m{get[Symbol.toStringTag](){return"Framebuffer"}width;height;colorAttachments=[];depthStencilAttachment=null;constructor(e,t={}){super(e,t,Ce.defaultProps),this.width=this.props.width,this.height=this.props.height}resize(e){let t=!e;if(e){let[o,n]=Array.isArray(e)?e:[e.width,e.height];t=t||n!==this.height||o!==this.width,this.width=o,this.height=n}t&&(c.log(2,`Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)(),this.resizeAttachments(this.width,this.height))}autoCreateAttachmentTextures(){if(this.props.colorAttachments.length===0&&!this.props.depthStencilAttachment)throw new Error("Framebuffer has noattachments");this.colorAttachments=this.props.colorAttachments.map(t=>{if(typeof t=="string"){let o=this.createColorTexture(t);return this.attachResource(o),o.view}return t instanceof l?t.view:t});let e=this.props.depthStencilAttachment;if(e)if(typeof e=="string"){let t=this.createDepthStencilTexture(e);this.attachResource(t),this.depthStencilAttachment=t.view}else e instanceof l?this.depthStencilAttachment=e.view:this.depthStencilAttachment=e}createColorTexture(e){return this.device.createTexture({id:"color-attachment",usage:l.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height})}createDepthStencilTexture(e){return this.device.createTexture({id:"depth-stencil-attachment",usage:l.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height})}resizeAttachments(e,t){for(let o=0;o<this.colorAttachments.length;++o)if(this.colorAttachments[o]){let n=this.device._createTexture({...this.colorAttachments[o].props,width:e,height:t});this.destroyAttachedResource(this.colorAttachments[o]),this.colorAttachments[o]=n.view,this.attachResource(n.view)}if(this.depthStencilAttachment){let o=this.device._createTexture({...this.depthStencilAttachment.props,width:e,height:t});this.destroyAttachedResource(this.depthStencilAttachment),this.depthStencilAttachment=o.view,this.attachResource(o)}}},O=Ce;u(O,"defaultProps",{...m.defaultProps,width:1,height:1,colorAttachments:[],depthStencilAttachment:null});var Ee=class extends m{get[Symbol.toStringTag](){return"RenderPipeline"}shaderLayout;bufferLayout;linkStatus="pending";hash="";constructor(e,t){super(e,t,Ee.defaultProps),this.shaderLayout=this.props.shaderLayout,this.bufferLayout=this.props.bufferLayout||[]}setUniformsWebGL(e){throw new Error("Use uniform blocks")}},z=Ee;u(z,"defaultProps",{...m.defaultProps,vs:null,vertexEntryPoint:"vertexMain",vsConstants:{},fs:null,fragmentEntryPoint:"fragmentMain",fsConstants:{},shaderLayout:null,bufferLayout:[],topology:"triangle-list",parameters:{},vertexCount:0,instanceCount:0,bindings:{},uniforms:{}});var De=class extends m{get[Symbol.toStringTag](){return"RenderPass"}constructor(e,t){super(e,t,De.defaultProps)}},G=De;u(G,"defaultProps",{...m.defaultProps,framebuffer:null,parameters:void 0,clearColor:[0,0,0,0],clearDepth:1,clearStencil:0,depthReadOnly:!1,stencilReadOnly:!1,discard:!1,occlusionQuerySet:void 0,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0});var Le=class extends m{get[Symbol.toStringTag](){return"ComputePipeline"}hash="";constructor(e,t){super(e,t,Le.defaultProps)}},H=Le;u(H,"defaultProps",{...m.defaultProps,shader:void 0,entryPoint:void 0,constants:{},shaderLayout:void 0});var Fe=class extends m{get[Symbol.toStringTag](){return"ComputePass"}constructor(e,t){super(e,t,Fe.defaultProps)}},W=Fe;u(W,"defaultProps",{...m.defaultProps,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0});var Ie=class extends m{get[Symbol.toStringTag](){return"CommandEncoder"}constructor(e,t){super(e,t,Ie.defaultProps)}},q=Ie;u(q,"defaultProps",{...m.defaultProps,measureExecutionTime:void 0});var _e=class extends m{get[Symbol.toStringTag](){return"CommandBuffer"}constructor(e,t){super(e,t,_e.defaultProps)}},j=_e;u(j,"defaultProps",{...m.defaultProps});function fe(r){let[e,t]=gr[r],o=e==="i32"||e==="u32",n=e!=="u32",s=br[e]*t,a=lr(e,t);return{dataType:e,components:t,defaultVertexFormat:a,byteLength:s,integer:o,signed:n}}function lr(r,e){let t;switch(r){case"f32":t="float32";break;case"i32":t="sint32";break;case"u32":t="uint32";break;case"f16":return e<=2?"float16x2":"float16x4"}return e===1?t:`${t}x${e}`}var gr={f32:["f32",1],"vec2<f32>":["f32",2],"vec3<f32>":["f32",3],"vec4<f32>":["f32",4],f16:["f16",1],"vec2<f16>":["f16",2],"vec3<f16>":["f16",3],"vec4<f16>":["f16",4],i32:["i32",1],"vec2<i32>":["i32",2],"vec3<i32>":["i32",3],"vec4<i32>":["i32",4],u32:["u32",1],"vec2<u32>":["u32",2],"vec3<u32>":["u32",3],"vec4<u32>":["u32",4]},br={f32:4,f16:2,i32:4,u32:4};function Q(r){let e;r.endsWith("-webgl")&&(r.replace("-webgl",""),e=!0);let[t,o]=r.split("x"),n=t,s=o?parseInt(o):1,a=ie(n),i={type:n,components:s,byteLength:a.byteLength*s,integer:a.integer,signed:a.signed,normalized:a.normalized};return e&&(i.webglOnly=!0),i}function Me(r,e){let t={};for(let o of r.attributes)t[o.name]=hr(r,e,o.name);return t}function ut(r,e,t=16){let o=Me(r,e),n=new Array(t).fill(null);for(let s of Object.values(o))n[s.location]=s;return n}function hr(r,e,t){let o=yr(r,t),n=xr(e,t);if(!o)return null;let s=fe(o.type),a=n?.vertexFormat||s.defaultVertexFormat,i=Q(a);return{attributeName:n?.attributeName||o.name,bufferName:n?.bufferName||o.name,location:o.location,shaderType:o.type,shaderDataType:s.dataType,shaderComponents:s.components,vertexFormat:a,bufferDataType:i.type,bufferComponents:i.components,normalized:i.normalized,integer:s.integer,stepMode:n?.stepMode||o.stepMode,byteOffset:n?.byteOffset||0,byteStride:n?.byteStride||0}}function yr(r,e){let t=r.attributes.find(o=>o.name===e);return t||c.warn(`shader layout attribute "${e}" not present in shader`),t||null}function xr(r,e){Tr(r);let t=Pr(r,e);return t||(t=vr(r,e),t)?t:(c.warn(`layout for attribute "${e}" not present in buffer layout`),null)}function Tr(r){for(let e of r)(e.attributes&&e.format||!e.attributes&&!e.format)&&c.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`)}function Pr(r,e){for(let t of r)if(t.format&&t.name===e)return{attributeName:t.name,bufferName:e,stepMode:t.stepMode,vertexFormat:t.format,byteOffset:0,byteStride:t.byteStride||0};return null}function vr(r,e){for(let t of r){let o=t.byteStride;if(typeof t.byteStride!="number")for(let s of t.attributes||[]){let a=Q(s.format);o+=a.byteLength}let n=t.attributes?.find(s=>s.attribute===e);if(n)return{attributeName:n.attribute,bufferName:t.name,stepMode:t.stepMode,vertexFormat:n.format,byteOffset:n.byteOffset,byteStride:o}}return null}function mt(r,e){let t={...r,attributes:r.attributes.map(o=>({...o}))};for(let o of e?.attributes||[]){let n=t.attributes.find(s=>s.name===o.name);n?(n.type=o.type||n.type,n.stepMode=o.stepMode||n.stepMode):c.warn(`shader layout attribute ${o.name} not present in shader`)}return t}var Ue=class extends m{get[Symbol.toStringTag](){return"VertexArray"}maxVertexAttributes;attributeInfos;indexBuffer=null;attributes;constructor(e,t){super(e,t,Ue.defaultProps),this.maxVertexAttributes=e.limits.maxVertexAttributes,this.attributes=new Array(this.maxVertexAttributes).fill(null),this.attributeInfos=ut(t.renderPipeline.shaderLayout,t.renderPipeline.bufferLayout,this.maxVertexAttributes)}setConstantWebGL(e,t){throw new Error("constant attributes not supported")}},Y=Ue;u(Y,"defaultProps",{...m.defaultProps,renderPipeline:null});var Ve=class extends m{get[Symbol.toStringTag](){return"TransformFeedback"}constructor(e,t){super(e,t,Ve.defaultProps)}},X=Ve;u(X,"defaultProps",{...m.defaultProps,layout:void 0,buffers:{}});var ke=class extends m{get[Symbol.toStringTag](){return"QuerySet"}constructor(e,t){super(e,t,ke.defaultProps)}},K=ke;u(K,"defaultProps",{...m.defaultProps,type:void 0,count:void 0});var wr={f32:{type:"f32",components:1},i32:{type:"i32",components:1},u32:{type:"u32",components:1},"vec2<f32>":{type:"f32",components:2},"vec3<f32>":{type:"f32",components:3},"vec4<f32>":{type:"f32",components:4},"vec2<i32>":{type:"i32",components:2},"vec3<i32>":{type:"i32",components:3},"vec4<i32>":{type:"i32",components:4},"vec2<u32>":{type:"u32",components:2},"vec3<u32>":{type:"u32",components:3},"vec4<u32>":{type:"u32",components:4},"mat2x2<f32>":{type:"f32",components:4},"mat2x3<f32>":{type:"f32",components:6},"mat2x4<f32>":{type:"f32",components:8},"mat3x2<f32>":{type:"f32",components:6},"mat3x3<f32>":{type:"f32",components:9},"mat3x4<f32>":{type:"f32",components:12},"mat4x2<f32>":{type:"f32",components:8},"mat4x3<f32>":{type:"f32",components:12},"mat4x4<f32>":{type:"f32",components:16}};function de(r){let e=wr[r];return E(r),e}function pt(r,e){switch(e){case 1:return r;case 2:return r+r%2;default:return r+(4-r%4)%4}}var le;function Z(r){return(!le||le.byteLength<r)&&(le=new ArrayBuffer(r)),le}function ct(r,e){let t=Z(r.BYTES_PER_ELEMENT*e);return new r(t,0,e)}function ft(r){let{target:e,source:t,start:o=0,count:n=1}=r,s=t.length,a=n*s,i=0;for(let p=o;i<s;i++)e[p++]=t[i];for(;i<a;)i<a-i?(e.copyWithin(o+i,o,o+i),i*=2):(e.copyWithin(o+i,o,o+a-i),i=a);return r.target}var dt=1024,L=class{layout={};byteLength;constructor(e){let t=0;for(let[n,s]of Object.entries(e)){let a=de(s),{type:i,components:p}=a;t=pt(t,p);let b=t;t+=p,this.layout[n]={type:i,size:p,offset:b}}t+=(4-t%4)%4;let o=t*4;this.byteLength=Math.max(o,dt)}getData(e){let t=Math.max(this.byteLength,dt),o=Z(t),n={i32:new Int32Array(o),u32:new Uint32Array(o),f32:new Float32Array(o),f16:new Uint16Array(o)};for(let[s,a]of Object.entries(e)){let i=this.layout[s];if(!i){c.warn(`Supplied uniform value ${s} not present in uniform block layout`)();continue}let{type:p,size:b,offset:y}=i,Ge=n[p];if(b===1){if(typeof a!="number"&&typeof a!="boolean"){c.warn(`Supplied value for single component uniform ${s} is not a number: ${a}`)();continue}Ge[y]=Number(a)}else{let He=h(a);if(!He){c.warn(`Supplied value for multi component / array uniform ${s} is not a numeric array: ${a}`)();continue}Ge.set(He,y)}}return new Uint8Array(o)}has(e){return Boolean(this.layout[e])}get(e){return this.layout[e]}};function lt(r,e,t=16){if(r!==e)return!1;let o=h(r);if(!o)return!1;let n=h(e);if(n&&o.length===n.length){for(let s=0;s<o.length;++s)if(n[s]!==o[s])return!1}return!0}function gt(r){let e=h(r);return e?e.slice():r}var F=class{name;uniforms={};modifiedUniforms={};modified=!0;bindingLayout={};needsRedraw="initialized";constructor(e){if(this.name=e?.name,e?.name&&e?.shaderLayout){let t=e?.shaderLayout.bindings?.find(n=>n.type==="uniform"&&n.name===e?.name);if(!t)throw new Error(e?.name);let o=t;for(let n of o.uniforms||[])this.bindingLayout[n.name]=n}}setUniforms(e){for(let[t,o]of Object.entries(e))this._setUniform(t,o),this.needsRedraw||this.setNeedsRedraw(`${this.name}.${t}=${o}`)}setNeedsRedraw(e){this.needsRedraw=this.needsRedraw||e}getAllUniforms(){return this.modifiedUniforms={},this.needsRedraw=!1,this.uniforms||{}}_setUniform(e,t){lt(this.uniforms[e],t)||(this.uniforms[e]=gt(t),this.modifiedUniforms[e]=!0,this.modified=!0)}};var ge=class{uniformBlocks=new Map;uniformBufferLayouts=new Map;uniformBuffers=new Map;constructor(e){for(let[t,o]of Object.entries(e)){let n=t,s=new L(o.uniformTypes||{});this.uniformBufferLayouts.set(n,s);let a=new F({name:t});a.setUniforms(o.defaultUniforms||{}),this.uniformBlocks.set(n,a)}}destroy(){for(let e of this.uniformBuffers.values())e.destroy()}setUniforms(e){for(let[t,o]of Object.entries(e))this.uniformBlocks.get(t).setUniforms(o);this.updateUniformBuffers()}getUniformBufferByteLength(e){return this.uniformBufferLayouts.get(e).byteLength}getUniformBufferData(e){let t=this.uniformBlocks.get(e).getAllUniforms();return this.uniformBufferLayouts.get(e).getData(t)}createUniformBuffer(e,t,o){o&&this.setUniforms(o);let n=this.getUniformBufferByteLength(t),s=e.createBuffer({usage:f.UNIFORM|f.COPY_DST,byteLength:n}),a=this.getUniformBufferData(t);return s.write(a),s}getManagedUniformBuffer(e,t){if(!this.uniformBuffers.get(t)){let o=this.getUniformBufferByteLength(t),n=e.createBuffer({usage:f.UNIFORM|f.COPY_DST,byteLength:o});this.uniformBuffers.set(t,n)}return this.uniformBuffers.get(t)}updateUniformBuffers(){let e=!1;for(let t of this.uniformBlocks.keys()){let o=this.updateUniformBuffer(t);e||=o}return e&&c.log(3,`UniformStore.updateUniformBuffers(): ${e}`)(),e}updateUniformBuffer(e){let t=this.uniformBlocks.get(e),o=this.uniformBuffers.get(e),n=!1;if(o&&t.needsRedraw){n||=t.needsRedraw;let s=this.getUniformBufferData(e);this.uniformBuffers.get(e).write(s);let i=this.uniformBlocks.get(e).getAllUniforms();c.log(4,`Writing to uniform buffer ${String(e)}`,s,i)()}return n}};function Ne(r){let e=ArrayBuffer.isView(r)?r.constructor:r;switch(e){case Float32Array:return"float32";case Uint16Array:return"uint16";case Uint32Array:return"uint32";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int8Array:return"sint8";case Int16Array:return"sint16";case Int32Array:return"sint32";default:throw new Error(e.constructor.name)}}function bt(r){switch(r){case"float32":return Float32Array;case"uint32":return Uint32Array;case"sint32":return Int32Array;case"uint16":case"unorm16":return Uint16Array;case"sint16":case"snorm16":return Int16Array;case"uint8":case"unorm8":return Uint8Array;case"sint8":case"snorm8":return Int8Array;default:throw new Error(r)}}function ht(r,e,t){if(!e||e>4)throw new Error(`size ${e}`);let o=e,n=Ne(r);if(n==="uint8"||n==="sint8"){if(o===1||o===3)throw new Error(`size: ${e}`);return t&&(n=n.replace("int","norm")),`${n}x${o}`}if(n==="uint16"||n==="sint16"){if(o===1||o===3)throw new Error(`size: ${e}`);return t&&(n=n.replace("int","norm")),`${n}x${o}`}return o===1?n:`${n}x${o}`}function yt(r){return r}function $e(r){return h(r)!==null||typeof r=="number"||typeof r=="boolean"}function xt(r){let e={bindings:{},uniforms:{}};return Object.keys(r).forEach(t=>{let o=r[t];$e(o)?e.uniforms[t]=o:e.bindings[t]=o}),e}function Sr(r,e={}){let{maxElts:t=16,size:o=1}=e,n="[";for(let a=0;a<r.length&&a<t;++a)a>0&&(n+=`,${a%o===0?" ":""}`),n+=Oe(r[a],e);let s=r.length>t?"...":"]";return`${n}${s}`}function Oe(r,e={}){let{isInteger:o=!1}=e;if(Array.isArray(r)||ArrayBuffer.isView(r))return Sr(r,e);if(typeof r!="number")return String(r);if(Math.abs(r)<1e-16)return o?"0":"0.";if(o||Math.abs(r)>100&&Math.abs(r)<1e4)return r.toFixed(0);let n=r.toPrecision(2);return n.indexOf(".0")===n.length-2?n.slice(0,-1):n}function Tt(r,e,t,o){let n=`See luma.gl ${t} Upgrade Guide at https://luma.gl/docs/upgrade-guide`,s=Object.getPrototypeOf(r);o.forEach(a=>{s.methodName||(s[a]=()=>{throw c.removed(`Calling removed method ${e}.${a}: `,n)(),new Error(a)})})}function Pt(r,e,t){let{removedProps:o={},deprecatedProps:n={},replacedProps:s={}}=t;for(let i in o)if(i in e){let b=o[i]?`${r}.${o[i]}`:"N/A";c.removed(`${r}.${i}`,b)()}for(let i in n)if(i in e){let p=n[i];c.deprecated(`${r}.${i}`,`${r}.${p}`)()}let a=null;for(let[i,p]of Object.entries(s))i in e&&(c.deprecated(`${r}.${i}`,`${r}.${p}`)(),a=a||Object.assign({},e),a[p]=e[i],delete a[i]);return a||e}var be="";function vt(r){be=r}async function wt(r,e){r=r.startsWith("http")?r:be+r;let t=e?.dataType||"text";return await(await fetch(r,e))[t]()}async function St(r,e){let t=new Image;return t.crossOrigin=e?.crossOrigin||"anonymous",t.src=r.startsWith("http")?r:be+r,await t.decode(),await createImageBitmap(t)}async function At(r,e){return await new Promise((t,o)=>{try{let n=new Image;n.onload=()=>t(n),n.onerror=()=>o(new Error(`Could not load image ${r}.`)),n.crossOrigin=e?.crossOrigin||"anonymous",n.src=r.startsWith("http")?r:be+r}catch(n){o(n)}})}async function Rt(r,e){let t=document.getElementsByTagName("head")[0];if(!t)throw new Error("loadScript");let o=document.createElement("script");return o.setAttribute("type","text/javascript"),o.setAttribute("src",r),e&&(o.id=e),new Promise((n,s)=>{o.onload=n,o.onerror=a=>s(new Error(`Unable to load script '${r}': ${a}`)),t.appendChild(o)})}function ze(){let r=1,e=1;return()=>(r=Math.sin(e*17.23),e=Math.cos(r*27.92),Ar(Math.abs(r*e)*1432.71))}function Ar(r){return r-Math.floor(r)}var Bt=ze();function he(r,e,t){if(r===e)return!0;if(!t||!r||!e)return!1;if(Array.isArray(r)){if(!Array.isArray(e)||r.length!==e.length)return!1;for(let o=0;o<r.length;o++)if(!he(r[o],e[o],t-1))return!1;return!0}if(Array.isArray(e))return!1;if(typeof r=="object"&&typeof e=="object"){let o=Object.keys(r),n=Object.keys(e);if(o.length!==n.length)return!1;for(let s of o)if(!e.hasOwnProperty(s)||!he(r[s],e[s],t-1))return!1;return!0}return!1}function Ct(r){return typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame(r):setTimeout(r,1e3/60)}function Et(r){return typeof window<"u"&&window.cancelAnimationFrame?window.cancelAnimationFrame(r):clearTimeout(r)}var Rr=r=>`${r}`;return Ut(Br);})();
|
|
17
|
+
return __exports__;
|
|
18
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/core",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.3",
|
|
4
4
|
"description": "The luma.gl core Device API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@probe.gl/stats": "^4.0.2",
|
|
47
47
|
"@types/offscreencanvas": "^2019.6.4"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "543e03b2d4bd865ac86cc8927611b91cc3e0393c"
|
|
50
50
|
}
|
|
@@ -107,7 +107,10 @@ export abstract class RenderPipeline extends Resource<RenderPipelineProps> {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/** Set bindings (stored on pipeline and set before each call) */
|
|
110
|
-
abstract setBindings(
|
|
110
|
+
abstract setBindings(
|
|
111
|
+
bindings: Record<string, Binding>,
|
|
112
|
+
options?: {disableWarnings?: boolean}
|
|
113
|
+
): void;
|
|
111
114
|
|
|
112
115
|
/** Draw call. Returns false if the draw call was aborted (due to resources still initializing) */
|
|
113
116
|
abstract draw(options: {
|
package/src/lib/luma.ts
CHANGED
|
@@ -10,11 +10,20 @@ import {lumaStats} from '../utils/stats-manager';
|
|
|
10
10
|
import {log} from '../utils/log';
|
|
11
11
|
import {assert} from '../utils/assert';
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const deviceMap = new Map<string, typeof Device>();
|
|
14
14
|
|
|
15
|
+
/** Properties for creating a new device */
|
|
15
16
|
export type CreateDeviceProps = DeviceProps & {
|
|
16
|
-
/**
|
|
17
|
-
type?: 'webgl' | 'webgpu' | 'best-available';
|
|
17
|
+
/** Selects the type of device. `best-available` uses webgpu if available, then webgl. */
|
|
18
|
+
type?: 'webgl' | 'webgpu' | 'unknown' | 'best-available';
|
|
19
|
+
devices?: any[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Properties for attaching an existing WebGL context or WebGPU device to a new luma Device */
|
|
23
|
+
export type AttachDeviceProps = DeviceProps & {
|
|
24
|
+
/** Externally created WebGL context or WebGPU device */
|
|
25
|
+
handle: WebGL2RenderingContext; // | GPUDevice;
|
|
26
|
+
devices?: any[];
|
|
18
27
|
};
|
|
19
28
|
|
|
20
29
|
/**
|
|
@@ -23,6 +32,12 @@ export type CreateDeviceProps = DeviceProps & {
|
|
|
23
32
|
* Run-time selection of the first available Device
|
|
24
33
|
*/
|
|
25
34
|
export class luma {
|
|
35
|
+
static defaultProps: Required<CreateDeviceProps> = {
|
|
36
|
+
...Device.defaultProps,
|
|
37
|
+
type: 'best-available',
|
|
38
|
+
devices: undefined!
|
|
39
|
+
};
|
|
40
|
+
|
|
26
41
|
/** Global stats for all devices */
|
|
27
42
|
static stats: StatsManager = lumaStats;
|
|
28
43
|
|
|
@@ -32,18 +47,18 @@ export class luma {
|
|
|
32
47
|
static registerDevices(deviceClasses: any[] /* : typeof Device */): void {
|
|
33
48
|
for (const deviceClass of deviceClasses) {
|
|
34
49
|
assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
|
|
35
|
-
|
|
50
|
+
deviceMap.set(deviceClass.type, deviceClass);
|
|
36
51
|
}
|
|
37
52
|
}
|
|
38
53
|
|
|
39
54
|
static getAvailableDevices(): string[] {
|
|
40
55
|
// @ts-expect-error
|
|
41
|
-
return Array.from(
|
|
56
|
+
return Array.from(deviceMap).map(Device => Device.type);
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
static getSupportedDevices(): string[] {
|
|
45
60
|
return (
|
|
46
|
-
Array.from(
|
|
61
|
+
Array.from(deviceMap)
|
|
47
62
|
// @ts-expect-error
|
|
48
63
|
.filter(Device => Device.isSupported())
|
|
49
64
|
// @ts-expect-error
|
|
@@ -55,6 +70,39 @@ export class luma {
|
|
|
55
70
|
Object.assign(Device.defaultProps, props);
|
|
56
71
|
}
|
|
57
72
|
|
|
73
|
+
/** Attach to an existing GPU API handle (WebGL2RenderingContext or GPUDevice). */
|
|
74
|
+
static async attachDevice(props: AttachDeviceProps): Promise<Device> {
|
|
75
|
+
const devices = getDeviceMap(props.devices) || deviceMap;
|
|
76
|
+
|
|
77
|
+
// WebGL
|
|
78
|
+
if (props.handle instanceof WebGL2RenderingContext) {
|
|
79
|
+
const WebGLDevice = devices.get('webgl') as any;
|
|
80
|
+
if (WebGLDevice) {
|
|
81
|
+
return (await WebGLDevice.attach(props.handle)) as Device;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// TODO - WebGPU does not yet have a stable API
|
|
86
|
+
// if (props.handle instanceof GPUDevice) {
|
|
87
|
+
// const WebGPUDevice = devices.get('webgpu') as any;
|
|
88
|
+
// if (WebGPUDevice) {
|
|
89
|
+
// return (await WebGPUDevice.attach(props.handle)) as Device;
|
|
90
|
+
// }
|
|
91
|
+
// }
|
|
92
|
+
|
|
93
|
+
// null
|
|
94
|
+
if (props.handle === null) {
|
|
95
|
+
const UnknownDevice = devices.get('unknown') as any;
|
|
96
|
+
if (UnknownDevice) {
|
|
97
|
+
return (await UnknownDevice.attach(null)) as Device;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
throw new Error(
|
|
102
|
+
'Failed to attach device. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.'
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
58
106
|
/** Creates a device. Asynchronously. */
|
|
59
107
|
static async createDevice(props: CreateDeviceProps = {}): Promise<Device> {
|
|
60
108
|
props = {...Device.defaultProps, ...props};
|
|
@@ -62,28 +110,38 @@ export class luma {
|
|
|
62
110
|
props.type = 'webgl';
|
|
63
111
|
}
|
|
64
112
|
|
|
65
|
-
|
|
113
|
+
const devices = getDeviceMap(props.devices) || deviceMap;
|
|
114
|
+
|
|
66
115
|
switch (props.type) {
|
|
67
116
|
case 'webgpu':
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
return await
|
|
117
|
+
let WebGPUDevice = devices.get('webgpu') as any;
|
|
118
|
+
if (WebGPUDevice) {
|
|
119
|
+
return await WebGPUDevice.create(props);
|
|
71
120
|
}
|
|
72
121
|
break;
|
|
122
|
+
|
|
73
123
|
case 'webgl':
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
return await
|
|
124
|
+
let WebGLDevice = devices.get('webgl') as any;
|
|
125
|
+
if (WebGLDevice) {
|
|
126
|
+
return await WebGLDevice.create(props);
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
|
|
130
|
+
case 'unknown':
|
|
131
|
+
const UnknownDevice = devices.get('unknown') as any;
|
|
132
|
+
if (UnknownDevice) {
|
|
133
|
+
return await UnknownDevice.create(props);
|
|
77
134
|
}
|
|
78
135
|
break;
|
|
136
|
+
|
|
79
137
|
case 'best-available':
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
return await
|
|
138
|
+
WebGPUDevice = devices.get('webgpu') as any;
|
|
139
|
+
if (WebGPUDevice?.isSupported?.()) {
|
|
140
|
+
return await WebGPUDevice.create(props);
|
|
83
141
|
}
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
return await
|
|
142
|
+
WebGLDevice = devices.get('webgl');
|
|
143
|
+
if (WebGLDevice?.isSupported?.()) {
|
|
144
|
+
return await WebGLDevice.create(props);
|
|
87
145
|
}
|
|
88
146
|
break;
|
|
89
147
|
}
|
|
@@ -92,3 +150,18 @@ export class luma {
|
|
|
92
150
|
);
|
|
93
151
|
}
|
|
94
152
|
}
|
|
153
|
+
|
|
154
|
+
/** Convert a list of devices to a map */
|
|
155
|
+
function getDeviceMap(
|
|
156
|
+
deviceClasses?: any[] /* : typeof Device */
|
|
157
|
+
): Map<string, typeof Device> | null {
|
|
158
|
+
if (!deviceClasses || deviceClasses?.length === 0) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const map = new Map<string, typeof Device>();
|
|
162
|
+
for (const deviceClass of deviceClasses) {
|
|
163
|
+
// assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
|
|
164
|
+
map.set(deviceClass.type, deviceClass);
|
|
165
|
+
}
|
|
166
|
+
return map;
|
|
167
|
+
}
|