@swf2es/context3d 0.0.0-stage → 0.1.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.
Files changed (88) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +219 -2
  3. package/dist/agal.d.ts +23 -0
  4. package/dist/agal.d.ts.map +1 -0
  5. package/dist/agal.js +410 -0
  6. package/dist/agal.js.map +1 -0
  7. package/dist/backend.d.ts +122 -0
  8. package/dist/backend.d.ts.map +1 -0
  9. package/dist/backend.js +63 -0
  10. package/dist/backend.js.map +1 -0
  11. package/dist/device/index.d.ts +3 -0
  12. package/dist/device/index.d.ts.map +1 -0
  13. package/dist/device/index.js +6 -0
  14. package/dist/device/index.js.map +1 -0
  15. package/dist/device/programs.d.ts +13 -0
  16. package/dist/device/programs.d.ts.map +1 -0
  17. package/dist/device/programs.js +59 -0
  18. package/dist/device/programs.js.map +1 -0
  19. package/dist/device/state.d.ts +53 -0
  20. package/dist/device/state.d.ts.map +1 -0
  21. package/dist/device/state.js +196 -0
  22. package/dist/device/state.js.map +1 -0
  23. package/dist/dxt.d.ts +22 -0
  24. package/dist/dxt.d.ts.map +1 -0
  25. package/dist/dxt.js +304 -0
  26. package/dist/dxt.js.map +1 -0
  27. package/dist/errors.d.ts +7 -0
  28. package/dist/errors.d.ts.map +1 -0
  29. package/dist/errors.js +8 -0
  30. package/dist/errors.js.map +1 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +6 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/webgl/buffers.d.ts +27 -0
  36. package/dist/webgl/buffers.d.ts.map +1 -0
  37. package/dist/webgl/buffers.js +53 -0
  38. package/dist/webgl/buffers.js.map +1 -0
  39. package/dist/webgl/context.d.ts +123 -0
  40. package/dist/webgl/context.d.ts.map +1 -0
  41. package/dist/webgl/context.js +1368 -0
  42. package/dist/webgl/context.js.map +1 -0
  43. package/dist/webgl/index.d.ts +3 -0
  44. package/dist/webgl/index.d.ts.map +1 -0
  45. package/dist/webgl/index.js +2 -0
  46. package/dist/webgl/index.js.map +1 -0
  47. package/dist/webgl/limits.d.ts +23 -0
  48. package/dist/webgl/limits.d.ts.map +1 -0
  49. package/dist/webgl/limits.js +35 -0
  50. package/dist/webgl/limits.js.map +1 -0
  51. package/dist/webgl/programs.d.ts +22 -0
  52. package/dist/webgl/programs.d.ts.map +1 -0
  53. package/dist/webgl/programs.js +110 -0
  54. package/dist/webgl/programs.js.map +1 -0
  55. package/dist/webgl/state.d.ts +42 -0
  56. package/dist/webgl/state.d.ts.map +1 -0
  57. package/dist/webgl/state.js +55 -0
  58. package/dist/webgl/state.js.map +1 -0
  59. package/dist/webgl/targets.d.ts +20 -0
  60. package/dist/webgl/targets.d.ts.map +1 -0
  61. package/dist/webgl/targets.js +138 -0
  62. package/dist/webgl/targets.js.map +1 -0
  63. package/dist/webgl/textures.d.ts +28 -0
  64. package/dist/webgl/textures.d.ts.map +1 -0
  65. package/dist/webgl/textures.js +119 -0
  66. package/dist/webgl/textures.js.map +1 -0
  67. package/dist/webgl/validation.d.ts +4 -0
  68. package/dist/webgl/validation.d.ts.map +1 -0
  69. package/dist/webgl/validation.js +52 -0
  70. package/dist/webgl/validation.js.map +1 -0
  71. package/package.json +37 -3
  72. package/src/agal.ts +496 -0
  73. package/src/backend.ts +210 -0
  74. package/src/device/index.ts +5 -0
  75. package/src/device/programs.ts +66 -0
  76. package/src/device/state.ts +214 -0
  77. package/src/dxt.ts +349 -0
  78. package/src/errors.ts +68 -0
  79. package/src/index.ts +35 -0
  80. package/src/webgl/buffers.ts +102 -0
  81. package/src/webgl/context.ts +1803 -0
  82. package/src/webgl/index.ts +2 -0
  83. package/src/webgl/limits.ts +61 -0
  84. package/src/webgl/programs.ts +145 -0
  85. package/src/webgl/state.ts +65 -0
  86. package/src/webgl/targets.ts +229 -0
  87. package/src/webgl/textures.ts +200 -0
  88. package/src/webgl/validation.ts +72 -0
@@ -0,0 +1,6 @@
1
+ // What the renderer (@swf2es/render) and Context3D share of a WebGL 2
2
+ // context: linking programs, and the cache of its state that its one owner
3
+ // sets it through (docs/renderer.md, "The backend").
4
+ export { linkProgram, ShaderError } from "./programs.js";
5
+ export { GlState } from "./state.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/device/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,2EAA2E;AAC3E,qDAAqD;AACrD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,13 @@
1
+ /** Why a program could not be made: no objects to make it of, a stage that did not compile, or no link. */
2
+ export declare class ShaderError extends Error {
3
+ readonly stage: "allocate" | "compile" | "link";
4
+ readonly log: string;
5
+ constructor(stage: "allocate" | "compile" | "link", log: string);
6
+ }
7
+ /**
8
+ * A program linked from GLSL `vertex` and `fragment`, its shaders detached
9
+ * and deleted once linked, and nothing left behind if it fails: a
10
+ * ShaderError says where.
11
+ */
12
+ export declare function linkProgram(gl: WebGL2RenderingContext, vertex: string, fragment: string): WebGLProgram;
13
+ //# sourceMappingURL=programs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"programs.d.ts","sourceRoot":"","sources":["../../src/device/programs.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,qBAAa,WAAY,SAAQ,KAAK;IAElC,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM;IAC/C,QAAQ,CAAC,GAAG,EAAE,MAAM;IAFtB,YACW,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,EACtC,GAAG,EAAE,MAAM,EAIrB;CACF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,EAAE,EAAE,sBAAsB,EAC1B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,YAAY,CA6Cd"}
@@ -0,0 +1,59 @@
1
+ /** Why a program could not be made: no objects to make it of, a stage that did not compile, or no link. */
2
+ export class ShaderError extends Error {
3
+ stage;
4
+ log;
5
+ constructor(stage, log) {
6
+ super(log);
7
+ this.stage = stage;
8
+ this.log = log;
9
+ this.name = "ShaderError";
10
+ }
11
+ }
12
+ /**
13
+ * A program linked from GLSL `vertex` and `fragment`, its shaders detached
14
+ * and deleted once linked, and nothing left behind if it fails: a
15
+ * ShaderError says where.
16
+ */
17
+ export function linkProgram(gl, vertex, fragment) {
18
+ const v = gl.createShader(gl.VERTEX_SHADER);
19
+ const f = gl.createShader(gl.FRAGMENT_SHADER);
20
+ const p = gl.createProgram();
21
+ let linked = false;
22
+ let attached = false;
23
+ try {
24
+ if (!v || !f || !p) {
25
+ throw new ShaderError("allocate", "cannot allocate shader");
26
+ }
27
+ gl.shaderSource(v, vertex);
28
+ gl.shaderSource(f, fragment);
29
+ gl.compileShader(v);
30
+ gl.compileShader(f);
31
+ if (!gl.getShaderParameter(v, gl.COMPILE_STATUS) ||
32
+ !gl.getShaderParameter(f, gl.COMPILE_STATUS)) {
33
+ throw new ShaderError("compile", `${gl.getShaderInfoLog(v)} ${gl.getShaderInfoLog(f)}`);
34
+ }
35
+ gl.attachShader(p, v);
36
+ gl.attachShader(p, f);
37
+ attached = true;
38
+ gl.linkProgram(p);
39
+ if (!gl.getProgramParameter(p, gl.LINK_STATUS)) {
40
+ throw new ShaderError("link", `${gl.getProgramInfoLog(p)}`);
41
+ }
42
+ linked = true;
43
+ return p;
44
+ }
45
+ finally {
46
+ if (attached && p && v) {
47
+ gl.detachShader(p, v);
48
+ }
49
+ if (attached && p && f) {
50
+ gl.detachShader(p, f);
51
+ }
52
+ gl.deleteShader(v);
53
+ gl.deleteShader(f);
54
+ if (!linked) {
55
+ gl.deleteProgram(p);
56
+ }
57
+ }
58
+ }
59
+ //# sourceMappingURL=programs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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SAAS,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC1F,CAAC;QAED,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACtB,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACtB,QAAQ,GAAG,IAAI,CAAC;QAChB,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9D,CAAC;QAED,MAAM,GAAG,IAAI,CAAC;QACd,OAAO,CAAC,CAAC;IACX,CAAC;YAAS,CAAC;QACT,IAAI,QAAQ,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxB,CAAC;QACD,IAAI,QAAQ,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxB,CAAC;QACD,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACnB,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACnB,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The GL state of a context as its one owner last set it, so that nothing
3
+ * is set twice: the program, vertex array, framebuffer, viewport, blending,
4
+ * scissor, colour mask and the textures on each unit. What sets state
5
+ * behind it (another library, a lost context) calls forget, and everything
6
+ * is set again on its next use.
7
+ */
8
+ export declare class GlState {
9
+ readonly gl: WebGL2RenderingContext;
10
+ private program;
11
+ private vertexArray;
12
+ private framebuffer;
13
+ private readonly view;
14
+ /** Blending: on or off, then the four factors and the equation, -1 as unknown. */
15
+ private blending;
16
+ private readonly blend;
17
+ private scissoring;
18
+ private readonly box;
19
+ private mask;
20
+ /** The stencil test: off (undefined unknown), or its function, reference and pass operation. */
21
+ private stencilling;
22
+ private readonly stencilState;
23
+ private unit;
24
+ private readonly textures;
25
+ private readonly samplers;
26
+ constructor(gl: WebGL2RenderingContext);
27
+ /** Everything unknown: set again as next asked for. */
28
+ forget(): void;
29
+ useProgram(program: WebGLProgram | null): void;
30
+ bindVertexArray(vertexArray: WebGLVertexArrayObject | null): void;
31
+ bindFramebuffer(framebuffer: WebGLFramebuffer | null): void;
32
+ viewport(x: number, y: number, width: number, height: number): void;
33
+ /** Blending by the factors and equation given, or off with `src` null. */
34
+ setBlend(src: number | null, dst?: number, srcAlpha?: number, dstAlpha?: number, equation?: number): void;
35
+ /** Scissoring to the box given, or off with none. */
36
+ scissor(box: readonly [number, number, number, number] | null): void;
37
+ /**
38
+ * The stencil test: passing where `func` holds of the stencil and `ref`,
39
+ * then `pass` done to it (KEEP, INCR, DECR...); off with `func` null.
40
+ */
41
+ stencil(func: number | null, ref?: number, pass?: number): void;
42
+ /** Which of red, green, blue and alpha are written, as bits 1, 2, 4 and 8. */
43
+ colorMask(bits: number): void;
44
+ /** `texture` bound to texture unit `unit` as a 2D texture. */
45
+ bindTexture(unit: number, texture: WebGLTexture | null): void;
46
+ /** `sampler` bound to texture unit `unit`, or none for the texture's own parameters. */
47
+ bindSampler(unit: number, sampler: WebGLSampler | null): void;
48
+ /** Make `unit` the active one, for an upload to the texture bound there. */
49
+ activeTexture(unit: number): void;
50
+ /** A texture deleted: no unit is thought to hold it any more. */
51
+ dropTexture(texture: WebGLTexture): void;
52
+ }
53
+ //# sourceMappingURL=state.d.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AAW,EAAE,QAAQ,SAAM,EAAE,QAAQ,SAAI,GAAG,IAAI,CA8B7F;IAED,qDAAqD;IACrD,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,IAAI,CAoBnE;IAED;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,SAAI,EAAE,IAAI,SAAI,GAAG,IAAI,CA4BpD;IAED,8EAA8E;IAC9E,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAK5B;IAED,8DAA8D;IAC9D,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI,CAQ5D;IAED,wFAAwF;IACxF,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI,CAK5D;IAED,4EAA4E;IAC5E,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAKhC;IAED,iEAAiE;IACjE,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAMvC;CACF"}
@@ -0,0 +1,196 @@
1
+ /**
2
+ * The GL state of a context as its one owner last set it, so that nothing
3
+ * is set twice: the program, vertex array, framebuffer, viewport, blending,
4
+ * scissor, colour mask and the textures on each unit. What sets state
5
+ * behind it (another library, a lost context) calls forget, and everything
6
+ * is set again on its next use.
7
+ */
8
+ export class GlState {
9
+ gl;
10
+ program;
11
+ vertexArray;
12
+ framebuffer;
13
+ view = [Number.NaN, Number.NaN, Number.NaN, Number.NaN];
14
+ /** Blending: on or off, then the four factors and the equation, -1 as unknown. */
15
+ blending;
16
+ blend = [-1, -1, -1, -1, -1];
17
+ scissoring;
18
+ box = [Number.NaN, Number.NaN, Number.NaN, Number.NaN];
19
+ mask = -1;
20
+ /** The stencil test: off (undefined unknown), or its function, reference and pass operation. */
21
+ stencilling;
22
+ stencilState = [-1, -1, -1];
23
+ unit = -1;
24
+ textures = [];
25
+ samplers = [];
26
+ constructor(gl) {
27
+ this.gl = gl;
28
+ }
29
+ /** Everything unknown: set again as next asked for. */
30
+ forget() {
31
+ this.program = undefined;
32
+ this.vertexArray = undefined;
33
+ this.framebuffer = undefined;
34
+ this.view.fill(Number.NaN);
35
+ this.blending = undefined;
36
+ this.blend.fill(-1);
37
+ this.scissoring = undefined;
38
+ this.box.fill(Number.NaN);
39
+ this.mask = -1;
40
+ this.stencilling = undefined;
41
+ this.stencilState.fill(-1);
42
+ this.unit = -1;
43
+ this.textures.length = 0;
44
+ this.samplers.length = 0;
45
+ }
46
+ useProgram(program) {
47
+ if (program !== this.program) {
48
+ this.program = program;
49
+ this.gl.useProgram(program);
50
+ }
51
+ }
52
+ bindVertexArray(vertexArray) {
53
+ if (vertexArray !== this.vertexArray) {
54
+ this.vertexArray = vertexArray;
55
+ this.gl.bindVertexArray(vertexArray);
56
+ }
57
+ }
58
+ bindFramebuffer(framebuffer) {
59
+ if (framebuffer !== this.framebuffer) {
60
+ this.framebuffer = framebuffer;
61
+ this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, framebuffer);
62
+ }
63
+ }
64
+ viewport(x, y, width, height) {
65
+ const v = this.view;
66
+ if (v[0] !== x || v[1] !== y || v[2] !== width || v[3] !== height) {
67
+ v[0] = x;
68
+ v[1] = y;
69
+ v[2] = width;
70
+ v[3] = height;
71
+ this.gl.viewport(x, y, width, height);
72
+ }
73
+ }
74
+ /** Blending by the factors and equation given, or off with `src` null. */
75
+ setBlend(src, dst = 0, srcAlpha = src ?? 0, dstAlpha = dst, equation = 0) {
76
+ const gl = this.gl;
77
+ const on = src !== null;
78
+ if (on !== this.blending) {
79
+ this.blending = on;
80
+ if (on) {
81
+ gl.enable(gl.BLEND);
82
+ }
83
+ else {
84
+ gl.disable(gl.BLEND);
85
+ }
86
+ }
87
+ if (!on) {
88
+ return;
89
+ }
90
+ const b = this.blend;
91
+ if (b[0] !== src || b[1] !== dst || b[2] !== srcAlpha || b[3] !== dstAlpha) {
92
+ b[0] = src;
93
+ b[1] = dst;
94
+ b[2] = srcAlpha;
95
+ b[3] = dstAlpha;
96
+ gl.blendFuncSeparate(src, dst, srcAlpha, dstAlpha);
97
+ }
98
+ const eq = equation || gl.FUNC_ADD;
99
+ if (b[4] !== eq) {
100
+ b[4] = eq;
101
+ gl.blendEquation(eq);
102
+ }
103
+ }
104
+ /** Scissoring to the box given, or off with none. */
105
+ scissor(box) {
106
+ const gl = this.gl;
107
+ const on = box !== null;
108
+ if (on !== this.scissoring) {
109
+ this.scissoring = on;
110
+ if (on) {
111
+ gl.enable(gl.SCISSOR_TEST);
112
+ }
113
+ else {
114
+ gl.disable(gl.SCISSOR_TEST);
115
+ }
116
+ }
117
+ const b = this.box;
118
+ if (box && (b[0] !== box[0] || b[1] !== box[1] || b[2] !== box[2] || b[3] !== box[3])) {
119
+ b[0] = box[0];
120
+ b[1] = box[1];
121
+ b[2] = box[2];
122
+ b[3] = box[3];
123
+ gl.scissor(box[0], box[1], box[2], box[3]);
124
+ }
125
+ }
126
+ /**
127
+ * The stencil test: passing where `func` holds of the stencil and `ref`,
128
+ * then `pass` done to it (KEEP, INCR, DECR...); off with `func` null.
129
+ */
130
+ stencil(func, ref = 0, pass = 0) {
131
+ const gl = this.gl;
132
+ const on = func !== null;
133
+ if (on !== this.stencilling) {
134
+ this.stencilling = on;
135
+ if (on) {
136
+ gl.enable(gl.STENCIL_TEST);
137
+ }
138
+ else {
139
+ gl.disable(gl.STENCIL_TEST);
140
+ }
141
+ }
142
+ if (!on) {
143
+ return;
144
+ }
145
+ const s = this.stencilState;
146
+ if (s[0] !== func || s[1] !== ref) {
147
+ s[0] = func;
148
+ s[1] = ref;
149
+ gl.stencilFunc(func, ref, 0xff);
150
+ }
151
+ const op = pass || gl.KEEP;
152
+ if (s[2] !== op) {
153
+ s[2] = op;
154
+ gl.stencilOp(gl.KEEP, gl.KEEP, op);
155
+ }
156
+ }
157
+ /** Which of red, green, blue and alpha are written, as bits 1, 2, 4 and 8. */
158
+ colorMask(bits) {
159
+ if (bits !== this.mask) {
160
+ this.mask = bits;
161
+ this.gl.colorMask((bits & 1) !== 0, (bits & 2) !== 0, (bits & 4) !== 0, (bits & 8) !== 0);
162
+ }
163
+ }
164
+ /** `texture` bound to texture unit `unit` as a 2D texture. */
165
+ bindTexture(unit, texture) {
166
+ if (this.textures[unit] === texture) {
167
+ return;
168
+ }
169
+ this.textures[unit] = texture;
170
+ this.activeTexture(unit);
171
+ this.gl.bindTexture(this.gl.TEXTURE_2D, texture);
172
+ }
173
+ /** `sampler` bound to texture unit `unit`, or none for the texture's own parameters. */
174
+ bindSampler(unit, sampler) {
175
+ if (this.samplers[unit] !== sampler) {
176
+ this.samplers[unit] = sampler;
177
+ this.gl.bindSampler(unit, sampler);
178
+ }
179
+ }
180
+ /** Make `unit` the active one, for an upload to the texture bound there. */
181
+ activeTexture(unit) {
182
+ if (unit !== this.unit) {
183
+ this.unit = unit;
184
+ this.gl.activeTexture(this.gl.TEXTURE0 + unit);
185
+ }
186
+ }
187
+ /** A texture deleted: no unit is thought to hold it any more. */
188
+ dropTexture(texture) {
189
+ for (let i = 0; i < this.textures.length; i++) {
190
+ if (this.textures[i] === texture) {
191
+ this.textures[i] = undefined;
192
+ }
193
+ }
194
+ }
195
+ }
196
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/device/state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,OAAO;IACT,EAAE,CAAyB;IAC5B,OAAO,CAAkC;IACzC,WAAW,CAA4C;IACvD,WAAW,CAAsC;IACxC,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IACzE,kFAAkF;IAC1E,QAAQ,CAAs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rC,CAAC;IACH,CAAC;IAED,4EAA4E;IAC5E,aAAa,CAAC,IAAY;QACxB,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED,iEAAiE;IACjE,WAAW,CAAC,OAAqB;QAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9C,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;gBACjC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
package/dist/dxt.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /** A whole RGBA level encoded to DXT blocks; null uses the TypeScript encoder. */
2
+ export type DxtEncoder = (rgba: Uint8Array, dxt5: boolean, width: number, height: number) => Uint8Array | null;
3
+ /**
4
+ * `blocks`, a level `width` by `height` of DXT1 (8 bytes a 4x4 block) or,
5
+ * with `dxt5`, DXT5 (16), rows of blocks from the top, written to `out` as
6
+ * top-down RGBA rows of `width` pixels. The level's edge blocks may stand
7
+ * past it, as a 2x2 level's one block does; what stands past is dropped.
8
+ */
9
+ export declare function decodeDxt(blocks: Uint8Array, dxt5: boolean, width: number, height: number, out: Uint8Array): void;
10
+ /** The bytes of a level `width` by `height` as DXT1's blocks, or DXT5's: one block at least. */
11
+ export declare function blockBytes(width: number, height: number, dxt5: boolean): number;
12
+ /**
13
+ * `rgba`, top-down RGBA rows of `width` pixels, `height` high, as blocks,
14
+ * DXT1's or with `dxt5` DXT5's, for `decodeDxt` or a GPU: each block's
15
+ * colours on the line through them that their spread runs along (its
16
+ * principal axis, by a few power iterations), between the pixels that lie
17
+ * farthest out on it, four of them always; DXT5's alpha between its lowest
18
+ * and highest, eight. A level smaller than a block repeats its pixels across
19
+ * it. The result is a view of a buffer the next call reuses.
20
+ */
21
+ export declare function encodeDxt(rgba: Uint8Array, dxt5: boolean, width: number, height: number): Uint8Array;
22
+ //# sourceMappingURL=dxt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dxt.d.ts","sourceRoot":"","sources":["../src/dxt.ts"],"names":[],"mappings":"AAkCA,kFAAkF;AAClF,MAAM,MAAM,UAAU,GAAG,CACvB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,KACX,UAAU,GAAG,IAAI,CAAC;AAEvB;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,UAAU,GACd,IAAI,CA4EN;AAeD,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAE/E;AAKD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,UAAU,CAqLZ"}