glre 0.45.0 → 0.47.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 (52) hide show
  1. package/README.md +4 -26
  2. package/dist/addons.d.ts +35 -50
  3. package/dist/index.cjs +6 -6
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +37 -90
  6. package/dist/index.js +6 -6
  7. package/dist/index.js.map +1 -1
  8. package/dist/native.cjs +1 -1
  9. package/dist/native.cjs.map +1 -1
  10. package/dist/native.d.ts +45 -93
  11. package/dist/native.js +1 -1
  12. package/dist/native.js.map +1 -1
  13. package/dist/node.cjs +15 -15
  14. package/dist/node.cjs.map +1 -1
  15. package/dist/node.d.ts +35 -50
  16. package/dist/node.js +15 -15
  17. package/dist/node.js.map +1 -1
  18. package/dist/react.cjs +1 -1
  19. package/dist/react.cjs.map +1 -1
  20. package/dist/react.d.ts +37 -91
  21. package/dist/react.js +1 -1
  22. package/dist/react.js.map +1 -1
  23. package/dist/solid.cjs +1 -1
  24. package/dist/solid.cjs.map +1 -1
  25. package/dist/solid.d.ts +37 -91
  26. package/dist/solid.js +1 -1
  27. package/dist/solid.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/{utils/helpers.ts → helpers.ts} +10 -32
  30. package/src/index.ts +45 -42
  31. package/src/native.ts +6 -7
  32. package/src/node/build.ts +3 -19
  33. package/src/node/create.ts +2 -4
  34. package/src/node/index.ts +8 -20
  35. package/src/node/types.ts +2 -0
  36. package/src/node/utils/index.ts +5 -2
  37. package/src/node/utils/infer.ts +5 -13
  38. package/src/node/utils/parse.ts +18 -34
  39. package/src/node/utils/utils.ts +15 -10
  40. package/src/react.ts +9 -12
  41. package/src/solid.ts +3 -10
  42. package/src/types.ts +30 -22
  43. package/src/webgl/compute.ts +56 -0
  44. package/src/webgl/graphic.ts +65 -0
  45. package/src/webgl/index.ts +21 -0
  46. package/src/{utils/program.ts → webgl/utils.ts} +30 -8
  47. package/src/webgpu/compute.ts +39 -0
  48. package/src/webgpu/graphic.ts +89 -0
  49. package/src/webgpu/index.ts +42 -0
  50. package/src/{utils/pipeline.ts → webgpu/utils.ts} +75 -78
  51. package/src/utils/webgl.ts +0 -135
  52. package/src/utils/webgpu.ts +0 -178
package/dist/react.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var c=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},l=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of L(e))!G.call(t,n)&&n!==r&&f(t,n,{get:()=>e[n],enumerable:!(i=u(e,n))||i.enumerable});return t},m=(t,e,r)=>(l(t,e,"default"),r&&l(r,e,"default"));var p=t=>l(f({},"__esModule",{value:!0}),t);var o={};c(o,{useGL:()=>x});module.exports=p(o);var s=require("react"),a=require("./index.cjs");m(o,require("./index.cjs"),module.exports);var x=(t={})=>(0,s.useState)(()=>{let e=(0,a.isGL)(t)?t:(0,a.createGL)(t);return e.ref=r=>{r?(e.el=r,e.mount()):e.clean()},e})[0];0&&(module.exports={useGL,...require("./index.cjs")});
1
+ "use strict";var i=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var s=(r,t)=>{for(var o in t)i(r,o,{get:t[o],enumerable:!0})},f=(r,t,o,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of c(t))!l.call(r,p)&&p!==o&&i(r,p,{get:()=>t[p],enumerable:!(u=L(t,p))||u.enumerable});return r},m=(r,t,o)=>(f(r,t,"default"),o&&f(o,t,"default"));var w=r=>f(i({},"__esModule",{value:!0}),r);var e={};s(e,{useGL:()=>x});module.exports=w(e);var n=require("react"),G=require("./index.cjs");m(e,require("./index.cjs"),module.exports);var x=(...r)=>{let[,t]=(0,n.useState)(null);return r[0]&&!r[0].error&&(r[0].error=(o="")=>t(()=>{throw new Error(o)})),(0,n.useState)(()=>(0,G.createGL)(...r))[0]};0&&(module.exports={useGL,...require("./index.cjs")});
2
2
  //# sourceMappingURL=react.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/react.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createGL, isGL } from './index'\nimport type { GL } from './types'\nexport * from './index'\n\nexport const useGL = (props: Partial<GL> = {}) => {\n return useState(() => {\n const gl = isGL(props) ? props : createGL(props)\n gl.ref = (el: HTMLCanvasElement | null) => {\n if (el) {\n gl.el = el\n gl.mount()\n } else gl.clean()\n }\n return gl\n })[0]\n}\n"],"mappings":"2dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyB,iBACzBC,EAA+B,uBAE/BC,EAAAN,EAAc,uBAHd,gBAKO,IAAME,EAAQ,CAACK,EAAqB,CAAC,OAC7B,YAAS,IAAM,CACd,IAAMC,KAAK,QAAKD,CAAK,EAAIA,KAAQ,YAASA,CAAK,EAC/C,OAAAC,EAAG,IAAOC,GAAiC,CAC/BA,GACID,EAAG,GAAKC,EACRD,EAAG,MAAM,GACVA,EAAG,MAAM,CACxB,EACOA,CACf,CAAC,EAAE,CAAC","names":["react_exports","__export","useGL","__toCommonJS","import_react","import_index","__reExport","props","gl","el"]}
1
+ {"version":3,"sources":["../src/react.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createGL } from './index'\nimport type { GL } from './types'\nexport * from './index'\n\nexport const useGL = (...args: Partial<GL>[]) => {\n const [, set] = useState(null) // for error boundary // ref: https://github.com/facebook/react/issues/14981\n if (args[0] && !args[0].error)\n args[0].error = (error = '') =>\n set(() => {\n throw new Error(error)\n })\n return useState(() => createGL(...args))[0]\n}\n"],"mappings":"2dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyB,iBACzBC,EAAyB,uBAEzBC,EAAAN,EAAc,uBAHd,gBAKO,IAAME,EAAQ,IAAIK,IAAwB,CACzC,GAAM,CAAC,CAAEC,CAAG,KAAI,YAAS,IAAI,EAC7B,OAAID,EAAK,CAAC,GAAK,CAACA,EAAK,CAAC,EAAE,QAChBA,EAAK,CAAC,EAAE,MAAQ,CAACE,EAAQ,KACjBD,EAAI,IAAM,CACF,MAAM,IAAI,MAAMC,CAAK,CAC7B,CAAC,MACV,YAAS,OAAM,YAAS,GAAGF,CAAI,CAAC,EAAE,CAAC,CAClD","names":["react_exports","__export","useGL","__toCommonJS","import_react","import_index","__reExport","args","set","error"]}
package/dist/react.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as reev from 'reev';
2
- import { EventState, Nested } from 'reev';
3
- import * as refr from 'refr';
2
+ import { EventState } from 'reev';
4
3
  import { Queue, Frame } from 'refr';
5
4
 
6
5
  declare const CONVERSIONS: readonly ["toBool", "toUInt", "toInt", "toFloat", "toBVec2", "toIVec2", "toUVec2", "toVec2", "toBVec3", "toIVec3", "toUVec3", "toVec3", "toBVec4", "toIVec4", "toUVec4", "toVec4", "toColor", "toMat2", "toMat3", "toMat4"];
@@ -70,6 +69,28 @@ declare const OPERATOR_TYPE_RULES: readonly [readonly ["float", "vec2", "vec2"],
70
69
  */
71
70
  declare const FUNCTIONS: readonly [...("texture" | "all" | "any" | "determinant" | "distance" | "dot" | "length" | "lengthSq" | "luminance" | "cross" | "cubeTexture" | "texelFetch" | "textureLod")[], "abs", "acos", "acosh", "asin", "asinh", "atan", "atanh", "ceil", "cos", "cosh", "dFdx", "dFdy", "degrees", "exp", "exp2", "floor", "fract", "fwidth", "inverse", "inverseSqrt", "log", "log2", "negate", "normalize", "oneMinus", "radians", "reciprocal", "round", "sign", "sin", "sinh", "sqrt", "tan", "tanh", "trunc", "saturate", "atan2", "clamp", "max", "min", "mix", "pow", "reflect", "refract", "smoothstep", "step"];
72
71
 
72
+ /**
73
+ * binding
74
+ */
75
+ declare const createBinding: () => {
76
+ uniform: reev.Nested<{
77
+ group: number;
78
+ binding: number;
79
+ }, []>;
80
+ texture: reev.Nested<{
81
+ group: number;
82
+ binding: number;
83
+ }, []>;
84
+ storage: reev.Nested<{
85
+ group: number;
86
+ binding: number;
87
+ }, []>;
88
+ attrib: reev.Nested<{
89
+ location: number;
90
+ }, []>;
91
+ };
92
+ type Binding = ReturnType<typeof createBinding>;
93
+
73
94
  type Constants = (typeof CONSTANTS)[number] | 'void';
74
95
  type Conversions = (typeof CONVERSIONS)[number];
75
96
  type Functions = (typeof FUNCTIONS)[number];
@@ -102,6 +123,7 @@ interface NodeProps {
102
123
  }
103
124
  interface NodeContext {
104
125
  gl?: Partial<GL>;
126
+ binding?: Binding;
105
127
  label?: 'vert' | 'frag' | 'compute';
106
128
  isWebGL?: boolean;
107
129
  units?: any;
@@ -397,16 +419,17 @@ type GL = EventState<{
397
419
  isDebug: boolean;
398
420
  isDepth: boolean;
399
421
  wireframe: boolean;
400
- isGL: true;
401
422
  width?: number;
402
423
  height?: number;
403
424
  size: [number, number];
404
425
  mouse: [number, number];
405
426
  count: number;
427
+ triangleCount: number;
406
428
  instanceCount: number;
407
429
  particleCount: number | [number, number] | [number, number, number];
408
430
  precision: 'lowp' | 'mediump' | 'highp';
409
- loading: number;
431
+ element?: HTMLCanvasElement;
432
+ elem?: HTMLCanvasElement;
410
433
  el: HTMLCanvasElement;
411
434
  vs?: string | Vec4;
412
435
  cs?: string | Void;
@@ -417,11 +440,16 @@ type GL = EventState<{
417
440
  vertex?: string | Vec4;
418
441
  compute?: string | Void;
419
442
  fragment?: string | Vec4;
443
+ program: WebGLProgram;
444
+ gl: WebGL2RenderingContext;
445
+ gpu: GPUCanvasContext;
446
+ device: GPUDevice;
447
+ format: GPUTextureFormat;
448
+ encoder: GPUCommandEncoder;
449
+ binding: Binding;
420
450
  /**
421
451
  * core state
422
452
  */
423
- webgpu: WebGPUState;
424
- webgl: WebGLState;
425
453
  queue: Queue;
426
454
  frame: Frame;
427
455
  /**
@@ -434,7 +462,6 @@ type GL = EventState<{
434
462
  render(): void;
435
463
  resize(e?: Event): void;
436
464
  mousemove(e: MouseEvent): void;
437
- loop(): void;
438
465
  /**
439
466
  * setter
440
467
  */
@@ -497,92 +524,11 @@ interface StorageData {
497
524
  binding: number;
498
525
  group: number;
499
526
  }
500
- interface WebGPUState {
501
- device: GPUDevice;
502
- uniforms: Nested<UniformData>;
503
- textures: Nested<TextureData>;
504
- attribs: Nested<AttribData>;
505
- storages: Nested<StorageData>;
506
- }
507
- /**
508
- * for webgl
509
- */
510
- interface WebGLState {
511
- context: WebGL2RenderingContext;
512
- program: WebGLProgram;
513
- uniforms: Nested<WebGLUniformLocation | null>;
514
- }
515
527
 
516
- declare const isGL: (a: unknown) => a is EventState<GL>;
517
528
  declare const isServer: () => boolean;
518
529
  declare const isWebGPUSupported: () => boolean;
519
- declare const createGL: (props?: Partial<GL>) => EventState<{
520
- isNative: boolean;
521
- isWebGL: boolean;
522
- isError: boolean;
523
- isLoop: boolean;
524
- isDebug: boolean;
525
- isDepth: boolean;
526
- wireframe: boolean;
527
- isGL: true;
528
- width?: number;
529
- height?: number;
530
- size: [number, number];
531
- mouse: [number, number];
532
- count: number;
533
- instanceCount: number;
534
- particleCount: number | [number, number] | [number, number, number];
535
- precision: "lowp" | "mediump" | "highp";
536
- loading: number;
537
- el: HTMLCanvasElement;
538
- vs?: string | Vec4;
539
- cs?: string | Void;
540
- fs?: string | Vec4;
541
- vert?: string | Vec4;
542
- comp?: string | Void;
543
- frag?: string | Vec4;
544
- vertex?: string | Vec4;
545
- compute?: string | Void;
546
- fragment?: string | Vec4;
547
- webgpu: WebGPUState;
548
- webgl: WebGLState;
549
- queue: refr.Queue;
550
- frame: refr.Frame;
551
- ref?: any;
552
- mount(): void;
553
- clean(): void;
554
- error(e?: string): void;
555
- render(): void;
556
- resize(e?: Event): void;
557
- mousemove(e: MouseEvent): void;
558
- loop(): void;
559
- _uniform?(key: string, value: number | number[] | Float32Array<ArrayBufferLike>, isMatrix?: boolean): GL;
560
- uniform(key: string, value: number | number[] | Float32Array<ArrayBufferLike>, isMatrix?: boolean): GL;
561
- uniform(target: {
562
- [key: string]: number | number[] | Float32Array<ArrayBufferLike>;
563
- }): GL;
564
- _texture?(key: string, value: string | HTMLImageElement | HTMLVideoElement): GL;
565
- texture(key: string, value: string | HTMLImageElement | HTMLVideoElement): GL;
566
- texture(target: {
567
- [key: string]: string | HTMLImageElement | HTMLVideoElement;
568
- }): GL;
569
- _attribute?(key: string, value: number[] | Float32Array<ArrayBufferLike>, iboValue?: number[] | Float32Array<ArrayBufferLike>): GL;
570
- attribute(key: string, value: number[] | Float32Array<ArrayBufferLike>, iboValue?: number[] | Float32Array<ArrayBufferLike>): GL;
571
- attribute(target: {
572
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
573
- }): GL;
574
- _instance?(key: string, value: number[] | Float32Array<ArrayBufferLike>, at?: number): GL;
575
- instance(key: string, value: number[] | Float32Array<ArrayBufferLike>, at?: number): GL;
576
- instance(target: {
577
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
578
- }): GL;
579
- _storage?(key: string, value: number[] | Float32Array<ArrayBufferLike>): GL;
580
- storage(key: string, value: number[] | Float32Array<ArrayBufferLike>): GL;
581
- storage(target: {
582
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
583
- }): GL;
584
- }, any[] | unknown[]>;
530
+ declare const createGL: (...args: Partial<GL>[]) => EventState<GL>;
585
531
 
586
- declare const useGL: (props?: Partial<GL>) => reev.EventState<GL>;
532
+ declare const useGL: (...args: Partial<GL>[]) => reev.EventState<GL>;
587
533
 
588
- export { type AttribData, type GL, type StorageData, type TextureData, type UniformData, type WebGLState, type WebGPUState, createGL, isGL, isServer, isWebGPUSupported, useGL };
534
+ export { type AttribData, type GL, type StorageData, type TextureData, type UniformData, createGL, isServer, isWebGPUSupported, useGL };
package/dist/react.js CHANGED
@@ -1,2 +1,2 @@
1
- import{useState as o}from"react";import{createGL as m,isGL as n}from"./index.js";export*from"./index.js";var f=(t={})=>o(()=>{let e=n(t)?t:m(t);return e.ref=r=>{r?(e.el=r,e.mount()):e.clean()},e})[0];export{f as useGL};
1
+ import{useState as t}from"react";import{createGL as m}from"./index.js";export*from"./index.js";var i=(...r)=>{let[,o]=t(null);return r[0]&&!r[0].error&&(r[0].error=(e="")=>o(()=>{throw new Error(e)})),t(()=>m(...r))[0]};export{i as useGL};
2
2
  //# sourceMappingURL=react.js.map
package/dist/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/react.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createGL, isGL } from './index'\nimport type { GL } from './types'\nexport * from './index'\n\nexport const useGL = (props: Partial<GL> = {}) => {\n return useState(() => {\n const gl = isGL(props) ? props : createGL(props)\n gl.ref = (el: HTMLCanvasElement | null) => {\n if (el) {\n gl.el = el\n gl.mount()\n } else gl.clean()\n }\n return gl\n })[0]\n}\n"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,QACzB,OAAS,YAAAC,EAAU,QAAAC,MAAY,aAE/B,WAAc,aAEP,IAAMC,EAAQ,CAACC,EAAqB,CAAC,IAC7BJ,EAAS,IAAM,CACd,IAAMK,EAAKH,EAAKE,CAAK,EAAIA,EAAQH,EAASG,CAAK,EAC/C,OAAAC,EAAG,IAAOC,GAAiC,CAC/BA,GACID,EAAG,GAAKC,EACRD,EAAG,MAAM,GACVA,EAAG,MAAM,CACxB,EACOA,CACf,CAAC,EAAE,CAAC","names":["useState","createGL","isGL","useGL","props","gl","el"]}
1
+ {"version":3,"sources":["../src/react.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createGL } from './index'\nimport type { GL } from './types'\nexport * from './index'\n\nexport const useGL = (...args: Partial<GL>[]) => {\n const [, set] = useState(null) // for error boundary // ref: https://github.com/facebook/react/issues/14981\n if (args[0] && !args[0].error)\n args[0].error = (error = '') =>\n set(() => {\n throw new Error(error)\n })\n return useState(() => createGL(...args))[0]\n}\n"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,QACzB,OAAS,YAAAC,MAAgB,aAEzB,WAAc,aAEP,IAAMC,EAAQ,IAAIC,IAAwB,CACzC,GAAM,CAAC,CAAEC,CAAG,EAAIJ,EAAS,IAAI,EAC7B,OAAIG,EAAK,CAAC,GAAK,CAACA,EAAK,CAAC,EAAE,QAChBA,EAAK,CAAC,EAAE,MAAQ,CAACE,EAAQ,KACjBD,EAAI,IAAM,CACF,MAAM,IAAI,MAAMC,CAAK,CAC7B,CAAC,GACVL,EAAS,IAAMC,EAAS,GAAGE,CAAI,CAAC,EAAE,CAAC,CAClD","names":["useState","createGL","useGL","args","set","error"]}
package/dist/solid.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var L=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var s=(t,e)=>{for(var r in e)L(t,r,{get:e[r],enumerable:!0})},a=(t,e,r,f)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of G(e))!c.call(t,o)&&o!==r&&L(t,o,{get:()=>e[o],enumerable:!(f=i(e,o))||f.enumerable});return t},l=(t,e,r)=>(a(t,e,"default"),r&&a(r,e,"default"));var u=t=>a(L({},"__esModule",{value:!0}),t);var n={};s(n,{onGL:()=>p});module.exports=u(n);var m=require("./index.cjs");l(n,require("./index.cjs"),module.exports);var p=t=>{let e=(0,m.isGL)(t)?t:(0,m.createGL)(t);return e.ref=r=>{r?(e.el=r,e.mount()):e.clean()},e};0&&(module.exports={onGL,...require("./index.cjs")});
1
+ "use strict";var L=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var s=(t,r)=>{for(var o in r)L(t,o,{get:r[o],enumerable:!0})},G=(t,r,o,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let p of n(r))!c.call(t,p)&&p!==o&&L(t,p,{get:()=>r[p],enumerable:!(a=i(r,p))||a.enumerable});return t},m=(t,r,o)=>(G(t,r,"default"),o&&G(o,r,"default"));var x=t=>G(L({},"__esModule",{value:!0}),t);var e={};s(e,{onGL:()=>y});module.exports=x(e);var f=require("./index.cjs");m(e,require("./index.cjs"),module.exports);var y=(...t)=>(0,f.createGL)(...t);0&&(module.exports={onGL,...require("./index.cjs")});
2
2
  //# sourceMappingURL=solid.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/solid.ts"],"sourcesContent":["import { createGL, isGL } from './index'\nimport type { GL } from './types'\nexport * from './index'\n\nexport const onGL = (props?: Partial<GL>) => {\n const gl = isGL(props) ? props : createGL(props)\n gl.ref = (el: HTMLCanvasElement | null) => {\n if (el) {\n gl.el = el\n gl.mount()\n } else gl.clean()\n }\n return gl\n}\n"],"mappings":"2dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA+B,uBAE/BC,EAAAL,EAAc,uBAFd,gBAIO,IAAME,EAAQI,GAAwB,CACrC,IAAMC,KAAK,QAAKD,CAAK,EAAIA,KAAQ,YAASA,CAAK,EAC/C,OAAAC,EAAG,IAAOC,GAAiC,CAC/BA,GACID,EAAG,GAAKC,EACRD,EAAG,MAAM,GACVA,EAAG,MAAM,CACxB,EACOA,CACf","names":["solid_exports","__export","onGL","__toCommonJS","import_index","__reExport","props","gl","el"]}
1
+ {"version":3,"sources":["../src/solid.ts"],"sourcesContent":["import { createGL } from './index'\nimport type { GL } from './types'\nexport * from './index'\n\nexport const onGL = (...args: Partial<GL>[]) => {\n return createGL(...args)\n}\n"],"mappings":"2dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyB,uBAEzBC,EAAAL,EAAc,uBAFd,gBAIO,IAAME,EAAO,IAAII,OACT,YAAS,GAAGA,CAAI","names":["solid_exports","__export","onGL","__toCommonJS","import_index","__reExport","args"]}
package/dist/solid.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as reev from 'reev';
2
- import { EventState, Nested } from 'reev';
3
- import * as refr from 'refr';
2
+ import { EventState } from 'reev';
4
3
  import { Queue, Frame } from 'refr';
5
4
 
6
5
  declare const CONVERSIONS: readonly ["toBool", "toUInt", "toInt", "toFloat", "toBVec2", "toIVec2", "toUVec2", "toVec2", "toBVec3", "toIVec3", "toUVec3", "toVec3", "toBVec4", "toIVec4", "toUVec4", "toVec4", "toColor", "toMat2", "toMat3", "toMat4"];
@@ -70,6 +69,28 @@ declare const OPERATOR_TYPE_RULES: readonly [readonly ["float", "vec2", "vec2"],
70
69
  */
71
70
  declare const FUNCTIONS: readonly [...("texture" | "all" | "any" | "determinant" | "distance" | "dot" | "length" | "lengthSq" | "luminance" | "cross" | "cubeTexture" | "texelFetch" | "textureLod")[], "abs", "acos", "acosh", "asin", "asinh", "atan", "atanh", "ceil", "cos", "cosh", "dFdx", "dFdy", "degrees", "exp", "exp2", "floor", "fract", "fwidth", "inverse", "inverseSqrt", "log", "log2", "negate", "normalize", "oneMinus", "radians", "reciprocal", "round", "sign", "sin", "sinh", "sqrt", "tan", "tanh", "trunc", "saturate", "atan2", "clamp", "max", "min", "mix", "pow", "reflect", "refract", "smoothstep", "step"];
72
71
 
72
+ /**
73
+ * binding
74
+ */
75
+ declare const createBinding: () => {
76
+ uniform: reev.Nested<{
77
+ group: number;
78
+ binding: number;
79
+ }, []>;
80
+ texture: reev.Nested<{
81
+ group: number;
82
+ binding: number;
83
+ }, []>;
84
+ storage: reev.Nested<{
85
+ group: number;
86
+ binding: number;
87
+ }, []>;
88
+ attrib: reev.Nested<{
89
+ location: number;
90
+ }, []>;
91
+ };
92
+ type Binding = ReturnType<typeof createBinding>;
93
+
73
94
  type Constants = (typeof CONSTANTS)[number] | 'void';
74
95
  type Conversions = (typeof CONVERSIONS)[number];
75
96
  type Functions = (typeof FUNCTIONS)[number];
@@ -102,6 +123,7 @@ interface NodeProps {
102
123
  }
103
124
  interface NodeContext {
104
125
  gl?: Partial<GL>;
126
+ binding?: Binding;
105
127
  label?: 'vert' | 'frag' | 'compute';
106
128
  isWebGL?: boolean;
107
129
  units?: any;
@@ -397,16 +419,17 @@ type GL = EventState<{
397
419
  isDebug: boolean;
398
420
  isDepth: boolean;
399
421
  wireframe: boolean;
400
- isGL: true;
401
422
  width?: number;
402
423
  height?: number;
403
424
  size: [number, number];
404
425
  mouse: [number, number];
405
426
  count: number;
427
+ triangleCount: number;
406
428
  instanceCount: number;
407
429
  particleCount: number | [number, number] | [number, number, number];
408
430
  precision: 'lowp' | 'mediump' | 'highp';
409
- loading: number;
431
+ element?: HTMLCanvasElement;
432
+ elem?: HTMLCanvasElement;
410
433
  el: HTMLCanvasElement;
411
434
  vs?: string | Vec4;
412
435
  cs?: string | Void;
@@ -417,11 +440,16 @@ type GL = EventState<{
417
440
  vertex?: string | Vec4;
418
441
  compute?: string | Void;
419
442
  fragment?: string | Vec4;
443
+ program: WebGLProgram;
444
+ gl: WebGL2RenderingContext;
445
+ gpu: GPUCanvasContext;
446
+ device: GPUDevice;
447
+ format: GPUTextureFormat;
448
+ encoder: GPUCommandEncoder;
449
+ binding: Binding;
420
450
  /**
421
451
  * core state
422
452
  */
423
- webgpu: WebGPUState;
424
- webgl: WebGLState;
425
453
  queue: Queue;
426
454
  frame: Frame;
427
455
  /**
@@ -434,7 +462,6 @@ type GL = EventState<{
434
462
  render(): void;
435
463
  resize(e?: Event): void;
436
464
  mousemove(e: MouseEvent): void;
437
- loop(): void;
438
465
  /**
439
466
  * setter
440
467
  */
@@ -497,92 +524,11 @@ interface StorageData {
497
524
  binding: number;
498
525
  group: number;
499
526
  }
500
- interface WebGPUState {
501
- device: GPUDevice;
502
- uniforms: Nested<UniformData>;
503
- textures: Nested<TextureData>;
504
- attribs: Nested<AttribData>;
505
- storages: Nested<StorageData>;
506
- }
507
- /**
508
- * for webgl
509
- */
510
- interface WebGLState {
511
- context: WebGL2RenderingContext;
512
- program: WebGLProgram;
513
- uniforms: Nested<WebGLUniformLocation | null>;
514
- }
515
527
 
516
- declare const isGL: (a: unknown) => a is EventState<GL>;
517
528
  declare const isServer: () => boolean;
518
529
  declare const isWebGPUSupported: () => boolean;
519
- declare const createGL: (props?: Partial<GL>) => EventState<{
520
- isNative: boolean;
521
- isWebGL: boolean;
522
- isError: boolean;
523
- isLoop: boolean;
524
- isDebug: boolean;
525
- isDepth: boolean;
526
- wireframe: boolean;
527
- isGL: true;
528
- width?: number;
529
- height?: number;
530
- size: [number, number];
531
- mouse: [number, number];
532
- count: number;
533
- instanceCount: number;
534
- particleCount: number | [number, number] | [number, number, number];
535
- precision: "lowp" | "mediump" | "highp";
536
- loading: number;
537
- el: HTMLCanvasElement;
538
- vs?: string | Vec4;
539
- cs?: string | Void;
540
- fs?: string | Vec4;
541
- vert?: string | Vec4;
542
- comp?: string | Void;
543
- frag?: string | Vec4;
544
- vertex?: string | Vec4;
545
- compute?: string | Void;
546
- fragment?: string | Vec4;
547
- webgpu: WebGPUState;
548
- webgl: WebGLState;
549
- queue: refr.Queue;
550
- frame: refr.Frame;
551
- ref?: any;
552
- mount(): void;
553
- clean(): void;
554
- error(e?: string): void;
555
- render(): void;
556
- resize(e?: Event): void;
557
- mousemove(e: MouseEvent): void;
558
- loop(): void;
559
- _uniform?(key: string, value: number | number[] | Float32Array<ArrayBufferLike>, isMatrix?: boolean): GL;
560
- uniform(key: string, value: number | number[] | Float32Array<ArrayBufferLike>, isMatrix?: boolean): GL;
561
- uniform(target: {
562
- [key: string]: number | number[] | Float32Array<ArrayBufferLike>;
563
- }): GL;
564
- _texture?(key: string, value: string | HTMLImageElement | HTMLVideoElement): GL;
565
- texture(key: string, value: string | HTMLImageElement | HTMLVideoElement): GL;
566
- texture(target: {
567
- [key: string]: string | HTMLImageElement | HTMLVideoElement;
568
- }): GL;
569
- _attribute?(key: string, value: number[] | Float32Array<ArrayBufferLike>, iboValue?: number[] | Float32Array<ArrayBufferLike>): GL;
570
- attribute(key: string, value: number[] | Float32Array<ArrayBufferLike>, iboValue?: number[] | Float32Array<ArrayBufferLike>): GL;
571
- attribute(target: {
572
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
573
- }): GL;
574
- _instance?(key: string, value: number[] | Float32Array<ArrayBufferLike>, at?: number): GL;
575
- instance(key: string, value: number[] | Float32Array<ArrayBufferLike>, at?: number): GL;
576
- instance(target: {
577
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
578
- }): GL;
579
- _storage?(key: string, value: number[] | Float32Array<ArrayBufferLike>): GL;
580
- storage(key: string, value: number[] | Float32Array<ArrayBufferLike>): GL;
581
- storage(target: {
582
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
583
- }): GL;
584
- }, any[] | unknown[]>;
530
+ declare const createGL: (...args: Partial<GL>[]) => EventState<GL>;
585
531
 
586
- declare const onGL: (props?: Partial<GL>) => reev.EventState<GL>;
532
+ declare const onGL: (...args: Partial<GL>[]) => reev.EventState<GL>;
587
533
 
588
- export { type AttribData, type GL, type StorageData, type TextureData, type UniformData, type WebGLState, type WebGPUState, createGL, isGL, isServer, isWebGPUSupported, onGL };
534
+ export { type AttribData, type GL, type StorageData, type TextureData, type UniformData, createGL, isServer, isWebGPUSupported, onGL };
package/dist/solid.js CHANGED
@@ -1,2 +1,2 @@
1
- import{createGL as n,isGL as o}from"./index.js";export*from"./index.js";var m=t=>{let e=o(t)?t:n(t);return e.ref=r=>{r?(e.el=r,e.mount()):e.clean()},e};export{m as onGL};
1
+ import{createGL as t}from"./index.js";export*from"./index.js";var e=(...r)=>t(...r);export{e as onGL};
2
2
  //# sourceMappingURL=solid.js.map
package/dist/solid.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/solid.ts"],"sourcesContent":["import { createGL, isGL } from './index'\nimport type { GL } from './types'\nexport * from './index'\n\nexport const onGL = (props?: Partial<GL>) => {\n const gl = isGL(props) ? props : createGL(props)\n gl.ref = (el: HTMLCanvasElement | null) => {\n if (el) {\n gl.el = el\n gl.mount()\n } else gl.clean()\n }\n return gl\n}\n"],"mappings":"AAAA,OAAS,YAAAA,EAAU,QAAAC,MAAY,aAE/B,WAAc,aAEP,IAAMC,EAAQC,GAAwB,CACrC,IAAMC,EAAKH,EAAKE,CAAK,EAAIA,EAAQH,EAASG,CAAK,EAC/C,OAAAC,EAAG,IAAOC,GAAiC,CAC/BA,GACID,EAAG,GAAKC,EACRD,EAAG,MAAM,GACVA,EAAG,MAAM,CACxB,EACOA,CACf","names":["createGL","isGL","onGL","props","gl","el"]}
1
+ {"version":3,"sources":["../src/solid.ts"],"sourcesContent":["import { createGL } from './index'\nimport type { GL } from './types'\nexport * from './index'\n\nexport const onGL = (...args: Partial<GL>[]) => {\n return createGL(...args)\n}\n"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,aAEzB,WAAc,aAEP,IAAMC,EAAO,IAAIC,IACTF,EAAS,GAAGE,CAAI","names":["createGL","onGL","args"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glre",
3
- "version": "0.45.0",
3
+ "version": "0.47.0",
4
4
  "author": "tseijp",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -27,41 +27,22 @@ export const flush = <Value extends Function, Key, This>(obj: Eachable<Value, Ke
27
27
  each(obj, (f) => f(...args))
28
28
  }
29
29
 
30
- /**
31
- * other
32
- */
33
- export const replace = (x = '', from = '_', to = '/') => x.split(from).join(to)
34
- export const ext = (src = '.pdf') => src.split('.').pop()?.toLowerCase() ?? ''
35
- export const fig = (x = 0) => `${x}`.split('.')[1]?.length ?? 0
36
- export const dig = (x = 0) => `${x}`.split('.')[0]?.length - (x < 0 ? 1 : 0)
37
- export const sig = (value = 0, digit = -2) => {
38
- digit *= -1
39
- digit = Math.pow(10, digit)
40
- value *= digit
41
- value = Math.round(value)
42
- value /= digit
43
- return value
44
- }
45
-
46
30
  export const isFloat32 = (value: unknown): value is Float32Array => {
47
31
  return value instanceof Float32Array
48
32
  }
49
33
 
50
- const loadingImage = (src: string, fun: (source: HTMLImageElement) => void) => {
51
- const source = new Image()
52
- Object.assign(source, { src, crossOrigin: 'anonymous' })
53
- source.decode().then(() => fun(source))
34
+ const loadingImage = (src: string, fun: (el: HTMLImageElement) => void) => {
35
+ const el = new Image()
36
+ Object.assign(el, { src, crossOrigin: 'anonymous' })
37
+ el.decode().then(() => fun(el))
54
38
  }
55
39
 
56
40
  const loadingVideo = (src: string, fun: (source: HTMLVideoElement) => void) => {
57
- const source = document.createElement('video')
58
- source.crossOrigin = 'anonymous'
59
- source.muted = true
60
- source.loop = true
61
- source.src = src
62
- source.load()
63
- source.play()
64
- source.addEventListener('canplay', fun.bind(null, source), { once: true })
41
+ const el = document.createElement('video')
42
+ Object.assign(el, { src, loop: true, muted: true, crossOrigin: 'anonymous' })
43
+ el.load()
44
+ el.play()
45
+ el.addEventListener('canplay', fun.bind(null, el), { once: true })
65
46
  }
66
47
 
67
48
  export function loadingTexture(src: string, fun: (source: HTMLVideoElement, isVideo: true) => void): void
@@ -85,10 +66,7 @@ const calcStride = (arrayLength: number, count = 3) => {
85
66
 
86
67
  export const getStride = (arrayLength: number, count = 1, error = console.warn) => {
87
68
  const ret = calcStride(arrayLength, count)
88
- if (!isValidStride(ret))
89
- error(
90
- `glre attribute error: Invalid attribute length ${arrayLength}. Must divide by vertex count (${count}) with valid stride (1,2,3,4,9,16)`
91
- )
69
+ if (!isValidStride(ret)) error(`glre attribute error: Invalid attribute length ${arrayLength}. Must divide by vertex count (${count}) with valid stride (1,2,3,4,9,16)`)
92
70
  return ret
93
71
  }
94
72