@solidrt/flux-types 0.0.38 → 0.0.39

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 +97 -5
  2. package/package.json +1 -1
package/gui/gpu.d.ts CHANGED
@@ -1,7 +1,12 @@
1
- // Low-level GPU textures and fragment shaders (gui-enabled runtime only). The
2
- // imperative primitive; @solidrt/core's gpu helpers add reactive auto-cleanup on
3
- // top. Texture ids are the public token (used as `<texture src>` and shader
4
- // sampler inputs), so there is no handle to hide here.
1
+ // Low-level GPU textures and shaders (gui-enabled runtime only). The
2
+ // imperative primitive; @solidrt/core's gpu helpers add reactive auto-cleanup
3
+ // on top. Three id spaces, each destroyed by its own destroyer: texture ids
4
+ // (the public token used as `<texture src>` and sampler inputs ->
5
+ // destroyTexture), buffer ids (-> destroyBuffer), and the raw shading layer's
6
+ // shader-stage ids (-> destroyShader) and program ids (-> destroyProgram).
7
+ // Layering: compileShader/linkProgram are the raw GL primitives (complete
8
+ // sources, explicit header opt-in); createShader/createPipeline are fused
9
+ // conveniences (compile + link + target in one call, curated preamble).
5
10
 
6
11
  declare module "flux:gpu" {
7
12
  /**
@@ -41,7 +46,11 @@ declare module "flux:gpu" {
41
46
  /**
42
47
  * Compile a GLSL ES fragment shader into an offscreen texture of the given
43
48
  * size. `params` sets float uniforms by name; `textures` binds sampler2D
44
- * uniforms to texture ids. Returns the resulting texture id.
49
+ * uniforms to texture ids. Returns the resulting texture id. The fused
50
+ * convenience: one call compiles a program and creates a target over it,
51
+ * and the program lives and dies with the target. To share one compile
52
+ * across targets (or hold a program with no target yet), use the raw layer:
53
+ * {@link compileShader} + {@link linkProgram} + {@link createShaderTarget}.
45
54
  */
46
55
  export function createShader(
47
56
  fragmentSrc: string,
@@ -50,6 +59,72 @@ declare module "flux:gpu" {
50
59
  params?: Record<string, number>,
51
60
  textures?: Record<string, number>,
52
61
  ): number
62
+ /**
63
+ * Compile a single shader stage from raw GLSL ES: the primitive under
64
+ * {@link linkProgram}, GL's own model (a "shader" is one stage; linking
65
+ * stages yields a program). The source is complete - it declares its own
66
+ * `#version 300 es`, precision, varyings and uniforms; nothing is injected.
67
+ * With `header: true` the standard header is prepended explicitly: `#version
68
+ * 300 es`, `precision highp float;`, `uniform vec2 iResolution;`, `uniform
69
+ * float iTime;`, plus `out vec4 fragColor;` for a fragment stage (the same
70
+ * text {@link createPipeline} injects). Do not combine `header` with your
71
+ * own `#version` line. Returns a shader (stage) id in its own id space;
72
+ * compile errors throw here, synchronously, at a call site the app chose.
73
+ * Free with {@link destroyShader}.
74
+ */
75
+ export function compileShader(
76
+ stage: "vertex" | "fragment",
77
+ source: string,
78
+ opts?: { header?: boolean },
79
+ ): number
80
+ /**
81
+ * Link a compiled vertex and fragment stage into a program, returning a
82
+ * program id (its own id space, like buffers - not a texture id). Link
83
+ * errors throw here. The stages remain usable for further links (mix one
84
+ * vertex stage with many fragment stages and vice versa), and may be
85
+ * destroyed right after: a linked program keeps its own compiled copies.
86
+ * Creating targets from the returned handle compiles nothing. Free with
87
+ * {@link destroyProgram}.
88
+ */
89
+ export function linkProgram(vertexShader: number, fragmentShader: number): number
90
+ /**
91
+ * Destroy a compiled stage by id. Programs linked from it are unaffected.
92
+ */
93
+ export function destroyShader(id: number): void
94
+ /**
95
+ * Create a render target over a linked program and render it once: the
96
+ * target half of {@link createPipeline}. Returns a texture id exactly like
97
+ * createShader/createPipeline do (drive uniforms via the `params` prop or
98
+ * {@link setShaderParams}, resize with {@link setShaderSize}, destroy with
99
+ * {@link destroyTexture}). Many targets may share one program. A raw-linked
100
+ * program carries its own vertex stage, so the mesh options apply:
101
+ * `attributes`/`buffer` for vertex input (omit for attributeless rendering
102
+ * via gl_VertexID - a fullscreen pass is `vertexCount: 3` with a
103
+ * covering-triangle vertex stage), `topology`, `vertexCount`, `depth`,
104
+ * `clearColor`, all as in {@link createPipeline}.
105
+ */
106
+ export function createShaderTarget(
107
+ program: number,
108
+ width: number,
109
+ height: number,
110
+ opts?: {
111
+ params?: Record<string, number>
112
+ textures?: Record<string, number>
113
+ attributes?: VertexAttribute[]
114
+ buffer?: number
115
+ topology?: Topology
116
+ vertexCount?: number
117
+ depth?: boolean
118
+ clearColor?: [number, number, number, number]
119
+ },
120
+ ): number
121
+ /**
122
+ * Destroy a linked program by id. Targets created from it are unaffected:
123
+ * each holds the program until it is itself destroyed, so either
124
+ * destruction order is safe. The id stops being usable for new targets
125
+ * immediately.
126
+ */
127
+ export function destroyProgram(id: number): void
53
128
  /** Update a shader texture's float uniforms by name and re-render it. */
54
129
  export function setShaderParams(id: number, params: Record<string, number>): void
55
130
  /**
@@ -137,6 +212,23 @@ declare module "flux:gpu" {
137
212
  * points. Each call returns an independent id you must {@link destroyTexture}
138
213
  * when done. Use the returned id anywhere a texture id is accepted
139
214
  * (`<texture src>`, a shader sampler input, {@link readTexture}).
215
+ *
216
+ * Intended for one-shot bakes and inspection: turning something the engine
217
+ * can draw but the app cannot compute - shaped text, an SVG, a themed view -
218
+ * into pixels, usually to hand to {@link readTexture} and process on the CPU.
219
+ * Baking a glyph atlas by laying out cells, capturing them and keeping the
220
+ * coverage channel is the worked example. Tests and freeze-frames are the
221
+ * same shape.
222
+ *
223
+ * Not a rendering primitive. Every call rasterizes the subtree into a fresh
224
+ * offscreen MSAA target, reads the pixels back to the CPU and uploads them
225
+ * again as a new texture: a full GPU -> CPU -> GPU round trip plus a paint
226
+ * pass of latency, per call, with nothing incremental about it. Batch what
227
+ * you capture (many nodes captured together are serviced by one paint pass),
228
+ * and do not drive it per frame or reach for it to feed live content into a
229
+ * shader - an effect over what is beneath it, a backdrop filter. Content that
230
+ * must stay current has to come from a source that updates in place: another
231
+ * pipeline's render target, a camera texture, a mutable texture.
140
232
  */
141
233
  export function captureSnapshot(nodeId: number): Promise<{ id: number; width: number; height: number }>
142
234
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/flux-types",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "types": "index.d.ts",