glre 0.12.0 → 0.14.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/index.cjs.js +1 -1
- package/index.develop.js +1 -1
- package/index.js +1 -1
- package/index.ts +141 -103
- package/native.ts +64 -0
- package/package.json +65 -41
- package/qwik.ts +42 -0
- package/react.ts +46 -27
- package/solid.ts +37 -17
- package/types.ts +44 -55
- package/utils.ts +121 -48
- package/events.ts +0 -68
package/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("reev"),r=require("refr");function t(e,r,t){var n=e.createShader(t);if(e.shaderSource(n,r),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS))return n;console.warn(e.getShaderInfoLog(n))}var n=[-1,-1,1,-1,-1,1,-1,1,1,-1,1,1],i=performance.now(),o=0,a=0,u=e.event({vertex:"\n attribute vec4 a_position;\n void main() {\n gl_Position = a_position;\n }\n",fragment:"\n precision mediump float;\n uniform vec2 iResolution;\n void main() {\n gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);\n }\n",size:[0,0],mouse:[0,0],count:6,counter:0,init:function(i){var o=u.gl,a=u.vs||u.vert||u.vertex,f=u.fs||u.frag||u.fragment,c=t(o,a,o.VERTEX_SHADER),l=t(o,f,o.FRAGMENT_SHADER);6===u.count&&u.attribute({a_position:n}),r.frame((function(){return void u.render()||1})),u.pg=i?function(e,r,t,n){var i=e.createProgram();return e.attachShader(i,r),e.attachShader(i,t),e.transformFeedbackVaryings(i,n,e.SEPARATE_ATTRIBS),e.linkProgram(i),e.getProgramParameter(i,e.LINK_STATUS)?(e.useProgram(i),i):(console.warn(e.getProgramInfoLog(i)),null)}(o,c,l,i):function(e,r,t){var n=e.createProgram();return e.attachShader(n,r),e.attachShader(n,t),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS)?(e.useProgram(n),n):(console.log(e.getProgramInfoLog(n)),null)}(o,c,l),u.lastActiveUnit=0,u.activeUnit=e.nested((function(){return u.lastActiveUnit++})),u.location=e.nested((function(e,r){return void 0===r&&(r=!1),r?null==o?void 0:o.getAttribLocation(u.pg,e):null==o?void 0:o.getUniformLocation(u.pg,e)}))},render:function(){u.gl.useProgram(u.pg),u.frame.flush(),o=i,i=performance.now()/1e3,a=i-o,u.uniform({iTime:i,iPrevTime:o,iDeltaTime:a})},_uniform:function(e,r,t){void 0===r&&(r=0),void 0===t&&(t=!1);var n=function(e,r){void 0===r&&(r=!1);var t="number"==typeof e?0:null==e?void 0:e.length;return t?r?"uniformMatrix"+(t=Math.sqrt(t)<<0)+"fv":"uniform"+t+"fv":"uniform1f"}(r,t);u.frame((function(){var i=u.location(e);t?u.gl[n](i,!1,r):u.gl[n](i,r)}))},_attribute:function(e,r,t){u.frame((function(){var n=u.location(e,!0),i=function(e,r){if(r){var t=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,t),e.bufferData(e.ARRAY_BUFFER,new Float32Array(r),e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,null),t}}(u.gl,r),o=function(e,r){if(r){var t=e.createBuffer();return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Int16Array(r),e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),t}}(u.gl,t),a=function(e,r,t){t&&(e=Math.max.apply(Math,t)+1);var n=r.length/e;return n!==n<<0&&console.warn("Vertex Stride Error: count "+e+" is mismatch"),n<<0}(u.count,r,t);!function(e,r,t,n,i){e.bindBuffer(e.ARRAY_BUFFER,n),e.enableVertexAttribArray(t),e.vertexAttribPointer(t,r,e.FLOAT,!1,0,0),i&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,i)}(u.gl,a,n,i,o)}))},_texture:function(e,r){if("undefined"!=typeof window){var t=new Image;t.addEventListener("load",(function(e){return u.load(e,t)}),!1),Object.assign(t,{src:r,alt:e,crossOrigin:"anonymous"})}},resize:function(e,r,t){void 0===r&&(r=window.innerWidth),void 0===t&&(t=window.innerHeight),u.size[0]=u.el.width=r,u.size[1]=u.el.height=t,u.uniform("iResolution",u.size)},mousemove:function(e,r,t){void 0===r&&(r=e.clientX),void 0===t&&(t=e.clientY);var n=u.size,i=n[0],o=n[1];u.mouse[0]=(r-i/2)/(i/2),u.mouse[1]=-(t-o/2)/(o/2),u.uniform("iMouse",u.mouse)},load:function(e,r){u.frame((function(){var e=u.location(r.alt),t=u.activeUnit(r.alt),n=function(e,r){var t=e.createTexture();return e.bindTexture(e.TEXTURE_2D,t),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r),e.generateMipmap(e.TEXTURE_2D),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),t}(u.gl,r);u.frame((function(){return function(e,r,t,n){e.uniform1i(r,t),e.activeTexture(e["TEXTURE"+t]),e.bindTexture(e.TEXTURE_2D,n)}(u.gl,e,t,n),!0}))}))},clear:function(e){void 0===e&&(e="COLOR_BUFFER_BIT"),u.gl.clear(u.gl[e])},viewport:function(e){var r;void 0===e&&(e=u.size),(r=u.gl).viewport.apply(r,[0,0].concat(e))},drawArrays:function(e){void 0===e&&(e="TRIANGLES"),u.gl.drawArrays(u.gl[e],0,u.count)},drawElements:function(e,r){void 0===e&&(e="TRIANGLES"),void 0===r&&(r="UNSIGNED_SHORT"),u.gl.drawElements(u.gl[e],u.count,u.gl[r],0)}});u.frame=r.queue(),u.texture=e.durable(u._texture),u.uniform=e.durable(u._uniform),u.attribute=e.durable(u._attribute),exports.default=u,exports.gl=u;
|
package/index.develop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("reev"),require("refr")):"function"==typeof define&&define.amd?define(["exports","reev","refr"],r):r(((e="undefined"!=typeof globalThis?globalThis:e||self).index=e.index||{},e.index.ts={}),e.reev,e.refr)}(this,(function(e,r,n){"use strict";function t(e,r,n){var t=e.createShader(n);if(e.shaderSource(t,r),e.compileShader(t),e.getShaderParameter(t,e.COMPILE_STATUS))return t;console.warn(e.getShaderInfoLog(t))}var i=[-1,-1,1,-1,-1,1,-1,1,1,-1,1,1],o=performance.now(),a=0,u=0,f=r.event({vertex:"\n attribute vec4 a_position;\n void main() {\n gl_Position = a_position;\n }\n",fragment:"\n precision mediump float;\n uniform vec2 iResolution;\n void main() {\n gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);\n }\n",size:[0,0],mouse:[0,0],count:6,counter:0,init:function(e){var o=f.gl,a=f.vs||f.vert||f.vertex,u=f.fs||f.frag||f.fragment,l=t(o,a,o.VERTEX_SHADER),c=t(o,u,o.FRAGMENT_SHADER);6===f.count&&f.attribute({a_position:i}),n.frame((function(){return void f.render()||1})),f.pg=e?function(e,r,n,t){var i=e.createProgram();return e.attachShader(i,r),e.attachShader(i,n),e.transformFeedbackVaryings(i,t,e.SEPARATE_ATTRIBS),e.linkProgram(i),e.getProgramParameter(i,e.LINK_STATUS)?(e.useProgram(i),i):(console.warn(e.getProgramInfoLog(i)),null)}(o,l,c,e):function(e,r,n){var t=e.createProgram();return e.attachShader(t,r),e.attachShader(t,n),e.linkProgram(t),e.getProgramParameter(t,e.LINK_STATUS)?(e.useProgram(t),t):(console.log(e.getProgramInfoLog(t)),null)}(o,l,c),f.lastActiveUnit=0,f.activeUnit=r.nested((function(){return f.lastActiveUnit++})),f.location=r.nested((function(e,r){return void 0===r&&(r=!1),r?null==o?void 0:o.getAttribLocation(f.pg,e):null==o?void 0:o.getUniformLocation(f.pg,e)}))},render:function(){f.gl.useProgram(f.pg),f.frame.flush(),a=o,o=performance.now()/1e3,u=o-a,f.uniform({iTime:o,iPrevTime:a,iDeltaTime:u})},_uniform:function(e,r,n){void 0===r&&(r=0),void 0===n&&(n=!1);var t=function(e,r){void 0===r&&(r=!1);var n="number"==typeof e?0:null==e?void 0:e.length;return n?r?"uniformMatrix"+(n=Math.sqrt(n)<<0)+"fv":"uniform"+n+"fv":"uniform1f"}(r,n);f.frame((function(){var i=f.location(e);n?f.gl[t](i,!1,r):f.gl[t](i,r)}))},_attribute:function(e,r,n){f.frame((function(){var t=f.location(e,!0),i=function(e,r){if(r){var n=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,new Float32Array(r),e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,null),n}}(f.gl,r),o=function(e,r){if(r){var n=e.createBuffer();return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Int16Array(r),e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),n}}(f.gl,n),a=function(e,r,n){n&&(e=Math.max.apply(Math,n)+1);var t=r.length/e;return t!==t<<0&&console.warn("Vertex Stride Error: count "+e+" is mismatch"),t<<0}(f.count,r,n);!function(e,r,n,t,i){e.bindBuffer(e.ARRAY_BUFFER,t),e.enableVertexAttribArray(n),e.vertexAttribPointer(n,r,e.FLOAT,!1,0,0),i&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,i)}(f.gl,a,t,i,o)}))},_texture:function(e,r){if("undefined"!=typeof window){var n=new Image;n.addEventListener("load",(function(e){return f.load(e,n)}),!1),Object.assign(n,{src:r,alt:e,crossOrigin:"anonymous"})}},resize:function(e,r,n){void 0===r&&(r=window.innerWidth),void 0===n&&(n=window.innerHeight),f.size[0]=f.el.width=r,f.size[1]=f.el.height=n,f.uniform("iResolution",f.size)},mousemove:function(e,r,n){void 0===r&&(r=e.clientX),void 0===n&&(n=e.clientY);var t=f.size,i=t[0],o=t[1];f.mouse[0]=(r-i/2)/(i/2),f.mouse[1]=-(n-o/2)/(o/2),f.uniform("iMouse",f.mouse)},load:function(e,r){f.frame((function(){var e=f.location(r.alt),n=f.activeUnit(r.alt),t=function(e,r){var n=e.createTexture();return e.bindTexture(e.TEXTURE_2D,n),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r),e.generateMipmap(e.TEXTURE_2D),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),n}(f.gl,r);f.frame((function(){return function(e,r,n,t){e.uniform1i(r,n),e.activeTexture(e["TEXTURE"+n]),e.bindTexture(e.TEXTURE_2D,t)}(f.gl,e,n,t),!0}))}))},clear:function(e){void 0===e&&(e="COLOR_BUFFER_BIT"),f.gl.clear(f.gl[e])},viewport:function(e){var r;void 0===e&&(e=f.size),(r=f.gl).viewport.apply(r,[0,0].concat(e))},drawArrays:function(e){void 0===e&&(e="TRIANGLES"),f.gl.drawArrays(f.gl[e],0,f.count)},drawElements:function(e,r){void 0===e&&(e="TRIANGLES"),void 0===r&&(r="UNSIGNED_SHORT"),f.gl.drawElements(f.gl[e],f.count,f.gl[r],0)}});f.frame=n.queue(),f.texture=r.durable(f._texture),f.uniform=r.durable(f._uniform),f.attribute=r.durable(f._attribute),e.default=f,e.gl=f,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{event as r,nested as e,durable as n}from"reev";import{frame as t,queue as i}from"refr";function o(r,e,n){var t=r.createShader(n);if(r.shaderSource(t,e),r.compileShader(t),r.getShaderParameter(t,r.COMPILE_STATUS))return t;console.warn(r.getShaderInfoLog(t))}var a=[-1,-1,1,-1,-1,1,-1,1,1,-1,1,1],u=performance.now(),f=0,c=0,l=r({vertex:"\n attribute vec4 a_position;\n void main() {\n gl_Position = a_position;\n }\n",fragment:"\n precision mediump float;\n uniform vec2 iResolution;\n void main() {\n gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);\n }\n",size:[0,0],mouse:[0,0],count:6,counter:0,init:function(r){var n=l.gl,i=l.vs||l.vert||l.vertex,u=l.fs||l.frag||l.fragment,f=o(n,i,n.VERTEX_SHADER),c=o(n,u,n.FRAGMENT_SHADER);6===l.count&&l.attribute({a_position:a}),t((function(){return void l.render()||1})),l.pg=r?function(r,e,n,t){var i=r.createProgram();return r.attachShader(i,e),r.attachShader(i,n),r.transformFeedbackVaryings(i,t,r.SEPARATE_ATTRIBS),r.linkProgram(i),r.getProgramParameter(i,r.LINK_STATUS)?(r.useProgram(i),i):(console.warn(r.getProgramInfoLog(i)),null)}(n,f,c,r):function(r,e,n){var t=r.createProgram();return r.attachShader(t,e),r.attachShader(t,n),r.linkProgram(t),r.getProgramParameter(t,r.LINK_STATUS)?(r.useProgram(t),t):(console.log(r.getProgramInfoLog(t)),null)}(n,f,c),l.lastActiveUnit=0,l.activeUnit=e((function(){return l.lastActiveUnit++})),l.location=e((function(r,e){return void 0===e&&(e=!1),e?null==n?void 0:n.getAttribLocation(l.pg,r):null==n?void 0:n.getUniformLocation(l.pg,r)}))},render:function(){l.gl.useProgram(l.pg),l.frame.flush(),f=u,u=performance.now()/1e3,c=u-f,l.uniform({iTime:u,iPrevTime:f,iDeltaTime:c})},_uniform:function(r,e,n){void 0===e&&(e=0),void 0===n&&(n=!1);var t=function(r,e){void 0===e&&(e=!1);var n="number"==typeof r?0:null==r?void 0:r.length;return n?e?"uniformMatrix"+(n=Math.sqrt(n)<<0)+"fv":"uniform"+n+"fv":"uniform1f"}(e,n);l.frame((function(){var i=l.location(r);n?l.gl[t](i,!1,e):l.gl[t](i,e)}))},_attribute:function(r,e,n){l.frame((function(){var t=l.location(r,!0),i=function(r,e){if(e){var n=r.createBuffer();return r.bindBuffer(r.ARRAY_BUFFER,n),r.bufferData(r.ARRAY_BUFFER,new Float32Array(e),r.STATIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),n}}(l.gl,e),o=function(r,e){if(e){var n=r.createBuffer();return r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,n),r.bufferData(r.ELEMENT_ARRAY_BUFFER,new Int16Array(e),r.STATIC_DRAW),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,null),n}}(l.gl,n),a=function(r,e,n){n&&(r=Math.max.apply(Math,n)+1);var t=e.length/r;return t!==t<<0&&console.warn("Vertex Stride Error: count "+r+" is mismatch"),t<<0}(l.count,e,n);!function(r,e,n,t,i){r.bindBuffer(r.ARRAY_BUFFER,t),r.enableVertexAttribArray(n),r.vertexAttribPointer(n,e,r.FLOAT,!1,0,0),i&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,i)}(l.gl,a,t,i,o)}))},_texture:function(r,e){if("undefined"!=typeof window){var n=new Image;n.addEventListener("load",(function(r){return l.load(r,n)}),!1),Object.assign(n,{src:e,alt:r,crossOrigin:"anonymous"})}},resize:function(r,e,n){void 0===e&&(e=window.innerWidth),void 0===n&&(n=window.innerHeight),l.size[0]=l.el.width=e,l.size[1]=l.el.height=n,l.uniform("iResolution",l.size)},mousemove:function(r,e,n){void 0===e&&(e=r.clientX),void 0===n&&(n=r.clientY);var t=l.size,i=t[0],o=t[1];l.mouse[0]=(e-i/2)/(i/2),l.mouse[1]=-(n-o/2)/(o/2),l.uniform("iMouse",l.mouse)},load:function(r,e){l.frame((function(){var r=l.location(e.alt),n=l.activeUnit(e.alt),t=function(r,e){var n=r.createTexture();return r.bindTexture(r.TEXTURE_2D,n),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e),r.generateMipmap(r.TEXTURE_2D),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.bindTexture(r.TEXTURE_2D,null),n}(l.gl,e);l.frame((function(){return function(r,e,n,t){r.uniform1i(e,n),r.activeTexture(r["TEXTURE"+n]),r.bindTexture(r.TEXTURE_2D,t)}(l.gl,r,n,t),!0}))}))},clear:function(r){void 0===r&&(r="COLOR_BUFFER_BIT"),l.gl.clear(l.gl[r])},viewport:function(r){var e;void 0===r&&(r=l.size),(e=l.gl).viewport.apply(e,[0,0].concat(r))},drawArrays:function(r){void 0===r&&(r="TRIANGLES"),l.gl.drawArrays(l.gl[r],0,l.count)},drawElements:function(r,e){void 0===r&&(r="TRIANGLES"),void 0===e&&(e="UNSIGNED_SHORT"),l.gl.drawElements(l.gl[r],l.count,l.gl[e],0)}});l.frame=i(),l.texture=n(l._texture),l.uniform=n(l._uniform),l.attribute=n(l._attribute);export{l as default,l as gl};
|
package/index.ts
CHANGED
|
@@ -1,120 +1,158 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { event, durable, nested } from 'reev'
|
|
2
|
+
import { queue, frame } from 'refr'
|
|
3
|
+
import {
|
|
4
|
+
uniformType,
|
|
5
|
+
vertexStride,
|
|
6
|
+
createProgram,
|
|
7
|
+
createTfProgram,
|
|
8
|
+
createShader,
|
|
9
|
+
createAttribute,
|
|
10
|
+
createTexture,
|
|
11
|
+
createVbo,
|
|
12
|
+
createIbo,
|
|
13
|
+
activeTexture,
|
|
14
|
+
} from './utils'
|
|
5
15
|
import type { GL } from './types'
|
|
6
16
|
|
|
7
|
-
const a_position = [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]
|
|
17
|
+
const a_position = [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]
|
|
8
18
|
|
|
9
|
-
const
|
|
19
|
+
const _defaultVertex = `
|
|
10
20
|
attribute vec4 a_position;
|
|
11
21
|
void main() {
|
|
12
22
|
gl_Position = a_position;
|
|
13
23
|
}
|
|
14
24
|
`
|
|
15
25
|
|
|
16
|
-
const
|
|
17
|
-
|
|
26
|
+
const _defaultFragment = `
|
|
27
|
+
precision mediump float;
|
|
28
|
+
uniform vec2 iResolution;
|
|
18
29
|
void main() {
|
|
19
|
-
gl_FragColor = vec4(fract(gl_FragCoord.xy /
|
|
30
|
+
gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
|
|
20
31
|
}
|
|
21
32
|
`
|
|
22
33
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return stride
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
self.uniformType = nested((key, value, isMatrix) => {
|
|
55
|
-
const [type, code] = switchUniformType(value, isMatrix)
|
|
56
|
-
self.uniformHeader.push([key, `uniform ${code} ${key};`])
|
|
57
|
-
return type
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
self.location = nested((key, isAttribute = false) => {
|
|
61
|
-
return isAttribute
|
|
62
|
-
? self.gl?.getAttribLocation(self.pg, key)
|
|
63
|
-
: self.gl?.getUniformLocation(self.pg, key)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
// setter
|
|
67
|
-
self.setDpr = (...args) => void ev('resize', {}, ...args) || self
|
|
68
|
-
self.setSize = (...args) => void ev('resize', {}, ...args) || self
|
|
69
|
-
self.setFrame = (frame) => void fr.mount(frame) || self
|
|
70
|
-
self.setMount = (mount) => void ev.mount({ mount }) || self
|
|
71
|
-
self.setClean = (clean) => void ev.mount({ clean }) || self
|
|
72
|
-
self.setConfig = durable((key, value) => void (self[key] = value), self)
|
|
73
|
-
|
|
74
|
-
// uniform
|
|
75
|
-
self.setUniform = durable((key, value, isMatrix = false) => {
|
|
76
|
-
const type = self.uniformType(key, value, isMatrix)
|
|
77
|
-
self.setFrame(() => {
|
|
78
|
-
if (isMatrix)
|
|
79
|
-
self.gl[type](self.location(key), false, value)
|
|
80
|
-
else self.gl[type](self.location(key), value)
|
|
34
|
+
let iTime = performance.now(),
|
|
35
|
+
iPrevTime = 0,
|
|
36
|
+
iDeltaTime = 0
|
|
37
|
+
|
|
38
|
+
const self = event<Partial<GL>>({
|
|
39
|
+
vertex: _defaultVertex,
|
|
40
|
+
fragment: _defaultFragment,
|
|
41
|
+
size: [0, 0],
|
|
42
|
+
mouse: [0, 0],
|
|
43
|
+
count: 6,
|
|
44
|
+
counter: 0,
|
|
45
|
+
init(varying?: string[]) {
|
|
46
|
+
const gl = self.gl
|
|
47
|
+
const _v = self.vs || self.vert || self.vertex
|
|
48
|
+
const _f = self.fs || self.frag || self.fragment
|
|
49
|
+
const vs = createShader(gl, _v, gl.VERTEX_SHADER)
|
|
50
|
+
const fs = createShader(gl, _f, gl.FRAGMENT_SHADER)
|
|
51
|
+
if (self.count === 6) self.attribute({ a_position })
|
|
52
|
+
frame(() => void self.render() || 1)
|
|
53
|
+
self.pg = varying
|
|
54
|
+
? createTfProgram(gl, vs, fs, varying)
|
|
55
|
+
: createProgram(gl, vs, fs)
|
|
56
|
+
self.lastActiveUnit = 0
|
|
57
|
+
self.activeUnit = nested(() => self.lastActiveUnit++)
|
|
58
|
+
self.location = nested((key, isAttribute = false) => {
|
|
59
|
+
return isAttribute
|
|
60
|
+
? gl?.getAttribLocation(self.pg, key)
|
|
61
|
+
: gl?.getUniformLocation(self.pg, key)
|
|
81
62
|
})
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
63
|
+
},
|
|
64
|
+
render() {
|
|
65
|
+
self.gl.useProgram(self.pg)
|
|
66
|
+
self.frame.flush()
|
|
67
|
+
iPrevTime = iTime
|
|
68
|
+
iTime = performance.now() / 1000
|
|
69
|
+
iDeltaTime = iTime - iPrevTime
|
|
70
|
+
self.uniform({ iTime, iPrevTime, iDeltaTime })
|
|
71
|
+
},
|
|
72
|
+
_uniform(key: string, value = 0, isMatrix = false) {
|
|
73
|
+
const type = uniformType(value, isMatrix)
|
|
74
|
+
self.frame(() => {
|
|
75
|
+
const loc = self.location(key)
|
|
76
|
+
if (isMatrix) self.gl[type](loc, false, value)
|
|
77
|
+
else self.gl[type](loc, value)
|
|
89
78
|
})
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
79
|
+
},
|
|
80
|
+
_attribute(key: string, value: number[], iboValue?: number[]) {
|
|
81
|
+
self.frame(() => {
|
|
82
|
+
const loc = self.location(key, true)
|
|
83
|
+
const vbo = createVbo(self.gl, value)
|
|
84
|
+
const ibo = createIbo(self.gl, iboValue)
|
|
85
|
+
const stride = vertexStride(self.count, value, iboValue)
|
|
86
|
+
createAttribute(self.gl, stride, loc, vbo, ibo)
|
|
87
|
+
})
|
|
88
|
+
},
|
|
89
|
+
_texture(key: string, src: string) {
|
|
90
|
+
if (typeof window === 'undefined') return
|
|
94
91
|
const image = new Image()
|
|
95
|
-
image.addEventListener(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
image.addEventListener(
|
|
93
|
+
'load',
|
|
94
|
+
(_) => self.load(_, image),
|
|
95
|
+
false
|
|
96
|
+
)
|
|
97
|
+
Object.assign(image, {
|
|
98
|
+
src,
|
|
99
|
+
alt: key,
|
|
100
|
+
crossOrigin: 'anonymous',
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
resize(
|
|
104
|
+
_e: any,
|
|
105
|
+
width = window.innerWidth,
|
|
106
|
+
height = window.innerHeight
|
|
107
|
+
) {
|
|
108
|
+
self.size[0] = self.el.width = width
|
|
109
|
+
self.size[1] = self.el.height = height
|
|
110
|
+
self.uniform('iResolution', self.size)
|
|
111
|
+
},
|
|
112
|
+
mousemove(_e: any, x = _e.clientX, y = _e.clientY) {
|
|
113
|
+
const [w, h] = self.size
|
|
114
|
+
self.mouse[0] = (x - w / 2) / (w / 2)
|
|
115
|
+
self.mouse[1] = -(y - h / 2) / (h / 2)
|
|
116
|
+
self.uniform('iMouse', self.mouse)
|
|
117
|
+
},
|
|
118
|
+
load(_: any, image: any) {
|
|
119
|
+
self.frame(() => {
|
|
120
|
+
const loc = self.location(image.alt)
|
|
121
|
+
const unit = self.activeUnit(image.alt)
|
|
122
|
+
const texture = createTexture(self.gl, image)
|
|
123
|
+
self.frame(() => {
|
|
124
|
+
activeTexture(self.gl, loc, unit, texture)
|
|
125
|
+
return true
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
},
|
|
129
|
+
clear(key = 'COLOR_BUFFER_BIT') {
|
|
130
|
+
self.gl.clear(self.gl[key])
|
|
131
|
+
},
|
|
132
|
+
viewport(size: number[] = self.size) {
|
|
133
|
+
self.gl.viewport(0, 0, ...size)
|
|
134
|
+
},
|
|
135
|
+
drawArrays(mode = 'TRIANGLES') {
|
|
105
136
|
self.gl.drawArrays(self.gl[mode], 0, self.count)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
137
|
+
},
|
|
138
|
+
drawElements(mode = 'TRIANGLES', type = 'UNSIGNED_SHORT') {
|
|
139
|
+
self.gl.drawElements(
|
|
140
|
+
self.gl[mode],
|
|
141
|
+
self.count,
|
|
142
|
+
self.gl[type],
|
|
143
|
+
0
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
}) as GL
|
|
147
|
+
|
|
148
|
+
self.frame = queue()
|
|
149
|
+
self.texture = durable(self._texture)
|
|
150
|
+
self.uniform = durable(self._uniform)
|
|
151
|
+
self.attribute = durable(self._attribute)
|
|
152
|
+
|
|
153
|
+
// @TODO
|
|
154
|
+
// export const clone = gl.clone()
|
|
155
|
+
|
|
156
|
+
export { self as gl }
|
|
157
|
+
|
|
158
|
+
export default self
|
package/native.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react'
|
|
2
|
+
import { Dimensions } from 'react-native'
|
|
3
|
+
import { useMutable } from 'reev/react'
|
|
4
|
+
import { gl } from './index'
|
|
5
|
+
import { frame } from 'refr'
|
|
6
|
+
import type { GL } from './types'
|
|
7
|
+
import type { Fun } from 'refr'
|
|
8
|
+
|
|
9
|
+
export const useGLEvent = <T>(props: Partial<GL & T> = {}, self = gl) => {
|
|
10
|
+
const memo = useMutable(props) as Partial<GL>
|
|
11
|
+
return useMemo(() => self(memo), [])
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const useGL = (props: Partial<GL> = {}, self = gl) => {
|
|
15
|
+
const memo = useMutable(props) as Partial<GL>
|
|
16
|
+
return useGLEvent({
|
|
17
|
+
ref(gl: any) {
|
|
18
|
+
self(memo)
|
|
19
|
+
self.el = {}
|
|
20
|
+
self.gl = gl
|
|
21
|
+
self.mount()
|
|
22
|
+
},
|
|
23
|
+
mount() {
|
|
24
|
+
const {
|
|
25
|
+
drawingBufferWidth: width,
|
|
26
|
+
drawingBufferHeight: height,
|
|
27
|
+
} = self.gl
|
|
28
|
+
self.size = [width, height]
|
|
29
|
+
self.init()
|
|
30
|
+
self.resize(void 0, width, height)
|
|
31
|
+
Dimensions.addEventListener('change', self.change)
|
|
32
|
+
frame.start()
|
|
33
|
+
},
|
|
34
|
+
clean() {
|
|
35
|
+
frame.cancel()
|
|
36
|
+
},
|
|
37
|
+
change() {
|
|
38
|
+
const {
|
|
39
|
+
drawingBufferWidth: width,
|
|
40
|
+
drawingBufferHeight: height,
|
|
41
|
+
} = self.gl
|
|
42
|
+
self.resize(void 0, width, height)
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function useTexture(props: any, self = gl) {
|
|
48
|
+
return self.texture(props)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function useAttribute(props: any, self = gl) {
|
|
52
|
+
return self.attribute(props)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function useUniform(props: any, self = gl) {
|
|
56
|
+
return self.uniform(props)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function useFrame(fun: Fun, self = gl) {
|
|
60
|
+
const ref = useMutable(fun)
|
|
61
|
+
useEffect(() => self.frame(fun), [])
|
|
62
|
+
useEffect(() => () => self.frame(ref), [])
|
|
63
|
+
return self
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,43 +1,67 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
2
|
+
"name": "glre",
|
|
3
|
+
"author": "tseijp",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "0.14.0",
|
|
6
|
+
"module": "index.js",
|
|
7
|
+
"types": "index.ts",
|
|
8
|
+
"main": "index.cjs.js",
|
|
9
|
+
"umd": "index.develop.js",
|
|
10
|
+
"private": false,
|
|
11
|
+
"sideEffect": false,
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"reev": "0.10.0",
|
|
17
|
+
"refr": "0.3.0"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"glsl",
|
|
21
|
+
"webgl",
|
|
22
|
+
"hooks",
|
|
23
|
+
"react",
|
|
24
|
+
"reactjs",
|
|
25
|
+
"reactive",
|
|
26
|
+
"solid",
|
|
27
|
+
"solidjs",
|
|
28
|
+
"typescript"
|
|
29
|
+
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"expo": "*",
|
|
32
|
+
"expo-gl": "*",
|
|
33
|
+
"react": ">=16.8",
|
|
34
|
+
"react-dom": ">=16.8",
|
|
35
|
+
"solid-js": "*"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"expo": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"expo-gl": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"react": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"react-dom": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"solid-js": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
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
|
+
]
|
|
43
67
|
}
|
package/qwik.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useSignal, useVisibleTask$, $ } from '@builder.io/qwik'
|
|
2
|
+
import { gl } from './index'
|
|
3
|
+
import { frame } from 'refr'
|
|
4
|
+
import type { GL } from './types'
|
|
5
|
+
import type { Fun } from 'reev/types'
|
|
6
|
+
|
|
7
|
+
export function useGL(props?: any, self = $(gl) as unknown as GL) {
|
|
8
|
+
const ref = useSignal<Element>()
|
|
9
|
+
useVisibleTask$(({ cleanup }) => {
|
|
10
|
+
self(props)
|
|
11
|
+
self.el = self.target = ref.value
|
|
12
|
+
self.gl = self.target.getContext('webgl2')
|
|
13
|
+
self.init()
|
|
14
|
+
self.resize()
|
|
15
|
+
frame.start()
|
|
16
|
+
window.addEventListener('resize', self.resize)
|
|
17
|
+
window.addEventListener('mousemove', self.mousemove)
|
|
18
|
+
cleanup(() => {
|
|
19
|
+
self.clean()
|
|
20
|
+
window.removeEventListener('resize', self.resize)
|
|
21
|
+
window.removeEventListener('mousemove', self.mousemove)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
return self
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useTexture(props: any, self = gl) {
|
|
28
|
+
return self?.texture(props)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useAttribute(props: any, self = gl) {
|
|
32
|
+
return self.attribute(props)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function useUniform(props: any, self = gl) {
|
|
36
|
+
return self.uniform(props)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useFrame(fun: Fun, self = gl) {
|
|
40
|
+
useTask$(() => self.frame(fun))
|
|
41
|
+
return self
|
|
42
|
+
}
|
package/react.ts
CHANGED
|
@@ -1,40 +1,59 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo } from 'react'
|
|
1
2
|
import { gl } from './index'
|
|
3
|
+
import { frame } from 'refr'
|
|
4
|
+
import { mutable } from 'reev'
|
|
2
5
|
import type { GL } from './types'
|
|
3
|
-
import {
|
|
6
|
+
import type { Fun } from 'refr'
|
|
7
|
+
import type { MutableArgs } from 'reev/types'
|
|
4
8
|
|
|
5
|
-
export
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
return (gl.default = gl(target))
|
|
9
|
-
}, [target])
|
|
10
|
-
useEffect(() => void self.setConfig(config), [self, config])
|
|
11
|
-
useEffect(() => void self.event('mount'), [self])
|
|
12
|
-
useEffect(() => () => self.event('clean'), [self])
|
|
13
|
-
return self
|
|
9
|
+
export const useMutable = <T extends object>(...args: MutableArgs<T>) => {
|
|
10
|
+
const [memo] = useState(() => mutable<T>())
|
|
11
|
+
return memo(...args)
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
export const useGL = (props: Partial<GL> = {}, self = gl) => {
|
|
15
|
+
const memo1 = useMutable(props) as Partial<GL>
|
|
16
|
+
const memo2 = useMutable({
|
|
17
|
+
ref(target: unknown) {
|
|
18
|
+
if (target) {
|
|
19
|
+
self.target = target
|
|
20
|
+
self.mount()
|
|
21
|
+
} else self.clean()
|
|
22
|
+
},
|
|
23
|
+
mount() {
|
|
24
|
+
self.el = self.target
|
|
25
|
+
self.gl = self.target.getContext('webgl2')
|
|
26
|
+
self.init()
|
|
27
|
+
self.resize()
|
|
28
|
+
frame.start()
|
|
29
|
+
window.addEventListener('resize', self.resize)
|
|
30
|
+
window.addEventListener('mousemove', self.mousemove)
|
|
31
|
+
},
|
|
32
|
+
clean() {
|
|
33
|
+
frame.cancel()
|
|
34
|
+
window.removeEventListener('resize', self.resize)
|
|
35
|
+
window.removeEventListener('mousemove', self.mousemove)
|
|
36
|
+
},
|
|
37
|
+
}) as Partial<GL>
|
|
38
|
+
|
|
39
|
+
return useMemo(() => self(memo2)(memo1), [self, memo1, memo2])
|
|
19
40
|
}
|
|
20
41
|
|
|
21
|
-
export function
|
|
22
|
-
|
|
23
|
-
return self.setAttribute(props)
|
|
42
|
+
export function useTexture(props: any, self = gl) {
|
|
43
|
+
return self.texture(props)
|
|
24
44
|
}
|
|
25
45
|
|
|
26
|
-
export function
|
|
27
|
-
|
|
28
|
-
return self.setUniform(props)
|
|
46
|
+
export function useAttribute(props: any, self = gl) {
|
|
47
|
+
return self.attribute(props)
|
|
29
48
|
}
|
|
30
49
|
|
|
31
|
-
export function
|
|
32
|
-
|
|
33
|
-
const ref = useMutable(fun)
|
|
34
|
-
useEffect(() => void self.setFrame(ref), [ref, self])
|
|
50
|
+
export function useUniform(props: any, self = gl) {
|
|
51
|
+
return self.uniform(props)
|
|
35
52
|
}
|
|
36
53
|
|
|
37
|
-
export function
|
|
38
|
-
const ref =
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
export function useFrame(fun: Fun, self = gl) {
|
|
55
|
+
const ref = useMutable(fun)
|
|
56
|
+
useEffect(() => self.frame(fun), [])
|
|
57
|
+
useEffect(() => () => self.frame(ref), [])
|
|
58
|
+
return self
|
|
59
|
+
}
|
package/solid.ts
CHANGED
|
@@ -1,25 +1,45 @@
|
|
|
1
|
-
import { gl } from './index'
|
|
2
|
-
import type { GL } from './types'
|
|
3
1
|
import { onMount, onCleanup } from 'solid-js'
|
|
2
|
+
import { frame } from 'refr'
|
|
3
|
+
import { gl } from './index'
|
|
4
|
+
import type { Fun } from 'reev/types'
|
|
4
5
|
|
|
5
|
-
export function createGL(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export function createGL(props?: any, self = gl) {
|
|
7
|
+
onCleanup(self.clean)
|
|
8
|
+
|
|
9
|
+
return self({
|
|
10
|
+
ref(target: unknown) {
|
|
11
|
+
if (target) {
|
|
12
|
+
self.target = target
|
|
13
|
+
self.mount()
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
mount() {
|
|
17
|
+
self(props)
|
|
18
|
+
self.el = self.target
|
|
19
|
+
self.gl = self.target.getContext('webgl2')
|
|
20
|
+
self.init()
|
|
21
|
+
self.resize()
|
|
22
|
+
frame.start()
|
|
23
|
+
window.addEventListener('resize', self.resize)
|
|
24
|
+
window.addEventListener('mousemove', self.mousemove)
|
|
25
|
+
},
|
|
26
|
+
clean() {
|
|
27
|
+
self(props)
|
|
28
|
+
frame.cancel()
|
|
29
|
+
window.removeEventListener('resize', self.resize)
|
|
30
|
+
window.removeEventListener('mousemove', self.mousemove)
|
|
31
|
+
},
|
|
32
|
+
})
|
|
10
33
|
}
|
|
11
34
|
|
|
12
|
-
export function onFrame(fun:
|
|
13
|
-
|
|
14
|
-
onMount(() => self.setFrame(fun))
|
|
35
|
+
export function onFrame(fun: Fun, self = gl) {
|
|
36
|
+
onMount(() => self('render', fun))
|
|
15
37
|
}
|
|
16
38
|
|
|
17
|
-
export function setTexture(props, self
|
|
18
|
-
|
|
19
|
-
return self.setTexture(props)
|
|
39
|
+
export function setTexture(props: any, self = gl) {
|
|
40
|
+
return self.texture(props)
|
|
20
41
|
}
|
|
21
42
|
|
|
22
|
-
export function setAttribute(props, self
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
43
|
+
export function setAttribute(props: any, self = gl) {
|
|
44
|
+
return self.attribute(props)
|
|
45
|
+
}
|
package/types.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import type { Frame, Fun } from 'refr'
|
|
5
|
-
import type { Nested, Event } from 'reev'
|
|
1
|
+
import type { Queue } from 'refr/types'
|
|
2
|
+
import type { Nested, EventState } from 'reev/types'
|
|
6
3
|
|
|
7
4
|
export type Uniform = number | number[]
|
|
8
5
|
|
|
@@ -12,10 +9,7 @@ export type Attributes = Record<string, Attribute>
|
|
|
12
9
|
|
|
13
10
|
export type Uniforms = Record<string, Uniform>
|
|
14
11
|
|
|
15
|
-
export
|
|
16
|
-
(fun: Fun): GL
|
|
17
|
-
(shader: string): GL
|
|
18
|
-
(strings: TemplateStringsArray, ...args: any[]): GL
|
|
12
|
+
export type GL = EventState<{
|
|
19
13
|
/**
|
|
20
14
|
* initial value
|
|
21
15
|
*/
|
|
@@ -23,71 +17,69 @@ export interface GL {
|
|
|
23
17
|
size: [number, number]
|
|
24
18
|
mouse: [number, number]
|
|
25
19
|
count: number
|
|
26
|
-
|
|
20
|
+
vs: string
|
|
21
|
+
fs: string
|
|
27
22
|
vert: string
|
|
23
|
+
frag: string
|
|
24
|
+
vertex: string
|
|
25
|
+
fragment: string
|
|
28
26
|
int: PrecisionMode
|
|
29
27
|
float: PrecisionMode
|
|
30
28
|
sampler2D: PrecisionMode
|
|
31
29
|
samplerCube: PrecisionMode
|
|
32
30
|
lastActiveUnit: number
|
|
33
|
-
|
|
34
|
-
attributeHeader: [string, string][]
|
|
31
|
+
|
|
35
32
|
/**
|
|
36
33
|
* core state
|
|
37
34
|
*/
|
|
38
35
|
gl: any
|
|
39
36
|
pg: any
|
|
40
37
|
el: any
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
stride: Nested<number>
|
|
38
|
+
frame: Queue
|
|
39
|
+
target: any
|
|
40
|
+
stride: Nested<number>
|
|
41
|
+
// @TODO Nested<(key: string, value: number: number[], ibo: number[]) => number>
|
|
44
42
|
location: Nested<any>
|
|
45
43
|
activeUnit: Nested<number>
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
default: any
|
|
45
|
+
|
|
48
46
|
/**
|
|
49
|
-
*
|
|
47
|
+
* events
|
|
50
48
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
setFrame(frame: Fun): GL
|
|
54
|
-
setMount(frame: Fun): GL
|
|
55
|
-
setClean(frame: Fun): GL
|
|
56
|
-
setUniform(key: string, value: Uniform): GL
|
|
57
|
-
setTexture(key: string, value: string): GL
|
|
58
|
-
setAttribute(key: string, value: Attribute, iboValue?: Attribute): GL
|
|
59
|
-
setConfig<K extends keyof Partial<GL>>(key: K, value: GLConfig[K]): GL
|
|
60
|
-
// setUniform: Durable<(
|
|
61
|
-
// key: string,
|
|
62
|
-
// value: Uniform,
|
|
63
|
-
// isMatrix: boolean
|
|
64
|
-
// ) => GL>,
|
|
65
|
-
// setTexture: Durable<(
|
|
66
|
-
// key: string,
|
|
67
|
-
// value: string,
|
|
68
|
-
// activeUnit: number
|
|
69
|
-
// ) => GL>,
|
|
70
|
-
// setAttribute: Durable<(
|
|
71
|
-
// key: string,
|
|
72
|
-
// value: Attribute,
|
|
73
|
-
// iboValue: Attribute
|
|
74
|
-
// ) => GL>,
|
|
75
|
-
// setConfig: Durable<<K extends keyof GLConfig>(
|
|
76
|
-
// key: K,
|
|
77
|
-
// value: GLConfig[K]
|
|
78
|
-
// ) => GL>,
|
|
49
|
+
ref?: any
|
|
50
|
+
init(varying?: string[]): void
|
|
79
51
|
mount(): void
|
|
80
52
|
clean(): void
|
|
53
|
+
render(): void
|
|
54
|
+
mousemove(e: Event): void
|
|
55
|
+
resize(e?: Event, width?: number, height?: number): void
|
|
56
|
+
load(e?: Event, image?: HTMLImageElement): void
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* setter
|
|
60
|
+
*/
|
|
61
|
+
_uniform(key: string, value: Uniform): GL
|
|
62
|
+
uniform(key: string, value: Uniform): GL
|
|
63
|
+
uniform(target: { [key: string]: Uniform }): GL
|
|
64
|
+
_texture(key: string, value: string): GL
|
|
65
|
+
texture(key: string, value: string): GL
|
|
66
|
+
texture(target: { [key: string]: string }): GL
|
|
67
|
+
_attribute(key: string, value: Attribute, iboValue?: Attribute): GL
|
|
68
|
+
attribute(key: string, value: Attribute, iboValue?: Attribute): GL
|
|
69
|
+
attribute(target: { [key: string]: Attribute }): GL
|
|
70
|
+
// config(key?: keyof GL, value?: GL[keyof GL]): GL
|
|
71
|
+
// config(target?: Partial<GL>): GL
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* short hands
|
|
75
|
+
*/
|
|
81
76
|
clear(key?: GLClearMode): void
|
|
82
77
|
viewport(size?: [number, number]): void
|
|
83
78
|
drawArrays(key?: GLDrawMode): void
|
|
84
79
|
drawElements(key?: GLDrawMode): void
|
|
85
|
-
}
|
|
80
|
+
}>
|
|
86
81
|
|
|
87
|
-
export type PrecisionMode =
|
|
88
|
-
| 'highp'
|
|
89
|
-
| 'mediump'
|
|
90
|
-
| 'lowp'
|
|
82
|
+
export type PrecisionMode = 'highp' | 'mediump' | 'lowp'
|
|
91
83
|
|
|
92
84
|
export type GLClearMode =
|
|
93
85
|
| 'COLOR_BUFFER_BIT'
|
|
@@ -103,7 +95,4 @@ export type GLDrawMode =
|
|
|
103
95
|
| 'TRIANGLE_FAN'
|
|
104
96
|
| 'TRIANGLES'
|
|
105
97
|
|
|
106
|
-
export type GLDrawType =
|
|
107
|
-
| 'UNSIGNED_BYTE'
|
|
108
|
-
| 'UNSIGNED_SHORT'
|
|
109
|
-
| 'UNSIGNED_INT'
|
|
98
|
+
export type GLDrawType = 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT' | 'UNSIGNED_INT'
|
package/utils.ts
CHANGED
|
@@ -1,42 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* utils
|
|
3
3
|
*/
|
|
4
|
-
export function
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export function uniformType(value: number | number[], isMatrix = false) {
|
|
5
|
+
let length = typeof value === 'number' ? 0 : value?.length
|
|
6
|
+
if (!length) return `uniform1f`
|
|
7
|
+
if (!isMatrix) return `uniform${length}fv`
|
|
8
|
+
length = Math.sqrt(length) << 0
|
|
9
|
+
return `uniformMatrix${length}fv`
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function concat(source: string, target: string, key = "") {
|
|
22
|
-
if (key === "" || include(source, key))
|
|
23
|
-
if (!include(source, target))
|
|
24
|
-
return target + source
|
|
25
|
-
return source
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function switchUniformType(value: unknown, isMatrix = false) {
|
|
29
|
-
let length = typeof value === "number" ? 0 : (value as any[]).length
|
|
30
|
-
if (!length) return [`uniform1f`, `float`]
|
|
31
|
-
if (!isMatrix) return [`uniform${length}fv`, `vec${length}`]
|
|
32
|
-
length = Math.sqrt(length) << 0;
|
|
33
|
-
return [`uniformMatrix${length}fv`, `mat${length}`]
|
|
12
|
+
export function vertexStride(
|
|
13
|
+
count: number,
|
|
14
|
+
value: number[],
|
|
15
|
+
iboValue?: number[]
|
|
16
|
+
) {
|
|
17
|
+
if (iboValue) count = Math.max(...iboValue) + 1
|
|
18
|
+
const stride = value.length / count
|
|
19
|
+
if (stride !== stride << 0)
|
|
20
|
+
console.warn(`Vertex Stride Error: count ${count} is mismatch`)
|
|
21
|
+
return stride << 0
|
|
34
22
|
}
|
|
35
23
|
|
|
36
24
|
/**
|
|
37
25
|
* graphics
|
|
38
26
|
*/
|
|
39
|
-
export function createShader(gl, source, type) {
|
|
27
|
+
export function createShader(gl: any, source: string, type: unknown) {
|
|
40
28
|
const shader = gl.createShader(type)
|
|
41
29
|
gl.shaderSource(shader, source)
|
|
42
30
|
gl.compileShader(shader)
|
|
@@ -45,7 +33,7 @@ export function createShader(gl, source, type) {
|
|
|
45
33
|
} else console.warn(gl.getShaderInfoLog(shader))
|
|
46
34
|
}
|
|
47
35
|
|
|
48
|
-
export function createProgram(gl, vs, fs) {
|
|
36
|
+
export function createProgram(gl: any, vs: any, fs: any) {
|
|
49
37
|
const program = gl.createProgram()
|
|
50
38
|
gl.attachShader(program, vs)
|
|
51
39
|
gl.attachShader(program, fs)
|
|
@@ -59,7 +47,22 @@ export function createProgram(gl, vs, fs) {
|
|
|
59
47
|
}
|
|
60
48
|
}
|
|
61
49
|
|
|
62
|
-
export function
|
|
50
|
+
export function createTfProgram(gl: any, vs: any, fs: any, varyings?: any) {
|
|
51
|
+
const pg = gl.createProgram()
|
|
52
|
+
gl.attachShader(pg, vs)
|
|
53
|
+
gl.attachShader(pg, fs)
|
|
54
|
+
gl.transformFeedbackVaryings(pg, varyings, gl.SEPARATE_ATTRIBS)
|
|
55
|
+
gl.linkProgram(pg)
|
|
56
|
+
if (gl.getProgramParameter(pg, gl.LINK_STATUS)) {
|
|
57
|
+
gl.useProgram(pg)
|
|
58
|
+
return pg
|
|
59
|
+
} else {
|
|
60
|
+
console.warn(gl.getProgramInfoLog(pg))
|
|
61
|
+
return null
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createVbo(gl: any, data: number[]) {
|
|
63
66
|
if (!data) return
|
|
64
67
|
const vbo = gl.createBuffer()
|
|
65
68
|
gl.bindBuffer(gl.ARRAY_BUFFER, vbo)
|
|
@@ -68,62 +71,121 @@ export function createVbo(gl, data) {
|
|
|
68
71
|
return vbo
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
export function createIbo(gl, data) {
|
|
74
|
+
export function createIbo(gl: any, data?: number[]) {
|
|
72
75
|
if (!data) return
|
|
73
76
|
const ibo = gl.createBuffer()
|
|
74
77
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo)
|
|
75
|
-
gl.bufferData(
|
|
78
|
+
gl.bufferData(
|
|
79
|
+
gl.ELEMENT_ARRAY_BUFFER,
|
|
80
|
+
new Int16Array(data),
|
|
81
|
+
gl.STATIC_DRAW
|
|
82
|
+
)
|
|
76
83
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null)
|
|
77
84
|
return ibo
|
|
78
85
|
}
|
|
79
86
|
|
|
80
|
-
export function createAttribute(
|
|
81
|
-
gl
|
|
87
|
+
export function createAttribute(
|
|
88
|
+
gl: any,
|
|
89
|
+
stride: number,
|
|
90
|
+
location: any,
|
|
91
|
+
vbo: any,
|
|
92
|
+
ibo: any
|
|
93
|
+
) {
|
|
94
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo)
|
|
82
95
|
gl.enableVertexAttribArray(location)
|
|
83
96
|
gl.vertexAttribPointer(location, stride, gl.FLOAT, false, 0, 0)
|
|
84
|
-
if (
|
|
85
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, createIbo(gl, iboValue))
|
|
97
|
+
if (ibo) gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo)
|
|
86
98
|
}
|
|
87
99
|
|
|
88
|
-
export function createFramebuffer(gl, width, height) {
|
|
100
|
+
export function createFramebuffer(gl: any, width: number, height: number) {
|
|
89
101
|
const frameBuffer = gl.createFramebuffer()
|
|
90
102
|
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer)
|
|
91
103
|
const renderBuffer = gl.createRenderbuffer()
|
|
92
104
|
gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer)
|
|
93
|
-
gl.renderbufferStorage(
|
|
94
|
-
|
|
105
|
+
gl.renderbufferStorage(
|
|
106
|
+
gl.RENDERBUFFER,
|
|
107
|
+
gl.DEPTH_COMPONENT16,
|
|
108
|
+
width,
|
|
109
|
+
height
|
|
110
|
+
)
|
|
111
|
+
gl.framebufferRenderbuffer(
|
|
112
|
+
gl.FRAMEBUFFER,
|
|
113
|
+
gl.DEPTH_ATTACHMENT,
|
|
114
|
+
gl.RENDERBUFFER,
|
|
115
|
+
renderBuffer
|
|
116
|
+
)
|
|
95
117
|
const texture = gl.createTexture()
|
|
96
118
|
gl.bindTexture(gl.TEXTURE_2D, texture)
|
|
97
|
-
gl.texImage2D(
|
|
119
|
+
gl.texImage2D(
|
|
120
|
+
gl.TEXTURE_2D,
|
|
121
|
+
0,
|
|
122
|
+
gl.RGBA,
|
|
123
|
+
width,
|
|
124
|
+
height,
|
|
125
|
+
0,
|
|
126
|
+
gl.RGBA,
|
|
127
|
+
gl.UNSIGNED_BYTE,
|
|
128
|
+
null
|
|
129
|
+
)
|
|
98
130
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
|
|
99
131
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
|
|
100
132
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
|
|
101
133
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
|
|
102
|
-
gl.framebufferTexture2D(
|
|
134
|
+
gl.framebufferTexture2D(
|
|
135
|
+
gl.FRAMEBUFFER,
|
|
136
|
+
gl.COLOR_ATTACHMENT0,
|
|
137
|
+
gl.TEXTURE_2D,
|
|
138
|
+
texture,
|
|
139
|
+
0
|
|
140
|
+
)
|
|
103
141
|
gl.bindTexture(gl.TEXTURE_2D, null)
|
|
104
142
|
gl.bindRenderbuffer(gl.RENDERBUFFER, null)
|
|
105
143
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
|
|
106
144
|
return { frameBuffer, renderBuffer, texture }
|
|
107
145
|
}
|
|
108
146
|
|
|
109
|
-
export function createFramebufferFloat(
|
|
110
|
-
|
|
147
|
+
export function createFramebufferFloat(
|
|
148
|
+
gl: any,
|
|
149
|
+
ext: any,
|
|
150
|
+
width: number,
|
|
151
|
+
height: number
|
|
152
|
+
) {
|
|
153
|
+
const flg =
|
|
154
|
+
ext.textureFloat != null
|
|
155
|
+
? gl.FLOAT
|
|
156
|
+
: ext.textureHalfFloat.HALF_FLOAT_OES
|
|
111
157
|
const frameBuffer = gl.createFramebuffer()
|
|
112
158
|
const texture = gl.createTexture()
|
|
113
159
|
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer)
|
|
114
160
|
gl.bindTexture(gl.TEXTURE_2D, texture)
|
|
115
|
-
gl.texImage2D(
|
|
161
|
+
gl.texImage2D(
|
|
162
|
+
gl.TEXTURE_2D,
|
|
163
|
+
0,
|
|
164
|
+
gl.RGBA,
|
|
165
|
+
width,
|
|
166
|
+
height,
|
|
167
|
+
0,
|
|
168
|
+
gl.RGBA,
|
|
169
|
+
flg,
|
|
170
|
+
null
|
|
171
|
+
)
|
|
116
172
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
|
|
117
173
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
|
|
118
174
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
|
|
119
175
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
|
|
120
|
-
gl.framebufferTexture2D(
|
|
176
|
+
gl.framebufferTexture2D(
|
|
177
|
+
gl.FRAMEBUFFER,
|
|
178
|
+
gl.COLOR_ATTACHMENT0,
|
|
179
|
+
gl.TEXTURE_2D,
|
|
180
|
+
texture,
|
|
181
|
+
0
|
|
182
|
+
)
|
|
121
183
|
gl.bindTexture(gl.TEXTURE_2D, null)
|
|
122
184
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
|
|
123
185
|
return { frameBuffer, texture }
|
|
124
186
|
}
|
|
125
187
|
|
|
126
|
-
export function createTexture(gl, img) {
|
|
188
|
+
export function createTexture(gl: any, img: any) {
|
|
127
189
|
const texture = gl.createTexture()
|
|
128
190
|
gl.bindTexture(gl.TEXTURE_2D, texture)
|
|
129
191
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img)
|
|
@@ -134,4 +196,15 @@ export function createTexture(gl, img) {
|
|
|
134
196
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
|
|
135
197
|
gl.bindTexture(gl.TEXTURE_2D, null)
|
|
136
198
|
return texture
|
|
137
|
-
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function activeTexture(
|
|
202
|
+
gl: any,
|
|
203
|
+
location: any,
|
|
204
|
+
activeUnit: any,
|
|
205
|
+
texture: any
|
|
206
|
+
) {
|
|
207
|
+
gl.uniform1i(location, activeUnit)
|
|
208
|
+
gl.activeTexture(gl['TEXTURE' + activeUnit])
|
|
209
|
+
gl.bindTexture(gl.TEXTURE_2D, texture)
|
|
210
|
+
}
|
package/events.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { event } from 'reev'
|
|
2
|
-
import { createProgram, createShader, createTexture, concat } from './utils'
|
|
3
|
-
import type { GL } from './types'
|
|
4
|
-
|
|
5
|
-
export const glEvent = (self: GL) =>
|
|
6
|
-
event({
|
|
7
|
-
// run if canvas is mounted
|
|
8
|
-
mount(e) {
|
|
9
|
-
// @TODO abbreviate to import uniform
|
|
10
|
-
// self.uniformHeader.map(([key, header]) => self.frag = concat(self.frag, header, key))
|
|
11
|
-
// self.uniformHeader.map(([key, header]) => self.frag = concat(self.vert, header, key))
|
|
12
|
-
// self.attributeHeader.map(([key, header]) => self.vert = concat(self.vert, header, key))
|
|
13
|
-
if (self.int) self.frag = concat(self.frag, `precision ${self.int} int;`)
|
|
14
|
-
if (self.float) self.frag = concat(self.frag, `precision ${self.float} float;`)
|
|
15
|
-
if (self.sampler2D) self.frag = concat(self.frag, `precision ${self.sampler2D} sampler2D;`)
|
|
16
|
-
if (self.samplerCube) self.frag = concat(self.frag, `precision ${self.samplerCube} samplerCube;`)
|
|
17
|
-
const el = (self.el = document.getElementById(self.id)) // @ts-ignore
|
|
18
|
-
const gl = (self.gl = el?.getContext('webgl'))
|
|
19
|
-
const frag = createShader(gl, self.frag, gl?.FRAGMENT_SHADER)
|
|
20
|
-
const vert = createShader(gl, self.vert, gl?.VERTEX_SHADER)
|
|
21
|
-
self.pg = createProgram(gl, vert, frag) // !!!
|
|
22
|
-
window.addEventListener('resize', e.on('resize'))
|
|
23
|
-
window.addEventListener('mousemove', e.on('mousemove'))
|
|
24
|
-
e('resize')
|
|
25
|
-
let iTime = performance.now(), iPrevTime = 0, iDeltaTime = 0;
|
|
26
|
-
self.setFrame(() => {
|
|
27
|
-
iPrevTime = iTime
|
|
28
|
-
iTime = performance.now() / 1000
|
|
29
|
-
iDeltaTime = iTime - iPrevTime
|
|
30
|
-
self.setUniform({ iTime, iPrevTime, iDeltaTime })
|
|
31
|
-
return true;
|
|
32
|
-
})
|
|
33
|
-
self.frame()
|
|
34
|
-
},
|
|
35
|
-
// run if canvas is cleaned
|
|
36
|
-
clean(e) {
|
|
37
|
-
window.removeEventListener('resize', e.on('resize'))
|
|
38
|
-
window.removeEventListener('mousemove', e.on('mousemove'))
|
|
39
|
-
self.frame.cancel()
|
|
40
|
-
},
|
|
41
|
-
// user mousemove event
|
|
42
|
-
mousemove(_e, { clientX, clientY }) {
|
|
43
|
-
const [w, h] = self.size
|
|
44
|
-
self.mouse[0] = (clientX - w / 2) / (w / 2)
|
|
45
|
-
self.mouse[1] = -(clientY - h / 2) / (h / 2)
|
|
46
|
-
self.setUniform('iMouse', self.mouse)
|
|
47
|
-
},
|
|
48
|
-
// user mousemove event
|
|
49
|
-
resize(_e, _resizeEvent, width = 0, height = 0) {
|
|
50
|
-
self.size[0] = self.el.width = width || window.innerWidth
|
|
51
|
-
self.size[1] = self.el.height = height || window.innerHeight
|
|
52
|
-
self.setUniform('iResolution', self.size)
|
|
53
|
-
},
|
|
54
|
-
// load image event
|
|
55
|
-
load(_e, _loadEvent, image) {
|
|
56
|
-
self.setFrame(() => {
|
|
57
|
-
const activeUnit = self.activeUnit(image.alt)
|
|
58
|
-
const location = self.location(image.alt)
|
|
59
|
-
const texture = createTexture(self.gl, image)
|
|
60
|
-
self.setFrame(() => {
|
|
61
|
-
self.gl.uniform1i(location, activeUnit)
|
|
62
|
-
self.gl.activeTexture(self.gl['TEXTURE' + activeUnit])
|
|
63
|
-
self.gl.bindTexture(self.gl.TEXTURE_2D, texture)
|
|
64
|
-
return true
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
} as any)
|