glre 0.21.0 → 0.23.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/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  [![ docs available ](https://img.shields.io/badge/docs-available-000.svg?style=flat&colorA=000)](https://glre.tsei.jp/>)
12
12
  [![ bundle size ](https://img.shields.io/bundlephobia/minzip/glre?style=flat&colorA=000&colorB=000)](https://bundlephobia.com/package/glre@latest)
13
13
 
14
- glre is a simple glsl Reactive Engine on the web and native via TypeScript, React, Solid and more.
14
+ glre is a simple glsl and wgsl Reactive Engine on the web and native via TypeScript, React, Solid and more.
15
15
 
16
16
  </p>
17
17
  <p align="center" valign="top">
@@ -95,44 +95,30 @@ npm install glre
95
95
  </td>
96
96
  </table>
97
97
 
98
- ## PRs
99
-
100
- ###### welcome✨
101
-
102
98
  ## What does it look like?
103
99
 
104
100
  <table>
105
- <tr>
106
- <td width="7500px" align="center" valign="center">
107
- glre simplifies glsl programming via TypeScript, React, Solid and more (<a href="https://codesandbox.io/s/glre-basic-demo-ppzo3d">live demo</a>).
108
- </td>
109
- <td width="2500px" valign="top">
110
- <a href="https://codesandbox.io/s/glre-basic-demo-ppzo3d">
111
- <img alt="4" src="https://i.imgur.com/Lb3h9fs.jpg"></img>
112
- </a>
113
- </td>
114
- </tr>
101
+ <tbody>
102
+ <tr>
103
+ <td width="7500px" align="center" valign="center">
104
+ glre simplifies WebGl2 / WebGPU programming via TypeScript, React, Solid and more (<a href="https://codesandbox.io/s/glre-basic-demo-ppzo3d">live demo</a>).
105
+ </td>
106
+ <td width="2500px" valign="top">
107
+ <a href="https://codesandbox.io/s/glre-basic-demo-ppzo3d">
108
+ <img alt="4" src="https://i.imgur.com/Lb3h9fs.jpg"></img>
109
+ </a>
110
+ </td>
111
+ </tr>
112
+ </tbody>
115
113
  </table>
116
114
 
117
115
  ```ts
118
116
  import { createRoot } from 'react-dom/client'
119
- import { useGL, useFrame } from 'glre/react'
120
-
121
- const fragment = `
122
- precision highp float;
123
- uniform vec2 iResolution;
124
- void main() {
125
- gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
126
- }
127
- `
117
+ import { useGL, vec4, fract, gl_FragCoord, iResolution } from 'glre/react'
118
+ const fragment = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1)
128
119
 
129
120
  const App = () => {
130
121
  const gl = useGL({ fragment })
131
- useFrame(() => {
132
- gl.clear()
133
- gl.viewport()
134
- gl.drawArrays()
135
- })
136
122
  return <canvas ref={gl.ref} />
137
123
  }
138
124
 
@@ -148,27 +134,13 @@ react-native supported ([codesandbox demo](https://codesandbox.io/p/sandbox/glre
148
134
 
149
135
  ```ts
150
136
  import { GLView } from 'expo-gl'
151
- import { useGL, useFrame } from 'glre/native'
152
137
  import { registerRootComponent } from 'expo'
153
-
154
- const fragment = `
155
- precision highp float;
156
- uniform vec2 iResolution;
157
- void main() {
158
- gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
159
- }
160
- `
138
+ import { useGL, vec4, fract, fragCoord, iResolution } from 'glre/native'
139
+ const fragment = vec4(fract(fragCoord.xy / iResolution), 0, 1)
161
140
 
162
141
  const App = () => {
163
- const self = useGL({ fragment })
164
- useFrame(() => {
165
- self.clear()
166
- self.viewport()
167
- self.drawArrays()
168
- self.gl.flush()
169
- self.gl.endFrameEXP()
170
- })
171
- return <GLView style={{ flex: 1 }} onContextCreate={self.ref} />
142
+ const { gl, ref } = useGL({ fragment })
143
+ return <GLView style={{ flex: 1 }} onContextCreate={ref} />
172
144
  }
173
145
 
174
146
  registerRootComponent(App)
@@ -184,23 +156,11 @@ solid js supported ([codesandbox demo](https://codesandbox.io/p/sandbox/glre-sol
184
156
 
185
157
  ```ts
186
158
  import { render } from 'solid-js/web'
187
- import { onGL, onFrame } from 'glre/solid'
188
-
189
- const fragment = `
190
- precision highp float;
191
- uniform vec2 iResolution;
192
- void main() {
193
- gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
194
- }
195
- `
159
+ import { onGL, vec4, fract, fragCoord, iResolution } from 'glre/solid'
160
+ const fragment = vec4(fract(fragCoord.xy / iResolution), 0, 1)
196
161
 
197
162
  const App = () => {
198
163
  const gl = onGL({ fragment })
199
- onFrame(() => {
200
- gl.clear()
201
- gl.viewport()
202
- gl.drawArrays()
203
- })
204
164
  return <canvas ref={gl.ref} />
205
165
  }
206
166
 
@@ -211,40 +171,143 @@ render(() => <App />, document.getElementById('root'))
211
171
  <details>
212
172
  <summary>
213
173
 
214
- pure js supported ([codesandbox demo](https://codesandbox.io/s/glre-basic-demo3-3bhr3y))
174
+ esm supported ([codesandbox demo](https://codesandbox.io/s/glre-basic-demo3-3bhr3y))
215
175
 
216
176
  </summary>
217
177
 
218
178
  ```html
219
- <canvas id="id" style="top: 0; left: 0; position: fixed" />
220
179
  <script type="module">
221
- import self from 'https://cdn.skypack.dev/glre@latest'
222
- const fragment = `
223
- precision highp float;
224
- uniform vec2 iResolution;
225
- void main() {
226
- gl_FragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);
227
- }
228
- `
229
- function setup() {
230
- const el = document.getElementById('id')
180
+ import createGL from 'https://esm.sh/glre'
181
+ import { vec4, fract, fragCoord, iResolution } from 'https://esm.sh/glre'
182
+ const fragment = vec4(fract(fragCoord.xy / iResolution), 0, 1)
183
+ function App() {
184
+ const el = document.createElement('canvas')
231
185
  const gl = el.getContext('webgl2')
232
- self({ el, gl, fragment })
233
- self.init()
234
- self.resize()
235
- draw()
186
+ createGL({ el, gl, fragment }).mount()
187
+ document.body.append(el)
236
188
  }
237
- function draw() {
238
- requestAnimationFrame(draw)
239
- self.render()
240
- self.clear()
241
- self.viewport()
242
- self.drawArrays()
243
- }
244
- document.addEventListener('DOMContentLoaded', setup)
189
+ document.addEventListener('DOMContentLoaded', App)
245
190
  </script>
246
191
  ```
247
192
 
248
193
  </details>
249
194
  </samp>
250
195
  </strong>
196
+
197
+ ## Node System
198
+
199
+ glre now features a powerful node-based shader system inspired by Three.js Shading Language (TSL). This system allows you to write shaders using TypeScript-like syntax and automatically handles the conversion to both WebGL2 and WebGPU shaders.
200
+
201
+ The node system provides a declarative approach to shader creation, making your code more readable, maintainable, and portable across different rendering backends.
202
+
203
+ ### Node Types and Functions
204
+
205
+ The node system provides various types and functions that mirror GLSL functionality:
206
+
207
+ ```ts
208
+ // Basic types
209
+ import { float, int, vec2, vec3, vec4, mat3, mat4 } from 'glre'
210
+
211
+ // Built-in variables
212
+ import { gl_FragCoord, gl_Position, iResolution, iTime } from 'glre'
213
+
214
+ // Math functions
215
+ import { sin, cos, abs, pow, mix, clamp, normalize } from 'glre'
216
+
217
+ // Texture functions
218
+ import { texture, textureCube, sampler2D } from 'glre'
219
+ ```
220
+
221
+ ### Creating Custom Functions
222
+
223
+ You can define reusable shader functions using the `Fn` constructor:
224
+
225
+ ```ts
226
+ import { Fn, vec3, sin, cos, float } from 'glre'
227
+
228
+ // Define a function that creates a rotation matrix
229
+ const rotateY = Fn(([angle = float(0)]) => {
230
+ const s = sin(angle)
231
+ const c = cos(angle)
232
+ return mat3(c, 0, s, 0, 1, 0, -s, 0, c)
233
+ })
234
+
235
+ // Use the function in your shader
236
+ const rotatedPosition = rotateY(iTime).mul(position)
237
+ ```
238
+
239
+ ### Conditional Logic
240
+
241
+ The node system supports conditional operations:
242
+
243
+ ```ts
244
+ import { If, vec4, lessThan } from 'glre'
245
+
246
+ // Create a conditional color output
247
+ const color = vec4(1, 0, 0, 1).toVar()
248
+
249
+ If(position.y.lessThan(0.5), () => {
250
+ color.assign(vec4(0, 1, 0, 1))
251
+ })
252
+
253
+ // Use the color in your shader
254
+ const fragment = color
255
+ ```
256
+
257
+ ### Uniforms
258
+
259
+ The node system provides a powerful way to define and manage uniform values in your shaders:
260
+
261
+ ```ts
262
+ import { createRoot } from 'react-dom/client'
263
+ import { useGL } from 'glre/react'
264
+ import { uniform, vec3, vec4 } from 'glre'
265
+
266
+ const uRand = uniform(1.0)
267
+
268
+ // Create a simple pulsing color shader
269
+ const App = () => {
270
+ const gl = useGL({
271
+ fragment: vec4(vec3(uRand), 1.0),
272
+ loop() {
273
+ pulse.set(0.5 + 0.5 * Math.random())
274
+ },
275
+ })
276
+ return <canvas ref={gl.ref} />
277
+ }
278
+
279
+ createRoot(document.getElementById('root')).render(<App />)
280
+ ```
281
+
282
+ ### Attributes
283
+
284
+ Attributes allow you to define per-vertex data for your shaders:
285
+
286
+ ```ts
287
+ import { createRoot } from 'react-dom/client'
288
+ import { useGL } from 'glre/react'
289
+ import { attribute, vec3, vec4 } from 'glre'
290
+
291
+ // Define vertex positions
292
+ const positions = attribute(-1.0, -1.0, 0.0, 1.0, -1.0, 0.0, -1.0, 1.0, 0.0, 1.0, 1.0, 0.0)
293
+
294
+ // Create a shader that uses attributes
295
+ const App = () => {
296
+ const gl = useGL({ vertex: positions })
297
+ return <canvas ref={gl.ref} />
298
+ }
299
+
300
+ createRoot(document.getElementById('root')).render(<App />)
301
+ ```
302
+
303
+ ### WebGL2 and WebGPU Support
304
+
305
+ The node system is designed to work with both WebGL2 and WebGPU, providing a seamless transition path as browsers adopt the new standard. Your shader code written with the node system will automatically compile to the appropriate shading language (GLSL ES 3.0 for WebGL2, WGSL for WebGPU) based on the available renderer.
306
+
307
+ ## PRs
308
+
309
+ ###### welcome✨
310
+
311
+ ## LICENSE
312
+
313
+ ###### MIT⚾️
package/dist/index.d.ts CHANGED
@@ -1,9 +1,366 @@
1
- import { G as GL } from './types-f429c8b1.js';
2
- export { Fun } from 'refr';
3
- import 'reev';
1
+ import * as refr from 'refr';
2
+ import { Queue, Frame } from 'refr';
3
+ export { Frame, Fun, Queue } from 'refr';
4
+ import { EventState } from 'reev';
4
5
 
5
- declare const createGL: (props?: Partial<GL>) => GL;
6
- declare const gl: GL;
7
- declare const createTF: (props?: Partial<GL>, self?: GL) => GL;
6
+ declare const TYPES: readonly ["float", "int", "uint", "bool", "color", "vec2", "vec3", "vec4", "mat2", "mat3", "mat4", "ivec2", "ivec3", "ivec4", "uvec2", "uvec3", "uvec4", "bvec2", "bvec3", "bvec4"];
7
+ type NodeType = (typeof TYPES)[number];
8
+ declare const SWIZZLES: readonly ["x", "y", "z", "w", "r", "g", "b", "a", "s", "t", "p", "q"];
9
+ type AllSwizzles<T extends string> = T | `${T}${T}` | `${T}${T}${T}` | `${T}${T}${T}${T}`;
10
+ type Swillzes = AllSwizzles<'x' | 'y' | 'z' | 'w'> | AllSwizzles<'r' | 'g' | 'b' | 'a'> | AllSwizzles<'p' | 'q'> | AllSwizzles<'s' | 't'>;
11
+ declare const OPERATORS: readonly ["add", "sub", "mul", "div", "mod", "equal", "notEqual", "lessThan", "lessThanEqual", "greaterThan", "greaterThanEqual", "and", "or", "not", "assign", "xor", "bitAnd", "bitNot", "bitOr", "bitXor", "shiftLeft", "shiftRight"];
12
+ type Operator = (typeof OPERATORS)[number];
13
+ declare const FUNCTIONS: readonly ["abs", "acos", "asin", "atan", "atan2", "ceil", "clamp", "cos", "cross", "degrees", "distance", "dot", "exp", "exp2", "faceforward", "floor", "fract", "length", "all", "any", "bitcast", "cbrt", "dFdx", "dFdy", "difference", "equals", "fwidth", "inverseSqrt", "lengthSq", "log", "log2", "max", "min", "mix", "negate", "normalize", "oneMinus", "pow", "pow2", "pow3", "pow4", "radians", "reciprocal", "reflect", "refract", "round", "saturate", "sign", "sin", "smoothstep", "sqrt", "step", "tan", "transformDirection", "trunc"];
14
+ type MathFunction = (typeof FUNCTIONS)[number];
15
+ declare const CACHE_BOOLS: readonly [true, false];
16
+ declare const CACHE_INTS: readonly [0, 1, 2, 3, 4, 5];
17
+ declare const CACHE_FLOATS: readonly [0, 1, 0.5, 2];
8
18
 
9
- export { GL, createGL, createTF, gl as default, gl };
19
+ interface Node {
20
+ id: string;
21
+ type: NodeType;
22
+ value?: any;
23
+ property?: string;
24
+ parent?: Node;
25
+ children?: Node[];
26
+ operator?: Operator;
27
+ mathFunction?: MathFunction;
28
+ }
29
+ interface ProxyCallback {
30
+ path: string[];
31
+ args: any[];
32
+ }
33
+ type NodeCreator = (value?: any) => X;
34
+ interface OperatorMethods {
35
+ add(x: X | number): X;
36
+ sub(x: X | number): X;
37
+ mul(x: X | number): X;
38
+ div(x: X | number): X;
39
+ mod(x: X | number): X;
40
+ equal(x: X | number): X;
41
+ notEqual(x: X | number): X;
42
+ lessThan(x: X | number): X;
43
+ lessThanEqual(x: X | number): X;
44
+ greaterThan(x: X | number): X;
45
+ greaterThanEqual(x: X | number): X;
46
+ and(x: X): X;
47
+ or(x: X): X;
48
+ not(): X;
49
+ }
50
+ interface MathMethods {
51
+ abs(): X;
52
+ acos(): X;
53
+ asin(): X;
54
+ atan(): X;
55
+ ceil(): X;
56
+ cos(): X;
57
+ floor(): X;
58
+ fract(): X;
59
+ length(): X;
60
+ normalize(): X;
61
+ sin(): X;
62
+ sqrt(): X;
63
+ tan(): X;
64
+ toVar(): X;
65
+ }
66
+ type SwizzleProperties = {
67
+ [k in Swillzes]: X;
68
+ };
69
+ interface X extends MathMethods, OperatorMethods, SwizzleProperties {
70
+ readonly id: string;
71
+ readonly type: NodeType;
72
+ readonly value: any;
73
+ readonly property: string;
74
+ (...args: any[]): X;
75
+ }
76
+ interface UniformNode extends X {
77
+ set(value: any): void;
78
+ onObjectUpdate(callback: (context: any) => any): UniformNode;
79
+ onRenderUpdate(callback: (context: any) => any): UniformNode;
80
+ }
81
+ interface FunctionNode {
82
+ (...args: any[]): X;
83
+ call(x: X[]): X;
84
+ }
85
+ interface ConditionalNode {
86
+ ElseIf(condition: X, callback: () => void): ConditionalNode;
87
+ Else(callback: () => void): void;
88
+ }
89
+ interface ConversionContext {
90
+ target: 'webgl' | 'webgpu';
91
+ nodes: Map<string, Node>;
92
+ variables: Map<string, string>;
93
+ functions: Map<string, string>;
94
+ }
95
+
96
+ declare const getCachedBool: (x: boolean) => X;
97
+ declare const getCachedInt: (x: number) => X;
98
+ declare const getCachedFloat: (x: number) => X;
99
+ declare const findDuplicateNodes: (nodes: X[]) => Map<string, X[]>;
100
+
101
+ declare const convertToNode: (x: unknown) => X;
102
+ declare const float: (x: unknown) => X;
103
+ declare const int: (x: unknown) => X;
104
+ declare const bool: (x: unknown) => X;
105
+ declare const vec2: (x?: any, y?: any) => X;
106
+ declare const vec3: (x?: any, y?: any, z?: any) => X;
107
+ declare const vec4: (x?: any, y?: any, z?: any, w?: any) => X;
108
+ declare const color: (r?: any, g?: any, b?: any) => X;
109
+
110
+ declare const createNode: (type: NodeType, value?: any, options?: Partial<Node>) => Node;
111
+ declare const node: (type: NodeType, value?: any, options?: Partial<Node>) => X;
112
+
113
+ interface UpdateContext {
114
+ object?: any;
115
+ camera?: any;
116
+ renderer?: any;
117
+ scene?: any;
118
+ time?: number;
119
+ }
120
+ declare const uniform: (initialValue: any) => UniformNode;
121
+ declare const iPrevTime: UniformNode;
122
+ declare const iDeltaTime: UniformNode;
123
+ declare const updateUniforms: (context: UpdateContext) => void;
124
+
125
+ declare const Fn: (jsFunc: Function) => FunctionNode;
126
+ declare const If: (condition: X, callback: () => void) => ConditionalNode;
127
+ declare const gl_FragCoord: X;
128
+ declare const gl_Position: X;
129
+ declare const iTime: UniformNode;
130
+ declare const iResolution: UniformNode;
131
+ declare const iMouse: UniformNode;
132
+ declare const abs: (x: X) => X;
133
+ declare const sin: (x: X) => X;
134
+ declare const cos: (x: X) => X;
135
+ declare const tan: (x: X) => X;
136
+ declare const sqrt: (x: X) => X;
137
+ declare const floor: (x: X) => X;
138
+ declare const ceil: (x: X) => X;
139
+ declare const fract: (x: X) => X;
140
+ declare const normalize: (x: X) => X;
141
+ declare const length: (x: X) => X;
142
+
143
+ type GPUContext = any;
144
+ type GPUDevice = any;
145
+ type GPUBuffer = any;
146
+ type GPUPipeline = any;
147
+ type Uniform = number | number[];
148
+ type Attribute = number[];
149
+ type Attributes = Record<string, Attribute>;
150
+ type Uniforms = Record<string, Uniform>;
151
+ type PrecisionMode = 'highp' | 'mediump' | 'lowp';
152
+ type GLClearMode = 'COLOR_BUFFER_BIT' | 'DEPTH_BUFFER_BIT' | 'STENCIL_BUFFER_BIT';
153
+ type GLDrawType = 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT' | 'UNSIGNED_INT';
154
+ type GLDrawMode = 'POINTS' | 'LINE_STRIP' | 'LINE_LOOP' | 'LINES' | 'TRIANGLE_STRIP' | 'TRIANGLE_FAN' | 'TRIANGLES';
155
+ interface WebGLState {
156
+ context: WebGLRenderingContext;
157
+ program: WebGLProgram;
158
+ }
159
+ interface WebGPUState {
160
+ device: GPUDevice;
161
+ context: GPUContext;
162
+ pipeline: GPUPipeline;
163
+ }
164
+ type GL = EventState<{
165
+ /**
166
+ * initial value
167
+ */
168
+ isNative: boolean;
169
+ isWebGL: boolean;
170
+ isLoop: boolean;
171
+ isGL: true;
172
+ width: number;
173
+ height: number;
174
+ size: [number, number];
175
+ mouse: [number, number];
176
+ count: number;
177
+ el: HTMLCanvasElement;
178
+ vs: string | X;
179
+ fs: string | X;
180
+ vert: string | X;
181
+ frag: string | X;
182
+ vertex: string | X;
183
+ fragment: string | X;
184
+ /**
185
+ * core state
186
+ */
187
+ webgpu: WebGPUState;
188
+ webgl: WebGLState;
189
+ queue: Queue;
190
+ frame: Frame;
191
+ /**
192
+ * events
193
+ */
194
+ ref?: any;
195
+ init(): void;
196
+ loop(): void;
197
+ mount(): void;
198
+ clean(): void;
199
+ render(): void;
200
+ resize(e?: Event): void;
201
+ mousemove(e: Event): void;
202
+ /**
203
+ * setter
204
+ */
205
+ _uniform?(key: string, value: Uniform, isMatrix?: boolean): GL;
206
+ uniform(key: string, value: Uniform, isMatrix?: boolean): GL;
207
+ uniform(target: {
208
+ [key: string]: Uniform;
209
+ }): GL;
210
+ _texture?(key: string, value: string): GL;
211
+ texture(key: string, value: string): GL;
212
+ texture(target: {
213
+ [key: string]: string;
214
+ }): GL;
215
+ _attribute?(key: string, value: Attribute, iboValue?: Attribute): GL;
216
+ attribute(key: string, value: Attribute, iboValue?: Attribute): GL;
217
+ attribute(target: {
218
+ [key: string]: Attribute;
219
+ }): GL;
220
+ }>;
221
+
222
+ interface GLSLContext extends ConversionContext {
223
+ target: 'webgl';
224
+ precision: 'lowp' | 'mediump' | 'highp';
225
+ version: '100' | '300 es';
226
+ }
227
+ declare const nodeToGLSL: (nodeProxy: X, context?: Partial<GLSLContext>) => string;
228
+ declare const glsl: (fragmentNode: X, options?: {
229
+ precision?: "lowp" | "mediump" | "highp";
230
+ version?: "100" | "300 es";
231
+ uniforms?: Record<string, any>;
232
+ }) => string;
233
+
234
+ interface WGSLContext extends ConversionContext {
235
+ target: 'webgpu';
236
+ }
237
+ declare const nodeToWGSL: (nodeProxy: X, context?: Partial<WGSLContext>) => string;
238
+ declare const wgsl: (fragmentNode: X, options?: {
239
+ uniforms?: Record<string, any>;
240
+ }) => string;
241
+
242
+ declare const is: {
243
+ arr: (arg: any) => arg is any[];
244
+ bol: (a: unknown) => a is boolean;
245
+ str: (a: unknown) => a is string;
246
+ num: (a: unknown) => a is number;
247
+ int: (a: unknown) => a is number;
248
+ fun: (a: unknown) => a is Function;
249
+ und: (a: unknown) => a is undefined;
250
+ nul: (a: unknown) => a is null;
251
+ set: (a: unknown) => a is Set<unknown>;
252
+ map: (a: unknown) => a is Map<unknown, unknown>;
253
+ obj: (a: unknown) => a is object;
254
+ nan: (a: unknown) => a is number;
255
+ };
256
+ /**
257
+ * each
258
+ */
259
+ type EachFn<Value, Key, This> = (this: This, value: Value, key: Key) => void;
260
+ type Eachable<Value = any, Key = any, This = any> = {
261
+ forEach(cb: EachFn<Value, Key, This>, ctx?: This): void;
262
+ };
263
+ declare const each: <Value, Key, This>(obj: Eachable<Value, Key, This>, fn: EachFn<Value, Key, This>) => void;
264
+ declare const flush: <Value extends Function, Key, This>(obj: Eachable<Value, Key, This>, ...args: any[]) => void;
265
+ /**
266
+ * other
267
+ */
268
+ declare const replace: (x?: string, from?: string, to?: string) => string;
269
+ declare const ext: (src?: string) => string;
270
+ declare const fig: (x?: number) => number;
271
+ declare const dig: (x?: number) => number;
272
+ declare const sig: (value?: number, digit?: number) => number;
273
+
274
+ declare const initWebGPUDevice: (el: HTMLCanvasElement) => Promise<{
275
+ device: any;
276
+ context: any;
277
+ format: any;
278
+ } | null>;
279
+ declare const createRenderPipeline: (device: GPUDevice, format: string, vs: string | undefined, fs: string | undefined, buffers: any[]) => GPUPipeline;
280
+ declare const createDescriptor: (c: GPUContext) => {
281
+ colorAttachments: {
282
+ view: any;
283
+ clearValue: {
284
+ r: number;
285
+ g: number;
286
+ b: number;
287
+ a: number;
288
+ };
289
+ loadOp: string;
290
+ storeOp: string;
291
+ }[];
292
+ };
293
+ declare const alignTo256: (size: number) => number;
294
+ declare const createUniformBuffer: (device: GPUDevice, size: number) => Buffer;
295
+ declare const createVertexBuffer: (device: GPUDevice, value: number[]) => Buffer;
296
+ declare const createBindGroup: (device: GPUDevice, pipeline: GPUPipeline, entries: any[]) => any;
297
+ declare const updateBindGroup: (device: GPUDevice, pipeline: GPUPipeline, uniformBuffer: Buffer, textures?: any, sampler?: any) => any;
298
+ declare const createUniform: (device: GPUDevice, buffer: any, data: Float32Array, offset?: number) => void;
299
+ declare const createDeviceTexture: (device: GPUDevice, image: HTMLImageElement) => any;
300
+ declare const createSampler: (device: GPUDevice) => any;
301
+ declare const getDefaultVertices: () => Float32Array<ArrayBuffer>;
302
+
303
+ declare const defaultVertexGLSL = "\n#version 300 es\nvoid main() {\n float x = float(gl_VertexID % 2) * 4.0 - 1.0;\n float y = float(gl_VertexID / 2) * 4.0 - 1.0;\n gl_Position = vec4(x, y, 0.0, 1.0);\n}\n";
304
+ declare const defaultFragmentGLSL = "\n#version 300 es\nprecision mediump float;\nuniform vec2 iResolution;\nout vec4 fragColor;\nvoid main() {\n fragColor = vec4(fract(gl_FragCoord.xy / iResolution), 0, 1);\n}\n";
305
+ declare const createShader: (c: WebGLRenderingContext, source: string, type: number) => WebGLShader;
306
+ declare const createProgram: (c: WebGLRenderingContext, vs?: string, fs?: string) => WebGLProgram;
307
+ declare const createVbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
308
+ declare const createIbo: (c: WebGLRenderingContext, data: number[]) => WebGLBuffer;
309
+ declare const createAttrib: (c: WebGLRenderingContext, stride: number, location: any, vbo: WebGLBuffer, ibo?: WebGLBuffer) => void;
310
+ declare const createTexture: (c: WebGLRenderingContext, img: HTMLImageElement) => WebGLTexture;
311
+ declare const activeTexture: (c: WebGLRenderingContext, location: WebGLUniformLocation | null, unit: number, texture: WebGLTexture) => void;
312
+
313
+ declare const webgl: (gl: GL) => Promise<GL>;
314
+
315
+ declare const webgpu: (gl: GL) => Promise<GL>;
316
+
317
+ declare const isGL: (a: unknown) => a is EventState<GL>;
318
+ declare const isServer: () => boolean;
319
+ declare const isWebGPUSupported: () => boolean;
320
+ declare const createGL: (props?: Partial<GL>) => EventState<{
321
+ isNative: boolean;
322
+ isWebGL: boolean;
323
+ isLoop: boolean;
324
+ isGL: true;
325
+ width: number;
326
+ height: number;
327
+ size: [number, number];
328
+ mouse: [number, number];
329
+ count: number;
330
+ el: HTMLCanvasElement;
331
+ vs: string | X;
332
+ fs: string | X;
333
+ vert: string | X;
334
+ frag: string | X;
335
+ vertex: string | X;
336
+ fragment: string | X;
337
+ webgpu: WebGPUState;
338
+ webgl: WebGLState;
339
+ queue: refr.Queue;
340
+ frame: refr.Frame;
341
+ ref?: any;
342
+ init(): void;
343
+ loop(): void;
344
+ mount(): void;
345
+ clean(): void;
346
+ render(): void;
347
+ resize(e?: Event): void;
348
+ mousemove(e: Event): void;
349
+ _uniform?(key: string, value: Uniform, isMatrix?: boolean): GL;
350
+ uniform(key: string, value: Uniform, isMatrix?: boolean): GL;
351
+ uniform(target: {
352
+ [key: string]: Uniform;
353
+ }): GL;
354
+ _texture?(key: string, value: string): GL;
355
+ texture(key: string, value: string): GL;
356
+ texture(target: {
357
+ [key: string]: string;
358
+ }): GL;
359
+ _attribute?(key: string, value: Attribute, iboValue?: Attribute): GL;
360
+ attribute(key: string, value: Attribute, iboValue?: Attribute): GL;
361
+ attribute(target: {
362
+ [key: string]: Attribute;
363
+ }): GL;
364
+ }, any[] | unknown[]>;
365
+
366
+ export { Attribute, Attributes, CACHE_BOOLS, CACHE_FLOATS, CACHE_INTS, ConditionalNode, ConversionContext, FUNCTIONS, Fn, FunctionNode, GL, GLClearMode, GLDrawMode, GLDrawType, GPUBuffer, GPUContext, GPUDevice, GPUPipeline, If, MathFunction, MathMethods, Node, NodeCreator, NodeType, OPERATORS, Operator, OperatorMethods, PrecisionMode, ProxyCallback, SWIZZLES, Swillzes, SwizzleProperties, TYPES, Uniform, UniformNode, Uniforms, WebGLState, WebGPUState, X, abs, activeTexture, alignTo256, bool, ceil, color, convertToNode, cos, createAttrib, createBindGroup, createDescriptor, createDeviceTexture, createGL, createIbo, createNode, createProgram, createRenderPipeline, createSampler, createShader, createTexture, createUniform, createUniformBuffer, createVbo, createVertexBuffer, createGL as default, defaultFragmentGLSL, defaultVertexGLSL, dig, each, ext, fig, findDuplicateNodes, float, floor, flush, fract, getCachedBool, getCachedFloat, getCachedInt, getDefaultVertices, gl_FragCoord, gl_Position, glsl, iDeltaTime, iMouse, iPrevTime, iResolution, iTime, initWebGPUDevice, int, is, isGL, isServer, isWebGPUSupported, length, node, nodeToGLSL, nodeToWGSL, normalize, replace, sig, sin, sqrt, tan, uniform, updateBindGroup, updateUniforms, vec2, vec3, vec4, webgl, webgpu, wgsl };