@luma.gl/webgl 9.0.11 → 9.1.0-alpha.1
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/LICENSE +34 -0
- package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
- package/dist/adapter/converters/device-parameters.js +12 -1
- package/dist/adapter/converters/texture-formats.d.ts +22 -16
- package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
- package/dist/adapter/converters/texture-formats.js +31 -32
- package/dist/adapter/device-helpers/webgl-device-features.js +1 -1
- package/dist/adapter/device-helpers/webgl-device-limits.js +1 -1
- package/dist/adapter/helpers/webgl-texture-utils.d.ts +300 -0
- package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -0
- package/dist/adapter/helpers/webgl-texture-utils.js +368 -0
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +0 -4
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +2 -2
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +6 -9
- package/dist/adapter/resources/webgl-framebuffer.d.ts +32 -5
- package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-framebuffer.js +42 -60
- package/dist/adapter/resources/webgl-render-pass.d.ts +3 -2
- package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +1 -3
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +45 -20
- package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-shader.js +2 -2
- package/dist/adapter/resources/webgl-texture-view.d.ts +1 -1
- package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture-view.js +1 -1
- package/dist/adapter/resources/webgl-texture.d.ts +58 -172
- package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-texture.js +402 -510
- package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -2
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +2 -2
- package/dist/adapter/webgl-canvas-context.d.ts +3 -1
- package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
- package/dist/adapter/webgl-canvas-context.js +2 -0
- package/dist/adapter/webgl-device.d.ts +4 -3
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +6 -5
- package/dist/classic/accessor.d.ts +22 -1
- package/dist/classic/accessor.d.ts.map +1 -1
- package/dist/classic/accessor.js +1 -9
- package/dist/classic/clear.d.ts.map +1 -1
- package/dist/classic/clear.js +2 -5
- package/dist/classic/copy-and-blit.d.ts +2 -1
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +11 -9
- package/dist/classic/format-utils.d.ts.map +1 -1
- package/dist/classic/format-utils.js +0 -3
- package/dist/classic/typed-array-utils.d.ts +1 -1
- package/dist/classic/typed-array-utils.d.ts.map +1 -1
- package/dist/context/debug/spector.d.ts.map +1 -1
- package/dist/context/debug/spector.js +2 -1
- package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
- package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
- package/dist/context/debug/webgl-developer-tools.js +2 -5
- package/dist/context/parameters/webgl-parameter-tables.js +1 -1
- package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
- package/dist/context/state-tracker/track-context-state.js +5 -6
- package/dist/dist.dev.js +870 -1261
- package/dist/dist.min.js +2 -2
- package/dist/index.cjs +859 -1137
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/utils/fill-array.d.ts +8 -0
- package/dist/utils/fill-array.d.ts.map +1 -0
- package/dist/utils/fill-array.js +26 -0
- package/dist/utils/load-script.d.ts +8 -0
- package/dist/utils/load-script.d.ts.map +1 -0
- package/dist/utils/load-script.js +26 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts +9 -0
- package/dist/utils/split-uniforms-and-bindings.d.ts.map +1 -0
- package/dist/utils/split-uniforms-and-bindings.js +20 -0
- package/package.json +6 -5
- package/src/adapter/converters/device-parameters.ts +13 -1
- package/src/adapter/converters/texture-formats.ts +45 -42
- package/src/adapter/device-helpers/webgl-device-features.ts +1 -1
- package/src/adapter/device-helpers/webgl-device-limits.ts +1 -1
- package/src/adapter/helpers/webgl-texture-utils.ts +481 -0
- package/src/adapter/helpers/webgl-topology-utils.ts +0 -4
- package/src/adapter/resources/webgl-buffer.ts +2 -2
- package/src/adapter/resources/webgl-command-buffer.ts +8 -10
- package/src/adapter/resources/webgl-framebuffer.ts +22 -56
- package/src/adapter/resources/webgl-render-pass.ts +4 -5
- package/src/adapter/resources/webgl-render-pipeline.ts +48 -23
- package/src/adapter/resources/webgl-shader.ts +3 -3
- package/src/adapter/resources/webgl-texture-view.ts +1 -3
- package/src/adapter/resources/webgl-texture.ts +432 -784
- package/src/adapter/resources/webgl-vertex-array.ts +8 -7
- package/src/adapter/webgl-canvas-context.ts +4 -1
- package/src/adapter/webgl-device.ts +10 -18
- package/src/classic/accessor.ts +31 -11
- package/src/classic/clear.ts +3 -6
- package/src/classic/copy-and-blit.ts +19 -19
- package/src/classic/format-utils.ts +0 -3
- package/src/classic/typed-array-utils.ts +1 -1
- package/src/context/debug/spector.ts +2 -1
- package/src/context/debug/webgl-developer-tools.ts +3 -7
- package/src/context/parameters/webgl-parameter-tables.ts +3 -3
- package/src/context/state-tracker/track-context-state.ts +5 -6
- package/src/index.ts +0 -6
- package/src/utils/fill-array.ts +35 -0
- package/src/utils/load-script.ts +30 -0
- package/src/utils/split-uniforms-and-bindings.ts +31 -0
- package/dist/adapter/objects/constants-to-keys.d.ts +0 -3
- package/dist/adapter/objects/constants-to-keys.d.ts.map +0 -1
- package/dist/adapter/objects/constants-to-keys.js +0 -22
- package/dist/adapter/objects/webgl-renderbuffer.d.ts +0 -43
- package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-renderbuffer.js +0 -95
- package/dist/adapter/objects/webgl-resource.d.ts +0 -32
- package/dist/adapter/objects/webgl-resource.d.ts.map +0 -1
- package/dist/adapter/objects/webgl-resource.js +0 -114
- package/src/adapter/objects/constants-to-keys.ts +0 -27
- package/src/adapter/objects/webgl-renderbuffer.ts +0 -132
- package/src/adapter/objects/webgl-resource.ts +0 -183
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { ResourceProps, TextureFormat } from '@luma.gl/core';
|
|
2
|
-
import { GL } from '@luma.gl/constants';
|
|
3
|
-
import { WebGLDevice } from "../webgl-device.js";
|
|
4
|
-
import { WebGLResource } from "./webgl-resource.js";
|
|
5
|
-
export type RenderbufferProps = ResourceProps & {
|
|
6
|
-
format: TextureFormat;
|
|
7
|
-
width?: number;
|
|
8
|
-
height?: number;
|
|
9
|
-
samples?: number;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Renderbuffers are GPU objects that contain images.
|
|
13
|
-
* In contrast to Textures they are optimized for use as render targets, with Framebuffers.
|
|
14
|
-
* while Textures may not be, and are the logical choice when
|
|
15
|
-
* you do not need to sample (i.e. in a post-pass shader)
|
|
16
|
-
* from the produced image. If you need to resample
|
|
17
|
-
* (such as when reading depth back in a second shader pass),
|
|
18
|
-
* use Textures instead.
|
|
19
|
-
* Renderbuffer objects also natively accommodate Multisampling (MSAA).
|
|
20
|
-
*/
|
|
21
|
-
export declare class WEBGLRenderbuffer extends WebGLResource<RenderbufferProps> {
|
|
22
|
-
static readonly defaultProps: Required<RenderbufferProps>;
|
|
23
|
-
get [Symbol.toStringTag](): string;
|
|
24
|
-
get width(): number;
|
|
25
|
-
get height(): number;
|
|
26
|
-
get format(): TextureFormat;
|
|
27
|
-
get samples(): number;
|
|
28
|
-
get attachment(): void;
|
|
29
|
-
/** WebGL format constant */
|
|
30
|
-
glFormat: GL;
|
|
31
|
-
static isTextureFormatSupported(device: WebGLDevice, format: TextureFormat): boolean;
|
|
32
|
-
constructor(device: WebGLDevice, props: RenderbufferProps);
|
|
33
|
-
resize(size: {
|
|
34
|
-
width: number;
|
|
35
|
-
height: number;
|
|
36
|
-
}): void;
|
|
37
|
-
/** Creates and initializes a renderbuffer object's data store */
|
|
38
|
-
protected _initialize(props: Required<RenderbufferProps>): void;
|
|
39
|
-
_createHandle(): WebGLRenderbuffer;
|
|
40
|
-
_deleteHandle(): void;
|
|
41
|
-
_bindHandle(handle: WEBGLRenderbuffer): void;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=webgl-renderbuffer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-renderbuffer.d.ts","sourceRoot":"","sources":["../../../src/adapter/objects/webgl-renderbuffer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAS,aAAa,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AACnE,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AACtC,OAAO,EAAC,WAAW,EAAC,2BAAwB;AAC5C,OAAO,EAAC,aAAa,EAAC,4BAAyB;AAO/C,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG;IAC9C,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,aAAa,CAAC,iBAAiB,CAAC;IACrE,gBAAyB,YAAY,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAQhE;IAEF,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IACD,IAAI,MAAM,IAAI,MAAM,CAEnB;IACD,IAAI,MAAM,IAAI,aAAa,CAE1B;IACD,IAAI,OAAO,IAAI,MAAM,CAEpB;IACD,IAAI,UAAU,SAEb;IAED,4BAA4B;IAC5B,QAAQ,EAAE,EAAE,CAAC;IAEb,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO;gBAIxE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB;IAUzD,MAAM,CAAC,IAAI,EAAE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,GAAG,IAAI;IAUnD,iEAAiE;IACjE,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GAAG,IAAI;IA6BtD,aAAa;IAIb,aAAa,IAAI,IAAI;IAKrB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;CAGtD"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { assert } from '@luma.gl/core';
|
|
5
|
-
import { GL } from '@luma.gl/constants';
|
|
6
|
-
import { WebGLResource } from "./webgl-resource.js";
|
|
7
|
-
import { isRenderbufferFormatSupported } from "../converters/texture-formats.js";
|
|
8
|
-
import { convertTextureFormatToGL, getTextureFormatBytesPerPixel } from "../converters/texture-formats.js";
|
|
9
|
-
/**
|
|
10
|
-
* Renderbuffers are GPU objects that contain images.
|
|
11
|
-
* In contrast to Textures they are optimized for use as render targets, with Framebuffers.
|
|
12
|
-
* while Textures may not be, and are the logical choice when
|
|
13
|
-
* you do not need to sample (i.e. in a post-pass shader)
|
|
14
|
-
* from the produced image. If you need to resample
|
|
15
|
-
* (such as when reading depth back in a second shader pass),
|
|
16
|
-
* use Textures instead.
|
|
17
|
-
* Renderbuffer objects also natively accommodate Multisampling (MSAA).
|
|
18
|
-
*/
|
|
19
|
-
export class WEBGLRenderbuffer extends WebGLResource {
|
|
20
|
-
static defaultProps = {
|
|
21
|
-
id: undefined,
|
|
22
|
-
handle: undefined,
|
|
23
|
-
userData: undefined,
|
|
24
|
-
format: undefined, // 'depth16unorm'
|
|
25
|
-
width: 1,
|
|
26
|
-
height: 1,
|
|
27
|
-
samples: 0
|
|
28
|
-
};
|
|
29
|
-
get [Symbol.toStringTag]() {
|
|
30
|
-
return 'Renderbuffer';
|
|
31
|
-
}
|
|
32
|
-
get width() {
|
|
33
|
-
return this.props.width;
|
|
34
|
-
}
|
|
35
|
-
get height() {
|
|
36
|
-
return this.props.height;
|
|
37
|
-
}
|
|
38
|
-
get format() {
|
|
39
|
-
return this.props.format;
|
|
40
|
-
}
|
|
41
|
-
get samples() {
|
|
42
|
-
return this.props.samples;
|
|
43
|
-
}
|
|
44
|
-
get attachment() {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
/** WebGL format constant */
|
|
48
|
-
glFormat;
|
|
49
|
-
static isTextureFormatSupported(device, format) {
|
|
50
|
-
return isRenderbufferFormatSupported(device.gl, format, device._extensions);
|
|
51
|
-
}
|
|
52
|
-
constructor(device, props) {
|
|
53
|
-
// TODO - remove temporary sanity check
|
|
54
|
-
if (typeof props.format === 'number') {
|
|
55
|
-
throw new Error('Renderbuffer');
|
|
56
|
-
}
|
|
57
|
-
super(device, props, WEBGLRenderbuffer.defaultProps);
|
|
58
|
-
this.glFormat = convertTextureFormatToGL(this.props.format);
|
|
59
|
-
this._initialize(this.props);
|
|
60
|
-
}
|
|
61
|
-
resize(size) {
|
|
62
|
-
// Don't resize if width/height haven't changed
|
|
63
|
-
if (size.width !== this.width || size.height !== this.height) {
|
|
64
|
-
Object.assign(this.props, { ...size, format: this.format, samples: this.samples });
|
|
65
|
-
this._initialize(this.props);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// PRIVATE METHODS
|
|
69
|
-
/** Creates and initializes a renderbuffer object's data store */
|
|
70
|
-
_initialize(props) {
|
|
71
|
-
const { format, width, height, samples } = props;
|
|
72
|
-
assert(format, 'Needs format');
|
|
73
|
-
this.trackDeallocatedMemory();
|
|
74
|
-
this.gl.bindRenderbuffer(36161, this.handle);
|
|
75
|
-
if (samples !== 0) {
|
|
76
|
-
this.gl.renderbufferStorageMultisample(36161, samples, this.glFormat, width, height);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
this.gl.renderbufferStorage(36161, this.glFormat, width, height);
|
|
80
|
-
}
|
|
81
|
-
this.gl.bindRenderbuffer(36161, null);
|
|
82
|
-
this.trackAllocatedMemory(width * height * (samples || 1) * getTextureFormatBytesPerPixel(this.format));
|
|
83
|
-
}
|
|
84
|
-
// RESOURCE IMPLEMENTATION
|
|
85
|
-
_createHandle() {
|
|
86
|
-
return this.gl.createRenderbuffer();
|
|
87
|
-
}
|
|
88
|
-
_deleteHandle() {
|
|
89
|
-
this.gl.deleteRenderbuffer(this.handle);
|
|
90
|
-
this.trackDeallocatedMemory();
|
|
91
|
-
}
|
|
92
|
-
_bindHandle(handle) {
|
|
93
|
-
this.gl.bindRenderbuffer(36161, handle);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Device, ResourceProps } from '@luma.gl/core';
|
|
2
|
-
import { Resource } from '@luma.gl/core';
|
|
3
|
-
import { GL } from '@luma.gl/constants';
|
|
4
|
-
import { WebGLDevice } from "../webgl-device.js";
|
|
5
|
-
/**
|
|
6
|
-
* Base class for WebGL object wrappers
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class WebGLResource<Props extends ResourceProps> extends Resource<Props> {
|
|
9
|
-
readonly device: WebGLDevice;
|
|
10
|
-
readonly gl: WebGL2RenderingContext;
|
|
11
|
-
readonly gl2: WebGL2RenderingContext;
|
|
12
|
-
private _handle;
|
|
13
|
-
private _bound;
|
|
14
|
-
byteLength: number;
|
|
15
|
-
constructor(device: Device, props: Props, defaultProps: Required<Props>);
|
|
16
|
-
toString(): string;
|
|
17
|
-
get handle(): any;
|
|
18
|
-
delete({ deleteChildren }?: {
|
|
19
|
-
deleteChildren?: boolean;
|
|
20
|
-
}): this;
|
|
21
|
-
bind(funcOrHandle?: any): any;
|
|
22
|
-
unbind(): void;
|
|
23
|
-
stubRemovedMethods(className: string, version: string, methodNames: string[]): void;
|
|
24
|
-
initialize(props: ResourceProps): void;
|
|
25
|
-
_createHandle(): void;
|
|
26
|
-
_deleteHandle(): void;
|
|
27
|
-
_bindHandle(handle: any): void;
|
|
28
|
-
_getOptsFromHandle(): void;
|
|
29
|
-
_getParameter(pname: GL, props: Record<string, any>): number;
|
|
30
|
-
_setParameter(pname: GL | string, value: any): void;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=webgl-resource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-resource.d.ts","sourceRoot":"","sources":["../../../src/adapter/objects/webgl-resource.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AACzD,OAAO,EAAC,QAAQ,EAA0B,MAAM,eAAe,CAAC;AAChE,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AACtC,OAAO,EAAC,WAAW,EAAC,2BAAwB;AAI5C;;GAEG;AACH,8BAAsB,aAAa,CAAC,KAAK,SAAS,aAAa,CAAE,SAAQ,QAAQ,CAAC,KAAK,CAAC;IACtF,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,sBAAsB,CAAC;IACpC,QAAQ,CAAC,GAAG,EAAE,sBAAsB,CAAC;IACrC,OAAO,CAAC,OAAO,CAAM;IAErB,OAAO,CAAC,MAAM,CAAS;IAEvB,UAAU,SAAK;gBAEH,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC;IA2B9D,QAAQ,IAAI,MAAM;IAI3B,IAAI,MAAM,QAWT;IAEQ,MAAM,CAAC,EAAC,cAAsB,EAAC;;KAAK;IAmB7C,IAAI,CAAC,YAAY,MAAc;IAuB/B,MAAM;IAKN,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE;IAK5E,UAAU,CAAC,KAAK,EAAE,aAAa;IAG/B,aAAa;IAIb,aAAa;IAIb,WAAW,CAAC,MAAM,EAAE,GAAG;IAIvB,kBAAkB;IAIlB,aAAa,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM;IAI5D,aAAa,CAAC,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG;CAuC7C"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { Resource, uid, stubRemovedMethods } from '@luma.gl/core';
|
|
5
|
-
const ERR_RESOURCE_METHOD_UNDEFINED = 'Resource subclass must define virtual methods';
|
|
6
|
-
/**
|
|
7
|
-
* Base class for WebGL object wrappers
|
|
8
|
-
*/
|
|
9
|
-
export class WebGLResource extends Resource {
|
|
10
|
-
device;
|
|
11
|
-
gl;
|
|
12
|
-
gl2;
|
|
13
|
-
_handle;
|
|
14
|
-
_bound = false;
|
|
15
|
-
// Only meaningful for resources that allocate GPU memory
|
|
16
|
-
byteLength = 0;
|
|
17
|
-
constructor(device, props, defaultProps) {
|
|
18
|
-
super(device, props, defaultProps);
|
|
19
|
-
this.device = device;
|
|
20
|
-
const gl = this.device.gl;
|
|
21
|
-
// extends
|
|
22
|
-
const { id } = props || {};
|
|
23
|
-
this.gl = gl;
|
|
24
|
-
this.gl2 = gl;
|
|
25
|
-
this.id = id || uid(this.constructor.name);
|
|
26
|
-
// Set the handle
|
|
27
|
-
// If handle was provided, use it, otherwise create a new handle
|
|
28
|
-
// TODO - Stores the handle with context loss information
|
|
29
|
-
// this.glCount = glGetContextLossCount(this.gl);
|
|
30
|
-
// Default VertexArray needs to be created with null handle, so compare against undefined
|
|
31
|
-
this._handle = props?.handle;
|
|
32
|
-
if (this._handle === undefined) {
|
|
33
|
-
this._handle = this._createHandle();
|
|
34
|
-
}
|
|
35
|
-
this.byteLength = 0;
|
|
36
|
-
}
|
|
37
|
-
toString() {
|
|
38
|
-
return `${this.constructor.name}(${this.id})`;
|
|
39
|
-
}
|
|
40
|
-
get handle() {
|
|
41
|
-
// TODO - Add context loss handling
|
|
42
|
-
// Will regenerate and reinitialize the handle if necessary
|
|
43
|
-
// const glCount = glGetContextLossCount(this.gl);
|
|
44
|
-
// if (this.glCount !== glCount) {
|
|
45
|
-
// this._handle = this._createHandle(this.props);
|
|
46
|
-
// this._glCount = glCount;
|
|
47
|
-
// // Reinitialize object
|
|
48
|
-
// this.initialize(this.props);
|
|
49
|
-
// }
|
|
50
|
-
return this._handle;
|
|
51
|
-
}
|
|
52
|
-
delete({ deleteChildren = false } = {}) {
|
|
53
|
-
// Delete this object, and get refs to any children
|
|
54
|
-
// @ts-expect-error
|
|
55
|
-
const children = this._handle && this._deleteHandle(this._handle);
|
|
56
|
-
if (this._handle) {
|
|
57
|
-
this.removeStats();
|
|
58
|
-
}
|
|
59
|
-
this._handle = null;
|
|
60
|
-
// Optionally, recursively delete the children
|
|
61
|
-
// @ts-expect-error
|
|
62
|
-
if (children && deleteChildren) {
|
|
63
|
-
// @ts-expect-error
|
|
64
|
-
children.filter(Boolean).forEach(child => child.destroy());
|
|
65
|
-
}
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
bind(funcOrHandle = this.handle) {
|
|
69
|
-
if (typeof funcOrHandle !== 'function') {
|
|
70
|
-
this._bindHandle(funcOrHandle);
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
let value;
|
|
74
|
-
if (!this._bound) {
|
|
75
|
-
this._bindHandle(this.handle);
|
|
76
|
-
this._bound = true;
|
|
77
|
-
value = funcOrHandle();
|
|
78
|
-
this._bound = false;
|
|
79
|
-
this._bindHandle(null);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
value = funcOrHandle();
|
|
83
|
-
}
|
|
84
|
-
return value;
|
|
85
|
-
}
|
|
86
|
-
unbind() {
|
|
87
|
-
this.bind(null);
|
|
88
|
-
}
|
|
89
|
-
// Install stubs for removed methods
|
|
90
|
-
stubRemovedMethods(className, version, methodNames) {
|
|
91
|
-
return stubRemovedMethods(this, className, version, methodNames);
|
|
92
|
-
}
|
|
93
|
-
// PUBLIC VIRTUAL METHODS
|
|
94
|
-
initialize(props) { }
|
|
95
|
-
// PROTECTED METHODS - These must be overridden by subclass
|
|
96
|
-
_createHandle() {
|
|
97
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
98
|
-
}
|
|
99
|
-
_deleteHandle() {
|
|
100
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
101
|
-
}
|
|
102
|
-
_bindHandle(handle) {
|
|
103
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
104
|
-
}
|
|
105
|
-
_getOptsFromHandle() {
|
|
106
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
107
|
-
}
|
|
108
|
-
_getParameter(pname, props) {
|
|
109
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
110
|
-
}
|
|
111
|
-
_setParameter(pname, value) {
|
|
112
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {assert} from '@luma.gl/core';
|
|
6
|
-
import {GL} from '@luma.gl/constants';
|
|
7
|
-
|
|
8
|
-
// Resolve a WebGL enumeration name (returns itself if already a number)
|
|
9
|
-
export function getKeyValue(gl: WebGL2RenderingContext, name: string | GL): GL {
|
|
10
|
-
// If not a string, return (assume number)
|
|
11
|
-
if (typeof name !== 'string') {
|
|
12
|
-
return name;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// If string converts to number, return number
|
|
16
|
-
const number = Number(name);
|
|
17
|
-
if (!isNaN(number)) {
|
|
18
|
-
return number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Look up string, after removing any 'GL.' or 'gl.' prefix
|
|
22
|
-
name = name.replace(/^.*\./, '');
|
|
23
|
-
// @ts-ignore expect-error depends on settings
|
|
24
|
-
const value = gl[name];
|
|
25
|
-
assert(value !== undefined, `Accessing undefined constant GL.${name}`);
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {assert, ResourceProps, TextureFormat} from '@luma.gl/core';
|
|
6
|
-
import {GL} from '@luma.gl/constants';
|
|
7
|
-
import {WebGLDevice} from '../webgl-device';
|
|
8
|
-
import {WebGLResource} from './webgl-resource';
|
|
9
|
-
import {isRenderbufferFormatSupported} from '../converters/texture-formats';
|
|
10
|
-
import {
|
|
11
|
-
convertTextureFormatToGL,
|
|
12
|
-
getTextureFormatBytesPerPixel
|
|
13
|
-
} from '../converters/texture-formats';
|
|
14
|
-
|
|
15
|
-
export type RenderbufferProps = ResourceProps & {
|
|
16
|
-
format: TextureFormat;
|
|
17
|
-
width?: number;
|
|
18
|
-
height?: number;
|
|
19
|
-
samples?: number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Renderbuffers are GPU objects that contain images.
|
|
24
|
-
* In contrast to Textures they are optimized for use as render targets, with Framebuffers.
|
|
25
|
-
* while Textures may not be, and are the logical choice when
|
|
26
|
-
* you do not need to sample (i.e. in a post-pass shader)
|
|
27
|
-
* from the produced image. If you need to resample
|
|
28
|
-
* (such as when reading depth back in a second shader pass),
|
|
29
|
-
* use Textures instead.
|
|
30
|
-
* Renderbuffer objects also natively accommodate Multisampling (MSAA).
|
|
31
|
-
*/
|
|
32
|
-
export class WEBGLRenderbuffer extends WebGLResource<RenderbufferProps> {
|
|
33
|
-
static override readonly defaultProps: Required<RenderbufferProps> = {
|
|
34
|
-
id: undefined,
|
|
35
|
-
handle: undefined,
|
|
36
|
-
userData: undefined,
|
|
37
|
-
format: undefined, // 'depth16unorm'
|
|
38
|
-
width: 1,
|
|
39
|
-
height: 1,
|
|
40
|
-
samples: 0
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
override get [Symbol.toStringTag](): string {
|
|
44
|
-
return 'Renderbuffer';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get width(): number {
|
|
48
|
-
return this.props.width;
|
|
49
|
-
}
|
|
50
|
-
get height(): number {
|
|
51
|
-
return this.props.height;
|
|
52
|
-
}
|
|
53
|
-
get format(): TextureFormat {
|
|
54
|
-
return this.props.format;
|
|
55
|
-
}
|
|
56
|
-
get samples(): number {
|
|
57
|
-
return this.props.samples;
|
|
58
|
-
}
|
|
59
|
-
get attachment() {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** WebGL format constant */
|
|
64
|
-
glFormat: GL;
|
|
65
|
-
|
|
66
|
-
static isTextureFormatSupported(device: WebGLDevice, format: TextureFormat): boolean {
|
|
67
|
-
return isRenderbufferFormatSupported(device.gl, format, device._extensions);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
constructor(device: WebGLDevice, props: RenderbufferProps) {
|
|
71
|
-
// TODO - remove temporary sanity check
|
|
72
|
-
if (typeof props.format === 'number') {
|
|
73
|
-
throw new Error('Renderbuffer');
|
|
74
|
-
}
|
|
75
|
-
super(device, props, WEBGLRenderbuffer.defaultProps);
|
|
76
|
-
this.glFormat = convertTextureFormatToGL(this.props.format);
|
|
77
|
-
this._initialize(this.props);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
resize(size: {width: number; height: number}): void {
|
|
81
|
-
// Don't resize if width/height haven't changed
|
|
82
|
-
if (size.width !== this.width || size.height !== this.height) {
|
|
83
|
-
Object.assign(this.props, {...size, format: this.format, samples: this.samples});
|
|
84
|
-
this._initialize(this.props);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// PRIVATE METHODS
|
|
89
|
-
|
|
90
|
-
/** Creates and initializes a renderbuffer object's data store */
|
|
91
|
-
protected _initialize(props: Required<RenderbufferProps>): void {
|
|
92
|
-
const {format, width, height, samples} = props;
|
|
93
|
-
assert(format, 'Needs format');
|
|
94
|
-
|
|
95
|
-
this.trackDeallocatedMemory();
|
|
96
|
-
|
|
97
|
-
this.gl.bindRenderbuffer(GL.RENDERBUFFER, this.handle);
|
|
98
|
-
|
|
99
|
-
if (samples !== 0) {
|
|
100
|
-
this.gl.renderbufferStorageMultisample(
|
|
101
|
-
GL.RENDERBUFFER,
|
|
102
|
-
samples,
|
|
103
|
-
this.glFormat,
|
|
104
|
-
width,
|
|
105
|
-
height
|
|
106
|
-
);
|
|
107
|
-
} else {
|
|
108
|
-
this.gl.renderbufferStorage(GL.RENDERBUFFER, this.glFormat, width, height);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
this.gl.bindRenderbuffer(GL.RENDERBUFFER, null);
|
|
112
|
-
|
|
113
|
-
this.trackAllocatedMemory(
|
|
114
|
-
width * height * (samples || 1) * getTextureFormatBytesPerPixel(this.format)
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// RESOURCE IMPLEMENTATION
|
|
119
|
-
|
|
120
|
-
override _createHandle() {
|
|
121
|
-
return this.gl.createRenderbuffer();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
override _deleteHandle(): void {
|
|
125
|
-
this.gl.deleteRenderbuffer(this.handle);
|
|
126
|
-
this.trackDeallocatedMemory();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
override _bindHandle(handle: WEBGLRenderbuffer): void {
|
|
130
|
-
this.gl.bindRenderbuffer(GL.RENDERBUFFER, handle);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {Device, ResourceProps} from '@luma.gl/core';
|
|
6
|
-
import {Resource, uid, stubRemovedMethods} from '@luma.gl/core';
|
|
7
|
-
import {GL} from '@luma.gl/constants';
|
|
8
|
-
import {WebGLDevice} from '../webgl-device';
|
|
9
|
-
|
|
10
|
-
const ERR_RESOURCE_METHOD_UNDEFINED = 'Resource subclass must define virtual methods';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Base class for WebGL object wrappers
|
|
14
|
-
*/
|
|
15
|
-
export abstract class WebGLResource<Props extends ResourceProps> extends Resource<Props> {
|
|
16
|
-
readonly device: WebGLDevice;
|
|
17
|
-
readonly gl: WebGL2RenderingContext;
|
|
18
|
-
readonly gl2: WebGL2RenderingContext;
|
|
19
|
-
private _handle: any;
|
|
20
|
-
|
|
21
|
-
private _bound = false;
|
|
22
|
-
// Only meaningful for resources that allocate GPU memory
|
|
23
|
-
byteLength = 0;
|
|
24
|
-
|
|
25
|
-
constructor(device: Device, props: Props, defaultProps: Required<Props>) {
|
|
26
|
-
super(device, props, defaultProps);
|
|
27
|
-
|
|
28
|
-
this.device = device as WebGLDevice;
|
|
29
|
-
const gl = this.device.gl;
|
|
30
|
-
|
|
31
|
-
// extends
|
|
32
|
-
const {id} = props || {};
|
|
33
|
-
this.gl = gl;
|
|
34
|
-
this.gl2 = gl;
|
|
35
|
-
this.id = id || uid(this.constructor.name);
|
|
36
|
-
|
|
37
|
-
// Set the handle
|
|
38
|
-
// If handle was provided, use it, otherwise create a new handle
|
|
39
|
-
|
|
40
|
-
// TODO - Stores the handle with context loss information
|
|
41
|
-
// this.glCount = glGetContextLossCount(this.gl);
|
|
42
|
-
|
|
43
|
-
// Default VertexArray needs to be created with null handle, so compare against undefined
|
|
44
|
-
this._handle = props?.handle;
|
|
45
|
-
if (this._handle === undefined) {
|
|
46
|
-
this._handle = this._createHandle();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.byteLength = 0;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
override toString(): string {
|
|
53
|
-
return `${this.constructor.name}(${this.id})`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get handle() {
|
|
57
|
-
// TODO - Add context loss handling
|
|
58
|
-
// Will regenerate and reinitialize the handle if necessary
|
|
59
|
-
// const glCount = glGetContextLossCount(this.gl);
|
|
60
|
-
// if (this.glCount !== glCount) {
|
|
61
|
-
// this._handle = this._createHandle(this.props);
|
|
62
|
-
// this._glCount = glCount;
|
|
63
|
-
// // Reinitialize object
|
|
64
|
-
// this.initialize(this.props);
|
|
65
|
-
// }
|
|
66
|
-
return this._handle;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
override delete({deleteChildren = false} = {}) {
|
|
70
|
-
// Delete this object, and get refs to any children
|
|
71
|
-
// @ts-expect-error
|
|
72
|
-
const children = this._handle && this._deleteHandle(this._handle);
|
|
73
|
-
if (this._handle) {
|
|
74
|
-
this.removeStats();
|
|
75
|
-
}
|
|
76
|
-
this._handle = null;
|
|
77
|
-
|
|
78
|
-
// Optionally, recursively delete the children
|
|
79
|
-
// @ts-expect-error
|
|
80
|
-
if (children && deleteChildren) {
|
|
81
|
-
// @ts-expect-error
|
|
82
|
-
children.filter(Boolean).forEach(child => child.destroy());
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
bind(funcOrHandle = this.handle) {
|
|
89
|
-
if (typeof funcOrHandle !== 'function') {
|
|
90
|
-
this._bindHandle(funcOrHandle);
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let value;
|
|
95
|
-
|
|
96
|
-
if (!this._bound) {
|
|
97
|
-
this._bindHandle(this.handle);
|
|
98
|
-
this._bound = true;
|
|
99
|
-
|
|
100
|
-
value = funcOrHandle();
|
|
101
|
-
|
|
102
|
-
this._bound = false;
|
|
103
|
-
this._bindHandle(null);
|
|
104
|
-
} else {
|
|
105
|
-
value = funcOrHandle();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return value;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
unbind() {
|
|
112
|
-
this.bind(null);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Install stubs for removed methods
|
|
116
|
-
stubRemovedMethods(className: string, version: string, methodNames: string[]) {
|
|
117
|
-
return stubRemovedMethods(this, className, version, methodNames);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// PUBLIC VIRTUAL METHODS
|
|
121
|
-
initialize(props: ResourceProps) {}
|
|
122
|
-
|
|
123
|
-
// PROTECTED METHODS - These must be overridden by subclass
|
|
124
|
-
_createHandle() {
|
|
125
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
_deleteHandle() {
|
|
129
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
_bindHandle(handle: any) {
|
|
133
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
_getOptsFromHandle() {
|
|
137
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
_getParameter(pname: GL, props: Record<string, any>): number {
|
|
141
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
_setParameter(pname: GL | string, value: any) {
|
|
145
|
-
throw new Error(ERR_RESOURCE_METHOD_UNDEFINED);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// PRIVATE METHODS
|
|
149
|
-
|
|
150
|
-
/*
|
|
151
|
-
_addStats() {
|
|
152
|
-
const name = this.constructor.name;
|
|
153
|
-
const stats = lumaStats.get('Resource Counts');
|
|
154
|
-
|
|
155
|
-
stats.get('Resources Created').incrementCount();
|
|
156
|
-
stats.get(`${name}s Created`).incrementCount();
|
|
157
|
-
stats.get(`${name}s Active`).incrementCount();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
_removeStats() {
|
|
161
|
-
const name = this.constructor.name;
|
|
162
|
-
const stats = lumaStats.get('Resource Counts');
|
|
163
|
-
|
|
164
|
-
stats.get(`${name}s Active`).decrementCount();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
trackAllocatedMemory(bytes, name = this.constructor.name) {
|
|
168
|
-
const stats = lumaStats.get('Memory Usage');
|
|
169
|
-
|
|
170
|
-
stats.get('GPU Memory').addCount(bytes);
|
|
171
|
-
stats.get(`${name} Memory`).addCount(bytes);
|
|
172
|
-
this.byteLength = bytes;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
trackDeallocatedMemory(name = this.constructor.name) {
|
|
176
|
-
const stats = lumaStats.get('Memory Usage');
|
|
177
|
-
|
|
178
|
-
stats.get('GPU Memory').subtractCount(this.byteLength);
|
|
179
|
-
stats.get(`${name} Memory`).subtractCount(this.byteLength);
|
|
180
|
-
this.byteLength = 0;
|
|
181
|
-
}
|
|
182
|
-
*/
|
|
183
|
-
}
|