glre 0.44.0 → 0.46.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 +41 -51
  3. package/dist/index.cjs +6 -6
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +43 -91
  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 +51 -94
  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 +41 -52
  16. package/dist/node.js +14 -14
  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 +43 -92
  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 +43 -92
  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 +6 -21
  33. package/src/node/create.ts +2 -4
  34. package/src/node/index.ts +8 -20
  35. package/src/node/types.ts +9 -1
  36. package/src/node/utils/index.ts +5 -25
  37. package/src/node/utils/infer.ts +4 -12
  38. package/src/node/utils/parse.ts +18 -34
  39. package/src/node/utils/utils.ts +3 -11
  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;
@@ -112,7 +134,7 @@ interface NodeContext {
112
134
  fragInputs: Map<string, string>;
113
135
  vertInputs: Map<string, string>;
114
136
  vertOutputs: Map<string, string>;
115
- vertVaryings: Map<string, string>;
137
+ vertVaryings: Map<string, VaryingInfo>;
116
138
  computeInputs: Map<string, string>;
117
139
  dependencies: Map<string, Set<string>>;
118
140
  structStructFields: Map<string, StructFields>;
@@ -208,6 +230,10 @@ type Mat4 = XImpl<'mat4'>;
208
230
  type Texture$1 = XImpl<'texture'>;
209
231
  type Sampler2D = XImpl<'sampler2D'>;
210
232
  type StructBase = XImpl<'struct'>;
233
+ interface VaryingInfo {
234
+ node: Y;
235
+ code?: string;
236
+ }
211
237
  interface ConstantsToType {
212
238
  void: Void;
213
239
  bool: Bool;
@@ -244,6 +270,7 @@ type XImpl<T extends C> = _X<T> & {
244
270
  };
245
271
  type C = Constants;
246
272
  type X<T extends C = C> = T extends keyof ConstantsToType ? ConstantsToType[T] : _X<T>;
273
+ type Y<T extends C = C> = number | number[] | string | boolean | undefined | HTMLElement | X<T>;
247
274
  type Methods = Functions | Operators | Conversions | Swizzles | '__nodeType' | 'type' | 'props' | 'isProxy' | 'assign' | 'toVar' | 'toString' | 'element' | 'select';
248
275
  interface _X<T extends C> {
249
276
  readonly __nodeType?: T;
@@ -392,16 +419,17 @@ type GL = EventState<{
392
419
  isDebug: boolean;
393
420
  isDepth: boolean;
394
421
  wireframe: boolean;
395
- isGL: true;
396
422
  width?: number;
397
423
  height?: number;
398
424
  size: [number, number];
399
425
  mouse: [number, number];
400
426
  count: number;
427
+ triangleCount: number;
401
428
  instanceCount: number;
402
429
  particleCount: number | [number, number] | [number, number, number];
403
430
  precision: 'lowp' | 'mediump' | 'highp';
404
- loading: number;
431
+ element?: HTMLCanvasElement;
432
+ elem?: HTMLCanvasElement;
405
433
  el: HTMLCanvasElement;
406
434
  vs?: string | Vec4;
407
435
  cs?: string | Void;
@@ -412,11 +440,16 @@ type GL = EventState<{
412
440
  vertex?: string | Vec4;
413
441
  compute?: string | Void;
414
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;
415
450
  /**
416
451
  * core state
417
452
  */
418
- webgpu: WebGPUState;
419
- webgl: WebGLState;
420
453
  queue: Queue;
421
454
  frame: Frame;
422
455
  /**
@@ -429,7 +462,6 @@ type GL = EventState<{
429
462
  render(): void;
430
463
  resize(e?: Event): void;
431
464
  mousemove(e: MouseEvent): void;
432
- loop(): void;
433
465
  /**
434
466
  * setter
435
467
  */
@@ -492,92 +524,11 @@ interface StorageData {
492
524
  binding: number;
493
525
  group: number;
494
526
  }
495
- interface WebGPUState {
496
- device: GPUDevice;
497
- uniforms: Nested<UniformData>;
498
- textures: Nested<TextureData>;
499
- attribs: Nested<AttribData>;
500
- storages: Nested<StorageData>;
501
- }
502
- /**
503
- * for webgl
504
- */
505
- interface WebGLState {
506
- context: WebGL2RenderingContext;
507
- program: WebGLProgram;
508
- uniforms: Nested<WebGLUniformLocation | null>;
509
- }
510
527
 
511
- declare const isGL: (a: unknown) => a is EventState<GL>;
512
528
  declare const isServer: () => boolean;
513
529
  declare const isWebGPUSupported: () => boolean;
514
- declare const createGL: (props?: Partial<GL>) => EventState<{
515
- isNative: boolean;
516
- isWebGL: boolean;
517
- isError: boolean;
518
- isLoop: boolean;
519
- isDebug: boolean;
520
- isDepth: boolean;
521
- wireframe: boolean;
522
- isGL: true;
523
- width?: number;
524
- height?: number;
525
- size: [number, number];
526
- mouse: [number, number];
527
- count: number;
528
- instanceCount: number;
529
- particleCount: number | [number, number] | [number, number, number];
530
- precision: "lowp" | "mediump" | "highp";
531
- loading: number;
532
- el: HTMLCanvasElement;
533
- vs?: string | Vec4;
534
- cs?: string | Void;
535
- fs?: string | Vec4;
536
- vert?: string | Vec4;
537
- comp?: string | Void;
538
- frag?: string | Vec4;
539
- vertex?: string | Vec4;
540
- compute?: string | Void;
541
- fragment?: string | Vec4;
542
- webgpu: WebGPUState;
543
- webgl: WebGLState;
544
- queue: refr.Queue;
545
- frame: refr.Frame;
546
- ref?: any;
547
- mount(): void;
548
- clean(): void;
549
- error(e?: string): void;
550
- render(): void;
551
- resize(e?: Event): void;
552
- mousemove(e: MouseEvent): void;
553
- loop(): void;
554
- _uniform?(key: string, value: number | number[] | Float32Array<ArrayBufferLike>, isMatrix?: boolean): GL;
555
- uniform(key: string, value: number | number[] | Float32Array<ArrayBufferLike>, isMatrix?: boolean): GL;
556
- uniform(target: {
557
- [key: string]: number | number[] | Float32Array<ArrayBufferLike>;
558
- }): GL;
559
- _texture?(key: string, value: string | HTMLImageElement | HTMLVideoElement): GL;
560
- texture(key: string, value: string | HTMLImageElement | HTMLVideoElement): GL;
561
- texture(target: {
562
- [key: string]: string | HTMLImageElement | HTMLVideoElement;
563
- }): GL;
564
- _attribute?(key: string, value: number[] | Float32Array<ArrayBufferLike>, iboValue?: number[] | Float32Array<ArrayBufferLike>): GL;
565
- attribute(key: string, value: number[] | Float32Array<ArrayBufferLike>, iboValue?: number[] | Float32Array<ArrayBufferLike>): GL;
566
- attribute(target: {
567
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
568
- }): GL;
569
- _instance?(key: string, value: number[] | Float32Array<ArrayBufferLike>, at?: number): GL;
570
- instance(key: string, value: number[] | Float32Array<ArrayBufferLike>, at?: number): GL;
571
- instance(target: {
572
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
573
- }): GL;
574
- _storage?(key: string, value: number[] | Float32Array<ArrayBufferLike>): GL;
575
- storage(key: string, value: number[] | Float32Array<ArrayBufferLike>): GL;
576
- storage(target: {
577
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
578
- }): GL;
579
- }, any[] | unknown[]>;
530
+ declare const createGL: (...args: Partial<GL>[]) => EventState<GL>;
580
531
 
581
- declare const useGL: (props?: Partial<GL>) => reev.EventState<GL>;
532
+ declare const useGL: (...args: Partial<GL>[]) => reev.EventState<GL>;
582
533
 
583
- 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;
@@ -112,7 +134,7 @@ interface NodeContext {
112
134
  fragInputs: Map<string, string>;
113
135
  vertInputs: Map<string, string>;
114
136
  vertOutputs: Map<string, string>;
115
- vertVaryings: Map<string, string>;
137
+ vertVaryings: Map<string, VaryingInfo>;
116
138
  computeInputs: Map<string, string>;
117
139
  dependencies: Map<string, Set<string>>;
118
140
  structStructFields: Map<string, StructFields>;
@@ -208,6 +230,10 @@ type Mat4 = XImpl<'mat4'>;
208
230
  type Texture$1 = XImpl<'texture'>;
209
231
  type Sampler2D = XImpl<'sampler2D'>;
210
232
  type StructBase = XImpl<'struct'>;
233
+ interface VaryingInfo {
234
+ node: Y;
235
+ code?: string;
236
+ }
211
237
  interface ConstantsToType {
212
238
  void: Void;
213
239
  bool: Bool;
@@ -244,6 +270,7 @@ type XImpl<T extends C> = _X<T> & {
244
270
  };
245
271
  type C = Constants;
246
272
  type X<T extends C = C> = T extends keyof ConstantsToType ? ConstantsToType[T] : _X<T>;
273
+ type Y<T extends C = C> = number | number[] | string | boolean | undefined | HTMLElement | X<T>;
247
274
  type Methods = Functions | Operators | Conversions | Swizzles | '__nodeType' | 'type' | 'props' | 'isProxy' | 'assign' | 'toVar' | 'toString' | 'element' | 'select';
248
275
  interface _X<T extends C> {
249
276
  readonly __nodeType?: T;
@@ -392,16 +419,17 @@ type GL = EventState<{
392
419
  isDebug: boolean;
393
420
  isDepth: boolean;
394
421
  wireframe: boolean;
395
- isGL: true;
396
422
  width?: number;
397
423
  height?: number;
398
424
  size: [number, number];
399
425
  mouse: [number, number];
400
426
  count: number;
427
+ triangleCount: number;
401
428
  instanceCount: number;
402
429
  particleCount: number | [number, number] | [number, number, number];
403
430
  precision: 'lowp' | 'mediump' | 'highp';
404
- loading: number;
431
+ element?: HTMLCanvasElement;
432
+ elem?: HTMLCanvasElement;
405
433
  el: HTMLCanvasElement;
406
434
  vs?: string | Vec4;
407
435
  cs?: string | Void;
@@ -412,11 +440,16 @@ type GL = EventState<{
412
440
  vertex?: string | Vec4;
413
441
  compute?: string | Void;
414
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;
415
450
  /**
416
451
  * core state
417
452
  */
418
- webgpu: WebGPUState;
419
- webgl: WebGLState;
420
453
  queue: Queue;
421
454
  frame: Frame;
422
455
  /**
@@ -429,7 +462,6 @@ type GL = EventState<{
429
462
  render(): void;
430
463
  resize(e?: Event): void;
431
464
  mousemove(e: MouseEvent): void;
432
- loop(): void;
433
465
  /**
434
466
  * setter
435
467
  */
@@ -492,92 +524,11 @@ interface StorageData {
492
524
  binding: number;
493
525
  group: number;
494
526
  }
495
- interface WebGPUState {
496
- device: GPUDevice;
497
- uniforms: Nested<UniformData>;
498
- textures: Nested<TextureData>;
499
- attribs: Nested<AttribData>;
500
- storages: Nested<StorageData>;
501
- }
502
- /**
503
- * for webgl
504
- */
505
- interface WebGLState {
506
- context: WebGL2RenderingContext;
507
- program: WebGLProgram;
508
- uniforms: Nested<WebGLUniformLocation | null>;
509
- }
510
527
 
511
- declare const isGL: (a: unknown) => a is EventState<GL>;
512
528
  declare const isServer: () => boolean;
513
529
  declare const isWebGPUSupported: () => boolean;
514
- declare const createGL: (props?: Partial<GL>) => EventState<{
515
- isNative: boolean;
516
- isWebGL: boolean;
517
- isError: boolean;
518
- isLoop: boolean;
519
- isDebug: boolean;
520
- isDepth: boolean;
521
- wireframe: boolean;
522
- isGL: true;
523
- width?: number;
524
- height?: number;
525
- size: [number, number];
526
- mouse: [number, number];
527
- count: number;
528
- instanceCount: number;
529
- particleCount: number | [number, number] | [number, number, number];
530
- precision: "lowp" | "mediump" | "highp";
531
- loading: number;
532
- el: HTMLCanvasElement;
533
- vs?: string | Vec4;
534
- cs?: string | Void;
535
- fs?: string | Vec4;
536
- vert?: string | Vec4;
537
- comp?: string | Void;
538
- frag?: string | Vec4;
539
- vertex?: string | Vec4;
540
- compute?: string | Void;
541
- fragment?: string | Vec4;
542
- webgpu: WebGPUState;
543
- webgl: WebGLState;
544
- queue: refr.Queue;
545
- frame: refr.Frame;
546
- ref?: any;
547
- mount(): void;
548
- clean(): void;
549
- error(e?: string): void;
550
- render(): void;
551
- resize(e?: Event): void;
552
- mousemove(e: MouseEvent): void;
553
- loop(): void;
554
- _uniform?(key: string, value: number | number[] | Float32Array<ArrayBufferLike>, isMatrix?: boolean): GL;
555
- uniform(key: string, value: number | number[] | Float32Array<ArrayBufferLike>, isMatrix?: boolean): GL;
556
- uniform(target: {
557
- [key: string]: number | number[] | Float32Array<ArrayBufferLike>;
558
- }): GL;
559
- _texture?(key: string, value: string | HTMLImageElement | HTMLVideoElement): GL;
560
- texture(key: string, value: string | HTMLImageElement | HTMLVideoElement): GL;
561
- texture(target: {
562
- [key: string]: string | HTMLImageElement | HTMLVideoElement;
563
- }): GL;
564
- _attribute?(key: string, value: number[] | Float32Array<ArrayBufferLike>, iboValue?: number[] | Float32Array<ArrayBufferLike>): GL;
565
- attribute(key: string, value: number[] | Float32Array<ArrayBufferLike>, iboValue?: number[] | Float32Array<ArrayBufferLike>): GL;
566
- attribute(target: {
567
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
568
- }): GL;
569
- _instance?(key: string, value: number[] | Float32Array<ArrayBufferLike>, at?: number): GL;
570
- instance(key: string, value: number[] | Float32Array<ArrayBufferLike>, at?: number): GL;
571
- instance(target: {
572
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
573
- }): GL;
574
- _storage?(key: string, value: number[] | Float32Array<ArrayBufferLike>): GL;
575
- storage(key: string, value: number[] | Float32Array<ArrayBufferLike>): GL;
576
- storage(target: {
577
- [key: string]: number[] | Float32Array<ArrayBufferLike>;
578
- }): GL;
579
- }, any[] | unknown[]>;
530
+ declare const createGL: (...args: Partial<GL>[]) => EventState<GL>;
580
531
 
581
- declare const onGL: (props?: Partial<GL>) => reev.EventState<GL>;
532
+ declare const onGL: (...args: Partial<GL>[]) => reev.EventState<GL>;
582
533
 
583
- 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.44.0",
3
+ "version": "0.46.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