glre 0.22.0 → 0.24.0

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.
Files changed (50) hide show
  1. package/README.md +19 -28
  2. package/dist/index.d.ts +49 -222
  3. package/dist/index.js +43 -37
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +43 -37
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/native.d.ts +49 -5
  8. package/dist/native.js +43 -37
  9. package/dist/native.js.map +1 -1
  10. package/dist/native.mjs +43 -37
  11. package/dist/native.mjs.map +1 -1
  12. package/dist/react.d.ts +1 -2
  13. package/dist/react.js +43 -37
  14. package/dist/react.js.map +1 -1
  15. package/dist/react.mjs +43 -37
  16. package/dist/react.mjs.map +1 -1
  17. package/dist/solid.d.ts +1 -2
  18. package/dist/solid.js +43 -37
  19. package/dist/solid.js.map +1 -1
  20. package/dist/solid.mjs +43 -37
  21. package/dist/solid.mjs.map +1 -1
  22. package/package.json +5 -1
  23. package/src/code/glsl.ts +7 -45
  24. package/src/code/wgsl.ts +10 -46
  25. package/src/index.ts +34 -35
  26. package/src/native.ts +9 -4
  27. package/src/node/cache.ts +3 -10
  28. package/src/node/const.ts +2 -19
  29. package/src/node/conv.ts +6 -17
  30. package/src/node/index.ts +5 -8
  31. package/src/node/node.ts +8 -22
  32. package/src/node/uniform.ts +6 -13
  33. package/src/react.ts +0 -1
  34. package/src/solid.ts +0 -1
  35. package/src/types.ts +21 -21
  36. package/src/{utils.ts → utils/helpers.ts} +0 -9
  37. package/src/utils/pipeline.ts +124 -0
  38. package/src/utils/program.ts +94 -0
  39. package/src/webgl.ts +77 -0
  40. package/src/webgpu.ts +102 -0
  41. package/src/webgl/buffer.ts +0 -78
  42. package/src/webgl/index.ts +0 -79
  43. package/src/webgl/program.ts +0 -61
  44. package/src/webgl/shader.ts +0 -60
  45. package/src/webgl/texture.ts +0 -93
  46. package/src/webgpu/buffer.ts +0 -96
  47. package/src/webgpu/device.ts +0 -91
  48. package/src/webgpu/index.ts +0 -40
  49. package/src/webgpu/pipeline.ts +0 -94
  50. package/src/webgpu/texture.ts +0 -139
package/src/code/wgsl.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { is } from '../utils'
1
+ import { is } from '../utils/helpers'
2
2
  import type { Node, NodeType, ConversionContext, X } from '../node'
3
3
 
4
4
  // WGSLコード生成コンテキスト
@@ -7,10 +7,7 @@ interface WGSLContext extends ConversionContext {
7
7
  }
8
8
 
9
9
  // ノードからWGSLコードを生成
10
- export const nodeToWGSL = (
11
- nodeProxy: X,
12
- context?: Partial<WGSLContext>
13
- ): string => {
10
+ export const nodeToWGSL = (nodeProxy: X, context?: Partial<WGSLContext>): string => {
14
11
  const ctx: WGSLContext = {
15
12
  target: 'webgpu',
16
13
  nodes: new Map(),
@@ -25,16 +22,14 @@ export const nodeToWGSL = (
25
22
  const generateWGSLExpression = (node: Node, context: WGSLContext): string => {
26
23
  if (!node) return '0.0'
27
24
  // 値ノード
28
- if (node.value !== undefined)
29
- return formatWGSLValue(node.value, node.type)
25
+ if (node.value !== undefined) return formatWGSLValue(node.value, node.type)
30
26
  // プロパティアクセス(スウィズル)
31
27
  if (node.property && node.parent) {
32
28
  const parentExpr = generateWGSLExpression(node.parent, context)
33
29
  return `${parentExpr}.${node.property}`
34
30
  }
35
31
  // 演算子ノード
36
- if (node.operator && node.children && node.children.length >= 2)
37
- return generateWGSLOperator(node, context)
32
+ if (node.operator && node.children && node.children.length >= 2) return generateWGSLOperator(node, context)
38
33
  // 数学関数ノード
39
34
  if (node.mathFunction && node.children && node.children.length >= 1)
40
35
  return generateWGSLMathFunction(node, context)
@@ -90,44 +85,13 @@ const generateWGSLOperator = (node: Node, context: WGSLContext): string => {
90
85
  const generateWGSLMathFunction = (node: Node, context: WGSLContext): string => {
91
86
  if (!node.children || node.children.length < 1) return '0.0'
92
87
  const fun = node.mathFunction
93
- const args = node.children.map((child) =>
94
- generateWGSLExpression(child, context)
95
- )
88
+ const args = node.children.map((child) => generateWGSLExpression(child, context))
96
89
  const [x, y, z] = args
97
- // 単項関数
98
- if (args.length === 1) {
99
- if (fun === 'abs') return `abs(${x})`
100
- if (fun === 'acos') return `acos(${x})`
101
- if (fun === 'asin') return `asin(${x})`
102
- if (fun === 'atan') return `atan(${x})`
103
- if (fun === 'ceil') return `ceil(${x})`
104
- if (fun === 'cos') return `cos(${x})`
105
- if (fun === 'floor') return `floor(${x})`
106
- if (fun === 'fract') return `fract(${x})`
107
- if (fun === 'length') return `length(${x})`
108
- if (fun === 'normalize') return `normalize(${x})`
109
- if (fun === 'sin') return `sin(${x})`
110
- if (fun === 'sqrt') return `sqrt(${x})`
111
- if (fun === 'tan') return `tan(${x})`
112
- }
113
- // 二項関数
114
- if (args.length === 2) {
115
- if (fun === 'atan2') return `atan2(${x}, ${y})`
116
- if (fun === 'pow') return `pow(${x}, ${y})`
117
- if (fun === 'min') return `min(${x}, ${y})`
118
- if (fun === 'max') return `max(${x}, ${y})`
119
- if (fun === 'dot') return `dot(${x}, ${y})`
120
- if (fun === 'cross') return `cross(${x}, ${y})`
121
- if (fun === 'distance') return `distance(${x}, ${y})`
122
- if (fun === 'reflect') return `reflect(${x}, ${y})`
123
- }
124
- // 三項関数
125
- if (args.length === 3) {
126
- if (fun === 'mix') return `mix(${x}, ${y}, ${z})`
127
- if (fun === 'clamp') return `clamp(${x}, ${y}, ${z})`
128
- if (fun === 'smoothstep') return `smoothstep(${x}, ${y}, ${z})`
129
- return x
130
- }
90
+ // @TODO FIX
91
+ // if (fun === 'toVar') return x // toVarは変数化のヒントなので、そのまま返す
92
+ if (args.length === 1) return `${fun}(${x})`
93
+ if (args.length === 2) return `${fun}(${x}, ${y})`
94
+ if (args.length === 3) return `${fun}(${x}, ${y}, ${z})`
131
95
  return x || '0.0'
132
96
  }
133
97
 
package/src/index.ts CHANGED
@@ -1,27 +1,35 @@
1
1
  import { durable, event } from 'reev'
2
2
  import { createFrame, createQueue } from 'refr'
3
- import { webgl } from './webgl/index'
4
- import { webgpu } from './webgpu/index'
5
- import { is, isWebGPUSupported } from './utils'
3
+ import { webgl } from './webgl'
4
+ import { webgpu } from './webgpu'
5
+ import { is } from './utils/helpers'
6
6
  import type { EventState } from 'reev'
7
7
  import type { GL } from './types'
8
8
  export * from './code/glsl'
9
9
  export * from './code/wgsl'
10
10
  export * from './node'
11
11
  export * from './types'
12
- export * from './utils'
12
+ export * from './utils/helpers'
13
+ export * from './utils/pipeline'
14
+ export * from './utils/program'
13
15
  export * from './webgl'
14
16
  export * from './webgpu'
15
17
 
16
- let iTime = performance.now(),
17
- iPrevTime = 0,
18
- iDeltaTime = 0
19
-
20
18
  export const isGL = (a: unknown): a is EventState<GL> => {
21
19
  if (!is.obj(a)) return false
22
20
  if ('isGL' in a) return true
23
21
  return false
24
22
  }
23
+ export const isServer = () => {
24
+ return typeof window === 'undefined'
25
+ }
26
+
27
+ export const isWebGPUSupported = () => {
28
+ if (isServer()) return false
29
+ return 'gpu' in navigator
30
+ }
31
+
32
+ let iTime = performance.now()
25
33
 
26
34
  export const createGL = (props?: Partial<GL>) => {
27
35
  const gl = event<Partial<GL>>({
@@ -31,19 +39,28 @@ export const createGL = (props?: Partial<GL>) => {
31
39
  isGL: true,
32
40
  size: [0, 0],
33
41
  mouse: [0, 0],
34
- count: 6,
35
- counter: 0,
42
+ count: 3,
43
+ webgl: {},
44
+ webgpu: {},
36
45
  }) as EventState<GL>
37
46
 
38
- gl('mount', () => {
47
+ gl.queue = createQueue()
48
+ gl.frame = createFrame()
49
+
50
+ gl.attribute = durable((k, v, i) => gl.queue(() => gl._attribute?.(k, v, i)))
51
+ gl.texture = durable((k, v) => gl.queue(() => gl._texture?.(k, v)))
52
+ gl.uniform = durable((k, v, i) => gl.queue(() => gl._uniform?.(k, v, i)))
53
+ gl.uniform({ iResolution: gl.size, iMouse: [0, 0], iTime: 0 }) // default uniform
54
+
55
+ gl('mount', async () => {
39
56
  if (!isWebGPUSupported()) gl.isWebGL = true
40
57
  if (gl.isWebGL) {
41
- webgl(gl)
42
- } else webgpu(gl)
43
- gl.init()
58
+ await webgl(gl)
59
+ } else await webgpu(gl)
44
60
  gl.resize()
45
61
  gl.frame(() => {
46
62
  gl.loop()
63
+ gl.queue.flush()
47
64
  gl.render()
48
65
  return gl.isLoop
49
66
  })
@@ -60,14 +77,6 @@ export const createGL = (props?: Partial<GL>) => {
60
77
  gl.el.removeEventListener('mousemove', gl.mousemove)
61
78
  })
62
79
 
63
- gl('loop', () => {
64
- iPrevTime = iTime
65
- iTime = performance.now() / 1000
66
- iDeltaTime = iTime - iPrevTime
67
- gl.uniform({ iPrevTime, iTime, iDeltaTime })
68
- // if (gl.fragmentNode) updateUniforms({ time: iTime }) // @TODO FIX
69
- })
70
-
71
80
  gl('resize', () => {
72
81
  const w = gl.width || window.innerWidth
73
82
  const h = gl.height || window.innerHeight
@@ -84,19 +93,9 @@ export const createGL = (props?: Partial<GL>) => {
84
93
  gl.uniform('iMouse', gl.mouse)
85
94
  })
86
95
 
87
- gl.queue = createQueue()
88
- gl.frame = createFrame()
89
-
90
- gl.attribute = durable((key, value, iboValue) => {
91
- gl.queue(() => void gl._attribute?.(key, value, iboValue))
92
- })
93
-
94
- gl.uniform = durable((key, value, isMatrix) => {
95
- gl.queue(() => void gl._uniform?.(key, value, isMatrix))
96
- })
97
-
98
- gl.texture = durable((key, value) => {
99
- gl.queue(() => void gl._texture?.(key, value))
96
+ gl('loop', () => {
97
+ iTime = performance.now() / 1000
98
+ gl.uniform('iTime', iTime)
100
99
  })
101
100
 
102
101
  return gl(props)
package/src/native.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { useState } from 'react'
1
+ import { useState } from 'react' // @ts-ignore
2
2
  import { Dimensions } from 'react-native'
3
3
  import { createGL, isGL } from './index'
4
4
  import type { GL } from './types'
@@ -8,8 +8,13 @@ export const useGL = (props: Partial<GL> = {}) => {
8
8
  return useState(() => {
9
9
  const gl = isGL(props) ? props : createGL(props)
10
10
  gl.ref = (ctx: any) => {
11
- gl.el = {}
12
- gl.gl = ctx
11
+ gl.el = {} as any
12
+ gl({
13
+ render() {
14
+ ctx.flush()
15
+ ctx.endFrameEXP()
16
+ },
17
+ })
13
18
  gl.mount()
14
19
  const resize = () => {
15
20
  gl.width = ctx.drawingBufferWidth
@@ -19,6 +24,6 @@ export const useGL = (props: Partial<GL> = {}) => {
19
24
  resize()
20
25
  Dimensions.addEventListener('change', resize)
21
26
  }
22
- return gl
27
+ return gl({ isNative: true })
23
28
  })[0]
24
29
  }
package/src/node/cache.ts CHANGED
@@ -43,10 +43,7 @@ export const findDuplicateNodes = (nodes: X[]): Map<string, X[]> => {
43
43
  nodes.forEach((nodeProxy) => {
44
44
  const signature = generateNodeSignature(nodeProxy)
45
45
  if (signatures.has(signature)) {
46
- if (!duplicates.has(signature))
47
- duplicates.set(signature, [
48
- signatures.get(signature)!,
49
- ])
46
+ if (!duplicates.has(signature)) duplicates.set(signature, [signatures.get(signature)!])
50
47
  duplicates.get(signature)!.push(nodeProxy)
51
48
  } else signatures.set(signature, nodeProxy)
52
49
  })
@@ -55,13 +52,9 @@ export const findDuplicateNodes = (nodes: X[]): Map<string, X[]> => {
55
52
 
56
53
  // ノードのシグネチャを生成
57
54
  const generateNodeSignature = (nodeProxy: X): string => {
58
- const parts = [
59
- nodeProxy.type,
60
- `${nodeProxy.value}`,
61
- nodeProxy.property || '',
62
- ]
55
+ const parts = [nodeProxy.type, `${nodeProxy.value}`, nodeProxy.property || '']
63
56
  return parts.join('|')
64
57
  }
65
58
 
66
59
  // 初期化を実行
67
- initializeCache()
60
+ // initializeCache()
package/src/node/const.ts CHANGED
@@ -25,26 +25,9 @@ export const TYPES = [
25
25
  export type NodeType = (typeof TYPES)[number]
26
26
 
27
27
  // スウィズル定数
28
- export const SWIZZLES = [
29
- 'x',
30
- 'y',
31
- 'z',
32
- 'w',
33
- 'r',
34
- 'g',
35
- 'b',
36
- 'a',
37
- 's',
38
- 't',
39
- 'p',
40
- 'q',
41
- ] as const
28
+ export const SWIZZLES = ['x', 'y', 'z', 'w', 'r', 'g', 'b', 'a', 's', 't', 'p', 'q'] as const
42
29
 
43
- type AllSwizzles<T extends string> =
44
- | T
45
- | `${T}${T}`
46
- | `${T}${T}${T}`
47
- | `${T}${T}${T}${T}`
30
+ type AllSwizzles<T extends string> = T | `${T}${T}` | `${T}${T}${T}` | `${T}${T}${T}${T}`
48
31
 
49
32
  export type Swillzes =
50
33
  | AllSwizzles<'x' | 'y' | 'z' | 'w'>
package/src/node/conv.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { node } from '.'
2
2
  import { getCachedBool, getCachedInt, getCachedFloat } from './cache'
3
- import { is } from '../utils'
3
+ import { is } from '../utils/helpers'
4
4
  import type { X } from './types'
5
5
 
6
6
  // JavaScript値をノードに変換
@@ -63,8 +63,7 @@ export const vec2 = (x?: any, y?: any): X => {
63
63
  if (is.und(x)) return node('vec2', [0, 0])
64
64
  if (is.und(y)) {
65
65
  if (is.arr(x)) return node('vec2', x.slice(0, 2))
66
- if (is.obj(x) && 'x' in x && 'y' in x)
67
- return node('vec2', [x.x, x.y])
66
+ if (is.obj(x) && 'x' in x && 'y' in x) return node('vec2', [x.x, x.y])
68
67
  return node('vec2', [Number(x), Number(x)])
69
68
  }
70
69
  return node('vec2', [Number(x), Number(y)])
@@ -74,8 +73,7 @@ export const vec3 = (x?: any, y?: any, z?: any): X => {
74
73
  if (is.und(x)) return node('vec3', [0, 0, 0])
75
74
  if (is.und(y)) {
76
75
  if (is.arr(x)) return node('vec3', x.slice(0, 3))
77
- if (is.obj(x) && 'x' in x && 'y' in x && 'z' in x)
78
- return node('vec3', [x.x, x.y, x.z])
76
+ if (is.obj(x) && 'x' in x && 'y' in x && 'z' in x) return node('vec3', [x.x, x.y, x.z])
79
77
  return node('vec3', [Number(x), Number(x), Number(x)])
80
78
  }
81
79
  if (z === undefined) {
@@ -88,8 +86,7 @@ export const vec4 = (x?: any, y?: any, z?: any, w?: any): X => {
88
86
  if (is.und(x)) return node('vec4', [0, 0, 0, 1])
89
87
  if (is.und(y)) {
90
88
  if (is.arr(x)) return node('vec4', x.slice(0, 4))
91
- if (is.obj(x) && 'x' in x && 'y' in x && 'z' in x && 'w' in x)
92
- return node('vec4', [x.x, x.y, x.z, x.w])
89
+ if (is.obj(x) && 'x' in x && 'y' in x && 'z' in x && 'w' in x) return node('vec4', [x.x, x.y, x.z, x.w])
93
90
  return node('vec4', [Number(x), Number(x), Number(x), 1])
94
91
  }
95
92
  return node('vec4', [Number(x), Number(y), Number(z), Number(w)])
@@ -102,20 +99,12 @@ export const color = (r?: any, g?: any, b?: any): X => {
102
99
  if (is.str(r) && r.startsWith('#')) {
103
100
  const hex = r.slice(1)
104
101
  const num = parseInt(hex, 16)
105
- return node('color', [
106
- ((num >> 16) & 255) / 255,
107
- ((num >> 8) & 255) / 255,
108
- (num & 255) / 255,
109
- ])
102
+ return node('color', [((num >> 16) & 255) / 255, ((num >> 8) & 255) / 255, (num & 255) / 255])
110
103
  }
111
104
 
112
105
  // 数値カラーの処理
113
106
  if (is.num(r) && g === undefined && b === undefined) {
114
- return node('color', [
115
- ((r >> 16) & 255) / 255,
116
- ((r >> 8) & 255) / 255,
117
- (r & 255) / 255,
118
- ])
107
+ return node('color', [((r >> 16) & 255) / 255, ((r >> 8) & 255) / 255, (r & 255) / 255])
119
108
  }
120
109
 
121
110
  return vec3(r, g, b)
package/src/node/index.ts CHANGED
@@ -1,7 +1,7 @@
1
+ import { float } from './conv'
1
2
  import { node } from './node'
2
3
  import { uniform } from './uniform'
3
- import { float } from './conv'
4
- import { is } from '../utils'
4
+ import { is } from '../utils/helpers'
5
5
  import type { X, FunctionNode, ConditionalNode } from './types'
6
6
  export type { X, FunctionNode, ConditionalNode }
7
7
  export * from './cache'
@@ -30,10 +30,7 @@ export const If = (condition: X, callback: () => void): ConditionalNode => {
30
30
  callback()
31
31
 
32
32
  const conditionalNode = {
33
- ElseIf(
34
- newCondition: X,
35
- newCallback: () => void
36
- ): ConditionalNode {
33
+ ElseIf(newCondition: X, newCallback: () => void): ConditionalNode {
37
34
  newCallback()
38
35
  return conditionalNode
39
36
  },
@@ -46,8 +43,8 @@ export const If = (condition: X, callback: () => void): ConditionalNode => {
46
43
  }
47
44
 
48
45
  // 組み込み変数
49
- export const gl_FragCoord = node('vec4', undefined)
50
- export const gl_Position = node('vec4', undefined)
46
+ export const fragCoord = node('vec4', undefined)
47
+ export const position = node('vec4', undefined)
51
48
  export const iTime = uniform(0.0)
52
49
  export const iResolution = uniform([1920, 1080])
53
50
  export const iMouse = uniform([0, 0])
package/src/node/node.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { OPERATORS, FUNCTIONS, SWIZZLES, NodeType } from './const'
2
- import { is } from '../utils'
1
+ import { OPERATORS, FUNCTIONS, SWIZZLES } from './const'
2
+ import { is } from '../utils/helpers'
3
+ import type { NodeType } from './const'
3
4
  import type { Node, ProxyCallback, X } from './types'
4
5
 
5
6
  let nodeIdCounter = 0
@@ -8,11 +9,7 @@ let nodeIdCounter = 0
8
9
  const generateNodeId = () => `node_${++nodeIdCounter}`
9
10
 
10
11
  // ノードを作成
11
- export const createNode = (
12
- type: NodeType,
13
- value?: any,
14
- options?: Partial<Node>
15
- ): Node => {
12
+ export const createNode = (type: NodeType, value?: any, options?: Partial<Node>): Node => {
16
13
  return {
17
14
  id: generateNodeId(),
18
15
  type,
@@ -62,21 +59,10 @@ const createNodeProxy = (node: Node, callback?: (info: ProxyCallback) => X) => {
62
59
  if (isMathMethod(key))
63
60
  return (...args: any[]) => {
64
61
  return createNodeProxy(
65
- createNode(
66
- getMathReturnType(
67
- key,
68
- node.type
69
- ),
70
- undefined,
71
- {
72
- mathFunction:
73
- key as any,
74
- children: [
75
- node,
76
- ...args,
77
- ],
78
- }
79
- ),
62
+ createNode(getMathReturnType(key, node.type), undefined, {
63
+ mathFunction: key as any,
64
+ children: [node, ...args],
65
+ }),
80
66
  callback
81
67
  )
82
68
  }
@@ -1,5 +1,5 @@
1
1
  import { node } from './node'
2
- import { is } from '../utils'
2
+ import { is } from '../utils/helpers'
3
3
  import type { UniformNode } from './types'
4
4
  import type { NodeType } from './const'
5
5
 
@@ -24,8 +24,7 @@ const inferUniformType = (value: any): NodeType => {
24
24
  if (len === 9) return 'mat3'
25
25
  if (len === 16) return 'mat4'
26
26
  }
27
- if (is.obj(value) && 'r' in value && 'g' in value && 'b' in value)
28
- return 'color'
27
+ if (is.obj(value) && 'r' in value && 'g' in value && 'b' in value) return 'color'
29
28
  return 'float'
30
29
  }
31
30
 
@@ -33,10 +32,8 @@ const inferUniformType = (value: any): NodeType => {
33
32
  export const uniform = (initialValue: any): UniformNode => {
34
33
  const type = inferUniformType(initialValue)
35
34
  let currentValue = initialValue
36
- let objectUpdateCallback: ((context: UpdateContext) => any) | null =
37
- null
38
- let renderUpdateCallback: ((context: UpdateContext) => any) | null =
39
- null
35
+ let objectUpdateCallback: ((context: UpdateContext) => any) | null = null
36
+ let renderUpdateCallback: ((context: UpdateContext) => any) | null = null
40
37
 
41
38
  const baseNode = node(type, currentValue) as any
42
39
 
@@ -46,16 +43,12 @@ export const uniform = (initialValue: any): UniformNode => {
46
43
  baseNode.value = value
47
44
  }
48
45
  // オブジェクト更新時のコールバックを設定
49
- const onObjectUpdate = (
50
- callback: (context: UpdateContext) => any
51
- ): UniformNode => {
46
+ const onObjectUpdate = (callback: (context: UpdateContext) => any): UniformNode => {
52
47
  objectUpdateCallback = callback
53
48
  return uniformNode
54
49
  }
55
50
  // レンダー更新時のコールバックを設定
56
- const onRenderUpdate = (
57
- callback: (context: UpdateContext) => any
58
- ): UniformNode => {
51
+ const onRenderUpdate = (callback: (context: UpdateContext) => any): UniformNode => {
59
52
  renderUpdateCallback = callback
60
53
  return uniformNode
61
54
  }
package/src/react.ts CHANGED
@@ -9,7 +9,6 @@ export const useGL = (props: Partial<GL> = {}) => {
9
9
  gl.ref = (el: HTMLCanvasElement | null) => {
10
10
  if (el) {
11
11
  gl.el = el
12
- gl.gl = el.getContext('webgl2')
13
12
  gl.mount()
14
13
  } else gl.clean()
15
14
  }
package/src/solid.ts CHANGED
@@ -7,7 +7,6 @@ export const onGL = (props?: Partial<GL>) => {
7
7
  gl.ref = (el: HTMLCanvasElement | null) => {
8
8
  if (el) {
9
9
  gl.el = el
10
- gl.gl = el.getContext('webgl2')
11
10
  gl.mount()
12
11
  } else gl.clean()
13
12
  }
package/src/types.ts CHANGED
@@ -1,15 +1,19 @@
1
- import { Nested, EventState } from 'reev'
2
- import { X } from './node'
1
+ import { EventState } from 'reev'
3
2
  import type { Fun, Queue, Frame } from 'refr'
3
+ import type { X } from './node'
4
4
  export type { Fun, Queue, Frame }
5
+ export type GPUContext = any // GPUCanvasContext https://developer.mozilla.org/en-US/docs/Web/API/GPUCanvasContext
6
+ export type GPUDevice = any //
7
+ export type GPUBuffer = any //
8
+ export type GPUPipeline = any //
9
+ export type GPUBindGroup = any
5
10
  export type Uniform = number | number[]
6
11
  export type Attribute = number[]
7
12
  export type Attributes = Record<string, Attribute>
8
13
  export type Uniforms = Record<string, Uniform>
9
14
  export type PrecisionMode = 'highp' | 'mediump' | 'lowp'
10
-
11
15
  export type GLClearMode = 'COLOR_BUFFER_BIT' | 'DEPTH_BUFFER_BIT' | 'STENCIL_BUFFER_BIT'
12
-
16
+ export type GLDrawType = 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT' | 'UNSIGNED_INT'
13
17
  export type GLDrawMode =
14
18
  | 'POINTS'
15
19
  | 'LINE_STRIP'
@@ -19,7 +23,16 @@ export type GLDrawMode =
19
23
  | 'TRIANGLE_FAN'
20
24
  | 'TRIANGLES'
21
25
 
22
- export type GLDrawType = 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT' | 'UNSIGNED_INT'
26
+ export interface WebGLState {
27
+ context: WebGLRenderingContext
28
+ program: WebGLProgram
29
+ }
30
+
31
+ export interface WebGPUState {
32
+ device: GPUDevice
33
+ context: GPUContext
34
+ pipeline: GPUPipeline
35
+ }
23
36
 
24
37
  export type GL = EventState<{
25
38
  /**
@@ -34,6 +47,7 @@ export type GL = EventState<{
34
47
  size: [number, number]
35
48
  mouse: [number, number]
36
49
  count: number
50
+ el: HTMLCanvasElement
37
51
  vs: string | X
38
52
  fs: string | X
39
53
  vert: string | X
@@ -41,27 +55,13 @@ export type GL = EventState<{
41
55
  vertex: string | X
42
56
  fragment: string | X
43
57
 
44
- /**
45
- * for webgl
46
- */
47
- int: PrecisionMode
48
- float: PrecisionMode
49
- sampler2D: PrecisionMode
50
- samplerCube: PrecisionMode
51
- lastActiveUnit: number
52
-
53
58
  /**
54
59
  * core state
55
60
  */
56
- gl: any
57
- pg: any
58
- el: any
61
+ webgpu: WebGPUState
62
+ webgl: WebGLState
59
63
  queue: Queue
60
64
  frame: Frame
61
- stride: Nested<number>
62
- location: Nested<any> // @TODO Nested<(key: string, value: number: number[], ibo: number[]) => number>
63
- activeUnit: Nested<number>
64
- default: any
65
65
 
66
66
  /**
67
67
  * events
@@ -13,15 +13,6 @@ export const is = {
13
13
  nan: (a: unknown): a is number => typeof a === 'number' && Number.isNaN(a),
14
14
  }
15
15
 
16
- export const isServer = () => {
17
- return typeof window === 'undefined'
18
- }
19
-
20
- export const isWebGPUSupported = () => {
21
- if (isServer()) return false
22
- return 'gpu' in navigator
23
- }
24
-
25
16
  /**
26
17
  * each
27
18
  */