glre 0.44.0 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.ts CHANGED
@@ -112,7 +112,7 @@ interface NodeContext {
112
112
  fragInputs: Map<string, string>;
113
113
  vertInputs: Map<string, string>;
114
114
  vertOutputs: Map<string, string>;
115
- vertVaryings: Map<string, string>;
115
+ vertVaryings: Map<string, VaryingInfo>;
116
116
  computeInputs: Map<string, string>;
117
117
  dependencies: Map<string, Set<string>>;
118
118
  structStructFields: Map<string, StructFields>;
@@ -208,6 +208,10 @@ type Mat4 = XImpl<'mat4'>;
208
208
  type Texture$1 = XImpl<'texture'>;
209
209
  type Sampler2D = XImpl<'sampler2D'>;
210
210
  type StructBase = XImpl<'struct'>;
211
+ interface VaryingInfo {
212
+ node: Y;
213
+ code?: string;
214
+ }
211
215
  interface ConstantsToType {
212
216
  void: Void;
213
217
  bool: Bool;
@@ -244,6 +248,7 @@ type XImpl<T extends C> = _X<T> & {
244
248
  };
245
249
  type C = Constants;
246
250
  type X<T extends C = C> = T extends keyof ConstantsToType ? ConstantsToType[T] : _X<T>;
251
+ type Y<T extends C = C> = number | number[] | string | boolean | undefined | HTMLElement | X<T>;
247
252
  type Methods = Functions | Operators | Conversions | Swizzles | '__nodeType' | 'type' | 'props' | 'isProxy' | 'assign' | 'toVar' | 'toString' | 'element' | 'select';
248
253
  interface _X<T extends C> {
249
254
  readonly __nodeType?: T;
package/dist/solid.d.ts CHANGED
@@ -112,7 +112,7 @@ interface NodeContext {
112
112
  fragInputs: Map<string, string>;
113
113
  vertInputs: Map<string, string>;
114
114
  vertOutputs: Map<string, string>;
115
- vertVaryings: Map<string, string>;
115
+ vertVaryings: Map<string, VaryingInfo>;
116
116
  computeInputs: Map<string, string>;
117
117
  dependencies: Map<string, Set<string>>;
118
118
  structStructFields: Map<string, StructFields>;
@@ -208,6 +208,10 @@ type Mat4 = XImpl<'mat4'>;
208
208
  type Texture$1 = XImpl<'texture'>;
209
209
  type Sampler2D = XImpl<'sampler2D'>;
210
210
  type StructBase = XImpl<'struct'>;
211
+ interface VaryingInfo {
212
+ node: Y;
213
+ code?: string;
214
+ }
211
215
  interface ConstantsToType {
212
216
  void: Void;
213
217
  bool: Bool;
@@ -244,6 +248,7 @@ type XImpl<T extends C> = _X<T> & {
244
248
  };
245
249
  type C = Constants;
246
250
  type X<T extends C = C> = T extends keyof ConstantsToType ? ConstantsToType[T] : _X<T>;
251
+ type Y<T extends C = C> = number | number[] | string | boolean | undefined | HTMLElement | X<T>;
247
252
  type Methods = Functions | Operators | Conversions | Swizzles | '__nodeType' | 'type' | 'props' | 'isProxy' | 'assign' | 'toVar' | 'toString' | 'element' | 'select';
248
253
  interface _X<T extends C> {
249
254
  readonly __nodeType?: T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glre",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "author": "tseijp",
5
5
  "license": "MIT",
6
6
  "private": false,
package/src/node/build.ts CHANGED
@@ -104,6 +104,7 @@ export const fragment = (x: X, c: NodeContext = {}) => {
104
104
  export const vertex = (x: X, c: NodeContext = {}) => {
105
105
  c.code?.headers?.clear()
106
106
  c.label = 'vert' // for varying inputs or outputs
107
+ if (c.code) for (const [id, { node }] of c.code.vertVaryings.entries()) c.code.vertVaryings.set(id, { node, code: code(node, c) }) // ① prebuild varying.code because the scope (e.g. output function definitions) is fixed to vertex.
107
108
  const [head, lines, ret] = build(x, c)
108
109
  const result = []
109
110
  if (c.isWebGL) {
@@ -114,7 +115,7 @@ export const vertex = (x: X, c: NodeContext = {}) => {
114
115
  result.push('void main() {')
115
116
  result.push(` ${lines}`)
116
117
  result.push(` gl_Position = ${ret};`)
117
- for (const [id, code] of c.code?.vertVaryings?.entries() || []) result.push(` ${id} = ${code};`)
118
+ if (c.code) for (const [id, varying] of c.code.vertVaryings.entries()) result.push(` ${id} = ${varying.code!};`) // ② varying.code is already prebuilt
118
119
  } else {
119
120
  if (c.code?.vertInputs?.size) result.push(generateStruct('In', c.code.vertInputs))
120
121
  if (c.code?.vertOutputs?.size) result.push(generateStruct('Out', c.code.vertOutputs))
@@ -124,7 +125,7 @@ export const vertex = (x: X, c: NodeContext = {}) => {
124
125
  result.push(' var out: Out;')
125
126
  result.push(` ${lines}`)
126
127
  result.push(` out.position = ${ret};`)
127
- for (const [id, code] of c.code?.vertVaryings?.entries() || []) result.push(` out.${id} = ${code};`)
128
+ if (c.code) for (const [id, varying] of c.code.vertVaryings.entries()) result.push(` out.${id} = ${varying.code!};`)
128
129
  result.push(' return out;')
129
130
  }
130
131
  result.push('}')
package/src/node/types.ts CHANGED
@@ -90,7 +90,7 @@ export interface NodeContext {
90
90
  fragInputs: Map<string, string>
91
91
  vertInputs: Map<string, string>
92
92
  vertOutputs: Map<string, string>
93
- vertVaryings: Map<string, string>
93
+ vertVaryings: Map<string, VaryingInfo>
94
94
  computeInputs: Map<string, string>
95
95
  dependencies: Map<string, Set<string>>
96
96
  structStructFields: Map<string, StructFields>
@@ -202,6 +202,12 @@ export type Mat4 = XImpl<'mat4'>
202
202
  export type Texture = XImpl<'texture'>
203
203
  export type Sampler2D = XImpl<'sampler2D'>
204
204
  export type StructBase = XImpl<'struct'>
205
+
206
+ export interface VaryingInfo {
207
+ node: Y
208
+ code?: string
209
+ }
210
+
205
211
  export type Struct<T extends StructFields = any> = Omit<StructBase, keyof T> & {
206
212
  [K in keyof T]: T[K] extends X<infer U> ? X<U> : never
207
213
  } & {
@@ -1,23 +1,6 @@
1
1
  import { infer } from './infer'
2
- import {
3
- parseArray,
4
- parseAttribHead,
5
- parseConstantHead,
6
- parseDeclare,
7
- parseDefine,
8
- parseGather,
9
- parseIf,
10
- parseLoop,
11
- parseScatter,
12
- parseStorageHead,
13
- parseStruct,
14
- parseStructHead,
15
- parseSwitch,
16
- parseTexture,
17
- parseUniformHead,
18
- parseVaryingHead,
19
- } from './parse'
20
- import { getBluiltin, getConversions, getOperator, initNodeContext, isElement, isX, setupEvent } from './utils'
2
+ import { parseArray, parseAttribHead, parseConstantHead, parseDeclare, parseDefine, parseGather, parseIf, parseLoop, parseScatter, parseStorageHead, parseStruct, parseStructHead, parseSwitch, parseTexture, parseUniformHead, parseVaryingHead } from './parse'
3
+ import { getBluiltin, getConversions, getOperator, initNodeContext, isX, setupEvent } from './utils'
21
4
  import { is } from '../../utils/helpers'
22
5
  import { mod } from '..'
23
6
  import type { Constants as C, NodeContext, Y } from '../types'
@@ -58,10 +41,7 @@ export const code = <T extends C>(target: Y<T>, c?: NodeContext | null): string
58
41
  ? parseScatter(c, storageNode, y) // indexNode is not using
59
42
  : `${code(storageNode, c)}[${code(indexNode, c)}] = ${code(y, c)};`
60
43
  }
61
- if (type === 'ternary')
62
- return c.isWebGL
63
- ? `(${code(z, c)} ? ${code(x, c)} : ${code(y, c)})`
64
- : `select(${code(x, c)}, ${code(y, c)}, ${code(z, c)})`
44
+ if (type === 'ternary') return c.isWebGL ? `(${code(z, c)} ? ${code(x, c)} : ${code(y, c)})` : `select(${code(x, c)}, ${code(y, c)}, ${code(z, c)})`
65
45
  if (type === 'conversion') return `${getConversions(x, c)}(${parseArray(children.slice(1), c)})`
66
46
  if (type === 'operator') {
67
47
  if (x === 'not' || x === 'bitNot') return `!${code(y, c)}`
@@ -110,7 +90,7 @@ export const code = <T extends C>(target: Y<T>, c?: NodeContext | null): string
110
90
  const field = parseVaryingHead(c, id, infer(target, c))
111
91
  c.code?.fragInputs.set(id, field)
112
92
  c.code?.vertOutputs.set(id, field)
113
- c.code?.vertVaryings.set(id, code(x, c))
93
+ c.code?.vertVaryings.set(id, { node: x })
114
94
  return c.isWebGL ? `${id}` : `out.${id}`
115
95
  }
116
96
  if (type === 'builtin') {
@@ -1,14 +1,6 @@
1
- import {
2
- CONSTANTS,
3
- CONVERSIONS,
4
- FUNCTIONS,
5
- OPERATOR_KEYS,
6
- OPERATORS,
7
- TYPE_MAPPING,
8
- WGSL_TO_GLSL_BUILTIN,
9
- } from './const'
1
+ import { CONSTANTS, CONVERSIONS, FUNCTIONS, OPERATOR_KEYS, OPERATORS, TYPE_MAPPING, WGSL_TO_GLSL_BUILTIN } from './const'
10
2
  import { is } from '../../utils/helpers'
11
- import type { Constants as C, Conversions, Functions, NodeContext, Operators, Swizzles, X, Y } from '../types'
3
+ import type { Constants as C, Conversions, Functions, NodeContext, Operators, Swizzles, VaryingInfo, X, Y } from '../types'
12
4
  import { storageSize } from '../../utils/program'
13
5
 
14
6
  export const isSwizzle = (key: unknown): key is Swizzles => {