@footgun/cobalt 0.6.4 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -1,19 +1,32 @@
1
+ # 0.6.6
2
+ * add sdl + webgpu support for tile node
3
+
4
+
5
+ # 0.6.5
6
+ * add sdl + webgpu support for tile node
7
+
8
+
1
9
  # 0.6.4
2
10
  * add parameters for @kmamal/gpu v0.2.1
3
11
 
12
+
4
13
  # 0.6.3
5
14
  * add labels to all renderpass nodes
6
15
 
16
+
7
17
  # 0.6.2
8
18
  * use preferred canvas format in more places
9
19
 
20
+
10
21
  # 0.6.1
11
22
  * use preferred canvas format in more places
12
23
 
24
+
13
25
  # 0.6.0
14
26
  * use preferred canvas format in various places instead of hardcoding to bgra8unorm, which doesn't seem to work on linux
15
27
  because that defaults to bgra8unorm-srgb
16
28
 
29
+
17
30
  # 0.5.1
18
31
  * add labels to all render pipelines
19
32
 
package/bundle.js CHANGED
@@ -8222,10 +8222,16 @@ var tile_default = {
8222
8222
  // optional
8223
8223
  customFunctions: {
8224
8224
  setTexture: async function(cobalt, node, textureUrl) {
8225
- const { device } = cobalt;
8225
+ const { canvas, device } = cobalt;
8226
8226
  destroy3(node);
8227
- node.options.textureUrl = textureUrl;
8228
- const material = await createTextureFromUrl(cobalt, "tile map", node.options.textureUrl);
8227
+ const format = getPreferredFormat(cobalt);
8228
+ let material;
8229
+ if (canvas) {
8230
+ node.options.textureUrl = textureUrl;
8231
+ material = await createTextureFromUrl(cobalt, "tile map", node.options.textureUrl, format);
8232
+ } else {
8233
+ material = await createTextureFromBuffer(cobalt, "tile map", node.options.texture, format);
8234
+ }
8229
8235
  const bindGroup = device.createBindGroup({
8230
8236
  layout: node.refs.tileAtlas.data.tileBindGroupLayout,
8231
8237
  entries: [
@@ -14235,8 +14241,14 @@ var atlas_default = {
14235
14241
  }
14236
14242
  };
14237
14243
  async function init10(cobalt, nodeData) {
14238
- const { device } = cobalt;
14239
- const atlasMaterial = await createTextureFromUrl(cobalt, "tile atlas", nodeData.options.textureUrl);
14244
+ const { canvas, device } = cobalt;
14245
+ const format = getPreferredFormat(cobalt);
14246
+ let atlasMaterial;
14247
+ if (canvas) {
14248
+ atlasMaterial = await await createTextureFromUrl(cobalt, "tile atlas", nodeData.options.textureUrl, format);
14249
+ } else {
14250
+ atlasMaterial = await await createTextureFromBuffer(cobalt, "tile atlas", nodeData.options.texture, format);
14251
+ }
14240
14252
  const uniformBuffer = device.createBuffer({
14241
14253
  size: 32,
14242
14254
  //32 + (16 * 32), // in bytes. 32 for common data + (32 max tile layers * 16 bytes per tile layer)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@footgun/cobalt",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "type": "module",
5
5
  "main": "bundle.js",
6
6
  "description": "A 2D WebGpu renderer",
@@ -260,10 +260,3 @@ function destroy (node) {
260
260
  node.data.spriteIndices.clear()
261
261
  node.data.spriteIndices = null
262
262
  }
263
-
264
-
265
- async function fetchJson (url) {
266
- const raw = await fetch(url)
267
- return raw.json()
268
- }
269
-
package/src/tile/atlas.js CHANGED
@@ -1,5 +1,7 @@
1
- import createTextureFromUrl from '../create-texture-from-url.js'
2
- import tileWGSL from './tile.wgsl'
1
+ import createTextureFromBuffer from '../create-texture-from-buffer.js'
2
+ import createTextureFromUrl from '../create-texture-from-url.js'
3
+ import getPreferredFormat from '../get-preferred-format.js'
4
+ import tileWGSL from './tile.wgsl'
3
5
 
4
6
 
5
7
  const _buf = new Float32Array(8) //(136) // tile instance data stored in a UBO
@@ -37,9 +39,20 @@ export default {
37
39
 
38
40
 
39
41
  async function init (cobalt, nodeData) {
40
- const { device } = cobalt
42
+ const { canvas, device } = cobalt
41
43
 
42
- const atlasMaterial = await createTextureFromUrl(cobalt, 'tile atlas', nodeData.options.textureUrl)
44
+ const format = getPreferredFormat(cobalt)
45
+
46
+ let atlasMaterial
47
+
48
+ if (canvas) {
49
+ // browser (canvas) path
50
+ atlasMaterial = await await createTextureFromUrl(cobalt, 'tile atlas', nodeData.options.textureUrl, format)
51
+ }
52
+ else {
53
+ // sdl + gpu path
54
+ atlasMaterial = await await createTextureFromBuffer(cobalt, 'tile atlas', nodeData.options.texture, format)
55
+ }
43
56
 
44
57
  const uniformBuffer = device.createBuffer({
45
58
  size: 32, //32 + (16 * 32), // in bytes. 32 for common data + (32 max tile layers * 16 bytes per tile layer)
package/src/tile/tile.js CHANGED
@@ -1,4 +1,6 @@
1
- import createTextureFromUrl from '../create-texture-from-url.js'
1
+ import createTextureFromBuffer from '../create-texture-from-buffer.js'
2
+ import createTextureFromUrl from '../create-texture-from-url.js'
3
+ import getPreferredFormat from '../get-preferred-format.js'
2
4
 
3
5
 
4
6
  /*
@@ -47,11 +49,23 @@ export default {
47
49
  // optional
48
50
  customFunctions: {
49
51
  setTexture: async function (cobalt, node, textureUrl) {
50
- const { device } = cobalt
52
+ const { canvas, device } = cobalt
51
53
 
52
54
  destroy(node)
53
- node.options.textureUrl = textureUrl
54
- const material = await createTextureFromUrl(cobalt, 'tile map', node.options.textureUrl)
55
+
56
+ const format = getPreferredFormat(cobalt)
57
+
58
+ let material
59
+
60
+ if (canvas) {
61
+ // browser (canvas) path
62
+ node.options.textureUrl = textureUrl
63
+ material = await createTextureFromUrl(cobalt, 'tile map', node.options.textureUrl, format)
64
+ }
65
+ else {
66
+ // sdl + gpu path
67
+ material = await createTextureFromBuffer(cobalt, 'tile map', node.options.texture, format)
68
+ }
55
69
 
56
70
  const bindGroup = device.createBindGroup({
57
71
  layout: node.refs.tileAtlas.data.tileBindGroupLayout,