@footgun/cobalt 0.6.3 → 0.6.5

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,16 +1,28 @@
1
+ # 0.6.5
2
+ * add sdl + webgpu support for tile node
3
+
4
+
5
+ # 0.6.4
6
+ * add parameters for @kmamal/gpu v0.2.1
7
+
8
+
1
9
  # 0.6.3
2
10
  * add labels to all renderpass nodes
3
- :
11
+
12
+
4
13
  # 0.6.2
5
14
  * use preferred canvas format in more places
6
15
 
16
+
7
17
  # 0.6.1
8
18
  * use preferred canvas format in more places
9
19
 
20
+
10
21
  # 0.6.0
11
22
  * use preferred canvas format in various places instead of hardcoding to bgra8unorm, which doesn't seem to work on linux
12
23
  because that defaults to bgra8unorm-srgb
13
24
 
25
+
14
26
  # 0.5.1
15
27
  * add labels to all render pipelines
16
28
 
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 createTextureFromUrl(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)
@@ -14613,9 +14625,11 @@ async function init13(ctx, viewportWidth, viewportHeight) {
14613
14625
  let device, gpu, context, canvas;
14614
14626
  if (ctx.sdlWindow && ctx.gpu) {
14615
14627
  gpu = ctx.gpu;
14616
- const instance = gpu.create(["verbose=1"]);
14628
+ const instance = gpu.create(["verbose=1", "enable-dawn-features=allow_unsafe_apis"]);
14617
14629
  const adapter = await instance.requestAdapter();
14618
- device = await adapter.requestDevice();
14630
+ device = await adapter.requestDevice({
14631
+ requiredFeatures: ["texture-component-swizzle"]
14632
+ });
14619
14633
  context = gpu.renderGPUDeviceToWindow({ device, window: ctx.sdlWindow });
14620
14634
  global.GPUBufferUsage = gpu.GPUBufferUsage;
14621
14635
  global.GPUShaderStage = gpu.GPUShaderStage;
@@ -11,7 +11,7 @@
11
11
  "author": "",
12
12
  "license": "ISC",
13
13
  "dependencies": {
14
- "@kmamal/gpu": "0.2.0",
14
+ "@kmamal/gpu": "^0.2.0",
15
15
  "@kmamal/sdl": "^0.11.7",
16
16
  "pngjs": "^7.0.0",
17
17
  "wgpu-matrix": "^3.4.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@footgun/cobalt",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "type": "module",
5
5
  "main": "bundle.js",
6
6
  "description": "A 2D WebGpu renderer",
package/src/cobalt.js CHANGED
@@ -31,9 +31,11 @@ export async function init (ctx, viewportWidth, viewportHeight) {
31
31
  // this is an sdl/gpu context
32
32
  gpu = ctx.gpu
33
33
 
34
- const instance = gpu.create([ 'verbose=1' ])
34
+ const instance = gpu.create([ 'verbose=1', 'enable-dawn-features=allow_unsafe_apis' ])
35
35
  const adapter = await instance.requestAdapter()
36
- device = await adapter.requestDevice()
36
+ device = await adapter.requestDevice({
37
+ requiredFeatures: [ 'texture-component-swizzle' ],
38
+ })
37
39
  context = gpu.renderGPUDeviceToWindow({ device, window: ctx.sdlWindow })
38
40
 
39
41
  // gpu module doesn't expose these globals to node namespace so manually wire them up
@@ -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 createTextureFromUrl(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,