webgl2-sdf 0.0.3 → 0.0.4
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/browser/index.min.js +1 -1
- package/node/generate-sdf.d.ts +3 -2
- package/node/generate-sdf.js +5 -6
- package/node/generate-sdf.js.map +1 -1
- package/node/index.d.ts +2 -0
- package/node/index.js +2 -0
- package/node/index.js.map +1 -1
- package/node/main-program.js +0 -1
- package/node/main-program.js.map +1 -1
- package/node/prepare-buffers.js +4 -6
- package/node/prepare-buffers.js.map +1 -1
- package/node/shaders/main.vertex.d.ts +1 -1
- package/node/shaders/main.vertex.js +0 -1
- package/node/shaders/main.vertex.js.map +1 -1
- package/node/types/gl-context.d.ts +0 -1
- package/node/types/program.d.ts +2 -0
- package/node/utils/calc-circs.js.map +1 -1
- package/node/utils/clip-line-segment-to-grid.d.ts +1 -1
- package/node/utils/clip-line-segment-to-grid.js +1 -4
- package/node/utils/clip-line-segment-to-grid.js.map +1 -1
- package/node/utils/clip-line-segment-to-strips.d.ts +2 -3
- package/node/utils/clip-line-segment-to-strips.js +5 -57
- package/node/utils/clip-line-segment-to-strips.js.map +1 -1
- package/node/utils/find-close-cells.js +14 -70
- package/node/utils/find-close-cells.js.map +1 -1
- package/node/utils/find-crossing-cells.js +0 -15
- package/node/utils/find-crossing-cells.js.map +1 -1
- package/node/utils/jump-idx.js +20 -18
- package/node/utils/jump-idx.js.map +1 -1
- package/node/webgl-utils/free-gl-context.d.ts +3 -0
- package/node/webgl-utils/free-gl-context.js +26 -0
- package/node/webgl-utils/free-gl-context.js.map +1 -0
- package/node/webgl-utils/get-gl-context.d.ts +2 -2
- package/node/webgl-utils/get-gl-context.js +6 -9
- package/node/webgl-utils/get-gl-context.js.map +1 -1
- package/node/webgl-utils/set-attribute.js +1 -1
- package/node/webgl-utils/set-attribute.js.map +1 -1
- package/node/webgl-utils/set-uniform-block.js +1 -3
- package/node/webgl-utils/set-uniform-block.js.map +1 -1
- package/node/webgl-utils/use-program.js +13 -3
- package/node/webgl-utils/use-program.js.map +1 -1
- package/package.json +1 -1
- package/src/generate-sdf.ts +7 -5
- package/src/index.ts +2 -0
- package/src/main-program.ts +0 -1
- package/src/prepare-buffers.ts +5 -6
- package/src/shaders/main.vertex.ts +0 -1
- package/src/types/gl-context.ts +0 -1
- package/src/types/program.ts +2 -0
- package/src/utils/calc-circs.ts +0 -2
- package/src/utils/clip-line-segment-to-grid.ts +1 -5
- package/src/utils/clip-line-segment-to-strips.ts +6 -73
- package/src/utils/find-close-cells.ts +27 -87
- package/src/utils/find-crossing-cells.ts +1 -18
- package/src/utils/jump-idx.ts +25 -20
- package/src/webgl-utils/free-gl-context.ts +35 -0
- package/src/webgl-utils/get-gl-context.ts +6 -9
- package/src/webgl-utils/set-attribute.ts +1 -1
- package/src/webgl-utils/set-uniform-block.ts +1 -3
- package/src/webgl-utils/use-program.ts +14 -3
- package/node/debug-shaders.d.ts +0 -9
- package/node/types/strip.d.ts +0 -8
- package/node/types/strip.js +0 -2
- package/node/types/strip.js.map +0 -1
- package/node/utils/create-empty-strips.d.ts +0 -7
- package/node/utils/create-empty-strips.js +0 -16
- package/node/utils/create-empty-strips.js.map +0 -1
- package/node/utils/distance-seg-to-p.d.ts +0 -5
- package/node/utils/distance-seg-to-p.js +0 -35
- package/node/utils/distance-seg-to-p.js.map +0 -1
- package/node/webgl2.d.ts +0 -2
- package/src/types/strip.ts +0 -11
- package/src/utils/create-empty-strips.ts +0 -21
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Strip } from "../types/strip.js";
|
|
2
1
|
import { segStripX } from "./seg-strip-x.js";
|
|
3
2
|
|
|
4
3
|
|
|
@@ -11,12 +10,12 @@ const { floor, ceil } = Math;
|
|
|
11
10
|
* * modifies strips by adding line segments to each strip
|
|
12
11
|
* * size/count *must* be a power of 2
|
|
13
12
|
*
|
|
14
|
-
* @param
|
|
13
|
+
* @param strips array of strips - each contains an array line segments
|
|
15
14
|
* @param height the height of a strip
|
|
16
15
|
* @param seg the line segment (array of 2 points)
|
|
17
16
|
*/
|
|
18
17
|
function clipLineSegmentToStrips(
|
|
19
|
-
strips:
|
|
18
|
+
strips: number[][][][],
|
|
20
19
|
height: number,
|
|
21
20
|
seg: number[][]): void {
|
|
22
21
|
|
|
@@ -93,7 +92,7 @@ function clipLineSegmentToStrips(
|
|
|
93
92
|
// if we're past the line endpoint
|
|
94
93
|
if ((tX > 1 || dX === 0) && tY > 1) {
|
|
95
94
|
const v = floor(p1[1]/cellSize);
|
|
96
|
-
strips[v]?.
|
|
95
|
+
strips[v]?.push([[x,y],p1]);
|
|
97
96
|
break;
|
|
98
97
|
}
|
|
99
98
|
|
|
@@ -109,7 +108,7 @@ function clipLineSegmentToStrips(
|
|
|
109
108
|
} else {
|
|
110
109
|
const v = fY(y/cellSize) - (btt ? 0 : 1); // previous v
|
|
111
110
|
const seg_ = [[x,y],ps[i]];
|
|
112
|
-
strips[v]?.
|
|
111
|
+
strips[v]?.push(seg_);
|
|
113
112
|
break;
|
|
114
113
|
}
|
|
115
114
|
}
|
|
@@ -117,7 +116,7 @@ function clipLineSegmentToStrips(
|
|
|
117
116
|
// previous v
|
|
118
117
|
const v = fY(y/cellSize) - (btt ? 0 : 1);
|
|
119
118
|
|
|
120
|
-
strips[v]?.
|
|
119
|
+
strips[v]?.push([[x,y], [xX,xY]]);
|
|
121
120
|
|
|
122
121
|
// update current position
|
|
123
122
|
x = xX;
|
|
@@ -127,70 +126,4 @@ function clipLineSegmentToStrips(
|
|
|
127
126
|
|
|
128
127
|
|
|
129
128
|
export { clipLineSegmentToStrips }
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// Quokka tests - https://www.desmos.com/calculator/uyqsdkviih
|
|
133
|
-
// import { createEmptyStrips } from "./create-empty-strips";
|
|
134
|
-
|
|
135
|
-
// {
|
|
136
|
-
// const strips = createEmptyStrips(8);
|
|
137
|
-
// const seg = [[0, 100], [0, 400]];
|
|
138
|
-
|
|
139
|
-
// toDesmosStr(seg);
|
|
140
|
-
// clipLineSegmentToStrips(strips, 512, seg);
|
|
141
|
-
// testAllEmptyExcept(strips,[1,2,3,4,5,6]);
|
|
142
|
-
// }
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// {
|
|
146
|
-
// const strips = createEmptyStrips(8);
|
|
147
|
-
// const seg = [[83, 166], [-90, 440]];
|
|
148
|
-
|
|
149
|
-
// toDesmosStr(seg);
|
|
150
|
-
// clipLineSegmentToStrips(strips, 512, seg);
|
|
151
|
-
// testAllEmptyExcept(strips,[4,5,6]);
|
|
152
|
-
// }
|
|
153
|
-
|
|
154
|
-
// {
|
|
155
|
-
// const strips = createEmptyStrips(8);
|
|
156
|
-
// const seg = [[-570, 236], [-392, 546]];
|
|
157
|
-
|
|
158
|
-
// toDesmosStr(seg);
|
|
159
|
-
// clipLineSegmentToStrips(strips, 512, seg);
|
|
160
|
-
// testAllEmptyExcept(strips,[3,4,5,6,7]);
|
|
161
|
-
// }
|
|
162
|
-
|
|
163
|
-
// {
|
|
164
|
-
// const strips = createEmptyStrips(8);
|
|
165
|
-
// const seg = [[-462, 632], [-152, 611]];
|
|
166
|
-
|
|
167
|
-
// toDesmosStr(seg);
|
|
168
|
-
// clipLineSegmentToStrips(strips, 512, seg);
|
|
169
|
-
// testAllEmptyExcept(strips,[]);
|
|
170
|
-
// }
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
// function toDesmosStr(seg: number[][]) {
|
|
174
|
-
// const [[x0,y0],[x1,y1]] = seg;
|
|
175
|
-
// return `\\left(\\left(1-t\\right)\\cdot${x0.toFixed(2)}+t\\cdot\\left(${x1.toFixed(2)}\\right),\\left(1-t\\right)\\cdot${y0.toFixed(2)}+t\\cdot${y1.toFixed(2)}\\right)`;
|
|
176
|
-
// }
|
|
177
|
-
// function testAllEmptyExcept(
|
|
178
|
-
// strips: Strip[],
|
|
179
|
-
// exceptions: number[]) {
|
|
180
|
-
|
|
181
|
-
// for (let i=0; i<strips.length; i++) {
|
|
182
|
-
// const strip = strips[i];
|
|
183
|
-
// const idx = exceptions.findIndex(v => v === i);
|
|
184
|
-
// const exception = exceptions[idx];
|
|
185
|
-
// const len = strip.lineSegs.length;
|
|
186
|
-
// if (exception === undefined) {
|
|
187
|
-
// if (len !== 0) {
|
|
188
|
-
// throw new Error(`Strip ${i} must be empty`);
|
|
189
|
-
// }
|
|
190
|
-
// } else {
|
|
191
|
-
// if (len !== 1) {
|
|
192
|
-
// throw new Error(`Strip ${i} must contain 1 segments, found ${len}`);
|
|
193
|
-
// }
|
|
194
|
-
// }
|
|
195
|
-
// }
|
|
196
|
-
// }
|
|
129
|
+
var a = [[1,1], [1,1]]
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Cell } from "../types/cell.js";
|
|
2
2
|
import { ROW_COUNT } from "../row-count.js";
|
|
3
3
|
import { circsCache } from "./calc-circs.js";
|
|
4
|
-
import { distanceSegToP } from "./distance-seg-to-p.js";
|
|
5
4
|
import { jumpIdx } from "./jump-idx.js";
|
|
6
5
|
|
|
7
6
|
|
|
8
|
-
const { min, SQRT2 } = Math;
|
|
7
|
+
const { min, max, SQRT2 } = Math;
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
function findCloseCells(
|
|
@@ -44,57 +43,47 @@ function findCloseCellsFor(
|
|
|
44
43
|
// reduce current circle search range since we moved one square
|
|
45
44
|
let k = jumpIdx((_minD - SQRT2*cellSize) / cellSize);
|
|
46
45
|
let minD = Number.POSITIVE_INFINITY;
|
|
47
|
-
while (
|
|
48
|
-
|
|
46
|
+
while (true) {
|
|
47
|
+
if (k >= circsCache.length) {
|
|
48
|
+
minD = cellSize*(circsCache[circsCache.length - 1].from - SQRT2);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { u, v, from } = circsCache[k];
|
|
49
53
|
|
|
50
54
|
// `SQRT2` to account for diagonal
|
|
51
55
|
if (cellSize*from > maxDistance + SQRT2*cellSize) {
|
|
56
|
+
minD = cellSize*(from - 2*SQRT2);
|
|
52
57
|
break;
|
|
53
58
|
}
|
|
54
59
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (let l=0; l<lineSegs.length; l++) {
|
|
68
|
-
// center of square
|
|
69
|
-
const c = [(i - padCount + 0.5)*cellSize, (j - padCount + 0.5)*cellSize];
|
|
70
|
-
const d = distanceSegToP(lineSegs[l], c);
|
|
71
|
-
if (d < minD) {
|
|
72
|
-
minD = d;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
k++;
|
|
77
|
-
// }
|
|
78
|
-
|
|
79
|
-
if (minD !== Number.POSITIVE_INFINITY) {
|
|
60
|
+
const u_ = u + i;
|
|
61
|
+
const v_ = v + j;
|
|
62
|
+
if (u_ < 0 || u_ >= colCount + 2*padCount ||
|
|
63
|
+
v_ < 0 || v_ >= ROW_COUNT + 2*padCount) {
|
|
64
|
+
|
|
65
|
+
k++; continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const { lineSegs } = grid[u_][v_];
|
|
69
|
+
|
|
70
|
+
if (lineSegs.length > 0) {
|
|
71
|
+
minD = cellSize*(from - SQRT2);
|
|
80
72
|
break;
|
|
81
73
|
}
|
|
82
|
-
}
|
|
83
74
|
|
|
84
|
-
|
|
85
|
-
return min(
|
|
86
|
-
maxDistance + SQRT2*cellSize,
|
|
87
|
-
cellSize * circsCache[circsCache.length - 1].from
|
|
88
|
-
);
|
|
75
|
+
k++;
|
|
89
76
|
}
|
|
90
77
|
|
|
78
|
+
|
|
91
79
|
const { closeCells } = grid[i][j];
|
|
92
|
-
|
|
80
|
+
|
|
81
|
+
let l = max(0, k - 1);
|
|
93
82
|
while (l < circsCache.length) {
|
|
94
83
|
const { from, u, v } = circsCache[l];
|
|
95
84
|
|
|
96
|
-
// `SQRT2` to account for diagonal
|
|
97
|
-
if (cellSize*from > min(minD, maxDistance) + SQRT2*cellSize) {
|
|
85
|
+
// `SQRT2` to account for diagonal (times 2 since we minused it off earlier)
|
|
86
|
+
if (cellSize*from > min(minD, maxDistance) + 2*SQRT2*cellSize) {
|
|
98
87
|
break;
|
|
99
88
|
}
|
|
100
89
|
|
|
@@ -120,52 +109,3 @@ function findCloseCellsFor(
|
|
|
120
109
|
|
|
121
110
|
|
|
122
111
|
export { findCloseCells }
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// Quokka tests
|
|
126
|
-
// const grid: Cell[][] = [
|
|
127
|
-
// [
|
|
128
|
-
// { u: 0, v: 0, lineSegs: [], closeCells: [], crossingCells: [] },
|
|
129
|
-
// { u: 0, v: 1, lineSegs: [], closeCells: [], crossingCells: [] },
|
|
130
|
-
// { u: 0, v: 2, lineSegs: [], closeCells: [], crossingCells: [] },
|
|
131
|
-
// { u: 0, v: 3, lineSegs: [], closeCells: [], crossingCells: [] }
|
|
132
|
-
// ],
|
|
133
|
-
// [
|
|
134
|
-
// { u: 1, v: 0, lineSegs: [], closeCells: [], crossingCells: [] },
|
|
135
|
-
// {
|
|
136
|
-
// u: 1, v: 1,
|
|
137
|
-
// lineSegs: [[[175, 163], [175, 355]]],
|
|
138
|
-
// closeCells: [], crossingCells: []
|
|
139
|
-
// },
|
|
140
|
-
// {
|
|
141
|
-
// u: 1, v: 2,
|
|
142
|
-
// lineSegs: [[[175, 355], [335, 355]]],
|
|
143
|
-
// closeCells: [], crossingCells: []
|
|
144
|
-
// },
|
|
145
|
-
// { u: 1, v: 3, lineSegs: [], closeCells: [], crossingCells: [] }
|
|
146
|
-
// ],
|
|
147
|
-
// [
|
|
148
|
-
// { u: 2, v: 0, lineSegs: [], closeCells: [], crossingCells: [] },
|
|
149
|
-
// {
|
|
150
|
-
// u: 2, v: 1,
|
|
151
|
-
// lineSegs: [[[335, 163], [175, 163]]],
|
|
152
|
-
// closeCells: [], crossingCells: []
|
|
153
|
-
// },
|
|
154
|
-
// {
|
|
155
|
-
// u: 2, v: 2,
|
|
156
|
-
// lineSegs: [[[335, 355], [335, 163]]],
|
|
157
|
-
// closeCells: [], crossingCells: []
|
|
158
|
-
// },
|
|
159
|
-
// { u: 2, v: 3, lineSegs: [], closeCells: [], crossingCells: [] }
|
|
160
|
-
// ],
|
|
161
|
-
// [
|
|
162
|
-
// { u: 3, v: 0, lineSegs: [], closeCells: [], crossingCells: [] },
|
|
163
|
-
// { u: 3, v: 1, lineSegs: [], closeCells: [], crossingCells: [] },
|
|
164
|
-
// { u: 3, v: 2, lineSegs: [], closeCells: [], crossingCells: [] },
|
|
165
|
-
// { u: 3, v: 3, lineSegs: [], closeCells: [], crossingCells: [] }
|
|
166
|
-
// ]
|
|
167
|
-
// ];
|
|
168
|
-
|
|
169
|
-
// findCloseCells(grid);
|
|
170
|
-
// const v = grid.map(cells => cells.map(c => ({ u: c.u, v: c.v, closeCells: c.closeCells })));
|
|
171
|
-
// v;//?
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { ROW_COUNT } from "../row-count.js";
|
|
2
1
|
import type { Cell } from "../types/cell.js";
|
|
2
|
+
import { ROW_COUNT } from "../row-count.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
// TODO - simplify?
|
|
6
|
-
// TODO - could be made much faster by also checking intersections here
|
|
7
|
-
// and passing the result to the next cell
|
|
8
5
|
function findCrossingCells(
|
|
9
6
|
grid: Cell[][],
|
|
10
7
|
colCount: number,
|
|
@@ -24,17 +21,3 @@ function findCrossingCells(
|
|
|
24
21
|
|
|
25
22
|
|
|
26
23
|
export { findCrossingCells }
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// Quokka tests
|
|
30
|
-
// import { createEmptyGrid } from "./create-empty-grid";
|
|
31
|
-
// // const g = createEmptyGrid(0);
|
|
32
|
-
// const g = createEmptyGrid(0);
|
|
33
|
-
// // g[0][0].lineSegs.push([[]]);
|
|
34
|
-
// g[2][0].lineSegs.push([[]]);
|
|
35
|
-
// g[2][2].lineSegs.push([[]]);
|
|
36
|
-
// findCrossingCells(g);
|
|
37
|
-
// let r = 2;
|
|
38
|
-
// // g.map(r => r.map(c => c.crossingCells))[r].map(v => v);//?
|
|
39
|
-
// g.map(r => r.map(c => c.crossingCells))[r].map(v => v.map(r => r[1]));//?
|
|
40
|
-
// g;//?
|
package/src/utils/jump-idx.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { circsCache } from "./calc-circs.js";
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { max, E } = Math;
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -14,10 +14,9 @@ function binarySearchRange<T>(
|
|
|
14
14
|
|
|
15
15
|
let mid = 0;
|
|
16
16
|
while (min <= max) {
|
|
17
|
-
mid = (min + max) >>> 1
|
|
17
|
+
mid = (min + max) >>> 1;
|
|
18
18
|
const midVal = circsCache[mid].from;
|
|
19
19
|
if (midVal === v) {
|
|
20
|
-
// return [min,mid,max];
|
|
21
20
|
return mid;
|
|
22
21
|
} else if (v > midVal) {
|
|
23
22
|
min = mid + 1;
|
|
@@ -26,11 +25,26 @@ function binarySearchRange<T>(
|
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
// return [min,mid,max];
|
|
30
28
|
return mid;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
|
|
32
|
+
function jumpIdx(
|
|
33
|
+
c: number) {
|
|
34
|
+
|
|
35
|
+
let idx = binarySearchRange(c);
|
|
36
|
+
|
|
37
|
+
c = max(0, c);
|
|
38
|
+
if (idx === 0) { return 0; }
|
|
39
|
+
|
|
40
|
+
while (circsCache[idx].from === circsCache[idx - 1].from) {
|
|
41
|
+
idx--;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return idx;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
34
48
|
// const [Q,R] = [10.606601717798213, 35.531676008879735];
|
|
35
49
|
// const [A1,B1,F1] = [102.42126, 0.153169, -117.56077];
|
|
36
50
|
// const [A2,B2,C2,D2,F2] = [-0.000660087, 0.388148, 841.25744, -0.0529616, -1089.49916];
|
|
@@ -55,30 +69,21 @@ function binarySearchRange<T>(
|
|
|
55
69
|
// }
|
|
56
70
|
|
|
57
71
|
|
|
58
|
-
function jumpIdx(
|
|
59
|
-
c: number) {
|
|
60
|
-
|
|
61
|
-
let idx = binarySearchRange(c);
|
|
62
|
-
|
|
63
|
-
c = max(0, c);
|
|
64
|
-
while (idx !== 0 && circsCache[idx].from >= c) { idx--; }
|
|
65
|
-
while (idx < circsCache.length - 2 && circsCache[idx + 1].from < c) { idx++; }
|
|
66
|
-
|
|
67
|
-
return idx;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
72
|
export { jumpIdx }
|
|
72
73
|
|
|
73
74
|
|
|
74
75
|
// Quokka tests
|
|
75
|
-
//
|
|
76
|
+
// circsCache.slice(0,10);//?
|
|
77
|
+
// circsCache.slice(0,30).map(c => c.from);//?
|
|
78
|
+
// circsCache[5].from;//?
|
|
76
79
|
// circsCache[12].from;//?
|
|
77
80
|
// circsCache[15].from;//?
|
|
78
81
|
// // circsCache.length;//?
|
|
79
82
|
|
|
80
|
-
//
|
|
81
|
-
//
|
|
83
|
+
// jumpIdxOld(1.5811388300841898);//?
|
|
84
|
+
// const v = (53.08771209782213 - Math.SQRT2*24.09375)/24.09375;//?
|
|
85
|
+
// jumpIdx(v);//?
|
|
86
|
+
// circsCache[8].from;//?
|
|
82
87
|
// binarySearchRange(1.5811388300841898);//?
|
|
83
88
|
|
|
84
89
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { GlContext } from '../types/gl-context.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function freeGlContext(
|
|
5
|
+
glContext: GlContext | undefined) {
|
|
6
|
+
|
|
7
|
+
if (glContext === undefined) { return; }
|
|
8
|
+
|
|
9
|
+
const { gl, programs, textures } = glContext;
|
|
10
|
+
|
|
11
|
+
for (let key in programs) {
|
|
12
|
+
const { attributes, fragmentShader, vertexShader, uniformBlocks, program } = programs[key];
|
|
13
|
+
|
|
14
|
+
for (let key in uniformBlocks) {
|
|
15
|
+
const { buf } = uniformBlocks[key];
|
|
16
|
+
gl.deleteBuffer(buf);
|
|
17
|
+
}
|
|
18
|
+
for (let key in attributes) {
|
|
19
|
+
const { buf } = attributes[key];
|
|
20
|
+
gl.deleteBuffer(buf);
|
|
21
|
+
}
|
|
22
|
+
gl.deleteShader(fragmentShader);
|
|
23
|
+
gl.deleteShader(vertexShader);
|
|
24
|
+
gl.deleteProgram(program);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (let key in textures) {
|
|
28
|
+
const { tex } = textures[key];
|
|
29
|
+
gl.deleteTexture(tex);
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export { freeGlContext }
|
|
@@ -13,7 +13,7 @@ const cache = new WeakMap<WebGL2RenderingContext, GlContext>();
|
|
|
13
13
|
* @param gl the `WebGL2RenderingContext` context to wrap
|
|
14
14
|
* @param callback
|
|
15
15
|
*/
|
|
16
|
-
function
|
|
16
|
+
function getWebGlContext(
|
|
17
17
|
gl: WebGL2RenderingContext): GlContext {
|
|
18
18
|
|
|
19
19
|
{
|
|
@@ -23,19 +23,17 @@ function getWebGLContext<T>(
|
|
|
23
23
|
|
|
24
24
|
const programs: { [index:string]: Program } = {};
|
|
25
25
|
const textures: { [index:string]: Texture } = {};
|
|
26
|
-
const framebufferStack: WebGLFramebuffer[] = [];
|
|
27
26
|
|
|
28
27
|
gl.canvas.addEventListener('webglcontextlost', e => {
|
|
29
|
-
|
|
28
|
+
onContextLoss();
|
|
30
29
|
e.preventDefault();
|
|
31
30
|
}, false);
|
|
32
31
|
|
|
33
32
|
const glContext: GlContext = {
|
|
34
33
|
gl,
|
|
35
|
-
onContextLoss
|
|
34
|
+
onContextLoss,
|
|
36
35
|
textures,
|
|
37
|
-
programs
|
|
38
|
-
framebufferStack
|
|
36
|
+
programs
|
|
39
37
|
};
|
|
40
38
|
|
|
41
39
|
cache.set(gl, glContext);
|
|
@@ -45,10 +43,9 @@ function getWebGLContext<T>(
|
|
|
45
43
|
|
|
46
44
|
////////////////////////
|
|
47
45
|
|
|
48
|
-
function
|
|
46
|
+
function onContextLoss() {
|
|
49
47
|
deleteAllProps(programs);
|
|
50
48
|
deleteAllProps(textures);
|
|
51
|
-
framebufferStack.length = 0;
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
51
|
|
|
@@ -58,4 +55,4 @@ function deleteAllProps(o: { [key:string] : unknown }) {
|
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
|
|
61
|
-
export {
|
|
58
|
+
export { getWebGlContext }
|
|
@@ -45,7 +45,7 @@ function setAttribute(
|
|
|
45
45
|
const { gl, attributes } = program;
|
|
46
46
|
|
|
47
47
|
const attr = attributes[name] = attributes[name] ?? {
|
|
48
|
-
buf: gl.createBuffer(),
|
|
48
|
+
buf: gl.createBuffer(),
|
|
49
49
|
loc: gl.getAttribLocation(program.program, name),
|
|
50
50
|
data: null
|
|
51
51
|
}
|
|
@@ -34,10 +34,8 @@ function setUniformBlock(
|
|
|
34
34
|
|
|
35
35
|
const { buf } = uniformBlock;
|
|
36
36
|
|
|
37
|
-
gl.bufferData(gl.UNIFORM_BUFFER, buffer, gl.
|
|
38
|
-
// gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
37
|
+
gl.bufferData(gl.UNIFORM_BUFFER, buffer, gl.STATIC_DRAW);
|
|
39
38
|
gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, buf);
|
|
40
|
-
// gl.bindBufferRange(gl.UNIFORM_BUFFER, bindingPoint, ubo, 0, sizeInBytes);
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
|
|
@@ -35,11 +35,22 @@ function initProgram(
|
|
|
35
35
|
const uniformBlocks: { [index:string]: UniformBlock } = {};
|
|
36
36
|
|
|
37
37
|
const program = gl.createProgram();
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const vertexShader = compileShader(gl, vert, gl.VERTEX_SHADER);
|
|
39
|
+
const fragmentShader = compileShader(gl, frag, gl.FRAGMENT_SHADER);
|
|
40
|
+
|
|
41
|
+
gl.attachShader(program, vertexShader);
|
|
42
|
+
gl.attachShader(program, fragmentShader);
|
|
40
43
|
gl.linkProgram(program);
|
|
41
44
|
|
|
42
|
-
programs[name] = {
|
|
45
|
+
programs[name] = {
|
|
46
|
+
gl,
|
|
47
|
+
program,
|
|
48
|
+
attributes,
|
|
49
|
+
uniforms,
|
|
50
|
+
uniformBlocks,
|
|
51
|
+
vertexShader,
|
|
52
|
+
fragmentShader
|
|
53
|
+
};
|
|
43
54
|
|
|
44
55
|
return programs[name];
|
|
45
56
|
}
|
package/node/debug-shaders.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param gl
|
|
4
|
-
* @param type `gl.VERTEX_SHADER | gl.FRAGMENT_SHADER`
|
|
5
|
-
* @param shaderStr
|
|
6
|
-
*/
|
|
7
|
-
declare function debugGlsl(gl: WebGL2RenderingContext, type: typeof gl.VERTEX_SHADER | typeof gl.FRAGMENT_SHADER, shaderStr: string): void;
|
|
8
|
-
declare function debugShaders(gl: WebGL2RenderingContext): void;
|
|
9
|
-
export { debugShaders, debugGlsl };
|
package/node/types/strip.d.ts
DELETED
package/node/types/strip.js
DELETED
package/node/types/strip.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strip.js","sourceRoot":"","sources":["../../src/types/strip.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ROW_COUNT } from "../row-count.js";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param count the number of strips
|
|
5
|
-
*/
|
|
6
|
-
// TODO - remove
|
|
7
|
-
function createEmptyStrips() {
|
|
8
|
-
const strips = [];
|
|
9
|
-
for (let v = 0; v < ROW_COUNT; v++) {
|
|
10
|
-
// TODO - simplify
|
|
11
|
-
strips.push({ lineSegs: [] });
|
|
12
|
-
}
|
|
13
|
-
return strips;
|
|
14
|
-
}
|
|
15
|
-
export { createEmptyStrips };
|
|
16
|
-
//# sourceMappingURL=create-empty-strips.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-empty-strips.js","sourceRoot":"","sources":["../../src/utils/create-empty-strips.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C;;;GAGG;AACH,gBAAgB;AAChB,SAAS,iBAAiB;IACtB,MAAM,MAAM,GAAY,EAAE,CAAC;IAC3B,KAAK,IAAI,CAAC,GAAC,CAAC,EAAE,CAAC,GAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,kBAAkB;QAClB,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAGD,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const { min, max, sqrt } = Math;
|
|
2
|
-
/**
|
|
3
|
-
* Returns the minimum distance from the given line segment to the origin.
|
|
4
|
-
*/
|
|
5
|
-
function distanceSegToP(seg, p) {
|
|
6
|
-
const seg0 = seg[0];
|
|
7
|
-
const seg1 = seg[1];
|
|
8
|
-
const _x1 = seg0[0];
|
|
9
|
-
const _y1 = seg0[1];
|
|
10
|
-
const _x2 = seg1[0];
|
|
11
|
-
const _y2 = seg1[1];
|
|
12
|
-
const x = p[0];
|
|
13
|
-
const y = p[1];
|
|
14
|
-
const x1 = _x1 - x;
|
|
15
|
-
const y1 = _y1 - y;
|
|
16
|
-
const x2 = _x2 - x;
|
|
17
|
-
const y2 = _y2 - y;
|
|
18
|
-
// Vector from point 1 to point 2
|
|
19
|
-
const dx = x2 - x1;
|
|
20
|
-
const dy = y2 - y1;
|
|
21
|
-
const lengthSq = dx * dx + dy * dy;
|
|
22
|
-
// Calculate projection parameter t
|
|
23
|
-
// t represents where the closest point lies on the line segment
|
|
24
|
-
// t = 0 means closest point is at seg[0], t = 1 means closest point is at seg[1]
|
|
25
|
-
const t = max(0, min(1, -(x1 * dx + y1 * dy) / lengthSq));
|
|
26
|
-
// Find the closest point on the segment
|
|
27
|
-
const closestX = x1 + t * dx;
|
|
28
|
-
const closestY = y1 + t * dy;
|
|
29
|
-
// Return distance from origin to closest point
|
|
30
|
-
return sqrt(closestX * closestX + closestY * closestY);
|
|
31
|
-
}
|
|
32
|
-
export { distanceSegToP };
|
|
33
|
-
// Quokka tests
|
|
34
|
-
// distanceSegToOrigin([[0,1],[-1,-2]]);//?
|
|
35
|
-
//# sourceMappingURL=distance-seg-to-p.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"distance-seg-to-p.js","sourceRoot":"","sources":["../../src/utils/distance-seg-to-p.ts"],"names":[],"mappings":"AACA,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;AAGhC;;GAEG;AACH,SAAS,cAAc,CACf,GAAe,EACf,CAAW;IAEf,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAEpB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACf,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEf,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;IACnB,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;IACnB,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;IACnB,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;IAEnB,iCAAiC;IACjC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACnB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAEnB,MAAM,QAAQ,GAAG,EAAE,GAAC,EAAE,GAAG,EAAE,GAAC,EAAE,CAAC;IAE/B,mCAAmC;IACnC,gEAAgE;IAChE,iFAAiF;IACjF,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAC,EAAE,GAAG,EAAE,GAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;IAEtD,wCAAwC;IACxC,MAAM,QAAQ,GAAG,EAAE,GAAG,CAAC,GAAC,EAAE,CAAC;IAC3B,MAAM,QAAQ,GAAG,EAAE,GAAG,CAAC,GAAC,EAAE,CAAC;IAE3B,+CAA+C;IAC/C,OAAO,IAAI,CAAC,QAAQ,GAAC,QAAQ,GAAG,QAAQ,GAAC,QAAQ,CAAC,CAAC;AACvD,CAAC;AAGD,OAAO,EAAE,cAAc,EAAE,CAAA;AAEzB,eAAe;AACf,2CAA2C"}
|
package/node/webgl2.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
declare function generateIntoFramebuffer(gl: WebGL2RenderingContext, psss: (number[][])[][] | string, width: number, height: number, viewbox: [number, number, number, number], maxDistance: number, sdfExponent?: number, inclInside?: boolean, inclOutside?: boolean, x?: number, y?: number, channel?: number, resolution?: 0.5 | 1): void;
|
|
2
|
-
export { generateIntoFramebuffer };
|
package/src/types/strip.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ROW_COUNT } from "../row-count.js";
|
|
2
|
-
import { Strip } from "../types/strip.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param count the number of strips
|
|
8
|
-
*/
|
|
9
|
-
// TODO - remove
|
|
10
|
-
function createEmptyStrips() {
|
|
11
|
-
const strips: Strip[] = [];
|
|
12
|
-
for (let v=0; v<ROW_COUNT; v++) {
|
|
13
|
-
// TODO - simplify
|
|
14
|
-
strips.push({ lineSegs: [] });
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return strips;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export { createEmptyStrips }
|