akarisub 0.2.0 → 0.2.1
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 +3 -3
- package/dist/akarisub-worker.js +2 -2
- package/dist/akarisub-worker.wasm +0 -0
- package/dist/akarisub.umd.js +3 -3
- package/dist/index.js +3 -3
- package/dist/ts/index.d.ts +14 -0
- package/dist/ts/index.d.ts.map +1 -0
- package/dist/ts/index.js +17 -0
- package/dist/ts/index.js.map +1 -0
- package/dist/ts/ts/akarisub.d.ts +229 -0
- package/dist/ts/ts/akarisub.d.ts.map +1 -0
- package/dist/ts/ts/akarisub.js +1079 -0
- package/dist/ts/ts/akarisub.js.map +1 -0
- package/dist/ts/ts/types.d.ts +424 -0
- package/dist/ts/ts/types.d.ts.map +1 -0
- package/dist/ts/ts/types.js +5 -0
- package/dist/ts/ts/types.js.map +1 -0
- package/dist/ts/ts/utils.d.ts +78 -0
- package/dist/ts/ts/utils.d.ts.map +1 -0
- package/dist/ts/ts/utils.js +395 -0
- package/dist/ts/ts/utils.js.map +1 -0
- package/dist/ts/ts/webgl2-renderer.d.ts +51 -0
- package/dist/ts/ts/webgl2-renderer.d.ts.map +1 -0
- package/dist/ts/ts/webgl2-renderer.js +388 -0
- package/dist/ts/ts/webgl2-renderer.js.map +1 -0
- package/dist/ts/ts/webgpu-renderer.d.ts +64 -0
- package/dist/ts/ts/webgpu-renderer.d.ts.map +1 -0
- package/dist/ts/ts/webgpu-renderer.js +610 -0
- package/dist/ts/ts/webgpu-renderer.js.map +1 -0
- package/dist/ts/ts/worker.d.ts +6 -0
- package/dist/ts/ts/worker.d.ts.map +1 -0
- package/dist/ts/ts/worker.js +1695 -0
- package/dist/ts/ts/worker.js.map +1 -0
- package/dist/ts/wrapper.d.ts +8 -0
- package/dist/ts/wrapper.d.ts.map +1 -0
- package/dist/ts/wrapper.js +9 -0
- package/dist/ts/wrapper.js.map +1 -0
- package/package.json +7 -6
- package/src/ts/akarisub.ts +46 -4
- package/src/ts/types.ts +18 -4
- package/src/ts/worker.ts +177 -23
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
const MAX_IMAGES_PER_BATCH = 256;
|
|
2
|
+
const MAX_TEXTURE_ARRAY_LAYERS = 256;
|
|
3
|
+
// GLSL Vertex Shader (GLSL ES 3.00)
|
|
4
|
+
const VERTEX_SHADER = /* glsl */ `#version 300 es
|
|
5
|
+
precision highp float;
|
|
6
|
+
|
|
7
|
+
in vec4 a_destRect;
|
|
8
|
+
in vec4 a_texInfo;
|
|
9
|
+
|
|
10
|
+
uniform vec2 u_resolution;
|
|
11
|
+
|
|
12
|
+
out vec2 v_uv;
|
|
13
|
+
flat out int v_texIndex;
|
|
14
|
+
flat out vec2 v_texSize;
|
|
15
|
+
|
|
16
|
+
vec2 quadPos(int id) {
|
|
17
|
+
if (id == 0) return vec2(0.0, 0.0);
|
|
18
|
+
if (id == 1) return vec2(1.0, 0.0);
|
|
19
|
+
if (id == 2) return vec2(0.0, 1.0);
|
|
20
|
+
if (id == 3) return vec2(1.0, 0.0);
|
|
21
|
+
if (id == 4) return vec2(1.0, 1.0);
|
|
22
|
+
return vec2(0.0, 1.0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
void main() {
|
|
26
|
+
vec2 qp = quadPos(gl_VertexID);
|
|
27
|
+
vec2 pixelPos = a_destRect.xy + qp * a_destRect.zw;
|
|
28
|
+
|
|
29
|
+
// Convert CSS pixel coords (y=0 top) to GL clip space (y=1 top)
|
|
30
|
+
vec2 clip = (pixelPos / u_resolution) * 2.0 - 1.0;
|
|
31
|
+
clip.y = -clip.y;
|
|
32
|
+
|
|
33
|
+
gl_Position = vec4(clip, 0.0, 1.0);
|
|
34
|
+
v_uv = qp;
|
|
35
|
+
v_texIndex = int(a_texInfo.z);
|
|
36
|
+
v_texSize = a_texInfo.xy;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
// GLSL Fragment Shader (GLSL ES 3.00)
|
|
40
|
+
const FRAGMENT_SHADER = /* glsl */ `#version 300 es
|
|
41
|
+
precision highp float;
|
|
42
|
+
precision highp sampler2DArray;
|
|
43
|
+
|
|
44
|
+
uniform sampler2DArray u_texArray;
|
|
45
|
+
uniform ivec2 u_texArraySize;
|
|
46
|
+
|
|
47
|
+
in vec2 v_uv;
|
|
48
|
+
flat in int v_texIndex;
|
|
49
|
+
flat in vec2 v_texSize;
|
|
50
|
+
|
|
51
|
+
out vec4 fragColor;
|
|
52
|
+
|
|
53
|
+
void main() {
|
|
54
|
+
vec2 normalizedCoord = v_uv * v_texSize / vec2(u_texArraySize);
|
|
55
|
+
vec4 color = texture(u_texArray, vec3(normalizedCoord, float(v_texIndex)));
|
|
56
|
+
// Premultiplied alpha output (matches WebGPU renderer behaviour)
|
|
57
|
+
fragColor = vec4(color.rgb * color.a, color.a);
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
/**
|
|
61
|
+
* Check if WebGL2 is supported in the current browser.
|
|
62
|
+
*/
|
|
63
|
+
export function isWebGL2Supported() {
|
|
64
|
+
if (typeof document === 'undefined')
|
|
65
|
+
return false;
|
|
66
|
+
try {
|
|
67
|
+
const canvas = document.createElement('canvas');
|
|
68
|
+
return canvas.getContext('webgl2') !== null;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function isArrayBufferView(value) {
|
|
75
|
+
return value instanceof Uint8Array || value instanceof Uint8ClampedArray;
|
|
76
|
+
}
|
|
77
|
+
function compileShader(gl, type, source) {
|
|
78
|
+
const shader = gl.createShader(type);
|
|
79
|
+
gl.shaderSource(shader, source);
|
|
80
|
+
gl.compileShader(shader);
|
|
81
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
82
|
+
const info = gl.getShaderInfoLog(shader);
|
|
83
|
+
gl.deleteShader(shader);
|
|
84
|
+
throw new Error(`WebGL2 shader compilation failed: ${info}`);
|
|
85
|
+
}
|
|
86
|
+
return shader;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* High-performance WebGL2 subtitle renderer for AkariSub.
|
|
90
|
+
*/
|
|
91
|
+
export class WebGL2Renderer {
|
|
92
|
+
_gl = null;
|
|
93
|
+
_canvas = null;
|
|
94
|
+
_program = null;
|
|
95
|
+
_vao = null;
|
|
96
|
+
_instanceBuffer = null;
|
|
97
|
+
_texArray = null;
|
|
98
|
+
_texWidth = 0;
|
|
99
|
+
_texHeight = 0;
|
|
100
|
+
_texLayers = 0;
|
|
101
|
+
_resolutionLoc = null;
|
|
102
|
+
_texArraySizeLoc = null;
|
|
103
|
+
_instanceData;
|
|
104
|
+
_lastCanvasWidth = 0;
|
|
105
|
+
_lastCanvasHeight = 0;
|
|
106
|
+
_initialized = false;
|
|
107
|
+
_initPromise = null;
|
|
108
|
+
constructor() {
|
|
109
|
+
this._instanceData = new Float32Array(MAX_IMAGES_PER_BATCH * 8);
|
|
110
|
+
}
|
|
111
|
+
async init() {
|
|
112
|
+
if (this._initPromise)
|
|
113
|
+
return this._initPromise;
|
|
114
|
+
this._initPromise = this._checkSupport();
|
|
115
|
+
return this._initPromise;
|
|
116
|
+
}
|
|
117
|
+
async _checkSupport() {
|
|
118
|
+
if (typeof document === 'undefined')
|
|
119
|
+
throw new Error('WebGL2 requires a DOM environment');
|
|
120
|
+
const canvas = document.createElement('canvas');
|
|
121
|
+
if (!canvas.getContext('webgl2'))
|
|
122
|
+
throw new Error('WebGL2 not supported');
|
|
123
|
+
}
|
|
124
|
+
_initGL() {
|
|
125
|
+
if (!this._canvas)
|
|
126
|
+
throw new Error('Canvas not set before _initGL');
|
|
127
|
+
if (this._gl)
|
|
128
|
+
return; // already initialised
|
|
129
|
+
const gl = this._canvas.getContext('webgl2', { alpha: true, premultipliedAlpha: true, antialias: false });
|
|
130
|
+
if (!gl)
|
|
131
|
+
throw new Error('Failed to create WebGL2 context');
|
|
132
|
+
this._gl = gl;
|
|
133
|
+
// Compile and link program
|
|
134
|
+
const vert = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
|
|
135
|
+
const frag = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
|
|
136
|
+
const program = gl.createProgram();
|
|
137
|
+
gl.attachShader(program, vert);
|
|
138
|
+
gl.attachShader(program, frag);
|
|
139
|
+
gl.linkProgram(program);
|
|
140
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
141
|
+
throw new Error(`WebGL2 program link failed: ${gl.getProgramInfoLog(program)}`);
|
|
142
|
+
}
|
|
143
|
+
gl.deleteShader(vert);
|
|
144
|
+
gl.deleteShader(frag);
|
|
145
|
+
this._program = program;
|
|
146
|
+
this._resolutionLoc = gl.getUniformLocation(program, 'u_resolution');
|
|
147
|
+
this._texArraySizeLoc = gl.getUniformLocation(program, 'u_texArraySize');
|
|
148
|
+
// VAO + instance VBO
|
|
149
|
+
this._vao = gl.createVertexArray();
|
|
150
|
+
gl.bindVertexArray(this._vao);
|
|
151
|
+
this._instanceBuffer = gl.createBuffer();
|
|
152
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._instanceBuffer);
|
|
153
|
+
// Size: MAX_IMAGES * 8 floats * 4 bytes
|
|
154
|
+
gl.bufferData(gl.ARRAY_BUFFER, MAX_IMAGES_PER_BATCH * 32, gl.DYNAMIC_DRAW);
|
|
155
|
+
// stride = 32 bytes (8 × float)
|
|
156
|
+
const aDestRect = gl.getAttribLocation(program, 'a_destRect');
|
|
157
|
+
gl.enableVertexAttribArray(aDestRect);
|
|
158
|
+
gl.vertexAttribPointer(aDestRect, 4, gl.FLOAT, false, 32, 0);
|
|
159
|
+
gl.vertexAttribDivisor(aDestRect, 1);
|
|
160
|
+
const aTexInfo = gl.getAttribLocation(program, 'a_texInfo');
|
|
161
|
+
gl.enableVertexAttribArray(aTexInfo);
|
|
162
|
+
gl.vertexAttribPointer(aTexInfo, 4, gl.FLOAT, false, 32, 16);
|
|
163
|
+
gl.vertexAttribDivisor(aTexInfo, 1);
|
|
164
|
+
gl.bindVertexArray(null);
|
|
165
|
+
// Texture array
|
|
166
|
+
this._texArray = gl.createTexture();
|
|
167
|
+
this._allocateTextureArray(256, 256, 32);
|
|
168
|
+
// Premultiplied-alpha blending
|
|
169
|
+
gl.enable(gl.BLEND);
|
|
170
|
+
gl.blendEquation(gl.FUNC_ADD);
|
|
171
|
+
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
172
|
+
this._initialized = true;
|
|
173
|
+
}
|
|
174
|
+
// ==========================================================================
|
|
175
|
+
// Texture management
|
|
176
|
+
// ==========================================================================
|
|
177
|
+
_nextPow2(n) {
|
|
178
|
+
n--;
|
|
179
|
+
n |= n >> 1;
|
|
180
|
+
n |= n >> 2;
|
|
181
|
+
n |= n >> 4;
|
|
182
|
+
n |= n >> 8;
|
|
183
|
+
n |= n >> 16;
|
|
184
|
+
return n + 1;
|
|
185
|
+
}
|
|
186
|
+
_allocateTextureArray(width, height, layers) {
|
|
187
|
+
const gl = this._gl;
|
|
188
|
+
const w = this._nextPow2(Math.max(width, 64));
|
|
189
|
+
const h = this._nextPow2(Math.max(height, 64));
|
|
190
|
+
const l = Math.min(this._nextPow2(Math.max(layers, 16)), MAX_TEXTURE_ARRAY_LAYERS);
|
|
191
|
+
gl.bindTexture(gl.TEXTURE_2D_ARRAY, this._texArray);
|
|
192
|
+
gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.RGBA8, w, h, l, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
193
|
+
gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
194
|
+
gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
195
|
+
gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
196
|
+
gl.texParameteri(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
197
|
+
this._texWidth = w;
|
|
198
|
+
this._texHeight = h;
|
|
199
|
+
this._texLayers = l;
|
|
200
|
+
}
|
|
201
|
+
_ensureTextureArray(maxW, maxH, count) {
|
|
202
|
+
const c = Math.min(count, MAX_TEXTURE_ARRAY_LAYERS);
|
|
203
|
+
if (maxW <= this._texWidth && maxH <= this._texHeight && c <= this._texLayers)
|
|
204
|
+
return;
|
|
205
|
+
const newW = this._nextPow2(Math.max(this._texWidth, maxW));
|
|
206
|
+
const newH = this._nextPow2(Math.max(this._texHeight, maxH));
|
|
207
|
+
const newL = Math.min(this._nextPow2(Math.max(this._texLayers, c, c + 16)), MAX_TEXTURE_ARRAY_LAYERS);
|
|
208
|
+
this._allocateTextureArray(newW, newH, newL);
|
|
209
|
+
}
|
|
210
|
+
// ==========================================================================
|
|
211
|
+
// Public interface
|
|
212
|
+
// ==========================================================================
|
|
213
|
+
async setCanvas(canvas, width, height) {
|
|
214
|
+
await this.init();
|
|
215
|
+
if (width <= 0 || height <= 0)
|
|
216
|
+
return;
|
|
217
|
+
this._canvas = canvas;
|
|
218
|
+
canvas.width = width;
|
|
219
|
+
canvas.height = height;
|
|
220
|
+
this._initGL();
|
|
221
|
+
this._gl.viewport(0, 0, width, height);
|
|
222
|
+
this._lastCanvasWidth = width;
|
|
223
|
+
this._lastCanvasHeight = height;
|
|
224
|
+
}
|
|
225
|
+
updateSize(width, height) {
|
|
226
|
+
if (!this._gl || !this._canvas || width <= 0 || height <= 0)
|
|
227
|
+
return;
|
|
228
|
+
if (width === this._lastCanvasWidth && height === this._lastCanvasHeight)
|
|
229
|
+
return;
|
|
230
|
+
this._canvas.width = width;
|
|
231
|
+
this._canvas.height = height;
|
|
232
|
+
this._gl.viewport(0, 0, width, height);
|
|
233
|
+
this._lastCanvasWidth = width;
|
|
234
|
+
this._lastCanvasHeight = height;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Render from ImageBitmaps (async render mode)
|
|
238
|
+
*/
|
|
239
|
+
renderBitmaps(images, _canvasWidth, _canvasHeight) {
|
|
240
|
+
if (!this._gl || !this._initialized)
|
|
241
|
+
return;
|
|
242
|
+
const len = images.length;
|
|
243
|
+
if (len === 0) {
|
|
244
|
+
this.clear();
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
let maxW = 0, maxH = 0;
|
|
248
|
+
for (let i = 0; i < len; i++) {
|
|
249
|
+
const { image } = images[i];
|
|
250
|
+
if (image.width > maxW)
|
|
251
|
+
maxW = image.width;
|
|
252
|
+
if (image.height > maxH)
|
|
253
|
+
maxH = image.height;
|
|
254
|
+
}
|
|
255
|
+
this._ensureTextureArray(maxW, maxH, Math.min(len, MAX_TEXTURE_ARRAY_LAYERS));
|
|
256
|
+
const gl = this._gl;
|
|
257
|
+
gl.clearColor(0, 0, 0, 0);
|
|
258
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
259
|
+
gl.useProgram(this._program);
|
|
260
|
+
gl.uniform2f(this._resolutionLoc, this._lastCanvasWidth, this._lastCanvasHeight);
|
|
261
|
+
gl.uniform2i(this._texArraySizeLoc, this._texWidth, this._texHeight);
|
|
262
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
263
|
+
gl.bindTexture(gl.TEXTURE_2D_ARRAY, this._texArray);
|
|
264
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
265
|
+
const instanceData = this._instanceData;
|
|
266
|
+
let imageIndex = 0;
|
|
267
|
+
while (imageIndex < len) {
|
|
268
|
+
let count = 0;
|
|
269
|
+
while (imageIndex < len && count < MAX_TEXTURE_ARRAY_LAYERS) {
|
|
270
|
+
const img = images[imageIndex++];
|
|
271
|
+
const w = img.image.width, h = img.image.height;
|
|
272
|
+
if (w <= 0 || h <= 0)
|
|
273
|
+
continue;
|
|
274
|
+
gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, count, w, h, 1, gl.RGBA, gl.UNSIGNED_BYTE, img.image);
|
|
275
|
+
const off = count << 3;
|
|
276
|
+
instanceData[off] = img.x;
|
|
277
|
+
instanceData[off + 1] = img.y;
|
|
278
|
+
instanceData[off + 2] = w;
|
|
279
|
+
instanceData[off + 3] = h;
|
|
280
|
+
instanceData[off + 4] = w;
|
|
281
|
+
instanceData[off + 5] = h;
|
|
282
|
+
instanceData[off + 6] = count;
|
|
283
|
+
instanceData[off + 7] = 0;
|
|
284
|
+
count++;
|
|
285
|
+
}
|
|
286
|
+
if (count === 0)
|
|
287
|
+
continue;
|
|
288
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._instanceBuffer);
|
|
289
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, instanceData, 0, count << 3);
|
|
290
|
+
gl.bindVertexArray(this._vao);
|
|
291
|
+
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, count);
|
|
292
|
+
gl.bindVertexArray(null);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Render from raw ArrayBuffer data (non-async render mode)
|
|
297
|
+
*/
|
|
298
|
+
render(images, _canvasWidth, _canvasHeight) {
|
|
299
|
+
if (!this._gl || !this._initialized)
|
|
300
|
+
return;
|
|
301
|
+
const len = images.length;
|
|
302
|
+
if (len === 0) {
|
|
303
|
+
this.clear();
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
let maxW = 0, maxH = 0;
|
|
307
|
+
for (let i = 0; i < len; i++) {
|
|
308
|
+
const { w, h } = images[i];
|
|
309
|
+
if (w > maxW)
|
|
310
|
+
maxW = w;
|
|
311
|
+
if (h > maxH)
|
|
312
|
+
maxH = h;
|
|
313
|
+
}
|
|
314
|
+
this._ensureTextureArray(maxW, maxH, Math.min(len, MAX_TEXTURE_ARRAY_LAYERS));
|
|
315
|
+
const gl = this._gl;
|
|
316
|
+
gl.clearColor(0, 0, 0, 0);
|
|
317
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
318
|
+
gl.useProgram(this._program);
|
|
319
|
+
gl.uniform2f(this._resolutionLoc, this._lastCanvasWidth, this._lastCanvasHeight);
|
|
320
|
+
gl.uniform2i(this._texArraySizeLoc, this._texWidth, this._texHeight);
|
|
321
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
322
|
+
gl.bindTexture(gl.TEXTURE_2D_ARRAY, this._texArray);
|
|
323
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
324
|
+
const instanceData = this._instanceData;
|
|
325
|
+
let imageIndex = 0;
|
|
326
|
+
while (imageIndex < len) {
|
|
327
|
+
let count = 0;
|
|
328
|
+
while (imageIndex < len && count < MAX_TEXTURE_ARRAY_LAYERS) {
|
|
329
|
+
const img = images[imageIndex++];
|
|
330
|
+
const w = img.w, h = img.h;
|
|
331
|
+
if (w <= 0 || h <= 0)
|
|
332
|
+
continue;
|
|
333
|
+
const imgData = img.image;
|
|
334
|
+
if (imgData instanceof ImageBitmap) {
|
|
335
|
+
gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, count, w, h, 1, gl.RGBA, gl.UNSIGNED_BYTE, imgData);
|
|
336
|
+
}
|
|
337
|
+
else if (imgData instanceof ArrayBuffer || isArrayBufferView(imgData)) {
|
|
338
|
+
const uploadData = imgData instanceof ArrayBuffer ? new Uint8Array(imgData) : imgData;
|
|
339
|
+
gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, count, w, h, 1, gl.RGBA, gl.UNSIGNED_BYTE, uploadData);
|
|
340
|
+
}
|
|
341
|
+
const off = count << 3;
|
|
342
|
+
instanceData[off] = img.x;
|
|
343
|
+
instanceData[off + 1] = img.y;
|
|
344
|
+
instanceData[off + 2] = w;
|
|
345
|
+
instanceData[off + 3] = h;
|
|
346
|
+
instanceData[off + 4] = w;
|
|
347
|
+
instanceData[off + 5] = h;
|
|
348
|
+
instanceData[off + 6] = count;
|
|
349
|
+
instanceData[off + 7] = 0;
|
|
350
|
+
count++;
|
|
351
|
+
}
|
|
352
|
+
if (count === 0)
|
|
353
|
+
continue;
|
|
354
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._instanceBuffer);
|
|
355
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, instanceData, 0, count << 3);
|
|
356
|
+
gl.bindVertexArray(this._vao);
|
|
357
|
+
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, count);
|
|
358
|
+
gl.bindVertexArray(null);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
clear() {
|
|
362
|
+
if (!this._gl)
|
|
363
|
+
return;
|
|
364
|
+
this._gl.clearColor(0, 0, 0, 0);
|
|
365
|
+
this._gl.clear(this._gl.COLOR_BUFFER_BIT);
|
|
366
|
+
}
|
|
367
|
+
get initialized() {
|
|
368
|
+
return this._initialized;
|
|
369
|
+
}
|
|
370
|
+
destroy() {
|
|
371
|
+
const gl = this._gl;
|
|
372
|
+
if (gl) {
|
|
373
|
+
gl.deleteProgram(this._program);
|
|
374
|
+
gl.deleteVertexArray(this._vao);
|
|
375
|
+
gl.deleteBuffer(this._instanceBuffer);
|
|
376
|
+
gl.deleteTexture(this._texArray);
|
|
377
|
+
}
|
|
378
|
+
this._gl = null;
|
|
379
|
+
this._program = null;
|
|
380
|
+
this._vao = null;
|
|
381
|
+
this._instanceBuffer = null;
|
|
382
|
+
this._texArray = null;
|
|
383
|
+
this._canvas = null;
|
|
384
|
+
this._initialized = false;
|
|
385
|
+
this._initPromise = null;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=webgl2-renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webgl2-renderer.js","sourceRoot":"","sources":["../../../src/ts/webgl2-renderer.ts"],"names":[],"mappings":"AAEA,MAAM,oBAAoB,GAAG,GAAG,CAAA;AAChC,MAAM,wBAAwB,GAAG,GAAG,CAAA;AAEp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C/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;IAC3C,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAED,OAAO;QACL,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAA;QACnB,IAAI,EAAE,EAAE,CAAC;YACP,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YAC/B,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC/B,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;YACrC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAClC,CAAC;QACD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAA;QACf,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAA;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;QACzB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { RenderImage } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Check if WebGPU is supported in the current browser.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isWebGPUSupported(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* High-performance WebGPU subtitle renderer for AkariSub.
|
|
8
|
+
*/
|
|
9
|
+
export declare class WebGPURenderer {
|
|
10
|
+
private device;
|
|
11
|
+
private context;
|
|
12
|
+
private pipeline;
|
|
13
|
+
private bindGroupLayout;
|
|
14
|
+
private uniformBuffer;
|
|
15
|
+
private imageDataBuffer;
|
|
16
|
+
private textureArray;
|
|
17
|
+
private textureArrayView;
|
|
18
|
+
private textureArraySize;
|
|
19
|
+
private textureArrayWidth;
|
|
20
|
+
private textureArrayHeight;
|
|
21
|
+
private pendingDestroyTextures;
|
|
22
|
+
private readonly imageDataArray;
|
|
23
|
+
private readonly resolutionArray;
|
|
24
|
+
private conversionBuffer;
|
|
25
|
+
private conversionBufferSize;
|
|
26
|
+
private bindGroup;
|
|
27
|
+
private bindGroupDirty;
|
|
28
|
+
private lastCanvasWidth;
|
|
29
|
+
private lastCanvasHeight;
|
|
30
|
+
format: GPUTextureFormat;
|
|
31
|
+
private _canvas;
|
|
32
|
+
private _initPromise;
|
|
33
|
+
private _initialized;
|
|
34
|
+
constructor();
|
|
35
|
+
init(): Promise<void>;
|
|
36
|
+
private _initDevice;
|
|
37
|
+
private nextPowerOf2;
|
|
38
|
+
private createTextureArray;
|
|
39
|
+
private ensureTextureArray;
|
|
40
|
+
private updateBindGroup;
|
|
41
|
+
private ensureConversionBuffer;
|
|
42
|
+
setCanvas(canvas: HTMLCanvasElement, width: number, height: number): Promise<void>;
|
|
43
|
+
updateSize(width: number, height: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* Render ImageBitmaps (async render mode)
|
|
46
|
+
* Handles batching when image count exceeds MAX_TEXTURE_ARRAY_LAYERS
|
|
47
|
+
*/
|
|
48
|
+
renderBitmaps(images: {
|
|
49
|
+
image: ImageBitmap;
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
}[], _canvasWidth: number, _canvasHeight: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Render from raw ArrayBuffer data (non-async render mode)
|
|
55
|
+
* Handles batching when image count exceeds MAX_TEXTURE_ARRAY_LAYERS
|
|
56
|
+
*/
|
|
57
|
+
render(images: RenderImage[], _canvasWidth: number, _canvasHeight: number): void;
|
|
58
|
+
private uploadTextureData;
|
|
59
|
+
private cleanupPendingTextures;
|
|
60
|
+
clear(): void;
|
|
61
|
+
get initialized(): boolean;
|
|
62
|
+
destroy(): void;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=webgpu-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webgpu-renderer.d.ts","sourceRoot":"","sources":["../../../src/ts/webgpu-renderer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AA2G1C;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAUD;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,QAAQ,CAAiC;IACjD,OAAO,CAAC,eAAe,CAAkC;IAEzD,OAAO,CAAC,aAAa,CAAyB;IAC9C,OAAO,CAAC,eAAe,CAAyB;IAGhD,OAAO,CAAC,YAAY,CAA0B;IAC9C,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,gBAAgB,CAAI;IAC5B,OAAO,CAAC,iBAAiB,CAAI;IAC7B,OAAO,CAAC,kBAAkB,CAAI;IAE9B,OAAO,CAAC,sBAAsB,CAAmB;IAGjD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAc;IAC7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAsB;IAGtD,OAAO,CAAC,gBAAgB,CAA0B;IAClD,OAAO,CAAC,oBAAoB,CAAI;IAGhC,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,cAAc,CAAO;IAG7B,OAAO,CAAC,eAAe,CAAI;IAC3B,OAAO,CAAC,gBAAgB,CAAI;IAE5B,MAAM,EAAE,gBAAgB,CAAe;IAEvC,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,YAAY,CAAQ;IAE5B,cAGC;IAEK,IAAI,IAAI,OAAO,CAAC,IA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