Archived
Speicher: kompaktes 12-Byte-Linienvertex (nativ), grobere Rundkappen bei duennen Strichen
This commit is contained in:
1 parent
470547071f
commit
072dd4ad92
5 files changed
+107
-11
No files matched your search
@@ -53,7 +53,8 @@ describe('compilePrimitivesToGpu: zusammenhängende Linien-Segmente', () => {
|
||||
it('verkettet NICHT bei unterschiedlichem Stil', () => {
|
||||
const single = lineIndexCount([seg(0, 0, 1, 0, 'a')]);
|
||||
const thick = { ...seg(1, 0, 2, 0, 'a'), weightMm: 0.5 } as Primitive;
|
||||
expect(lineIndexCount([seg(0, 0, 1, 0, 'a'), thick])).toBe(2 * single);
|
||||
// Dicke Striche bekommen mehr Kappen-Schritte als dünne → je einzeln zählen.
|
||||
expect(lineIndexCount([seg(0, 0, 1, 0, 'a'), thick])).toBe(single + lineIndexCount([thick]));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -182,3 +183,28 @@ describe('computeOrthoMatrix', () => {
|
||||
expect([...a].every((v, i) => v === b[i])).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('compilePrimitivesToGpu: kompaktes Linien-Vertex-Format (nativ)', () => {
|
||||
it('liefert 3 Wörter je Vertex statt 6 Floats', () => {
|
||||
const uploaded: ArrayBufferView[] = [];
|
||||
const mk = (packed: boolean) =>
|
||||
({
|
||||
ARRAY_BUFFER: 1,
|
||||
ELEMENT_ARRAY_BUFFER: 2,
|
||||
STATIC_DRAW: 3,
|
||||
packedLineVertices: packed,
|
||||
createBuffer: () => ({}),
|
||||
bindBuffer: () => {},
|
||||
bufferData: (_t: number, d: ArrayBufferView) => void uploaded.push(d),
|
||||
deleteBuffer: () => {},
|
||||
}) as any;
|
||||
const p = [seg(0, 0, 1, 0, 'a')];
|
||||
uploaded.length = 0;
|
||||
compilePrimitivesToGpu(mk(false), p, 0);
|
||||
const fullBytes = uploaded.find((u) => u.byteLength % 24 === 0 && u.byteLength > 0)!.byteLength;
|
||||
uploaded.length = 0;
|
||||
compilePrimitivesToGpu(mk(true), p, 0);
|
||||
const packedBytes = uploaded.find((u) => u.byteLength % 12 === 0 && u.byteLength > 0)!.byteLength;
|
||||
expect(packedBytes).toBe(fullBytes / 2);
|
||||
});
|
||||
});
|
||||
@@ -277,8 +277,19 @@ export function compilePrimitivesToGpu(
|
||||
const fillIdx = new GrowBuffer((n) => new Uint32Array(n));
|
||||
const fillBatches: GpuGeometry['fill']['batches'] = [];
|
||||
|
||||
// Linien-Puffer (interleaved [x,y, nx,ny, side]).
|
||||
// Linien-Puffer: interleaved [x,y, nx,ny, side, miter] (6 Float32) — oder, wenn
|
||||
// der Aufrufer es verlangt (nativer Renderer), kompakt 3 Wörter je Vertex:
|
||||
// [x, y (float32-Bits), nx|ny|side|miter als 4 × snorm8].
|
||||
const packedLines = gl.packedLineVertices === true;
|
||||
const lineVerts = new GrowBuffer((n) => new Float32Array(n));
|
||||
const lineVertsPacked = new GrowBuffer((n) => new Uint32Array(n));
|
||||
const bitsF32 = new Float32Array(1);
|
||||
const bitsU32 = new Uint32Array(bitsF32.buffer);
|
||||
const f2u = (v: number): number => {
|
||||
bitsF32[0] = v;
|
||||
return bitsU32[0];
|
||||
};
|
||||
const snorm8 = (v: number): number => Math.round(Math.max(-1, Math.min(1, v)) * 127) & 0xff;
|
||||
const lineIdx = new GrowBuffer((n) => new Uint32Array(n));
|
||||
|
||||
// LOKALER URSPRUNG dieser Geometrie: alle Vertices werden relativ zum ersten
|
||||
@@ -384,10 +395,18 @@ export function compilePrimitivesToGpu(
|
||||
const leftNormal = (d: Vec2): Vec2 => ({ x: -d.y, y: d.x });
|
||||
|
||||
const startIdxLen = lineIdx.length;
|
||||
const vBase = lineVerts.length / 6;
|
||||
const vBase = packedLines ? lineVertsPacked.length / 3 : lineVerts.length / 6;
|
||||
let vcount = 0;
|
||||
const pushVert = (p: Vec2, nx: number, ny: number, side: number): number => {
|
||||
lineVerts.push6(p.x, p.y, nx, ny, side, 1);
|
||||
if (packedLines) {
|
||||
lineVertsPacked.push3(
|
||||
f2u(p.x),
|
||||
f2u(p.y),
|
||||
(snorm8(nx) | (snorm8(ny) << 8) | (snorm8(side) << 16) | (127 << 24)) >>> 0,
|
||||
);
|
||||
} else {
|
||||
lineVerts.push6(p.x, p.y, nx, ny, side, 1);
|
||||
}
|
||||
vcount++;
|
||||
return vBase + vcount - 1;
|
||||
};
|
||||
@@ -415,7 +434,10 @@ export function compilePrimitivesToGpu(
|
||||
// Randpunkten (voller Versatz in Richtung (cosθ,sinθ)).
|
||||
const addFanArc = (p: Vec2, aFrom: number, aTo: number) => {
|
||||
const delta = aTo - aFrom;
|
||||
const steps = Math.max(1, Math.ceil(Math.abs(delta) / (Math.PI / 10)));
|
||||
// Dünne Striche (≤ 0.35 mm, nur wenige Pixel breit): grobe Rundung genügt
|
||||
// und spart ~3× Vertices je Kappe/Ecke (Speicher bei Kataster-Importen).
|
||||
const stepAngle = strokeMm <= 0.35 ? Math.PI / 3 : Math.PI / 10;
|
||||
const steps = Math.max(1, Math.ceil(Math.abs(delta) / stepAngle));
|
||||
const iCenter = pushVert(p, 1, 0, 0);
|
||||
let prev = pushVert(p, Math.cos(aFrom), Math.sin(aFrom), 1);
|
||||
for (let s = 1; s <= steps; s++) {
|
||||
@@ -749,7 +771,7 @@ export function compilePrimitivesToGpu(
|
||||
}
|
||||
|
||||
// Puffer hochladen.
|
||||
const uploadArray = (data: GrowBuffer<Float32Array>): WebGLBuffer | null => {
|
||||
const uploadArray = (data: GrowBuffer<Float32Array> | GrowBuffer<Uint32Array>): WebGLBuffer | null => {
|
||||
if (!data.length) return null;
|
||||
const buf = gl.createBuffer();
|
||||
if (!buf) return null;
|
||||
@@ -773,7 +795,7 @@ export function compilePrimitivesToGpu(
|
||||
batches: fillBatches,
|
||||
},
|
||||
line: {
|
||||
vertexBuffer: uploadArray(lineVerts),
|
||||
vertexBuffer: uploadArray(packedLines ? lineVertsPacked : lineVerts),
|
||||
indexBuffer: uploadIndex(lineIdx),
|
||||
batches: lineBatches,
|
||||
},
|
||||
|
||||
@@ -117,6 +117,12 @@ export interface ViewBox {
|
||||
* Renderer (nativeGl.ts) liefert eine Attrappe, die die Bytes an Rust schickt.
|
||||
*/
|
||||
export interface BufferGl {
|
||||
/**
|
||||
* Linien-Vertices kompakt (12 statt 24 Byte): [x,y als float32, dann 4 Bytes
|
||||
* snorm8 = nx, ny, side, miter]. Nur der native Renderer (chunks.rs) liest das;
|
||||
* der WebGL-Pfad bleibt beim 6-Float-Layout.
|
||||
*/
|
||||
readonly packedLineVertices?: boolean;
|
||||
readonly ARRAY_BUFFER: number;
|
||||
readonly ELEMENT_ARRAY_BUFFER: number;
|
||||
readonly STATIC_DRAW: number;
|
||||
|
||||
@@ -32,6 +32,7 @@ export class NativeGl implements BufferGl {
|
||||
readonly ARRAY_BUFFER = 0x8892;
|
||||
readonly ELEMENT_ARRAY_BUFFER = 0x8893;
|
||||
readonly STATIC_DRAW = 0x88e4;
|
||||
readonly packedLineVertices = true;
|
||||
|
||||
private nextId = 1;
|
||||
private bound: NativeBuffer | null = null;
|
||||
|
||||
Reference in new issue
Block a user