@luma.gl/webgl 9.0.0-alpha.10 → 9.0.0-alpha.11
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/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +1 -3
- package/dist/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +33 -27
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +32 -24
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/context/context/context-state.d.ts +0 -5
- package/dist/context/context/context-state.d.ts.map +1 -1
- package/dist/context/context/context-state.js +0 -5
- package/dist/context/context/context-state.js.map +1 -1
- package/dist/es5/adapter/webgl-canvas-context.js +1 -4
- package/dist/es5/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/es5/adapter/webgl-device.js +34 -24
- package/dist/es5/adapter/webgl-device.js.map +1 -1
- package/dist/es5/context/context/context-state.js +0 -5
- package/dist/es5/context/context/context-state.js.map +1 -1
- package/dist/es5/index.js +0 -14
- package/dist/es5/index.js.map +1 -1
- package/dist/esm/adapter/webgl-canvas-context.js +1 -3
- package/dist/esm/adapter/webgl-canvas-context.js.map +1 -1
- package/dist/esm/adapter/webgl-device.js +32 -24
- package/dist/esm/adapter/webgl-device.js.map +1 -1
- package/dist/esm/context/context/context-state.js +0 -5
- package/dist/esm/context/context/context-state.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/webgl-canvas-context.ts +1 -3
- package/src/adapter/webgl-device.ts +60 -48
- package/src/context/context/context-state.ts +0 -10
- package/src/index.ts +0 -3
- 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/device-pixels.js +0 -121
- package/dist/es5/context/context/device-pixels.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/device-pixels.ts +0 -158
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgl-canvas-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"webgl-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgl-canvas-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAC;AAC3C,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,OAAO,gBAAgB,MAAM,+BAA+B,CAAC;AAE7D;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,aAAa;IAC3D,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,OAAO,CAAC,YAAY,CAAiC;gBAEzC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,kBAAkB;IAQ1D,qBAAqB,IAAI,gBAAgB;IAMzC,sDAAsD;IACtD,MAAM;IAQN;;;;;;;;;;;OAWG;IACF,MAAM,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAC,GAAG,IAAI;IAc9F,MAAM;CAOP"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { CanvasContext } from '@luma.gl/api';
|
|
3
|
-
import { getDevicePixelRatio, setDevicePixelRatio } from '../context/context/device-pixels';
|
|
4
3
|
import WEBGLFramebuffer from './resources/webgl-framebuffer';
|
|
5
4
|
export default class WebGLCanvasContext extends CanvasContext {
|
|
6
5
|
constructor(device, props) {
|
|
@@ -36,8 +35,7 @@ export default class WebGLCanvasContext extends CanvasContext {
|
|
|
36
35
|
|
|
37
36
|
resize(options) {
|
|
38
37
|
if (this.canvas) {
|
|
39
|
-
|
|
40
|
-
setDevicePixelRatio(this.device.gl, devicePixelRatio, options);
|
|
38
|
+
this.setDevicePixelRatio(devicePixelRatio, options);
|
|
41
39
|
return;
|
|
42
40
|
}
|
|
43
41
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adapter/webgl-canvas-context.ts"],"names":["CanvasContext","
|
|
1
|
+
{"version":3,"sources":["../../src/adapter/webgl-canvas-context.ts"],"names":["CanvasContext","WEBGLFramebuffer","WebGLCanvasContext","constructor","device","props","presentationSize","update","getCurrentFramebuffer","_framebuffer","handle","size","getPixelSize","sizeChanged","resize","options","canvas","setDevicePixelRatio","devicePixelRatio","ext","gl","getExtension","width","height","commit"],"mappings":";AAEA,SAAQA,aAAR,QAA4B,cAA5B;AAEA,OAAOC,gBAAP,MAA6B,+BAA7B;AAMA,eAAe,MAAMC,kBAAN,SAAiCF,aAAjC,CAA+C;AAK5DG,EAAAA,WAAW,CAACC,MAAD,EAAsBC,KAAtB,EAAiD;AAE1D,UAAMA,KAAN;;AAF0D;;AAAA;;AAAA,0CAFZ,IAEY;;AAG1D,SAAKD,MAAL,GAAcA,MAAd;AACA,SAAKE,gBAAL,GAAwB,CAAC,CAAC,CAAF,EAAK,CAAC,CAAN,CAAxB;AACA,SAAKC,MAAL;AACD;;AAEDC,EAAAA,qBAAqB,GAAqB;AACxC,SAAKD,MAAL;AACA,SAAKE,YAAL,GAAoB,KAAKA,YAAL,IAAqB,IAAIR,gBAAJ,CAAqB,KAAKG,MAA1B,EAAkC;AAACM,MAAAA,MAAM,EAAE;AAAT,KAAlC,CAAzC;AACA,WAAO,KAAKD,YAAZ;AACD;;AAGDF,EAAAA,MAAM,GAAG;AACP,UAAMI,IAAI,GAAG,KAAKC,YAAL,EAAb;AACA,UAAMC,WAAW,GAAGF,IAAI,CAAC,CAAD,CAAJ,KAAY,KAAKL,gBAAL,CAAsB,CAAtB,CAAZ,IAAwCK,IAAI,CAAC,CAAD,CAAJ,KAAY,KAAKL,gBAAL,CAAsB,CAAtB,CAAxE;;AACA,QAAIO,WAAJ,EAAiB;AACf,WAAKP,gBAAL,GAAwBK,IAAxB;AACD;AACF;;AAcAG,EAAAA,MAAM,CAACC,OAAD,EAAwF;AAE7F,QAAI,KAAKC,MAAT,EAAiB;AACf,WAAKC,mBAAL,CAAyBC,gBAAzB,EAA2CH,OAA3C;AACA;AACD;;AAGD,UAAMI,GAAG,GAAG,KAAKf,MAAL,CAAYgB,EAAZ,CAAeC,YAAf,CAA4B,8BAA5B,CAAZ;;AACA,QAAIF,GAAG,IAAIJ,OAAP,IAAkB,WAAWA,OAA7B,IAAwC,YAAYA,OAAxD,EAAiE;AAC/DI,MAAAA,GAAG,CAACL,MAAJ,CAAWC,OAAO,CAACO,KAAnB,EAA0BP,OAAO,CAACQ,MAAlC;AACD;AACF;;AAEDC,EAAAA,MAAM,GAAG,CAMR;;AA5D2D","sourcesContent":["// luma.gl, MIT license\nimport type {CanvasContextProps} from '@luma.gl/api';\nimport {CanvasContext} from '@luma.gl/api';\nimport WebGLDevice from './webgl-device';\nimport WEBGLFramebuffer from './resources/webgl-framebuffer';\n\n/** \n * Holds a WebGL Canvas Context which will handle drawing buffer resizing etc \n * @todo This class is WIP, intended to replace the old gltools-based context size tracking\n */\nexport default class WebGLCanvasContext extends CanvasContext {\n readonly device: WebGLDevice;\n presentationSize: [number, number];\n private _framebuffer: WEBGLFramebuffer | null = null;\n\n constructor(device: WebGLDevice, props: CanvasContextProps) {\n // Note: Base class creates / looks up the canvas (unless under Node.js)\n super(props);\n this.device = device;\n this.presentationSize = [-1, -1];\n this.update();\n }\n\n getCurrentFramebuffer(): WEBGLFramebuffer {\n this.update();\n this._framebuffer = this._framebuffer || new WEBGLFramebuffer(this.device, {handle: null});\n return this._framebuffer;\n }\n\n /** Resizes and updates render targets if necessary */\n update() {\n const size = this.getPixelSize();\n const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];\n if (sizeChanged) {\n this.presentationSize = size;\n }\n }\n\n /**\n * Resize the canvas' drawing buffer.\n *\n * Can match the canvas CSS size, and optionally also consider devicePixelRatio\n * Can be called every frame\n *\n * Regardless of size, the drawing buffer will always be scaled to the viewport, but\n * for best visual results, usually set to either:\n * canvas CSS width x canvas CSS height\n * canvas CSS width * devicePixelRatio x canvas CSS height * devicePixelRatio\n * See http://webgl2fundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n */\n resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {\n // Resize browser context .\n if (this.canvas) {\n this.setDevicePixelRatio(devicePixelRatio, options);\n return;\n }\n\n // Resize headless gl context\n const ext = this.device.gl.getExtension('STACKGL_resize_drawingbuffer');\n if (ext && options && `width` in options && `height` in options) {\n ext.resize(options.width, options.height);\n }\n }\n\n commit() {\n // gl.commit was ultimately removed from standard??\n // if (this.offScreen && this.gl.commit) {\n // // @ts-expect-error gl.commit is not officially part of WebGLRenderingContext\n // this.gl.commit();\n // }\n }\n}\n"],"file":"webgl-canvas-context.js"}
|
|
@@ -27,28 +27,6 @@ export default class WebGLDevice extends Device implements ContextState {
|
|
|
27
27
|
private _resolveContextLost?;
|
|
28
28
|
private _features?;
|
|
29
29
|
private _limits?;
|
|
30
|
-
/** WebGL1 typed context. Can always be used. */
|
|
31
|
-
readonly gl: WebGLRenderingContext;
|
|
32
|
-
/** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */
|
|
33
|
-
readonly gl2: WebGL2RenderingContext | null;
|
|
34
|
-
readonly debug: boolean;
|
|
35
|
-
/** `true` if this is a WebGL1 context. @note `false` if WebGL2 */
|
|
36
|
-
readonly isWebGL1: boolean;
|
|
37
|
-
/** `true` if this is a WebGL2 context. @note `false` if WebGL1 */
|
|
38
|
-
readonly isWebGL2: boolean;
|
|
39
|
-
get webglLimits(): WebGLLimits;
|
|
40
|
-
private _webglLimits?;
|
|
41
|
-
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
42
|
-
readonly _canvasSizeInfo: {
|
|
43
|
-
clientWidth: number;
|
|
44
|
-
clientHeight: number;
|
|
45
|
-
devicePixelRatio: number;
|
|
46
|
-
};
|
|
47
|
-
/** State used by luma.gl classes */
|
|
48
|
-
readonly _extensions: Record<string, any>;
|
|
49
|
-
_polyfilled: boolean;
|
|
50
|
-
/** Instance of Spector.js (if initialized) */
|
|
51
|
-
spector: any;
|
|
52
30
|
/**
|
|
53
31
|
* Get a device instance from a GL context
|
|
54
32
|
* Creates and instruments the device if not already created
|
|
@@ -63,11 +41,6 @@ export default class WebGLDevice extends Device implements ContextState {
|
|
|
63
41
|
* @note Has no effect for browser contexts, there is no browser API for destroying contexts
|
|
64
42
|
*/
|
|
65
43
|
destroy(): void;
|
|
66
|
-
/**
|
|
67
|
-
* Loses the context
|
|
68
|
-
* @note Triggers context loss, mainly for testing
|
|
69
|
-
*/
|
|
70
|
-
loseDevice(): void;
|
|
71
44
|
get isLost(): boolean;
|
|
72
45
|
getSize(): [number, number];
|
|
73
46
|
isTextureFormatSupported(format: TextureFormat): boolean;
|
|
@@ -94,5 +67,38 @@ export default class WebGLDevice extends Device implements ContextState {
|
|
|
94
67
|
* Chrome's offscreen canvas does not require gl.commit
|
|
95
68
|
*/
|
|
96
69
|
submit(): void;
|
|
70
|
+
/** WebGL1 typed context. Can always be used. */
|
|
71
|
+
readonly gl: WebGLRenderingContext;
|
|
72
|
+
/** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */
|
|
73
|
+
readonly gl2: WebGL2RenderingContext | null;
|
|
74
|
+
readonly debug: boolean;
|
|
75
|
+
/** `true` if this is a WebGL1 context. @note `false` if WebGL2 */
|
|
76
|
+
readonly isWebGL1: boolean;
|
|
77
|
+
/** `true` if this is a WebGL2 context. @note `false` if WebGL1 */
|
|
78
|
+
readonly isWebGL2: boolean;
|
|
79
|
+
/** State used by luma.gl classes: TODO - move to canvasContext*/
|
|
80
|
+
readonly _canvasSizeInfo: {
|
|
81
|
+
clientWidth: number;
|
|
82
|
+
clientHeight: number;
|
|
83
|
+
devicePixelRatio: number;
|
|
84
|
+
};
|
|
85
|
+
/** State used by luma.gl classes */
|
|
86
|
+
readonly _extensions: Record<string, any>;
|
|
87
|
+
_polyfilled: boolean;
|
|
88
|
+
/** Instance of Spector.js (if initialized) */
|
|
89
|
+
spector: any;
|
|
90
|
+
private _webglLimits?;
|
|
91
|
+
/** Return WebGL specific limits */
|
|
92
|
+
get webglLimits(): WebGLLimits;
|
|
93
|
+
/**
|
|
94
|
+
* Loses the context
|
|
95
|
+
* @note Triggers context loss, mainly for testing
|
|
96
|
+
* @todo Promote to `Device` API?
|
|
97
|
+
*/
|
|
98
|
+
loseDevice(): void;
|
|
99
|
+
/** Save current WebGL context state onto an internal stack */
|
|
100
|
+
pushState(): void;
|
|
101
|
+
/** Restores previously saved context state */
|
|
102
|
+
popState(): void;
|
|
97
103
|
}
|
|
98
104
|
//# sourceMappingURL=webgl-device.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-device.d.ts","sourceRoot":"","sources":["../../src/adapter/webgl-device.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,MAAM,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I5D,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,GAAG,mBAAmB;IAIrE,eAAe,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe;IAIxD,qBAAqB,CAAC,KAAK,CAAC,EAAE,oBAAoB,GAAG,eAAe;IAIpE,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,WAAW;IAItD,OAAO,CAAC,UAAU,CAAgC;IAElD,oBAAoB,IAAI,eAAe;IASvC;;;;OAIG;IACH,MAAM,IAAI,IAAI;IAUd,gDAAgD;IAChD,QAAQ,CAAC,EAAE,EAAE,qBAAqB,CAAC;IACnC,6EAA6E;IAC7E,QAAQ,CAAC,GAAG,EAAE,sBAAsB,GAAG,IAAI,CAAQ;IACnD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAS;IAEhC,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B,iEAAiE;IACjE,QAAQ,CAAC,eAAe;;;;MAA0D;IAClF,oCAAoC;IACpC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;IAC/C,WAAW,EAAE,OAAO,CAAS;IAE7B,8CAA8C;IAC9C,OAAO,MAAC;IAER,OAAO,CAAC,YAAY,CAAC,CAAc;IAEnC,mCAAmC;IACnC,IAAI,WAAW,IAAK,WAAW,CAG9B;IAED;;;;OAIG;IACF,UAAU,IAAI,IAAI;IAYnB,8DAA8D;IAC9D,SAAS,IAAI,IAAI;IAIjB,8CAA8C;IAC9C,QAAQ,IAAI,IAAI;CAGjB"}
|
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
2
2
|
import { Device, CanvasContext, log } from '@luma.gl/api';
|
|
3
3
|
import { isBrowser } from '@probe.gl/env';
|
|
4
4
|
import { polyfillContext } from '../context/polyfill/polyfill-context';
|
|
5
|
-
import { trackContextState } from '../context/state-tracker/track-context-state';
|
|
5
|
+
import { popContextState, pushContextState, trackContextState } from '../context/state-tracker/track-context-state';
|
|
6
6
|
import { createBrowserContext } from '../context/context/create-browser-context';
|
|
7
7
|
import { createHeadlessContext, isHeadlessGLRegistered } from '../context/context/create-headless-context';
|
|
8
8
|
import { getDeviceInfo } from './device-helpers/get-device-info';
|
|
@@ -36,11 +36,6 @@ export default class WebGLDevice extends Device {
|
|
|
36
36
|
return this._limits;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
get webglLimits() {
|
|
40
|
-
this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
|
|
41
|
-
return this._webglLimits;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
39
|
static attach(gl) {
|
|
45
40
|
if (gl instanceof WebGLDevice) {
|
|
46
41
|
return gl;
|
|
@@ -102,6 +97,8 @@ export default class WebGLDevice extends Device {
|
|
|
102
97
|
|
|
103
98
|
_defineProperty(this, "_limits", void 0);
|
|
104
99
|
|
|
100
|
+
_defineProperty(this, "renderPass", null);
|
|
101
|
+
|
|
105
102
|
_defineProperty(this, "gl", void 0);
|
|
106
103
|
|
|
107
104
|
_defineProperty(this, "gl2", null);
|
|
@@ -112,8 +109,6 @@ export default class WebGLDevice extends Device {
|
|
|
112
109
|
|
|
113
110
|
_defineProperty(this, "isWebGL2", void 0);
|
|
114
111
|
|
|
115
|
-
_defineProperty(this, "_webglLimits", void 0);
|
|
116
|
-
|
|
117
112
|
_defineProperty(this, "_canvasSizeInfo", {
|
|
118
113
|
clientWidth: 0,
|
|
119
114
|
clientHeight: 0,
|
|
@@ -126,7 +121,7 @@ export default class WebGLDevice extends Device {
|
|
|
126
121
|
|
|
127
122
|
_defineProperty(this, "spector", void 0);
|
|
128
123
|
|
|
129
|
-
_defineProperty(this, "
|
|
124
|
+
_defineProperty(this, "_webglLimits", void 0);
|
|
130
125
|
|
|
131
126
|
const device = (_props$gl = props.gl) === null || _props$gl === void 0 ? void 0 : _props$gl.device;
|
|
132
127
|
|
|
@@ -210,21 +205,6 @@ export default class WebGLDevice extends Device {
|
|
|
210
205
|
}
|
|
211
206
|
}
|
|
212
207
|
|
|
213
|
-
loseDevice() {
|
|
214
|
-
var _this$_resolveContext2;
|
|
215
|
-
|
|
216
|
-
const ext = this.gl.getExtension('WEBGL_lose_context');
|
|
217
|
-
|
|
218
|
-
if (ext) {
|
|
219
|
-
ext.loseContext();
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
(_this$_resolveContext2 = this._resolveContextLost) === null || _this$_resolveContext2 === void 0 ? void 0 : _this$_resolveContext2.call(this, {
|
|
223
|
-
reason: 'destroyed',
|
|
224
|
-
message: 'Application triggered context loss'
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
208
|
get isLost() {
|
|
229
209
|
return this.gl.isContextLost();
|
|
230
210
|
}
|
|
@@ -311,6 +291,34 @@ export default class WebGLDevice extends Device {
|
|
|
311
291
|
this.renderPass = null;
|
|
312
292
|
}
|
|
313
293
|
|
|
294
|
+
get webglLimits() {
|
|
295
|
+
this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
|
|
296
|
+
return this._webglLimits;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
loseDevice() {
|
|
300
|
+
var _this$_resolveContext2;
|
|
301
|
+
|
|
302
|
+
const ext = this.gl.getExtension('WEBGL_lose_context');
|
|
303
|
+
|
|
304
|
+
if (ext) {
|
|
305
|
+
ext.loseContext();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
(_this$_resolveContext2 = this._resolveContextLost) === null || _this$_resolveContext2 === void 0 ? void 0 : _this$_resolveContext2.call(this, {
|
|
309
|
+
reason: 'destroyed',
|
|
310
|
+
message: 'Application triggered context loss'
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
pushState() {
|
|
315
|
+
pushContextState(this.gl);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
popState() {
|
|
319
|
+
popContextState(this.gl);
|
|
320
|
+
}
|
|
321
|
+
|
|
314
322
|
}
|
|
315
323
|
|
|
316
324
|
_defineProperty(WebGLDevice, "type", 'webgl');
|
|
@@ -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,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;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","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","counter","WebGLDevice","isSupported","WebGLRenderingContext","features","_features","gl","limits","_limits","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","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,QAAiD,cAAjD;AACA,SAAQC,SAAR,QAAwB,eAAxB;AACA,SAAQC,eAAR,QAA8B,sCAA9B;AACA,SAAQC,eAAR,EAAyBC,gBAAzB,EAA2CC,iBAA3C,QAAmE,8CAAnE;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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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 {popContextState, pushContextState, 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 // 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 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 /** 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 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"}
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
* Stores luma.gl specific state associated with a context
|
|
3
3
|
*/
|
|
4
4
|
export interface ContextState {
|
|
5
|
-
_canvasSizeInfo: {
|
|
6
|
-
clientWidth: number;
|
|
7
|
-
clientHeight: number;
|
|
8
|
-
devicePixelRatio: number;
|
|
9
|
-
};
|
|
10
5
|
_polyfilled: boolean;
|
|
11
6
|
_extensions: Record<string, any>;
|
|
12
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-state.d.ts","sourceRoot":"","sources":["../../../src/context/context/context-state.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,
|
|
1
|
+
{"version":3,"file":"context-state.d.ts","sourceRoot":"","sources":["../../../src/context/context/context-state.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,qBAAqB,GAAG,YAAY,CAkBvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/context/context-state.ts"],"names":["getContextState","gl","device","luma","contextState","
|
|
1
|
+
{"version":3,"sources":["../../../src/context/context/context-state.ts"],"names":["getContextState","gl","device","luma","contextState","_polyfilled","_extensions","Error"],"mappings":"AAYA,OAAO,SAASA,eAAT,CAAyBC,EAAzB,EAAkE;AAEvE,QAAM;AAACC,IAAAA,MAAD;AAASC,IAAAA;AAAT,MAAiBF,EAAvB;;AACA,MAAIC,MAAJ,EAAY;AACV,WAAOA,MAAP;AACD;;AACD,MAAI,CAACC,IAAL,EAAW;AACT,UAAMC,YAA0B,GAAG;AACjCC,MAAAA,WAAW,EAAE,KADoB;AAEjCC,MAAAA,WAAW,EAAE;AAFoB,KAAnC;AAKAL,IAAAA,EAAE,CAACE,IAAH,GAAUC,YAAV;AACD;;AACD,QAAM,IAAIG,KAAJ,CAAU,8BAAV,CAAN;AAID","sourcesContent":["/**\n * Stores luma.gl specific state associated with a context\n */\nexport interface ContextState {\n _polyfilled: boolean;\n _extensions: Record<string, any>;\n}\n\n/**\n * Gets luma.gl specific state from a context\n * @returns context state\n */\nexport function getContextState(gl: WebGLRenderingContext): ContextState {\n // @ts-expect-error\n const {device, luma} = gl;\n if (device) {\n return device as ContextState;\n }\n if (!luma) {\n const contextState: ContextState = {\n _polyfilled: false,\n _extensions: {}\n };\n // @ts-expect-error\n gl.luma = contextState;\n }\n throw new Error('context state without device');\n\n // // @ts-expect-error\n // return gl.luma;\n}\n"],"file":"context-state.js"}
|
|
@@ -23,8 +23,6 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
23
23
|
|
|
24
24
|
var _api = require("@luma.gl/api");
|
|
25
25
|
|
|
26
|
-
var _devicePixels = require("../context/context/device-pixels");
|
|
27
|
-
|
|
28
26
|
var _webglFramebuffer = _interopRequireDefault(require("./resources/webgl-framebuffer"));
|
|
29
27
|
|
|
30
28
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
@@ -75,8 +73,7 @@ var WebGLCanvasContext = function (_CanvasContext) {
|
|
|
75
73
|
key: "resize",
|
|
76
74
|
value: function resize(options) {
|
|
77
75
|
if (this.canvas) {
|
|
78
|
-
|
|
79
|
-
(0, _devicePixels.setDevicePixelRatio)(this.device.gl, devicePixelRatio, options);
|
|
76
|
+
this.setDevicePixelRatio(devicePixelRatio, options);
|
|
80
77
|
return;
|
|
81
78
|
}
|
|
82
79
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapter/webgl-canvas-context.ts"],"names":["WebGLCanvasContext","device","props","presentationSize","update","_framebuffer","WEBGLFramebuffer","handle","size","getPixelSize","sizeChanged","options","canvas","
|
|
1
|
+
{"version":3,"sources":["../../../src/adapter/webgl-canvas-context.ts"],"names":["WebGLCanvasContext","device","props","presentationSize","update","_framebuffer","WEBGLFramebuffer","handle","size","getPixelSize","sizeChanged","options","canvas","setDevicePixelRatio","devicePixelRatio","ext","gl","getExtension","resize","width","height","CanvasContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA;;AAEA;;;;;;IAMqBA,kB;;;;;AAKnB,8BAAYC,MAAZ,EAAiCC,KAAjC,EA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nimport WebGLDevice from './webgl-device';\nimport WEBGLFramebuffer from './resources/webgl-framebuffer';\n\n/** \n * Holds a WebGL Canvas Context which will handle drawing buffer resizing etc \n * @todo This class is WIP, intended to replace the old gltools-based context size tracking\n */\nexport default class WebGLCanvasContext extends CanvasContext {\n readonly device: WebGLDevice;\n presentationSize: [number, number];\n private _framebuffer: WEBGLFramebuffer | null = null;\n\n constructor(device: WebGLDevice, props: CanvasContextProps) {\n // Note: Base class creates / looks up the canvas (unless under Node.js)\n super(props);\n this.device = device;\n this.presentationSize = [-1, -1];\n this.update();\n }\n\n getCurrentFramebuffer(): WEBGLFramebuffer {\n this.update();\n this._framebuffer = this._framebuffer || new WEBGLFramebuffer(this.device, {handle: null});\n return this._framebuffer;\n }\n\n /** Resizes and updates render targets if necessary */\n update() {\n const size = this.getPixelSize();\n const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];\n if (sizeChanged) {\n this.presentationSize = size;\n }\n }\n\n /**\n * Resize the canvas' drawing buffer.\n *\n * Can match the canvas CSS size, and optionally also consider devicePixelRatio\n * Can be called every frame\n *\n * Regardless of size, the drawing buffer will always be scaled to the viewport, but\n * for best visual results, usually set to either:\n * canvas CSS width x canvas CSS height\n * canvas CSS width * devicePixelRatio x canvas CSS height * devicePixelRatio\n * See http://webgl2fundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n */\n resize(options?: {width?: number; height?: number; useDevicePixels?: boolean | number}): void {\n // Resize browser context .\n if (this.canvas) {\n this.setDevicePixelRatio(devicePixelRatio, options);\n return;\n }\n\n // Resize headless gl context\n const ext = this.device.gl.getExtension('STACKGL_resize_drawingbuffer');\n if (ext && options && `width` in options && `height` in options) {\n ext.resize(options.width, options.height);\n }\n }\n\n commit() {\n // gl.commit was ultimately removed from standard??\n // if (this.offScreen && this.gl.commit) {\n // // @ts-expect-error gl.commit is not officially part of WebGLRenderingContext\n // this.gl.commit();\n // }\n }\n}\n"],"file":"webgl-canvas-context.js"}
|
|
@@ -95,12 +95,12 @@ var WebGLDevice = function (_Device) {
|
|
|
95
95
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_resolveContextLost", void 0);
|
|
96
96
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_features", void 0);
|
|
97
97
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_limits", void 0);
|
|
98
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderPass", null);
|
|
98
99
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "gl", void 0);
|
|
99
100
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "gl2", null);
|
|
100
101
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "debug", false);
|
|
101
102
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isWebGL1", void 0);
|
|
102
103
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isWebGL2", void 0);
|
|
103
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_webglLimits", void 0);
|
|
104
104
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_canvasSizeInfo", {
|
|
105
105
|
clientWidth: 0,
|
|
106
106
|
clientHeight: 0,
|
|
@@ -109,7 +109,7 @@ var WebGLDevice = function (_Device) {
|
|
|
109
109
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_extensions", {});
|
|
110
110
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_polyfilled", false);
|
|
111
111
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "spector", void 0);
|
|
112
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
112
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_webglLimits", void 0);
|
|
113
113
|
var device = (_props$gl = props.gl) === null || _props$gl === void 0 ? void 0 : _props$gl.device;
|
|
114
114
|
|
|
115
115
|
if (device) {
|
|
@@ -207,12 +207,6 @@ var WebGLDevice = function (_Device) {
|
|
|
207
207
|
this._limits = this._limits || (0, _deviceLimits.getDeviceLimits)(this.gl);
|
|
208
208
|
return this._limits;
|
|
209
209
|
}
|
|
210
|
-
}, {
|
|
211
|
-
key: "webglLimits",
|
|
212
|
-
get: function get() {
|
|
213
|
-
this._webglLimits = this._webglLimits || (0, _deviceLimits.getWebGLLimits)(this.gl);
|
|
214
|
-
return this._webglLimits;
|
|
215
|
-
}
|
|
216
210
|
}, {
|
|
217
211
|
key: "destroy",
|
|
218
212
|
value: function destroy() {
|
|
@@ -222,22 +216,6 @@ var WebGLDevice = function (_Device) {
|
|
|
222
216
|
ext.destroy();
|
|
223
217
|
}
|
|
224
218
|
}
|
|
225
|
-
}, {
|
|
226
|
-
key: "loseDevice",
|
|
227
|
-
value: function loseDevice() {
|
|
228
|
-
var _this$_resolveContext2;
|
|
229
|
-
|
|
230
|
-
var ext = this.gl.getExtension('WEBGL_lose_context');
|
|
231
|
-
|
|
232
|
-
if (ext) {
|
|
233
|
-
ext.loseContext();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
(_this$_resolveContext2 = this._resolveContextLost) === null || _this$_resolveContext2 === void 0 ? void 0 : _this$_resolveContext2.call(this, {
|
|
237
|
-
reason: 'destroyed',
|
|
238
|
-
message: 'Application triggered context loss'
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
219
|
}, {
|
|
242
220
|
key: "isLost",
|
|
243
221
|
get: function get() {
|
|
@@ -343,6 +321,38 @@ var WebGLDevice = function (_Device) {
|
|
|
343
321
|
(_this$renderPass = this.renderPass) === null || _this$renderPass === void 0 ? void 0 : _this$renderPass.endPass();
|
|
344
322
|
this.renderPass = null;
|
|
345
323
|
}
|
|
324
|
+
}, {
|
|
325
|
+
key: "webglLimits",
|
|
326
|
+
get: function get() {
|
|
327
|
+
this._webglLimits = this._webglLimits || (0, _deviceLimits.getWebGLLimits)(this.gl);
|
|
328
|
+
return this._webglLimits;
|
|
329
|
+
}
|
|
330
|
+
}, {
|
|
331
|
+
key: "loseDevice",
|
|
332
|
+
value: function loseDevice() {
|
|
333
|
+
var _this$_resolveContext2;
|
|
334
|
+
|
|
335
|
+
var ext = this.gl.getExtension('WEBGL_lose_context');
|
|
336
|
+
|
|
337
|
+
if (ext) {
|
|
338
|
+
ext.loseContext();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
(_this$_resolveContext2 = this._resolveContextLost) === null || _this$_resolveContext2 === void 0 ? void 0 : _this$_resolveContext2.call(this, {
|
|
342
|
+
reason: 'destroyed',
|
|
343
|
+
message: 'Application triggered context loss'
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}, {
|
|
347
|
+
key: "pushState",
|
|
348
|
+
value: function pushState() {
|
|
349
|
+
(0, _trackContextState.pushContextState)(this.gl);
|
|
350
|
+
}
|
|
351
|
+
}, {
|
|
352
|
+
key: "popState",
|
|
353
|
+
value: function popState() {
|
|
354
|
+
(0, _trackContextState.popContextState)(this.gl);
|
|
355
|
+
}
|
|
346
356
|
}], [{
|
|
347
357
|
key: "isSupported",
|
|
348
358
|
value: function isSupported() {
|