@solidrt/flux-types 0.0.39 → 0.0.40

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 (2) hide show
  1. package/gui/gpu.d.ts +96 -16
  2. package/package.json +1 -1
package/gui/gpu.d.ts CHANGED
@@ -7,19 +7,54 @@
7
7
  // Layering: compileShader/linkProgram are the raw GL primitives (complete
8
8
  // sources, explicit header opt-in); createShader/createPipeline are fused
9
9
  // conveniences (compile + link + target in one call, curated preamble).
10
+ //
11
+ // Sampling is a per-texture property declared at creation: every create path
12
+ // accepts `{ filter?, wrap? }` ("linear"/"nearest", "clamp"/"repeat";
13
+ // defaults linear + clamp for every origin). The state follows the id
14
+ // everywhere it is sampled - shader passes and `<texture>` display alike -
15
+ // and survives id-stable resizes. It cannot be changed after creation. No
16
+ // mipmaps exist.
17
+ //
18
+ // Compositing several targets is a render-tree job, not a shader one: stack
19
+ // `<texture>` elements and set their `blendMode` (the full Skia set, e.g.
20
+ // "plus" for an additive pass over a base pass) instead of writing a pass that
21
+ // samples both. WITHIN one pipeline draw, `blend: "add"` accumulates
22
+ // overlapping geometry additively; anything else (a fragment target, or a
23
+ // pipeline without the option) draws with GL blending disabled and overwrites.
10
24
 
11
25
  declare module "flux:gpu" {
26
+ /**
27
+ * Shader uniform values by name. A number drives a scalar uniform (`float`,
28
+ * or `int`/`bool`, truncated); a flat number array drives a typed uniform
29
+ * whose declared GLSL type sets the expected length: 2/3/4 for
30
+ * `vec2`/`vec3`/`vec4`, 16 (column-major) for `mat4`. Dispatch follows the
31
+ * shader's own declaration; a value whose length does not fit it is skipped
32
+ * with a runtime warning, as is a name with no active uniform.
33
+ */
34
+ export type ShaderParams = Record<string, number | number[]>
35
+ /** Magnification/minification filter; "linear" (default) or hard-pixel "nearest". */
36
+ export type FilterMode = "linear" | "nearest"
37
+ /** Sampling outside 0..1: "clamp" (default, extend edge pixels) or "repeat" (tile). */
38
+ export type WrapMode = "clamp" | "repeat"
39
+ /**
40
+ * Per-texture sampling, declared at creation and fixed for the id's
41
+ * lifetime. Applies wherever the texture is sampled: shader/pipeline
42
+ * sampler2D inputs AND `<texture src>` display (a "nearest" texture
43
+ * upscales with hard pixels on screen - the pixel-art path). `wrap` only
44
+ * matters to shaders sampling outside 0..1; the display draw never tiles.
45
+ */
46
+ export type SamplerOptions = { filter?: FilterMode; wrap?: WrapMode }
12
47
  /**
13
48
  * Create an immutable texture from an RGBA8 pixel buffer (exactly
14
49
  * width*height*4 bytes). Returns the texture id.
15
50
  */
16
- export function createTexture(data: Uint8Array, width: number, height: number): number
51
+ export function createTexture(data: Uint8Array, width: number, height: number, opts?: SamplerOptions): number
17
52
  /**
18
53
  * Create a texture intended to be updated later via {@link uploadTexture}. The
19
54
  * seed buffer must hold at least one frame (width*height*4 bytes) and may hold
20
55
  * more (uploadTexture selects a frame by offset).
21
56
  */
22
- export function createMutableTexture(data: Uint8Array, width: number, height: number): number
57
+ export function createMutableTexture(data: Uint8Array, width: number, height: number, opts?: SamplerOptions): number
23
58
  /**
24
59
  * Replace a mutable texture's pixels. `data` may hold several frames; `offset`
25
60
  * (default 0) selects which frame to upload.
@@ -45,19 +80,35 @@ declare module "flux:gpu" {
45
80
  export function destroyTexture(id: number): void
46
81
  /**
47
82
  * Compile a GLSL ES fragment shader into an offscreen texture of the given
48
- * size. `params` sets float uniforms by name; `textures` binds sampler2D
49
- * uniforms to texture ids. Returns the resulting texture id. The fused
83
+ * size. `params` sets uniforms by name (see {@link ShaderParams} for the
84
+ * value shapes); `textures` binds sampler2D uniforms to texture ids - any
85
+ * texture id, including another shader/pipeline target's output. Bound
86
+ * targets are live dependencies: when a source re-renders (its params,
87
+ * geometry, or data change), every target sampling it re-renders too,
88
+ * transitively through chains, before the next frame or readback - no
89
+ * per-frame uniform write is needed to keep a chain current. Returns the resulting texture id. The fused
50
90
  * convenience: one call compiles a program and creates a target over it,
51
91
  * and the program lives and dies with the target. To share one compile
52
92
  * across targets (or hold a program with no target yet), use the raw layer:
53
93
  * {@link compileShader} + {@link linkProgram} + {@link createShaderTarget}.
94
+ *
95
+ * The preamble (`#version 300 es`, precision, `vUV`, `iResolution`, `iTime`,
96
+ * `fragColor`) is injected only into sources that do not declare their own
97
+ * `#version` line. A source that starts with `#version 300 es` is compiled
98
+ * exactly as written, so a shader with its own uniform names (a port from
99
+ * elsewhere) needs no rewriting and no drop to the raw layer. The built-in
100
+ * vertex stage still supplies `vUV` to a complete source; declare
101
+ * `in vec2 vUV;` yourself to read it. Same rule on {@link createPipeline}.
102
+ * A complete source may also declare `iResolution` as vec3 (the Shadertoy
103
+ * shape); it is then filled as `(w, h, 1.0)`.
54
104
  */
55
105
  export function createShader(
56
106
  fragmentSrc: string,
57
107
  width: number,
58
108
  height: number,
59
- params?: Record<string, number>,
109
+ params?: ShaderParams,
60
110
  textures?: Record<string, number>,
111
+ opts?: SamplerOptions,
61
112
  ): number
62
113
  /**
63
114
  * Compile a single shader stage from raw GLSL ES: the primitive under
@@ -108,15 +159,17 @@ declare module "flux:gpu" {
108
159
  width: number,
109
160
  height: number,
110
161
  opts?: {
111
- params?: Record<string, number>
162
+ params?: ShaderParams
112
163
  textures?: Record<string, number>
113
164
  attributes?: VertexAttribute[]
114
165
  buffer?: number
115
166
  topology?: Topology
116
167
  vertexCount?: number
117
168
  depth?: boolean
169
+ depthWrite?: boolean
170
+ blend?: BlendMode
118
171
  clearColor?: [number, number, number, number]
119
- },
172
+ } & SamplerOptions,
120
173
  ): number
121
174
  /**
122
175
  * Destroy a linked program by id. Targets created from it are unaffected:
@@ -125,16 +178,20 @@ declare module "flux:gpu" {
125
178
  * immediately.
126
179
  */
127
180
  export function destroyProgram(id: number): void
128
- /** Update a shader texture's float uniforms by name and re-render it. */
129
- export function setShaderParams(id: number, params: Record<string, number>): void
181
+ /**
182
+ * Update a shader texture's uniforms by name and re-render it (see
183
+ * {@link ShaderParams} for the value shapes).
184
+ */
185
+ export function setShaderParams(id: number, params: ShaderParams): void
130
186
  /**
131
187
  * Rebind a shader texture's sampler2D inputs by uniform name and re-render
132
188
  * it with its last-applied params - the sampler analog of
133
189
  * {@link setShaderParams}. Bindings not named keep their current source, so
134
190
  * a single input can be retargeted (post-process source swap, ping-pong
135
191
  * between two data textures) without recompiling the shader. Throws if the
136
- * shader or a source texture id is unknown, or a sampler would source the
137
- * shader's own target.
192
+ * shader or a source texture id is unknown, or a binding would create a
193
+ * sampling cycle among targets (binding a shader's own target is the
194
+ * shortest case).
138
195
  */
139
196
  export function setShaderTextures(id: number, textures: Record<string, number>): void
140
197
  /**
@@ -146,6 +203,17 @@ declare module "flux:gpu" {
146
203
  export function setShaderSize(id: number, width: number, height: number): void
147
204
 
148
205
  export type Topology = "points" | "lines" | "line-strip" | "triangles" | "triangle-strip"
206
+ /**
207
+ * Blending for a pipeline's own draw. "none" (default) overwrites:
208
+ * overlapping geometry resolves by depth or draw order. "add" accumulates
209
+ * (glBlendFunc(ONE, ONE)): order-independent, so geometry needs no sorting
210
+ * - the additive half of translucency (point splats, glow passes). A
211
+ * depth-tested additive pass usually pairs with `depthWrite: false`; with
212
+ * writes on, unsorted geometry depth-rejects its own later fragments and
213
+ * accumulation becomes draw-order-dependent. That pairing is the app's to
214
+ * state - neither option implies the other.
215
+ */
216
+ export type BlendMode = "none" | "add"
149
217
  /**
150
218
  * One float attribute of an interleaved vertex. The attribute list's order
151
219
  * defines the byte layout; locations are resolved by name against the
@@ -161,8 +229,13 @@ declare module "flux:gpu" {
161
229
  * `buffer` (a {@link createBuffer} id); omit both for attributeless
162
230
  * rendering via gl_VertexID. `vertexCount` defaults to the whole buffer
163
231
  * (buffer size / vertex stride). With `depth: true` the pipeline gets a
164
- * private depth buffer, cleared and tested on every render. The target is
165
- * cleared to `clearColor` (default transparent black) before each draw.
232
+ * private depth buffer, cleared and tested on every render; `depthWrite:
233
+ * false` (requires `depth: true`) keeps the test but stops the draw from
234
+ * writing depth. `blend` sets the draw's own blending (see
235
+ * {@link BlendMode}); an additive pass over a depth buffer is
236
+ * `{ depth: true, blend: "add", depthWrite: false }`, stated explicitly.
237
+ * The target is cleared to `clearColor` (default transparent black) before
238
+ * each draw.
166
239
  * Returns a texture id: display it with `<texture src>`, drive uniforms via
167
240
  * the `params` prop or {@link setShaderParams}, destroy with
168
241
  * {@link destroyTexture}.
@@ -173,15 +246,17 @@ declare module "flux:gpu" {
173
246
  width: number,
174
247
  height: number,
175
248
  opts?: {
176
- params?: Record<string, number>
249
+ params?: ShaderParams
177
250
  textures?: Record<string, number>
178
251
  attributes?: VertexAttribute[]
179
252
  buffer?: number
180
253
  topology?: Topology
181
254
  vertexCount?: number
182
255
  depth?: boolean
256
+ depthWrite?: boolean
257
+ blend?: BlendMode
183
258
  clearColor?: [number, number, number, number]
184
- },
259
+ } & SamplerOptions,
185
260
  ): number
186
261
 
187
262
  /**
@@ -206,7 +281,12 @@ declare module "flux:gpu" {
206
281
  /**
207
282
  * Capture a render-tree node's subtree into a new GPU texture, resolving once
208
283
  * it has been rendered on the next paint pass. The node must be attached to
209
- * the live tree (a detached node is never painted, so its capture rejects).
284
+ * the live tree (an unmounted node is never painted, so its capture rejects)
285
+ * and paint a non-zero box. A laid-out node captures its layout box. A `d-*`
286
+ * node has no layout box - that is what detached means - so it captures its
287
+ * painted box instead: its own `w`/`h` when set, else the nearest laid-out
288
+ * ancestor's box (the same box the render tree reports for it), with its
289
+ * `x`/`y` paint offset mapped to the texture origin.
210
290
  * Rendered at the current display scale, so `width`/`height` are the texture's
211
291
  * actual pixel dimensions (ceil(logicalSize * displayScale)), not logical
212
292
  * points. Each call returns an independent id you must {@link destroyTexture}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/flux-types",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "types": "index.d.ts",