@luma.gl/webgl 9.0.0-alpha.42 → 9.0.0-alpha.44
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/resources/webgl-render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pass.js +10 -1
- package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.d.ts +0 -2
- package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/webgl-render-pipeline.js +11 -10
- package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
- package/dist/dist.dev.js +48 -9
- package/dist/index.cjs +15 -9
- package/dist.min.js +22 -22
- package/package.json +5 -5
- package/src/adapter/resources/webgl-render-pass.ts +6 -0
- package/src/adapter/resources/webgl-render-pipeline.ts +19 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-render-pass.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-render-pass.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAK,YAAY,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"webgl-render-pass.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-render-pass.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,oBAAoB,EAAC,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAK,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAYpD,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAE7B,8DAA8D;IAC9D,YAAY,EAAE,YAAY,CAAC;gBAEf,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe;IAYvD,GAAG,IAAI,IAAI;IAQX,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IACxC,aAAa,IAAI,IAAI;IACrB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAS5C;;OAEG;IACH,aAAa,CAAC,UAAU,GAAE,oBAAyB,GAAG,IAAI;IAiD1D;;OAEG;IACH,SAAS,CAAC,KAAK,IAAI,IAAI;IA+BvB;;OAEG;IACH,SAAS,CAAC,gBAAgB,CAAC,UAAU,GAAE,MAAU,EAAE,KAAK,GAAE,WAA0B;CAwCrF"}
|
|
@@ -2,6 +2,7 @@ import { RenderPass } from '@luma.gl/core';
|
|
|
2
2
|
import { GL } from '@luma.gl/constants';
|
|
3
3
|
import { withGLParameters } from "../../context/state-tracker/with-parameters.js";
|
|
4
4
|
import { setGLParameters } from "../../context/parameters/unified-parameter-api.js";
|
|
5
|
+
import { pushContextState, popContextState } from "../../context/state-tracker/track-context-state.js";
|
|
5
6
|
const GL_DEPTH_BUFFER_BIT = 0x00000100;
|
|
6
7
|
const GL_STENCIL_BUFFER_BIT = 0x00000400;
|
|
7
8
|
const GL_COLOR_BUFFER_BIT = 0x00004000;
|
|
@@ -12,10 +13,18 @@ export class WEBGLRenderPass extends RenderPass {
|
|
|
12
13
|
this.device = void 0;
|
|
13
14
|
this.glParameters = void 0;
|
|
14
15
|
this.device = device;
|
|
16
|
+
pushContextState(this.device.gl);
|
|
15
17
|
this.setParameters(this.props.parameters);
|
|
16
18
|
this.clear();
|
|
17
19
|
}
|
|
18
|
-
end() {
|
|
20
|
+
end() {
|
|
21
|
+
popContextState(this.device.gl);
|
|
22
|
+
if (this.props.framebuffer) {
|
|
23
|
+
setGLParameters(this.device, {
|
|
24
|
+
framebuffer: null
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
19
28
|
pushDebugGroup(groupLabel) {}
|
|
20
29
|
popDebugGroup() {}
|
|
21
30
|
insertDebugMarker(markerLabel) {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-render-pass.js","names":["RenderPass","GL","withGLParameters","setGLParameters","GL_DEPTH_BUFFER_BIT","GL_STENCIL_BUFFER_BIT","GL_COLOR_BUFFER_BIT","GL_COLOR","WEBGLRenderPass","constructor","device","props","glParameters","setParameters","parameters","clear","end","pushDebugGroup","groupLabel","popDebugGroup","insertDebugMarker","markerLabel","arguments","length","undefined","framebuffer","depthReadOnly","depthMask","stencilMask","stencilReadOnly","RASTERIZER_DISCARD","discard","viewport","slice","depthRange","scissorTest","Boolean","scissorRect","scissor","blendConstant","blendColor","stencilReference","console","warn","STENCIL_REF","clearMask","clearColor","clearDepth","clearStencil","gl","clearColorBuffer","drawBuffer","value","gl2","Int32Array","clearBufferiv","Uint32Array","clearBufferuiv","Float32Array","clearBufferfv"],"sources":["../../../src/adapter/resources/webgl-render-pass.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {RenderPass, RenderPassProps, NumberArray, RenderPassParameters} from '@luma.gl/core';\nimport {WebGLDevice} from '../webgl-device';\nimport {GL, GLParameters} from '@luma.gl/constants';\nimport {withGLParameters} from '../../context/state-tracker/with-parameters';\nimport {setGLParameters} from '../../context/parameters/unified-parameter-api';\n\n// Should collapse during minification\nconst GL_DEPTH_BUFFER_BIT = 0x00000100;\nconst GL_STENCIL_BUFFER_BIT = 0x00000400;\nconst GL_COLOR_BUFFER_BIT = 0x00004000;\n\nconst GL_COLOR = 0x1800;\n\nexport class WEBGLRenderPass extends RenderPass {\n readonly device: WebGLDevice;\n\n /** Parameters that should be applied before each draw call */\n glParameters: GLParameters;\n\n constructor(device: WebGLDevice, props: RenderPassProps) {\n super(device, props);\n this.device = device;\n\n // TODO - do parameters (scissorRect) affect the clear operation?\n this.setParameters(this.props.parameters);\n\n // Hack - for now WebGL draws in \"immediate mode\" (instead of queueing the operations)...\n this.clear();\n }\n\n end(): void {\n // should add commands to CommandEncoder.\n }\n\n pushDebugGroup(groupLabel: string): void {}\n popDebugGroup(): void {}\n insertDebugMarker(markerLabel: string): void {}\n\n // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;\n\n // beginOcclusionQuery(queryIndex: number): void;\n // endOcclusionQuery(): void;\n\n // executeBundles(bundles: Iterable<GPURenderBundle>): void;\n\n /**\n * Maps RenderPass parameters to GL parameters\n */\n setParameters(parameters: RenderPassParameters = {}): void {\n const glParameters: GLParameters = {};\n\n // Framebuffers are specified using parameters in WebGL\n if (this.props.framebuffer) {\n glParameters.framebuffer = this.props.framebuffer;\n }\n\n if (this.props.depthReadOnly) {\n glParameters.depthMask = !this.props.depthReadOnly;\n }\n\n glParameters.stencilMask = this.props.stencilReadOnly ? 0 : 1;\n\n glParameters[GL.RASTERIZER_DISCARD] = this.props.discard;\n\n // Map the four renderpass parameters to WebGL parameters\n if (parameters.viewport) {\n // WebGPU viewports are 6 coordinates (X, Y, Z)\n if (parameters.viewport.length >= 6) {\n glParameters.viewport = parameters.viewport.slice(0, 4);\n glParameters.depthRange = [parameters.viewport[4], parameters.viewport[5]];\n } else {\n // WebGL viewports are 4 coordinates (X, Y)\n glParameters.viewport = parameters.viewport;\n }\n }\n glParameters.scissorTest = Boolean(parameters.scissorRect);\n if (parameters.scissorRect) {\n glParameters.scissor = parameters.scissorRect;\n }\n if (parameters.blendConstant) {\n glParameters.blendColor = parameters.blendConstant;\n }\n if (parameters.stencilReference) {\n // eslint-disable-next-line no-console\n console.warn('RenderPassParameters.stencilReference not yet implemented in WebGL');\n // parameters.stencilFunc = [func, ref, mask];\n // Does this work?\n parameters[GL.STENCIL_REF] = parameters.stencilReference;\n }\n\n this.glParameters = glParameters;\n\n setGLParameters(this.device, glParameters);\n }\n\n // Internal\n\n /**\n * Optionally clears depth, color and stencil buffers based on parameters\n */\n protected clear(): void {\n const glParameters: GLParameters = {...this.glParameters};\n\n let clearMask = 0;\n\n if (this.props.clearColor !== false) {\n clearMask |= GL_COLOR_BUFFER_BIT;\n glParameters.clearColor = this.props.clearColor;\n }\n if (this.props.clearDepth !== false) {\n clearMask |= GL_DEPTH_BUFFER_BIT;\n glParameters.clearDepth = this.props.clearDepth;\n }\n if (this.props.clearStencil !== false) {\n clearMask |= GL_STENCIL_BUFFER_BIT;\n glParameters.clearStencil = this.props.clearStencil;\n }\n\n if (clearMask !== 0) {\n // Temporarily set any clear \"colors\" and call clear\n withGLParameters(this.device, glParameters, () => {\n this.device.gl.clear(clearMask);\n });\n\n // TODO - clear multiple color attachments\n // for (attachment of this.framebuffer.colorAttachments) {\n // this.clearColorBuffer \n // }\n }\n }\n\n /** \n * WebGL2 - clear a specific color buffer \n */\n protected clearColorBuffer(drawBuffer: number = 0, value: NumberArray = [0, 0, 0, 0]) {\n withGLParameters(this.device.gl2, {framebuffer: this.props.framebuffer}, () => {\n // Method selection per OpenGL ES 3 docs\n switch (value.constructor) {\n case Int32Array:\n this.device.gl2.clearBufferiv(GL_COLOR, drawBuffer, value);\n break;\n case Uint32Array:\n this.device.gl2.clearBufferuiv(GL_COLOR, drawBuffer, value);\n break;\n case Float32Array:\n default:\n this.device.gl2.clearBufferfv(GL_COLOR, drawBuffer, value);\n break;\n }\n });\n }\n\n // clearDepthStencil() {\n // const GL_DEPTH = 0x1801;\n // const GL_STENCIL = 0x1802;\n // const GL_DEPTH_STENCIL = 0x84f9;\n\n // case GL_DEPTH:\n // this.device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);\n // break;\n\n // case GL_STENCIL:\n // this.device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);\n // break;\n\n // case GL_DEPTH_STENCIL:\n // const [depth, stencil] = value;\n // this.device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);\n // break;\n\n // default:\n // assert(false, ERR_ARGUMENTS);\n // }\n // });\n}\n\n"],"mappings":"AAGA,SAAQA,UAAU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W;UACd,IAAI,CAAC9C,MAAM,CAAC2C,GAAG,CAACI,cAAc,CAAClD,QAAQ,EAAE4C,UAAU,EAAEC,KAAK,CAAC;UAC3D;QACF,KAAKM,YAAY;QACjB;UACE,IAAI,CAAChD,MAAM,CAAC2C,GAAG,CAACM,aAAa,CAACpD,QAAQ,EAAE4C,UAAU,EAAEC,KAAK,CAAC;UAC1D;MACJ;IACF,CAAC,CAAC;EACJ;AAwBF"}
|
|
1
|
+
{"version":3,"file":"webgl-render-pass.js","names":["RenderPass","GL","withGLParameters","setGLParameters","pushContextState","popContextState","GL_DEPTH_BUFFER_BIT","GL_STENCIL_BUFFER_BIT","GL_COLOR_BUFFER_BIT","GL_COLOR","WEBGLRenderPass","constructor","device","props","glParameters","gl","setParameters","parameters","clear","end","framebuffer","pushDebugGroup","groupLabel","popDebugGroup","insertDebugMarker","markerLabel","arguments","length","undefined","depthReadOnly","depthMask","stencilMask","stencilReadOnly","RASTERIZER_DISCARD","discard","viewport","slice","depthRange","scissorTest","Boolean","scissorRect","scissor","blendConstant","blendColor","stencilReference","console","warn","STENCIL_REF","clearMask","clearColor","clearDepth","clearStencil","clearColorBuffer","drawBuffer","value","gl2","Int32Array","clearBufferiv","Uint32Array","clearBufferuiv","Float32Array","clearBufferfv"],"sources":["../../../src/adapter/resources/webgl-render-pass.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {RenderPass, RenderPassProps, NumberArray, RenderPassParameters} from '@luma.gl/core';\nimport {WebGLDevice} from '../webgl-device';\nimport {GL, GLParameters} from '@luma.gl/constants';\nimport {withGLParameters} from '../../context/state-tracker/with-parameters';\nimport {setGLParameters} from '../../context/parameters/unified-parameter-api';\nimport {pushContextState, popContextState} from '../../context/state-tracker/track-context-state';\n\n// Should collapse during minification\nconst GL_DEPTH_BUFFER_BIT = 0x00000100;\nconst GL_STENCIL_BUFFER_BIT = 0x00000400;\nconst GL_COLOR_BUFFER_BIT = 0x00004000;\n\nconst GL_COLOR = 0x1800;\n\nexport class WEBGLRenderPass extends RenderPass {\n readonly device: WebGLDevice;\n\n /** Parameters that should be applied before each draw call */\n glParameters: GLParameters;\n\n constructor(device: WebGLDevice, props: RenderPassProps) {\n super(device, props);\n this.device = device;\n\n // TODO - do parameters (scissorRect) affect the clear operation?\n pushContextState(this.device.gl);\n this.setParameters(this.props.parameters);\n\n // Hack - for now WebGL draws in \"immediate mode\" (instead of queueing the operations)...\n this.clear();\n }\n\n end(): void {\n popContextState(this.device.gl);\n if (this.props.framebuffer) {\n setGLParameters(this.device, {framebuffer: null});\n }\n // should add commands to CommandEncoder.\n }\n\n pushDebugGroup(groupLabel: string): void {}\n popDebugGroup(): void {}\n insertDebugMarker(markerLabel: string): void {}\n\n // writeTimestamp(querySet: GPUQuerySet, queryIndex: number): void;\n\n // beginOcclusionQuery(queryIndex: number): void;\n // endOcclusionQuery(): void;\n\n // executeBundles(bundles: Iterable<GPURenderBundle>): void;\n\n /**\n * Maps RenderPass parameters to GL parameters\n */\n setParameters(parameters: RenderPassParameters = {}): void {\n const glParameters: GLParameters = {};\n\n // Framebuffers are specified using parameters in WebGL\n if (this.props.framebuffer) {\n glParameters.framebuffer = this.props.framebuffer;\n }\n\n if (this.props.depthReadOnly) {\n glParameters.depthMask = !this.props.depthReadOnly;\n }\n\n glParameters.stencilMask = this.props.stencilReadOnly ? 0 : 1;\n\n glParameters[GL.RASTERIZER_DISCARD] = this.props.discard;\n\n // Map the four renderpass parameters to WebGL parameters\n if (parameters.viewport) {\n // WebGPU viewports are 6 coordinates (X, Y, Z)\n if (parameters.viewport.length >= 6) {\n glParameters.viewport = parameters.viewport.slice(0, 4);\n glParameters.depthRange = [parameters.viewport[4], parameters.viewport[5]];\n } else {\n // WebGL viewports are 4 coordinates (X, Y)\n glParameters.viewport = parameters.viewport;\n }\n }\n glParameters.scissorTest = Boolean(parameters.scissorRect);\n if (parameters.scissorRect) {\n glParameters.scissor = parameters.scissorRect;\n }\n if (parameters.blendConstant) {\n glParameters.blendColor = parameters.blendConstant;\n }\n if (parameters.stencilReference) {\n // eslint-disable-next-line no-console\n console.warn('RenderPassParameters.stencilReference not yet implemented in WebGL');\n // parameters.stencilFunc = [func, ref, mask];\n // Does this work?\n parameters[GL.STENCIL_REF] = parameters.stencilReference;\n }\n\n this.glParameters = glParameters;\n\n setGLParameters(this.device, glParameters);\n }\n\n // Internal\n\n /**\n * Optionally clears depth, color and stencil buffers based on parameters\n */\n protected clear(): void {\n const glParameters: GLParameters = {...this.glParameters};\n\n let clearMask = 0;\n\n if (this.props.clearColor !== false) {\n clearMask |= GL_COLOR_BUFFER_BIT;\n glParameters.clearColor = this.props.clearColor;\n }\n if (this.props.clearDepth !== false) {\n clearMask |= GL_DEPTH_BUFFER_BIT;\n glParameters.clearDepth = this.props.clearDepth;\n }\n if (this.props.clearStencil !== false) {\n clearMask |= GL_STENCIL_BUFFER_BIT;\n glParameters.clearStencil = this.props.clearStencil;\n }\n\n if (clearMask !== 0) {\n // Temporarily set any clear \"colors\" and call clear\n withGLParameters(this.device, glParameters, () => {\n this.device.gl.clear(clearMask);\n });\n\n // TODO - clear multiple color attachments\n // for (attachment of this.framebuffer.colorAttachments) {\n // this.clearColorBuffer \n // }\n }\n }\n\n /** \n * WebGL2 - clear a specific color buffer \n */\n protected clearColorBuffer(drawBuffer: number = 0, value: NumberArray = [0, 0, 0, 0]) {\n withGLParameters(this.device.gl2, {framebuffer: this.props.framebuffer}, () => {\n // Method selection per OpenGL ES 3 docs\n switch (value.constructor) {\n case Int32Array:\n this.device.gl2.clearBufferiv(GL_COLOR, drawBuffer, value);\n break;\n case Uint32Array:\n this.device.gl2.clearBufferuiv(GL_COLOR, drawBuffer, value);\n break;\n case Float32Array:\n default:\n this.device.gl2.clearBufferfv(GL_COLOR, drawBuffer, value);\n break;\n }\n });\n }\n\n // clearDepthStencil() {\n // const GL_DEPTH = 0x1801;\n // const GL_STENCIL = 0x1802;\n // const GL_DEPTH_STENCIL = 0x84f9;\n\n // case GL_DEPTH:\n // this.device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);\n // break;\n\n // case GL_STENCIL:\n // this.device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);\n // break;\n\n // case GL_DEPTH_STENCIL:\n // const [depth, stencil] = value;\n // this.device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);\n // break;\n\n // default:\n // assert(false, ERR_ARGUMENTS);\n // }\n // });\n}\n\n"],"mappings":"AAGA,SAAQA,UAAU,QAA2D,eAAe;AAE5F,SAAQC,EAAE,QAAqB,oBAAoB;AAAC,SAC5CC,gBAAgB;AAAA,SAChBC,eAAe;AAAA,SACfC,gBAAgB,EAAEC,eAAe;AAGzC,MAAMC,mBAAmB,GAAG,UAAU;AACtC,MAAMC,qBAAqB,GAAG,UAAU;AACxC,MAAMC,mBAAmB,GAAG,UAAU;AAEtC,MAAMC,QAAQ,GAAG,MAAM;AAEvB,OAAO,MAAMC,eAAe,SAASV,UAAU,CAAC;EAM9CW,WAAWA,CAACC,MAAmB,EAAEC,KAAsB,EAAE;IACvD,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAAC,KANdD,MAAM;IAAA,KAGfE,YAAY;IAIV,IAAI,CAACF,MAAM,GAAGA,MAAM;IAGpBR,gBAAgB,CAAC,IAAI,CAACQ,MAAM,CAACG,EAAE,CAAC;IAChC,IAAI,CAACC,aAAa,CAAC,IAAI,CAACH,KAAK,CAACI,UAAU,CAAC;IAGzC,IAAI,CAACC,KAAK,CAAC,CAAC;EACd;EAEAC,GAAGA,CAAA,EAAS;IACVd,eAAe,CAAC,IAAI,CAACO,MAAM,CAACG,EAAE,CAAC;IAC/B,IAAI,IAAI,CAACF,KAAK,CAACO,WAAW,EAAE;MAC1BjB,eAAe,CAAC,IAAI,CAACS,MAAM,EAAE;QAACQ,WAAW,EAAE;MAAI,CAAC,CAAC;IACnD;EAEF;EAEAC,cAAcA,CAACC,UAAkB,EAAQ,CAAC;EAC1CC,aAAaA,C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AKUI,gBAAgBA,CAAA,EAA4D;IAAA,IAA3DC,UAAkB,GAAA3B,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;IAAA,IAAE4B,KAAkB,GAAA5B,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAClFxB,gBAAgB,CAAC,IAAI,CAACU,MAAM,CAAC2C,GAAG,EAAE;MAACnC,WAAW,EAAE,IAAI,CAACP,KAAK,CAACO;IAAW,CAAC,EAAE,MAAM;MAE7E,QAAQkC,KAAK,CAAC3C,WAAW;QACvB,KAAK6C,UAAU;UACb,IAAI,CAAC5C,MAAM,CAAC2C,GAAG,CAACE,aAAa,CAAChD,QAAQ,EAAE4C,UAAU,EAAEC,KAAK,CAAC;UAC1D;QACF,KAAKI,WAAW;UACd,IAAI,CAAC9C,MAAM,CAAC2C,GAAG,CAACI,cAAc,CAAClD,QAAQ,EAAE4C,UAAU,EAAEC,KAAK,CAAC;UAC3D;QACF,KAAKM,YAAY;QACjB;UACE,IAAI,CAAChD,MAAM,CAAC2C,GAAG,CAACM,aAAa,CAACpD,QAAQ,EAAE4C,UAAU,EAAEC,KAAK,CAAC;UAC1D;MACJ;IACF,CAAC,CAAC;EACJ;AAwBF"}
|
|
@@ -22,8 +22,6 @@ export declare class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
22
22
|
bindings: Record<string, Binding>;
|
|
23
23
|
/** WebGL varyings */
|
|
24
24
|
varyings: string[] | null;
|
|
25
|
-
_textureUniforms: Record<string, any>;
|
|
26
|
-
_textureIndexCounter: number;
|
|
27
25
|
_uniformCount: number;
|
|
28
26
|
_uniformSetters: Record<string, Function>;
|
|
29
27
|
constructor(device: WebGLDevice, props: RenderPipelineProps);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-render-pipeline.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-render-pipeline.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAE,mBAAmB,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAC9E,OAAO,KAAK,EAAC,YAAY,EAAoB,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAC,UAAU,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,cAAc,
|
|
1
|
+
{"version":3,"file":"webgl-render-pipeline.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/webgl-render-pipeline.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAE,mBAAmB,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAC9E,OAAO,KAAK,EAAC,YAAY,EAAoB,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAC,UAAU,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,cAAc,EAAsC,MAAM,eAAe,CAAC;AAUlF,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAQ3C,oCAAoC;AACpC,qBAAa,mBAAoB,SAAQ,cAAc;IACrD,yDAAyD;IACzD,MAAM,EAAE,WAAW,CAAC;IACpB,yCAAyC;IACzC,MAAM,EAAE,YAAY,CAAC;IACrB,oBAAoB;IACpB,EAAE,EAAE,WAAW,CAAC;IAChB,sBAAsB;IACtB,EAAE,EAAE,WAAW,CAAC;IAChB,mEAAmE;IACnE,kBAAkB,EAAE,YAAY,CAAC;IAEjC,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAM;IAC5C,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IACvC,qBAAqB;IACrB,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAQ;IAEjC,aAAa,EAAE,MAAM,CAAK;IAC1B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAM;gBAEnC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,mBAAmB;IA+BlD,OAAO,IAAI,IAAI;IAyCxB;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAiDpD,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAWlD;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE;QACZ,UAAU,EAAE,UAAU,CAAC;QACvB,wBAAwB;QACxB,WAAW,EAAE,WAAW,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO;IAgHX,SAAS,CAAC,eAAe;IA4BzB;;;;OAIG;IACH,sBAAsB;IAatB;;;;;;;;;;;;;;;;;;;;MAoBE;IAEF,iDAAiD;IACjD,cAAc;IA+Ed;;;OAGG;IACH,cAAc;CASf"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderPipeline, cast, log } from '@luma.gl/core';
|
|
1
|
+
import { RenderPipeline, cast, splitUniformsAndBindings, log } from '@luma.gl/core';
|
|
2
2
|
import { mergeShaderLayout } from '@luma.gl/core';
|
|
3
3
|
import { GL } from '@luma.gl/constants';
|
|
4
4
|
import { getShaderLayout } from "../helpers/get-shader-layout.js";
|
|
@@ -19,8 +19,6 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
19
19
|
this.uniforms = {};
|
|
20
20
|
this.bindings = {};
|
|
21
21
|
this.varyings = null;
|
|
22
|
-
this._textureUniforms = {};
|
|
23
|
-
this._textureIndexCounter = 0;
|
|
24
22
|
this._uniformCount = 0;
|
|
25
23
|
this._uniformSetters = {};
|
|
26
24
|
this.device = device;
|
|
@@ -52,7 +50,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
52
50
|
}
|
|
53
51
|
setBindings(bindings) {
|
|
54
52
|
for (const [name, value] of Object.entries(bindings)) {
|
|
55
|
-
const binding = this.shaderLayout.bindings.find(binding => binding.name === name);
|
|
53
|
+
const binding = this.shaderLayout.bindings.find(binding => binding.name === name) || this.shaderLayout.bindings.find(binding => binding.name === `${name}Uniforms`);
|
|
56
54
|
if (!binding) {
|
|
57
55
|
const validBindings = this.shaderLayout.bindings.map(binding => `"${binding.name}"`).join(', ');
|
|
58
56
|
log.warn(`Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`)();
|
|
@@ -82,6 +80,12 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
setUniforms(uniforms) {
|
|
83
|
+
const {
|
|
84
|
+
bindings
|
|
85
|
+
} = splitUniformsAndBindings(uniforms);
|
|
86
|
+
Object.keys(bindings).forEach(name => {
|
|
87
|
+
log.warn(`Unsupported value "${bindings[name]}" used in setUniforms() for key ${name}. Use setBindings() instead?`)();
|
|
88
|
+
});
|
|
85
89
|
Object.assign(this.uniforms, uniforms);
|
|
86
90
|
}
|
|
87
91
|
draw(options) {
|
|
@@ -151,12 +155,9 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
151
155
|
}
|
|
152
156
|
_areTexturesRenderable() {
|
|
153
157
|
let texturesRenderable = true;
|
|
154
|
-
for (const [, texture] of Object.entries(this._textureUniforms)) {
|
|
155
|
-
texture.update();
|
|
156
|
-
texturesRenderable = texturesRenderable && texture.loaded;
|
|
157
|
-
}
|
|
158
158
|
for (const [, texture] of Object.entries(this.bindings)) {
|
|
159
|
-
if (texture
|
|
159
|
+
if (texture instanceof WEBGLTexture) {
|
|
160
|
+
texture.update();
|
|
160
161
|
texturesRenderable = texturesRenderable && texture.loaded;
|
|
161
162
|
}
|
|
162
163
|
}
|
|
@@ -173,7 +174,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
|
|
|
173
174
|
let textureUnit = 0;
|
|
174
175
|
let uniformBufferIndex = 0;
|
|
175
176
|
for (const binding of this.shaderLayout.bindings) {
|
|
176
|
-
const value = this.bindings[binding.name];
|
|
177
|
+
const value = this.bindings[binding.name] || this.bindings[binding.name.replace(/Uniforms$/, '')];
|
|
177
178
|
if (!value) {
|
|
178
179
|
throw new Error(`No value for binding ${binding.name} in ${this.id}`);
|
|
179
180
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl-render-pipeline.js","names":["RenderPipeline","cast","log","mergeShaderLayout","GL","getShaderLayout","withDeviceAndGLParameters","setUniform","WEBGLBuffer","WEBGLFramebuffer","WEBGLTexture","LOG_PROGRAM_PERF_PRIORITY","WEBGLRenderPipeline","constructor","device","props","handle","vs","fs","introspectedLayout","uniforms","bindings","varyings","_textureUniforms","_textureIndexCounter","_uniformCount","_uniformSetters","gl","createProgram","setSpectorMetadata","id","bufferMode","SEPARATE_ATTRIBS","length","_this$device$gl","assertWebGL2","gl2","transformFeedbackVaryings","_compileAndLink","shaderLayout","destroy","deleteProgram","destroyed","setBindings","name","value","Object","entries","binding","find","validBindings","map","join","warn","type","buffer","Error","setUniforms","assign","draw","options","_vertexArray$indexBuf","renderPass","vertexArray","vertexCount","instanceCount","firstVertex","glDrawMode","getGLDrawMode","topology","isIndexed","Boolean","indexBuffer","glIndexType","isInstanced","Number","_areTexturesRenderable","useProgram","bindBeforeRender","primitiveMode","getGLPrimitive","transformFeedback","begin","_applyBindings","_applyUniforms","webglRenderPass","parameters","glParameters","_this$device$gl2","drawElementsInstanced","drawElements","_this$device$gl3","drawArraysInstanced","drawArrays","end","unbindAfterRender","attachShader","time","linkProgram","timeEnd","debug","level","linked","getProgramParameter","LINK_STATUS","getProgramInfoLog","validateProgram","validated","VALIDATE_STATUS","texturesRenderable","texture","update","loaded","undefined","textureUnit","uniformBufferIndex","location","getUniformBlockIndex","INVALID_INDEX","uniformBlockBinding","bindBufferBase","UNIFORM_BUFFER","bindBufferRange","offset","size","byteLength","colorAttachments","activeTexture","TEXTURE0","bindTexture","target","uniformLayout","_this$uniforms$name","POINTS","LINES","LINE_STRIP","LINE_LOOP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"],"sources":["../../../src/adapter/resources/webgl-render-pipeline.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {UniformValue, RenderPipelineProps, Binding} from '@luma.gl/core';\nimport type {ShaderLayout, PrimitiveTopology} from '@luma.gl/core';\nimport type {RenderPass, VertexArray} from '@luma.gl/core';\nimport {RenderPipeline, cast, log} from '@luma.gl/core';\nimport {mergeShaderLayout} from '@luma.gl/core';\n// import {mergeShaderLayout, getAttributeInfosFromLayouts} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\n\nimport {getShaderLayout} from '../helpers/get-shader-layout';\nimport {withDeviceAndGLParameters} from '../converters/device-parameters';\nimport {setUniform} from '../helpers/set-uniform';\n// import {copyUniform, checkUniformValues} from '../../classes/uniforms';\n\nimport {WebGLDevice} from '../webgl-device';\nimport {WEBGLBuffer} from './webgl-buffer';\nimport {WEBGLShader} from './webgl-shader';\nimport {WEBGLFramebuffer} from './webgl-framebuffer';\nimport {WEBGLTexture} from './webgl-texture';\n// import {WEBGLVertexArray} from './webgl-vertex-array';\nimport {WEBGLRenderPass} from './webgl-render-pass';\n\nconst LOG_PROGRAM_PERF_PRIORITY = 4;\n\n/** Creates a new render pipeline */\nexport class WEBGLRenderPipeline extends RenderPipeline {\n /** The WebGL device that created this render pipeline */\n device: WebGLDevice;\n /** Handle to underlying WebGL program */\n handle: WebGLProgram;\n /** vertex shader */\n vs: WEBGLShader;\n /** fragment shader */\n fs: WEBGLShader;\n /** The layout extracted from shader by WebGL introspection APIs */\n introspectedLayout: ShaderLayout;\n\n /** Uniforms set on this model */\n uniforms: Record<string, UniformValue> = {};\n /** Bindings set on this model */\n bindings: Record<string, Binding> = {};\n /** WebGL varyings */\n varyings: string[] | null = null;\n\n _textureUniforms: Record<string, any> = {};\n _textureIndexCounter: number = 0;\n _uniformCount: number = 0;\n _uniformSetters: Record<string, Function> = {}; // TODO are these used?\n\n constructor(device: WebGLDevice, props: RenderPipelineProps) {\n super(device, props);\n this.device = device;\n this.handle = this.props.handle || this.device.gl.createProgram();\n this.device.setSpectorMetadata(this.handle, {id: this.props.id});\n\n // Create shaders if needed\n this.vs = cast<WEBGLShader>(props.vs);\n this.fs = cast<WEBGLShader>(props.fs);\n // assert(this.vs.stage === 'vertex');\n // assert(this.fs.stage === 'fragment');\n\n // Setup varyings if supplied\n // @ts-expect-error WebGL only\n const {varyings, bufferMode = GL.SEPARATE_ATTRIBS} = props;\n if (varyings && varyings.length > 0) {\n this.device.assertWebGL2();\n this.varyings = varyings;\n this.device.gl2?.transformFeedbackVaryings(this.handle, varyings, bufferMode);\n }\n\n this._compileAndLink();\n\n this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);\n // Merge provided layout with introspected layout\n this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);\n // Merge layout with any buffer map overrides\n // this.bufferLayout = props.bufferLayout || [];\n // this.shaderLayout = mergeBufferMap(this.shaderLayout, this.bufferLayout);\n }\n\n override destroy(): void {\n if (this.handle) {\n this.device.gl.deleteProgram(this.handle);\n // this.handle = null;\n this.destroyed = true;\n }\n }\n\n // setIndexBuffer(indexBuffer: Buffer): void {\n // const webglBuffer = cast<WEBGLBuffer>(indexBuffer);\n // this.vertexArrayObject.setElementBuffer(webglBuffer);\n // this._indexBuffer = indexBuffer;\n // }\n\n // /** @todo needed for portable model */\n // setAttributes(attributes: Record<string, Buffer>): void {\n // for (const [name, buffer] of Object.entries(attributes)) {\n // const webglBuffer = cast<WEBGLBuffer>(buffer);\n // const attribute = getAttributeLayout(this.layout, name);\n // if (!attribute) {\n // log.warn(\n // `Ignoring buffer supplied for unknown attribute \"${name}\" in pipeline \"${this.id}\" (buffer \"${buffer.id}\")`\n // )();\n // continue;\n // }\n // const decoded = decodeVertexFormat(attribute.format);\n // const {type: typeString, components: size, byteLength: stride, normalized, integer} = decoded;\n // const divisor = attribute.stepMode === 'instance' ? 1 : 0;\n // const type = getWebGLDataType(typeString);\n // this.vertexArrayObject.setBuffer(attribute.location, webglBuffer, {\n // size,\n // type,\n // stride,\n // offset: 0,\n // normalized,\n // integer,\n // divisor\n // });\n // }\n // }\n\n /**\n * Bindings include: textures, samplers and uniform buffers\n * @todo needed for portable model\n */\n setBindings(bindings: Record<string, Binding>): void {\n // if (log.priority >= 2) {\n // checkUniformValues(uniforms, this.id, this._uniformSetters);\n // }\n\n for (const [name, value] of Object.entries(bindings)) {\n const binding = this.shaderLayout.bindings.find(binding => binding.name === name);\n if (!binding) {\n const validBindings = this.shaderLayout.bindings\n .map(binding => `\"${binding.name}\"`)\n .join(', ');\n log.warn(\n `Unknown binding \"${name}\" in render pipeline \"${this.id}\", expected one of ${validBindings}`\n )();\n continue; // eslint-disable-line no-continue\n }\n if (!value) {\n log.warn(`Unsetting binding \"${name}\" in render pipeline \"${this.id}\"`)();\n }\n switch (binding.type) {\n case 'uniform':\n // @ts-expect-error\n if (!(value instanceof WEBGLBuffer) && !(value.buffer instanceof WEBGLBuffer)) {\n throw new Error('buffer value');\n }\n break;\n case 'texture':\n if (!(value instanceof WEBGLTexture || value instanceof WEBGLFramebuffer)) {\n throw new Error('texture value');\n }\n break;\n case 'sampler':\n log.warn(`Ignoring sampler ${name}`)();\n break;\n default:\n throw new Error(binding.type);\n }\n\n this.bindings[name] = value;\n }\n }\n\n setUniforms(uniforms: Record<string, UniformValue>) {\n // TODO - check against layout\n Object.assign(this.uniforms, uniforms);\n }\n\n /** @todo needed for portable model\n * @note The WebGL API is offers many ways to draw things\n * This function unifies those ways into a single call using common parameters with sane defaults\n */\n draw(options: {\n renderPass: RenderPass;\n /** vertex attributes */\n vertexArray: VertexArray;\n vertexCount?: number;\n indexCount?: number;\n instanceCount?: number;\n firstVertex?: number;\n firstIndex?: number;\n firstInstance?: number;\n baseVertex?: number;\n }): boolean {\n const {\n renderPass,\n vertexArray,\n vertexCount,\n // indexCount,\n instanceCount,\n firstVertex = 0\n // firstIndex,\n // firstInstance,\n // baseVertex\n } = options;\n\n const glDrawMode = getGLDrawMode(this.props.topology);\n const isIndexed: boolean = Boolean(vertexArray.indexBuffer);\n const glIndexType = (vertexArray.indexBuffer as WEBGLBuffer)?.glIndexType;\n const isInstanced: boolean = Number(instanceCount) > 0;\n\n // Avoid WebGL draw call when not rendering any data or values are incomplete\n // Note: async textures set as uniforms might still be loading.\n // Now that all uniforms have been updated, check if any texture\n // in the uniforms is not yet initialized, then we don't draw\n if (!this._areTexturesRenderable() || vertexCount === 0) {\n // (isInstanced && instanceCount === 0)\n return false;\n }\n\n this.device.gl.useProgram(this.handle);\n\n // Note: Rebinds constant attributes before each draw call\n vertexArray.bindBeforeRender(renderPass);\n\n const primitiveMode = getGLPrimitive(this.props.topology);\n const transformFeedback: any = null;\n if (transformFeedback) {\n transformFeedback.begin(primitiveMode);\n }\n\n // We have to apply bindings before every draw call since other draw calls will overwrite\n this._applyBindings();\n this._applyUniforms();\n\n const webglRenderPass = renderPass as WEBGLRenderPass;\n // // TODO - Use polyfilled WebGL2RenderingContext instead of ANGLE extension\n // if (isIndexed && isInstanced) {\n // // ANGLE_instanced_arrays extension\n // this.device.gl2?.drawElementsInstanced(\n // drawMode,\n // vertexCount || 0, // indexCount?\n // indexType,\n // firstVertex,\n // instanceCount || 0\n // );\n // // } else if (isIndexed && this.device.isWebGL2 && !isNaN(start) && !isNaN(end)) {\n // // this.device.gl2.drawRangeElements(drawMode, start, end, vertexCount, indexType, offset);\n // } else if (isIndexed) {\n // this.device.gl.drawElements(drawMode, vertexCount || 0, indexType, firstVertex); // indexCount?\n // } else if (isInstanced) {\n // this.device.gl2?.drawArraysInstanced(\n // drawMode,\n // firstVertex,\n // vertexCount || 0,\n // instanceCount || 0\n // );\n // } else {\n // this.device.gl.drawArrays(drawMode, firstVertex, vertexCount || 0);\n // }\n // });\n\n withDeviceAndGLParameters(\n this.device,\n this.props.parameters,\n webglRenderPass.glParameters,\n () => {\n if (isIndexed && isInstanced) {\n // ANGLE_instanced_arrays extension\n this.device.gl2?.drawElementsInstanced(\n glDrawMode,\n vertexCount || 0, // indexCount?\n glIndexType,\n firstVertex,\n instanceCount || 0\n );\n // } else if (isIndexed && this.device.isWebGL2 && !isNaN(start) && !isNaN(end)) {\n // this.device.gl2.drawRangeElements(glDrawMode, start, end, vertexCount, glIndexType, offset);\n } else if (isIndexed) {\n this.device.gl.drawElements(glDrawMode, vertexCount || 0, glIndexType, firstVertex); // indexCount?\n } else if (isInstanced) {\n this.device.gl2?.drawArraysInstanced(\n glDrawMode,\n firstVertex,\n vertexCount || 0,\n instanceCount || 0\n );\n } else {\n this.device.gl.drawArrays(glDrawMode, firstVertex, vertexCount || 0);\n }\n\n if (transformFeedback) {\n transformFeedback.end();\n }\n }\n );\n\n vertexArray.unbindAfterRender(renderPass);\n\n return true;\n }\n\n // setAttributes(attributes: Record<string, Buffer>): void {}\n // setBindings(bindings: Record<string, Binding>): void {}\n\n protected _compileAndLink() {\n const {gl} = this.device;\n gl.attachShader(this.handle, this.vs.handle);\n gl.attachShader(this.handle, this.fs.handle);\n log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();\n gl.linkProgram(this.handle);\n log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();\n\n // Avoid checking program linking error in production\n // @ts-expect-error\n if (!gl.debug && log.level === 0) {\n // return;\n }\n\n const linked = gl.getProgramParameter(this.handle, gl.LINK_STATUS);\n if (!linked) {\n throw new Error(`Error linking: ${gl.getProgramInfoLog(this.handle)}`);\n }\n\n gl.validateProgram(this.handle);\n const validated = gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS);\n if (!validated) {\n throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);\n }\n }\n\n // PRIVATE METHODS\n\n /**\n * Checks if all texture-values uniforms are renderable (i.e. loaded)\n * Update a texture if needed (e.g. from video)\n * Note: This is currently done before every draw call\n */\n _areTexturesRenderable() {\n let texturesRenderable = true;\n\n for (const [, texture] of Object.entries(this._textureUniforms)) {\n texture.update();\n texturesRenderable = texturesRenderable && texture.loaded;\n }\n\n for (const [, texture] of Object.entries(this.bindings)) {\n // texture.update();\n // @ts-expect-error\n if (texture.loaded !== undefined) {\n // @ts-expect-error\n texturesRenderable = texturesRenderable && texture.loaded;\n }\n }\n\n return texturesRenderable;\n }\n\n /**\n * Constant attributes need to be reset before every draw call\n * Any attribute that is disabled in the current vertex array object\n * is read from the context's global constant value for that attribute location.\n * @note Constant attributes are only supported in WebGL, not in WebGPU\n *\n _applyConstantAttributes(vertexArray: WEBGLVertexArray): void {\n const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);\n for (const [name, value] of Object.entries(this.)) {\n const attributeInfo = attributeInfos[name];\n if (!attributeInfo) {\n log.warn(\n `Ignoring constant value supplied for unknown attribute \"${name}\" in pipeline \"${this.id}\"`\n )();\n continue; // eslint-disable-line no-continue\n }\n vertexArray.setConstant(attributeInfo.location, value);\n vertexArray.enable(attributeInfo.location, false);\n }\n }\n */\n\n /** Apply any bindings (before each draw call) */\n _applyBindings() {\n this.device.gl.useProgram(this.handle);\n\n const {gl2} = this.device;\n if (!gl2) {\n throw new Error('bindings');\n }\n\n let textureUnit = 0;\n let uniformBufferIndex = 0;\n for (const binding of this.shaderLayout.bindings) {\n const value = this.bindings[binding.name];\n if (!value) {\n throw new Error(`No value for binding ${binding.name} in ${this.id}`);\n }\n switch (binding.type) {\n case 'uniform':\n // Set buffer\n const {name} = binding;\n const location = gl2.getUniformBlockIndex(this.handle, name);\n if (location === GL.INVALID_INDEX) {\n throw new Error(`Invalid uniform block name ${name}`);\n }\n gl2.uniformBlockBinding(this.handle, uniformBufferIndex, location);\n // console.debug(binding, location);\n if (value instanceof WEBGLBuffer) {\n gl2.bindBufferBase(GL.UNIFORM_BUFFER, uniformBufferIndex, value.handle);\n } else {\n gl2.bindBufferRange(\n GL.UNIFORM_BUFFER,\n uniformBufferIndex,\n // @ts-expect-error\n value.buffer.handle,\n // @ts-expect-error\n value.offset || 0,\n // @ts-expect-error\n value.size || value.buffer.byteLength - value.offset\n );\n }\n uniformBufferIndex += 1;\n break;\n\n case 'texture':\n if (!(value instanceof WEBGLTexture || value instanceof WEBGLFramebuffer)) {\n throw new Error('texture');\n }\n let texture: WEBGLTexture;\n if (value instanceof WEBGLTexture) {\n texture = value;\n } else if (\n value instanceof WEBGLFramebuffer &&\n value.colorAttachments[0] instanceof WEBGLTexture\n ) {\n log.warn(\n 'Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead'\n )();\n texture = value.colorAttachments[0];\n } else {\n throw new Error('No texture');\n }\n\n gl2.activeTexture(GL.TEXTURE0 + textureUnit);\n gl2.bindTexture(texture.target, texture.handle);\n // gl2.bindSampler(textureUnit, sampler.handle);\n textureUnit += 1;\n break;\n\n case 'sampler':\n // ignore\n break;\n\n case 'storage':\n case 'read-only-storage':\n throw new Error(`binding type '${binding.type}' not supported in WebGL`);\n }\n }\n }\n\n /**\n * Due to program sharing, uniforms need to be reset before every draw call\n * (though caching will avoid redundant WebGL calls)\n */\n _applyUniforms() {\n for (const uniformLayout of this.shaderLayout.uniforms || []) {\n const {name, location, type, textureUnit} = uniformLayout;\n const value = this.uniforms[name] ?? textureUnit;\n if (value !== undefined) {\n setUniform(this.device.gl, location, type, value);\n }\n }\n }\n}\n\n/** Get the primitive type for draw */\nfunction getGLDrawMode(\n topology: PrimitiveTopology\n):\n | GL.POINTS\n | GL.LINES\n | GL.LINE_STRIP\n | GL.LINE_LOOP\n | GL.TRIANGLES\n | GL.TRIANGLE_STRIP\n | GL.TRIANGLE_FAN {\n // prettier-ignore\n switch (topology) {\n case 'point-list': return GL.POINTS;\n case 'line-list': return GL.LINES;\n case 'line-strip': return GL.LINE_STRIP;\n case 'line-loop-webgl': return GL.LINE_LOOP;\n case 'triangle-list': return GL.TRIANGLES;\n case 'triangle-strip': return GL.TRIANGLE_STRIP;\n case 'triangle-fan-webgl': return GL.TRIANGLE_FAN;\n default: throw new Error(topology);\n }\n}\n\n/** Get the primitive type for transform feedback */\nfunction getGLPrimitive(topology: PrimitiveTopology): GL.POINTS | GL.LINES | GL.TRIANGLES {\n // prettier-ignore\n switch (topology) {\n case 'point-list': return GL.POINTS;\n case 'line-list': return GL.LINES;\n case 'line-strip': return GL.LINES;\n case 'line-loop-webgl': return GL.LINES;\n case 'triangle-list': return GL.TRIANGLES;\n case 'triangle-strip': return GL.TRIANGLES;\n case 'triangle-fan-webgl': return GL.TRIANGLES;\n default: throw new Error(topology);\n }\n}\n"],"mappings":"AAMA,SAAQA,cAAc,EAAEC,IAAI,EAAEC,GAAG,QAAO,eAAe;AACvD,SAAQC,iBAAiB,QAAO,eAAe;AAE/C,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAE9BC,eAAe;AAAA,SACfC,yBAAyB;AAAA,SACzBC,UAAU;AAAA,SAIVC,WAAW;AAAA,SAEXC,gBAAgB;AAAA,SAChBC,YAAY;AAIpB,MAAMC,yBAAyB,GAAG,CAAC;AAGnC,OAAO,MAAMC,mBAAmB,SAASZ,cAAc,CAAC;EAwBtDa,WAAWA,CAACC,MAAmB,EAAEC,KAA0B,EAAE;IAC3D,KAAK,CAACD,MAAM,EAAEC,KAAK,CAAC;IAAC,KAvBvBD,MAAM;IAAA,KAENE,MAAM;IAAA,KAENC,EAAE;IAAA,KAEFC,EAAE;IAAA,KAEFC,kBAAkB;IAAA,KAGlBC,QAAQ,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,EAAE,CAACmI,UAAU;IACvC,KAAK,iBAAiB;MAAE,OAAOnI,EAAE,CAACoI,SAAS;IAC3C,KAAK,eAAe;MAAE,OAAOpI,EAAE,CAACqI,SAAS;IACzC,KAAK,gBAAgB;MAAE,OAAOrI,EAAE,CAACsI,cAAc;IAC/C,KAAK,oBAAoB;MAAE,OAAOtI,EAAE,CAACuI,YAAY;IACjD;MAAS,MAAM,IAAInF,KAAK,CAACa,QAAQ,CAAC;EACpC;AACF;AAGA,SAASW,cAAcA,CAACX,QAA2B,EAAuC;EAExF,QAAQA,QAAQ;IACd,KAAK,YAAY;MAAE,OAAOjE,EAAE,CAACiI,MAAM;IACnC,KAAK,WAAW;MAAE,OAAOjI,EAAE,CAACkI,KAAK;IACjC,KAAK,YAAY;MAAE,OAAOlI,EAAE,CAACkI,KAAK;IAClC,KAAK,iBAAiB;MAAE,OAAOlI,EAAE,CAACkI,KAAK;IACvC,KAAK,eAAe;MAAE,OAAOlI,EAAE,CAACqI,SAAS;IACzC,KAAK,gBAAgB;MAAE,OAAOrI,EAAE,CAACqI,SAAS;IAC1C,KAAK,oBAAoB;MAAE,OAAOrI,EAAE,CAACqI,SAAS;IAC9C;MAAS,MAAM,IAAIjF,KAAK,CAACa,QAAQ,CAAC;EACpC;AACF"}
|
|
1
|
+
{"version":3,"file":"webgl-render-pipeline.js","names":["RenderPipeline","cast","splitUniformsAndBindings","log","mergeShaderLayout","GL","getShaderLayout","withDeviceAndGLParameters","setUniform","WEBGLBuffer","WEBGLFramebuffer","WEBGLTexture","LOG_PROGRAM_PERF_PRIORITY","WEBGLRenderPipeline","constructor","device","props","handle","vs","fs","introspectedLayout","uniforms","bindings","varyings","_uniformCount","_uniformSetters","gl","createProgram","setSpectorMetadata","id","bufferMode","SEPARATE_ATTRIBS","length","_this$device$gl","assertWebGL2","gl2","transformFeedbackVaryings","_compileAndLink","shaderLayout","destroy","deleteProgram","destroyed","setBindings","name","value","Object","entries","binding","find","validBindings","map","join","warn","type","buffer","Error","setUniforms","keys","forEach","assign","draw","options","_vertexArray$indexBuf","renderPass","vertexArray","vertexCount","instanceCount","firstVertex","glDrawMode","getGLDrawMode","topology","isIndexed","Boolean","indexBuffer","glIndexType","isInstanced","Number","_areTexturesRenderable","useProgram","bindBeforeRender","primitiveMode","getGLPrimitive","transformFeedback","begin","_applyBindings","_applyUniforms","webglRenderPass","parameters","glParameters","_this$device$gl2","drawElementsInstanced","drawElements","_this$device$gl3","drawArraysInstanced","drawArrays","end","unbindAfterRender","attachShader","time","linkProgram","timeEnd","debug","level","linked","getProgramParameter","LINK_STATUS","getProgramInfoLog","validateProgram","validated","VALIDATE_STATUS","texturesRenderable","texture","update","loaded","textureUnit","uniformBufferIndex","replace","location","getUniformBlockIndex","INVALID_INDEX","uniformBlockBinding","bindBufferBase","UNIFORM_BUFFER","bindBufferRange","offset","size","byteLength","colorAttachments","activeTexture","TEXTURE0","bindTexture","target","uniformLayout","_this$uniforms$name","undefined","POINTS","LINES","LINE_STRIP","LINE_LOOP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"],"sources":["../../../src/adapter/resources/webgl-render-pipeline.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {UniformValue, RenderPipelineProps, Binding} from '@luma.gl/core';\nimport type {ShaderLayout, PrimitiveTopology} from '@luma.gl/core';\nimport type {RenderPass, VertexArray} from '@luma.gl/core';\nimport {RenderPipeline, cast, splitUniformsAndBindings, log} from '@luma.gl/core';\nimport {mergeShaderLayout} from '@luma.gl/core';\n// import {mergeShaderLayout, getAttributeInfosFromLayouts} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\n\nimport {getShaderLayout} from '../helpers/get-shader-layout';\nimport {withDeviceAndGLParameters} from '../converters/device-parameters';\nimport {setUniform} from '../helpers/set-uniform';\n// import {copyUniform, checkUniformValues} from '../../classes/uniforms';\n\nimport {WebGLDevice} from '../webgl-device';\nimport {WEBGLBuffer} from './webgl-buffer';\nimport {WEBGLShader} from './webgl-shader';\nimport {WEBGLFramebuffer} from './webgl-framebuffer';\nimport {WEBGLTexture} from './webgl-texture';\n// import {WEBGLVertexArray} from './webgl-vertex-array';\nimport {WEBGLRenderPass} from './webgl-render-pass';\n\nconst LOG_PROGRAM_PERF_PRIORITY = 4;\n\n/** Creates a new render pipeline */\nexport class WEBGLRenderPipeline extends RenderPipeline {\n /** The WebGL device that created this render pipeline */\n device: WebGLDevice;\n /** Handle to underlying WebGL program */\n handle: WebGLProgram;\n /** vertex shader */\n vs: WEBGLShader;\n /** fragment shader */\n fs: WEBGLShader;\n /** The layout extracted from shader by WebGL introspection APIs */\n introspectedLayout: ShaderLayout;\n\n /** Uniforms set on this model */\n uniforms: Record<string, UniformValue> = {};\n /** Bindings set on this model */\n bindings: Record<string, Binding> = {};\n /** WebGL varyings */\n varyings: string[] | null = null;\n\n _uniformCount: number = 0;\n _uniformSetters: Record<string, Function> = {}; // TODO are these used?\n\n constructor(device: WebGLDevice, props: RenderPipelineProps) {\n super(device, props);\n this.device = device;\n this.handle = this.props.handle || this.device.gl.createProgram();\n this.device.setSpectorMetadata(this.handle, {id: this.props.id});\n\n // Create shaders if needed\n this.vs = cast<WEBGLShader>(props.vs);\n this.fs = cast<WEBGLShader>(props.fs);\n // assert(this.vs.stage === 'vertex');\n // assert(this.fs.stage === 'fragment');\n\n // Setup varyings if supplied\n // @ts-expect-error WebGL only\n const {varyings, bufferMode = GL.SEPARATE_ATTRIBS} = props;\n if (varyings && varyings.length > 0) {\n this.device.assertWebGL2();\n this.varyings = varyings;\n this.device.gl2?.transformFeedbackVaryings(this.handle, varyings, bufferMode);\n }\n\n this._compileAndLink();\n\n this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);\n // Merge provided layout with introspected layout\n this.shaderLayout = mergeShaderLayout(this.introspectedLayout, props.shaderLayout);\n // Merge layout with any buffer map overrides\n // this.bufferLayout = props.bufferLayout || [];\n // this.shaderLayout = mergeBufferMap(this.shaderLayout, this.bufferLayout);\n }\n\n override destroy(): void {\n if (this.handle) {\n this.device.gl.deleteProgram(this.handle);\n // this.handle = null;\n this.destroyed = true;\n }\n }\n\n // setIndexBuffer(indexBuffer: Buffer): void {\n // const webglBuffer = cast<WEBGLBuffer>(indexBuffer);\n // this.vertexArrayObject.setElementBuffer(webglBuffer);\n // this._indexBuffer = indexBuffer;\n // }\n\n // /** @todo needed for portable model */\n // setAttributes(attributes: Record<string, Buffer>): void {\n // for (const [name, buffer] of Object.entries(attributes)) {\n // const webglBuffer = cast<WEBGLBuffer>(buffer);\n // const attribute = getAttributeLayout(this.layout, name);\n // if (!attribute) {\n // log.warn(\n // `Ignoring buffer supplied for unknown attribute \"${name}\" in pipeline \"${this.id}\" (buffer \"${buffer.id}\")`\n // )();\n // continue;\n // }\n // const decoded = decodeVertexFormat(attribute.format);\n // const {type: typeString, components: size, byteLength: stride, normalized, integer} = decoded;\n // const divisor = attribute.stepMode === 'instance' ? 1 : 0;\n // const type = getWebGLDataType(typeString);\n // this.vertexArrayObject.setBuffer(attribute.location, webglBuffer, {\n // size,\n // type,\n // stride,\n // offset: 0,\n // normalized,\n // integer,\n // divisor\n // });\n // }\n // }\n\n /**\n * Bindings include: textures, samplers and uniform buffers\n * @todo needed for portable model\n */\n setBindings(bindings: Record<string, Binding>): void {\n // if (log.priority >= 2) {\n // checkUniformValues(uniforms, this.id, this._uniformSetters);\n // }\n\n for (const [name, value] of Object.entries(bindings)) {\n // Accept both `xyz` and `xyzUniforms` as valid names for `xyzUniforms` uniform block\n // This convention allows shaders to name uniform blocks as `uniform appUniforms {} app;`\n // and reference them as `app` from both GLSL and JS.\n // TODO - this is rather hacky - we could also remap the name directly in the shader layout.\n const binding = \n this.shaderLayout.bindings.find(binding => binding.name === name) ||\n this.shaderLayout.bindings.find(binding => binding.name === `${name}Uniforms`);\n\n if (!binding) {\n const validBindings = this.shaderLayout.bindings\n .map(binding => `\"${binding.name}\"`)\n .join(', ');\n log.warn(\n `Unknown binding \"${name}\" in render pipeline \"${this.id}\", expected one of ${validBindings}`\n )();\n continue; // eslint-disable-line no-continue\n }\n if (!value) {\n log.warn(`Unsetting binding \"${name}\" in render pipeline \"${this.id}\"`)();\n }\n switch (binding.type) {\n case 'uniform':\n // @ts-expect-error\n if (!(value instanceof WEBGLBuffer) && !(value.buffer instanceof WEBGLBuffer)) {\n throw new Error('buffer value');\n }\n break;\n case 'texture':\n if (!(value instanceof WEBGLTexture || value instanceof WEBGLFramebuffer)) {\n throw new Error('texture value');\n }\n break;\n case 'sampler':\n log.warn(`Ignoring sampler ${name}`)();\n break;\n default:\n throw new Error(binding.type);\n }\n\n this.bindings[name] = value;\n }\n }\n\n setUniforms(uniforms: Record<string, UniformValue>) {\n const {bindings} = splitUniformsAndBindings(uniforms);\n Object.keys(bindings).forEach(name => {\n log.warn(\n `Unsupported value \"${bindings[name]}\" used in setUniforms() for key ${name}. Use setBindings() instead?`\n )();\n });\n // TODO - check against layout\n Object.assign(this.uniforms, uniforms);\n }\n\n /** @todo needed for portable model\n * @note The WebGL API is offers many ways to draw things\n * This function unifies those ways into a single call using common parameters with sane defaults\n */\n draw(options: {\n renderPass: RenderPass;\n /** vertex attributes */\n vertexArray: VertexArray;\n vertexCount?: number;\n indexCount?: number;\n instanceCount?: number;\n firstVertex?: number;\n firstIndex?: number;\n firstInstance?: number;\n baseVertex?: number;\n }): boolean {\n const {\n renderPass,\n vertexArray,\n vertexCount,\n // indexCount,\n instanceCount,\n firstVertex = 0\n // firstIndex,\n // firstInstance,\n // baseVertex\n } = options;\n\n const glDrawMode = getGLDrawMode(this.props.topology);\n const isIndexed: boolean = Boolean(vertexArray.indexBuffer);\n const glIndexType = (vertexArray.indexBuffer as WEBGLBuffer)?.glIndexType;\n const isInstanced: boolean = Number(instanceCount) > 0;\n\n // Avoid WebGL draw call when not rendering any data or values are incomplete\n // Note: async textures set as uniforms might still be loading.\n // Now that all uniforms have been updated, check if any texture\n // in the uniforms is not yet initialized, then we don't draw\n if (!this._areTexturesRenderable() || vertexCount === 0) {\n // (isInstanced && instanceCount === 0)\n return false;\n }\n\n this.device.gl.useProgram(this.handle);\n\n // Note: Rebinds constant attributes before each draw call\n vertexArray.bindBeforeRender(renderPass);\n\n const primitiveMode = getGLPrimitive(this.props.topology);\n const transformFeedback: any = null;\n if (transformFeedback) {\n transformFeedback.begin(primitiveMode);\n }\n\n // We have to apply bindings before every draw call since other draw calls will overwrite\n this._applyBindings();\n this._applyUniforms();\n\n const webglRenderPass = renderPass as WEBGLRenderPass;\n // // TODO - Use polyfilled WebGL2RenderingContext instead of ANGLE extension\n // if (isIndexed && isInstanced) {\n // // ANGLE_instanced_arrays extension\n // this.device.gl2?.drawElementsInstanced(\n // drawMode,\n // vertexCount || 0, // indexCount?\n // indexType,\n // firstVertex,\n // instanceCount || 0\n // );\n // // } else if (isIndexed && this.device.isWebGL2 && !isNaN(start) && !isNaN(end)) {\n // // this.device.gl2.drawRangeElements(drawMode, start, end, vertexCount, indexType, offset);\n // } else if (isIndexed) {\n // this.device.gl.drawElements(drawMode, vertexCount || 0, indexType, firstVertex); // indexCount?\n // } else if (isInstanced) {\n // this.device.gl2?.drawArraysInstanced(\n // drawMode,\n // firstVertex,\n // vertexCount || 0,\n // instanceCount || 0\n // );\n // } else {\n // this.device.gl.drawArrays(drawMode, firstVertex, vertexCount || 0);\n // }\n // });\n\n withDeviceAndGLParameters(\n this.device,\n this.props.parameters,\n webglRenderPass.glParameters,\n () => {\n if (isIndexed && isInstanced) {\n // ANGLE_instanced_arrays extension\n this.device.gl2?.drawElementsInstanced(\n glDrawMode,\n vertexCount || 0, // indexCount?\n glIndexType,\n firstVertex,\n instanceCount || 0\n );\n // } else if (isIndexed && this.device.isWebGL2 && !isNaN(start) && !isNaN(end)) {\n // this.device.gl2.drawRangeElements(glDrawMode, start, end, vertexCount, glIndexType, offset);\n } else if (isIndexed) {\n this.device.gl.drawElements(glDrawMode, vertexCount || 0, glIndexType, firstVertex); // indexCount?\n } else if (isInstanced) {\n this.device.gl2?.drawArraysInstanced(\n glDrawMode,\n firstVertex,\n vertexCount || 0,\n instanceCount || 0\n );\n } else {\n this.device.gl.drawArrays(glDrawMode, firstVertex, vertexCount || 0);\n }\n\n if (transformFeedback) {\n transformFeedback.end();\n }\n }\n );\n\n vertexArray.unbindAfterRender(renderPass);\n\n return true;\n }\n\n // setAttributes(attributes: Record<string, Buffer>): void {}\n // setBindings(bindings: Record<string, Binding>): void {}\n\n protected _compileAndLink() {\n const {gl} = this.device;\n gl.attachShader(this.handle, this.vs.handle);\n gl.attachShader(this.handle, this.fs.handle);\n log.time(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();\n gl.linkProgram(this.handle);\n log.timeEnd(LOG_PROGRAM_PERF_PRIORITY, `linkProgram for ${this.id}`)();\n\n // Avoid checking program linking error in production\n // @ts-expect-error\n if (!gl.debug && log.level === 0) {\n // return;\n }\n\n const linked = gl.getProgramParameter(this.handle, gl.LINK_STATUS);\n if (!linked) {\n throw new Error(`Error linking: ${gl.getProgramInfoLog(this.handle)}`);\n }\n\n gl.validateProgram(this.handle);\n const validated = gl.getProgramParameter(this.handle, gl.VALIDATE_STATUS);\n if (!validated) {\n throw new Error(`Error validating: ${gl.getProgramInfoLog(this.handle)}`);\n }\n }\n\n // PRIVATE METHODS\n\n /**\n * Checks if all texture-values uniforms are renderable (i.e. loaded)\n * Update a texture if needed (e.g. from video)\n * Note: This is currently done before every draw call\n */\n _areTexturesRenderable() {\n let texturesRenderable = true;\n\n for (const [, texture] of Object.entries(this.bindings)) {\n if (texture instanceof WEBGLTexture) {\n texture.update();\n texturesRenderable = texturesRenderable && texture.loaded;\n }\n }\n\n return texturesRenderable;\n }\n\n /**\n * Constant attributes need to be reset before every draw call\n * Any attribute that is disabled in the current vertex array object\n * is read from the context's global constant value for that attribute location.\n * @note Constant attributes are only supported in WebGL, not in WebGPU\n *\n _applyConstantAttributes(vertexArray: WEBGLVertexArray): void {\n const attributeInfos = getAttributeInfosFromLayouts(this.shaderLayout, this.bufferLayout);\n for (const [name, value] of Object.entries(this.)) {\n const attributeInfo = attributeInfos[name];\n if (!attributeInfo) {\n log.warn(\n `Ignoring constant value supplied for unknown attribute \"${name}\" in pipeline \"${this.id}\"`\n )();\n continue; // eslint-disable-line no-continue\n }\n vertexArray.setConstant(attributeInfo.location, value);\n vertexArray.enable(attributeInfo.location, false);\n }\n }\n */\n\n /** Apply any bindings (before each draw call) */\n _applyBindings() {\n this.device.gl.useProgram(this.handle);\n\n const {gl2} = this.device;\n if (!gl2) {\n throw new Error('bindings');\n }\n\n let textureUnit = 0;\n let uniformBufferIndex = 0;\n for (const binding of this.shaderLayout.bindings) {\n // Accept both `xyz` and `xyzUniforms` as valid names for `xyzUniforms` uniform block\n const value = this.bindings[binding.name] || this.bindings[binding.name.replace(/Uniforms$/, '')];\n if (!value) {\n throw new Error(`No value for binding ${binding.name} in ${this.id}`);\n }\n switch (binding.type) {\n case 'uniform':\n // Set buffer\n const {name} = binding;\n const location = gl2.getUniformBlockIndex(this.handle, name);\n if (location === GL.INVALID_INDEX) {\n throw new Error(`Invalid uniform block name ${name}`);\n }\n gl2.uniformBlockBinding(this.handle, uniformBufferIndex, location);\n // console.debug(binding, location);\n if (value instanceof WEBGLBuffer) {\n gl2.bindBufferBase(GL.UNIFORM_BUFFER, uniformBufferIndex, value.handle);\n } else {\n gl2.bindBufferRange(\n GL.UNIFORM_BUFFER,\n uniformBufferIndex,\n // @ts-expect-error\n value.buffer.handle,\n // @ts-expect-error\n value.offset || 0,\n // @ts-expect-error\n value.size || value.buffer.byteLength - value.offset\n );\n }\n uniformBufferIndex += 1;\n break;\n\n case 'texture':\n if (!(value instanceof WEBGLTexture || value instanceof WEBGLFramebuffer)) {\n throw new Error('texture');\n }\n let texture: WEBGLTexture;\n if (value instanceof WEBGLTexture) {\n texture = value;\n } else if (\n value instanceof WEBGLFramebuffer &&\n value.colorAttachments[0] instanceof WEBGLTexture\n ) {\n log.warn(\n 'Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead'\n )();\n texture = value.colorAttachments[0];\n } else {\n throw new Error('No texture');\n }\n\n gl2.activeTexture(GL.TEXTURE0 + textureUnit);\n gl2.bindTexture(texture.target, texture.handle);\n // gl2.bindSampler(textureUnit, sampler.handle);\n textureUnit += 1;\n break;\n\n case 'sampler':\n // ignore\n break;\n\n case 'storage':\n case 'read-only-storage':\n throw new Error(`binding type '${binding.type}' not supported in WebGL`);\n }\n }\n }\n\n /**\n * Due to program sharing, uniforms need to be reset before every draw call\n * (though caching will avoid redundant WebGL calls)\n */\n _applyUniforms() {\n for (const uniformLayout of this.shaderLayout.uniforms || []) {\n const {name, location, type, textureUnit} = uniformLayout;\n const value = this.uniforms[name] ?? textureUnit;\n if (value !== undefined) {\n setUniform(this.device.gl, location, type, value);\n }\n }\n }\n}\n\n/** Get the primitive type for draw */\nfunction getGLDrawMode(\n topology: PrimitiveTopology\n):\n | GL.POINTS\n | GL.LINES\n | GL.LINE_STRIP\n | GL.LINE_LOOP\n | GL.TRIANGLES\n | GL.TRIANGLE_STRIP\n | GL.TRIANGLE_FAN {\n // prettier-ignore\n switch (topology) {\n case 'point-list': return GL.POINTS;\n case 'line-list': return GL.LINES;\n case 'line-strip': return GL.LINE_STRIP;\n case 'line-loop-webgl': return GL.LINE_LOOP;\n case 'triangle-list': return GL.TRIANGLES;\n case 'triangle-strip': return GL.TRIANGLE_STRIP;\n case 'triangle-fan-webgl': return GL.TRIANGLE_FAN;\n default: throw new Error(topology);\n }\n}\n\n/** Get the primitive type for transform feedback */\nfunction getGLPrimitive(topology: PrimitiveTopology): GL.POINTS | GL.LINES | GL.TRIANGLES {\n // prettier-ignore\n switch (topology) {\n case 'point-list': return GL.POINTS;\n case 'line-list': return GL.LINES;\n case 'line-strip': return GL.LINES;\n case 'line-loop-webgl': return GL.LINES;\n case 'triangle-list': return GL.TRIANGLES;\n case 'triangle-strip': return GL.TRIANGLES;\n case 'triangle-fan-webgl': return GL.TRIANGLES;\n default: throw new Error(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AK,WAAW;MAAE,OAAOlI,EAAE,CAACmI,KAAK;IACjC,KAAK,YAAY;MAAE,OAAOnI,EAAE,CAACmI,KAAK;IAClC,KAAK,iBAAiB;MAAE,OAAOnI,EAAE,CAACmI,KAAK;IACvC,KAAK,eAAe;MAAE,OAAOnI,EAAE,CAACsI,SAAS;IACzC,KAAK,gBAAgB;MAAE,OAAOtI,EAAE,CAACsI,SAAS;IAC1C,KAAK,oBAAoB;MAAE,OAAOtI,EAAE,CAACsI,SAAS;IAC9C;MAAS,MAAM,IAAIpF,KAAK,CAACe,QAAQ,CAAC;EACpC;AACF"}
|
package/dist/dist.dev.js
CHANGED
|
@@ -908,6 +908,17 @@ var __exports__ = (() => {
|
|
|
908
908
|
}
|
|
909
909
|
var VERSION2 = initializeLuma();
|
|
910
910
|
|
|
911
|
+
// ../core/src/lib/utils/is-array.ts
|
|
912
|
+
function isTypedArray(value) {
|
|
913
|
+
return ArrayBuffer.isView(value) && !(value instanceof DataView) ? value : null;
|
|
914
|
+
}
|
|
915
|
+
function isNumberArray(value) {
|
|
916
|
+
if (Array.isArray(value)) {
|
|
917
|
+
return value.length === 0 || typeof value[0] === "number" ? value : null;
|
|
918
|
+
}
|
|
919
|
+
return isTypedArray(value);
|
|
920
|
+
}
|
|
921
|
+
|
|
911
922
|
// ../core/src/lib/utils/utils.ts
|
|
912
923
|
var uidCounters = {};
|
|
913
924
|
function uid(id = "id") {
|
|
@@ -2468,6 +2479,26 @@ var __exports__ = (() => {
|
|
|
2468
2479
|
return value;
|
|
2469
2480
|
}
|
|
2470
2481
|
|
|
2482
|
+
// ../core/src/lib/utils/uniform.ts
|
|
2483
|
+
function isUniformValue(value) {
|
|
2484
|
+
return isNumberArray(value) !== null || typeof value === "number" || typeof value === "boolean";
|
|
2485
|
+
}
|
|
2486
|
+
function splitUniformsAndBindings(uniforms) {
|
|
2487
|
+
const result = {
|
|
2488
|
+
bindings: {},
|
|
2489
|
+
uniforms: {}
|
|
2490
|
+
};
|
|
2491
|
+
Object.keys(uniforms).forEach((name2) => {
|
|
2492
|
+
const uniform = uniforms[name2];
|
|
2493
|
+
if (isUniformValue(uniform)) {
|
|
2494
|
+
result.uniforms[name2] = uniform;
|
|
2495
|
+
} else {
|
|
2496
|
+
result.bindings[name2] = uniform;
|
|
2497
|
+
}
|
|
2498
|
+
});
|
|
2499
|
+
return result;
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2471
2502
|
// ../core/src/lib/utils/stub-methods.ts
|
|
2472
2503
|
function stubRemovedMethods(instance, className, version, methodNames) {
|
|
2473
2504
|
const upgradeMessage = `See luma.gl ${version} Upgrade Guide at https://luma.gl/docs/upgrade-guide`;
|
|
@@ -8375,10 +8406,17 @@ ${formattedLog}`)();
|
|
|
8375
8406
|
constructor(device, props) {
|
|
8376
8407
|
super(device, props);
|
|
8377
8408
|
this.device = device;
|
|
8409
|
+
pushContextState(this.device.gl);
|
|
8378
8410
|
this.setParameters(this.props.parameters);
|
|
8379
8411
|
this.clear();
|
|
8380
8412
|
}
|
|
8381
8413
|
end() {
|
|
8414
|
+
popContextState(this.device.gl);
|
|
8415
|
+
if (this.props.framebuffer) {
|
|
8416
|
+
setGLParameters(this.device, {
|
|
8417
|
+
framebuffer: null
|
|
8418
|
+
});
|
|
8419
|
+
}
|
|
8382
8420
|
}
|
|
8383
8421
|
pushDebugGroup(groupLabel) {
|
|
8384
8422
|
}
|
|
@@ -8913,8 +8951,6 @@ ${formattedLog}`)();
|
|
|
8913
8951
|
bindings = {};
|
|
8914
8952
|
/** WebGL varyings */
|
|
8915
8953
|
varyings = null;
|
|
8916
|
-
_textureUniforms = {};
|
|
8917
|
-
_textureIndexCounter = 0;
|
|
8918
8954
|
_uniformCount = 0;
|
|
8919
8955
|
_uniformSetters = {};
|
|
8920
8956
|
// TODO are these used?
|
|
@@ -8983,7 +9019,7 @@ ${formattedLog}`)();
|
|
|
8983
9019
|
*/
|
|
8984
9020
|
setBindings(bindings) {
|
|
8985
9021
|
for (const [name2, value] of Object.entries(bindings)) {
|
|
8986
|
-
const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name2);
|
|
9022
|
+
const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name2) || this.shaderLayout.bindings.find((binding2) => binding2.name === `${name2}Uniforms`);
|
|
8987
9023
|
if (!binding) {
|
|
8988
9024
|
const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
|
|
8989
9025
|
log.warn(`Unknown binding "${name2}" in render pipeline "${this.id}", expected one of ${validBindings}`)();
|
|
@@ -9013,6 +9049,12 @@ ${formattedLog}`)();
|
|
|
9013
9049
|
}
|
|
9014
9050
|
}
|
|
9015
9051
|
setUniforms(uniforms) {
|
|
9052
|
+
const {
|
|
9053
|
+
bindings
|
|
9054
|
+
} = splitUniformsAndBindings(uniforms);
|
|
9055
|
+
Object.keys(bindings).forEach((name2) => {
|
|
9056
|
+
log.warn(`Unsupported value "${bindings[name2]}" used in setUniforms() for key ${name2}. Use setBindings() instead?`)();
|
|
9057
|
+
});
|
|
9016
9058
|
Object.assign(this.uniforms, uniforms);
|
|
9017
9059
|
}
|
|
9018
9060
|
/** @todo needed for portable model
|
|
@@ -9103,12 +9145,9 @@ ${formattedLog}`)();
|
|
|
9103
9145
|
*/
|
|
9104
9146
|
_areTexturesRenderable() {
|
|
9105
9147
|
let texturesRenderable = true;
|
|
9106
|
-
for (const [, texture] of Object.entries(this._textureUniforms)) {
|
|
9107
|
-
texture.update();
|
|
9108
|
-
texturesRenderable = texturesRenderable && texture.loaded;
|
|
9109
|
-
}
|
|
9110
9148
|
for (const [, texture] of Object.entries(this.bindings)) {
|
|
9111
|
-
if (texture
|
|
9149
|
+
if (texture instanceof WEBGLTexture) {
|
|
9150
|
+
texture.update();
|
|
9112
9151
|
texturesRenderable = texturesRenderable && texture.loaded;
|
|
9113
9152
|
}
|
|
9114
9153
|
}
|
|
@@ -9147,7 +9186,7 @@ ${formattedLog}`)();
|
|
|
9147
9186
|
let textureUnit = 0;
|
|
9148
9187
|
let uniformBufferIndex = 0;
|
|
9149
9188
|
for (const binding of this.shaderLayout.bindings) {
|
|
9150
|
-
const value = this.bindings[binding.name];
|
|
9189
|
+
const value = this.bindings[binding.name] || this.bindings[binding.name.replace(/Uniforms$/, "")];
|
|
9151
9190
|
if (!value) {
|
|
9152
9191
|
throw new Error(`No value for binding ${binding.name} in ${this.id}`);
|
|
9153
9192
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -4697,10 +4697,15 @@ var WEBGLRenderPass = class extends import_core21.RenderPass {
|
|
|
4697
4697
|
constructor(device, props) {
|
|
4698
4698
|
super(device, props);
|
|
4699
4699
|
this.device = device;
|
|
4700
|
+
pushContextState(this.device.gl);
|
|
4700
4701
|
this.setParameters(this.props.parameters);
|
|
4701
4702
|
this.clear();
|
|
4702
4703
|
}
|
|
4703
4704
|
end() {
|
|
4705
|
+
popContextState(this.device.gl);
|
|
4706
|
+
if (this.props.framebuffer) {
|
|
4707
|
+
setGLParameters(this.device, { framebuffer: null });
|
|
4708
|
+
}
|
|
4704
4709
|
}
|
|
4705
4710
|
pushDebugGroup(groupLabel) {
|
|
4706
4711
|
}
|
|
@@ -5218,8 +5223,6 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
|
|
|
5218
5223
|
this.bindings = {};
|
|
5219
5224
|
/** WebGL varyings */
|
|
5220
5225
|
this.varyings = null;
|
|
5221
|
-
this._textureUniforms = {};
|
|
5222
|
-
this._textureIndexCounter = 0;
|
|
5223
5226
|
this._uniformCount = 0;
|
|
5224
5227
|
this._uniformSetters = {};
|
|
5225
5228
|
this.device = device;
|
|
@@ -5280,7 +5283,7 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
|
|
|
5280
5283
|
*/
|
|
5281
5284
|
setBindings(bindings) {
|
|
5282
5285
|
for (const [name, value] of Object.entries(bindings)) {
|
|
5283
|
-
const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name);
|
|
5286
|
+
const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name) || this.shaderLayout.bindings.find((binding2) => binding2.name === `${name}Uniforms`);
|
|
5284
5287
|
if (!binding) {
|
|
5285
5288
|
const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
|
|
5286
5289
|
import_core22.log.warn(
|
|
@@ -5312,6 +5315,12 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
|
|
|
5312
5315
|
}
|
|
5313
5316
|
}
|
|
5314
5317
|
setUniforms(uniforms) {
|
|
5318
|
+
const { bindings } = (0, import_core22.splitUniformsAndBindings)(uniforms);
|
|
5319
|
+
Object.keys(bindings).forEach((name) => {
|
|
5320
|
+
import_core22.log.warn(
|
|
5321
|
+
`Unsupported value "${bindings[name]}" used in setUniforms() for key ${name}. Use setBindings() instead?`
|
|
5322
|
+
)();
|
|
5323
|
+
});
|
|
5315
5324
|
Object.assign(this.uniforms, uniforms);
|
|
5316
5325
|
}
|
|
5317
5326
|
/** @todo needed for portable model
|
|
@@ -5412,12 +5421,9 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
|
|
|
5412
5421
|
*/
|
|
5413
5422
|
_areTexturesRenderable() {
|
|
5414
5423
|
let texturesRenderable = true;
|
|
5415
|
-
for (const [, texture] of Object.entries(this._textureUniforms)) {
|
|
5416
|
-
texture.update();
|
|
5417
|
-
texturesRenderable = texturesRenderable && texture.loaded;
|
|
5418
|
-
}
|
|
5419
5424
|
for (const [, texture] of Object.entries(this.bindings)) {
|
|
5420
|
-
if (texture
|
|
5425
|
+
if (texture instanceof WEBGLTexture) {
|
|
5426
|
+
texture.update();
|
|
5421
5427
|
texturesRenderable = texturesRenderable && texture.loaded;
|
|
5422
5428
|
}
|
|
5423
5429
|
}
|
|
@@ -5454,7 +5460,7 @@ var WEBGLRenderPipeline = class extends import_core22.RenderPipeline {
|
|
|
5454
5460
|
let textureUnit = 0;
|
|
5455
5461
|
let uniformBufferIndex = 0;
|
|
5456
5462
|
for (const binding of this.shaderLayout.bindings) {
|
|
5457
|
-
const value = this.bindings[binding.name];
|
|
5463
|
+
const value = this.bindings[binding.name] || this.bindings[binding.name.replace(/Uniforms$/, "")];
|
|
5458
5464
|
if (!value) {
|
|
5459
5465
|
throw new Error(`No value for binding ${binding.name} in ${this.id}`);
|
|
5460
5466
|
}
|