gputex 0.3.4 → 0.5.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 +173 -93
- package/dist/index.d.ts +198 -67
- package/dist/index.js +1406 -672
- package/dist/testing.d.ts +52 -15
- package/dist/testing.js +935 -109
- package/dist/three.d.ts +80 -21
- package/dist/three.js +1740 -719
- package/package.json +1 -1
package/dist/three.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TextureHint, PreferredFormat,
|
|
2
|
-
export { ASTC4x4Encoder, ASTC4x4WebGLEncoder, BC1Encoder, BC1WebGLEncoder, BC5Encoder, BC5WebGLEncoder, BC7Encoder, BC7WebGLEncoder, Capabilities, EncodeBytesResult, EncodeCallOptions, EncoderConstructor, EncoderOptions, ExtensionProvider, FeatureProvider, FormatSelection, FormatVariant, MipLevel, RasterizeSvgOptions, RawPixelSource, SelectFormatOptions, WebGLBlockEncoder, WebGLCapabilities, WebGLEncodeBytesResult, WebGLEncoderConstructor, WebGLEncoderImageSource, WebGLEncoderOptions, WebGLFormatSelection, WebGPUFeature, createWebGLContext, detectCapabilities, detectWebGLCapabilities, generateMipChain, getSharedWebGLContext, isWebGLAvailable, padToBlockMultiple, rasterizeSvg, selectFormat, selectWebGLFormat } from './index.js';
|
|
1
|
+
import { TextureHint, PreferredFormat, FormatQuality, SvgRasterSize, TextureFormat, Encoder, EncoderImageSource } from './index.js';
|
|
2
|
+
export { ASTC4x4Encoder, ASTC4x4WebGLEncoder, BC1Encoder, BC1WebGLEncoder, BC5Encoder, BC5WebGLEncoder, BC7Encoder, BC7EncoderOptions, BC7WebGLEncoder, Capabilities, ETC2Encoder, EncodeBytesResult, EncodeCallOptions, EncodeMipChainResult, EncodedLevelBytes, EncoderConstructor, EncoderOptions, ExtensionProvider, FeatureProvider, FormatSelection, FormatVariant, MipLevel, RasterizeSvgOptions, RawPixelSource, SelectFormatOptions, WebGLBlockEncoder, WebGLCapabilities, WebGLEncodeBytesResult, WebGLEncoderConstructor, WebGLEncoderImageSource, WebGLEncoderOptions, WebGLFormatSelection, WebGPUFeature, createWebGLContext, detectCapabilities, detectWebGLCapabilities, generateGpuMipChain, generateMipChain, getSharedWebGLContext, gpuMipLevelCount, isWebGLAvailable, padToBlockMultiple, rasterizeSvg, selectFormat, selectWebGLFormat } from './index.js';
|
|
3
3
|
import { Texture, CompressedTexture, Loader, CompressedPixelFormat } from 'three';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -18,12 +18,22 @@ interface CompressOptions {
|
|
|
18
18
|
hint?: TextureHint;
|
|
19
19
|
/**
|
|
20
20
|
* Prefer a specific format over the default choice when the device
|
|
21
|
-
* supports it; falls back to the normal selection (BC7 → ASTC →
|
|
22
|
-
* when it doesn't. Currently only 'bc1': half the memory of BC7
|
|
23
|
-
* opaque colour textures, at lower quality. Only honoured with
|
|
21
|
+
* supports it; falls back to the normal selection (BC7 → ASTC → ETC2 →
|
|
22
|
+
* RGBA8) when it doesn't. Currently only 'bc1': half the memory of BC7
|
|
23
|
+
* for opaque colour textures, at lower quality. Only honoured with
|
|
24
24
|
* `hint: 'color'` — BC1 can't carry real alpha or normal maps.
|
|
25
25
|
*/
|
|
26
26
|
preferredFormat?: PreferredFormat;
|
|
27
|
+
/**
|
|
28
|
+
* Memory/fidelity trade-off for opaque colour textures. Default 'high'
|
|
29
|
+
* (BC7 / ASTC 4×4, 1 byte/pixel). 'low' picks the 4-bpp formats when the
|
|
30
|
+
* device has one — BC1 on desktop-class GPUs, ETC2 RGB8 on mobile-class
|
|
31
|
+
* ones — halving GPU memory at visibly lower quality on smooth content.
|
|
32
|
+
* Ignored for `hint: 'colorWithAlpha'` and `hint: 'normal'` (the 4-bpp
|
|
33
|
+
* formats can't carry them). On the WebGL fallback tier only BC1 is
|
|
34
|
+
* available at 'low'.
|
|
35
|
+
*/
|
|
36
|
+
quality?: FormatQuality;
|
|
27
37
|
/** Pick the sRGB or linear variant of the chosen format. Default 'srgb'. */
|
|
28
38
|
colorSpace?: 'srgb' | 'linear';
|
|
29
39
|
/**
|
|
@@ -38,19 +48,31 @@ interface CompressOptions {
|
|
|
38
48
|
flipY?: boolean;
|
|
39
49
|
/** Generate a full mip chain down to 1×1 on the CPU, encode every level. */
|
|
40
50
|
mipmaps?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Encode quality / speed trade-off. 'fast' (default) is ~2–4× faster for a
|
|
43
|
-
* ≤0.36 dB PSNR cost; 'high' runs the exhaustive search (output identical to
|
|
44
|
-
* the CPU reference encoders; for BC1, a principal-axis seed + iterative
|
|
45
|
-
* refit). No effect on the WebGL fallback (which always uses the fast
|
|
46
|
-
* encoders).
|
|
47
|
-
*/
|
|
48
|
-
quality?: EncodeQuality;
|
|
49
51
|
/** Reuse an existing device (e.g. Three.js's renderer device) instead
|
|
50
52
|
* of creating a new one. WebGPU path only. When provided, the encoder
|
|
51
53
|
* never destroys it. */
|
|
52
54
|
device?: GPUDevice;
|
|
53
55
|
adapter?: GPUAdapter;
|
|
56
|
+
/**
|
|
57
|
+
* Keep the compressed bytes in a session-scoped in-memory LRU and reuse
|
|
58
|
+
* them on repeat calls, skipping BOTH the image decode and the encode —
|
|
59
|
+
* the dominant costs. Re-loading a texture later in the session (e.g.
|
|
60
|
+
* two worlds sharing an atlas) becomes a few ms. Keyed by source
|
|
61
|
+
* identity + selected format + encode options; capped at 256 MiB of
|
|
62
|
+
* compressed bytes by default (`setTranscodeCacheLimit()` to tune) and
|
|
63
|
+
* never touches persistent storage. Default false.
|
|
64
|
+
*
|
|
65
|
+
* URL and Blob/File sources get an identity automatically (URL string or
|
|
66
|
+
* content hash). Pixel sources (ImageBitmap, canvas, ImageData) are only
|
|
67
|
+
* cached when `cacheKey` is provided.
|
|
68
|
+
*/
|
|
69
|
+
cache?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Explicit cache identity for the source, overriding the derived one.
|
|
72
|
+
* Use when you already know a stable name (e.g. an asset path) and want
|
|
73
|
+
* to skip content hashing, or to make pixel sources cacheable.
|
|
74
|
+
*/
|
|
75
|
+
cacheKey?: string;
|
|
54
76
|
}
|
|
55
77
|
interface CompressResult {
|
|
56
78
|
/** CompressedTexture on a compressed path; Texture on RGBA8 fallback. */
|
|
@@ -75,12 +97,43 @@ interface CompressResult {
|
|
|
75
97
|
mipLevels: number;
|
|
76
98
|
/** Wall-clock time of GPU encoding, summed across mip levels. */
|
|
77
99
|
encodeMs: number;
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
100
|
+
/**
|
|
101
|
+
* Wall-clock time to turn the source into decoded RGBA pixels: fetch /
|
|
102
|
+
* base64 decode, image decode, SVG rasterisation. Usually the dominant
|
|
103
|
+
* cost for large images — when a load feels slower than `encodeMs`
|
|
104
|
+
* suggests, this is where the time went.
|
|
105
|
+
*/
|
|
106
|
+
decodeMs: number;
|
|
107
|
+
/** Wall-clock time of the whole `compressTexture()` call: decode + CPU
|
|
108
|
+
* mip generation + encode + texture assembly. */
|
|
109
|
+
totalMs: number;
|
|
110
|
+
/** True when the result came from the in-memory transcode cache (the
|
|
111
|
+
* `cache` option) — no decode or encode ran; decodeMs/encodeMs are 0. */
|
|
112
|
+
cacheHit: boolean;
|
|
113
|
+
/** Dispose the texture and release GPU resources owned by this call.
|
|
114
|
+
* On the default path (no `device`/`adapter` option) the encoder and
|
|
115
|
+
* device are shared across `compressTexture()` calls and survive this —
|
|
116
|
+
* release those with `releaseSharedGpuResources()`. */
|
|
80
117
|
destroy(): void;
|
|
81
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Destroy the WebGPU device and encoders that `compressTexture()` shares
|
|
121
|
+
* across calls (created lazily when neither the `device` nor the `adapter`
|
|
122
|
+
* option is passed). Safe to call at any time — in-flight encodes on the
|
|
123
|
+
* shared device will fail, and the next `compressTexture()` call recreates
|
|
124
|
+
* everything. No-op when nothing is cached.
|
|
125
|
+
*/
|
|
126
|
+
declare function releaseSharedGpuResources(): void;
|
|
82
127
|
declare function compressTexture(source: CompressTextureSource, options?: CompressOptions): Promise<CompressResult>;
|
|
83
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Cap the cache's total compressed payload in bytes (default 256 MiB).
|
|
131
|
+
* Lower it to evict immediately; 0 disables caching entirely.
|
|
132
|
+
*/
|
|
133
|
+
declare function setTranscodeCacheLimit(bytes: number): void;
|
|
134
|
+
/** Drop every cached transcode. Textures already built from entries are unaffected. */
|
|
135
|
+
declare function clearTranscodeCache(): void;
|
|
136
|
+
|
|
84
137
|
declare class GputexLoader extends Loader<Texture> {
|
|
85
138
|
/** Format-selection hint. Default 'color'. */
|
|
86
139
|
hint: TextureHint;
|
|
@@ -90,6 +143,12 @@ declare class GputexLoader extends Loader<Texture> {
|
|
|
90
143
|
* `CompressOptions.preferredFormat`.
|
|
91
144
|
*/
|
|
92
145
|
preferredFormat?: PreferredFormat;
|
|
146
|
+
/**
|
|
147
|
+
* Memory/fidelity trade-off: 'high' (default, BC7 / ASTC) or 'low'
|
|
148
|
+
* (BC1 / ETC2 RGB8 at half the memory, opaque colour only). See
|
|
149
|
+
* `CompressOptions.quality`.
|
|
150
|
+
*/
|
|
151
|
+
quality: FormatQuality;
|
|
93
152
|
/** Pick the sRGB or linear variant of the chosen format. Default 'srgb'. */
|
|
94
153
|
colorSpace: 'srgb' | 'linear';
|
|
95
154
|
/**
|
|
@@ -102,8 +161,10 @@ declare class GputexLoader extends Loader<Texture> {
|
|
|
102
161
|
flipY: boolean;
|
|
103
162
|
/** Generate + encode a full mip chain. Default false. */
|
|
104
163
|
mipmaps: boolean;
|
|
105
|
-
/**
|
|
106
|
-
|
|
164
|
+
/** Reuse compressed bytes from the session's in-memory transcode cache,
|
|
165
|
+
* skipping decode + encode on repeat loads. See `CompressOptions.cache`.
|
|
166
|
+
* Default false. */
|
|
167
|
+
cache: boolean;
|
|
107
168
|
/**
|
|
108
169
|
* Optional pre-existing WebGPU device. Reusing the renderer's device
|
|
109
170
|
* avoids spinning up a second WebGPU context for encoding.
|
|
@@ -158,8 +219,6 @@ interface EncodeResult {
|
|
|
158
219
|
interface EncodeToTextureOptions {
|
|
159
220
|
/** Pick the sRGB or linear variant of the encoder's format. Default 'srgb'. */
|
|
160
221
|
colorSpace?: 'srgb' | 'linear';
|
|
161
|
-
/** Encode quality / speed trade-off. Default 'fast'. */
|
|
162
|
-
quality?: EncodeQuality;
|
|
163
222
|
/** Flip the image vertically before encoding. Default false. */
|
|
164
223
|
flipY?: boolean;
|
|
165
224
|
}
|
|
@@ -169,6 +228,6 @@ interface EncodeToTextureOptions {
|
|
|
169
228
|
* `encoder.encodeToBytes()` + `buildCompressedTexture()` for callers that want
|
|
170
229
|
* a ready-to-use Three.js texture from one call.
|
|
171
230
|
*/
|
|
172
|
-
declare function encodeToTexture(encoder: Encoder, source: EncoderImageSource, { colorSpace,
|
|
231
|
+
declare function encodeToTexture(encoder: Encoder, source: EncoderImageSource, { colorSpace, flipY }?: EncodeToTextureOptions): Promise<EncodeResult>;
|
|
173
232
|
|
|
174
|
-
export { type CompressOptions, type CompressResult, type CompressTextureSource,
|
|
233
|
+
export { type CompressOptions, type CompressResult, type CompressTextureSource, type EncodeResult, type EncodeToTextureOptions, Encoder, EncoderImageSource, FormatQuality, GputexLoader, PreferredFormat, SvgRasterSize, TextureFormat, TextureHint, buildCompressedTexture, clearTranscodeCache, compressTexture, encodeToTexture, releaseSharedGpuResources, setTranscodeCacheLimit, threeFormatFor };
|