@luma.gl/webgl 9.0.0-alpha.25 → 9.0.0-alpha.26

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.
@@ -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;AAC3C,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,aAAa;IACnD,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;IAS1D,qBAAqB,IAAI,gBAAgB;IAOzC,sDAAsD;IACtD,MAAM;IAQN;;;;;;;;;;;OAWG;IACH,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;IAc7F,MAAM;CAOP"}
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,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,aAAa;IACnD,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;IAS1D,qBAAqB,IAAI,gBAAgB;IAOzC,sDAAsD;IACtD,MAAM;IAQN;;;;;;;;;;;OAWG;IACH,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;IAe7F,MAAM;CAOP"}
@@ -28,6 +28,7 @@ export class WebGLCanvasContext extends CanvasContext {
28
28
  }
29
29
  resize(options) {
30
30
  if (this.canvas) {
31
+ const devicePixelRatio = this.getDevicePixelRatio(options === null || options === void 0 ? void 0 : options.useDevicePixels);
31
32
  this.setDevicePixelRatio(devicePixelRatio, options);
32
33
  return;
33
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-canvas-context.js","names":["CanvasContext","WEBGLFramebuffer","WebGLCanvasContext","constructor","device","props","_defineProperty","presentationSize","_setAutoCreatedCanvasId","concat","id","update","getCurrentFramebuffer","_framebuffer","handle","size","getPixelSize","sizeChanged","resize","options","canvas","setDevicePixelRatio","devicePixelRatio","ext","gl","getExtension","width","height","commit"],"sources":["../../src/adapter/webgl-canvas-context.ts"],"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 * A WebGL Canvas Context which manages the canvas and handles drawing buffer resizing etc \n */\nexport 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._setAutoCreatedCanvasId(`${this.device.id}-canvas`);\n this.update();\n }\n\n getCurrentFramebuffer(): WEBGLFramebuffer {\n this.update();\n // Setting handle to null returns a reference to the default framebuffer\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"],"mappings":";AAEA,SAAQA,aAAa,QAAO,cAAc;AAAC,SAEnCC,gBAAgB;AAKxB,OAAO,MAAMC,kBAAkB,SAASF,aAAa,CAAC;EAKpDG,WAAWA,CAACC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AAIA,OAAO,EAAE;MAC/DI,GAAG,CAACL,MAAM,CAACC,OAAO,CAACO,KAAK,EAAEP,OAAO,CAACQ,MAAM,CAAC;IAC3C;EACF;EAEAC,MAAMA,CAAA,EAAG,CAMT;AACF"}
1
+ {"version":3,"file":"webgl-canvas-context.js","names":["CanvasContext","WEBGLFramebuffer","WebGLCanvasContext","constructor","device","props","_defineProperty","presentationSize","_setAutoCreatedCanvasId","concat","id","update","getCurrentFramebuffer","_framebuffer","handle","size","getPixelSize","sizeChanged","resize","options","canvas","devicePixelRatio","getDevicePixelRatio","useDevicePixels","setDevicePixelRatio","ext","gl","getExtension","width","height","commit"],"sources":["../../src/adapter/webgl-canvas-context.ts"],"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 * A WebGL Canvas Context which manages the canvas and handles drawing buffer resizing etc \n */\nexport 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._setAutoCreatedCanvasId(`${this.device.id}-canvas`);\n this.update();\n }\n\n getCurrentFramebuffer(): WEBGLFramebuffer {\n this.update();\n // Setting handle to null returns a reference to the default framebuffer\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 const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);\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 the WebGL 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"],"mappings":";AAEA,SAAQA,aAAa,QAAO,cAAc;AAAC,SAEnCC,gBAAgB;AAKxB,OAAO,MAAMC,kBAAkB,SAASF,aAAa,CAAC;EAKpDG,WAAWA,CAACC,MAAmB,EAAEC,KAAyB,EAAE;IAE1D,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA;IAAAA,eAAA;IAAAA,eAAA,uBAJiC,IAAI;IAKlD,IAAI,CAACF,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACG,gBAAgB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,IAAI,CAACC,uBAAuB,IAAAC,MAAA,CAAI,IAAI,CAACL,MAAM,CAACM,EAAE,YAAS,CAAC;IACxD,IAAI,CAACC,MAAM,CAAC,CAAC;EACf;EAEAC,qBAAqBA,CAAA,EAAqB;IACxC,IAAI,CAACD,MAAM,CAAC,CAAC;IAEb,IAAI,CAACE,YAAY,GAAG,IAAI,CAACA,YAAY,IAAI,IAAIZ,gBAAgB,CAAC,IAAI,CAACG,MAAM,EAAE;MAACU,MAAM,EAAE;IAAI,CAAC,CAAC;IAC1F,OAAO,IAAI,CAACD,YAAY;EAC1B;EAGAF,MAAMA,CAAA,EAAG;IACP,MAAMI,IAAI,GAAG,IAAI,CAACC,YAAY,CAAC,CAAC;IAChC,MAAMC,WAAW,GAAGF,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAACR,gBAAgB,CAAC,CAAC,CAAC,IAAIQ,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAACR,gBAAgB,CAAC,CAAC,CAAC;IAChG,IAAIU,WAAW,EAAE;MACf,IAAI,CAACV,gBAAgB,GAAGQ,IAAI;IAC9B;EACF;EAcAG,MAAMA,CAACC,OAA+E,EAAQ;IAE5F,IAAI,IAAI,CAACC,MAAM,EAAE;MACf,MAAMC,gBAAgB,GAAG,IAAI,CAACC,mBAAmB,CAACH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEI,eAAe,CAAC;MAC3E,IAAI,CAACC,mBAAmB,CAACH,gBAAgB,EAAEF,OAAO,CAAC;MACnD;IACF;IAGA,MAAMM,GAAG,GAAG,IAAI,CAACrB,MAAM,CAACsB,EAAE,CAACC,YAAY,CAAC,8BAA8B,CAAC;IACvE,IAAIF,GAAG,IAAIN,OAAO,IAAI,OAAO,IAAIA,OAAO,IAAI,QAAQ,IAAIA,OAAO,EAAE;MAC/DM,GAAG,CAACP,MAAM,CAACC,OAAO,CAACS,KAAK,EAAET,OAAO,CAACU,MAAM,CAAC;IAC3C;EACF;EAEAC,MAAMA,CAAA,EAAG,CAMT;AACF"}
@@ -1,4 +1,5 @@
1
1
  import { Texture, Framebuffer, FramebufferProps } from '@luma.gl/api';
2
+ import { GL } from '@luma.gl/constants';
2
3
  import { BufferWithAccessor as Buffer } from './buffer-with-accessor';
3
4
  /**
4
5
  * Copies data from a type or a Texture object into ArrayBuffer object.
@@ -24,6 +25,7 @@ export declare function readPixelsToArray(source: Framebuffer | Texture, options
24
25
  /**
25
26
  * Copies data from a Framebuffer or a Texture object into a Buffer object.
26
27
  * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
28
+ * @deprecated Use CommandEncoder
27
29
  * @param source
28
30
  * @param options
29
31
  */
@@ -37,6 +39,21 @@ export declare function readPixelsToBuffer(source: Framebuffer | Texture, option
37
39
  sourceHeight?: number;
38
40
  sourceType?: number;
39
41
  }): Buffer;
42
+ /**
43
+ * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
44
+ * @deprecated Use CommandEncoder
45
+ */
46
+ export declare function copyToTexture(source: Framebuffer | Texture, target: Texture | GL, options?: {
47
+ sourceX?: number;
48
+ sourceY?: number;
49
+ targetX?: number;
50
+ targetY?: number;
51
+ targetZ?: number;
52
+ targetMipmaplevel?: number;
53
+ targetInternalFormat?: number;
54
+ width?: number;
55
+ height?: number;
56
+ }): Texture;
40
57
  /**
41
58
  * Wraps a given texture into a framebuffer object, that can be further used
42
59
  * to read data from the texture object.
@@ -1 +1 @@
1
- {"version":3,"file":"copy-and-blit.d.ts","sourceRoot":"","sources":["../../src/classic/copy-and-blit.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAG5E,OAAO,EAAC,kBAAkB,IAAI,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAOpE;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,GAAG,OAAO,EAC7B,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;IAEjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EA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AC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,UAAU,GAAG,WAAW,GAAG,YAAY,CA0CzC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,GAAG,OAAO,EAC7B,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,MAAM,CA2CR;AAED;;;GAGG;AAEH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,GAAG,OAAO,EAC7B,MAAM,EAAE,OAAO,GAAG,EAAE,EACpB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GACA,OAAO,CAgGT;AAYD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,gBAAgB,GAAG,WAAW,CAarF"}
@@ -1,4 +1,4 @@
1
- import { assert, Framebuffer } from '@luma.gl/api';
1
+ import { assert, Texture, Framebuffer } from '@luma.gl/api';
2
2
  import { GL } from '@luma.gl/constants';
3
3
  import { BufferWithAccessor as Buffer } from "./buffer-with-accessor.js";
4
4
  import { withParameters } from "../context/state-tracker/with-parameters.js";
@@ -94,6 +94,72 @@ export function readPixelsToBuffer(source, options) {
94
94
  }
95
95
  return target;
96
96
  }
97
+ export function copyToTexture(source, target, options) {
98
+ const {
99
+ sourceX = 0,
100
+ sourceY = 0,
101
+ targetMipmaplevel = 0,
102
+ targetInternalFormat = GL.RGBA
103
+ } = options || {};
104
+ let {
105
+ targetX,
106
+ targetY,
107
+ targetZ,
108
+ width,
109
+ height
110
+ } = options || {};
111
+ const {
112
+ framebuffer,
113
+ deleteFramebuffer
114
+ } = getFramebuffer(source);
115
+ assert(framebuffer);
116
+ const webglFramebuffer = framebuffer;
117
+ const {
118
+ device,
119
+ handle
120
+ } = webglFramebuffer;
121
+ const isSubCopy = typeof targetX !== 'undefined' || typeof targetY !== 'undefined' || typeof targetZ !== 'undefined';
122
+ targetX = targetX || 0;
123
+ targetY = targetY || 0;
124
+ targetZ = targetZ || 0;
125
+ const prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
126
+ assert(target);
127
+ let texture = null;
128
+ let textureTarget;
129
+ if (target instanceof Texture) {
130
+ texture = target;
131
+ width = Number.isFinite(width) ? width : texture.width;
132
+ height = Number.isFinite(height) ? height : texture.height;
133
+ texture.bind(0);
134
+ textureTarget = texture.target;
135
+ } else {
136
+ textureTarget = target;
137
+ }
138
+ if (!isSubCopy) {
139
+ device.gl.copyTexImage2D(textureTarget, targetMipmaplevel, targetInternalFormat, sourceX, sourceY, width, height, 0);
140
+ } else {
141
+ switch (textureTarget) {
142
+ case GL.TEXTURE_2D:
143
+ case GL.TEXTURE_CUBE_MAP:
144
+ device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
145
+ break;
146
+ case GL.TEXTURE_2D_ARRAY:
147
+ case GL.TEXTURE_3D:
148
+ device.assertWebGL2();
149
+ device.gl2.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
150
+ break;
151
+ default:
152
+ }
153
+ }
154
+ if (texture) {
155
+ texture.unbind();
156
+ }
157
+ gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
158
+ if (deleteFramebuffer) {
159
+ framebuffer.destroy();
160
+ }
161
+ return texture;
162
+ }
97
163
  function getFramebuffer(source) {
98
164
  if (!(source instanceof Framebuffer)) {
99
165
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"copy-and-blit.js","names":["assert","Framebuffer","GL","BufferWithAccessor","Buffer","withParameters","getGLTypeFromTypedArray","getTypedArrayFromGLType","glFormatToComponents","glTypeToBytes","readPixelsToArray","source","options","sourceX","sourceY","sourceFormat","RGBA","sourceAttachment","COLOR_ATTACHMENT0","target","sourceWidth","sourceHeight","sourceType","framebuffer","deleteFramebuffer","getFramebuffer","gl","handle","width","height","FRONT","attachment","colorAttachments","type","getPixelArray","prevHandle","bindFramebuffer","FRAMEBUFFER","readPixels","destroy","readPixelsToBuffer","targetByteOffset","webglFramebuffer","gl2","device","assertWebGL2","UNSIGNED_BYTE","components","byteCount","byteLength","accessor","size","bind","PIXEL_PACK_BUFFER","unbind","toFramebuffer","texture","props","id","createFramebuffer","concat","pixelArray","format","ArrayType","clamped"],"sources":["../../src/classic/copy-and-blit.ts"],"sourcesContent":["// luma.gl, MIT license\nimport {assert, Texture, Framebuffer, FramebufferProps} from '@luma.gl/api';\nimport {GL} from '@luma.gl/constants';\n\nimport {BufferWithAccessor as Buffer} from './buffer-with-accessor';\nimport {WEBGLTexture} from '../adapter/resources/webgl-texture';\nimport {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';\nimport {withParameters} from '../context/state-tracker/with-parameters';\nimport {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';\nimport {glFormatToComponents, glTypeToBytes} from './format-utils';\n\n/**\n * Copies data from a type or a Texture object into ArrayBuffer object.\n * App can provide targetPixelArray or have it auto allocated by this method\n * newly allocated by this method unless provided by app.\n * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read\n * @note Slow requires roundtrip to GPU\n *\n * @param source\n * @param options\n * @returns pixel array,\n */\nexport function readPixelsToArray(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n sourceAttachment?: number;\n target?: Uint8Array | Uint16Array | Float32Array;\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Uint8Array | Uint16Array | Float32Array {\n const {sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA} = options || {};\n let {\n sourceAttachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer\n target = null,\n // following parameters are auto deduced if not provided\n sourceWidth,\n sourceHeight,\n sourceType\n } = options || {};\n\n const {framebuffer, deleteFramebuffer} = getFramebuffer(source);\n assert(framebuffer);\n const {gl, handle} = framebuffer as WEBGLFramebuffer;\n sourceWidth = sourceWidth || framebuffer.width;\n sourceHeight = sourceHeight || framebuffer.height;\n\n // TODO - Set and unset gl.readBuffer\n if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {\n sourceAttachment = GL.FRONT;\n }\n\n const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;\n // assert(attachments[sourceAttachment]);\n\n // Deduce the type from color attachment if not provided.\n sourceType = sourceType || (framebuffer.colorAttachments[attachment] as WEBGLTexture).type;\n\n // Deduce type and allocated pixelArray if needed\n target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);\n\n // Pixel array available, if necessary, deduce type from it.\n sourceType = sourceType || getGLTypeFromTypedArray(target);\n\n const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);\n gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);\n // @ts-expect-error\n gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (deleteFramebuffer) {\n framebuffer.destroy();\n }\n return target;\n}\n\n/**\n * Copies data from a Framebuffer or a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.\n * @param source\n * @param options\n */\nexport function readPixelsToBuffer(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n target?: Buffer; // A new Buffer object is created when not provided.\n targetByteOffset?: number; // byte offset in buffer object\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Buffer {\n const {sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, targetByteOffset = 0} = options || {};\n // following parameters are auto deduced if not provided\n let {target, sourceWidth, sourceHeight, sourceType} = options || {};\n const {framebuffer, deleteFramebuffer} = getFramebuffer(source);\n assert(framebuffer);\n sourceWidth = sourceWidth || framebuffer.width;\n sourceHeight = sourceHeight || framebuffer.height;\n\n // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature\n const webglFramebuffer = framebuffer as WEBGLFramebuffer;\n const gl2 = webglFramebuffer.device.assertWebGL2();\n\n // deduce type if not available.\n sourceType = sourceType || (target ? target.type : GL.UNSIGNED_BYTE);\n\n if (!target) {\n // Create new buffer with enough size\n const components = glFormatToComponents(sourceFormat);\n const byteCount = glTypeToBytes(sourceType);\n const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;\n target = new Buffer(gl2, {byteLength, accessor: {type: sourceType, size: components}});\n }\n\n // @ts-expect-error\n target.bind({target: GL.PIXEL_PACK_BUFFER});\n withParameters(gl2, {framebuffer}, () => {\n gl2.readPixels(\n sourceX,\n sourceY,\n sourceWidth,\n sourceHeight,\n sourceFormat,\n sourceType,\n targetByteOffset\n );\n });\n target.unbind({target: GL.PIXEL_PACK_BUFFER});\n if (deleteFramebuffer) {\n framebuffer.destroy();\n }\n\n return target;\n}\n\nfunction getFramebuffer(source: Texture | Framebuffer): {\n framebuffer: Framebuffer;\n deleteFramebuffer: boolean;\n} {\n if (!(source instanceof Framebuffer)) {\n return {framebuffer: toFramebuffer(source), deleteFramebuffer: true};\n }\n return {framebuffer: source, deleteFramebuffer: false};\n}\n\n/**\n * Wraps a given texture into a framebuffer object, that can be further used\n * to read data from the texture object.\n */\nexport function toFramebuffer(texture: Texture, props?: FramebufferProps): Framebuffer {\n const {device, width, height, id} = texture;\n const framebuffer = device.createFramebuffer({\n ...props,\n id: `framebuffer-for-${id}`,\n width,\n height,\n colorAttachments: [\n texture\n ]\n }\n );\n return framebuffer;\n}\n\nfunction getPixelArray(\n pixelArray,\n type,\n format,\n width: number,\n height: number\n): Uint8Array | Uint16Array | Float32Array {\n if (pixelArray) {\n return pixelArray;\n }\n // Allocate pixel array if not already available, using supplied type\n type = type || GL.UNSIGNED_BYTE;\n const ArrayType = getTypedArrayFromGLType(type, {clamped: false});\n const components = glFormatToComponents(format);\n // TODO - check for composite type (components = 1).\n return new ArrayType(width * height * components) as Uint8Array | Uint16Array | Float32Array;\n}\n"],"mappings":"AACA,SAAQA,MAAM,EAAWC,WAAW,QAAyB,cAAc;AAC3E,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAE9BC,kBAAkB,IAAIC,MAAM;AAAA,SAG5BC,cAAc;AAAA,SACdC,uBAAuB,EAAEC,uBAAuB;AAAA,SAChDC,oBAAoB,EAAEC,aAAa;AAa3C,OAAO,SAASC,iBAAiBA,CAC/BC,MAA6B,EAC7BC,OAUC,EACwC;EACzC,MAAM;IAACC,OAAO,GAAG,CAAC;IAAEC,OAAO,GAAG,CAAC;IAAEC,YAAY,GAAGb,EAAE,CAACc;EAAI,CAAC,GAAGJ,OAAO,IAAI,CAAC,CAAC;EACxE,IAAI;IACFK,gBAAgB,GAAGf,EAAE,CAACgB,iBAAiB;IACvCC,MAAM,GAAG,IAAI;IAEbC,WAAW;IACXC,YAAY;IACZC;EACF,CAAC,GAAGV,OAAO,IAAI,CAAC,CAAC;EAEjB,MAAM;IAACW,WAAW;IAAEC;EAAiB,CAA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,MAAM,CAAC;EAE/C,OAAO,IAAIC,SAAS,CAACnC,KAAK,GAAGC,MAAM,GAAGkB,UAAU,CAAC;AACnD"}
1
+ {"version":3,"file":"copy-and-blit.js","names":["assert","Texture","Framebuffer","GL","BufferWithAccessor","Buffer","withParameters","getGLTypeFromTypedArray","getTypedArrayFromGLType","glFormatToComponents","glTypeToBytes","readPixelsToArray","source","options","sourceX","sourceY","sourceFormat","RGBA","sourceAttachment","COLOR_ATTACHMENT0","target","sourceWidth","sourceHeight","sourceType","framebuffer","deleteFramebuffer","getFramebuffer","gl","handle","width","height","FRONT","attachment","colorAttachments","type","getPixelArray","prevHandle","bindFramebuffer","FRAMEBUFFER","readPixels","destroy","readPixelsToBuffer","targetByteOffset","webglFramebuffer","gl2","device","assertWebGL2","UNSIGNED_BYTE","components","byteCount","byteLength","accessor","size","bind","PIXEL_PACK_BUFFER","unbind","copyToTexture","targetMipmaplevel","targetInternalFormat","targetX","targetY","targetZ","isSubCopy","texture","textureTarget","Number","isFinite","copyTexImage2D","TEXTURE_2D","TEXTURE_CUBE_MAP","copyTexSubImage2D","TEXTURE_2D_ARRAY","TEXTURE_3D","copyTexSubImage3D","toFramebuffer","props","id","createFramebuffer","concat","pixelArray","format","ArrayType","clamped"],"sources":["../../src/classic/copy-and-blit.ts"],"sourcesContent":["// luma.gl, MIT license\nimport {assert, Texture, Framebuffer, FramebufferProps} from '@luma.gl/api';\nimport {GL} from '@luma.gl/constants';\n\nimport {BufferWithAccessor as Buffer} from './buffer-with-accessor';\nimport {WEBGLTexture} from '../adapter/resources/webgl-texture';\nimport {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';\nimport {withParameters} from '../context/state-tracker/with-parameters';\nimport {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';\nimport {glFormatToComponents, glTypeToBytes} from './format-utils';\n\n/**\n * Copies data from a type or a Texture object into ArrayBuffer object.\n * App can provide targetPixelArray or have it auto allocated by this method\n * newly allocated by this method unless provided by app.\n * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read\n * @note Slow requires roundtrip to GPU\n *\n * @param source\n * @param options\n * @returns pixel array,\n */\nexport function readPixelsToArray(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n sourceAttachment?: number;\n target?: Uint8Array | Uint16Array | Float32Array;\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Uint8Array | Uint16Array | Float32Array {\n const {sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA} = options || {};\n let {\n sourceAttachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer\n target = null,\n // following parameters are auto deduced if not provided\n sourceWidth,\n sourceHeight,\n sourceType\n } = options || {};\n\n const {framebuffer, deleteFramebuffer} = getFramebuffer(source);\n assert(framebuffer);\n const {gl, handle} = framebuffer as WEBGLFramebuffer;\n sourceWidth = sourceWidth || framebuffer.width;\n sourceHeight = sourceHeight || framebuffer.height;\n\n // TODO - Set and unset gl.readBuffer\n if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {\n sourceAttachment = GL.FRONT;\n }\n\n const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;\n // assert(attachments[sourceAttachment]);\n\n // Deduce the type from color attachment if not provided.\n sourceType = sourceType || (framebuffer.colorAttachments[attachment] as WEBGLTexture).type;\n\n // Deduce type and allocated pixelArray if needed\n target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);\n\n // Pixel array available, if necessary, deduce type from it.\n sourceType = sourceType || getGLTypeFromTypedArray(target);\n\n const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);\n gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);\n // @ts-expect-error\n gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (deleteFramebuffer) {\n framebuffer.destroy();\n }\n return target;\n}\n\n/**\n * Copies data from a Framebuffer or a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.\n * @deprecated Use CommandEncoder\n * @param source\n * @param options\n */\nexport function readPixelsToBuffer(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n target?: Buffer; // A new Buffer object is created when not provided.\n targetByteOffset?: number; // byte offset in buffer object\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Buffer {\n const {sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, targetByteOffset = 0} = options || {};\n // following parameters are auto deduced if not provided\n let {target, sourceWidth, sourceHeight, sourceType} = options || {};\n const {framebuffer, deleteFramebuffer} = getFramebuffer(source);\n assert(framebuffer);\n sourceWidth = sourceWidth || framebuffer.width;\n sourceHeight = sourceHeight || framebuffer.height;\n\n // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature\n const webglFramebuffer = framebuffer as WEBGLFramebuffer;\n const gl2 = webglFramebuffer.device.assertWebGL2();\n\n // deduce type if not available.\n sourceType = sourceType || (target ? target.type : GL.UNSIGNED_BYTE);\n\n if (!target) {\n // Create new buffer with enough size\n const components = glFormatToComponents(sourceFormat);\n const byteCount = glTypeToBytes(sourceType);\n const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;\n target = new Buffer(gl2, {byteLength, accessor: {type: sourceType, size: components}});\n }\n\n // @ts-expect-error\n target.bind({target: GL.PIXEL_PACK_BUFFER});\n withParameters(gl2, {framebuffer}, () => {\n gl2.readPixels(\n sourceX,\n sourceY,\n sourceWidth,\n sourceHeight,\n sourceFormat,\n sourceType,\n targetByteOffset\n );\n });\n target.unbind({target: GL.PIXEL_PACK_BUFFER});\n if (deleteFramebuffer) {\n framebuffer.destroy();\n }\n\n return target;\n}\n\n/**\n * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)\n * @deprecated Use CommandEncoder\n */\n// eslint-disable-next-line complexity, max-statements\nexport function copyToTexture(\n source: Framebuffer | Texture,\n target: Texture | GL,\n options?: {\n sourceX?: number;\n sourceY?: number;\n\n targetX?: number;\n targetY?: number;\n targetZ?: number;\n targetMipmaplevel?: number;\n targetInternalFormat?: number;\n\n width?: number; // defaults to target width\n height?: number; // defaults to target height\n }\n): Texture {\n const {\n sourceX = 0,\n sourceY = 0,\n // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer\n targetMipmaplevel = 0,\n targetInternalFormat = GL.RGBA\n } = options || {};\n let {\n targetX,\n targetY,\n targetZ,\n width, // defaults to target width\n height // defaults to target height\n } = options || {};\n\n const {framebuffer, deleteFramebuffer} = getFramebuffer(source);\n assert(framebuffer);\n const webglFramebuffer = framebuffer as WEBGLFramebuffer;\n const {device, handle} = webglFramebuffer;\n const isSubCopy =\n typeof targetX !== 'undefined' ||\n typeof targetY !== 'undefined' ||\n typeof targetZ !== 'undefined';\n targetX = targetX || 0;\n targetY = targetY || 0;\n targetZ = targetZ || 0;\n const prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);\n // TODO - support gl.readBuffer (WebGL2 only)\n // const prevBuffer = gl.readBuffer(attachment);\n assert(target);\n let texture = null;\n let textureTarget: GL;\n if (target instanceof Texture) {\n texture = target;\n width = Number.isFinite(width) ? width : texture.width;\n height = Number.isFinite(height) ? height : texture.height;\n texture.bind(0);\n textureTarget = texture.target;\n } else {\n textureTarget = target;\n }\n\n if (!isSubCopy) {\n device.gl.copyTexImage2D(\n textureTarget,\n targetMipmaplevel,\n targetInternalFormat,\n sourceX,\n sourceY,\n width,\n height,\n 0 /* border must be 0 */\n );\n } else {\n switch (textureTarget) {\n case GL.TEXTURE_2D:\n case GL.TEXTURE_CUBE_MAP:\n device.gl.copyTexSubImage2D(\n textureTarget,\n targetMipmaplevel,\n targetX,\n targetY,\n sourceX,\n sourceY,\n width,\n height\n );\n break;\n case GL.TEXTURE_2D_ARRAY:\n case GL.TEXTURE_3D:\n device.assertWebGL2();\n device.gl2.copyTexSubImage3D(\n textureTarget,\n targetMipmaplevel,\n targetX,\n targetY,\n targetZ,\n sourceX,\n sourceY,\n width,\n height\n );\n break;\n default:\n }\n }\n if (texture) {\n texture.unbind();\n }\n // @ts-expect-error\n gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (deleteFramebuffer) {\n framebuffer.destroy();\n }\n return texture;\n}\n\nfunction getFramebuffer(source: Texture | Framebuffer): {\n framebuffer: Framebuffer;\n deleteFramebuffer: boolean;\n} {\n if (!(source instanceof Framebuffer)) {\n return {framebuffer: toFramebuffer(source), deleteFramebuffer: true};\n }\n return {framebuffer: source, deleteFramebuffer: false};\n}\n\n/**\n * Wraps a given texture into a framebuffer object, that can be further used\n * to read data from the texture object.\n */\nexport function toFramebuffer(texture: Texture, props?: FramebufferProps): Framebuffer {\n const {device, width, height, id} = texture;\n const framebuffer = device.createFramebuffer({\n ...props,\n id: `framebuffer-for-${id}`,\n width,\n height,\n colorAttachments: [\n texture\n ]\n }\n );\n return framebuffer;\n}\n\nfunction getPixelArray(\n pixelArray,\n type,\n format,\n width: number,\n height: number\n): Uint8Array | Uint16Array | Float32Array {\n if (pixelArray) {\n return pixelArray;\n }\n // Allocate pixel array if not already available, using supplied type\n type = type || GL.UNSIGNED_BYTE;\n const ArrayType = getTypedArrayFromGLType(type, {clamped: false});\n const components = glFormatToComponents(format);\n // TODO - check for composite type (components = 1).\n return new ArrayType(width * height * components) as Uint8Array | Uint16Array | Float32Array;\n}\n"],"mappings":"AACA,SAAQA,MAAM,EAAEC,OAAO,EAAEC,WAAW,QAAyB,cAAc;AAC3E,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAE9BC,kBAAkB,IAAIC,MAAM;AAAA,SAG5BC,cAAc;AAAA,SACdC,uBAAuB,EAAEC,uBAAuB;AAAA,SAChDC,oBAAoB,EAAEC,aAAa;AAa3C,OAAO,SAASC,iBAAiBA,CAC/BC,MAA6B,EAC7BC,OAUC,EAC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