@zephyr3d/device 0.2.2 → 0.2.3

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.
@@ -21,11 +21,12 @@ const COMPRESSED_FORMAT_SHIFT = 24;
21
21
  const COMPRESSION_FORMAT_BC1 = 1 << COMPRESSED_FORMAT_SHIFT;
22
22
  const COMPRESSION_FORMAT_BC2 = 2 << COMPRESSED_FORMAT_SHIFT;
23
23
  const COMPRESSION_FORMAT_BC3 = 3 << COMPRESSED_FORMAT_SHIFT;
24
+ const COMPRESSION_FORMAT_BC4 = 4 << COMPRESSED_FORMAT_SHIFT;
25
+ const COMPRESSION_FORMAT_BC5 = 5 << COMPRESSED_FORMAT_SHIFT;
26
+ const COMPRESSION_FORMAT_BC6H = 6 << COMPRESSED_FORMAT_SHIFT;
27
+ const COMPRESSION_FORMAT_BC7 = 7 << COMPRESSED_FORMAT_SHIFT;
28
+ const COMPRESSION_FORMAT_ASTC = 8 << COMPRESSED_FORMAT_SHIFT;
24
29
  /*
25
- const COMPRESSION_FORMAT_BC4 = 4 << COMPRESSED_FORMAT_SHIFT;
26
- const COMPRESSION_FORMAT_BC5 = 5 << COMPRESSED_FORMAT_SHIFT;
27
- const COMPRESSION_FORMAT_BC6 = 6 << COMPRESSED_FORMAT_SHIFT;
28
- const COMPRESSION_FORMAT_BC7 = 7 << COMPRESSED_FORMAT_SHIFT;
29
30
  const COMPRESSION_FORMAT_ETC2_RGB8 = 8 << COMPRESSED_FORMAT_SHIFT;
30
31
  const COMPRESSION_FORMAT_ETC2_RGB8_A1 = 9 << COMPRESSED_FORMAT_SHIFT;
31
32
  const COMPRESSION_FORMAT_ETC2_RGBA8 = 10 << COMPRESSED_FORMAT_SHIFT;
@@ -114,7 +115,43 @@ const textureFormatMap = {
114
115
  dxt3: makeTextureFormat(COMPRESSION_FORMAT_BC2, true, true, true, true, false, false, false, false, false, false, false, 4, 4, 16),
115
116
  'dxt3-srgb': makeTextureFormat(COMPRESSION_FORMAT_BC2, true, true, true, true, false, false, false, false, false, true, false, 4, 4, 16),
116
117
  dxt5: makeTextureFormat(COMPRESSION_FORMAT_BC3, true, true, true, true, false, false, false, false, false, false, false, 4, 4, 16),
117
- 'dxt5-srgb': makeTextureFormat(COMPRESSION_FORMAT_BC3, true, true, true, true, false, false, false, false, false, true, false, 4, 4, 16)
118
+ 'dxt5-srgb': makeTextureFormat(COMPRESSION_FORMAT_BC3, true, true, true, true, false, false, false, false, false, true, false, 4, 4, 16),
119
+ bc4: makeTextureFormat(COMPRESSION_FORMAT_BC4, true, false, false, false, false, false, false, false, false, false, false, 4, 4, 8),
120
+ 'bc4-signed': makeTextureFormat(COMPRESSION_FORMAT_BC4, true, false, false, false, false, false, false, false, true, false, false, 4, 4, 8),
121
+ bc5: makeTextureFormat(COMPRESSION_FORMAT_BC5, true, true, false, false, false, false, false, false, false, false, false, 4, 4, 16),
122
+ 'bc5-signed': makeTextureFormat(COMPRESSION_FORMAT_BC5, true, true, false, false, false, false, false, false, true, false, false, 4, 4, 16),
123
+ bc6h: makeTextureFormat(COMPRESSION_FORMAT_BC6H, true, true, true, false, false, false, true, false, false, false, false, 4, 4, 16),
124
+ 'bc6h-signed': makeTextureFormat(COMPRESSION_FORMAT_BC6H, true, true, true, false, false, false, true, false, true, false, false, 4, 4, 16),
125
+ bc7: makeTextureFormat(COMPRESSION_FORMAT_BC7, true, true, true, true, false, false, false, false, false, false, false, 4, 4, 16),
126
+ 'bc7-srgb': makeTextureFormat(COMPRESSION_FORMAT_BC7, true, true, true, true, false, false, false, false, false, true, false, 4, 4, 16),
127
+ 'astc-4x4': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 4, 4, 16),
128
+ 'astc-4x4-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 4, 4, 16),
129
+ 'astc-5x4': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 5, 4, 16),
130
+ 'astc-5x4-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 5, 4, 16),
131
+ 'astc-5x5': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 5, 5, 16),
132
+ 'astc-5x5-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 5, 5, 16),
133
+ 'astc-6x5': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 6, 5, 16),
134
+ 'astc-6x5-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 6, 5, 16),
135
+ 'astc-6x6': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 6, 6, 16),
136
+ 'astc-6x6-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 6, 6, 16),
137
+ 'astc-8x5': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 8, 5, 16),
138
+ 'astc-8x5-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 8, 5, 16),
139
+ 'astc-8x6': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 8, 6, 16),
140
+ 'astc-8x6-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 8, 6, 16),
141
+ 'astc-8x8': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 8, 8, 16),
142
+ 'astc-8x8-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 8, 8, 16),
143
+ 'astc-10x5': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 10, 5, 16),
144
+ 'astc-10x5-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 10, 5, 16),
145
+ 'astc-10x6': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 10, 6, 16),
146
+ 'astc-10x6-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 10, 6, 16),
147
+ 'astc-10x8': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 10, 8, 16),
148
+ 'astc-10x8-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 10, 8, 16),
149
+ 'astc-10x10': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 10, 10, 16),
150
+ 'astc-10x10-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 10, 10, 16),
151
+ 'astc-12x10': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 12, 10, 16),
152
+ 'astc-12x10-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 12, 10, 16),
153
+ 'astc-12x12': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, false, false, 12, 12, 16),
154
+ 'astc-12x12-srgb': makeTextureFormat(COMPRESSION_FORMAT_ASTC, true, true, true, true, false, false, false, false, false, true, false, 12, 12, 16)
118
155
  };
119
156
  /**
120
157
  * Converts a non-sRGB texture format to the corresponding sRGB texture format
@@ -133,6 +170,36 @@ const textureFormatMap = {
133
170
  return 'dxt3-srgb';
134
171
  case 'dxt5':
135
172
  return 'dxt5-srgb';
173
+ case 'bc7':
174
+ return 'bc7-srgb';
175
+ case 'astc-4x4':
176
+ return 'astc-4x4-srgb';
177
+ case 'astc-5x4':
178
+ return 'astc-5x4-srgb';
179
+ case 'astc-5x5':
180
+ return 'astc-5x5-srgb';
181
+ case 'astc-6x5':
182
+ return 'astc-6x5-srgb';
183
+ case 'astc-6x6':
184
+ return 'astc-6x6-srgb';
185
+ case 'astc-8x5':
186
+ return 'astc-8x5-srgb';
187
+ case 'astc-8x6':
188
+ return 'astc-8x6-srgb';
189
+ case 'astc-8x8':
190
+ return 'astc-8x8-srgb';
191
+ case 'astc-10x5':
192
+ return 'astc-10x5-srgb';
193
+ case 'astc-10x6':
194
+ return 'astc-10x6-srgb';
195
+ case 'astc-10x8':
196
+ return 'astc-10x8-srgb';
197
+ case 'astc-10x10':
198
+ return 'astc-10x10-srgb';
199
+ case 'astc-12x10':
200
+ return 'astc-12x10-srgb';
201
+ case 'astc-12x12':
202
+ return 'astc-12x12-srgb';
136
203
  default:
137
204
  return format;
138
205
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base_types.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"base_types.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/device.js CHANGED
@@ -6,6 +6,7 @@ import { ProgramBuilder } from './builder/programbuilder.js';
6
6
  import { DeviceGPUObjectAddedEvent, DeviceGPUObjectRemovedEvent, DeviceResizeEvent } from './base_types.js';
7
7
  import '@zephyr3d/base';
8
8
  import { DrawText } from './helpers/drawtext.js';
9
+ import { Pool } from './pool.js';
9
10
 
10
11
  /**
11
12
  * Base class for rendering device
@@ -28,6 +29,9 @@ import { DrawText } from './helpers/drawtext.js';
28
29
  _backend;
29
30
  _beginFrameCounter;
30
31
  _programBuilder;
32
+ _pool;
33
+ _temporalFramebuffer;
34
+ _vSync;
31
35
  _stateStack;
32
36
  constructor(cvs, backend){
33
37
  this._backend = backend;
@@ -72,6 +76,9 @@ import { DrawText } from './helpers/drawtext.js';
72
76
  };
73
77
  this._stateStack = [];
74
78
  this._beginFrameCounter = 0;
79
+ this._pool = new Pool(this);
80
+ this._temporalFramebuffer = false;
81
+ this._vSync = true;
75
82
  this._registerEventHandlers();
76
83
  }
77
84
  get backend() {
@@ -92,6 +99,15 @@ import { DrawText } from './helpers/drawtext.js';
92
99
  get type() {
93
100
  return this._backend.typeName();
94
101
  }
102
+ get vSync() {
103
+ return this._vSync;
104
+ }
105
+ set vSync(val) {
106
+ this._vSync = !!val;
107
+ }
108
+ get pool() {
109
+ return this._pool;
110
+ }
95
111
  get runLoopFunction() {
96
112
  return this._runLoopFunc;
97
113
  }
@@ -104,6 +120,31 @@ import { DrawText } from './helpers/drawtext.js';
104
120
  drawText(text, x, y, color) {
105
121
  DrawText.drawText(this, text, color, x, y);
106
122
  }
123
+ setFramebuffer(colorOrRT, depth, sampleCount) {
124
+ let newRT = null;
125
+ let temporal = false;
126
+ if (!Array.isArray(colorOrRT)) {
127
+ newRT = colorOrRT ?? null;
128
+ } else {
129
+ const colorAttachments = colorOrRT.map((val)=>val.texture ?? val);
130
+ newRT = this._pool.createTemporalFramebuffer(false, colorAttachments, depth, sampleCount, true);
131
+ for(let i = 0; i < colorOrRT.length; i++){
132
+ const rt = colorOrRT[i];
133
+ newRT.setColorAttachmentMipLevel(i, rt.texture ? rt.miplevel ?? 0 : 0);
134
+ newRT.setColorAttachmentLayer(i, rt.texture ? rt.face ?? 0 : 0);
135
+ newRT.setColorAttachmentCubeFace(i, rt.texture ? rt.layer ?? 0 : 0);
136
+ }
137
+ temporal = true;
138
+ }
139
+ const currentRT = this.getFramebuffer();
140
+ if (currentRT !== newRT) {
141
+ if (this._temporalFramebuffer) {
142
+ this._pool.releaseFrameBuffer(currentRT);
143
+ }
144
+ this._temporalFramebuffer = temporal;
145
+ this._setFramebuffer(newRT);
146
+ }
147
+ }
107
148
  disposeObject(obj, remove = true) {
108
149
  if (obj) {
109
150
  if (remove) {
@@ -145,6 +186,7 @@ import { DrawText } from './helpers/drawtext.js';
145
186
  this._beginFrameCounter++;
146
187
  this._beginFrameTime = this._cpuTimer.now();
147
188
  this.updateFrameInfo();
189
+ this._pool.autoRelease();
148
190
  return this.onBeginFrame();
149
191
  }
150
192
  endFrame() {
@@ -224,8 +266,12 @@ import { DrawText } from './helpers/drawtext.js';
224
266
  }
225
267
  }
226
268
  exitLoop() {
227
- if (this._runningLoop) {
228
- cancelAnimationFrame(this._runningLoop);
269
+ if (this._runningLoop !== null) {
270
+ if (this._runningLoop !== 0) {
271
+ cancelAnimationFrame(this._runningLoop);
272
+ } else {
273
+ this.cancelNextFrame(this._runningLoop);
274
+ }
229
275
  this._runningLoop = null;
230
276
  }
231
277
  }
@@ -241,7 +287,15 @@ import { DrawText } from './helpers/drawtext.js';
241
287
  const that = this;
242
288
  that._runLoopFunc = func;
243
289
  (function entry() {
244
- that._runningLoop = requestAnimationFrame(entry);
290
+ if (that._vSync) {
291
+ that._runningLoop = requestAnimationFrame(entry);
292
+ } else {
293
+ that._runningLoop = that.nextFrame(()=>{
294
+ if (that._runningLoop !== null) {
295
+ entry();
296
+ }
297
+ });
298
+ }
245
299
  if (that.beginFrame()) {
246
300
  that._runLoopFunc(that);
247
301
  that.endFrame();
@@ -1 +1 @@
1
- {"version":3,"file":"device.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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/gpuobject.js CHANGED
@@ -1754,6 +1754,48 @@ const vertexAttribFormatMap = {
1754
1754
  'u32',
1755
1755
  4
1756
1756
  ],
1757
+ blendweights_f16x1: [
1758
+ VERTEX_ATTRIB_BLEND_WEIGHT,
1759
+ PBPrimitiveType.F16,
1760
+ 2,
1761
+ 'f16',
1762
+ 1
1763
+ ],
1764
+ blendweights_f32x1: [
1765
+ VERTEX_ATTRIB_BLEND_WEIGHT,
1766
+ PBPrimitiveType.F32,
1767
+ 4,
1768
+ 'f32',
1769
+ 1
1770
+ ],
1771
+ blendweights_f16x2: [
1772
+ VERTEX_ATTRIB_BLEND_WEIGHT,
1773
+ PBPrimitiveType.F16VEC2,
1774
+ 4,
1775
+ 'f16',
1776
+ 2
1777
+ ],
1778
+ blendweights_f32x2: [
1779
+ VERTEX_ATTRIB_BLEND_WEIGHT,
1780
+ PBPrimitiveType.F32VEC2,
1781
+ 8,
1782
+ 'f32',
1783
+ 2
1784
+ ],
1785
+ blendweights_f16x3: [
1786
+ VERTEX_ATTRIB_BLEND_WEIGHT,
1787
+ PBPrimitiveType.F16VEC3,
1788
+ 6,
1789
+ 'f16',
1790
+ 3
1791
+ ],
1792
+ blendweights_f32x3: [
1793
+ VERTEX_ATTRIB_BLEND_WEIGHT,
1794
+ PBPrimitiveType.F32VEC3,
1795
+ 12,
1796
+ 'f32',
1797
+ 3
1798
+ ],
1757
1799
  blendweights_f16x4: [
1758
1800
  VERTEX_ATTRIB_BLEND_WEIGHT,
1759
1801
  PBPrimitiveType.F16VEC4,
@@ -1768,6 +1810,90 @@ const vertexAttribFormatMap = {
1768
1810
  'f32',
1769
1811
  4
1770
1812
  ],
1813
+ blendindices_u16x1: [
1814
+ VERTEX_ATTRIB_BLEND_INDICES,
1815
+ PBPrimitiveType.U16,
1816
+ 2,
1817
+ 'u16',
1818
+ 1
1819
+ ],
1820
+ blendindices_f16x1: [
1821
+ VERTEX_ATTRIB_BLEND_INDICES,
1822
+ PBPrimitiveType.F16,
1823
+ 2,
1824
+ 'f16',
1825
+ 1
1826
+ ],
1827
+ blendindices_f32x1: [
1828
+ VERTEX_ATTRIB_BLEND_INDICES,
1829
+ PBPrimitiveType.F32,
1830
+ 4,
1831
+ 'f32',
1832
+ 1
1833
+ ],
1834
+ blendindices_u32x1: [
1835
+ VERTEX_ATTRIB_BLEND_INDICES,
1836
+ PBPrimitiveType.U32,
1837
+ 4,
1838
+ 'u32',
1839
+ 1
1840
+ ],
1841
+ blendindices_u16x2: [
1842
+ VERTEX_ATTRIB_BLEND_INDICES,
1843
+ PBPrimitiveType.U16VEC2,
1844
+ 4,
1845
+ 'u16',
1846
+ 2
1847
+ ],
1848
+ blendindices_f16x2: [
1849
+ VERTEX_ATTRIB_BLEND_INDICES,
1850
+ PBPrimitiveType.F16VEC2,
1851
+ 4,
1852
+ 'f16',
1853
+ 2
1854
+ ],
1855
+ blendindices_f32x2: [
1856
+ VERTEX_ATTRIB_BLEND_INDICES,
1857
+ PBPrimitiveType.F32VEC2,
1858
+ 8,
1859
+ 'f32',
1860
+ 2
1861
+ ],
1862
+ blendindices_u32x2: [
1863
+ VERTEX_ATTRIB_BLEND_INDICES,
1864
+ PBPrimitiveType.U32VEC2,
1865
+ 8,
1866
+ 'u32',
1867
+ 2
1868
+ ],
1869
+ blendindices_u16x3: [
1870
+ VERTEX_ATTRIB_BLEND_INDICES,
1871
+ PBPrimitiveType.U16VEC3,
1872
+ 6,
1873
+ 'u16',
1874
+ 3
1875
+ ],
1876
+ blendindices_f16x3: [
1877
+ VERTEX_ATTRIB_BLEND_INDICES,
1878
+ PBPrimitiveType.F16VEC3,
1879
+ 6,
1880
+ 'f16',
1881
+ 3
1882
+ ],
1883
+ blendindices_f32x3: [
1884
+ VERTEX_ATTRIB_BLEND_INDICES,
1885
+ PBPrimitiveType.F32VEC3,
1886
+ 12,
1887
+ 'f32',
1888
+ 3
1889
+ ],
1890
+ blendindices_u32x3: [
1891
+ VERTEX_ATTRIB_BLEND_INDICES,
1892
+ PBPrimitiveType.U32VEC3,
1893
+ 12,
1894
+ 'u32',
1895
+ 3
1896
+ ],
1771
1897
  blendindices_u16x4: [
1772
1898
  VERTEX_ATTRIB_BLEND_INDICES,
1773
1899
  PBPrimitiveType.U16VEC4,
@@ -1846,22 +1972,28 @@ var GPUResourceUsageFlags;
1846
1972
  })(GPUResourceUsageFlags || (GPUResourceUsageFlags = {}));
1847
1973
  /**
1848
1974
  * Get vertex attribute index by semantic
1849
- * @internal
1975
+ * @public
1850
1976
  */ function getVertexAttribByName(name) {
1851
1977
  return vertexAttribNameMap[name];
1852
1978
  }
1853
1979
  /**
1854
1980
  * Get vertex semantic by attribute index
1855
- * @internal
1981
+ * @public
1856
1982
  */ function getVertexAttribName(attrib) {
1857
1983
  return vertexAttribNameRevMap[attrib];
1858
1984
  }
1859
1985
  /**
1860
1986
  * Get byte size of specified vertex format
1861
- * @internal
1987
+ * @public
1862
1988
  */ function getVertexFormatSize(fmt) {
1863
1989
  return vertexAttribFormatMap[fmt][2];
1864
1990
  }
1991
+ /**
1992
+ * Get number of components of specified vertex format
1993
+ * @public
1994
+ */ function getVertexFormatComponentCount(fmt) {
1995
+ return vertexAttribFormatMap[fmt][4];
1996
+ }
1865
1997
  /**
1866
1998
  * Get vertex format by semantic and component type and component count
1867
1999
  * @param semantic - The vertex semantic
@@ -2043,5 +2175,5 @@ var GPUResourceUsageFlags;
2043
2175
  }
2044
2176
  }
2045
2177
 
2046
- export { GPUResourceUsageFlags, MAX_BINDING_GROUPS, MAX_TEXCOORD_INDEX_COUNT, MAX_VERTEX_ATTRIBUTES, VERTEX_ATTRIB_BLEND_INDICES, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_DIFFUSE, VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_TANGENT, VERTEX_ATTRIB_TEXCOORD0, VERTEX_ATTRIB_TEXCOORD1, VERTEX_ATTRIB_TEXCOORD2, VERTEX_ATTRIB_TEXCOORD3, VERTEX_ATTRIB_TEXCOORD4, VERTEX_ATTRIB_TEXCOORD5, VERTEX_ATTRIB_TEXCOORD6, VERTEX_ATTRIB_TEXCOORD7, genDefaultName, getVertexAttribByName, getVertexAttribFormat, getVertexAttribName, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, getVertexFormatSize, makeVertexBufferType, semanticList, semanticToAttrib };
2178
+ export { GPUResourceUsageFlags, MAX_BINDING_GROUPS, MAX_TEXCOORD_INDEX_COUNT, MAX_VERTEX_ATTRIBUTES, VERTEX_ATTRIB_BLEND_INDICES, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_DIFFUSE, VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_TANGENT, VERTEX_ATTRIB_TEXCOORD0, VERTEX_ATTRIB_TEXCOORD1, VERTEX_ATTRIB_TEXCOORD2, VERTEX_ATTRIB_TEXCOORD3, VERTEX_ATTRIB_TEXCOORD4, VERTEX_ATTRIB_TEXCOORD5, VERTEX_ATTRIB_TEXCOORD6, VERTEX_ATTRIB_TEXCOORD7, genDefaultName, getVertexAttribByName, getVertexAttribFormat, getVertexAttribName, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, getVertexFormatComponentCount, getVertexFormatSize, makeVertexBufferType, semanticList, semanticToAttrib };
2047
2179
  //# sourceMappingURL=gpuobject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gpuobject.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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@ type TextureImageElement = ImageBitmap | HTMLCanvasElement;
599
599
  * The vertex format types
600
600
  * @public
601
601
  */
602
- type VertexAttribFormat = 'position_u8normx2' | 'position_u8normx4' | 'position_i8normx2' | 'position_i8normx4' | 'position_u16x2' | 'position_u16x4' | 'position_i16x2' | 'position_i16x4' | 'position_u16normx2' | 'position_u16normx4' | 'position_i16normx2' | 'position_i16normx4' | 'position_f16x2' | 'position_f16x4' | 'position_f32' | 'position_f32x2' | 'position_f32x3' | 'position_f32x4' | 'position_i32' | 'position_i32x2' | 'position_i32x3' | 'position_i32x4' | 'position_u32' | 'position_u32x2' | 'position_u32x3' | 'position_u32x4' | 'normal_f16x4' | 'normal_f32x3' | 'normal_f32x4' | 'diffuse_u8normx4' | 'diffuse_u16x4' | 'diffuse_u16normx4' | 'diffuse_f16x4' | 'diffuse_f32x3' | 'diffuse_f32x4' | 'diffuse_u32x3' | 'diffuse_u32x4' | 'tangent_f16x4' | 'tangent_f32x3' | 'tangent_f32x4' | 'tex0_u8normx2' | 'tex0_u8normx4' | 'tex0_i8normx2' | 'tex0_i8normx4' | 'tex0_u16x2' | 'tex0_u16x4' | 'tex0_i16x2' | 'tex0_i16x4' | 'tex0_u16normx2' | 'tex0_u16normx4' | 'tex0_i16normx2' | 'tex0_i16normx4' | 'tex0_f16x2' | 'tex0_f16x4' | 'tex0_f32' | 'tex0_f32x2' | 'tex0_f32x3' | 'tex0_f32x4' | 'tex0_i32' | 'tex0_i32x2' | 'tex0_i32x3' | 'tex0_i32x4' | 'tex0_u32' | 'tex0_u32x2' | 'tex0_u32x3' | 'tex0_u32x4' | 'tex1_u8normx2' | 'tex1_u8normx4' | 'tex1_i8normx2' | 'tex1_i8normx4' | 'tex1_u16x2' | 'tex1_u16x4' | 'tex1_i16x2' | 'tex1_i16x4' | 'tex1_u16normx2' | 'tex1_u16normx4' | 'tex1_i16normx2' | 'tex1_i16normx4' | 'tex1_f16x2' | 'tex1_f16x4' | 'tex1_f32' | 'tex1_f32x2' | 'tex1_f32x3' | 'tex1_f32x4' | 'tex1_i32' | 'tex1_i32x2' | 'tex1_i32x3' | 'tex1_i32x4' | 'tex1_u32' | 'tex1_u32x2' | 'tex1_u32x3' | 'tex1_u32x4' | 'tex2_u8normx2' | 'tex2_u8normx4' | 'tex2_i8normx2' | 'tex2_i8normx4' | 'tex2_u16x2' | 'tex2_u16x4' | 'tex2_i16x2' | 'tex2_i16x4' | 'tex2_u16normx2' | 'tex2_u16normx4' | 'tex2_i16normx2' | 'tex2_i16normx4' | 'tex2_f16x2' | 'tex2_f16x4' | 'tex2_f32' | 'tex2_f32x2' | 'tex2_f32x3' | 'tex2_f32x4' | 'tex2_i32' | 'tex2_i32x2' | 'tex2_i32x3' | 'tex2_i32x4' | 'tex2_u32' | 'tex2_u32x2' | 'tex2_u32x3' | 'tex2_u32x4' | 'tex3_u8normx2' | 'tex3_u8normx4' | 'tex3_i8normx2' | 'tex3_i8normx4' | 'tex3_u16x2' | 'tex3_u16x4' | 'tex3_i16x2' | 'tex3_i16x4' | 'tex3_u16normx2' | 'tex3_u16normx4' | 'tex3_i16normx2' | 'tex3_i16normx4' | 'tex3_f16x2' | 'tex3_f16x4' | 'tex3_f32' | 'tex3_f32x2' | 'tex3_f32x3' | 'tex3_f32x4' | 'tex3_i32' | 'tex3_i32x2' | 'tex3_i32x3' | 'tex3_i32x4' | 'tex3_u32' | 'tex3_u32x2' | 'tex3_u32x3' | 'tex3_u32x4' | 'tex4_u8normx2' | 'tex4_u8normx4' | 'tex4_i8normx2' | 'tex4_i8normx4' | 'tex4_u16x2' | 'tex4_u16x4' | 'tex4_i16x2' | 'tex4_i16x4' | 'tex4_u16normx2' | 'tex4_u16normx4' | 'tex4_i16normx2' | 'tex4_i16normx4' | 'tex4_f16x2' | 'tex4_f16x4' | 'tex4_f32' | 'tex4_f32x2' | 'tex4_f32x3' | 'tex4_f32x4' | 'tex4_i32' | 'tex4_i32x2' | 'tex4_i32x3' | 'tex4_i32x4' | 'tex4_u32' | 'tex4_u32x2' | 'tex4_u32x3' | 'tex4_u32x4' | 'tex5_u8normx2' | 'tex5_u8normx4' | 'tex5_i8normx2' | 'tex5_i8normx4' | 'tex5_u16x2' | 'tex5_u16x4' | 'tex5_i16x2' | 'tex5_i16x4' | 'tex5_u16normx2' | 'tex5_u16normx4' | 'tex5_i16normx2' | 'tex5_i16normx4' | 'tex5_f16x2' | 'tex5_f16x4' | 'tex5_f32' | 'tex5_f32x2' | 'tex5_f32x3' | 'tex5_f32x4' | 'tex5_i32' | 'tex5_i32x2' | 'tex5_i32x3' | 'tex5_i32x4' | 'tex5_u32' | 'tex5_u32x2' | 'tex5_u32x3' | 'tex5_u32x4' | 'tex6_u8normx2' | 'tex6_u8normx4' | 'tex6_i8normx2' | 'tex6_i8normx4' | 'tex6_u16x2' | 'tex6_u16x4' | 'tex6_i16x2' | 'tex6_i16x4' | 'tex6_u16normx2' | 'tex6_u16normx4' | 'tex6_i16normx2' | 'tex6_i16normx4' | 'tex6_f16x2' | 'tex6_f16x4' | 'tex6_f32' | 'tex6_f32x2' | 'tex6_f32x3' | 'tex6_f32x4' | 'tex6_i32' | 'tex6_i32x2' | 'tex6_i32x3' | 'tex6_i32x4' | 'tex6_u32' | 'tex6_u32x2' | 'tex6_u32x3' | 'tex6_u32x4' | 'tex7_u8normx2' | 'tex7_u8normx4' | 'tex7_i8normx2' | 'tex7_i8normx4' | 'tex7_u16x2' | 'tex7_u16x4' | 'tex7_i16x2' | 'tex7_i16x4' | 'tex7_u16normx2' | 'tex7_u16normx4' | 'tex7_i16normx2' | 'tex7_i16normx4' | 'tex7_f16x2' | 'tex7_f16x4' | 'tex7_f32' | 'tex7_f32x2' | 'tex7_f32x3' | 'tex7_f32x4' | 'tex7_i32' | 'tex7_i32x2' | 'tex7_i32x3' | 'tex7_i32x4' | 'tex7_u32' | 'tex7_u32x2' | 'tex7_u32x3' | 'tex7_u32x4' | 'blendweights_f16x4' | 'blendweights_f32x4' | 'blendindices_u16x4' | 'blendindices_f16x4' | 'blendindices_f32x4' | 'blendindices_u32x4';
602
+ type VertexAttribFormat = 'position_u8normx2' | 'position_u8normx4' | 'position_i8normx2' | 'position_i8normx4' | 'position_u16x2' | 'position_u16x4' | 'position_i16x2' | 'position_i16x4' | 'position_u16normx2' | 'position_u16normx4' | 'position_i16normx2' | 'position_i16normx4' | 'position_f16x2' | 'position_f16x4' | 'position_f32' | 'position_f32x2' | 'position_f32x3' | 'position_f32x4' | 'position_i32' | 'position_i32x2' | 'position_i32x3' | 'position_i32x4' | 'position_u32' | 'position_u32x2' | 'position_u32x3' | 'position_u32x4' | 'normal_f16x4' | 'normal_f32x3' | 'normal_f32x4' | 'diffuse_u8normx4' | 'diffuse_u16x4' | 'diffuse_u16normx4' | 'diffuse_f16x4' | 'diffuse_f32x3' | 'diffuse_f32x4' | 'diffuse_u32x3' | 'diffuse_u32x4' | 'tangent_f16x4' | 'tangent_f32x3' | 'tangent_f32x4' | 'tex0_u8normx2' | 'tex0_u8normx4' | 'tex0_i8normx2' | 'tex0_i8normx4' | 'tex0_u16x2' | 'tex0_u16x4' | 'tex0_i16x2' | 'tex0_i16x4' | 'tex0_u16normx2' | 'tex0_u16normx4' | 'tex0_i16normx2' | 'tex0_i16normx4' | 'tex0_f16x2' | 'tex0_f16x4' | 'tex0_f32' | 'tex0_f32x2' | 'tex0_f32x3' | 'tex0_f32x4' | 'tex0_i32' | 'tex0_i32x2' | 'tex0_i32x3' | 'tex0_i32x4' | 'tex0_u32' | 'tex0_u32x2' | 'tex0_u32x3' | 'tex0_u32x4' | 'tex1_u8normx2' | 'tex1_u8normx4' | 'tex1_i8normx2' | 'tex1_i8normx4' | 'tex1_u16x2' | 'tex1_u16x4' | 'tex1_i16x2' | 'tex1_i16x4' | 'tex1_u16normx2' | 'tex1_u16normx4' | 'tex1_i16normx2' | 'tex1_i16normx4' | 'tex1_f16x2' | 'tex1_f16x4' | 'tex1_f32' | 'tex1_f32x2' | 'tex1_f32x3' | 'tex1_f32x4' | 'tex1_i32' | 'tex1_i32x2' | 'tex1_i32x3' | 'tex1_i32x4' | 'tex1_u32' | 'tex1_u32x2' | 'tex1_u32x3' | 'tex1_u32x4' | 'tex2_u8normx2' | 'tex2_u8normx4' | 'tex2_i8normx2' | 'tex2_i8normx4' | 'tex2_u16x2' | 'tex2_u16x4' | 'tex2_i16x2' | 'tex2_i16x4' | 'tex2_u16normx2' | 'tex2_u16normx4' | 'tex2_i16normx2' | 'tex2_i16normx4' | 'tex2_f16x2' | 'tex2_f16x4' | 'tex2_f32' | 'tex2_f32x2' | 'tex2_f32x3' | 'tex2_f32x4' | 'tex2_i32' | 'tex2_i32x2' | 'tex2_i32x3' | 'tex2_i32x4' | 'tex2_u32' | 'tex2_u32x2' | 'tex2_u32x3' | 'tex2_u32x4' | 'tex3_u8normx2' | 'tex3_u8normx4' | 'tex3_i8normx2' | 'tex3_i8normx4' | 'tex3_u16x2' | 'tex3_u16x4' | 'tex3_i16x2' | 'tex3_i16x4' | 'tex3_u16normx2' | 'tex3_u16normx4' | 'tex3_i16normx2' | 'tex3_i16normx4' | 'tex3_f16x2' | 'tex3_f16x4' | 'tex3_f32' | 'tex3_f32x2' | 'tex3_f32x3' | 'tex3_f32x4' | 'tex3_i32' | 'tex3_i32x2' | 'tex3_i32x3' | 'tex3_i32x4' | 'tex3_u32' | 'tex3_u32x2' | 'tex3_u32x3' | 'tex3_u32x4' | 'tex4_u8normx2' | 'tex4_u8normx4' | 'tex4_i8normx2' | 'tex4_i8normx4' | 'tex4_u16x2' | 'tex4_u16x4' | 'tex4_i16x2' | 'tex4_i16x4' | 'tex4_u16normx2' | 'tex4_u16normx4' | 'tex4_i16normx2' | 'tex4_i16normx4' | 'tex4_f16x2' | 'tex4_f16x4' | 'tex4_f32' | 'tex4_f32x2' | 'tex4_f32x3' | 'tex4_f32x4' | 'tex4_i32' | 'tex4_i32x2' | 'tex4_i32x3' | 'tex4_i32x4' | 'tex4_u32' | 'tex4_u32x2' | 'tex4_u32x3' | 'tex4_u32x4' | 'tex5_u8normx2' | 'tex5_u8normx4' | 'tex5_i8normx2' | 'tex5_i8normx4' | 'tex5_u16x2' | 'tex5_u16x4' | 'tex5_i16x2' | 'tex5_i16x4' | 'tex5_u16normx2' | 'tex5_u16normx4' | 'tex5_i16normx2' | 'tex5_i16normx4' | 'tex5_f16x2' | 'tex5_f16x4' | 'tex5_f32' | 'tex5_f32x2' | 'tex5_f32x3' | 'tex5_f32x4' | 'tex5_i32' | 'tex5_i32x2' | 'tex5_i32x3' | 'tex5_i32x4' | 'tex5_u32' | 'tex5_u32x2' | 'tex5_u32x3' | 'tex5_u32x4' | 'tex6_u8normx2' | 'tex6_u8normx4' | 'tex6_i8normx2' | 'tex6_i8normx4' | 'tex6_u16x2' | 'tex6_u16x4' | 'tex6_i16x2' | 'tex6_i16x4' | 'tex6_u16normx2' | 'tex6_u16normx4' | 'tex6_i16normx2' | 'tex6_i16normx4' | 'tex6_f16x2' | 'tex6_f16x4' | 'tex6_f32' | 'tex6_f32x2' | 'tex6_f32x3' | 'tex6_f32x4' | 'tex6_i32' | 'tex6_i32x2' | 'tex6_i32x3' | 'tex6_i32x4' | 'tex6_u32' | 'tex6_u32x2' | 'tex6_u32x3' | 'tex6_u32x4' | 'tex7_u8normx2' | 'tex7_u8normx4' | 'tex7_i8normx2' | 'tex7_i8normx4' | 'tex7_u16x2' | 'tex7_u16x4' | 'tex7_i16x2' | 'tex7_i16x4' | 'tex7_u16normx2' | 'tex7_u16normx4' | 'tex7_i16normx2' | 'tex7_i16normx4' | 'tex7_f16x2' | 'tex7_f16x4' | 'tex7_f32' | 'tex7_f32x2' | 'tex7_f32x3' | 'tex7_f32x4' | 'tex7_i32' | 'tex7_i32x2' | 'tex7_i32x3' | 'tex7_i32x4' | 'tex7_u32' | 'tex7_u32x2' | 'tex7_u32x3' | 'tex7_u32x4' | 'blendweights_f16x1' | 'blendweights_f32x1' | 'blendweights_f16x2' | 'blendweights_f32x2' | 'blendweights_f16x3' | 'blendweights_f32x3' | 'blendweights_f16x4' | 'blendweights_f32x4' | 'blendindices_f16x1' | 'blendindices_u16x1' | 'blendindices_f32x1' | 'blendindices_u32x1' | 'blendindices_f16x2' | 'blendindices_u16x2' | 'blendindices_f32x2' | 'blendindices_u32x2' | 'blendindices_f16x3' | 'blendindices_u16x3' | 'blendindices_f32x3' | 'blendindices_u32x3' | 'blendindices_f16x4' | 'blendindices_u16x4' | 'blendindices_f32x4' | 'blendindices_u32x4';
603
603
  /**
604
604
  * The semantic type of vertex
605
605
  * @public
@@ -688,6 +688,26 @@ declare enum GPUResourceUsageFlags {
688
688
  DYNAMIC = 2048,
689
689
  MANAGED = 4096
690
690
  }
691
+ /**
692
+ * Get vertex attribute index by semantic
693
+ * @public
694
+ */
695
+ declare function getVertexAttribByName(name: VertexSemantic): number;
696
+ /**
697
+ * Get vertex semantic by attribute index
698
+ * @public
699
+ */
700
+ declare function getVertexAttribName(attrib: number): VertexSemantic;
701
+ /**
702
+ * Get byte size of specified vertex format
703
+ * @public
704
+ */
705
+ declare function getVertexFormatSize(fmt: VertexAttribFormat): number;
706
+ /**
707
+ * Get number of components of specified vertex format
708
+ * @public
709
+ */
710
+ declare function getVertexFormatComponentCount(fmt: VertexAttribFormat): number;
691
711
  /**
692
712
  * Get vertex format by semantic and component type and component count
693
713
  * @param semantic - The vertex semantic
@@ -1021,6 +1041,7 @@ interface BaseTexture<T = unknown> extends GPUObject<T> {
1021
1041
  readonly depth: number;
1022
1042
  readonly format: TextureFormat;
1023
1043
  readonly mipLevelCount: number;
1044
+ readonly memCost: number;
1024
1045
  samplerOptions: SamplerOptions;
1025
1046
  init(): void;
1026
1047
  generateMipmaps(): void;
@@ -2688,6 +2709,133 @@ interface RenderStateSet {
2688
2709
  apply(force?: boolean): void;
2689
2710
  }
2690
2711
 
2712
+ /**
2713
+ * ObjectPool class is responsible for managing and reusing textures and framebuffers.
2714
+ * @public
2715
+ */
2716
+ declare class Pool {
2717
+ /**
2718
+ * Creates an instance of Pool class
2719
+ * @param device - Rendering device
2720
+ */
2721
+ constructor(device: AbstractDevice, memCostThreshold?: number);
2722
+ autoRelease(): void;
2723
+ /**
2724
+ * Fetch a temporal 2D texture from the object pool.
2725
+ * @param autoRelease - Whether the texture should be automatically released at the next frame.
2726
+ * @param format - The format of the texture.
2727
+ * @param width - The width of the texture.
2728
+ * @param height - The height of the texture.
2729
+ * @param mipmapping - Whether this texture support mipmapping
2730
+ * @returns The fetched Texture2D object.
2731
+ */
2732
+ fetchTemporalTexture2D(autoRelease: boolean, format: TextureFormat, width: number, height: number, mipmapping: boolean): Texture2D;
2733
+ /**
2734
+ * Fetch a temporal 2D array texture from the object pool.
2735
+ * @param autoRelease - Whether the texture should be automatically released at the next frame.
2736
+ * @param format - Format of the texture.
2737
+ * @param width - Width of the texture.
2738
+ * @param height - Height of the texture.
2739
+ * @param numLayers - Layer count of the texture
2740
+ * @param mipmapping - Whether this texture support mipmapping
2741
+ * @returns The fetched Texture2DArray object.
2742
+ */
2743
+ fetchTemporalTexture2DArray(autoRelease: boolean, format: TextureFormat, width: number, height: number, numLayers: number, mipmapping: boolean): Texture2DArray;
2744
+ /**
2745
+ * Fetch a temporal Cube texture from the object pool.
2746
+ * @param autoRelease - Whether the texture should be automatically released at the next frame.
2747
+ * @param format - Format of the texture.
2748
+ * @param size - size of the texture.
2749
+ * @param mipmapping - Whether this texture support mipmapping
2750
+ * @returns The fetched TextureCube object.
2751
+ */
2752
+ fetchTemporalTextureCube(autoRelease: boolean, format: TextureFormat, size: number, mipmapping: boolean): TextureCube;
2753
+ /**
2754
+ * Fetch a temporal framebuffer from the object pool.
2755
+ * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.
2756
+ * @param colorFormat - Texture format for color attachment.
2757
+ * @param depthFormat - Texture format for depth attachment.
2758
+ * @param sampleCount - The sample count for the framebuffer.
2759
+ * @param ignoreDepthStencil - Whether to ignore depth stencil.
2760
+ * @returns The fetched FrameBuffer object.
2761
+ */
2762
+ fetchTemporalFramebuffer(autoRelease: boolean, width: number, height: number, colorFormat: TextureFormat, depthFormat?: TextureFormat, mipmapping?: boolean, sampleCount?: number, ignoreDepthStencil?: boolean): FrameBuffer;
2763
+ /**
2764
+ * Fetch a temporal framebuffer from the object pool.
2765
+ * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.
2766
+ * @param colorFormat - Texture format for color attachment.
2767
+ * @param depthTex - depth attachment.
2768
+ * @param sampleCount - The sample count for the framebuffer.
2769
+ * @param ignoreDepthStencil - Whether to ignore depth stencil.
2770
+ * @returns The fetched FrameBuffer object.
2771
+ */
2772
+ fetchTemporalFramebuffer<T extends BaseTexture<unknown>>(autoRelease: boolean, width: number, height: number, colorFormat: TextureFormat, depthTex?: T, mipmapping?: boolean, sampleCount?: number, ignoreDepthStencil?: boolean): FrameBuffer;
2773
+ /**
2774
+ * Fetch a temporal framebuffer from the object pool.
2775
+ * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.
2776
+ * @param colorTex - color attachment.
2777
+ * @param depthFormat - Texture format for depth attachment.
2778
+ * @param sampleCount - The sample count for the framebuffer.
2779
+ * @param ignoreDepthStencil - Whether to ignore depth stencil.
2780
+ * @returns The fetched FrameBuffer object.
2781
+ */
2782
+ fetchTemporalFramebuffer<T extends BaseTexture<unknown>>(autoRelease: boolean, width: number, height: number, colorTex: T, depthFormat?: TextureFormat, mipmapping?: boolean, sampleCount?: number, ignoreDepthStencil?: boolean): FrameBuffer;
2783
+ /**
2784
+ * Fetch a temporal framebuffer from the object pool.
2785
+ * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.
2786
+ * @param colorTex - color attachment.
2787
+ * @param depthTex - depth attachment.
2788
+ * @param sampleCount - The sample count for the framebuffer.
2789
+ * @param ignoreDepthStencil - Whether to ignore depth stencil.
2790
+ * @returns The fetched FrameBuffer object.
2791
+ */
2792
+ fetchTemporalFramebuffer<T extends BaseTexture<unknown>>(autoRelease: boolean, width: number, height: number, colorTex: T, depthTex?: T, mipmapping?: boolean, sampleCount?: number, ignoreDepthStencil?: boolean): FrameBuffer;
2793
+ /**
2794
+ * Fetch a temporal framebuffer from the object pool.
2795
+ * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.
2796
+ * @param colorTexOrFormat - color attachment or texture format.
2797
+ * @param depthTexOrFormat - depth attachment or texture format.
2798
+ * @param sampleCount - The sample count for the framebuffer.
2799
+ * @param ignoreDepthStencil - Whether to ignore depth stencil.
2800
+ * @returns The fetched FrameBuffer object.
2801
+ */
2802
+ fetchTemporalFramebuffer<T extends BaseTexture<unknown>>(autoRelease: boolean, width: number, height: number, colorTexOrFormat: TextureFormat | T, depthTexOrFormat?: TextureFormat | T, mipmapping?: boolean, sampleCount?: number, ignoreDepthStencil?: boolean): FrameBuffer;
2803
+ /**
2804
+ * Creates a temporal framebuffer from the object pool.
2805
+ * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.
2806
+ * @param colorAttachments - Array of color attachments for the framebuffer.
2807
+ * @param depthAttachment - Depth attachment for the framebuffer.
2808
+ * @param sampleCount - The sample count for the framebuffer.
2809
+ * @param ignoreDepthStencil - Whether to ignore depth stencil.
2810
+ * @returns The fetched FrameBuffer object.
2811
+ */
2812
+ createTemporalFramebuffer(autoRelease: boolean, colorAttachments: BaseTexture[], depthAttachment?: BaseTexture, sampleCount?: number, ignoreDepthStencil?: boolean): FrameBuffer<unknown>;
2813
+ /**
2814
+ * Dispose a texture that is allocated from the object pool.
2815
+ * @param texture - The texture to dispose.
2816
+ */
2817
+ disposeTexture(texture: BaseTexture): void;
2818
+ /**
2819
+ * Release a texture back to the object pool.
2820
+ * @param texture - The texture to release.
2821
+ */
2822
+ releaseTexture(texture: BaseTexture): void;
2823
+ /**
2824
+ * Dispose a framebuffer that is allocated from the object pool.
2825
+ * @param fb - The framebuffer to dispose.
2826
+ */
2827
+ disposeFrameBuffer(fb: FrameBuffer): void;
2828
+ /**
2829
+ * Release a framebuffer back to the object pool.
2830
+ * @param fb - The framebuffer to release.
2831
+ */
2832
+ releaseFrameBuffer(fb: FrameBuffer): void;
2833
+ /**
2834
+ * Purge the object pool by disposing all free framebuffers and textures.
2835
+ */
2836
+ purge(): void;
2837
+ }
2838
+
2691
2839
  /**
2692
2840
  * The webgl context type
2693
2841
  * @public
@@ -2722,7 +2870,7 @@ type DataType = 'u8' | 'u8norm' | 'i8' | 'i8norm' | 'u16' | 'u16norm' | 'i16' |
2722
2870
  * Texture format type
2723
2871
  * @public
2724
2872
  */
2725
- type TextureFormat = 'unknown' | 'r8unorm' | 'r8snorm' | 'r16f' | 'r32f' | 'r8ui' | 'r8i' | 'r16ui' | 'r16i' | 'r32ui' | 'r32i' | 'rg8unorm' | 'rg8snorm' | 'rg16f' | 'rg32f' | 'rg8ui' | 'rg8i' | 'rg16ui' | 'rg16i' | 'rg32ui' | 'rg32i' | 'rgba8unorm' | 'rgba8unorm-srgb' | 'rgba8snorm' | 'bgra8unorm' | 'bgra8unorm-srgb' | 'rgba16f' | 'rgba32f' | 'rgba8ui' | 'rgba8i' | 'rgba16ui' | 'rgba16i' | 'rgba32ui' | 'rgba32i' | 'rg11b10uf' | 'd16' | 'd24' | 'd32f' | 'd24s8' | 'd32fs8' | 'dxt1' | 'dxt1-srgb' | 'dxt3' | 'dxt3-srgb' | 'dxt5' | 'dxt5-srgb';
2873
+ type TextureFormat = 'unknown' | 'r8unorm' | 'r8snorm' | 'r16f' | 'r32f' | 'r8ui' | 'r8i' | 'r16ui' | 'r16i' | 'r32ui' | 'r32i' | 'rg8unorm' | 'rg8snorm' | 'rg16f' | 'rg32f' | 'rg8ui' | 'rg8i' | 'rg16ui' | 'rg16i' | 'rg32ui' | 'rg32i' | 'rgba8unorm' | 'rgba8unorm-srgb' | 'rgba8snorm' | 'bgra8unorm' | 'bgra8unorm-srgb' | 'rgba16f' | 'rgba32f' | 'rgba8ui' | 'rgba8i' | 'rgba16ui' | 'rgba16i' | 'rgba32ui' | 'rgba32i' | 'rg11b10uf' | 'd16' | 'd24' | 'd32f' | 'd24s8' | 'd32fs8' | 'dxt1' | 'dxt1-srgb' | 'dxt3' | 'dxt3-srgb' | 'dxt5' | 'dxt5-srgb' | 'bc4' | 'bc4-signed' | 'bc5' | 'bc5-signed' | 'bc7' | 'bc7-srgb' | 'bc6h' | 'bc6h-signed' | 'astc-4x4' | 'astc-4x4-srgb' | 'astc-5x4' | 'astc-5x4-srgb' | 'astc-5x5' | 'astc-5x5-srgb' | 'astc-6x5' | 'astc-6x5-srgb' | 'astc-6x6' | 'astc-6x6-srgb' | 'astc-8x5' | 'astc-8x5-srgb' | 'astc-8x6' | 'astc-8x6-srgb' | 'astc-8x8' | 'astc-8x8-srgb' | 'astc-10x5' | 'astc-10x5-srgb' | 'astc-10x6' | 'astc-10x6-srgb' | 'astc-10x8' | 'astc-10x8-srgb' | 'astc-10x10' | 'astc-10x10-srgb' | 'astc-12x10' | 'astc-12x10-srgb' | 'astc-12x12' | 'astc-12x12-srgb';
2726
2874
  /**
2727
2875
  * Converts a non-sRGB texture format to the corresponding sRGB texture format
2728
2876
  * @param format - The texture format to be converted
@@ -2990,6 +3138,12 @@ interface TextureCaps {
2990
3138
  npo2Repeating: boolean;
2991
3139
  /** True if device supports dxt1, dxt3, dxt5 texture format */
2992
3140
  supportS3TC: boolean;
3141
+ /** True if device supports bptc texture format */
3142
+ supportBPTC: boolean;
3143
+ /** True if device supports rgtc texture format */
3144
+ supportRGTC: boolean;
3145
+ /** True if device supports astc texture format */
3146
+ supportASTC: boolean;
2993
3147
  /** True if device supports dxt1_srgb, dxt3-srgb, dxt5-srgb texture format */
2994
3148
  supportS3TCSRGB: boolean;
2995
3149
  /** True if device supports depth texture */
@@ -3168,6 +3322,12 @@ type DeviceViewport = {
3168
3322
  * @public
3169
3323
  */
3170
3324
  interface AbstractDevice extends IEventTarget<DeviceEventMap> {
3325
+ /** Get pool object */
3326
+ pool: Pool;
3327
+ /** vSync */
3328
+ vSync: boolean;
3329
+ /** Get adapter information */
3330
+ getAdapterInfo(): any;
3171
3331
  /** Get sample count of current frame buffer */
3172
3332
  getFrameBufferSampleCount(): number;
3173
3333
  /** Returns true if device context is lost. */
@@ -3184,6 +3344,10 @@ interface AbstractDevice extends IEventTarget<DeviceEventMap> {
3184
3344
  getBackBufferHeight(): number;
3185
3345
  /** Get the device capabilities */
3186
3346
  getDeviceCaps(): DeviceCaps;
3347
+ /** Schedule next frame */
3348
+ nextFrame(callback: () => void): number;
3349
+ /** Cancel schedule next frame */
3350
+ cancelNextFrame(handle: number): any;
3187
3351
  /** Set font for drawText function */
3188
3352
  setFont(fontName: string): any;
3189
3353
  /**
@@ -3389,11 +3553,29 @@ interface AbstractDevice extends IEventTarget<DeviceEventMap> {
3389
3553
  /** Get current render states */
3390
3554
  getRenderStates(): RenderStateSet;
3391
3555
  /**
3392
- * Set current frame buffer
3556
+ * Sets the current framebuffer to the specified FrameBuffer object.
3393
3557
  *
3394
- * @param rt - The frame buffer
3558
+ * @param rt - The FrameBuffer object to set as the current framebuffer.
3395
3559
  */
3396
- setFramebuffer(rt: FrameBuffer): void;
3560
+ setFramebuffer(rt: FrameBuffer): any;
3561
+ /**
3562
+ * Sets the current framebuffer specifying complex color attachments, an optional depth attachment, MIP level, face, and sample count.
3563
+ *
3564
+ * @param color - An array of BaseTextures or objects containing a BaseTexture and optional properties. Each BaseTexture or object will serve as a color attachment.
3565
+ * - If an object is provided, it can specify:
3566
+ * - `texture`: The BaseTexture to use.
3567
+ * - `miplevel`: Optional MIP level for this specific texture. default is 0.
3568
+ * - `face`: Optional face index for cube map textures, specifying the cube face this texture is attached to. default is 0.
3569
+ * - `layer`: Optional layer index, useful for texture arrays. default is 0.
3570
+ * @param depth - Optional BaseTexture to serve as the depth attachment.
3571
+ * @param sampleCount - Optional sample count defining the number of samples for multisampling.
3572
+ */
3573
+ setFramebuffer(color: (BaseTexture | {
3574
+ texture: BaseTexture;
3575
+ miplevel?: number;
3576
+ face?: number;
3577
+ layer?: number;
3578
+ })[], depth?: BaseTexture, miplevel?: number, face?: number, sampleCount?: number): any;
3397
3579
  /** Get current frame buffer */
3398
3580
  getFramebuffer(): FrameBuffer;
3399
3581
  /**
@@ -3638,8 +3820,12 @@ declare abstract class BaseDevice {
3638
3820
  protected _backend: DeviceBackend;
3639
3821
  protected _beginFrameCounter: number;
3640
3822
  protected _programBuilder: ProgramBuilder;
3823
+ protected _pool: Pool;
3824
+ protected _temporalFramebuffer: boolean;
3825
+ protected _vSync: boolean;
3641
3826
  private _stateStack;
3642
3827
  constructor(cvs: HTMLCanvasElement, backend: DeviceBackend);
3828
+ abstract getAdapterInfo(): any;
3643
3829
  abstract getFrameBufferSampleCount(): number;
3644
3830
  abstract isContextLost(): boolean;
3645
3831
  abstract getScale(): number;
@@ -3684,11 +3870,12 @@ declare abstract class BaseDevice {
3684
3870
  abstract getVertexLayout(): VertexLayout;
3685
3871
  abstract setRenderStates(renderStates: RenderStateSet): void;
3686
3872
  abstract getRenderStates(): RenderStateSet;
3687
- abstract setFramebuffer(rt: FrameBuffer): void;
3688
3873
  abstract getFramebuffer(): FrameBuffer;
3689
3874
  abstract setBindGroup(index: number, bindGroup: BindGroup, dynamicOffsets?: Iterable<number>): any;
3690
3875
  abstract getBindGroup(index: number): [BindGroup, Iterable<number>];
3691
3876
  abstract flush(): void;
3877
+ abstract nextFrame(callback: () => void): number;
3878
+ abstract cancelNextFrame(handle: number): any;
3692
3879
  abstract readPixels(index: number, x: number, y: number, w: number, h: number, buffer: TypedArray): Promise<void>;
3693
3880
  abstract readPixelsToBuffer(index: number, x: number, y: number, w: number, h: number, buffer: GPUDataBuffer): void;
3694
3881
  abstract beginCapture(): void;
@@ -3705,10 +3892,20 @@ declare abstract class BaseDevice {
3705
3892
  get isRendering(): boolean;
3706
3893
  get canvas(): HTMLCanvasElement;
3707
3894
  get type(): string;
3895
+ get vSync(): boolean;
3896
+ set vSync(val: boolean);
3897
+ get pool(): Pool;
3708
3898
  get runLoopFunction(): (device: AbstractDevice) => void;
3709
3899
  get programBuilder(): ProgramBuilder;
3710
3900
  setFont(fontName: string): void;
3711
3901
  drawText(text: string, x: number, y: number, color: string): void;
3902
+ setFramebuffer(rt: FrameBuffer): any;
3903
+ setFramebuffer(color: (BaseTexture | {
3904
+ texture: BaseTexture;
3905
+ miplevel?: number;
3906
+ face?: number;
3907
+ layer?: number;
3908
+ })[], depth?: BaseTexture, sampleCount?: number): any;
3712
3909
  disposeObject(obj: GPUObject, remove?: boolean): void;
3713
3910
  restoreObject(obj: GPUObject): Promise<void>;
3714
3911
  enableGPUTimeRecording(enable: boolean): void;
@@ -3736,6 +3933,7 @@ declare abstract class BaseDevice {
3736
3933
  updateVideoMemoryCost(delta: number): void;
3737
3934
  protected abstract onBeginFrame(): boolean;
3738
3935
  protected abstract onEndFrame(): void;
3936
+ protected abstract _setFramebuffer(fb: FrameBuffer): any;
3739
3937
  private _onresize;
3740
3938
  private _registerEventHandlers;
3741
3939
  private updateFrameInfo;
@@ -3963,4 +4161,4 @@ declare class StructuredBufferData {
3963
4161
  set(name: string, value: StructuredValue): void;
3964
4162
  }
3965
4163
 
3966
- export { AbstractDevice, ArrayTypeDetail, AtlasInfo, AtomicTypeInfoDetail, BaseCreationOptions, BaseDevice, BaseTexture, BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindPointInfo, BlendEquation, BlendFunc, BlendingState, BufferBindingLayout, BufferCreationOptions, BufferUsage, CPUTimer, ColorState, CompareFunc, ComputeProgramConstructParams, DataType, DepthState, DeviceBackend, DeviceCaps, DeviceEventMap, DeviceGPUObjectAddedEvent, DeviceGPUObjectRemovedEvent, DeviceGPUObjectRenameEvent, DeviceLostEvent, DeviceOptions, DeviceResizeEvent, DeviceRestoreEvent, DeviceViewport, DrawText, ExpValueNonArrayType, ExpValueType, ExternalTextureBindingLayout, FaceMode, FaceWinding, Font, FrameBuffer, FrameBufferOptions, FrameBufferTextureAttachment, FrameInfo, FramebufferCaps, FunctionTypeDetail, GPUDataBuffer, GPUObject, GPUObjectList, GPUProgram, GPUProgramConstructParams, GPUResourceUsageFlags, GlyphManager, ITimer, IndexBuffer, MiscCaps, PBAddressSpace, PBAnyTypeInfo, PBArrayTypeInfo, PBAtomicI32TypeInfo, PBAtomicU32TypeInfo, PBBuiltinScope, PBComputeOptions, PBDoWhileScope, PBForScope, PBFunctionScope, PBFunctionTypeInfo, PBGlobalScope, PBIfScope, PBInputScope, PBInsideFunctionScope, PBLocalScope, PBNakedScope, PBOutputScope, PBPointerTypeInfo, PBPrimitiveType, PBPrimitiveTypeInfo, PBReflection, PBReflectionTagGetter, PBRenderOptions, PBSamplerAccessMode, PBSamplerTypeInfo, PBScope, PBShaderExp, PBStructLayout, PBStructTypeInfo, PBTextureType, PBTextureTypeInfo, PBTypeInfo, PBVoidTypeInfo, PBWhileScope, PointerTypeDetail, PrimitiveType, PrimitiveTypeDetail, ProgramBuilder, Proxiable, RasterizerState, RenderBundle, RenderProgramConstructParams, RenderStateSet, SamplerBindingLayout, SamplerOptions, SamplerTypeDetail, ShaderCaps, ShaderExpTagRecord, ShaderExpTagValue, ShaderKind, ShaderType, ShaderTypeFunc, StencilOp, StencilState, StorageTextureBindingLayout, StructTypeDetail, StructuredBuffer, StructuredBufferData, StructuredValue, Texture2D, Texture2DArray, Texture3D, TextureAddressMode, TextureAtlasManager, TextureBindingLayout, TextureCaps, TextureColorSpace, TextureCreationOptions, TextureCube, TextureFilterMode, TextureFormat, TextureFormatInfo, TextureImageElement, TextureMipmapData, TextureMipmapLevelData, TextureSampler, TextureType, TextureTypeDetail, TextureVideo, TypeDetailInfo, UniformBufferLayout, UniformLayout, VertexAttribFormat, VertexBufferInfo, VertexData, VertexLayout, VertexLayoutOptions, VertexSemantic, VertexStepMode, WebGLContext, genDefaultName, getTextureFormatBlockHeight, getTextureFormatBlockSize, getTextureFormatBlockWidth, getVertexAttribFormat, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, hasAlphaChannel, hasBlueChannel, hasDepthChannel, hasGreenChannel, hasRedChannel, hasStencilChannel, isCompressedTextureFormat, isFloatTextureFormat, isIntegerTextureFormat, isSRGBTextureFormat, isSignedTextureFormat, linearTextureFormatToSRGB, makeVertexBufferType, semanticList };
4164
+ export { AbstractDevice, ArrayTypeDetail, AtlasInfo, AtomicTypeInfoDetail, BaseCreationOptions, BaseDevice, BaseTexture, BindGroup, BindGroupLayout, BindGroupLayoutEntry, BindPointInfo, BlendEquation, BlendFunc, BlendingState, BufferBindingLayout, BufferCreationOptions, BufferUsage, CPUTimer, ColorState, CompareFunc, ComputeProgramConstructParams, DataType, DepthState, DeviceBackend, DeviceCaps, DeviceEventMap, DeviceGPUObjectAddedEvent, DeviceGPUObjectRemovedEvent, DeviceGPUObjectRenameEvent, DeviceLostEvent, DeviceOptions, DeviceResizeEvent, DeviceRestoreEvent, DeviceViewport, DrawText, ExpValueNonArrayType, ExpValueType, ExternalTextureBindingLayout, FaceMode, FaceWinding, Font, FrameBuffer, FrameBufferOptions, FrameBufferTextureAttachment, FrameInfo, FramebufferCaps, FunctionTypeDetail, GPUDataBuffer, GPUObject, GPUObjectList, GPUProgram, GPUProgramConstructParams, GPUResourceUsageFlags, GlyphManager, ITimer, IndexBuffer, MiscCaps, PBAddressSpace, PBAnyTypeInfo, PBArrayTypeInfo, PBAtomicI32TypeInfo, PBAtomicU32TypeInfo, PBBuiltinScope, PBComputeOptions, PBDoWhileScope, PBForScope, PBFunctionScope, PBFunctionTypeInfo, PBGlobalScope, PBIfScope, PBInputScope, PBInsideFunctionScope, PBLocalScope, PBNakedScope, PBOutputScope, PBPointerTypeInfo, PBPrimitiveType, PBPrimitiveTypeInfo, PBReflection, PBReflectionTagGetter, PBRenderOptions, PBSamplerAccessMode, PBSamplerTypeInfo, PBScope, PBShaderExp, PBStructLayout, PBStructTypeInfo, PBTextureType, PBTextureTypeInfo, PBTypeInfo, PBVoidTypeInfo, PBWhileScope, PointerTypeDetail, PrimitiveType, PrimitiveTypeDetail, ProgramBuilder, Proxiable, RasterizerState, RenderBundle, RenderProgramConstructParams, RenderStateSet, SamplerBindingLayout, SamplerOptions, SamplerTypeDetail, ShaderCaps, ShaderExpTagRecord, ShaderExpTagValue, ShaderKind, ShaderType, ShaderTypeFunc, StencilOp, StencilState, StorageTextureBindingLayout, StructTypeDetail, StructuredBuffer, StructuredBufferData, StructuredValue, Texture2D, Texture2DArray, Texture3D, TextureAddressMode, TextureAtlasManager, TextureBindingLayout, TextureCaps, TextureColorSpace, TextureCreationOptions, TextureCube, TextureFilterMode, TextureFormat, TextureFormatInfo, TextureImageElement, TextureMipmapData, TextureMipmapLevelData, TextureSampler, TextureType, TextureTypeDetail, TextureVideo, TypeDetailInfo, UniformBufferLayout, UniformLayout, VertexAttribFormat, VertexBufferInfo, VertexData, VertexLayout, VertexLayoutOptions, VertexSemantic, VertexStepMode, WebGLContext, genDefaultName, getTextureFormatBlockHeight, getTextureFormatBlockSize, getTextureFormatBlockWidth, getVertexAttribByName, getVertexAttribFormat, getVertexAttribName, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, getVertexFormatComponentCount, getVertexFormatSize, hasAlphaChannel, hasBlueChannel, hasDepthChannel, hasGreenChannel, hasRedChannel, hasStencilChannel, isCompressedTextureFormat, isFloatTextureFormat, isIntegerTextureFormat, isSRGBTextureFormat, isSignedTextureFormat, linearTextureFormatToSRGB, makeVertexBufferType, semanticList };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { DeviceGPUObjectAddedEvent, DeviceGPUObjectRemovedEvent, DeviceGPUObjectRenameEvent, DeviceLostEvent, DeviceResizeEvent, DeviceRestoreEvent, ShaderType, encodePixel, encodePixelToArray, getTextureFormatBlockHeight, getTextureFormatBlockSize, getTextureFormatBlockWidth, hasAlphaChannel, hasBlueChannel, hasDepthChannel, hasGreenChannel, hasRedChannel, hasStencilChannel, isCompressedTextureFormat, isFloatTextureFormat, isIntegerTextureFormat, isSRGBTextureFormat, isSignedTextureFormat, linearTextureFormatToSRGB } from './base_types.js';
2
2
  export { VertexData } from './vertexdata.js';
3
- export { GPUResourceUsageFlags, MAX_BINDING_GROUPS, MAX_TEXCOORD_INDEX_COUNT, MAX_VERTEX_ATTRIBUTES, VERTEX_ATTRIB_BLEND_INDICES, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_DIFFUSE, VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_TANGENT, VERTEX_ATTRIB_TEXCOORD0, VERTEX_ATTRIB_TEXCOORD1, VERTEX_ATTRIB_TEXCOORD2, VERTEX_ATTRIB_TEXCOORD3, VERTEX_ATTRIB_TEXCOORD4, VERTEX_ATTRIB_TEXCOORD5, VERTEX_ATTRIB_TEXCOORD6, VERTEX_ATTRIB_TEXCOORD7, genDefaultName, getVertexAttribByName, getVertexAttribFormat, getVertexAttribName, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, getVertexFormatSize, makeVertexBufferType, semanticList, semanticToAttrib } from './gpuobject.js';
3
+ export { GPUResourceUsageFlags, MAX_BINDING_GROUPS, MAX_TEXCOORD_INDEX_COUNT, MAX_VERTEX_ATTRIBUTES, VERTEX_ATTRIB_BLEND_INDICES, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_DIFFUSE, VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_POSITION, VERTEX_ATTRIB_TANGENT, VERTEX_ATTRIB_TEXCOORD0, VERTEX_ATTRIB_TEXCOORD1, VERTEX_ATTRIB_TEXCOORD2, VERTEX_ATTRIB_TEXCOORD3, VERTEX_ATTRIB_TEXCOORD4, VERTEX_ATTRIB_TEXCOORD5, VERTEX_ATTRIB_TEXCOORD6, VERTEX_ATTRIB_TEXCOORD7, genDefaultName, getVertexAttribByName, getVertexAttribFormat, getVertexAttribName, getVertexBufferAttribType, getVertexBufferAttribTypeBySemantic, getVertexBufferLength, getVertexBufferStride, getVertexFormatComponentCount, getVertexFormatSize, makeVertexBufferType, semanticList, semanticToAttrib } from './gpuobject.js';
4
4
  export { BaseDevice } from './device.js';
5
5
  export { PBShaderExp, Proxiable, getCurrentProgramBuilder, makeConstructor, setCurrentProgramBuilder } from './builder/base.js';
6
6
  export { ASTAddressOf, ASTArrayIndex, ASTAssignment, ASTBinaryFunc, ASTBreak, ASTCallFunction, ASTCast, ASTContinue, ASTDeclareVar, ASTDiscard, ASTDoWhile, ASTExpression, ASTFunction, ASTFunctionParameter, ASTGlobalScope, ASTHash, ASTIf, ASTLValue, ASTLValueArray, ASTLValueDeclare, ASTLValueHash, ASTLValueScalar, ASTNakedScope, ASTPrimitive, ASTRange, ASTReferenceOf, ASTReturn, ASTScalar, ASTScope, ASTSelect, ASTShaderExpConstructor, ASTStructDefine, ASTTouch, ASTUnaryFunc, ASTWhile, DeclareType, ShaderAST, ShaderPrecisionType, builtinVariables, genSamplerName, getBuiltinInputStructInstanceName, getBuiltinInputStructName, getBuiltinOutputStructInstanceName, getBuiltinOutputStructName, getBuiltinParamName, getTextureSampleType } from './builder/ast.js';
package/dist/pool.js ADDED
@@ -0,0 +1,324 @@
1
+ /**
2
+ * ObjectPool class is responsible for managing and reusing textures and framebuffers.
3
+ * @public
4
+ */ class Pool {
5
+ /** @internal */ _memCost;
6
+ /** @internal */ _memCostThreshold;
7
+ /** @internal */ _device;
8
+ /** @internal */ _freeTextures = {};
9
+ /** @internal */ _allocatedTextures = new WeakMap();
10
+ /** @internal */ _autoReleaseTextures = new Set();
11
+ /** @internal */ _freeFramebuffers = {};
12
+ /** @internal */ _allocatedFramebuffers = new WeakMap();
13
+ /** @internal */ _autoReleaseFramebuffers = new Set();
14
+ /**
15
+ * Creates an instance of Pool class
16
+ * @param device - Rendering device
17
+ */ constructor(device, memCostThreshold = 1024 * 1024 * 1024){
18
+ this._device = device;
19
+ this._memCost = 0;
20
+ this._memCostThreshold = memCostThreshold;
21
+ this._freeTextures = {};
22
+ this._allocatedTextures = new WeakMap();
23
+ this._autoReleaseTextures = new Set();
24
+ this._freeFramebuffers = {};
25
+ this._allocatedFramebuffers = new WeakMap();
26
+ this._autoReleaseFramebuffers = new Set();
27
+ this._memCost = 0;
28
+ }
29
+ autoRelease() {
30
+ // auto release objects
31
+ for (const tex of this._autoReleaseTextures){
32
+ this.releaseTexture(tex);
33
+ }
34
+ this._autoReleaseTextures.clear();
35
+ for (const fb of this._autoReleaseFramebuffers){
36
+ this.releaseFrameBuffer(fb);
37
+ }
38
+ this._autoReleaseFramebuffers.clear();
39
+ // Free up video memory if memory usage is greater than specific value
40
+ if (this._memCost >= this._memCostThreshold) {
41
+ this.purge();
42
+ }
43
+ }
44
+ /**
45
+ * Fetch a temporal 2D texture from the object pool.
46
+ * @param autoRelease - Whether the texture should be automatically released at the next frame.
47
+ * @param format - The format of the texture.
48
+ * @param width - The width of the texture.
49
+ * @param height - The height of the texture.
50
+ * @param mipmapping - Whether this texture support mipmapping
51
+ * @returns The fetched Texture2D object.
52
+ */ fetchTemporalTexture2D(autoRelease, format, width, height, mipmapping) {
53
+ const hash = `2d:${format}:${width}:${height}:${mipmapping ? 1 : 0}`;
54
+ let texture = null;
55
+ const list = this._freeTextures[hash];
56
+ if (!list) {
57
+ texture = this._device.createTexture2D(format, width, height, mipmapping ? {} : {
58
+ samplerOptions: {
59
+ mipFilter: 'none'
60
+ }
61
+ });
62
+ this._memCost += texture.memCost;
63
+ } else {
64
+ texture = list.pop();
65
+ if (list.length === 0) {
66
+ delete this._freeTextures[hash];
67
+ }
68
+ }
69
+ this._allocatedTextures.set(texture, {
70
+ hash,
71
+ refcount: 1,
72
+ dispose: false
73
+ });
74
+ if (autoRelease) {
75
+ this._autoReleaseTextures.add(texture);
76
+ }
77
+ return texture;
78
+ }
79
+ /**
80
+ * Fetch a temporal 2D array texture from the object pool.
81
+ * @param autoRelease - Whether the texture should be automatically released at the next frame.
82
+ * @param format - Format of the texture.
83
+ * @param width - Width of the texture.
84
+ * @param height - Height of the texture.
85
+ * @param numLayers - Layer count of the texture
86
+ * @param mipmapping - Whether this texture support mipmapping
87
+ * @returns The fetched Texture2DArray object.
88
+ */ fetchTemporalTexture2DArray(autoRelease, format, width, height, numLayers, mipmapping) {
89
+ const hash = `2darray:${format}:${width}:${height}:${numLayers}:${mipmapping ? 1 : 0}`;
90
+ let texture = null;
91
+ const list = this._freeTextures[hash];
92
+ if (!list) {
93
+ texture = this._device.createTexture2DArray(format, width, height, numLayers, mipmapping ? {} : {
94
+ samplerOptions: {
95
+ mipFilter: 'none'
96
+ }
97
+ });
98
+ this._memCost += texture.memCost;
99
+ } else {
100
+ texture = list.pop();
101
+ if (list.length === 0) {
102
+ delete this._freeTextures[hash];
103
+ }
104
+ }
105
+ this._allocatedTextures.set(texture, {
106
+ hash,
107
+ refcount: 1,
108
+ dispose: false
109
+ });
110
+ if (autoRelease) {
111
+ this._autoReleaseTextures.add(texture);
112
+ }
113
+ return texture;
114
+ }
115
+ /**
116
+ * Fetch a temporal Cube texture from the object pool.
117
+ * @param autoRelease - Whether the texture should be automatically released at the next frame.
118
+ * @param format - Format of the texture.
119
+ * @param size - size of the texture.
120
+ * @param mipmapping - Whether this texture support mipmapping
121
+ * @returns The fetched TextureCube object.
122
+ */ fetchTemporalTextureCube(autoRelease, format, size, mipmapping) {
123
+ const hash = `cube:${format}:${size}:${mipmapping ? 1 : 0}`;
124
+ let texture = null;
125
+ const list = this._freeTextures[hash];
126
+ if (!list) {
127
+ texture = this._device.createCubeTexture(format, size, mipmapping ? {} : {
128
+ samplerOptions: {
129
+ mipFilter: 'none'
130
+ }
131
+ });
132
+ this._memCost += texture.memCost;
133
+ } else {
134
+ texture = list.pop();
135
+ if (list.length === 0) {
136
+ delete this._freeTextures[hash];
137
+ }
138
+ }
139
+ this._allocatedTextures.set(texture, {
140
+ hash,
141
+ refcount: 1,
142
+ dispose: false
143
+ });
144
+ if (autoRelease) {
145
+ this._autoReleaseTextures.add(texture);
146
+ }
147
+ return texture;
148
+ }
149
+ fetchTemporalFramebuffer(autoRelease, width, height, colorTexOrFormat, depthTexOrFormat, mipmapping, sampleCount, ignoreDepthStencil) {
150
+ const colorAttachments = typeof colorTexOrFormat === 'string' ? [
151
+ this.fetchTemporalTexture2D(false, colorTexOrFormat, width, height, mipmapping)
152
+ ] : colorTexOrFormat ? [
153
+ colorTexOrFormat
154
+ ] : null;
155
+ const depthAttachment = typeof depthTexOrFormat === 'string' ? this.fetchTemporalTexture2D(false, depthTexOrFormat, width, height, false) : depthTexOrFormat;
156
+ const fb = this.createTemporalFramebuffer(autoRelease, colorAttachments, depthAttachment, sampleCount, ignoreDepthStencil);
157
+ if (typeof colorTexOrFormat === 'string') {
158
+ this.releaseTexture(colorAttachments[0]);
159
+ }
160
+ if (typeof depthTexOrFormat === 'string') {
161
+ this.releaseTexture(depthAttachment);
162
+ }
163
+ return fb;
164
+ }
165
+ /**
166
+ * Creates a temporal framebuffer from the object pool.
167
+ * @param autoRelease - Whether the framebuffer should be automatically released at the next frame.
168
+ * @param colorAttachments - Array of color attachments for the framebuffer.
169
+ * @param depthAttachment - Depth attachment for the framebuffer.
170
+ * @param sampleCount - The sample count for the framebuffer.
171
+ * @param ignoreDepthStencil - Whether to ignore depth stencil.
172
+ * @returns The fetched FrameBuffer object.
173
+ */ createTemporalFramebuffer(autoRelease, colorAttachments, depthAttachment, sampleCount, ignoreDepthStencil) {
174
+ colorAttachments = colorAttachments ?? [];
175
+ let hash = `${depthAttachment?.uid ?? 0}:${sampleCount ?? 1}:${ignoreDepthStencil ? 1 : 0}`;
176
+ for (const tex of colorAttachments){
177
+ hash += `:${tex.uid}`;
178
+ }
179
+ let fb = null;
180
+ const list = this._freeFramebuffers[hash];
181
+ if (!list) {
182
+ fb = this._device.createFrameBuffer(colorAttachments, depthAttachment, {
183
+ ignoreDepthStencil,
184
+ sampleCount
185
+ });
186
+ } else {
187
+ fb = list.pop();
188
+ if (list.length === 0) {
189
+ delete this._freeFramebuffers[hash];
190
+ }
191
+ }
192
+ // Mark referenced textures
193
+ const info = this._allocatedTextures.get(depthAttachment);
194
+ if (info) {
195
+ info.refcount++;
196
+ }
197
+ for (const tex of colorAttachments){
198
+ const info = this._allocatedTextures.get(tex);
199
+ if (info) {
200
+ info.refcount++;
201
+ }
202
+ }
203
+ this._allocatedFramebuffers.set(fb, hash);
204
+ if (autoRelease) {
205
+ this._autoReleaseFramebuffers.add(fb);
206
+ }
207
+ return fb;
208
+ }
209
+ /**
210
+ * Dispose a texture that is allocated from the object pool.
211
+ * @param texture - The texture to dispose.
212
+ */ disposeTexture(texture) {
213
+ this.safeReleaseTexture(texture, true);
214
+ }
215
+ /**
216
+ * Release a texture back to the object pool.
217
+ * @param texture - The texture to release.
218
+ */ releaseTexture(texture) {
219
+ const info = this._allocatedTextures.get(texture);
220
+ if (!info) {
221
+ console.error(`ObjectPool.releaseTexture(): texture is not allocated from pool`);
222
+ } else {
223
+ this.safeReleaseTexture(texture);
224
+ }
225
+ }
226
+ /**
227
+ * Dispose a framebuffer that is allocated from the object pool.
228
+ * @param fb - The framebuffer to dispose.
229
+ */ disposeFrameBuffer(fb) {
230
+ const hash = this._allocatedFramebuffers.get(fb);
231
+ if (!hash) {
232
+ console.error(`ObjectPool.disposeFrameBuffer(): framebuffer is not allocated from pool`);
233
+ } else {
234
+ this.internalDisposeFrameBuffer(fb);
235
+ fb.dispose();
236
+ }
237
+ }
238
+ /**
239
+ * Release a framebuffer back to the object pool.
240
+ * @param fb - The framebuffer to release.
241
+ */ releaseFrameBuffer(fb) {
242
+ const hash = this._allocatedFramebuffers.get(fb);
243
+ if (!hash) {
244
+ console.error(`ObjectPool.releaseFrameBuffer(): framebuffer is not allocated from pool`);
245
+ } else {
246
+ this.internalDisposeFrameBuffer(fb);
247
+ const list = this._freeFramebuffers[hash];
248
+ if (list) {
249
+ list.push(fb);
250
+ } else {
251
+ this._freeFramebuffers[hash] = [
252
+ fb
253
+ ];
254
+ }
255
+ }
256
+ }
257
+ /**
258
+ * Purge the object pool by disposing all free framebuffers and textures.
259
+ */ purge() {
260
+ for(const k in this._freeFramebuffers){
261
+ const list = this._freeFramebuffers[k];
262
+ if (list) {
263
+ for (const fb of this._freeFramebuffers[k]){
264
+ this.internalDisposeFrameBuffer(fb);
265
+ fb.dispose();
266
+ }
267
+ }
268
+ }
269
+ this._freeFramebuffers = {};
270
+ for(const k in this._freeTextures){
271
+ const list = this._freeTextures[k];
272
+ for (const tex of list){
273
+ this._memCost -= tex.memCost;
274
+ tex.dispose();
275
+ }
276
+ }
277
+ this._freeTextures = {};
278
+ }
279
+ /** @internal */ internalDisposeFrameBuffer(fb) {
280
+ if (fb) {
281
+ // Release attachment textures
282
+ const colorAttachments = fb.getColorAttachments();
283
+ if (colorAttachments) {
284
+ for (const tex of colorAttachments){
285
+ this.safeReleaseTexture(tex);
286
+ }
287
+ }
288
+ const depthAttachment = fb.getDepthAttachment();
289
+ if (depthAttachment) {
290
+ this.safeReleaseTexture(depthAttachment);
291
+ }
292
+ this._allocatedFramebuffers.delete(fb);
293
+ this._autoReleaseFramebuffers.delete(fb);
294
+ }
295
+ }
296
+ /** @internal */ safeReleaseTexture(texture, purge = false) {
297
+ const info = this._allocatedTextures.get(texture);
298
+ if (info) {
299
+ info.refcount--;
300
+ if (info.refcount === 0) {
301
+ this._allocatedTextures.delete(texture);
302
+ this._autoReleaseTextures.delete(texture);
303
+ if (purge || info.dispose) {
304
+ this._memCost -= texture.memCost;
305
+ texture.dispose();
306
+ } else {
307
+ const list = this._freeTextures[info.hash];
308
+ if (list) {
309
+ list.push(texture);
310
+ } else {
311
+ this._freeTextures[info.hash] = [
312
+ texture
313
+ ];
314
+ }
315
+ }
316
+ } else if (purge) {
317
+ info.dispose = true;
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ export { Pool };
324
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zephyr3d/device",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Device API for zephyr3d",
5
5
  "homepage": "https://github.com/gavinyork/zephyr3d#readme",
6
6
  "type": "module",
@@ -44,7 +44,7 @@
44
44
  "@rollup/plugin-terser": "^0.4.0",
45
45
  "@rollup/pluginutils": "^5.0.2",
46
46
  "@swc/core": "^1.3.62",
47
- "@zephyr3d/base": "^0.1.3",
47
+ "@zephyr3d/base": "^0.1.4",
48
48
  "cross-env": "^7.0.3",
49
49
  "rollup": "^3.15.0",
50
50
  "rollup-plugin-copy": "^3.4.0",
@@ -55,7 +55,7 @@
55
55
  "typescript": "^5.1.3"
56
56
  },
57
57
  "peerDependencies": {
58
- "@zephyr3d/base": "^0.1.3"
58
+ "@zephyr3d/base": "^0.1.4"
59
59
  },
60
60
  "dependencies": {
61
61
  "@types/node": "^18.13.0",