@antv/l7-renderer 2.20.5 → 2.20.6

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.
@@ -4,7 +4,7 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
4
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
5
  var _dec, _class;
6
6
  import _regeneratorRuntime from "@babel/runtime/regenerator";
7
- import { Format, TextureUsage, TransparentBlack, WebGLDeviceContribution, WebGPUDeviceContribution } from '@antv/g-device-api';
7
+ import { Format, TextureUsage, TransparentBlack, WebGLDeviceContribution, WebGPUDeviceContribution, colorNewFromRGBA } from '@antv/g-device-api';
8
8
  import { injectable } from 'inversify';
9
9
  import 'reflect-metadata';
10
10
  import DeviceAttribute from "./DeviceAttribute";
@@ -24,7 +24,7 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
24
24
  _classCallCheck(this, DeviceRendererService);
25
25
  _defineProperty(this, "uniformBuffers", []);
26
26
  _defineProperty(this, "createModel", function (options) {
27
- return new DeviceModel(_this.device, options);
27
+ return new DeviceModel(_this.device, options, _this);
28
28
  });
29
29
  _defineProperty(this, "createAttribute", function (options) {
30
30
  return new DeviceAttribute(_this.device, options);
@@ -41,35 +41,28 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
41
41
  _defineProperty(this, "createFramebuffer", function (options) {
42
42
  return new DeviceFramebuffer(_this.device, options);
43
43
  });
44
- _defineProperty(this, "useFramebuffer", function ()
45
- // framebuffer: IFramebuffer | null,
46
- // drawCommands: () => void,
47
- {
48
- // if (framebuffer == null) {
49
- // // @ts-ignore
50
- // this.device.currentFramebuffer = this.device.onscreenFramebuffer;
51
- // } else {
52
- // // @ts-ignore
53
- // this.device.currentFramebuffer = framebuffer;
54
- // }
55
- // drawCommands();
44
+ _defineProperty(this, "useFramebuffer", function (framebuffer, drawCommands) {
45
+ _this.currentFramebuffer = framebuffer;
46
+ _this.beginFrame();
47
+ drawCommands();
48
+ _this.endFrame();
49
+ _this.currentFramebuffer = null;
56
50
  });
57
- _defineProperty(this, "clear", function ()
58
- // options: IClearOptions
59
- {
51
+ _defineProperty(this, "clear", function (options) {
60
52
  // @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clear-the-draw-buffer
61
- // const { color, depth, stencil, framebuffer = null } = options;
62
- // const reglClearOptions: regl.ClearOptions = {
63
- // color,
64
- // depth,
65
- // stencil,
66
- // };
67
- // reglClearOptions.framebuffer =
68
- // framebuffer === null
69
- // ? framebuffer
70
- // : (framebuffer as DeviceFramebuffer).get();
71
- // this.gl?.clear(reglClearOptions);
72
- // TODO: clear
53
+ var color = options.color,
54
+ depth = options.depth,
55
+ stencil = options.stencil,
56
+ _options$framebuffer = options.framebuffer,
57
+ framebuffer = _options$framebuffer === void 0 ? null : _options$framebuffer;
58
+ if (framebuffer) {
59
+ // @ts-ignore
60
+ framebuffer.clearOptions = {
61
+ color: color,
62
+ depth: depth,
63
+ stencil: stencil
64
+ };
65
+ }
73
66
  });
74
67
  _defineProperty(this, "viewport", function (_ref) {
75
68
  var width = _ref.width,
@@ -80,33 +73,23 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
80
73
  _this.width = width;
81
74
  _this.height = height;
82
75
  // Will be used in `setViewport` from RenderPass later.
83
- // @ts-ignore
84
- _this.device.width = width;
85
- // @ts-ignore
86
- _this.device.height = height;
87
-
88
76
  // this.gl._refresh();
89
77
  });
90
- _defineProperty(this, "readPixels", function ()
91
- // options: IReadPixelsOptions
92
- {
93
- // const { framebuffer, x, y, width, height } = options;
94
-
95
- // const readback = this.device.createReadback();
96
-
97
- // if (framebuffer) {
98
- // readPixelsOptions.framebuffer = (framebuffer as DeviceFramebuffer).get();
99
- // }
100
- // return readback.readTextureSync(null, x, y, width, height, new Uint8Array()) as Uint8Array;
101
- return new Uint8Array();
78
+ _defineProperty(this, "readPixels", function (options) {
79
+ var framebuffer = options.framebuffer,
80
+ x = options.x,
81
+ y = options.y,
82
+ width = options.width,
83
+ height = options.height;
84
+ var readback = _this.device.createReadback();
85
+ var texture = framebuffer['colorTexture'];
86
+ return readback.readTextureSync(texture, x, y, width, height, new Uint8Array(width * height * 4));
102
87
  });
103
88
  _defineProperty(this, "getViewportSize", function () {
104
89
  // FIXME: add viewport size in Device API.
105
90
  return {
106
- // @ts-ignore
107
- width: _this.device.width,
108
- // @ts-ignore
109
- height: _this.device.height
91
+ width: _this.width,
92
+ height: _this.height
110
93
  };
111
94
  });
112
95
  _defineProperty(this, "getContainer", function () {
@@ -143,9 +126,16 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
143
126
  }
144
127
  _createClass(DeviceRendererService, [{
145
128
  key: "init",
146
- value: function () {
129
+ value:
130
+ /**
131
+ * Current render pass.
132
+ */
133
+ /**
134
+ * Current FBO.
135
+ */
136
+ function () {
147
137
  var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(canvas, cfg) {
148
- var enableWebGPU, shaderCompilerPath, deviceContribution, swapChain, gl, renderTargetTexture;
138
+ var enableWebGPU, shaderCompilerPath, deviceContribution, swapChain, gl;
149
139
  return _regeneratorRuntime.wrap(function _callee$(_context) {
150
140
  while (1) switch (_context.prev = _context.next) {
151
141
  case 0:
@@ -177,15 +167,7 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
177
167
  this.swapChain = swapChain;
178
168
 
179
169
  // Create default RT
180
- // @ts-ignore
181
- // this.device.onscreenFramebuffer = this.createFramebuffer({
182
- // width: canvas.width,
183
- // height: canvas.height,
184
- // });
185
- // // @ts-ignore
186
- // this.device.onscreenFramebuffer.onscreen = true;
187
- // // @ts-ignore
188
- // this.device.currentFramebuffer = this.device.onscreenFramebuffer;
170
+ this.currentFramebuffer = null;
189
171
 
190
172
  // @ts-ignore
191
173
  gl = this.device['gl'];
@@ -193,13 +175,12 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
193
175
  // @ts-ignore
194
176
  OES_texture_float: !isWebGL2(gl) && this.device['OES_texture_float']
195
177
  };
196
- renderTargetTexture = this.device.createTexture({
178
+ this.mainColorRT = this.device.createRenderTargetFromTexture(this.device.createTexture({
197
179
  format: Format.U8_RGBA_RT,
198
180
  width: canvas.width,
199
181
  height: canvas.height,
200
182
  usage: TextureUsage.RENDER_TARGET
201
- });
202
- this.renderTarget = this.device.createRenderTargetFromTexture(renderTargetTexture);
183
+ }));
203
184
  this.mainDepthRT = this.device.createRenderTargetFromTexture(this.device.createTexture({
204
185
  format: Format.D24_S8,
205
186
  width: canvas.width,
@@ -220,17 +201,35 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
220
201
  }, {
221
202
  key: "beginFrame",
222
203
  value: function beginFrame() {
223
- var onscreenTexture = this.swapChain.getOnscreenTexture();
224
- this.renderPass = this.device.createRenderPass({
225
- colorAttachment: [this.renderTarget],
226
- // colorResolveTo: [onscreen ? onscreenTexture : onscreenTexture],
227
- colorResolveTo: [onscreenTexture],
228
- colorClearColor: [TransparentBlack],
229
- depthStencilAttachment: this.mainDepthRT,
230
- depthClearValue: 1
204
+ var currentFramebuffer = this.currentFramebuffer,
205
+ swapChain = this.swapChain,
206
+ mainColorRT = this.mainColorRT,
207
+ mainDepthRT = this.mainDepthRT;
208
+ var onscreenTexture = swapChain.getOnscreenTexture();
209
+ var colorAttachment = currentFramebuffer ? currentFramebuffer['colorRenderTarget'] : mainColorRT;
210
+ var colorResolveTo = currentFramebuffer ? null : onscreenTexture;
211
+ var depthStencilAttachment = currentFramebuffer ? currentFramebuffer['depthRenderTarget'] : mainDepthRT;
212
+ var _ref2 =
213
+ // @ts-ignore
214
+ (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer.clearOptions) || {},
215
+ _ref2$color = _ref2.color,
216
+ color = _ref2$color === void 0 ? [0, 0, 0, 0] : _ref2$color,
217
+ _ref2$depth = _ref2.depth,
218
+ depth = _ref2$depth === void 0 ? 1 : _ref2$depth,
219
+ _ref2$stencil = _ref2.stencil,
220
+ stencil = _ref2$stencil === void 0 ? 0 : _ref2$stencil;
221
+ var colorClearColor = colorAttachment ? colorNewFromRGBA(color[0] * 255, color[1] * 255, color[2] * 255, color[3]) : TransparentBlack;
222
+ var depthClearValue = depthStencilAttachment ? depth : undefined;
223
+ var stencilClearValue = depthStencilAttachment ? stencil : undefined;
224
+ var renderPass = this.device.createRenderPass({
225
+ colorAttachment: [colorAttachment],
226
+ colorResolveTo: [colorResolveTo],
227
+ colorClearColor: [colorClearColor],
228
+ depthStencilAttachment: depthStencilAttachment,
229
+ depthClearValue: depthClearValue,
230
+ stencilClearValue: stencilClearValue
231
231
  });
232
- // @ts-ignore
233
- this.device.renderPass = this.renderPass;
232
+ this.renderPass = renderPass;
234
233
  }
235
234
  }, {
236
235
  key: "endFrame",
@@ -1,5 +1,5 @@
1
- import { IAttribute, IAttributeInitializationOptions } from '@antv/l7-core';
2
- import regl from 'regl';
1
+ import type { IAttribute, IAttributeInitializationOptions } from '@antv/l7-core';
2
+ import type regl from 'regl';
3
3
  /**
4
4
  * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#attributes
5
5
  */
@@ -1,5 +1,5 @@
1
- import { IBuffer, IBufferInitializationOptions } from '@antv/l7-core';
2
- import regl from 'regl';
1
+ import type { IBuffer, IBufferInitializationOptions } from '@antv/l7-core';
2
+ import type regl from 'regl';
3
3
  /**
4
4
  * adaptor for regl.Buffer
5
5
  * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#buffers
@@ -1,5 +1,5 @@
1
- import { IElements, IElementsInitializationOptions } from '@antv/l7-core';
2
- import regl from 'regl';
1
+ import type { IElements, IElementsInitializationOptions } from '@antv/l7-core';
2
+ import type regl from 'regl';
3
3
  /**
4
4
  * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#elements
5
5
  */
@@ -1,5 +1,5 @@
1
- import { IFramebuffer, IFramebufferInitializationOptions } from '@antv/l7-core';
2
- import regl from 'regl';
1
+ import type { IFramebuffer, IFramebufferInitializationOptions } from '@antv/l7-core';
2
+ import type regl from 'regl';
3
3
  /**
4
4
  * adaptor for regl.Framebuffer
5
5
  * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#framebuffers
@@ -1,5 +1,5 @@
1
- import { IAttribute, IElements, IModel, IModelDrawOptions, IModelInitializationOptions, IUniform } from '@antv/l7-core';
2
- import regl from 'regl';
1
+ import type { IAttribute, IElements, IModel, IModelDrawOptions, IModelInitializationOptions, IUniform } from '@antv/l7-core';
2
+ import type regl from 'regl';
3
3
  /**
4
4
  * adaptor for regl.DrawCommand
5
5
  */
@@ -56,11 +56,13 @@ var ReglModel = /*#__PURE__*/function () {
56
56
  Object.keys(attributes).forEach(function (name) {
57
57
  reglAttributes[name] = attributes[name].get();
58
58
  });
59
+ var frag = removeDuplicateUniforms(preprocessShader_GLSL(vendorInfo, 'frag', fs, null, false));
60
+ var vert = removeDuplicateUniforms(preprocessShader_GLSL(vendorInfo, 'vert', vs, null, false));
59
61
  var drawParams = {
60
62
  attributes: reglAttributes,
61
- frag: removeDuplicateUniforms(preprocessShader_GLSL(vendorInfo, 'frag', fs, null, false)),
63
+ frag: frag,
62
64
  uniforms: reglUniforms,
63
- vert: removeDuplicateUniforms(preprocessShader_GLSL(vendorInfo, 'vert', vs, null, false)),
65
+ vert: vert,
64
66
  // @ts-ignore
65
67
  colorMask: reGl.prop('colorMask'),
66
68
  lineWidth: 1,
@@ -1,5 +1,5 @@
1
- import { IRenderbuffer, IRenderbufferInitializationOptions } from '@antv/l7-core';
2
- import regl from 'regl';
1
+ import type { IRenderbuffer, IRenderbufferInitializationOptions } from '@antv/l7-core';
2
+ import type regl from 'regl';
3
3
  /**
4
4
  * adaptor for regl.Renderbuffer
5
5
  * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#renderbuffers
@@ -1,5 +1,5 @@
1
- import { ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
2
- import regl from 'regl';
1
+ import type { ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
2
+ import type regl from 'regl';
3
3
  /**
4
4
  * adaptor for regl.Buffer
5
5
  * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#buffers
@@ -1,4 +1,4 @@
1
- import regl from 'regl';
1
+ import type regl from 'regl';
2
2
  export declare const primitiveMap: {
3
3
  [key: string]: 'points' | 'lines' | 'line loop' | 'line strip' | 'triangles' | 'triangle strip' | 'triangle fan';
4
4
  };
@@ -2,7 +2,7 @@
2
2
  * render w/ regl
3
3
  * @see https://github.com/regl-project/regl/blob/gh-pages/API.md
4
4
  */
5
- import { IAttribute, IAttributeInitializationOptions, IBuffer, IBufferInitializationOptions, IClearOptions, IElements, IElementsInitializationOptions, IExtensions, IFramebuffer, IFramebufferInitializationOptions, IModel, IModelInitializationOptions, IReadPixelsOptions, IRenderConfig, IRendererService, ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
5
+ import type { IAttribute, IAttributeInitializationOptions, IBuffer, IBufferInitializationOptions, IClearOptions, IElements, IElementsInitializationOptions, IExtensions, IFramebuffer, IFramebufferInitializationOptions, IModel, IModelInitializationOptions, IReadPixelsOptions, IRenderConfig, IRendererService, ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
6
6
  import 'reflect-metadata';
7
7
  import regl from 'regl';
8
8
  import ReglFramebuffer from './ReglFramebuffer';
@@ -29,7 +29,7 @@ var import_typedarray = require("./utils/typedarray");
29
29
  var DeviceBuffer = class {
30
30
  constructor(device, options) {
31
31
  this.isDestroyed = false;
32
- const { data, usage, type, isUBO } = options;
32
+ const { data, usage, type, isUBO, label } = options;
33
33
  let typed;
34
34
  if ((0, import_typedarray.isTypedArray)(data)) {
35
35
  typed = data;
@@ -43,6 +43,9 @@ var DeviceBuffer = class {
43
43
  usage: isUBO ? import_g_device_api.BufferUsage.UNIFORM : import_g_device_api.BufferUsage.VERTEX,
44
44
  hint: import_constants.hintMap[usage || import_l7_core.gl.STATIC_DRAW]
45
45
  });
46
+ if (label) {
47
+ device.setResourceName(this.buffer, label);
48
+ }
46
49
  }
47
50
  get() {
48
51
  return this.buffer;
@@ -27,41 +27,75 @@ var import_DeviceTexture2D = require("./DeviceTexture2D");
27
27
  var DeviceFramebuffer = class {
28
28
  constructor(device, options) {
29
29
  this.device = device;
30
- const { width, height, color } = options;
31
- if ((0, import_DeviceTexture2D.isTexture2D)(color)) {
32
- this.renderTarget = device.createRenderTargetFromTexture(
33
- color.get()
34
- );
35
- this.width = color["width"];
36
- this.height = color["height"];
37
- } else if (width && height) {
38
- this.renderTarget = device.createRenderTarget({
39
- format: import_g_device_api.Format.U8_RGBA_RT,
40
- width,
41
- height
42
- });
43
- this.width = width;
44
- this.height = height;
30
+ this.options = options;
31
+ this.createColorRenderTarget();
32
+ this.createDepthRenderTarget();
33
+ }
34
+ createColorRenderTarget() {
35
+ const { width, height, color } = this.options;
36
+ if (color) {
37
+ if ((0, import_DeviceTexture2D.isTexture2D)(color)) {
38
+ this.colorTexture = color.get();
39
+ this.colorRenderTarget = this.device.createRenderTargetFromTexture(
40
+ this.colorTexture
41
+ );
42
+ this.width = color["width"];
43
+ this.height = color["height"];
44
+ } else if (width && height) {
45
+ this.colorTexture = this.device.createTexture({
46
+ format: import_g_device_api.Format.U8_RGBA_RT,
47
+ usage: import_g_device_api.TextureUsage.RENDER_TARGET,
48
+ width,
49
+ height
50
+ });
51
+ this.colorRenderTarget = this.device.createRenderTargetFromTexture(
52
+ this.colorTexture
53
+ );
54
+ this.width = width;
55
+ this.height = height;
56
+ }
57
+ }
58
+ }
59
+ createDepthRenderTarget() {
60
+ const { width, height, depth } = this.options;
61
+ if (depth) {
62
+ if ((0, import_DeviceTexture2D.isTexture2D)(depth)) {
63
+ this.depthTexture = depth.get();
64
+ this.depthRenderTarget = this.device.createRenderTargetFromTexture(
65
+ this.depthTexture
66
+ );
67
+ this.width = depth["width"];
68
+ this.height = depth["height"];
69
+ } else if (width && height) {
70
+ this.depthTexture = this.device.createTexture({
71
+ format: import_g_device_api.Format.D24_S8,
72
+ usage: import_g_device_api.TextureUsage.RENDER_TARGET,
73
+ width,
74
+ height
75
+ });
76
+ this.depthRenderTarget = this.device.createRenderTargetFromTexture(
77
+ this.depthTexture
78
+ );
79
+ this.width = width;
80
+ this.height = height;
81
+ }
45
82
  }
46
83
  }
47
84
  get() {
48
- return this.renderTarget;
85
+ return this.colorRenderTarget;
49
86
  }
50
87
  destroy() {
51
- this.renderTarget.destroy();
88
+ var _a, _b;
89
+ (_a = this.colorRenderTarget) == null ? void 0 : _a.destroy();
90
+ (_b = this.depthRenderTarget) == null ? void 0 : _b.destroy();
52
91
  }
53
92
  resize({ width, height }) {
54
93
  if (this.width !== width || this.height !== height) {
55
- if (this.renderTarget) {
56
- this.renderTarget.destroy();
57
- }
58
- this.renderTarget = this.device.createRenderTarget({
59
- format: import_g_device_api.Format.U8_RGBA_RT,
60
- width,
61
- height
62
- });
63
- this.width = width;
64
- this.height = height;
94
+ this.destroy();
95
+ this.options.width = width;
96
+ this.options.height = height;
97
+ this.createColorRenderTarget();
98
+ this.createDepthRenderTarget();
65
99
  }
66
100
  }
67
101
  };
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/device/DeviceModel.ts
@@ -25,12 +35,15 @@ module.exports = __toCommonJS(DeviceModel_exports);
25
35
  var import_g_device_api = require("@antv/g-device-api");
26
36
  var import_l7_core = require("@antv/l7-core");
27
37
  var import_l7_utils = require("@antv/l7-utils");
38
+ var import_DeviceFramebuffer = __toESM(require("./DeviceFramebuffer"));
39
+ var import_DeviceTexture2D = __toESM(require("./DeviceTexture2D"));
28
40
  var import_constants = require("./constants");
29
41
  var { isPlainObject, isTypedArray } = import_l7_utils.lodashUtil;
30
42
  var DeviceModel = class {
31
- constructor(device, options) {
43
+ constructor(device, options, service) {
32
44
  this.device = device;
33
45
  this.options = options;
46
+ this.service = service;
34
47
  this.destroyed = false;
35
48
  this.uniforms = {};
36
49
  this.vertexBuffers = [];
@@ -91,7 +104,7 @@ var DeviceModel = class {
91
104
  this.inputLayout = inputLayout;
92
105
  this.pipeline = this.createPipeline(options);
93
106
  }
94
- createPipeline(options) {
107
+ createPipeline(options, pick) {
95
108
  const { primitive = import_l7_core.gl.TRIANGLES, depth, cull, blend } = options;
96
109
  const depthParams = this.initDepthDrawParams({ depth });
97
110
  const depthEnabled = !!(depthParams && depthParams.enable);
@@ -107,7 +120,19 @@ var DeviceModel = class {
107
120
  depthStencilAttachmentFormat: import_g_device_api.Format.D24_S8,
108
121
  megaStateDescriptor: {
109
122
  attachmentsState: [
110
- {
123
+ pick ? {
124
+ channelWriteMask: import_g_device_api.ChannelWriteMask.ALL,
125
+ rgbBlendState: {
126
+ blendMode: import_g_device_api.BlendMode.ADD,
127
+ blendSrcFactor: import_g_device_api.BlendFactor.ONE,
128
+ blendDstFactor: import_g_device_api.BlendFactor.ZERO
129
+ },
130
+ alphaBlendState: {
131
+ blendMode: import_g_device_api.BlendMode.ADD,
132
+ blendSrcFactor: import_g_device_api.BlendFactor.ONE,
133
+ blendDstFactor: import_g_device_api.BlendFactor.ZERO
134
+ }
135
+ } : {
111
136
  channelWriteMask: import_g_device_api.ChannelWriteMask.ALL,
112
137
  rgbBlendState: {
113
138
  blendMode: blendEnabled && blendParams.equation.rgb || import_g_device_api.BlendMode.ADD,
@@ -117,11 +142,11 @@ var DeviceModel = class {
117
142
  alphaBlendState: {
118
143
  blendMode: blendEnabled && blendParams.equation.alpha || import_g_device_api.BlendMode.ADD,
119
144
  blendSrcFactor: blendEnabled && blendParams.func.srcAlpha || import_g_device_api.BlendFactor.ONE,
120
- blendDstFactor: blendEnabled && blendParams.func.dstAlpha || import_g_device_api.BlendFactor.ONE_MINUS_SRC_ALPHA
145
+ blendDstFactor: blendEnabled && blendParams.func.dstAlpha || import_g_device_api.BlendFactor.ONE
121
146
  }
122
147
  }
123
148
  ],
124
- blendConstant: import_g_device_api.TransparentBlack,
149
+ blendConstant: blendEnabled ? import_g_device_api.TransparentBlack : void 0,
125
150
  depthWrite: depthEnabled,
126
151
  depthCompare: depthEnabled && depthParams.func || import_g_device_api.CompareFunction.LESS,
127
152
  cullMode: cullEnabled && cullParams.face || import_g_device_api.CullMode.NONE,
@@ -131,6 +156,17 @@ var DeviceModel = class {
131
156
  }
132
157
  updateAttributesAndElements() {
133
158
  }
159
+ /**
160
+ * No need to implement this method, you should update data on `Attribute` like this:
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * attribute.updateBuffer({
165
+ * data: [],
166
+ * offset: 0,
167
+ * });
168
+ * ```
169
+ */
134
170
  updateAttributes() {
135
171
  }
136
172
  addUniforms(uniforms) {
@@ -139,12 +175,13 @@ var DeviceModel = class {
139
175
  ...this.extractUniforms(uniforms)
140
176
  };
141
177
  }
142
- draw(options) {
178
+ draw(options, pick) {
143
179
  const mergedOptions = {
144
180
  ...this.options,
145
181
  ...options
146
182
  };
147
183
  const {
184
+ depth: { enable: depthEnabled } = {},
148
185
  count = 0,
149
186
  instances,
150
187
  elements,
@@ -156,9 +193,14 @@ var DeviceModel = class {
156
193
  ...this.uniforms,
157
194
  ...this.extractUniforms(uniforms)
158
195
  };
159
- const { width, height } = this.device;
160
- const renderPass = this.device.renderPass;
161
- this.pipeline = this.createPipeline(mergedOptions);
196
+ const { renderPass, currentFramebuffer, width, height } = this.service;
197
+ this.pipeline = this.createPipeline(mergedOptions, pick);
198
+ renderPass.setViewport(
199
+ 0,
200
+ 0,
201
+ (currentFramebuffer == null ? void 0 : currentFramebuffer["width"]) || width,
202
+ (currentFramebuffer == null ? void 0 : currentFramebuffer["height"]) || height
203
+ );
162
204
  renderPass.setPipeline(this.pipeline);
163
205
  renderPass.setVertexInput(
164
206
  this.inputLayout,
@@ -168,10 +210,8 @@ var DeviceModel = class {
168
210
  elements ? {
169
211
  buffer: this.indexBuffer,
170
212
  offset: 0
171
- // TODO: use defaule value
172
213
  } : null
173
214
  );
174
- renderPass.setViewport(0, 0, width, height);
175
215
  if (uniformBuffers) {
176
216
  this.bindings = this.device.createBindings({
177
217
  pipeline: this.pipeline,
@@ -191,6 +231,14 @@ var DeviceModel = class {
191
231
  }
192
232
  if (this.bindings) {
193
233
  renderPass.setBindings(this.bindings);
234
+ Object.keys(this.uniforms).forEach((uniformName) => {
235
+ const uniform = this.uniforms[uniformName];
236
+ if (uniform instanceof import_DeviceTexture2D.default) {
237
+ this.uniforms[uniformName] = uniform.get();
238
+ } else if (uniform instanceof import_DeviceFramebuffer.default) {
239
+ this.uniforms[uniformName] = uniform.get()["texture"];
240
+ }
241
+ });
194
242
  this.program.setUniformsLegacy(this.uniforms);
195
243
  }
196
244
  if (elements) {