@luma.gl/webgl 9.0.0-alpha.21 → 9.0.0-alpha.24

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.
Files changed (165) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +1 -1
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +9 -9
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.d.ts +1 -1
  6. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  7. package/dist/adapter/converters/sampler-parameters.js +1 -1
  8. package/dist/adapter/converters/sampler-parameters.js.map +1 -1
  9. package/dist/adapter/converters/texture-formats.d.ts +29 -40
  10. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  11. package/dist/adapter/converters/texture-formats.js +152 -114
  12. package/dist/adapter/converters/texture-formats.js.map +1 -1
  13. package/dist/adapter/device-helpers/device-limits.d.ts +1 -1
  14. package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
  15. package/dist/adapter/helpers/attribute-utils.d.ts +1 -1
  16. package/dist/adapter/helpers/attribute-utils.d.ts.map +1 -1
  17. package/dist/adapter/helpers/attribute-utils.js +1 -1
  18. package/dist/adapter/helpers/attribute-utils.js.map +1 -1
  19. package/dist/adapter/helpers/get-shader-info.d.ts +1 -1
  20. package/dist/adapter/helpers/get-shader-info.d.ts.map +1 -1
  21. package/dist/adapter/helpers/get-shader-info.js.map +1 -1
  22. package/dist/adapter/helpers/uniforms.d.ts +7 -8
  23. package/dist/adapter/helpers/uniforms.d.ts.map +1 -1
  24. package/dist/adapter/helpers/uniforms.js +4 -4
  25. package/dist/adapter/helpers/uniforms.js.map +1 -1
  26. package/dist/adapter/objects/constants-to-keys.d.ts +0 -2
  27. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  28. package/dist/adapter/objects/constants-to-keys.js +0 -20
  29. package/dist/adapter/objects/constants-to-keys.js.map +1 -1
  30. package/dist/adapter/objects/webgl-renderbuffer.d.ts +12 -9
  31. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  32. package/dist/adapter/objects/webgl-renderbuffer.js +29 -19
  33. package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
  34. package/dist/adapter/objects/webgl-resource.d.ts +0 -1
  35. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  36. package/dist/adapter/objects/webgl-resource.js +4 -7
  37. package/dist/adapter/objects/webgl-resource.js.map +1 -1
  38. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +1 -1
  39. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
  40. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  41. package/dist/adapter/resources/webgl-buffer.js +3 -2
  42. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  43. package/dist/adapter/resources/webgl-command-buffer.d.ts +13 -7
  44. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgl-command-buffer.js +168 -25
  46. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  47. package/dist/adapter/resources/webgl-command-encoder.d.ts +3 -2
  48. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  49. package/dist/adapter/resources/webgl-command-encoder.js +6 -2
  50. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
  51. package/dist/adapter/resources/webgl-framebuffer.d.ts +11 -14
  52. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgl-framebuffer.js +29 -79
  54. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  55. package/dist/adapter/resources/webgl-render-pass.d.ts +16 -1
  56. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgl-render-pass.js +80 -0
  58. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  59. package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
  60. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  61. package/dist/adapter/resources/webgl-render-pipeline.js +5 -5
  62. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  63. package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
  64. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  65. package/dist/adapter/resources/webgl-sampler.js +1 -1
  66. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  67. package/dist/adapter/resources/webgl-texture.d.ts +43 -23
  68. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  69. package/dist/adapter/resources/webgl-texture.js +32 -30
  70. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  71. package/dist/adapter/webgl-canvas-context.d.ts +1 -2
  72. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  73. package/dist/adapter/webgl-canvas-context.js.map +1 -1
  74. package/dist/adapter/webgl-device.d.ts +13 -6
  75. package/dist/adapter/webgl-device.d.ts.map +1 -1
  76. package/dist/adapter/webgl-device.js +20 -2
  77. package/dist/adapter/webgl-device.js.map +1 -1
  78. package/dist/classic/buffer.d.ts +1 -2
  79. package/dist/classic/buffer.d.ts.map +1 -1
  80. package/dist/classic/buffer.js +0 -6
  81. package/dist/classic/buffer.js.map +1 -1
  82. package/dist/classic/clear.d.ts +22 -0
  83. package/dist/classic/clear.d.ts.map +1 -0
  84. package/dist/classic/clear.js +88 -0
  85. package/dist/classic/clear.js.map +1 -0
  86. package/dist/classic/copy-and-blit.d.ts +45 -0
  87. package/dist/classic/copy-and-blit.d.ts.map +1 -0
  88. package/dist/classic/copy-and-blit.js +136 -0
  89. package/dist/classic/copy-and-blit.js.map +1 -0
  90. package/dist/classic/format-utils.d.ts +3 -0
  91. package/dist/classic/format-utils.d.ts.map +1 -0
  92. package/dist/classic/format-utils.js +38 -0
  93. package/dist/classic/format-utils.js.map +1 -0
  94. package/dist/classic/typed-array-utils.d.ts +15 -17
  95. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  96. package/dist/classic/typed-array-utils.js +1 -1
  97. package/dist/classic/typed-array-utils.js.map +1 -1
  98. package/dist/context/context/create-browser-context.d.ts +17 -19
  99. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  100. package/dist/context/context/create-browser-context.js +4 -4
  101. package/dist/context/context/create-browser-context.js.map +1 -1
  102. package/dist/context/context/create-headless-context.d.ts +1 -1
  103. package/dist/context/context/create-headless-context.d.ts.map +1 -1
  104. package/dist/context/debug/spector.d.ts +1 -3
  105. package/dist/context/debug/spector.d.ts.map +1 -1
  106. package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
  107. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  108. package/dist/context/parameters/unified-parameter-api.d.ts +1 -1
  109. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  110. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  111. package/dist/context/parameters/webgl-parameter-tables.d.ts +2 -3
  112. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  113. package/dist/context/parameters/webgl-parameter-tables.js +1 -1
  114. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  115. package/dist/dist.dev.js +1306 -659
  116. package/dist/index.cjs +1269 -897
  117. package/dist/index.d.ts +5 -2
  118. package/dist/index.d.ts.map +1 -1
  119. package/dist/index.js +4 -1
  120. package/dist/index.js.map +1 -1
  121. package/dist/types.d.ts +1 -1
  122. package/dist/types.d.ts.map +1 -1
  123. package/dist.min.js +22 -21
  124. package/package.json +7 -4
  125. package/src/adapter/converters/device-parameters.ts +46 -22
  126. package/src/adapter/converters/sampler-parameters.ts +1 -2
  127. package/src/adapter/converters/texture-formats.ts +242 -161
  128. package/src/adapter/helpers/attribute-utils.ts +1 -2
  129. package/src/adapter/helpers/get-shader-info.ts +3 -0
  130. package/src/adapter/helpers/uniforms.ts +9 -10
  131. package/src/adapter/objects/constants-to-keys.ts +0 -25
  132. package/src/adapter/objects/webgl-renderbuffer.ts +32 -29
  133. package/src/adapter/objects/webgl-resource.ts +4 -8
  134. package/src/adapter/resources/webgl-buffer.ts +4 -5
  135. package/src/adapter/resources/webgl-command-buffer.ts +328 -21
  136. package/src/adapter/resources/webgl-command-encoder.ts +7 -2
  137. package/src/adapter/resources/webgl-framebuffer.ts +63 -111
  138. package/src/adapter/resources/webgl-render-pass.ts +146 -2
  139. package/src/adapter/resources/webgl-render-pipeline.ts +7 -4
  140. package/src/adapter/resources/webgl-sampler.ts +1 -2
  141. package/src/adapter/resources/webgl-texture.ts +61 -43
  142. package/src/adapter/webgl-canvas-context.ts +2 -2
  143. package/src/adapter/webgl-device.ts +37 -8
  144. package/src/classic/buffer.ts +3 -3
  145. package/src/classic/clear.ts +110 -0
  146. package/src/classic/copy-and-blit.ts +189 -0
  147. package/src/classic/format-utils.ts +43 -0
  148. package/src/classic/typed-array-utils.ts +15 -26
  149. package/src/context/context/create-browser-context.ts +37 -30
  150. package/src/context/parameters/unified-parameter-api.ts +1 -1
  151. package/src/context/parameters/webgl-parameter-tables.ts +2 -2
  152. package/src/index.ts +10 -3
  153. package/dist/adapter/converters/renderbuffer-formats.d.ts +0 -16
  154. package/dist/adapter/converters/renderbuffer-formats.d.ts.map +0 -1
  155. package/dist/adapter/converters/renderbuffer-formats.js +0 -180
  156. package/dist/adapter/converters/renderbuffer-formats.js.map +0 -1
  157. package/dist/types/webgl.d.ts +0 -145
  158. package/dist/types/webgl.d.ts.map +0 -1
  159. package/dist/types/webgl.js +0 -2
  160. package/dist/types/webgl.js.map +0 -1
  161. package/src/.DS_Store +0 -0
  162. package/src/adapter/.DS_Store +0 -0
  163. package/src/adapter/converters/renderbuffer-formats.ts +0 -90
  164. package/src/context/.DS_Store +0 -0
  165. package/src/types/webgl.ts +0 -286
@@ -0,0 +1,189 @@
1
+ // luma.gl, MIT license
2
+ import {assert, Texture, Framebuffer, FramebufferProps} from '@luma.gl/api';
3
+ import GL from '@luma.gl/constants';
4
+
5
+ import {ClassicBuffer as Buffer} from './buffer';
6
+ import {WEBGLTexture} from '../adapter/resources/webgl-texture';
7
+ import {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';
8
+ import {withParameters} from '../context/state-tracker/with-parameters';
9
+ import {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';
10
+ import {glFormatToComponents, glTypeToBytes} from './format-utils';
11
+
12
+ /**
13
+ * Copies data from a type or a Texture object into ArrayBuffer object.
14
+ * App can provide targetPixelArray or have it auto allocated by this method
15
+ * newly allocated by this method unless provided by app.
16
+ * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read
17
+ * @note Slow requires roundtrip to GPU
18
+ *
19
+ * @param source
20
+ * @param options
21
+ * @returns pixel array,
22
+ */
23
+ export function readPixelsToArray(
24
+ source: Framebuffer | Texture,
25
+ options?: {
26
+ sourceX?: number;
27
+ sourceY?: number;
28
+ sourceFormat?: number;
29
+ sourceAttachment?: number;
30
+ target?: Uint8Array | Uint16Array | Float32Array;
31
+ // following parameters are auto deduced if not provided
32
+ sourceWidth?: number;
33
+ sourceHeight?: number;
34
+ sourceType?: number;
35
+ }
36
+ ): Uint8Array | Uint16Array | Float32Array {
37
+ const {sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA} = options || {};
38
+ let {
39
+ sourceAttachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
40
+ target = null,
41
+ // following parameters are auto deduced if not provided
42
+ sourceWidth,
43
+ sourceHeight,
44
+ sourceType
45
+ } = options || {};
46
+
47
+ const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
48
+ assert(framebuffer);
49
+ const {gl, handle} = framebuffer as WEBGLFramebuffer;
50
+ sourceWidth = sourceWidth || framebuffer.width;
51
+ sourceHeight = sourceHeight || framebuffer.height;
52
+
53
+ // TODO - Set and unset gl.readBuffer
54
+ if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
55
+ sourceAttachment = GL.FRONT;
56
+ }
57
+
58
+ const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;
59
+ // assert(attachments[sourceAttachment]);
60
+
61
+ // Deduce the type from color attachment if not provided.
62
+ sourceType = sourceType || (framebuffer.colorAttachments[attachment] as WEBGLTexture).type;
63
+
64
+ // Deduce type and allocated pixelArray if needed
65
+ target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
66
+
67
+ // Pixel array available, if necessary, deduce type from it.
68
+ sourceType = sourceType || getGLTypeFromTypedArray(target);
69
+
70
+ const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
71
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
72
+ // @ts-expect-error
73
+ gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
74
+ if (deleteFramebuffer) {
75
+ framebuffer.destroy();
76
+ }
77
+ return target;
78
+ }
79
+
80
+ /**
81
+ * Copies data from a Framebuffer or a Texture object into a Buffer object.
82
+ * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
83
+ * @param source
84
+ * @param options
85
+ */
86
+ export function readPixelsToBuffer(
87
+ source: Framebuffer | Texture,
88
+ options?: {
89
+ sourceX?: number;
90
+ sourceY?: number;
91
+ sourceFormat?: number;
92
+ target?: Buffer; // A new Buffer object is created when not provided.
93
+ targetByteOffset?: number; // byte offset in buffer object
94
+ // following parameters are auto deduced if not provided
95
+ sourceWidth?: number;
96
+ sourceHeight?: number;
97
+ sourceType?: number;
98
+ }
99
+ ): Buffer {
100
+ const {sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, targetByteOffset = 0} = options || {};
101
+ // following parameters are auto deduced if not provided
102
+ let {target, sourceWidth, sourceHeight, sourceType} = options || {};
103
+ const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
104
+ assert(framebuffer);
105
+ sourceWidth = sourceWidth || framebuffer.width;
106
+ sourceHeight = sourceHeight || framebuffer.height;
107
+
108
+ // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
109
+ const webglFramebuffer = framebuffer as WEBGLFramebuffer;
110
+ const gl2 = webglFramebuffer.device.assertWebGL2();
111
+
112
+ // deduce type if not available.
113
+ sourceType = sourceType || (target ? target.type : GL.UNSIGNED_BYTE);
114
+
115
+ if (!target) {
116
+ // Create new buffer with enough size
117
+ const components = glFormatToComponents(sourceFormat);
118
+ const byteCount = glTypeToBytes(sourceType);
119
+ const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
120
+ target = new Buffer(gl2, {byteLength, accessor: {type: sourceType, size: components}});
121
+ }
122
+
123
+ // @ts-expect-error
124
+ target.bind({target: GL.PIXEL_PACK_BUFFER});
125
+ withParameters(gl2, {framebuffer}, () => {
126
+ gl2.readPixels(
127
+ sourceX,
128
+ sourceY,
129
+ sourceWidth,
130
+ sourceHeight,
131
+ sourceFormat,
132
+ sourceType,
133
+ targetByteOffset
134
+ );
135
+ });
136
+ target.unbind({target: GL.PIXEL_PACK_BUFFER});
137
+ if (deleteFramebuffer) {
138
+ framebuffer.destroy();
139
+ }
140
+
141
+ return target;
142
+ }
143
+
144
+ function getFramebuffer(source: Texture | Framebuffer): {
145
+ framebuffer: Framebuffer;
146
+ deleteFramebuffer: boolean;
147
+ } {
148
+ if (!(source instanceof Framebuffer)) {
149
+ return {framebuffer: toFramebuffer(source), deleteFramebuffer: true};
150
+ }
151
+ return {framebuffer: source, deleteFramebuffer: false};
152
+ }
153
+
154
+ /**
155
+ * Wraps a given texture into a framebuffer object, that can be further used
156
+ * to read data from the texture object.
157
+ */
158
+ export function toFramebuffer(texture: Texture, props?: FramebufferProps): Framebuffer {
159
+ const {device, width, height, id} = texture;
160
+ const framebuffer = device.createFramebuffer({
161
+ ...props,
162
+ id: `framebuffer-for-${id}`,
163
+ width,
164
+ height,
165
+ colorAttachments: [
166
+ texture
167
+ ]
168
+ }
169
+ );
170
+ return framebuffer;
171
+ }
172
+
173
+ function getPixelArray(
174
+ pixelArray,
175
+ type,
176
+ format,
177
+ width: number,
178
+ height: number
179
+ ): Uint8Array | Uint16Array | Float32Array {
180
+ if (pixelArray) {
181
+ return pixelArray;
182
+ }
183
+ // Allocate pixel array if not already available, using supplied type
184
+ type = type || GL.UNSIGNED_BYTE;
185
+ const ArrayType = getTypedArrayFromGLType(type, {clamped: false});
186
+ const components = glFormatToComponents(format);
187
+ // TODO - check for composite type (components = 1).
188
+ return new ArrayType(width * height * components) as Uint8Array | Uint16Array | Float32Array;
189
+ }
@@ -0,0 +1,43 @@
1
+ import {assert} from '@luma.gl/api';
2
+ import GL from '@luma.gl/constants';
3
+
4
+ // Returns number of components in a specific readPixels WebGL format
5
+ export function glFormatToComponents(format) {
6
+ switch (format) {
7
+ case GL.ALPHA:
8
+ case GL.R32F:
9
+ case GL.RED:
10
+ return 1;
11
+ case GL.RG32F:
12
+ case GL.RG:
13
+ return 2;
14
+ case GL.RGB:
15
+ case GL.RGB32F:
16
+ return 3;
17
+ case GL.RGBA:
18
+ case GL.RGBA32F:
19
+ return 4;
20
+ // TODO: Add support for additional WebGL2 formats
21
+ default:
22
+ assert(false);
23
+ return 0;
24
+ }
25
+ }
26
+
27
+ // Return byte count for given readPixels WebGL type
28
+ export function glTypeToBytes(type) {
29
+ switch (type) {
30
+ case GL.UNSIGNED_BYTE:
31
+ return 1;
32
+ case GL.UNSIGNED_SHORT_5_6_5:
33
+ case GL.UNSIGNED_SHORT_4_4_4_4:
34
+ case GL.UNSIGNED_SHORT_5_5_5_1:
35
+ return 2;
36
+ case GL.FLOAT:
37
+ return 4;
38
+ // TODO: Add support for additional WebGL2 types
39
+ default:
40
+ assert(false);
41
+ return 0;
42
+ }
43
+ }
@@ -1,28 +1,17 @@
1
1
  // luma.gl, MIT license
2
2
 
3
- import {TypedArray} from '@luma.gl/api';
4
- import GL from '@luma.gl/constants';
5
- import {GLType} from '../types/webgl'
3
+ import {TypedArray, TypedArrayConstructor} from '@luma.gl/api';
4
+ import {GL, GLDataType, GLPixelType} from '@luma.gl/constants';
6
5
 
7
6
  const ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';
8
7
 
9
- type TypedArrayConstructor =
10
- | Float32ArrayConstructor
11
- | Uint16ArrayConstructor
12
- | Uint32ArrayConstructor
13
- | Uint8ArrayConstructor
14
- | Uint8ClampedArrayConstructor
15
- | Int8ArrayConstructor
16
- | Int16ArrayConstructor
17
- | Int32ArrayConstructor;
18
-
19
8
  /**
20
9
  * Converts TYPED ARRAYS to corresponding GL constant
21
10
  * Used to auto deduce gl parameter types
22
- * @param {*} arrayOrType
11
+ * @param arrayOrType
23
12
  * @returns
24
13
  */
25
- export function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLType {
14
+ export function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLDataType {
26
15
  // If typed array, look up constructor
27
16
  const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
28
17
  switch (type) {
@@ -50,13 +39,13 @@ export function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLType {
50
39
  /**
51
40
  * Converts GL constant to corresponding TYPED ARRAY
52
41
  * Used to auto deduce gl parameter types
53
- * @param {*} glType
54
- * @param {*} param1
42
+ * @param glType
43
+ * @param param1
55
44
  * @returns
56
45
  */
57
46
  // eslint-disable-next-line complexity
58
47
  export function getTypedArrayFromGLType(
59
- glType: any,
48
+ glType: GLDataType | GLPixelType,
60
49
  options?: {
61
50
  clamped?: boolean;
62
51
  }
@@ -90,14 +79,14 @@ export function getTypedArrayFromGLType(
90
79
  * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)
91
80
  * https: *stackoverflow.com/questions/41969562/
92
81
  * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels
93
- * @param {*} param0
82
+ * @param param0
94
83
  */
95
84
  export function flipRows(options: {
96
- data: any;
97
- width: any;
98
- height: any;
85
+ data: TypedArray;
86
+ width: number;
87
+ height: number;
99
88
  bytesPerPixel?: number;
100
- temp?: any;
89
+ temp?: Uint8Array;
101
90
  }): void {
102
91
  const {data, width, height, bytesPerPixel = 4, temp} = options;
103
92
  const bytesPerRow = width * bytesPerPixel;
@@ -118,9 +107,9 @@ export function flipRows(options: {
118
107
 
119
108
 
120
109
  export function scalePixels(options: {
121
- data: any;
122
- width: any;
123
- height: any;
110
+ data: TypedArray;
111
+ width: number;
112
+ height: number;
124
113
  }): {
125
114
  data: Uint8Array;
126
115
  width: number;
@@ -2,21 +2,21 @@
2
2
 
3
3
  /**
4
4
  * ContextProps
5
- * @param webgl2 Set to false to not create a WebGL2 context (force webgl1)
6
- * @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)
7
- * @param onContextLost
8
- * @param onContextRestored
9
- *
10
- * BROWSER CONTEXT PARAMETERS
11
- * @param debug Instrument context (at the expense of performance).
12
- * @param alpha Default render target has an alpha buffer.
13
- * @param depth Default render target has a depth buffer of at least 16 bits.
14
- * @param stencil Default render target has a stencil buffer of at least 8 bits.
15
- * @param antialias Boolean that indicates whether or not to perform anti-aliasing.
16
- * @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
17
- * @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten
18
- * @param failIfMajorPerformanceCaveat Do not create if the system performance is low.
19
- */
5
+ * @param webgl2 Set to false to not create a WebGL2 context (force webgl1)
6
+ * @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)
7
+ * @param onContextLost
8
+ * @param onContextRestored
9
+ *
10
+ * BROWSER CONTEXT PARAMETERS
11
+ * @param debug Instrument context (at the expense of performance).
12
+ * @param alpha Default render target has an alpha buffer.
13
+ * @param depth Default render target has a depth buffer of at least 16 bits.
14
+ * @param stencil Default render target has a stencil buffer of at least 8 bits.
15
+ * @param antialias Boolean that indicates whether or not to perform anti-aliasing.
16
+ * @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
17
+ * @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten
18
+ * @param failIfMajorPerformanceCaveat Do not create if the system performance is low.
19
+ */
20
20
  type ContextProps = {
21
21
  type?: 'webgl' | 'webgl1' | 'webgl2' | string;
22
22
  webgl1?: boolean;
@@ -27,10 +27,10 @@ type ContextProps = {
27
27
  desynchronized?: boolean; // hints the user agent to reduce the latency by desynchronizing the canvas paint cycle from the event loop
28
28
  antialias?: boolean; // indicates whether or not to perform anti-aliasing.
29
29
  depth?: boolean; // indicates that the drawing buffer has a depth buffer of at least 16 bits.
30
- failIfMajorPerformanceCaveat?: boolean, // indicates if a context will be created if the system performance is low or if no hardware GPU is available.
31
- powerPreference?: 'default' | 'high-performance' | 'low-power',
32
- premultipliedAlpha?: boolean, // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
33
- preserveDrawingBuffer?: boolean // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.
30
+ failIfMajorPerformanceCaveat?: boolean; // indicates if a context will be created if the system performance is low or if no hardware GPU is available.
31
+ powerPreference?: 'default' | 'high-performance' | 'low-power';
32
+ premultipliedAlpha?: boolean; // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
33
+ preserveDrawingBuffer?: boolean; // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.
34
34
  };
35
35
 
36
36
  const DEFAULT_CONTEXT_PROPS: ContextProps = {
@@ -40,24 +40,27 @@ const DEFAULT_CONTEXT_PROPS: ContextProps = {
40
40
  // eslint-disable-next-line no-console
41
41
  onContextLost: () => console.error('WebGL context lost'),
42
42
  // eslint-disable-next-line no-console
43
- onContextRestored: () => console.info('WebGL context restored'),
43
+ onContextRestored: () => console.info('WebGL context restored')
44
44
  };
45
45
 
46
46
  /**
47
47
  * Create a WebGL context for a canvas
48
48
  * Note calling this multiple time on the same canvas does return the same context
49
- * @param canvas A canvas element or offscreen canvas
49
+ * @param canvas A canvas element or offscreen canvas
50
50
  */
51
- export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): WebGLRenderingContext {
51
+ export function createBrowserContext(
52
+ canvas: HTMLCanvasElement | OffscreenCanvas,
53
+ props: ContextProps
54
+ ): WebGLRenderingContext {
52
55
  props = {...DEFAULT_CONTEXT_PROPS, ...props};
53
56
 
54
57
  // Try to extract any extra information about why context creation failed
55
58
  let errorMessage = null;
56
- const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);
59
+ const onCreateError = error => (errorMessage = error.statusMessage || errorMessage);
57
60
  canvas.addEventListener('webglcontextcreationerror', onCreateError, false);
58
61
 
59
62
  // Create the desired context
60
- let gl: WebGLRenderingContext | null = null;
63
+ let gl: WebGLRenderingContext | WebGL2RenderingContext | null = null;
61
64
 
62
65
  if (props.type === 'webgl2') {
63
66
  props = {...props, webgl1: false};
@@ -67,11 +70,11 @@ export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas
67
70
  }
68
71
 
69
72
  // Prefer webgl2 over webgl1 if both are acceptable
70
- if (props.webgl2) {
71
- gl = gl || canvas.getContext('webgl2', props) as WebGL2RenderingContext | null;
73
+ if (!gl && props.webgl2) {
74
+ gl = canvas.getContext('webgl2', props) as WebGL2RenderingContext;
72
75
  }
73
- if (props.webgl1) {
74
- gl = gl || canvas.getContext('webgl', props) as WebGLRenderingContext | null;
76
+ if (!gl && props.webgl1) {
77
+ gl = canvas.getContext('webgl', props) as WebGLRenderingContext;
75
78
  }
76
79
 
77
80
  // TODO are we removing this listener before giving it a chance to fire?
@@ -88,12 +91,16 @@ export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas
88
91
  if (props.onContextLost) {
89
92
  // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
90
93
  const {onContextLost} = props;
91
- canvas.addEventListener('webglcontextlost',(event: Event) => onContextLost(event), false);
94
+ canvas.addEventListener('webglcontextlost', (event: Event) => onContextLost(event), false);
92
95
  }
93
96
  if (props.onContextRestored) {
94
97
  // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
95
98
  const {onContextRestored} = props;
96
- canvas.addEventListener('webglcontextrestored', (event: Event) => onContextRestored(event), false);
99
+ canvas.addEventListener(
100
+ 'webglcontextrestored',
101
+ (event: Event) => onContextRestored(event),
102
+ false
103
+ );
97
104
  }
98
105
 
99
106
  return gl;
@@ -2,7 +2,7 @@
2
2
  // Also knows default values of all parameters, enabling fast cache initialization
3
3
  // Provides base functionality for the state caching.
4
4
  import {Device} from '@luma.gl/api';
5
- import type {GLParameters} from '../../types/webgl';
5
+ import type {GLParameters} from '@luma.gl/constants';
6
6
  import {
7
7
  GL_PARAMETER_DEFAULTS,
8
8
  GL_PARAMETER_SETTERS,
@@ -1,7 +1,7 @@
1
1
  // Tables describing WebGL parameters
2
- import GL from '@luma.gl/constants';
2
+ import {GL, GLParameters} from '@luma.gl/constants';
3
3
  import {isWebGL2} from '../context/webgl-checks';
4
- import type {GLParameters} from '../../types/webgl';
4
+
5
5
  // DEFAULT SETTINGS - FOR FAST CACHE INITIALIZATION AND CONTEXT RESETS
6
6
 
7
7
  /* eslint-disable no-shadow */
package/src/index.ts CHANGED
@@ -33,7 +33,7 @@ export type {RenderbufferProps} from './adapter/objects/webgl-renderbuffer';
33
33
  export {WEBGLRenderbuffer} from './adapter/objects/webgl-renderbuffer';
34
34
  export {WEBGLVertexArrayObject} from './adapter/objects/webgl-vertex-array-object';
35
35
 
36
- // WebGL adapter classes (Legacy, will be moved to gltools)
36
+ // WebGL adapter classes (Legacy, will be moved to webgl-legacy)
37
37
  export {Accessor} from './classic/accessor';
38
38
  export type {AccessorObject} from './types';
39
39
  export type {ClassicBufferProps, ClassicBufferProps as BufferProps} from './classic/buffer';
@@ -51,7 +51,7 @@ export {
51
51
 
52
52
  export {setDeviceParameters, withDeviceParameters} from './adapter/converters/device-parameters';
53
53
 
54
- export type {GLParameters} from './types/webgl';
54
+ export type {GLParameters} from '@luma.gl/constants';
55
55
  export {
56
56
  getParameters,
57
57
  setParameters,
@@ -74,4 +74,11 @@ export {polyfillContext} from './context/polyfill/polyfill-context';
74
74
 
75
75
  // HELPERS - EXPERIMENTAL
76
76
  export {getShaderLayout, getProgramBindings} from './adapter/helpers/get-shader-layout';
77
- export {_checkFloat32ColorAttachment} from './adapter/converters/texture-formats';
77
+ export {convertGLToTextureFormat, _checkFloat32ColorAttachment} from './adapter/converters/texture-formats';
78
+
79
+ // TEST EXPORTS
80
+ export {TEXTURE_FORMATS as _TEXTURE_FORMATS} from './adapter/converters/texture-formats';
81
+
82
+ // DEPRECATED EXPORTS
83
+ export {clear} from './classic/clear';
84
+ export {readPixelsToBuffer, readPixelsToArray} from './classic/copy-and-blit';
@@ -1,16 +0,0 @@
1
- import GL from '@luma.gl/constants';
2
- export declare function isRenderbufferFormatSupported(gl: WebGLRenderingContext, format: GL): boolean;
3
- export declare function getRenderbufferFormatBytesPerPixel(format: GL): number;
4
- /**
5
- * @param bpp "bytes per pixel", used for memory usage calculations.
6
- * @param gl2 requires WebGL2
7
- * @param ext requires extension
8
- */
9
- declare type RenderbufferFormat = {
10
- bpp: number;
11
- gl2?: boolean;
12
- ext?: string;
13
- };
14
- export declare const RENDERBUFFER_FORMATS: Record<string, RenderbufferFormat>;
15
- export {};
16
- //# sourceMappingURL=renderbuffer-formats.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderbuffer-formats.d.ts","sourceRoot":"","sources":["../../../src/adapter/converters/renderbuffer-formats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGpC,wBAAgB,6BAA6B,CAAC,EAAE,EAAE,qBAAqB,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,CAa5F;AAED,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,CAErE;AAKD;;;;GAIG;AACH,aAAK,kBAAkB,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAqDnE,CAAC"}
@@ -1,180 +0,0 @@
1
- import GL from '@luma.gl/constants';
2
- import { isWebGL2 } from "../../context/context/webgl-checks.js";
3
- export function isRenderbufferFormatSupported(gl, format) {
4
- const info = RENDERBUFFER_FORMATS[format];
5
- if (!info) {
6
- return false;
7
- }
8
- if (info.ext) {
9
- return Boolean(gl.getExtension(info.ext));
10
- }
11
- if (info.gl2) {
12
- return isWebGL2(gl);
13
- }
14
- return true;
15
- }
16
- export function getRenderbufferFormatBytesPerPixel(format) {
17
- return RENDERBUFFER_FORMATS[format].bpp;
18
- }
19
- const EXT_FLOAT_WEBGL2 = 'EXT_color_buffer_float';
20
- export const RENDERBUFFER_FORMATS = {
21
- [GL.DEPTH_COMPONENT16]: {
22
- bpp: 2
23
- },
24
- [GL.DEPTH_COMPONENT24]: {
25
- gl2: true,
26
- bpp: 3
27
- },
28
- [GL.DEPTH_COMPONENT32F]: {
29
- gl2: true,
30
- bpp: 4
31
- },
32
- [GL.STENCIL_INDEX8]: {
33
- bpp: 1
34
- },
35
- [GL.DEPTH_STENCIL]: {
36
- bpp: 4
37
- },
38
- [GL.DEPTH24_STENCIL8]: {
39
- gl2: true,
40
- bpp: 4
41
- },
42
- [GL.DEPTH32F_STENCIL8]: {
43
- gl2: true,
44
- bpp: 5
45
- },
46
- [GL.RGBA4]: {
47
- bpp: 2
48
- },
49
- [GL.RGB565]: {
50
- bpp: 2
51
- },
52
- [GL.RGB5_A1]: {
53
- bpp: 2
54
- },
55
- [GL.R8]: {
56
- gl2: true,
57
- bpp: 1
58
- },
59
- [GL.R8UI]: {
60
- gl2: true,
61
- bpp: 1
62
- },
63
- [GL.R8I]: {
64
- gl2: true,
65
- bpp: 1
66
- },
67
- [GL.R16UI]: {
68
- gl2: true,
69
- bpp: 2
70
- },
71
- [GL.R16I]: {
72
- gl2: true,
73
- bpp: 2
74
- },
75
- [GL.R32UI]: {
76
- gl2: true,
77
- bpp: 4
78
- },
79
- [GL.R32I]: {
80
- gl2: true,
81
- bpp: 4
82
- },
83
- [GL.RG8]: {
84
- gl2: true,
85
- bpp: 2
86
- },
87
- [GL.RG8UI]: {
88
- gl2: true,
89
- bpp: 2
90
- },
91
- [GL.RG8I]: {
92
- gl2: true,
93
- bpp: 2
94
- },
95
- [GL.RG16UI]: {
96
- gl2: true,
97
- bpp: 4
98
- },
99
- [GL.RG16I]: {
100
- gl2: true,
101
- bpp: 4
102
- },
103
- [GL.RG32UI]: {
104
- gl2: true,
105
- bpp: 8
106
- },
107
- [GL.RG32I]: {
108
- gl2: true,
109
- bpp: 8
110
- },
111
- [GL.RGB8]: {
112
- gl2: true,
113
- bpp: 3
114
- },
115
- [GL.RGBA8]: {
116
- gl2: true,
117
- bpp: 4
118
- },
119
- [GL.RGB10_A2]: {
120
- gl2: true,
121
- bpp: 4
122
- },
123
- [GL.RGBA8UI]: {
124
- gl2: true,
125
- bpp: 4
126
- },
127
- [GL.RGBA8I]: {
128
- gl2: true,
129
- bpp: 4
130
- },
131
- [GL.RGB10_A2UI]: {
132
- gl2: true,
133
- bpp: 4
134
- },
135
- [GL.RGBA16UI]: {
136
- gl2: true,
137
- bpp: 8
138
- },
139
- [GL.RGBA16I]: {
140
- gl2: true,
141
- bpp: 8
142
- },
143
- [GL.RGBA32I]: {
144
- gl2: true,
145
- bpp: 16
146
- },
147
- [GL.RGBA32UI]: {
148
- gl2: true,
149
- bpp: 16
150
- },
151
- [GL.R16F]: {
152
- ext: EXT_FLOAT_WEBGL2,
153
- bpp: 2
154
- },
155
- [GL.RG16F]: {
156
- ext: EXT_FLOAT_WEBGL2,
157
- bpp: 4
158
- },
159
- [GL.RGBA16F]: {
160
- ext: EXT_FLOAT_WEBGL2,
161
- bpp: 8
162
- },
163
- [GL.R32F]: {
164
- ext: EXT_FLOAT_WEBGL2,
165
- bpp: 4
166
- },
167
- [GL.RG32F]: {
168
- ext: EXT_FLOAT_WEBGL2,
169
- bpp: 8
170
- },
171
- [GL.RGBA32F]: {
172
- ext: EXT_FLOAT_WEBGL2,
173
- bpp: 16
174
- },
175
- [GL.R11F_G11F_B10F]: {
176
- ext: EXT_FLOAT_WEBGL2,
177
- bpp: 4
178
- }
179
- };
180
- //# sourceMappingURL=renderbuffer-formats.js.map