glre 0.16.0 → 0.18.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.
- package/dist/index.d.ts +9 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +15 -0
- package/dist/index.mjs.map +1 -0
- package/dist/native.d.ts +66 -0
- package/dist/native.js +15 -0
- package/dist/native.js.map +1 -0
- package/dist/native.mjs +15 -0
- package/dist/native.mjs.map +1 -0
- package/dist/react.d.ts +66 -0
- package/dist/react.js +15 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +15 -0
- package/dist/react.mjs.map +1 -0
- package/dist/solid.d.ts +65 -0
- package/dist/solid.js +15 -0
- package/dist/solid.js.map +1 -0
- package/dist/solid.mjs +15 -0
- package/dist/solid.mjs.map +1 -0
- package/dist/types-20446758.d.ts +78 -0
- package/index.ts +143 -112
- package/native.ts +4 -4
- package/package.json +120 -22
- package/qwik.ts +6 -6
- package/react.ts +8 -15
- package/solid.ts +7 -6
- package/test/index.test.ts +5 -0
- package/test/utils.test.ts +43 -0
- package/tsup.config.ts +16 -0
- package/types.ts +0 -3
- package/utils.ts +16 -16
- package/index.cjs.js +0 -1
- package/index.develop.js +0 -1
- package/index.js +0 -1
package/index.ts
CHANGED
|
@@ -36,6 +36,84 @@ let iTime = performance.now(),
|
|
|
36
36
|
iDeltaTime = 0
|
|
37
37
|
|
|
38
38
|
export const createGL = (props?: Partial<GL>) => {
|
|
39
|
+
const init = () => {
|
|
40
|
+
self(props)
|
|
41
|
+
const gl = self.gl
|
|
42
|
+
const _v = self.vs || self.vert || self.vertex
|
|
43
|
+
const _f = self.fs || self.frag || self.fragment
|
|
44
|
+
const vs = createShader(gl, _v, gl.VERTEX_SHADER)
|
|
45
|
+
const fs = createShader(gl, _f, gl.FRAGMENT_SHADER)
|
|
46
|
+
if (self.count === 6) self.attribute({ a_position })
|
|
47
|
+
frame(() => void self.render() || 1)
|
|
48
|
+
self.pg = self.varying
|
|
49
|
+
? createTfProgram(gl, vs, fs, self.varying)
|
|
50
|
+
: createProgram(gl, vs, fs)
|
|
51
|
+
self.lastActiveUnit = 0
|
|
52
|
+
self.activeUnit = nested(() => self.lastActiveUnit++)
|
|
53
|
+
self.location = nested((key, isAttribute = false) => {
|
|
54
|
+
return isAttribute
|
|
55
|
+
? gl?.getAttribLocation(self.pg, key)
|
|
56
|
+
: gl?.getUniformLocation(self.pg, key)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const render = () => {
|
|
61
|
+
self.gl.useProgram(self.pg)
|
|
62
|
+
self.frame.flush()
|
|
63
|
+
iPrevTime = iTime
|
|
64
|
+
iTime = performance.now() / 1000
|
|
65
|
+
iDeltaTime = iTime - iPrevTime
|
|
66
|
+
self.uniform({ iTime, iPrevTime, iDeltaTime })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const resize = (
|
|
70
|
+
_e: any,
|
|
71
|
+
width = self.width || window.innerWidth,
|
|
72
|
+
height = self.height || window.innerHeight
|
|
73
|
+
) => {
|
|
74
|
+
self.size[0] = self.el.width = width
|
|
75
|
+
self.size[1] = self.el.height = height
|
|
76
|
+
self.uniform('iResolution', self.size)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const mousemove = (_e: any, x = _e.clientX, y = _e.clientY) => {
|
|
80
|
+
const [w, h] = self.size
|
|
81
|
+
const { top, left } = self.el.getBoundingClientRect()
|
|
82
|
+
self.mouse[0] = (x - top - w / 2) / (w / 2)
|
|
83
|
+
self.mouse[1] = -(y - left - h / 2) / (h / 2)
|
|
84
|
+
self.uniform('iMouse', self.mouse)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const load = (_: any, image: any) => {
|
|
88
|
+
self.frame(() => {
|
|
89
|
+
const loc = self.location(image.alt)
|
|
90
|
+
const unit = self.activeUnit(image.alt)
|
|
91
|
+
const tex = createTexture(self.gl, image)
|
|
92
|
+
self.frame(() => {
|
|
93
|
+
activeTexture(self.gl, loc, unit, tex)
|
|
94
|
+
return true
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const clear = (key = 'COLOR_BUFFER_BIT') => {
|
|
100
|
+
self.gl.clear(self.gl[key])
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const viewport = (size: number[] = self.size) => {
|
|
104
|
+
self.gl.viewport(0, 0, ...size)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const drawArrays = (mode = 'TRIANGLES') => {
|
|
108
|
+
self.gl.drawArrays(self.gl[mode], 0, self.count)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const drawElements = (mode = 'TRIANGLES', type = 'UNSIGNED_SHORT') => {
|
|
112
|
+
mode = self.gl[mode]
|
|
113
|
+
type = self.gl[type]
|
|
114
|
+
self.gl.drawElements(mode, self.count, type, 0)
|
|
115
|
+
}
|
|
116
|
+
|
|
39
117
|
const self = event<Partial<GL>>({
|
|
40
118
|
vertex: _defaultVertex,
|
|
41
119
|
fragment: _defaultFragment,
|
|
@@ -43,106 +121,57 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
43
121
|
mouse: [0, 0],
|
|
44
122
|
count: 6,
|
|
45
123
|
counter: 0,
|
|
46
|
-
init
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
self.pg = self.varying
|
|
56
|
-
? createTfProgram(gl, vs, fs, self.varying)
|
|
57
|
-
: createProgram(gl, vs, fs)
|
|
58
|
-
self.lastActiveUnit = 0
|
|
59
|
-
self.activeUnit = nested(() => self.lastActiveUnit++)
|
|
60
|
-
self.location = nested((key, isAttribute = false) => {
|
|
61
|
-
return isAttribute
|
|
62
|
-
? gl?.getAttribLocation(self.pg, key)
|
|
63
|
-
: gl?.getUniformLocation(self.pg, key)
|
|
64
|
-
})
|
|
65
|
-
},
|
|
66
|
-
render() {
|
|
67
|
-
self.gl.useProgram(self.pg)
|
|
68
|
-
self.frame.flush()
|
|
69
|
-
iPrevTime = iTime
|
|
70
|
-
iTime = performance.now() / 1000
|
|
71
|
-
iDeltaTime = iTime - iPrevTime
|
|
72
|
-
self.uniform({ iTime, iPrevTime, iDeltaTime })
|
|
73
|
-
},
|
|
74
|
-
_uniform(key: string, value = 0, isMatrix = false) {
|
|
75
|
-
const type = uniformType(value, isMatrix)
|
|
76
|
-
self.frame(() => {
|
|
77
|
-
const loc = self.location(key)
|
|
78
|
-
if (isMatrix) self.gl[type](loc, false, value)
|
|
79
|
-
else self.gl[type](loc, value)
|
|
80
|
-
})
|
|
81
|
-
},
|
|
82
|
-
_attribute(key: string, value: number[], iboValue?: number[]) {
|
|
83
|
-
self.frame(() => {
|
|
84
|
-
const loc = self.location(key, true)
|
|
85
|
-
const vbo = createVbo(self.gl, value)
|
|
86
|
-
const ibo = createIbo(self.gl, iboValue)
|
|
87
|
-
const n = self.count
|
|
88
|
-
const stride = vertexStride(n, value, iboValue)
|
|
89
|
-
createAttribute(self.gl, stride, loc, vbo, ibo)
|
|
90
|
-
})
|
|
91
|
-
},
|
|
92
|
-
_texture(alt: string, src: string, crossOrigin = 'anonymous') {
|
|
93
|
-
if (typeof window === 'undefined') return
|
|
94
|
-
const image = new Image()
|
|
95
|
-
const callback = (_: any) => self.load(_, image)
|
|
96
|
-
image.addEventListener('load', callback, false)
|
|
97
|
-
Object.assign(image, { src, alt, crossOrigin })
|
|
98
|
-
},
|
|
99
|
-
resize(
|
|
100
|
-
_e: any,
|
|
101
|
-
width = self.width || window.innerWidth,
|
|
102
|
-
height = self.height || window.innerHeight
|
|
103
|
-
) {
|
|
104
|
-
self.size[0] = self.el.width = width
|
|
105
|
-
self.size[1] = self.el.height = height
|
|
106
|
-
self.uniform('iResolution', self.size)
|
|
107
|
-
},
|
|
108
|
-
mousemove(_e: any, x = _e.clientX, y = _e.clientY) {
|
|
109
|
-
const [w, h] = self.size
|
|
110
|
-
const { top, left } = self.el.getBoundingClientRect()
|
|
111
|
-
self.mouse[0] = (x - top - w / 2) / (w / 2)
|
|
112
|
-
self.mouse[1] = -(y - left - h / 2) / (h / 2)
|
|
113
|
-
self.uniform('iMouse', self.mouse)
|
|
114
|
-
},
|
|
115
|
-
load(_: any, image: any) {
|
|
116
|
-
self.frame(() => {
|
|
117
|
-
const loc = self.location(image.alt)
|
|
118
|
-
const unit = self.activeUnit(image.alt)
|
|
119
|
-
const tex = createTexture(self.gl, image)
|
|
120
|
-
self.frame(() => {
|
|
121
|
-
activeTexture(self.gl, loc, unit, tex)
|
|
122
|
-
return true
|
|
123
|
-
})
|
|
124
|
-
})
|
|
125
|
-
},
|
|
126
|
-
clear(key = 'COLOR_BUFFER_BIT') {
|
|
127
|
-
self.gl.clear(self.gl[key])
|
|
128
|
-
},
|
|
129
|
-
viewport(size: number[] = self.size) {
|
|
130
|
-
self.gl.viewport(0, 0, ...size)
|
|
131
|
-
},
|
|
132
|
-
drawArrays(mode = 'TRIANGLES') {
|
|
133
|
-
self.gl.drawArrays(self.gl[mode], 0, self.count)
|
|
134
|
-
},
|
|
135
|
-
drawElements(mode = 'TRIANGLES', type = 'UNSIGNED_SHORT') {
|
|
136
|
-
mode = self.gl[mode]
|
|
137
|
-
type = self.gl[type]
|
|
138
|
-
self.gl.drawElements(mode, self.count, type, 0)
|
|
139
|
-
},
|
|
124
|
+
init,
|
|
125
|
+
render,
|
|
126
|
+
resize,
|
|
127
|
+
mousemove,
|
|
128
|
+
load,
|
|
129
|
+
clear,
|
|
130
|
+
viewport,
|
|
131
|
+
drawArrays,
|
|
132
|
+
drawElements,
|
|
140
133
|
}) as GL
|
|
141
134
|
|
|
135
|
+
const _texture = (
|
|
136
|
+
alt: string,
|
|
137
|
+
src: string,
|
|
138
|
+
crossOrigin = 'anonymous'
|
|
139
|
+
) => {
|
|
140
|
+
if (typeof window === 'undefined') return
|
|
141
|
+
const image = new Image()
|
|
142
|
+
const callback = (_: any) => self.load(_, image)
|
|
143
|
+
image.addEventListener('load', callback, false)
|
|
144
|
+
Object.assign(image, { src, alt, crossOrigin })
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const _uniform = (key: string, value = 0, isMatrix = false) => {
|
|
148
|
+
const type = uniformType(value, isMatrix)
|
|
149
|
+
self.frame(() => {
|
|
150
|
+
const loc = self.location(key)
|
|
151
|
+
if (isMatrix) self.gl[type](loc, false, value)
|
|
152
|
+
else self.gl[type](loc, value)
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const _attribute = (
|
|
157
|
+
key: string,
|
|
158
|
+
value: number[],
|
|
159
|
+
iboValue?: number[]
|
|
160
|
+
) => {
|
|
161
|
+
self.frame(() => {
|
|
162
|
+
const loc = self.location(key, true)
|
|
163
|
+
const vbo = createVbo(self.gl, value)
|
|
164
|
+
const ibo = createIbo(self.gl, iboValue)
|
|
165
|
+
const n = self.count
|
|
166
|
+
const stride = vertexStride(n, value, iboValue)
|
|
167
|
+
createAttribute(self.gl, stride, loc, vbo, ibo)
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
142
171
|
self.frame = queue()
|
|
143
|
-
self.texture = durable(
|
|
144
|
-
self.uniform = durable(
|
|
145
|
-
self.attribute = durable(
|
|
172
|
+
self.texture = durable(_texture)
|
|
173
|
+
self.uniform = durable(_uniform)
|
|
174
|
+
self.attribute = durable(_attribute)
|
|
146
175
|
|
|
147
176
|
return self
|
|
148
177
|
}
|
|
@@ -150,22 +179,24 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
150
179
|
export const gl = createGL()
|
|
151
180
|
|
|
152
181
|
export const createTF = (props?: Partial<GL>, self = gl) => {
|
|
182
|
+
const mount = () => {
|
|
183
|
+
tf(props)
|
|
184
|
+
tf.el = self.el
|
|
185
|
+
tf.gl = self.gl
|
|
186
|
+
tf.frame = self.frame
|
|
187
|
+
tf.init()
|
|
188
|
+
self({ resize: tf.resize, mousemove: tf.mousemove })
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const clean = () => {
|
|
192
|
+
tf(props)
|
|
193
|
+
self({ resize: tf.resize, mousemove: tf.mousemove })
|
|
194
|
+
}
|
|
195
|
+
|
|
153
196
|
const tf = createGL()
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
tf(props)
|
|
157
|
-
tf.el = self.el
|
|
158
|
-
tf.gl = self.gl
|
|
159
|
-
tf.frame = self.frame
|
|
160
|
-
tf.init()
|
|
161
|
-
self({ resize: tf.resize, mousemove: tf.mousemove })
|
|
162
|
-
},
|
|
163
|
-
clean() {
|
|
164
|
-
tf(props)
|
|
165
|
-
self({ resize: tf.resize, mousemove: tf.mousemove })
|
|
166
|
-
},
|
|
167
|
-
})
|
|
197
|
+
|
|
198
|
+
tf({ mount, clean })
|
|
168
199
|
return tf
|
|
169
200
|
}
|
|
170
201
|
|
|
171
|
-
export default
|
|
202
|
+
export default gl
|
package/native.ts
CHANGED
|
@@ -44,19 +44,19 @@ export const useTF = (props: Partial<GL>, self = gl) => {
|
|
|
44
44
|
return tf
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export
|
|
47
|
+
export const useTexture = (props: any, self = gl) => {
|
|
48
48
|
return self.texture(props)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export
|
|
51
|
+
export const useAttribute = (props: any, self = gl) => {
|
|
52
52
|
return self.attribute(props)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
export
|
|
55
|
+
export const useUniform = (props: any, self = gl) => {
|
|
56
56
|
return self.uniform(props)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export
|
|
59
|
+
export const useFrame = (fun: Fun, self = gl) => {
|
|
60
60
|
const ref = useMutable(fun)
|
|
61
61
|
useEffect(() => self.frame(fun), [])
|
|
62
62
|
useEffect(() => () => self.frame(ref), [])
|
package/package.json
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glre",
|
|
3
|
+
"version": "0.18.0",
|
|
3
4
|
"author": "tseijp",
|
|
4
5
|
"license": "MIT",
|
|
5
|
-
"version": "0.16.0",
|
|
6
|
-
"module": "index.js",
|
|
7
|
-
"types": "index.ts",
|
|
8
|
-
"main": "index.cjs.js",
|
|
9
|
-
"umd": "index.develop.js",
|
|
10
6
|
"private": false,
|
|
11
7
|
"sideEffect": false,
|
|
12
8
|
"publishConfig": {
|
|
13
9
|
"access": "public"
|
|
14
10
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"refr": "0.3.0"
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/tseijp/glre/issues"
|
|
18
13
|
},
|
|
14
|
+
"repository": "tseijp/glre",
|
|
15
|
+
"homepage": "https://glre.tsei.jp",
|
|
19
16
|
"keywords": [
|
|
20
17
|
"glsl",
|
|
21
18
|
"webgl",
|
|
@@ -27,6 +24,120 @@
|
|
|
27
24
|
"solidjs",
|
|
28
25
|
"typescript"
|
|
29
26
|
],
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"module": "./dist/index.mjs",
|
|
30
|
+
"exports": {
|
|
31
|
+
"./packages.json": "./packages.json",
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"default": "./dist/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"module": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"require": "./dist/index.js",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./*": {
|
|
46
|
+
"types": "./dist/index.d.ts",
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/index.d.ts",
|
|
49
|
+
"default": "./dist/index.mjs"
|
|
50
|
+
},
|
|
51
|
+
"module": {
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"default": "./dist/index.mjs"
|
|
54
|
+
},
|
|
55
|
+
"require": "./dist/index.js",
|
|
56
|
+
"default": "./dist/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./react": {
|
|
59
|
+
"types": "./dist/react.d.ts",
|
|
60
|
+
"import": {
|
|
61
|
+
"types": "./dist/react.d.ts",
|
|
62
|
+
"default": "./dist/react.mjs"
|
|
63
|
+
},
|
|
64
|
+
"module": {
|
|
65
|
+
"types": "./dist/react.d.ts",
|
|
66
|
+
"default": "./dist/react.mjs"
|
|
67
|
+
},
|
|
68
|
+
"require": "./dist/react.js",
|
|
69
|
+
"default": "./dist/react.js"
|
|
70
|
+
},
|
|
71
|
+
"./react/*": {
|
|
72
|
+
"types": "./dist/react.d.ts",
|
|
73
|
+
"import": {
|
|
74
|
+
"types": "./dist/react.d.ts",
|
|
75
|
+
"default": "./dist/react.mjs"
|
|
76
|
+
},
|
|
77
|
+
"module": {
|
|
78
|
+
"types": "./dist/react.d.ts",
|
|
79
|
+
"default": "./dist/react.mjs"
|
|
80
|
+
},
|
|
81
|
+
"require": "./dist/react.js",
|
|
82
|
+
"default": "./dist/react.js"
|
|
83
|
+
},
|
|
84
|
+
"./native": {
|
|
85
|
+
"types": "./dist/native.d.ts",
|
|
86
|
+
"import": {
|
|
87
|
+
"types": "./dist/native.d.ts",
|
|
88
|
+
"default": "./dist/native.mjs"
|
|
89
|
+
},
|
|
90
|
+
"module": {
|
|
91
|
+
"types": "./dist/native.d.ts",
|
|
92
|
+
"default": "./dist/native.mjs"
|
|
93
|
+
},
|
|
94
|
+
"require": "./dist/native.js",
|
|
95
|
+
"default": "./dist/native.js"
|
|
96
|
+
},
|
|
97
|
+
"./native/*": {
|
|
98
|
+
"types": "./dist/native.d.ts",
|
|
99
|
+
"import": {
|
|
100
|
+
"types": "./dist/native.d.ts",
|
|
101
|
+
"default": "./dist/native.mjs"
|
|
102
|
+
},
|
|
103
|
+
"module": {
|
|
104
|
+
"types": "./dist/native.d.ts",
|
|
105
|
+
"default": "./dist/native.mjs"
|
|
106
|
+
},
|
|
107
|
+
"require": "./dist/native.js",
|
|
108
|
+
"default": "./dist/native.js"
|
|
109
|
+
},
|
|
110
|
+
"./solid": {
|
|
111
|
+
"types": "./dist/solid.d.ts",
|
|
112
|
+
"import": {
|
|
113
|
+
"types": "./dist/solid.d.ts",
|
|
114
|
+
"default": "./dist/solid.mjs"
|
|
115
|
+
},
|
|
116
|
+
"module": {
|
|
117
|
+
"types": "./dist/solid.d.ts",
|
|
118
|
+
"default": "./dist/solid.mjs"
|
|
119
|
+
},
|
|
120
|
+
"require": "./dist/solid.js",
|
|
121
|
+
"default": "./dist/solid.js"
|
|
122
|
+
},
|
|
123
|
+
"./solid/*": {
|
|
124
|
+
"types": "./dist/solid.d.ts",
|
|
125
|
+
"import": {
|
|
126
|
+
"types": "./dist/solid.d.ts",
|
|
127
|
+
"default": "./dist/solid.mjs"
|
|
128
|
+
},
|
|
129
|
+
"module": {
|
|
130
|
+
"types": "./dist/solid.d.ts",
|
|
131
|
+
"default": "./dist/solid.mjs"
|
|
132
|
+
},
|
|
133
|
+
"require": "./dist/solid.js",
|
|
134
|
+
"default": "./dist/solid.js"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
"dependencies": {
|
|
138
|
+
"reev": "0.12.0",
|
|
139
|
+
"refr": "0.3.0"
|
|
140
|
+
},
|
|
30
141
|
"peerDependencies": {
|
|
31
142
|
"expo": "*",
|
|
32
143
|
"expo-gl": "*",
|
|
@@ -50,18 +161,5 @@
|
|
|
50
161
|
"solid-js": {
|
|
51
162
|
"optional": true
|
|
52
163
|
}
|
|
53
|
-
}
|
|
54
|
-
"files": [
|
|
55
|
-
"index.js",
|
|
56
|
-
"index.cjs.js",
|
|
57
|
-
"index.develop.js",
|
|
58
|
-
"index.product.js",
|
|
59
|
-
"index.ts",
|
|
60
|
-
"native.ts",
|
|
61
|
-
"qwik.ts",
|
|
62
|
-
"react.ts",
|
|
63
|
-
"solid.ts",
|
|
64
|
-
"types.ts",
|
|
65
|
-
"utils.ts"
|
|
66
|
-
]
|
|
164
|
+
}
|
|
67
165
|
}
|
package/qwik.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useSignal,
|
|
1
|
+
import { useSignal, useTask$, useVisibleTask$ } from '@builder.io/qwik'
|
|
2
2
|
import { gl } from './index'
|
|
3
3
|
import { frame } from 'refr'
|
|
4
4
|
import type { GL } from './types'
|
|
5
5
|
import type { Fun } from 'reev/types'
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export const useGL = (props?: any, self = gl as unknown as GL) => {
|
|
8
8
|
const ref = useSignal<Element>()
|
|
9
9
|
useVisibleTask$(({ cleanup }) => {
|
|
10
10
|
self(props)
|
|
@@ -24,19 +24,19 @@ export function useGL(props?: any, self = $(gl) as unknown as GL) {
|
|
|
24
24
|
return self
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export
|
|
27
|
+
export const useTexture = (props: any, self = gl) => {
|
|
28
28
|
return self?.texture(props)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export
|
|
31
|
+
export const useAttribute = (props: any, self = gl) => {
|
|
32
32
|
return self.attribute(props)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export
|
|
35
|
+
export const useUniform = (props: any, self = gl) => {
|
|
36
36
|
return self.uniform(props)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export
|
|
39
|
+
export const useFrame = (fun: Fun, self = gl) => {
|
|
40
40
|
useTask$(() => self.frame(fun))
|
|
41
41
|
return self
|
|
42
42
|
}
|
package/react.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect, useMemo } from 'react'
|
|
2
2
|
import { createTF, gl } from './index'
|
|
3
3
|
import { frame } from 'refr'
|
|
4
|
-
import {
|
|
4
|
+
import { useMutable } from 'reev/react'
|
|
5
5
|
import type { GL } from './types'
|
|
6
6
|
import type { Fun } from 'refr'
|
|
7
|
-
import type { MutableArgs } from 'reev/types'
|
|
8
|
-
|
|
9
|
-
export const useMutable = <T extends object>(...args: MutableArgs<T>) => {
|
|
10
|
-
const [memo] = useState(() => mutable<T>())
|
|
11
|
-
return memo(...args)
|
|
12
|
-
}
|
|
13
7
|
|
|
14
8
|
export const useGL = (props: Partial<GL> = {}, self = gl) => {
|
|
15
9
|
const memo1 = useMutable(props) as Partial<GL>
|
|
@@ -46,21 +40,20 @@ export const useTF = (props: Partial<GL>, self = gl) => {
|
|
|
46
40
|
return tf
|
|
47
41
|
}
|
|
48
42
|
|
|
49
|
-
export
|
|
43
|
+
export const useTexture = (props: any, self = gl) => {
|
|
50
44
|
return self.texture(props)
|
|
51
45
|
}
|
|
52
46
|
|
|
53
|
-
export
|
|
47
|
+
export const useAttribute = (props: any, self = gl) => {
|
|
54
48
|
return self.attribute(props)
|
|
55
49
|
}
|
|
56
50
|
|
|
57
|
-
export
|
|
51
|
+
export const useUniform = (props: any, self = gl) => {
|
|
58
52
|
return self.uniform(props)
|
|
59
53
|
}
|
|
60
54
|
|
|
61
|
-
export
|
|
62
|
-
|
|
63
|
-
useEffect(() => self.frame(fun), [])
|
|
64
|
-
useEffect(() => () => self.frame(ref), [])
|
|
55
|
+
export const useFrame = (fun: Fun, self = gl) => {
|
|
56
|
+
useEffect(() => void self.frame(fun), [])
|
|
57
|
+
useEffect(() => () => self.frame(fun), [])
|
|
65
58
|
return self
|
|
66
59
|
}
|
package/solid.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { onMount, onCleanup } from 'solid-js'
|
|
2
2
|
import { frame } from 'refr'
|
|
3
|
-
import { gl } from './index'
|
|
3
|
+
import { createTF, gl } from './index'
|
|
4
|
+
import { GL } from './types'
|
|
4
5
|
import type { Fun } from 'reev/types'
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
+
export const onGL = (props?: Partial<GL>, self = gl) => {
|
|
7
8
|
const memo = {
|
|
8
9
|
ref(target: unknown) {
|
|
9
10
|
if (target) {
|
|
@@ -31,21 +32,21 @@ export function createGL(props?: any, self = gl) {
|
|
|
31
32
|
return self(props)(memo)
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export const
|
|
35
|
+
export const onTF = (props?: Partial<GL>, self = gl) => {
|
|
35
36
|
const tf = createTF(props, self)
|
|
36
37
|
onMount(() => tf.mount())
|
|
37
38
|
onCleanup(() => tf.clean())
|
|
38
39
|
return tf
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
export
|
|
42
|
+
export const onFrame = (fun: Fun, self = gl) => {
|
|
42
43
|
onMount(() => self('render', fun))
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
export
|
|
46
|
+
export const setTexture = (props: any, self = gl) => {
|
|
46
47
|
return self.texture(props)
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
export
|
|
50
|
+
export const setAttribute = (props: any, self = gl) => {
|
|
50
51
|
return self.attribute(props)
|
|
51
52
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
interleave,
|
|
3
|
+
isTemplateLiteral,
|
|
4
|
+
concat,
|
|
5
|
+
switchUniformType,
|
|
6
|
+
} from 'glre/utils'
|
|
7
|
+
|
|
8
|
+
describe('utils', () => {
|
|
9
|
+
const _ = (str, ...args) => [str, args] as [any, any]
|
|
10
|
+
const _0 = _`foo${false}bar${undefined}baz${null}`
|
|
11
|
+
const _1 = _`foo${ 0 }bar${ NaN }baz${ -1 }`
|
|
12
|
+
it('interleave merge strings', () => {
|
|
13
|
+
expect(interleave(..._0)).toEqual(`foofalsebarundefinedbaznull`)
|
|
14
|
+
expect(interleave(..._1)).toEqual(`foo0barNaNbaz-1`)
|
|
15
|
+
})
|
|
16
|
+
it('isTemplateLiteral', () => {
|
|
17
|
+
expect(isTemplateLiteral(_0[0])).toEqual(true)
|
|
18
|
+
expect(isTemplateLiteral(_1[0])).toEqual(true)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const headerUniform = `uniform vec2 iMouse;`;
|
|
22
|
+
const withUniform = `void main() { gl_FragColor = vec4(iMouse, 0., 1.); }`
|
|
23
|
+
const noneUniform = `void main() { gl_FragColor = vec4(0., 1., 0., 1.); }`
|
|
24
|
+
it.each`
|
|
25
|
+
i | key | shader | toBe
|
|
26
|
+
${0} | ${void 0} | ${ withUniform} | ${headerUniform + withUniform}
|
|
27
|
+
${1} | ${"iMouse"} | ${ withUniform} | ${headerUniform + withUniform}
|
|
28
|
+
${2} | ${"iMouse"} | ${ noneUniform} | ${noneUniform}
|
|
29
|
+
${3} | ${void 0} | ${headerUniform + withUniform} | ${headerUniform + withUniform}
|
|
30
|
+
${4} | ${"iMouse"} | ${headerUniform + withUniform} | ${headerUniform + withUniform}
|
|
31
|
+
${5} | ${"iMouse"} | ${headerUniform + noneUniform} | ${headerUniform + noneUniform}
|
|
32
|
+
`('concat $i', ({ key, shader, toBe }) => {
|
|
33
|
+
expect(concat(shader, headerUniform, key)).toBe(toBe)
|
|
34
|
+
})
|
|
35
|
+
it.each`
|
|
36
|
+
i | uniformType | uniformKey | isMatrix | value
|
|
37
|
+
${0} | ${'uniform1f'} | ${'float'} | ${false} | ${10}
|
|
38
|
+
${1} | ${'uniform2fv'} | ${'vec2'} | ${false} | ${[0, 1]}
|
|
39
|
+
${2} | ${`uniformMatrix2fv`} | ${'mat2'} | ${true} | ${[0, 1, 2, 3]}
|
|
40
|
+
`('switchUniformType $i', ({ value, isMatrix, uniformType, uniformKey }) => {
|
|
41
|
+
expect(switchUniformType(value, isMatrix)).toEqual([uniformType, uniformKey])
|
|
42
|
+
})
|
|
43
|
+
})
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup'
|
|
2
|
+
import { defaultConfig } from '../../tsup.config.base'
|
|
3
|
+
|
|
4
|
+
export default defineConfig((options) => {
|
|
5
|
+
return defaultConfig(
|
|
6
|
+
{
|
|
7
|
+
entry: [
|
|
8
|
+
'index.ts',
|
|
9
|
+
'native.ts',
|
|
10
|
+
'react.ts',
|
|
11
|
+
'solid.ts',
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
options
|
|
15
|
+
)
|
|
16
|
+
})
|
package/types.ts
CHANGED
|
@@ -61,13 +61,10 @@ export type GL = EventState<{
|
|
|
61
61
|
/**
|
|
62
62
|
* setter
|
|
63
63
|
*/
|
|
64
|
-
_uniform(key: string, value: Uniform): GL
|
|
65
64
|
uniform(key: string, value: Uniform): GL
|
|
66
65
|
uniform(target: { [key: string]: Uniform }): GL
|
|
67
|
-
_texture(key: string, value: string): GL
|
|
68
66
|
texture(key: string, value: string): GL
|
|
69
67
|
texture(target: { [key: string]: string }): GL
|
|
70
|
-
_attribute(key: string, value: Attribute, iboValue?: Attribute): GL
|
|
71
68
|
attribute(key: string, value: Attribute, iboValue?: Attribute): GL
|
|
72
69
|
attribute(target: { [key: string]: Attribute }): GL
|
|
73
70
|
// config(key?: keyof GL, value?: GL[keyof GL]): GL
|