@swf2es/context3d 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +219 -2
- package/dist/agal.d.ts +23 -0
- package/dist/agal.d.ts.map +1 -0
- package/dist/agal.js +410 -0
- package/dist/agal.js.map +1 -0
- package/dist/backend.d.ts +122 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +63 -0
- package/dist/backend.js.map +1 -0
- package/dist/device/index.d.ts +3 -0
- package/dist/device/index.d.ts.map +1 -0
- package/dist/device/index.js +6 -0
- package/dist/device/index.js.map +1 -0
- package/dist/device/programs.d.ts +13 -0
- package/dist/device/programs.d.ts.map +1 -0
- package/dist/device/programs.js +59 -0
- package/dist/device/programs.js.map +1 -0
- package/dist/device/state.d.ts +53 -0
- package/dist/device/state.d.ts.map +1 -0
- package/dist/device/state.js +196 -0
- package/dist/device/state.js.map +1 -0
- package/dist/dxt.d.ts +22 -0
- package/dist/dxt.d.ts.map +1 -0
- package/dist/dxt.js +304 -0
- package/dist/dxt.js.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +8 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/webgl/buffers.d.ts +27 -0
- package/dist/webgl/buffers.d.ts.map +1 -0
- package/dist/webgl/buffers.js +53 -0
- package/dist/webgl/buffers.js.map +1 -0
- package/dist/webgl/context.d.ts +123 -0
- package/dist/webgl/context.d.ts.map +1 -0
- package/dist/webgl/context.js +1368 -0
- package/dist/webgl/context.js.map +1 -0
- package/dist/webgl/index.d.ts +3 -0
- package/dist/webgl/index.d.ts.map +1 -0
- package/dist/webgl/index.js +2 -0
- package/dist/webgl/index.js.map +1 -0
- package/dist/webgl/limits.d.ts +23 -0
- package/dist/webgl/limits.d.ts.map +1 -0
- package/dist/webgl/limits.js +35 -0
- package/dist/webgl/limits.js.map +1 -0
- package/dist/webgl/programs.d.ts +22 -0
- package/dist/webgl/programs.d.ts.map +1 -0
- package/dist/webgl/programs.js +110 -0
- package/dist/webgl/programs.js.map +1 -0
- package/dist/webgl/state.d.ts +42 -0
- package/dist/webgl/state.d.ts.map +1 -0
- package/dist/webgl/state.js +55 -0
- package/dist/webgl/state.js.map +1 -0
- package/dist/webgl/targets.d.ts +20 -0
- package/dist/webgl/targets.d.ts.map +1 -0
- package/dist/webgl/targets.js +138 -0
- package/dist/webgl/targets.js.map +1 -0
- package/dist/webgl/textures.d.ts +28 -0
- package/dist/webgl/textures.d.ts.map +1 -0
- package/dist/webgl/textures.js +119 -0
- package/dist/webgl/textures.js.map +1 -0
- package/dist/webgl/validation.d.ts +4 -0
- package/dist/webgl/validation.d.ts.map +1 -0
- package/dist/webgl/validation.js +52 -0
- package/dist/webgl/validation.js.map +1 -0
- package/package.json +37 -3
- package/src/agal.ts +496 -0
- package/src/backend.ts +210 -0
- package/src/device/index.ts +5 -0
- package/src/device/programs.ts +66 -0
- package/src/device/state.ts +214 -0
- package/src/dxt.ts +349 -0
- package/src/errors.ts +68 -0
- package/src/index.ts +35 -0
- package/src/webgl/buffers.ts +102 -0
- package/src/webgl/context.ts +1803 -0
- package/src/webgl/index.ts +2 -0
- package/src/webgl/limits.ts +61 -0
- package/src/webgl/programs.ts +145 -0
- package/src/webgl/state.ts +65 -0
- package/src/webgl/targets.ts +229 -0
- package/src/webgl/textures.ts +200 -0
- package/src/webgl/validation.ts +72 -0
package/dist/agal.js
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
// Deliberately small AGAL v1 slice for the opt-in Context3D probe.
|
|
2
|
+
// Format: https://github.com/adobe/glsl2agal/blob/master/agalassembler/agal.h
|
|
3
|
+
import { SamplerBiasError } from "./backend.js";
|
|
4
|
+
import { Context3DError } from "./errors.js";
|
|
5
|
+
const SUPPORTED = new Set([
|
|
6
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
|
|
7
|
+
0x15, 0x16, 0x17, 0x18, 0x19, 0x27, 0x28, 0x29, 0x2a, 0x2c,
|
|
8
|
+
]);
|
|
9
|
+
const UNARY = new Set([0, 5, 8, 9, 0x0a, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x14, 0x15, 0x16, 0x27]);
|
|
10
|
+
export function translate(bytes, stage) {
|
|
11
|
+
const data = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
12
|
+
if (bytes.length < 31 || (bytes.length - 7) % 24 !== 0) {
|
|
13
|
+
throw new Context3DError("agalLength", "Invalid AGAL program length");
|
|
14
|
+
}
|
|
15
|
+
if ((bytes.length - 7) / 24 > 200) {
|
|
16
|
+
throw new Context3DError("agalTokens", "Too many AGAL instructions");
|
|
17
|
+
}
|
|
18
|
+
if (bytes[0] !== 0xa0) {
|
|
19
|
+
throw new Context3DError("agalMagic", "Invalid AGAL magic byte");
|
|
20
|
+
}
|
|
21
|
+
if (data.getUint32(1, true) !== 1) {
|
|
22
|
+
throw new Context3DError("agalVersion", "Context3D experiment requires an AGAL v1 program");
|
|
23
|
+
}
|
|
24
|
+
if (bytes[5] !== 0xa1) {
|
|
25
|
+
throw new Context3DError("agalStageMarker", "Invalid AGAL stage marker");
|
|
26
|
+
}
|
|
27
|
+
if (bytes[6] > 1) {
|
|
28
|
+
throw new Context3DError("agalStage", "Invalid AGAL shader type");
|
|
29
|
+
}
|
|
30
|
+
if (bytes[6] !== (stage === "vertex" ? 0 : 1)) {
|
|
31
|
+
throw new Context3DError(stage === "vertex" ? "agalVertexStage" : "agalFragmentStage", "Invalid AGAL shader type");
|
|
32
|
+
}
|
|
33
|
+
// Direct-only shaders keep their sparse uniform uploads. An indirect shader
|
|
34
|
+
// shares one bank for direct and indexed reads, without duplicate uniforms.
|
|
35
|
+
let indirect = false;
|
|
36
|
+
for (let offset = 7; offset < bytes.length; offset += 24) {
|
|
37
|
+
const opcode = data.getUint32(offset, true);
|
|
38
|
+
if (data.getUint32(offset + 12, true) >>> 31 ||
|
|
39
|
+
(!UNARY.has(opcode) && opcode !== 0x28 && data.getUint32(offset + 20, true) >>> 31)) {
|
|
40
|
+
indirect = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const names = new Map();
|
|
44
|
+
const attributes = new Set();
|
|
45
|
+
const constants = new Set();
|
|
46
|
+
const samplers = new Map();
|
|
47
|
+
const lines = [];
|
|
48
|
+
const components = "xyzw";
|
|
49
|
+
let output = 0;
|
|
50
|
+
const temporaries = new Uint8Array(8);
|
|
51
|
+
const varyings = new Uint8Array(8);
|
|
52
|
+
const readTemporary = (index, mask) => {
|
|
53
|
+
if (!temporaries[index]) {
|
|
54
|
+
throw new Context3DError("agalTemporaryRead", "AGAL temporary read before writing");
|
|
55
|
+
}
|
|
56
|
+
if ((temporaries[index] & mask) !== mask) {
|
|
57
|
+
throw new Context3DError("agalTemporaryComponent", "AGAL temporary component read before writing");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const register = (type, index, write) => {
|
|
61
|
+
let name;
|
|
62
|
+
let declaration;
|
|
63
|
+
switch (type) {
|
|
64
|
+
case 0:
|
|
65
|
+
if (write || stage !== "vertex" || index >= 8) {
|
|
66
|
+
const reason = write
|
|
67
|
+
? "agalAttributeWrite"
|
|
68
|
+
: stage !== "vertex"
|
|
69
|
+
? "agalAttributeStage"
|
|
70
|
+
: "agalAttributeIndex";
|
|
71
|
+
throw new Context3DError(reason, "Invalid AGAL attribute");
|
|
72
|
+
}
|
|
73
|
+
name = `va${index}`;
|
|
74
|
+
declaration = `layout(location = ${index}) in vec4 ${name};`;
|
|
75
|
+
attributes.add(index);
|
|
76
|
+
break;
|
|
77
|
+
case 1:
|
|
78
|
+
if (write || index >= (stage === "vertex" ? 128 : 28)) {
|
|
79
|
+
throw new Context3DError(write ? "agalConstantWrite" : "agalConstantIndex", "Invalid AGAL constant");
|
|
80
|
+
}
|
|
81
|
+
if (indirect && stage === "vertex") {
|
|
82
|
+
names.set("vc", "uniform vec4 vc[128];");
|
|
83
|
+
return `vc[${index}]`;
|
|
84
|
+
}
|
|
85
|
+
name = `${stage === "vertex" ? "vc" : "fc"}${index}`;
|
|
86
|
+
declaration = `uniform vec4 ${name};`;
|
|
87
|
+
constants.add(index);
|
|
88
|
+
break;
|
|
89
|
+
case 2:
|
|
90
|
+
if (index >= 8) {
|
|
91
|
+
throw new Context3DError("agalTemporaryIndex", "Invalid AGAL temporary");
|
|
92
|
+
}
|
|
93
|
+
name = `t${index}`;
|
|
94
|
+
declaration = `vec4 ${name};`;
|
|
95
|
+
break;
|
|
96
|
+
case 3:
|
|
97
|
+
if (!write || index !== 0) {
|
|
98
|
+
throw new Context3DError(write ? "agalOutputIndex" : "agalOutputRead", "Invalid AGAL output");
|
|
99
|
+
}
|
|
100
|
+
return "result";
|
|
101
|
+
case 4:
|
|
102
|
+
if (index >= 8 || write !== (stage === "vertex")) {
|
|
103
|
+
throw new Context3DError(index >= 8 ? "agalVaryingIndex" : write ? "agalVaryingWrite" : "agalVaryingRead", "Invalid AGAL varying");
|
|
104
|
+
}
|
|
105
|
+
name = `v${index}`;
|
|
106
|
+
declaration = `${stage === "vertex" ? "out" : "in"} vec4 ${name};`;
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
throw new Context3DError("agalRegister", "Unsupported AGAL register");
|
|
110
|
+
}
|
|
111
|
+
names.set(name, declaration);
|
|
112
|
+
return name;
|
|
113
|
+
};
|
|
114
|
+
const source = (offset, row = 0) => {
|
|
115
|
+
const low = data.getUint32(offset, true);
|
|
116
|
+
const high = data.getUint32(offset + 4, true);
|
|
117
|
+
let name;
|
|
118
|
+
if (high >>> 31) {
|
|
119
|
+
const type = (high >>> 8) & 255;
|
|
120
|
+
const component = (high >>> 16) & 255;
|
|
121
|
+
const add = (low >>> 16) & 255;
|
|
122
|
+
if (stage !== "vertex" ||
|
|
123
|
+
high >>> 24 !== 128 ||
|
|
124
|
+
(high & 255) !== 1 ||
|
|
125
|
+
type > 2 ||
|
|
126
|
+
component > 3 ||
|
|
127
|
+
add >= 128) {
|
|
128
|
+
throw new Context3DError("agalIndirect", "Unsupported AGAL indirect constant");
|
|
129
|
+
}
|
|
130
|
+
const index = register(type, low & 65535, false);
|
|
131
|
+
if (type === 2) {
|
|
132
|
+
readTemporary(low & 65535, 1 << component);
|
|
133
|
+
}
|
|
134
|
+
names.set("vc", "uniform vec4 vc[128];");
|
|
135
|
+
name = `readConstant(${index}.${components[component]}, ${add + row}.0)`;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (high >>> 8 || ((low >>> 16) & 255) !== 0) {
|
|
139
|
+
throw new Context3DError("agalSourceEncoding", "Unsupported AGAL source encoding");
|
|
140
|
+
}
|
|
141
|
+
name = register(high & 255, (low & 65535) + row, false);
|
|
142
|
+
}
|
|
143
|
+
const swizzle = low >>> 24;
|
|
144
|
+
let lanes = "";
|
|
145
|
+
let readMask = 0;
|
|
146
|
+
for (let c = 0; c < 4; c++) {
|
|
147
|
+
const lane = (swizzle >>> (c * 2)) & 3;
|
|
148
|
+
lanes += components[lane];
|
|
149
|
+
readMask |= 1 << lane;
|
|
150
|
+
}
|
|
151
|
+
if (!(high >>> 31)) {
|
|
152
|
+
const type = high & 255;
|
|
153
|
+
const index = (low & 65535) + row;
|
|
154
|
+
if (type === 2) {
|
|
155
|
+
readTemporary(index, readMask);
|
|
156
|
+
}
|
|
157
|
+
else if (type === 4) {
|
|
158
|
+
varyings[index] |= readMask;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return `${name}.${lanes}`;
|
|
162
|
+
};
|
|
163
|
+
for (let offset = 7; offset < bytes.length; offset += 24) {
|
|
164
|
+
const opcode = data.getUint32(offset, true);
|
|
165
|
+
// Unsupported instructions may have no destination or a sampler operand;
|
|
166
|
+
// do not misreport those layouts as malformed arithmetic registers.
|
|
167
|
+
if (!SUPPORTED.has(opcode)) {
|
|
168
|
+
throw new Context3DError("agalOpcode", "Unsupported AGAL opcode");
|
|
169
|
+
}
|
|
170
|
+
const dest = data.getUint32(offset + 4, true);
|
|
171
|
+
const unary = UNARY.has(opcode);
|
|
172
|
+
if (unary && (data.getUint32(offset + 16, true) || data.getUint32(offset + 20, true))) {
|
|
173
|
+
throw new Context3DError("agalUnusedSource", "Nonempty unused AGAL source");
|
|
174
|
+
}
|
|
175
|
+
if (opcode === 0x27) {
|
|
176
|
+
const operand = data.getUint32(offset + 8, true);
|
|
177
|
+
const type = data.getUint32(offset + 12, true);
|
|
178
|
+
const swizzle = operand >>> 24;
|
|
179
|
+
if (stage !== "fragment" ||
|
|
180
|
+
dest !== 0 ||
|
|
181
|
+
(type !== 2 && type !== 4) ||
|
|
182
|
+
swizzle !== (swizzle & 3) * 0x55) {
|
|
183
|
+
throw new Context3DError("agalDiscard", "Invalid AGAL discard");
|
|
184
|
+
}
|
|
185
|
+
lines.push(`if (${source(offset + 8)}.x < 0.0) { discard; }`);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const mask = (dest >>> 16) & 255;
|
|
189
|
+
if (mask === 0 || mask > 15) {
|
|
190
|
+
throw new Context3DError("agalMask", "Invalid AGAL write mask");
|
|
191
|
+
}
|
|
192
|
+
const targetType = dest >>> 24;
|
|
193
|
+
const targetIndex = dest & 65535;
|
|
194
|
+
const target = register(targetType, targetIndex, true);
|
|
195
|
+
if (stage === "fragment" && targetType === 3 && mask !== 15) {
|
|
196
|
+
throw new Context3DError("agalColorMask", "AGAL color output must write all components");
|
|
197
|
+
}
|
|
198
|
+
const a = source(offset + 8);
|
|
199
|
+
const b = unary || opcode === 0x28 ? "" : source(offset + 16);
|
|
200
|
+
// AIR differs for overlaps that shuffle written lanes. Replicating the
|
|
201
|
+
// destination lane for a scalar write is safe; unused lanes do not matter.
|
|
202
|
+
if (opcode === 5 || opcode === 9 || opcode === 0x0b || opcode === 0x0c || opcode === 0x0d) {
|
|
203
|
+
for (let operand = offset + 8; operand <= offset + (unary ? 8 : 16); operand += 8) {
|
|
204
|
+
const low = data.getUint32(operand, true);
|
|
205
|
+
if (data.getUint32(operand + 4, true) === dest >>> 24 && (low & 65535) === (dest & 65535)) {
|
|
206
|
+
for (let lane = 0; lane < 4; lane++) {
|
|
207
|
+
if (mask & (1 << lane) && ((low >>> (24 + lane * 2)) & 3) !== lane) {
|
|
208
|
+
throw new Context3DError("unsupported", "Unsupported AGAL swizzled scalar-math overlap");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
let expression;
|
|
215
|
+
switch (opcode) {
|
|
216
|
+
case 0:
|
|
217
|
+
expression = a;
|
|
218
|
+
break;
|
|
219
|
+
case 1:
|
|
220
|
+
expression = `(${a} + ${b})`;
|
|
221
|
+
break;
|
|
222
|
+
case 2:
|
|
223
|
+
expression = `(${a} - ${b})`;
|
|
224
|
+
break;
|
|
225
|
+
case 3:
|
|
226
|
+
expression = `(${a} * ${b})`;
|
|
227
|
+
break;
|
|
228
|
+
case 4:
|
|
229
|
+
expression = `(${a} / ${b})`;
|
|
230
|
+
break;
|
|
231
|
+
case 5:
|
|
232
|
+
expression = `(vec4(1.0) / ${a})`;
|
|
233
|
+
break;
|
|
234
|
+
case 6:
|
|
235
|
+
expression = `min(${a}, ${b})`;
|
|
236
|
+
break;
|
|
237
|
+
case 7:
|
|
238
|
+
expression = `max(${a}, ${b})`;
|
|
239
|
+
break;
|
|
240
|
+
case 8:
|
|
241
|
+
expression = `fract(${a})`;
|
|
242
|
+
break;
|
|
243
|
+
case 9:
|
|
244
|
+
expression = `sqrt(${a})`;
|
|
245
|
+
break;
|
|
246
|
+
case 0x0a:
|
|
247
|
+
expression = `inversesqrt(${a})`;
|
|
248
|
+
break;
|
|
249
|
+
case 0x0b:
|
|
250
|
+
// As Direct3D's pow, which AIR draws with: |a|^b. GLSL leaves a
|
|
251
|
+
// negative base undefined, where GPUs give NaN, which draws black.
|
|
252
|
+
expression = `pow(abs(${a}), ${b})`;
|
|
253
|
+
break;
|
|
254
|
+
case 0x0c:
|
|
255
|
+
expression = `log2(${a})`;
|
|
256
|
+
break;
|
|
257
|
+
case 0x0d:
|
|
258
|
+
expression = `exp2(${a})`;
|
|
259
|
+
break;
|
|
260
|
+
case 0x0f:
|
|
261
|
+
expression = `sin(${a})`;
|
|
262
|
+
break;
|
|
263
|
+
case 0x10:
|
|
264
|
+
expression = `cos(${a})`;
|
|
265
|
+
break;
|
|
266
|
+
case 0x0e:
|
|
267
|
+
case 0x11:
|
|
268
|
+
if (mask !== 7) {
|
|
269
|
+
throw new Context3DError("unsupported", "Unsupported AGAL vector write mask");
|
|
270
|
+
}
|
|
271
|
+
expression = opcode === 0x0e ? `normalize(${a}.xyz)` : `cross(${a}.xyz, ${b}.xyz)`;
|
|
272
|
+
break;
|
|
273
|
+
case 0x12:
|
|
274
|
+
expression = `vec4(dot(${a}.xyz, ${b}.xyz))`;
|
|
275
|
+
break;
|
|
276
|
+
case 0x13:
|
|
277
|
+
expression = `vec4(dot(${a}, ${b}))`;
|
|
278
|
+
break;
|
|
279
|
+
case 0x14:
|
|
280
|
+
expression = `abs(${a})`;
|
|
281
|
+
break;
|
|
282
|
+
case 0x15:
|
|
283
|
+
expression = `(-${a})`;
|
|
284
|
+
break;
|
|
285
|
+
case 0x16:
|
|
286
|
+
expression = `clamp(${a}, 0.0, 1.0)`;
|
|
287
|
+
break;
|
|
288
|
+
case 0x17:
|
|
289
|
+
case 0x18:
|
|
290
|
+
case 0x19: {
|
|
291
|
+
const rows = opcode === 0x18 ? 4 : 3;
|
|
292
|
+
const dimensions = opcode === 0x17 ? ".xyz" : "";
|
|
293
|
+
const matrixHigh = data.getUint32(offset + 20, true);
|
|
294
|
+
const matrixType = matrixHigh & 255;
|
|
295
|
+
if ((rows === 3 && (mask & 8 || ((matrixType === 2 || matrixHigh >>> 31) && mask !== 7))) ||
|
|
296
|
+
(matrixType !== 1 && matrixType !== 2) ||
|
|
297
|
+
data.getUint32(offset + 16, true) >>> 24 !== 0xe4) {
|
|
298
|
+
throw new Context3DError("unsupported", "Unsupported AGAL matrix operand or write mask");
|
|
299
|
+
}
|
|
300
|
+
const dots = [];
|
|
301
|
+
for (let row = 0; row < rows; row++) {
|
|
302
|
+
dots.push(`dot(${a}${dimensions}, ${source(offset + 16, row)}${dimensions})`);
|
|
303
|
+
}
|
|
304
|
+
expression = `vec${rows}(${dots.join(", ")})`;
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
case 0x28: {
|
|
308
|
+
const low = data.getUint32(offset + 16, true);
|
|
309
|
+
const high = data.getUint32(offset + 20, true);
|
|
310
|
+
const index = low & 65535;
|
|
311
|
+
const bias = data.getInt8(offset + 18) / 8;
|
|
312
|
+
const format = (high >>> 8) & 15;
|
|
313
|
+
const mip = (high >>> 24) & 15;
|
|
314
|
+
const filter = high >>> 28;
|
|
315
|
+
if (stage !== "fragment" ||
|
|
316
|
+
index >= 8 ||
|
|
317
|
+
low >>> 24 !== 0 ||
|
|
318
|
+
(high & ~0x73141f00) !== 5 ||
|
|
319
|
+
format > 2 ||
|
|
320
|
+
filter > 5 ||
|
|
321
|
+
mip > 2) {
|
|
322
|
+
throw new Context3DError("agalSampler", "Unsupported AGAL sampler encoding");
|
|
323
|
+
}
|
|
324
|
+
const cube = (high & 0x1000) !== 0;
|
|
325
|
+
const repeat = (high & 0x00100000) !== 0;
|
|
326
|
+
const ignore = (high & 0x00040000) !== 0;
|
|
327
|
+
const previous = samplers.get(index);
|
|
328
|
+
if (previous && previous.bias !== bias) {
|
|
329
|
+
throw new SamplerBiasError("Conflicting AGAL sampler biases");
|
|
330
|
+
}
|
|
331
|
+
if (previous &&
|
|
332
|
+
(previous.format !== format ||
|
|
333
|
+
previous.filter !== filter ||
|
|
334
|
+
previous.repeat !== repeat ||
|
|
335
|
+
previous.mip !== mip ||
|
|
336
|
+
previous.cube !== cube ||
|
|
337
|
+
previous.ignore !== ignore)) {
|
|
338
|
+
throw new Context3DError("agalSampler", "Conflicting AGAL sampler states");
|
|
339
|
+
}
|
|
340
|
+
samplers.set(index, { index, format, filter, repeat, mip, cube, ignore, bias });
|
|
341
|
+
names.set(`fs${index}`, `uniform ${cube ? "samplerCube" : "sampler2D"} fs${index};`);
|
|
342
|
+
// Bias stays in the shader even when ignoresampler preserves runtime state.
|
|
343
|
+
expression = `texture(fs${index}, ${a}.${cube ? "xyz" : "xy"}${bias === 0 ? "" : `, ${bias.toFixed(3)}`})`;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case 0x29:
|
|
347
|
+
expression = `vec4(greaterThanEqual(${a}, ${b}))`;
|
|
348
|
+
break;
|
|
349
|
+
case 0x2a:
|
|
350
|
+
expression = `vec4(lessThan(${a}, ${b}))`;
|
|
351
|
+
break;
|
|
352
|
+
case 0x2c:
|
|
353
|
+
expression = `vec4(equal(${a}, ${b}))`;
|
|
354
|
+
break;
|
|
355
|
+
default:
|
|
356
|
+
throw new Context3DError("agalOpcode", "Unsupported AGAL opcode");
|
|
357
|
+
}
|
|
358
|
+
let lanes = "";
|
|
359
|
+
for (let c = 0; c < 4; c++) {
|
|
360
|
+
if (mask & (1 << c)) {
|
|
361
|
+
lanes += components[c];
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// One vector assignment evaluates every source before changing any lane,
|
|
365
|
+
// including overlapping temporary registers in matrix operations.
|
|
366
|
+
lines.push(`${target}.${lanes} = ${expression}.${lanes};`);
|
|
367
|
+
switch (targetType) {
|
|
368
|
+
case 2:
|
|
369
|
+
temporaries[targetIndex] |= mask;
|
|
370
|
+
break;
|
|
371
|
+
case 3:
|
|
372
|
+
output |= mask;
|
|
373
|
+
break;
|
|
374
|
+
case 4:
|
|
375
|
+
varyings[targetIndex] |= mask;
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (output !== 15) {
|
|
380
|
+
throw new Context3DError(stage === "vertex" ? "agalVertexOutput" : "agalFragmentOutput", "AGAL program does not write its complete output");
|
|
381
|
+
}
|
|
382
|
+
const declarations = [...names.values()].join("\n");
|
|
383
|
+
const finish = stage === "vertex"
|
|
384
|
+
? "gl_Position = vec4(result.x, result.y * targetY, result.z * 2.0 - result.w, result.w);"
|
|
385
|
+
: "color = result;";
|
|
386
|
+
return {
|
|
387
|
+
source: `#version 300 es
|
|
388
|
+
precision highp float;
|
|
389
|
+
${declarations}
|
|
390
|
+
${indirect
|
|
391
|
+
? `vec4 readConstant(float address, float offset) {
|
|
392
|
+
float index = roundEven(address) + offset;
|
|
393
|
+
if (!(index >= 0.0 && index < 128.0)) { return vec4(0.0); }
|
|
394
|
+
return vc[int(index)];
|
|
395
|
+
}`
|
|
396
|
+
: ""}
|
|
397
|
+
${stage === "fragment" ? "out vec4 color;" : "uniform float targetY;"}
|
|
398
|
+
void main() {
|
|
399
|
+
vec4 result = vec4(0.0);
|
|
400
|
+
${lines.join("\n ")}
|
|
401
|
+
${finish}
|
|
402
|
+
}`,
|
|
403
|
+
varyings,
|
|
404
|
+
attributes: [...attributes],
|
|
405
|
+
constants: [...constants],
|
|
406
|
+
indirect,
|
|
407
|
+
samplers: [...samplers.values()],
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
//# sourceMappingURL=agal.js.map
|
package/dist/agal.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agal.js","sourceRoot":"","sources":["../src/agal.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,8EAA8E;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA0B7C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,C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,UAAU,EAAE,CAAC,GAAG,UAAU,CAAC;QAC3B,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC;QACzB,QAAQ;QACR,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { ProgramType } from "./agal.js";
|
|
2
|
+
import type { DxtEncoder } from "./dxt.js";
|
|
3
|
+
export declare const COMPARE_MODES: readonly ["always", "never", "less", "lessEqual", "equal", "notEqual", "greaterEqual", "greater"];
|
|
4
|
+
export type CompareMode = (typeof COMPARE_MODES)[number];
|
|
5
|
+
export declare const CULL_FACES: readonly ["none", "back", "front", "frontAndBack"];
|
|
6
|
+
export type CullFace = (typeof CULL_FACES)[number];
|
|
7
|
+
export declare const STENCIL_ACTIONS: readonly ["keep", "zero", "set", "incrementSaturate", "decrementSaturate", "invert", "incrementWrap", "decrementWrap"];
|
|
8
|
+
export type StencilAction = (typeof STENCIL_ACTIONS)[number];
|
|
9
|
+
export declare const BLEND_FACTORS: readonly ["zero", "one", "sourceColor", "oneMinusSourceColor", "sourceAlpha", "oneMinusSourceAlpha", "destinationColor", "oneMinusDestinationColor", "destinationAlpha", "oneMinusDestinationAlpha"];
|
|
10
|
+
export type BlendFactor = (typeof BLEND_FACTORS)[number];
|
|
11
|
+
export declare const SAMPLER_WRAPS: readonly ["clamp", "repeat_u_clamp_v", "clamp_u_repeat_v", "repeat"];
|
|
12
|
+
export type SamplerWrap = (typeof SAMPLER_WRAPS)[number];
|
|
13
|
+
export declare const SAMPLER_FILTERS: readonly ["nearest", "linear", "anisotropic2x", "anisotropic4x", "anisotropic8x", "anisotropic16x"];
|
|
14
|
+
export type SamplerFilter = (typeof SAMPLER_FILTERS)[number];
|
|
15
|
+
export declare const SAMPLER_MIPS: readonly ["mipnone", "mipnearest", "miplinear"];
|
|
16
|
+
export type SamplerMip = (typeof SAMPLER_MIPS)[number];
|
|
17
|
+
/** The texture formats a backend stores: BGRA, and S3TC's DXT1 and DXT5 as Flash calls them. */
|
|
18
|
+
export declare const TEXTURE_FORMATS: readonly ["bgra", "compressed", "compressedAlpha"];
|
|
19
|
+
export type TextureFormat = (typeof TEXTURE_FORMATS)[number];
|
|
20
|
+
export declare const VERTEX_FORMATS: readonly ["float1", "float2", "float3", "float4", "bytes4"];
|
|
21
|
+
export type VertexFormat = (typeof VERTEX_FORMATS)[number];
|
|
22
|
+
export declare class VertexOffsetError extends Error {
|
|
23
|
+
}
|
|
24
|
+
export declare class ScissorBoundsError extends Error {
|
|
25
|
+
}
|
|
26
|
+
export declare class SamplerBiasError extends Error {
|
|
27
|
+
}
|
|
28
|
+
export declare class TextureBindingError extends Error {
|
|
29
|
+
readonly reason: "unused" | "conflicting" | "missing" | "unuploaded" | "mipmaps" | "dimension" | "wrap" | "rectangleMip" | "feedback" | "format";
|
|
30
|
+
/** The sampler it names, where it names one. */
|
|
31
|
+
readonly sampler: number;
|
|
32
|
+
constructor(reason: TextureBindingError["reason"], sampler?: number);
|
|
33
|
+
}
|
|
34
|
+
export interface Buffer3D {
|
|
35
|
+
readonly count: number;
|
|
36
|
+
readonly stride: number;
|
|
37
|
+
upload(values: ArrayLike<number>, start: number, count: number): void;
|
|
38
|
+
/** Raw little-endian bytes, copied before returning; offset is relative to data. */
|
|
39
|
+
uploadBytes(data: Uint8Array, offset: number, start: number, count: number): void;
|
|
40
|
+
dispose(): void;
|
|
41
|
+
}
|
|
42
|
+
export interface Program3D {
|
|
43
|
+
upload(vertex: Uint8Array, fragment: Uint8Array): void;
|
|
44
|
+
dispose(): void;
|
|
45
|
+
}
|
|
46
|
+
export interface Texture3D {
|
|
47
|
+
readonly width: number;
|
|
48
|
+
readonly height: number;
|
|
49
|
+
readonly levels: number;
|
|
50
|
+
readonly cube: boolean;
|
|
51
|
+
readonly rectangle: boolean;
|
|
52
|
+
/** What samplers must read it as; a compressed texture also takes pixels, as AIR's do. */
|
|
53
|
+
readonly format: TextureFormat;
|
|
54
|
+
/** Top-down premultiplied ARGB pixels, copied before returning.
|
|
55
|
+
* All texture kinds clip/pad source dimensions against the selected face/mip. */
|
|
56
|
+
upload(pixels: Uint32Array, level?: number, face?: number, sourceWidth?: number, sourceHeight?: number): void;
|
|
57
|
+
/** Top-down BGRA bytes, copied verbatim without alpha conversion. */
|
|
58
|
+
uploadBytes(data: Uint8Array, offset: number, level?: number, face?: number): void;
|
|
59
|
+
/**
|
|
60
|
+
* A compressed texture's level as S3TC blocks, DXT1's for "compressed" and
|
|
61
|
+
* DXT5's for "compressedAlpha": rows of 4x4 blocks from the top, at least
|
|
62
|
+
* one however small the level, copied before returning.
|
|
63
|
+
*/
|
|
64
|
+
uploadCompressed(blocks: Uint8Array, level?: number, face?: number): void;
|
|
65
|
+
dispose(): void;
|
|
66
|
+
}
|
|
67
|
+
export interface Context3DLifecycle {
|
|
68
|
+
lost(): void;
|
|
69
|
+
restored(): void;
|
|
70
|
+
}
|
|
71
|
+
/** Loss callbacks are asynchronous. Keep the lost surface until remove(), including
|
|
72
|
+
* its restoration listener; remove() must detach both listeners before releasing it. */
|
|
73
|
+
export interface Stage3DHost {
|
|
74
|
+
create(slot: number, lifecycle: Context3DLifecycle): Context3D;
|
|
75
|
+
place(slot: number, x: number, y: number, visible: boolean): void;
|
|
76
|
+
remove(slot: number): void;
|
|
77
|
+
}
|
|
78
|
+
export interface Context3D {
|
|
79
|
+
readonly width: number;
|
|
80
|
+
readonly height: number;
|
|
81
|
+
readonly disposed: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Whether a draw refuses a sampler that reads its texture as another
|
|
84
|
+
* format (TextureBindingError "format"): AIR checks from SWF 17 on.
|
|
85
|
+
*/
|
|
86
|
+
samplerFormats: boolean;
|
|
87
|
+
/** Optional acceleration for pixels uploaded to compressed textures. */
|
|
88
|
+
setDxtEncoder?(encoder: DxtEncoder): void;
|
|
89
|
+
configure(width: number, height: number, depth?: boolean, antiAlias?: number): void;
|
|
90
|
+
clear(red: number, green: number, blue: number, alpha: number, depth?: number, mask?: number, stencil?: number): void;
|
|
91
|
+
setStencilActions(face: CullFace, compare: CompareMode, pass: StencilAction, depthFail: StencilAction, stencilFail: StencilAction): void;
|
|
92
|
+
setStencilReference(reference: number, readMask: number, writeMask: number): void;
|
|
93
|
+
setDepth(write: boolean, compare: CompareMode): void;
|
|
94
|
+
setCulling(face: CullFace): void;
|
|
95
|
+
setBlend(source: BlendFactor, destination: BlendFactor): void;
|
|
96
|
+
setColorMask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void;
|
|
97
|
+
/** Null disables clipping; coordinates are in top-down target pixels. */
|
|
98
|
+
setScissor(x: number | null, y?: number, width?: number, height?: number): void;
|
|
99
|
+
createBuffer(count: number, stride: number): Buffer3D;
|
|
100
|
+
createProgram(): Program3D;
|
|
101
|
+
createTexture(width: number, height: number, cube?: boolean, format?: TextureFormat): Texture3D;
|
|
102
|
+
createRectangleTexture(width: number, height: number): Texture3D;
|
|
103
|
+
/** Level-zero target; face selects a cube surface. Null resumes the back buffer. */
|
|
104
|
+
setRenderTarget(texture: Texture3D | null, depth?: boolean, face?: number, antiAlias?: number): void;
|
|
105
|
+
setSampler(index: number, wrap: SamplerWrap, filter: SamplerFilter, mip: SamplerMip): void;
|
|
106
|
+
setTexture(index: number, texture: Texture3D | null): void;
|
|
107
|
+
setProgram(program: Program3D): void;
|
|
108
|
+
/** Offset counts 32-bit words; bytes4 consumes one word, normalized on the GPU. */
|
|
109
|
+
setVertex(index: number, buffer: Buffer3D | null, offset: number, format: VertexFormat): void;
|
|
110
|
+
setConstants(stage: ProgramType, first: number, values: ArrayLike<number>, count: number): void;
|
|
111
|
+
draw(indices: Buffer3D, first: number, triangles: number): void;
|
|
112
|
+
/**
|
|
113
|
+
* Top-down raw RGBA channels of the back buffer's top-left width by height
|
|
114
|
+
* (the whole of it by default), rows width * 4 bytes apart, without alpha
|
|
115
|
+
* conversion; valid until the next read. Each size is at most the back
|
|
116
|
+
* buffer's: a larger one is clamped to it, a negative one to 0.
|
|
117
|
+
*/
|
|
118
|
+
read(width?: number, height?: number): Uint8Array;
|
|
119
|
+
present(): void;
|
|
120
|
+
dispose(): void;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,eAAO,MAAM,aAAa,YACxB,QAAQ,EACR,OAAO,EACP,MAAM,EACN,WAAW,EACX,OAAO,EACP,UAAU,EACV,cAAc,EACd,SAAS,CACD,CAAC;AACX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,eAAO,MAAM,UAAU,YAAI,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAU,CAAC;AAC7E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,eAAO,MAAM,eAAe,YAC1B,MAAM,EACN,MAAM,EACN,KAAK,EACL,mBAAmB,EACnB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,eAAe,CACP,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,eAAO,MAAM,aAAa,YACxB,MAAM,EACN,KAAK,EACL,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,0BAA0B,EAC1B,kBAAkB,EAClB,0BAA0B,CAClB,CAAC;AACX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,eAAO,MAAM,aAAa,YAAI,O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AK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAAC;IAC3F,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3D,UAAU,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,CAAC;IACrC,mFAAmF;IACnF,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC9F,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAChG,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAChE;;;;;OAKG;IACH,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAClD,OAAO,IAAI,IAAI,CAAC;IAChB,OAAO,IAAI,IAAI,CAAC;CACjB"}
|
package/dist/backend.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const COMPARE_MODES = [
|
|
2
|
+
"always",
|
|
3
|
+
"never",
|
|
4
|
+
"less",
|
|
5
|
+
"lessEqual",
|
|
6
|
+
"equal",
|
|
7
|
+
"notEqual",
|
|
8
|
+
"greaterEqual",
|
|
9
|
+
"greater",
|
|
10
|
+
];
|
|
11
|
+
export const CULL_FACES = ["none", "back", "front", "frontAndBack"];
|
|
12
|
+
export const STENCIL_ACTIONS = [
|
|
13
|
+
"keep",
|
|
14
|
+
"zero",
|
|
15
|
+
"set",
|
|
16
|
+
"incrementSaturate",
|
|
17
|
+
"decrementSaturate",
|
|
18
|
+
"invert",
|
|
19
|
+
"incrementWrap",
|
|
20
|
+
"decrementWrap",
|
|
21
|
+
];
|
|
22
|
+
export const BLEND_FACTORS = [
|
|
23
|
+
"zero",
|
|
24
|
+
"one",
|
|
25
|
+
"sourceColor",
|
|
26
|
+
"oneMinusSourceColor",
|
|
27
|
+
"sourceAlpha",
|
|
28
|
+
"oneMinusSourceAlpha",
|
|
29
|
+
"destinationColor",
|
|
30
|
+
"oneMinusDestinationColor",
|
|
31
|
+
"destinationAlpha",
|
|
32
|
+
"oneMinusDestinationAlpha",
|
|
33
|
+
];
|
|
34
|
+
export const SAMPLER_WRAPS = ["clamp", "repeat_u_clamp_v", "clamp_u_repeat_v", "repeat"];
|
|
35
|
+
export const SAMPLER_FILTERS = [
|
|
36
|
+
"nearest",
|
|
37
|
+
"linear",
|
|
38
|
+
"anisotropic2x",
|
|
39
|
+
"anisotropic4x",
|
|
40
|
+
"anisotropic8x",
|
|
41
|
+
"anisotropic16x",
|
|
42
|
+
];
|
|
43
|
+
export const SAMPLER_MIPS = ["mipnone", "mipnearest", "miplinear"];
|
|
44
|
+
/** The texture formats a backend stores: BGRA, and S3TC's DXT1 and DXT5 as Flash calls them. */
|
|
45
|
+
export const TEXTURE_FORMATS = ["bgra", "compressed", "compressedAlpha"];
|
|
46
|
+
export const VERTEX_FORMATS = ["float1", "float2", "float3", "float4", "bytes4"];
|
|
47
|
+
export class VertexOffsetError extends Error {
|
|
48
|
+
}
|
|
49
|
+
export class ScissorBoundsError extends Error {
|
|
50
|
+
}
|
|
51
|
+
export class SamplerBiasError extends Error {
|
|
52
|
+
}
|
|
53
|
+
export class TextureBindingError extends Error {
|
|
54
|
+
reason;
|
|
55
|
+
/** The sampler it names, where it names one. */
|
|
56
|
+
sampler;
|
|
57
|
+
constructor(reason, sampler = -1) {
|
|
58
|
+
super(`Invalid texture binding: ${reason}`);
|
|
59
|
+
this.reason = reason;
|
|
60
|
+
this.sampler = sampler;
|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