@luma.gl/webgl 9.0.0-alpha.44 → 9.0.0-alpha.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/device-helpers/device-features.js +1 -0
- package/dist/adapter/device-helpers/device-features.js.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.d.ts +6 -1
- package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
- package/dist/adapter/helpers/webgl-topology-utils.js +40 -0
- package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
- package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-buffer.js +2 -0
- package/dist/adapter/resources/webgl-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-command-buffer.js +6 -4
- package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +2 -0
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +4 -44
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/adapter/resources/webgl-transform-feedback.d.ts +53 -0
- package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -0
- package/dist/adapter/resources/webgl-transform-feedback.js +161 -0
- package/dist/adapter/resources/webgl-transform-feedback.js.map +1 -0
- package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-vertex-array.js +5 -3
- package/dist/adapter/resources/webgl-vertex-array.js.map +1 -1
- package/dist/adapter/webgl-device.d.ts +4 -2
- package/dist/adapter/webgl-device.d.ts.map +1 -1
- package/dist/adapter/webgl-device.js +7 -3
- package/dist/adapter/webgl-device.js.map +1 -1
- package/dist/classic/copy-and-blit.d.ts +3 -3
- package/dist/classic/copy-and-blit.d.ts.map +1 -1
- package/dist/classic/copy-and-blit.js +12 -20
- package/dist/classic/copy-and-blit.js.map +1 -1
- package/dist/dist.dev.js +2140 -2302
- package/dist/index.cjs +645 -806
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist.min.js +23 -22
- package/package.json +5 -5
- package/src/adapter/device-helpers/device-features.ts +1 -0
- package/src/adapter/helpers/webgl-topology-utils.ts +40 -0
- package/src/adapter/resources/webgl-buffer.ts +12 -8
- package/src/adapter/resources/webgl-command-buffer.ts +7 -13
- package/src/adapter/resources/webgl-render-pipeline.ts +11 -47
- package/src/adapter/resources/webgl-transform-feedback.ts +205 -0
- package/src/adapter/resources/webgl-vertex-array.ts +11 -8
- package/src/adapter/webgl-device.ts +10 -5
- package/src/classic/copy-and-blit.ts +16 -19
- package/src/index.ts +5 -4
- package/LICENSE +0 -34
- package/dist/classic/buffer-with-accessor.d.ts +0 -82
- package/dist/classic/buffer-with-accessor.d.ts.map +0 -1
- package/dist/classic/buffer-with-accessor.js +0 -314
- package/dist/classic/buffer-with-accessor.js.map +0 -1
- package/src/classic/buffer-with-accessor.ts +0 -466
|
@@ -11,7 +11,7 @@ import { WebGLCanvasContext } from "./webgl-canvas-context.js";
|
|
|
11
11
|
import { loadSpectorJS, initializeSpectorJS } from "../context/debug/spector.js";
|
|
12
12
|
import { loadWebGLDeveloperTools, makeDebugContext } from "../context/debug/webgl-developer-tools.js";
|
|
13
13
|
import { isTextureFormatSupported, isTextureFormatRenderable, isTextureFormatFilterable } from "./converters/texture-formats.js";
|
|
14
|
-
import {
|
|
14
|
+
import { WEBGLBuffer } from "./resources/webgl-buffer.js";
|
|
15
15
|
import { WEBGLShader } from "./resources/webgl-shader.js";
|
|
16
16
|
import { WEBGLSampler } from "./resources/webgl-sampler.js";
|
|
17
17
|
import { WEBGLTexture } from "./resources/webgl-texture.js";
|
|
@@ -20,6 +20,7 @@ import { WEBGLRenderPass } from "./resources/webgl-render-pass.js";
|
|
|
20
20
|
import { WEBGLRenderPipeline } from "./resources/webgl-render-pipeline.js";
|
|
21
21
|
import { WEBGLCommandEncoder } from "./resources/webgl-command-encoder.js";
|
|
22
22
|
import { WEBGLVertexArray } from "./resources/webgl-vertex-array.js";
|
|
23
|
+
import { WEBGLTransformFeedback } from "./resources/webgl-transform-feedback.js";
|
|
23
24
|
const LOG_LEVEL = 1;
|
|
24
25
|
export class WebGLDevice extends Device {
|
|
25
26
|
static isSupported() {
|
|
@@ -203,7 +204,7 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
|
|
|
203
204
|
}
|
|
204
205
|
createBuffer(props) {
|
|
205
206
|
const newProps = this._getBufferProps(props);
|
|
206
|
-
return new
|
|
207
|
+
return new WEBGLBuffer(this, newProps);
|
|
207
208
|
}
|
|
208
209
|
_createTexture(props) {
|
|
209
210
|
return new WEBGLTexture(this, props);
|
|
@@ -233,7 +234,10 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
|
|
|
233
234
|
throw new Error('ComputePipeline not supported in WebGL');
|
|
234
235
|
}
|
|
235
236
|
beginComputePass(props) {
|
|
236
|
-
throw new Error('
|
|
237
|
+
throw new Error('ComputePass not supported in WebGL');
|
|
238
|
+
}
|
|
239
|
+
createTransformFeedback(props) {
|
|
240
|
+
return new WEBGLTransformFeedback(this, props);
|
|
237
241
|
}
|
|
238
242
|
getDefaultRenderPass() {
|
|
239
243
|
this.renderPass = this.renderPass || this.beginRenderPass({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-device.js","names":["Device","CanvasContext","log","uid","assert","isBrowser","polyfillContext","popContextState","pushContextState","trackContextState","createBrowserContext","createHeadlessContext","isHeadlessGLRegistered","getDeviceInfo","getDeviceFeatures","getDeviceLimits","getWebGLLimits","WebGLCanvasContext","loadSpectorJS","initializeSpectorJS","loadWebGLDeveloperTools","makeDebugContext","isTextureFormatSupported","isTextureFormatRenderable","isTextureFormatFilterable","BufferWithAccessor","WEBGLShader","WEBGLSampler","WEBGLTexture","WEBGLFramebuffer","WEBGLRenderPass","WEBGLRenderPipeline","WEBGLCommandEncoder","WEBGLVertexArray","LOG_LEVEL","WebGLDevice","isSupported","WebGLRenderingContext","features","_features","gl","limits","_limits","attach","device","isWebGL","Error","create","props","arguments","length","undefined","groupCollapsed","canvas","pageLoaded","get","debug","spector","probe","constructor","_props$gl","id","info","canvasContext","handle","lost","_resolveContextLost","renderPass","gl2","isWebGL1","isWebGL2","_canvasSizeInfo","clientWidth","clientHeight","devicePixelRatio","_extensions","_polyfilled","_webglLimits","_constants","Promise","resolve","onContextLost","event","_this$_resolveContext","call","reason","message","_version","enable","copyState","_len","args","Array","_key","webgl2","throwOnError","level","Math","max","warn","type","vendor","renderer","groupEnd","destroy","ext","getExtension","isLost","isContextLost","getSize","drawingBufferWidth","drawingBufferHeight","format","assertWebGL2","createCanvasContext","createBuffer","newProps","_getBufferProps","_createTexture","createExternalTexture","createSampler","createShader","createFramebuffer","createRenderPipeline","createVertexArray","beginRenderPass","createComputePipeline","beginComputePass","getDefaultRenderPass","framebuffer","getCurrentFramebuffer","createCommandEncoder","submit","_this$renderPass","end","webglLimits","loseDevice","_this$_resolveContext2","deviceLossTriggered","loseContext","pushState","popState","setSpectorMetadata","__SPECTOR_Metadata","getGLKey","value","number","Number","key","String","setConstantAttribute","location","constant","maxVertexAttributes","fill","currentConstant","compareConstantArrayValues","Float32Array","setConstantFloatArray","Int32Array","setConstantIntArray","Uint32Array","setConstantUintArray","WebGL2RenderingContext","Boolean","isFinite","array","vertexAttrib1fv","vertexAttrib2fv","vertexAttrib3fv","vertexAttrib4fv","_device$gl","vertexAttribI4iv","_device$gl2","vertexAttribI4uiv","v1","v2","i"],"sources":["../../src/adapter/webgl-device.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {\n DeviceProps,\n DeviceInfo,\n DeviceLimits,\n DeviceFeature,\n CanvasContextProps,\n TextureFormat,\n VertexArray,\n VertexArrayProps,\n TypedArray\n} from '@luma.gl/core';\nimport {Device, CanvasContext, log, uid, assert} from '@luma.gl/core';\nimport {isBrowser} from '@probe.gl/env';\nimport {polyfillContext} from '../context/polyfill/polyfill-context';\nimport {\n popContextState,\n pushContextState,\n trackContextState\n} from '../context/state-tracker/track-context-state';\nimport {createBrowserContext} from '../context/context/create-browser-context';\nimport {\n createHeadlessContext,\n isHeadlessGLRegistered\n} from '../context/context/create-headless-context';\nimport {getDeviceInfo} from './device-helpers/get-device-info';\nimport {getDeviceFeatures} from './device-helpers/device-features';\nimport {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';\nimport {WebGLCanvasContext} from './webgl-canvas-context';\nimport {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';\nimport {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';\nimport {\n isTextureFormatSupported,\n isTextureFormatRenderable,\n isTextureFormatFilterable\n} from './converters/texture-formats';\n\n// WebGL classes\nimport type {\n BufferProps,\n ShaderProps,\n // Sampler,\n SamplerProps,\n TextureProps,\n ExternalTexture,\n ExternalTextureProps,\n FramebufferProps,\n // RenderPipeline,\n RenderPipelineProps,\n ComputePipeline,\n ComputePipelineProps,\n // RenderPass,\n RenderPassProps,\n ComputePass,\n ComputePassProps,\n // CommandEncoder,\n CommandEncoderProps\n} from '@luma.gl/core';\n\nimport {BufferWithAccessor} from '../classic/buffer-with-accessor';\nimport {WEBGLBuffer} from './resources/webgl-buffer';\nimport {WEBGLShader} from './resources/webgl-shader';\nimport {WEBGLSampler} from './resources/webgl-sampler';\nimport {WEBGLTexture} from './resources/webgl-texture';\nimport {WEBGLFramebuffer} from './resources/webgl-framebuffer';\nimport {WEBGLRenderPass} from './resources/webgl-render-pass';\nimport {WEBGLRenderPipeline} from './resources/webgl-render-pipeline';\nimport {WEBGLCommandEncoder} from './resources/webgl-command-encoder';\nimport {WEBGLVertexArray} from './resources/webgl-vertex-array';\n\nconst LOG_LEVEL = 1;\n\n/** WebGPU style Device API for a WebGL context */\nexport class WebGLDevice extends Device {\n //\n // Public `Device` API\n //\n\n static type: string = 'webgl';\n\n static isSupported(): boolean {\n return typeof WebGLRenderingContext !== 'undefined' || isHeadlessGLRegistered();\n }\n\n readonly info: DeviceInfo;\n readonly canvasContext: WebGLCanvasContext;\n\n readonly handle: WebGLRenderingContext;\n\n get features(): Set<DeviceFeature> {\n this._features = this._features || getDeviceFeatures(this.gl);\n return this._features;\n }\n\n get limits(): DeviceLimits {\n this._limits = this._limits || getDeviceLimits(this.gl);\n return this._limits;\n }\n\n readonly lost: Promise<{reason: 'destroyed'; message: string}>;\n\n private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;\n private _features?: Set<DeviceFeature>;\n private _limits?: DeviceLimits;\n\n //\n // Static methods, expected to be present by `luma.createDevice()`\n //\n\n /**\n * Get a device instance from a GL context\n * Creates and instruments the device if not already created\n * @param gl\n * @returns\n */\n static attach(gl: Device | WebGLRenderingContext | WebGL2RenderingContext): WebGLDevice {\n if (gl instanceof WebGLDevice) {\n return gl;\n }\n // @ts-expect-error\n if (gl?.device instanceof Device) {\n // @ts-expect-error\n return gl.device as WebGLDevice;\n }\n if (!isWebGL(gl)) {\n throw new Error('Invalid WebGLRenderingContext');\n }\n return new WebGLDevice({gl: gl as WebGLRenderingContext});\n }\n\n static async create(props: DeviceProps = {}): Promise<WebGLDevice> {\n log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created');\n\n // Wait for page to load. Only wait when props. canvas is string\n // to avoid setting page onload callback unless necessary\n if (typeof props.canvas === 'string') {\n await CanvasContext.pageLoaded;\n }\n\n // Load webgl and spector debug scripts from CDN if requested\n if (log.get('debug') || props.debug) {\n await loadWebGLDeveloperTools();\n }\n\n // @ts-expect-error spector not on props\n const {spector} = props;\n if (log.get('spector') || spector) {\n await loadSpectorJS();\n }\n\n log.probe(LOG_LEVEL + 1, 'DOM is loaded')();\n\n // @ts-expect-error\n if (props.gl && props.gl.device) {\n return WebGLDevice.attach(props.gl);\n }\n\n return new WebGLDevice(props);\n }\n\n //\n // Public API\n //\n\n constructor(props: DeviceProps) {\n super({...props, id: props.id || uid('webgl-device')});\n\n // If attaching to an already attached context, return the attached device\n // @ts-expect-error device is attached to context\n const device: WebGLDevice | undefined = props.gl?.device;\n if (device) {\n throw new Error(`WebGL context already attached to device ${device.id}`);\n }\n\n // Create and instrument context\n this.canvasContext = new WebGLCanvasContext(this, props);\n\n this.lost = new Promise<{reason: 'destroyed'; message: string}>(resolve => {\n this._resolveContextLost = resolve;\n });\n\n const onContextLost = (event: Event) =>\n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'\n });\n\n let gl: WebGLRenderingContext | WebGL2RenderingContext | null = props.gl || null;\n gl =\n gl ||\n (isBrowser()\n ? createBrowserContext(this.canvasContext.canvas, {...props, onContextLost})\n : null);\n gl = gl || (!isBrowser() ? createHeadlessContext({...props, onContextLost}) : null);\n\n if (!gl) {\n throw new Error('WebGL context creation failed');\n }\n\n this.handle = gl;\n this.gl = this.handle;\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.isWebGL2 = isWebGL2(this.gl);\n this.isWebGL1 = !this.isWebGL2;\n\n // luma Device fields\n this.info = getDeviceInfo(this.gl);\n\n // @ts-expect-error Link webgl context back to device\n this.gl.device = this;\n // @ts-expect-error Annotate webgl context to handle\n this.gl._version = this.isWebGL2 ? 2 : 1;\n\n // Add subset of WebGL2 methods to WebGL1 context\n polyfillContext(this.gl);\n\n // Install context state tracking\n // @ts-expect-error - hidden parameters\n const {enable = true, copyState = false} = props;\n trackContextState(this.gl, {\n enable,\n copyState,\n log: (...args: any[]) => log.log(1, ...args)()\n });\n\n // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1\n if (isBrowser() && props.debug) {\n this.gl = makeDebugContext(this.gl, {...props, webgl2: this.isWebGL2, throwOnError: true});\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.debug = true;\n log.level = Math.max(log.level, 1);\n log.warn('WebGL debug mode activated. Performance reduced.')();\n }\n\n // @ts-expect-error spector not on props\n if (isBrowser() && props.spector) {\n const canvas = this.handle.canvas || (props.canvas as HTMLCanvasElement);\n this.spector = initializeSpectorJS({...this.props, canvas});\n }\n\n // Log some debug info about the newly created context\n const message = `\\\nCreated ${this.info.type}${this.debug ? ' debug' : ''} context: \\\n${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`;\n log.probe(LOG_LEVEL, message)();\n\n log.groupEnd(LOG_LEVEL)();\n }\n\n /**\n * Destroys the context\n * @note Has no effect for browser contexts, there is no browser API for destroying contexts\n */\n destroy(): void {\n const ext = this.gl.getExtension('STACKGL_destroy_context');\n if (ext) {\n ext.destroy();\n }\n }\n\n get isLost(): boolean {\n return this.gl.isContextLost();\n }\n\n getSize(): [number, number] {\n return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];\n }\n\n isTextureFormatSupported(format: TextureFormat): boolean {\n return isTextureFormatSupported(this.gl, format);\n }\n\n isTextureFormatFilterable(format: TextureFormat): boolean {\n return isTextureFormatFilterable(this.gl, format);\n }\n\n isTextureFormatRenderable(format: TextureFormat): boolean {\n return isTextureFormatRenderable(this.gl, format);\n }\n\n // WEBGL SPECIFIC METHODS\n\n /** Returns a WebGL2RenderingContext or throws an error */\n assertWebGL2(): WebGL2RenderingContext {\n if (!this.gl2) {\n throw new Error('Requires WebGL2');\n }\n return this.gl2;\n }\n\n // IMPLEMENTATION OF ABSTRACT DEVICE\n\n createCanvasContext(props?: CanvasContextProps): CanvasContext {\n throw new Error('WebGL only supports a single canvas');\n }\n\n createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WEBGLBuffer {\n const newProps = this._getBufferProps(props);\n return new BufferWithAccessor(this, newProps);\n }\n\n _createTexture(props: TextureProps): WEBGLTexture {\n return new WEBGLTexture(this, props);\n }\n\n createExternalTexture(props: ExternalTextureProps): ExternalTexture {\n throw new Error('createExternalTexture() not implemented'); // return new Program(props);\n }\n\n createSampler(props: SamplerProps): WEBGLSampler {\n return new WEBGLSampler(this, props);\n }\n\n createShader(props: ShaderProps): WEBGLShader {\n return new WEBGLShader(this, props);\n }\n\n createFramebuffer(props: FramebufferProps): WEBGLFramebuffer {\n return new WEBGLFramebuffer(this, props);\n }\n\n createRenderPipeline(props: RenderPipelineProps): WEBGLRenderPipeline {\n return new WEBGLRenderPipeline(this, props);\n }\n\n override createVertexArray(props: VertexArrayProps): VertexArray {\n return new WEBGLVertexArray(this, props);\n }\n\n beginRenderPass(props: RenderPassProps): WEBGLRenderPass {\n return new WEBGLRenderPass(this, props);\n }\n\n createComputePipeline(props?: ComputePipelineProps): ComputePipeline {\n throw new Error('ComputePipeline not supported in WebGL');\n }\n\n beginComputePass(props: ComputePassProps): ComputePass {\n throw new Error('compute shaders not supported in WebGL');\n }\n\n private renderPass: WEBGLRenderPass | null = null;\n\n getDefaultRenderPass(): WEBGLRenderPass {\n this.renderPass =\n this.renderPass ||\n this.beginRenderPass({\n framebuffer: this.canvasContext.getCurrentFramebuffer()\n });\n return this.renderPass;\n }\n\n override createCommandEncoder(props: CommandEncoderProps): WEBGLCommandEncoder {\n return new WEBGLCommandEncoder(this, props);\n }\n\n /**\n * Offscreen Canvas Support: Commit the frame\n * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit\n * Chrome's offscreen canvas does not require gl.commit\n */\n submit(): void {\n this.renderPass?.end();\n this.renderPass = null;\n // this.canvasContext.commit();\n }\n\n //\n // WebGL-only API (not part of `Device` API)\n //\n\n /** WebGL1 typed context. Can always be used. */\n readonly gl: WebGLRenderingContext;\n /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */\n readonly gl2: WebGL2RenderingContext | null = null;\n readonly debug: boolean = false;\n\n /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */\n readonly isWebGL1: boolean;\n /** `true` if this is a WebGL2 context. @note `false` if WebGL1 */\n readonly isWebGL2: boolean;\n\n /** State used by luma.gl classes: TODO - move to canvasContext*/\n readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};\n\n /** State used by luma.gl classes - TODO - not used? */\n readonly _extensions: Record<string, any> = {};\n _polyfilled: boolean = false;\n\n /** Instance of Spector.js (if initialized) */\n spector;\n\n private _webglLimits?: WebGLLimits;\n\n /** Return WebGL specific limits */\n get webglLimits(): WebGLLimits {\n this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);\n return this._webglLimits;\n }\n\n /**\n * Triggers device (or WebGL context) loss.\n * @note primarily intended for testing how application reacts to device loss\n */\n override loseDevice(): boolean {\n let deviceLossTriggered = false;\n const ext = this.gl.getExtension('WEBGL_lose_context');\n if (ext) {\n deviceLossTriggered = true;\n ext.loseContext();\n // ext.loseContext should trigger context loss callback but the platform may not do this, so do it explicitly\n }\n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Application triggered context loss'\n });\n return deviceLossTriggered;\n }\n\n /** Save current WebGL context state onto an internal stack */\n pushState(): void {\n pushContextState(this.gl);\n }\n\n /** Restores previously saved context state */\n popState(): void {\n popContextState(this.gl);\n }\n\n /**\n * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension\n * luma.gl ids and props can be inspected\n */\n setSpectorMetadata(handle: unknown, props: Record<string, unknown>) {\n // @ts-expect-error\n // eslint-disable-next-line camelcase\n handle.__SPECTOR_Metadata = props;\n }\n\n /**\n * Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant\n * Be aware that there are some duplicates especially for constants that are 0,\n * so this isn't guaranteed to return the right key in all cases.\n */\n getGLKey(value: unknown, gl?: WebGLRenderingContext): string {\n // @ts-ignore expect-error depends on settings\n gl = gl || this.gl2 || this.gl;\n const number = Number(value);\n for (const key in gl) {\n // @ts-ignore expect-error depends on settings\n if (gl[key] === number) {\n return `GL.${key}`;\n }\n }\n // No constant found. Stringify the value and return it.\n return String(value);\n }\n\n /** Store constants */\n _constants: (TypedArray | null)[];\n\n /**\n * Set a constant value for a location. Disabled attributes at that location will read from this value\n * @note WebGL constants are stored globally on the WebGL context, not the VertexArray\n * so they need to be updated before every render\n * @todo - remember/cache values to avoid setting them unnecessarily?\n */\n setConstantAttribute(location: number, constant: TypedArray): void {\n this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);\n const currentConstant = this._constants[location];\n if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {\n log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();\n }\n this._constants[location] = constant;\n\n switch (constant.constructor) {\n case Float32Array:\n setConstantFloatArray(this, location, constant as Float32Array);\n break;\n case Int32Array:\n setConstantIntArray(this, location, constant as Int32Array);\n break;\n case Uint32Array:\n setConstantUintArray(this, location, constant as Uint32Array);\n break;\n default:\n assert(false);\n }\n }\n}\n\n/** Check if supplied parameter is a WebGLRenderingContext */\nfunction isWebGL(gl: any): boolean {\n if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {\n return true;\n }\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && Number.isFinite(gl._version));\n}\n\n/** Check if supplied parameter is a WebGL2RenderingContext */\nfunction isWebGL2(gl: any): boolean {\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && gl._version === 2);\n}\n\n/** Set constant float array attribute */\nfunction setConstantFloatArray(device: WebGLDevice, location: number, array: Float32Array): void {\n switch (array.length) {\n case 1:\n device.gl.vertexAttrib1fv(location, array);\n break;\n case 2:\n device.gl.vertexAttrib2fv(location, array);\n break;\n case 3:\n device.gl.vertexAttrib3fv(location, array);\n break;\n case 4:\n device.gl.vertexAttrib4fv(location, array);\n break;\n default:\n assert(false);\n }\n}\n\n/** Set constant signed int array attribute */\nfunction setConstantIntArray(device: WebGLDevice, location: number, array: Int32Array): void {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4iv(location, array);\n // TODO - not clear if we need to use the special forms, more testing needed\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1iv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2iv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3iv(location, array);\n // break;\n // case 4:\n // break;\n // default:\n // assert(false);\n // }\n}\n\n/** Set constant unsigned int array attribute */\nfunction setConstantUintArray(device: WebGLDevice, location: number, array: Uint32Array) {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4uiv(location, array);\n // TODO - not clear if we need to use the special forms, more testing needed\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1uiv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2uiv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3uiv(location, array);\n // break;\n // case 4:\n // gl.vertexAttribI4uiv(location, array);\n // break;\n // default:\n // assert(false);\n // }\n}\n\n/**\n *\n */\nfunction compareConstantArrayValues(v1: TypedArray, v2: TypedArray): boolean {\n if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {\n return false;\n }\n for (let i = 0; i < v1.length; ++i) {\n if (v1[i] !== v2[i]) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":"AAcA,SAAQA,MAAM,EAAEC,aAAa,EAAEC,GAAG,EAAEC,GAAG,EAAEC,MAAM,QAAO,eAAe;AACrE,SAAQC,SAAS,QAAO,eAAe;AAAC,SAChCC,eAAe;AAAA,SAErBC,eAAe,EACfC,gBAAgB,EAChBC,iBAAiB;AAAA,SAEXC,oBAAoB;AAAA,SAE1BC,qBAAqB,EACrBC,sBAAsB;AAAA,SAEhBC,aAAa;AAAA,SACbC,iBAAiB;AAAA,SACjBC,eAAe,EAAEC,cAAc;AAAA,SAC/BC,kBAAkB;AAAA,SAClBC,aAAa,EAAEC,mBAAmB;AAAA,S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AiB/C;AAGA,SAASJ,oBAAoBA,CAACtH,MAAmB,EAAE2G,QAAgB,EAAEe,KAAkB,EAAE;EAAA,IAAAO,WAAA;EACvFjI,MAAM,CAACqE,YAAY,CAAC,CAAC;EACrB,CAAA4D,WAAA,GAAAjI,MAAM,CAACwB,GAAG,cAAAyG,WAAA,uBAAVA,WAAA,CAAYC,iBAAiB,CAACvB,QAAQ,EAAEe,KAAK,CAAC;AAkBhD;AAKA,SAASV,0BAA0BA,CAACmB,EAAc,EAAEC,EAAc,EAAW;EAC3E,IAAI,CAACD,EAAE,IAAI,CAACC,EAAE,IAAID,EAAE,CAAC7H,MAAM,KAAK8H,EAAE,CAAC9H,MAAM,IAAI6H,EAAE,CAACpH,WAAW,KAAKqH,EAAE,CAACrH,WAAW,EAAE;IAC9E,OAAO,KAAK;EACd;EACA,KAAK,IAAIsH,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,EAAE,CAAC7H,MAAM,EAAE,EAAE+H,CAAC,EAAE;IAClC,IAAIF,EAAE,CAACE,CAAC,CAAC,KAAKD,EAAE,CAACC,CAAC,CAAC,EAAE;MACnB,OAAO,KAAK;IACd;EACF;EACA,OAAO,IAAI;AACb"}
|
|
1
|
+
{"version":3,"file":"webgl-device.js","names":["Device","CanvasContext","log","uid","assert","isBrowser","polyfillContext","popContextState","pushContextState","trackContextState","createBrowserContext","createHeadlessContext","isHeadlessGLRegistered","getDeviceInfo","getDeviceFeatures","getDeviceLimits","getWebGLLimits","WebGLCanvasContext","loadSpectorJS","initializeSpectorJS","loadWebGLDeveloperTools","makeDebugContext","isTextureFormatSupported","isTextureFormatRenderable","isTextureFormatFilterable","WEBGLBuffer","WEBGLShader","WEBGLSampler","WEBGLTexture","WEBGLFramebuffer","WEBGLRenderPass","WEBGLRenderPipeline","WEBGLCommandEncoder","WEBGLVertexArray","WEBGLTransformFeedback","LOG_LEVEL","WebGLDevice","isSupported","WebGLRenderingContext","features","_features","gl","limits","_limits","attach","device","isWebGL","Error","create","props","arguments","length","undefined","groupCollapsed","canvas","pageLoaded","get","debug","spector","probe","constructor","_props$gl","id","info","canvasContext","handle","lost","_resolveContextLost","renderPass","gl2","isWebGL1","isWebGL2","_canvasSizeInfo","clientWidth","clientHeight","devicePixelRatio","_extensions","_polyfilled","_webglLimits","_constants","Promise","resolve","onContextLost","event","_this$_resolveContext","call","reason","message","_version","enable","copyState","_len","args","Array","_key","webgl2","throwOnError","level","Math","max","warn","type","vendor","renderer","groupEnd","destroy","ext","getExtension","isLost","isContextLost","getSize","drawingBufferWidth","drawingBufferHeight","format","assertWebGL2","createCanvasContext","createBuffer","newProps","_getBufferProps","_createTexture","createExternalTexture","createSampler","createShader","createFramebuffer","createRenderPipeline","createVertexArray","beginRenderPass","createComputePipeline","beginComputePass","createTransformFeedback","getDefaultRenderPass","framebuffer","getCurrentFramebuffer","createCommandEncoder","submit","_this$renderPass","end","webglLimits","loseDevice","_this$_resolveContext2","deviceLossTriggered","loseContext","pushState","popState","setSpectorMetadata","__SPECTOR_Metadata","getGLKey","value","number","Number","key","String","setConstantAttribute","location","constant","maxVertexAttributes","fill","currentConstant","compareConstantArrayValues","Float32Array","setConstantFloatArray","Int32Array","setConstantIntArray","Uint32Array","setConstantUintArray","WebGL2RenderingContext","Boolean","isFinite","array","vertexAttrib1fv","vertexAttrib2fv","vertexAttrib3fv","vertexAttrib4fv","_device$gl","vertexAttribI4iv","_device$gl2","vertexAttribI4uiv","v1","v2","i"],"sources":["../../src/adapter/webgl-device.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {\n DeviceProps,\n DeviceInfo,\n DeviceLimits,\n DeviceFeature,\n CanvasContextProps,\n TextureFormat,\n VertexArray,\n VertexArrayProps,\n TypedArray\n} from '@luma.gl/core';\nimport {Device, CanvasContext, log, uid, assert} from '@luma.gl/core';\nimport {isBrowser} from '@probe.gl/env';\nimport {polyfillContext} from '../context/polyfill/polyfill-context';\nimport {\n popContextState,\n pushContextState,\n trackContextState\n} from '../context/state-tracker/track-context-state';\nimport {createBrowserContext} from '../context/context/create-browser-context';\nimport {\n createHeadlessContext,\n isHeadlessGLRegistered\n} from '../context/context/create-headless-context';\nimport {getDeviceInfo} from './device-helpers/get-device-info';\nimport {getDeviceFeatures} from './device-helpers/device-features';\nimport {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';\nimport {WebGLCanvasContext} from './webgl-canvas-context';\nimport {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';\nimport {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';\nimport {\n isTextureFormatSupported,\n isTextureFormatRenderable,\n isTextureFormatFilterable\n} from './converters/texture-formats';\n\n// WebGL classes\nimport type {\n BufferProps,\n ShaderProps,\n // Sampler,\n SamplerProps,\n TextureProps,\n ExternalTexture,\n ExternalTextureProps,\n FramebufferProps,\n // RenderPipeline,\n RenderPipelineProps,\n ComputePipeline,\n ComputePipelineProps,\n // RenderPass,\n RenderPassProps,\n ComputePass,\n ComputePassProps,\n // CommandEncoder,\n CommandEncoderProps,\n TransformFeedbackProps\n} from '@luma.gl/core';\n\nimport {WEBGLBuffer} from './resources/webgl-buffer';\nimport {WEBGLShader} from './resources/webgl-shader';\nimport {WEBGLSampler} from './resources/webgl-sampler';\nimport {WEBGLTexture} from './resources/webgl-texture';\nimport {WEBGLFramebuffer} from './resources/webgl-framebuffer';\nimport {WEBGLRenderPass} from './resources/webgl-render-pass';\nimport {WEBGLRenderPipeline} from './resources/webgl-render-pipeline';\nimport {WEBGLCommandEncoder} from './resources/webgl-command-encoder';\nimport {WEBGLVertexArray} from './resources/webgl-vertex-array';\nimport {WEBGLTransformFeedback} from './resources/webgl-transform-feedback';\n\nconst LOG_LEVEL = 1;\n\n/** WebGPU style Device API for a WebGL context */\nexport class WebGLDevice extends Device {\n //\n // Public `Device` API\n //\n\n static type: string = 'webgl';\n\n static isSupported(): boolean {\n return typeof WebGLRenderingContext !== 'undefined' || isHeadlessGLRegistered();\n }\n\n readonly info: DeviceInfo;\n readonly canvasContext: WebGLCanvasContext;\n\n readonly handle: WebGLRenderingContext;\n\n get features(): Set<DeviceFeature> {\n this._features = this._features || getDeviceFeatures(this.gl);\n return this._features;\n }\n\n get limits(): DeviceLimits {\n this._limits = this._limits || getDeviceLimits(this.gl);\n return this._limits;\n }\n\n readonly lost: Promise<{reason: 'destroyed'; message: string}>;\n\n private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;\n private _features?: Set<DeviceFeature>;\n private _limits?: DeviceLimits;\n\n //\n // Static methods, expected to be present by `luma.createDevice()`\n //\n\n /**\n * Get a device instance from a GL context\n * Creates and instruments the device if not already created\n * @param gl\n * @returns\n */\n static attach(gl: Device | WebGLRenderingContext | WebGL2RenderingContext): WebGLDevice {\n if (gl instanceof WebGLDevice) {\n return gl;\n }\n // @ts-expect-error\n if (gl?.device instanceof Device) {\n // @ts-expect-error\n return gl.device as WebGLDevice;\n }\n if (!isWebGL(gl)) {\n throw new Error('Invalid WebGLRenderingContext');\n }\n return new WebGLDevice({gl: gl as WebGLRenderingContext});\n }\n\n static async create(props: DeviceProps = {}): Promise<WebGLDevice> {\n log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created');\n\n // Wait for page to load. Only wait when props. canvas is string\n // to avoid setting page onload callback unless necessary\n if (typeof props.canvas === 'string') {\n await CanvasContext.pageLoaded;\n }\n\n // Load webgl and spector debug scripts from CDN if requested\n if (log.get('debug') || props.debug) {\n await loadWebGLDeveloperTools();\n }\n\n // @ts-expect-error spector not on props\n const {spector} = props;\n if (log.get('spector') || spector) {\n await loadSpectorJS();\n }\n\n log.probe(LOG_LEVEL + 1, 'DOM is loaded')();\n\n // @ts-expect-error\n if (props.gl && props.gl.device) {\n return WebGLDevice.attach(props.gl);\n }\n\n return new WebGLDevice(props);\n }\n\n //\n // Public API\n //\n\n constructor(props: DeviceProps) {\n super({...props, id: props.id || uid('webgl-device')});\n\n // If attaching to an already attached context, return the attached device\n // @ts-expect-error device is attached to context\n const device: WebGLDevice | undefined = props.gl?.device;\n if (device) {\n throw new Error(`WebGL context already attached to device ${device.id}`);\n }\n\n // Create and instrument context\n this.canvasContext = new WebGLCanvasContext(this, props);\n\n this.lost = new Promise<{reason: 'destroyed'; message: string}>(resolve => {\n this._resolveContextLost = resolve;\n });\n\n const onContextLost = (event: Event) =>\n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'\n });\n\n let gl: WebGLRenderingContext | WebGL2RenderingContext | null = props.gl || null;\n gl =\n gl ||\n (isBrowser()\n ? createBrowserContext(this.canvasContext.canvas, {...props, onContextLost})\n : null);\n gl = gl || (!isBrowser() ? createHeadlessContext({...props, onContextLost}) : null);\n\n if (!gl) {\n throw new Error('WebGL context creation failed');\n }\n\n this.handle = gl;\n this.gl = this.handle;\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.isWebGL2 = isWebGL2(this.gl);\n this.isWebGL1 = !this.isWebGL2;\n\n // luma Device fields\n this.info = getDeviceInfo(this.gl);\n\n // @ts-expect-error Link webgl context back to device\n this.gl.device = this;\n // @ts-expect-error Annotate webgl context to handle\n this.gl._version = this.isWebGL2 ? 2 : 1;\n\n // Add subset of WebGL2 methods to WebGL1 context\n polyfillContext(this.gl);\n\n // Install context state tracking\n // @ts-expect-error - hidden parameters\n const {enable = true, copyState = false} = props;\n trackContextState(this.gl, {\n enable,\n copyState,\n log: (...args: any[]) => log.log(1, ...args)()\n });\n\n // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1\n if (isBrowser() && props.debug) {\n this.gl = makeDebugContext(this.gl, {...props, webgl2: this.isWebGL2, throwOnError: true});\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.debug = true;\n log.level = Math.max(log.level, 1);\n log.warn('WebGL debug mode activated. Performance reduced.')();\n }\n\n // @ts-expect-error spector not on props\n if (isBrowser() && props.spector) {\n const canvas = this.handle.canvas || (props.canvas as HTMLCanvasElement);\n this.spector = initializeSpectorJS({...this.props, canvas});\n }\n\n // Log some debug info about the newly created context\n const message = `\\\nCreated ${this.info.type}${this.debug ? ' debug' : ''} context: \\\n${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`;\n log.probe(LOG_LEVEL, message)();\n\n log.groupEnd(LOG_LEVEL)();\n }\n\n /**\n * Destroys the context\n * @note Has no effect for browser contexts, there is no browser API for destroying contexts\n */\n destroy(): void {\n const ext = this.gl.getExtension('STACKGL_destroy_context');\n if (ext) {\n ext.destroy();\n }\n }\n\n get isLost(): boolean {\n return this.gl.isContextLost();\n }\n\n getSize(): [number, number] {\n return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];\n }\n\n isTextureFormatSupported(format: TextureFormat): boolean {\n return isTextureFormatSupported(this.gl, format);\n }\n\n isTextureFormatFilterable(format: TextureFormat): boolean {\n return isTextureFormatFilterable(this.gl, format);\n }\n\n isTextureFormatRenderable(format: TextureFormat): boolean {\n return isTextureFormatRenderable(this.gl, format);\n }\n\n // WEBGL SPECIFIC METHODS\n\n /** Returns a WebGL2RenderingContext or throws an error */\n assertWebGL2(): WebGL2RenderingContext {\n if (!this.gl2) {\n throw new Error('Requires WebGL2');\n }\n return this.gl2;\n }\n\n // IMPLEMENTATION OF ABSTRACT DEVICE\n\n createCanvasContext(props?: CanvasContextProps): CanvasContext {\n throw new Error('WebGL only supports a single canvas');\n }\n\n createBuffer(props: BufferProps | ArrayBuffer | ArrayBufferView): WEBGLBuffer {\n const newProps = this._getBufferProps(props);\n return new WEBGLBuffer(this, newProps);\n }\n\n _createTexture(props: TextureProps): WEBGLTexture {\n return new WEBGLTexture(this, props);\n }\n\n createExternalTexture(props: ExternalTextureProps): ExternalTexture {\n throw new Error('createExternalTexture() not implemented'); // return new Program(props);\n }\n\n createSampler(props: SamplerProps): WEBGLSampler {\n return new WEBGLSampler(this, props);\n }\n\n createShader(props: ShaderProps): WEBGLShader {\n return new WEBGLShader(this, props);\n }\n\n createFramebuffer(props: FramebufferProps): WEBGLFramebuffer {\n return new WEBGLFramebuffer(this, props);\n }\n\n createRenderPipeline(props: RenderPipelineProps): WEBGLRenderPipeline {\n return new WEBGLRenderPipeline(this, props);\n }\n\n override createVertexArray(props: VertexArrayProps): VertexArray {\n return new WEBGLVertexArray(this, props);\n }\n\n beginRenderPass(props: RenderPassProps): WEBGLRenderPass {\n return new WEBGLRenderPass(this, props);\n }\n\n createComputePipeline(props?: ComputePipelineProps): ComputePipeline {\n throw new Error('ComputePipeline not supported in WebGL');\n }\n\n beginComputePass(props: ComputePassProps): ComputePass {\n throw new Error('ComputePass not supported in WebGL');\n }\n\n createTransformFeedback(props: TransformFeedbackProps): WEBGLTransformFeedback {\n return new WEBGLTransformFeedback(this, props);\n }\n\n private renderPass: WEBGLRenderPass | null = null;\n\n getDefaultRenderPass(): WEBGLRenderPass {\n this.renderPass =\n this.renderPass ||\n this.beginRenderPass({\n framebuffer: this.canvasContext.getCurrentFramebuffer()\n });\n return this.renderPass;\n }\n\n override createCommandEncoder(props?: CommandEncoderProps): WEBGLCommandEncoder {\n return new WEBGLCommandEncoder(this, props);\n }\n\n /**\n * Offscreen Canvas Support: Commit the frame\n * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit\n * Chrome's offscreen canvas does not require gl.commit\n */\n submit(): void {\n this.renderPass?.end();\n this.renderPass = null;\n // this.canvasContext.commit();\n }\n\n //\n // WebGL-only API (not part of `Device` API)\n //\n\n /** WebGL1 typed context. Can always be used. */\n readonly gl: WebGLRenderingContext;\n /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */\n readonly gl2: WebGL2RenderingContext | null = null;\n readonly debug: boolean = false;\n\n /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */\n readonly isWebGL1: boolean;\n /** `true` if this is a WebGL2 context. @note `false` if WebGL1 */\n readonly isWebGL2: boolean;\n\n /** State used by luma.gl classes: TODO - move to canvasContext*/\n readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};\n\n /** State used by luma.gl classes - TODO - not used? */\n readonly _extensions: Record<string, any> = {};\n _polyfilled: boolean = false;\n\n /** Instance of Spector.js (if initialized) */\n spector;\n\n private _webglLimits?: WebGLLimits;\n\n /** Return WebGL specific limits */\n get webglLimits(): WebGLLimits {\n this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);\n return this._webglLimits;\n }\n\n /**\n * Triggers device (or WebGL context) loss.\n * @note primarily intended for testing how application reacts to device loss\n */\n override loseDevice(): boolean {\n let deviceLossTriggered = false;\n const ext = this.gl.getExtension('WEBGL_lose_context');\n if (ext) {\n deviceLossTriggered = true;\n ext.loseContext();\n // ext.loseContext should trigger context loss callback but the platform may not do this, so do it explicitly\n }\n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Application triggered context loss'\n });\n return deviceLossTriggered;\n }\n\n /** Save current WebGL context state onto an internal stack */\n pushState(): void {\n pushContextState(this.gl);\n }\n\n /** Restores previously saved context state */\n popState(): void {\n popContextState(this.gl);\n }\n\n /**\n * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension\n * luma.gl ids and props can be inspected\n */\n setSpectorMetadata(handle: unknown, props: Record<string, unknown>) {\n // @ts-expect-error\n // eslint-disable-next-line camelcase\n handle.__SPECTOR_Metadata = props;\n }\n\n /**\n * Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant\n * Be aware that there are some duplicates especially for constants that are 0,\n * so this isn't guaranteed to return the right key in all cases.\n */\n getGLKey(value: unknown, gl?: WebGLRenderingContext): string {\n // @ts-ignore expect-error depends on settings\n gl = gl || this.gl2 || this.gl;\n const number = Number(value);\n for (const key in gl) {\n // @ts-ignore expect-error depends on settings\n if (gl[key] === number) {\n return `GL.${key}`;\n }\n }\n // No constant found. Stringify the value and return it.\n return String(value);\n }\n\n /** Store constants */\n _constants: (TypedArray | null)[];\n\n /**\n * Set a constant value for a location. Disabled attributes at that location will read from this value\n * @note WebGL constants are stored globally on the WebGL context, not the VertexArray\n * so they need to be updated before every render\n * @todo - remember/cache values to avoid setting them unnecessarily?\n */\n setConstantAttribute(location: number, constant: TypedArray): void {\n this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);\n const currentConstant = this._constants[location];\n if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {\n log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();\n }\n this._constants[location] = constant;\n\n switch (constant.constructor) {\n case Float32Array:\n setConstantFloatArray(this, location, constant as Float32Array);\n break;\n case Int32Array:\n setConstantIntArray(this, location, constant as Int32Array);\n break;\n case Uint32Array:\n setConstantUintArray(this, location, constant as Uint32Array);\n break;\n default:\n assert(false);\n }\n }\n}\n\n/** Check if supplied parameter is a WebGLRenderingContext */\nfunction isWebGL(gl: any): boolean {\n if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {\n return true;\n }\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && Number.isFinite(gl._version));\n}\n\n/** Check if supplied parameter is a WebGL2RenderingContext */\nfunction isWebGL2(gl: any): boolean {\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && gl._version === 2);\n}\n\n/** Set constant float array attribute */\nfunction setConstantFloatArray(device: WebGLDevice, location: number, array: Float32Array): void {\n switch (array.length) {\n case 1:\n device.gl.vertexAttrib1fv(location, array);\n break;\n case 2:\n device.gl.vertexAttrib2fv(location, array);\n break;\n case 3:\n device.gl.vertexAttrib3fv(location, array);\n break;\n case 4:\n device.gl.vertexAttrib4fv(location, array);\n break;\n default:\n assert(false);\n }\n}\n\n/** Set constant signed int array attribute */\nfunction setConstantIntArray(device: WebGLDevice, location: number, array: Int32Array): void {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4iv(location, array);\n // TODO - not clear if we need to use the special forms, more testing needed\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1iv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2iv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3iv(location, array);\n // break;\n // case 4:\n // break;\n // default:\n // assert(false);\n // }\n}\n\n/** Set constant unsigned int array attribute */\nfunction setConstantUintArray(device: WebGLDevice, location: number, array: Uint32Array) {\n device.assertWebGL2();\n device.gl2?.vertexAttribI4uiv(location, array);\n // TODO - not clear if we need to use the special forms, more testing needed\n // switch (array.length) {\n // case 1:\n // gl.vertexAttribI1uiv(location, array);\n // break;\n // case 2:\n // gl.vertexAttribI2uiv(location, array);\n // break;\n // case 3:\n // gl.vertexAttribI3uiv(location, array);\n // break;\n // case 4:\n // gl.vertexAttribI4uiv(location, array);\n // break;\n // default:\n // assert(false);\n // }\n}\n\n/**\n *\n */\nfunction compareConstantArrayValues(v1: TypedArray, v2: TypedArray): boolean {\n if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {\n return false;\n }\n for (let i = 0; i < v1.length; ++i) {\n if (v1[i] !== v2[i]) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":"AAcA,SAAQA,MAAM,EAAEC,aAAa,EAAEC,GAAG,EAAEC,GAAG,EAAEC,MAAM,QAAO,eAAe;AACrE,SAAQC,SAAS,QAAO,eAAe;AAAC,SAChCC,eAAe;AAAA,SAErBC,eAAe,EACfC,gBAAgB,EAChBC,iBAAiB;AAAA,SAEXC,oBAAoB;AAAA,SAE1BC,qBAAqB,EACrBC,sBAAsB;AAAA,SAEhBC,aAAa;AAAA,SACbC,iBAAiB;AAAA,SACjBC,eAAe,EAAEC,cAAc;AAAA,SAC/BC,kBAAkB;AAAA,SAClBC,aAAa,EAAEC,mBAAmB;AAAA,SAClCC,uBAAuB,EAAEC,gBAAgB;AAAA,SAE/CC,wBAAwB,EACxBC,yBAAyB,EACzBC,yBAAyB;AAAA,SA0BnBC,WAAW;AAAA,SACXC,WA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AC;AAiB/C;AAGA,SAASJ,oBAAoBA,CAACvH,MAAmB,EAAE4G,QAAgB,EAAEe,KAAkB,EAAE;EAAA,IAAAO,WAAA;EACvFlI,MAAM,CAACqE,YAAY,CAAC,CAAC;EACrB,CAAA6D,WAAA,GAAAlI,MAAM,CAACwB,GAAG,cAAA0G,WAAA,uBAAVA,WAAA,CAAYC,iBAAiB,CAACvB,QAAQ,EAAEe,KAAK,CAAC;AAkBhD;AAKA,SAASV,0BAA0BA,CAACmB,EAAc,EAAEC,EAAc,EAAW;EAC3E,IAAI,CAACD,EAAE,IAAI,CAACC,EAAE,IAAID,EAAE,CAAC9H,MAAM,KAAK+H,EAAE,CAAC/H,MAAM,IAAI8H,EAAE,CAACrH,WAAW,KAAKsH,EAAE,CAACtH,WAAW,EAAE;IAC9E,OAAO,KAAK;EACd;EACA,KAAK,IAAIuH,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,EAAE,CAAC9H,MAAM,EAAE,EAAEgI,CAAC,EAAE;IAClC,IAAIF,EAAE,CAACE,CAAC,CAAC,KAAKD,EAAE,CAACC,CAAC,CAAC,EAAE;MACnB,OAAO,KAAK;IACd;EACF;EACA,OAAO,IAAI;AACb"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Texture, Framebuffer, FramebufferProps } from '@luma.gl/core';
|
|
2
2
|
import { GL } from '@luma.gl/constants';
|
|
3
|
-
import {
|
|
3
|
+
import { WEBGLBuffer } from '../adapter/resources/webgl-buffer';
|
|
4
4
|
/**
|
|
5
5
|
* Copies data from a type or a Texture object into ArrayBuffer object.
|
|
6
6
|
* App can provide targetPixelArray or have it auto allocated by this method
|
|
@@ -33,12 +33,12 @@ export declare function readPixelsToBuffer(source: Framebuffer | Texture, option
|
|
|
33
33
|
sourceX?: number;
|
|
34
34
|
sourceY?: number;
|
|
35
35
|
sourceFormat?: number;
|
|
36
|
-
target?:
|
|
36
|
+
target?: WEBGLBuffer;
|
|
37
37
|
targetByteOffset?: number;
|
|
38
38
|
sourceWidth?: number;
|
|
39
39
|
sourceHeight?: number;
|
|
40
40
|
sourceType?: number;
|
|
41
|
-
}):
|
|
41
|
+
}): WEBGLBuffer;
|
|
42
42
|
/**
|
|
43
43
|
* Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
|
|
44
44
|
* @deprecated Use CommandEncoder
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy-and-blit.d.ts","sourceRoot":"","sources":["../../src/classic/copy-and-blit.ts"],"names":[],"mappings":"AAGA,OAAO,EAAS,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"copy-and-blit.d.ts","sourceRoot":"","sources":["../../src/classic/copy-and-blit.ts"],"names":[],"mappings":"AAGA,OAAO,EAAS,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAC;AAMtC,OAAO,EAAC,WAAW,EAAC,MAAM,mCAAmC,CAAC;AAE9D;;;;;;;;;;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,EAAE,MAAM,CAAC;CACrB,GACA,UAAU,GAAG,WAAW,GAAG,YAAY,CAiDzC;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,WAAW,CAAC;IACrB,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,WAAW,CAwCb;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,CAUrF"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { assert, Texture, Framebuffer } from '@luma.gl/core';
|
|
2
2
|
import { GL } from '@luma.gl/constants';
|
|
3
|
-
import { BufferWithAccessor as Buffer } from "./buffer-with-accessor.js";
|
|
4
|
-
import { withGLParameters } from "../context/state-tracker/with-parameters.js";
|
|
5
3
|
import { getGLTypeFromTypedArray, getTypedArrayFromGLType } from "./typed-array-utils.js";
|
|
6
4
|
import { glFormatToComponents, glTypeToBytes } from "./format-utils.js";
|
|
7
5
|
export function readPixelsToArray(source, options) {
|
|
@@ -62,31 +60,25 @@ export function readPixelsToBuffer(source, options) {
|
|
|
62
60
|
sourceWidth = sourceWidth || framebuffer.width;
|
|
63
61
|
sourceHeight = sourceHeight || framebuffer.height;
|
|
64
62
|
const webglFramebuffer = framebuffer;
|
|
65
|
-
|
|
66
|
-
sourceType = sourceType || (target ? target.type : GL.UNSIGNED_BYTE);
|
|
63
|
+
sourceType = sourceType || GL.UNSIGNED_BYTE;
|
|
67
64
|
if (!target) {
|
|
68
65
|
const components = glFormatToComponents(sourceFormat);
|
|
69
66
|
const byteCount = glTypeToBytes(sourceType);
|
|
70
67
|
const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
|
|
71
|
-
target =
|
|
72
|
-
byteLength
|
|
73
|
-
accessor: {
|
|
74
|
-
type: sourceType,
|
|
75
|
-
size: components
|
|
76
|
-
}
|
|
68
|
+
target = webglFramebuffer.device.createBuffer({
|
|
69
|
+
byteLength
|
|
77
70
|
});
|
|
78
71
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
target.unbind({
|
|
88
|
-
glTarget: GL.PIXEL_PACK_BUFFER
|
|
72
|
+
const commandEncoder = source.device.createCommandEncoder();
|
|
73
|
+
commandEncoder.copyTextureToBuffer({
|
|
74
|
+
source: source,
|
|
75
|
+
width: sourceWidth,
|
|
76
|
+
height: sourceHeight,
|
|
77
|
+
origin: [sourceX, sourceY],
|
|
78
|
+
destination: target,
|
|
79
|
+
byteOffset: targetByteOffset
|
|
89
80
|
});
|
|
81
|
+
commandEncoder.destroy();
|
|
90
82
|
if (deleteFramebuffer) {
|
|
91
83
|
framebuffer.destroy();
|
|
92
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy-and-blit.js","names":["assert","Texture","Framebuffer","GL","BufferWithAccessor","Buffer","withGLParameters","getGLTypeFromTypedArray","getTypedArrayFromGLType","glFormatToComponents","glTypeToBytes","readPixelsToArray","source","options","_framebuffer$colorAtt","sourceX","sourceY","sourceFormat","RGBA","sourceAttachment","COLOR_ATTACHMENT0","target","sourceWidth","sourceHeight","sourceType","framebuffer","deleteFramebuffer","getFramebuffer","gl","handle","width","height","attachment","colorAttachments","type","UNSIGNED_BYTE","getPixelArray","prevHandle","bindFramebuffer","FRAMEBUFFER","readPixels","destroy","readPixelsToBuffer","targetByteOffset","webglFramebuffer","gl2","device","assertWebGL2","components","byteCount","byteLength","accessor","size","bind","glTarget","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","pixelArray","format","ArrayType","clamped"],"sources":["../../src/classic/copy-and-blit.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {assert, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';\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 {withGLParameters} 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 {\n sourceX = 0,\n sourceY = 0,\n sourceFormat = GL.RGBA,\n sourceAttachment = GL.COLOR_ATTACHMENT0 // TODO - support gl.readBuffer\n } = options || {};\n let {\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 =\n sourceType ||\n (framebuffer.colorAttachments[attachment] as WEBGLTexture)?.type ||\n GL.UNSIGNED_BYTE;\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 target.bind({glTarget: GL.PIXEL_PACK_BUFFER});\n withGLParameters(gl2, {framebuffer}, () => {\n gl2.readPixels(\n sourceX,\n sourceY,\n sourceWidth,\n sourceHeight,\n sourceFormat,\n sourceType,\n targetByteOffset\n );\n });\n target.unbind({glTarget: 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 device.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: [texture]\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":"AAGA,SAAQA,MAAM,EAAEC,OAAO,EAAEC,WAAW,QAAyB,eAAe;AAC5E,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAE9BC,kBAAkB,IAAIC,MAAM;AAAA,SAG5BC,gBAAgB;AAAA,SAChBC,uBAAuB,EAAEC,uBAAuB;AAAA,SAChDC,oBAAoB,EAAEC,aAAa;AAa3C,OAAO,SAASC,iBAAiBA,CAC/BC,MAA6B,EAC7BC,OAUC,EACwC;EAAA,IAAAC,qBAAA;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AAU;EACnB;EAEA7C,IAAI,GAAGA,IAAI,IAAI/B,EAAE,CAACgC,aAAa;EAC/B,MAAM8C,SAAS,GAAGzE,uBAAuB,CAAC0B,IAAI,EAAE;IAACgD,OAAO,EAAE;EAAK,CAAC,CAAC;EACjE,MAAMlC,UAAU,GAAGvC,oBAAoB,CAACuE,MAAM,CAAC;EAE/C,OAAO,IAAIC,SAAS,CAACnD,KAAK,GAAGC,MAAM,GAAGiB,UAAU,CAAC;AACnD"}
|
|
1
|
+
{"version":3,"file":"copy-and-blit.js","names":["assert","Texture","Framebuffer","GL","getGLTypeFromTypedArray","getTypedArrayFromGLType","glFormatToComponents","glTypeToBytes","readPixelsToArray","source","options","_framebuffer$colorAtt","sourceX","sourceY","sourceFormat","RGBA","sourceAttachment","COLOR_ATTACHMENT0","target","sourceWidth","sourceHeight","sourceType","framebuffer","deleteFramebuffer","getFramebuffer","gl","handle","width","height","attachment","colorAttachments","type","UNSIGNED_BYTE","getPixelArray","prevHandle","bindFramebuffer","FRAMEBUFFER","readPixels","destroy","readPixelsToBuffer","targetByteOffset","webglFramebuffer","components","byteCount","byteLength","device","createBuffer","commandEncoder","createCommandEncoder","copyTextureToBuffer","origin","destination","byteOffset","copyToTexture","targetMipmaplevel","targetInternalFormat","targetX","targetY","targetZ","isSubCopy","texture","textureTarget","Number","isFinite","bind","copyTexImage2D","TEXTURE_2D","TEXTURE_CUBE_MAP","copyTexSubImage2D","TEXTURE_2D_ARRAY","TEXTURE_3D","assertWebGL2","gl2","copyTexSubImage3D","unbind","toFramebuffer","props","id","createFramebuffer","pixelArray","format","ArrayType","clamped"],"sources":["../../src/classic/copy-and-blit.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {assert, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\n\nimport {WEBGLTexture} from '../adapter/resources/webgl-texture';\nimport {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';\nimport {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';\nimport {glFormatToComponents, glTypeToBytes} from './format-utils';\nimport {WEBGLBuffer} from '../adapter/resources/webgl-buffer';\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 {\n sourceX = 0,\n sourceY = 0,\n sourceFormat = GL.RGBA,\n sourceAttachment = GL.COLOR_ATTACHMENT0 // TODO - support gl.readBuffer\n } = options || {};\n let {\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 =\n sourceType ||\n (framebuffer.colorAttachments[attachment] as WEBGLTexture)?.type ||\n GL.UNSIGNED_BYTE;\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?: WEBGLBuffer; // 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): WEBGLBuffer {\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\n // deduce type if not available.\n sourceType = sourceType || 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 = webglFramebuffer.device.createBuffer({byteLength});\n }\n\n // TODO(donmccurdy): Do we have tests to confirm this is working?\n const commandEncoder = source.device.createCommandEncoder();\n commandEncoder.copyTextureToBuffer({\n source: source as Texture,\n width: sourceWidth,\n height: sourceHeight,\n origin: [sourceX, sourceY],\n destination: target,\n byteOffset: targetByteOffset\n });\n commandEncoder.destroy();\n\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 device.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: [texture]\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":"AAGA,SAAQA,MAAM,EAAEC,OAAO,EAAEC,WAAW,QAAyB,eAAe;AAC5E,SAAQC,EAA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