@absolutejs/rendering 0.1.0 → 0.2.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 +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/renderTargetScope.d.ts +18 -0
- package/dist/renderTargetScope.js +47 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,3 +35,22 @@ This retains onBeforeCompile, customProgramCacheKey and onBeforeRender. A regist
|
|
|
35
35
|
Qualified against Three r186. No React dependency and no animation loop. Runtime cost is a small callback and destination check per affected draw; switching sampling modes can select another cached shader program. Hardware frame-rate improvements are not claimed. Game-specific foliage algorithms, lighting, world generation and simulation remain outside this package.
|
|
36
36
|
|
|
37
37
|
Use `bun run check:package` to build declarations and run the ownership/policy tests. Browser evidence is retained under docs/.
|
|
38
|
+
|
|
39
|
+
## Scoped captures and readback
|
|
40
|
+
|
|
41
|
+
`renderTargetScope(renderer, run)` restores the render target, cube face, mip,
|
|
42
|
+
viewport, scissor and scissor-test state even if synchronous work throws. The
|
|
43
|
+
callback must finish renderer mutations synchronously; do not hold a scope over
|
|
44
|
+
an await.
|
|
45
|
+
|
|
46
|
+
`readTargetPixelsScoped(renderer, target, width, height, buffer, textureIndex?)`
|
|
47
|
+
submits a byte/float read from a neutral target and restores the caller through
|
|
48
|
+
Three's target setter. This avoids restoring a resolve framebuffer in place of
|
|
49
|
+
its multisample draw attachment, or treating a cube framebuffer array as a single
|
|
50
|
+
framebuffer.
|
|
51
|
+
|
|
52
|
+
`readFloatTargetScoped(...)` submits asynchronous float readback in the same
|
|
53
|
+
neutral state, restores the caller immediately, and returns the exact supplied
|
|
54
|
+
Float32Array on completion. It never restores stale renderer state after await.
|
|
55
|
+
Allocate supported targets and correctly sized buffers before calling these
|
|
56
|
+
helpers. The helpers do not choose formats, sample counts or capture resolution.
|
package/dist/index.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export declare function bindAlphaToCoverageDestination(material: Material, enabl
|
|
|
11
11
|
* Destination policy is cloned independently so changing one owner's preference
|
|
12
12
|
* cannot alter another. No source material is mutated. */
|
|
13
13
|
export declare function cloneRenderMaterial<T extends Material>(source: T): T;
|
|
14
|
+
export { renderTargetScope, readTargetPixelsScoped, readFloatTargetScoped, } from "./renderTargetScope.js";
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type WebGLRenderer } from "three";
|
|
2
|
+
/** Synchronous offscreen work; preserve target attachment, viewport and clipping.
|
|
3
|
+
* The callback must finish its renderer mutations before returning.
|
|
4
|
+
*/
|
|
5
|
+
export declare function renderTargetScope<T>(renderer: WebGLRenderer, run: () => T): T;
|
|
6
|
+
/** Start an async float diagnostic with a neutral current target, then immediately
|
|
7
|
+
* restore the caller's attachment. Three's async reader restores a raw framebuffer
|
|
8
|
+
* property before awaiting; cube/mipmap targets store arrays in that property.
|
|
9
|
+
* Keeping the neutral target only for submission avoids that invalid bind without
|
|
10
|
+
* holding renderer state across the asynchronous wait.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readFloatTargetScoped(renderer: WebGLRenderer, target: import("three").WebGLRenderTarget, width: number, height: number, buffer: Float32Array, textureIndex?: number): Promise<Float32Array>;
|
|
13
|
+
/** Synchronous authoring/diagnostic read. Three restores the raw resolve
|
|
14
|
+
* framebuffer, not a current target's multisample attachment, after reading.
|
|
15
|
+
* Submit from a neutral target and let setRenderTarget restore the actual
|
|
16
|
+
* attachment; otherwise the next draw can resolve stale samples over new data.
|
|
17
|
+
* This also avoids restoring cube/mip framebuffer arrays as a framebuffer. */
|
|
18
|
+
export declare function readTargetPixelsScoped(renderer: WebGLRenderer, target: import("three").WebGLRenderTarget, width: number, height: number, buffer: Uint8Array | Float32Array, textureIndex?: number): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Vector4 } from "three";
|
|
2
|
+
/** Synchronous offscreen work; preserve target attachment, viewport and clipping.
|
|
3
|
+
* The callback must finish its renderer mutations before returning.
|
|
4
|
+
*/
|
|
5
|
+
export function renderTargetScope(renderer, run) {
|
|
6
|
+
const target = renderer.getRenderTarget(), face = renderer.getActiveCubeFace(), mip = renderer.getActiveMipmapLevel();
|
|
7
|
+
const viewport = renderer.getViewport(new Vector4()), scissor = renderer.getScissor(new Vector4()), test = renderer.getScissorTest();
|
|
8
|
+
try {
|
|
9
|
+
renderer.setScissorTest(false);
|
|
10
|
+
return run();
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
renderer.setRenderTarget(target, face, mip);
|
|
14
|
+
renderer.setViewport(viewport);
|
|
15
|
+
renderer.setScissor(scissor);
|
|
16
|
+
renderer.setScissorTest(test);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Start an async float diagnostic with a neutral current target, then immediately
|
|
20
|
+
* restore the caller's attachment. Three's async reader restores a raw framebuffer
|
|
21
|
+
* property before awaiting; cube/mipmap targets store arrays in that property.
|
|
22
|
+
* Keeping the neutral target only for submission avoids that invalid bind without
|
|
23
|
+
* holding renderer state across the asynchronous wait.
|
|
24
|
+
*/
|
|
25
|
+
export function readFloatTargetScoped(renderer, target, width, height, buffer, textureIndex = 0) {
|
|
26
|
+
let pending;
|
|
27
|
+
renderTargetScope(renderer, () => {
|
|
28
|
+
renderer.setRenderTarget(null);
|
|
29
|
+
pending = renderer.readRenderTargetPixelsAsync(target, 0, 0, width, height, buffer, undefined, textureIndex);
|
|
30
|
+
});
|
|
31
|
+
return pending.then((value) => {
|
|
32
|
+
if (value !== buffer)
|
|
33
|
+
throw new Error("Float target read did not return its buffer");
|
|
34
|
+
return buffer;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** Synchronous authoring/diagnostic read. Three restores the raw resolve
|
|
38
|
+
* framebuffer, not a current target's multisample attachment, after reading.
|
|
39
|
+
* Submit from a neutral target and let setRenderTarget restore the actual
|
|
40
|
+
* attachment; otherwise the next draw can resolve stale samples over new data.
|
|
41
|
+
* This also avoids restoring cube/mip framebuffer arrays as a framebuffer. */
|
|
42
|
+
export function readTargetPixelsScoped(renderer, target, width, height, buffer, textureIndex = 0) {
|
|
43
|
+
renderTargetScope(renderer, () => {
|
|
44
|
+
renderer.setRenderTarget(null);
|
|
45
|
+
renderer.readRenderTargetPixels(target, 0, 0, width, height, buffer, undefined, textureIndex);
|
|
46
|
+
});
|
|
47
|
+
}
|
package/package.json
CHANGED