native2d Stufe 2: Plan-Ansicht rendert in eingebetteter Metal-Flaeche (Chunk-Upload binaer, Frame = nur Ausschnitt); altes Diagnose-Fenster entfernt
This commit is contained in:
1 parent
aad15fa8c0
commit
ef3dfd8a6b
9 files changed
+412
-41
No files matched your search
@@ -25,7 +25,7 @@
|
||||
import type { Primitive, UnderlayGroup } from '../generatePlan';
|
||||
import type { Drawing2D } from '../../model/types';
|
||||
import { compilePrimitivesToGpu } from './glPlanCompile';
|
||||
import type { GpuGeometry } from './glPlanTypes';
|
||||
import type { BufferGl, GpuGeometry } from './glPlanTypes';
|
||||
|
||||
/** Ziel: im Mittel so viele Elemente (drawingIds) je Chunk = 2^BITS. */
|
||||
const BOUNDARY_BITS = 8;
|
||||
@@ -85,7 +85,7 @@ interface Chunk {
|
||||
geometry: GpuGeometry;
|
||||
}
|
||||
|
||||
function disposeGeometry(gl: WebGL2RenderingContext, g: GpuGeometry): void {
|
||||
function disposeGeometry(gl: BufferGl, g: GpuGeometry): void {
|
||||
gl.deleteBuffer(g.fill.positionBuffer);
|
||||
gl.deleteBuffer(g.fill.indexBuffer);
|
||||
gl.deleteBuffer(g.line.vertexBuffer);
|
||||
@@ -141,7 +141,7 @@ class UnderlayChunkCache {
|
||||
private previous: UnderChunk[] = [];
|
||||
recompiled = 0;
|
||||
|
||||
constructor(private readonly gl: WebGL2RenderingContext) {}
|
||||
constructor(private readonly gl: BufferGl) {}
|
||||
|
||||
/** Liefert je Gruppe die Geometrien ihrer Chunks (in Reihenfolge). */
|
||||
update(groups: readonly UnderlayGroup[]): GpuGeometry[][] {
|
||||
@@ -216,7 +216,7 @@ export class GpuChunkCache {
|
||||
|
||||
private readonly under: UnderlayChunkCache;
|
||||
|
||||
constructor(private readonly gl: WebGL2RenderingContext) {
|
||||
constructor(private readonly gl: BufferGl) {
|
||||
this.under = new UnderlayChunkCache(gl);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import type { Primitive } from '../generatePlan';
|
||||
import type { Vec2 } from '../../model/types';
|
||||
import type { GpuGeometry, Rgba } from './glPlanTypes';
|
||||
import type { BufferGl, GpuGeometry, Rgba } from './glPlanTypes';
|
||||
import { applyDashRuns, buildHatchRuns, zigzagPoints, motifPoints, DASH_MM_TO_M } from './glPlanHatch';
|
||||
|
||||
const PX_PER_M = 90;
|
||||
@@ -263,7 +263,7 @@ function dimFill(color: Rgba, greyed: boolean | undefined, opacity?: number): Rg
|
||||
* bildschirmkonstante Striche). Text/Bögen bleiben im SVG-Overlay.
|
||||
*/
|
||||
export function compilePrimitivesToGpu(
|
||||
gl: WebGL2RenderingContext,
|
||||
gl: BufferGl,
|
||||
primitives: Primitive[],
|
||||
// Bildschirm-Massstab (Geräte-px je Modell-Meter) beim aktuellen Zoom. Steuert
|
||||
// NUR die adaptive Bogen-Tessellierung (siehe 'arc'-Zweig): je stärker
|
||||
|
||||
@@ -110,3 +110,18 @@ export interface ViewBox {
|
||||
w: number;
|
||||
h: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Der Teil des GL-Kontexts, den Kompilierung + Chunk-Cache wirklich brauchen:
|
||||
* Puffer anlegen/befüllen/freigeben. WebGL2 erfüllt das direkt; der native
|
||||
* Renderer (nativeGl.ts) liefert eine Attrappe, die die Bytes an Rust schickt.
|
||||
*/
|
||||
export interface BufferGl {
|
||||
readonly ARRAY_BUFFER: number;
|
||||
readonly ELEMENT_ARRAY_BUFFER: number;
|
||||
readonly STATIC_DRAW: number;
|
||||
createBuffer(): WebGLBuffer | null;
|
||||
bindBuffer(target: number, buffer: WebGLBuffer | null): void;
|
||||
bufferData(target: number, data: ArrayBufferView, usage: number): void;
|
||||
deleteBuffer(buffer: WebGLBuffer | null): void;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Puffer-Attrappe für den NATIVEN Plan-Renderer (macOS, src-tauri/src/native_embed.rs).
|
||||
*
|
||||
* Kompilierung (`compilePrimitivesToGpu`) und Chunk-Cache (`GpuChunkCache`) laufen
|
||||
* unverändert in TypeScript und sprechen nur diese vier Puffer-Funktionen an
|
||||
* (`BufferGl`). Statt eines GL-Kontexts liegen die Bytes danach in Rust: jeder
|
||||
* Puffer geht EINMAL als Rohdaten über die Tauri-Schnittstelle (kein JSON); pro
|
||||
* Frame wandert danach nur noch der Ausschnitt.
|
||||
*/
|
||||
|
||||
import type { BufferGl, GpuGeometry } from './glPlanTypes';
|
||||
|
||||
export type NativeInvoke = (cmd: string, args?: unknown, options?: unknown) => Promise<unknown>;
|
||||
|
||||
interface NativeBuffer {
|
||||
id: number;
|
||||
}
|
||||
|
||||
/** Layout-Eintrag einer Geometrie (Spiegel von `ChunkGeom` in render2d/chunks.rs). */
|
||||
export interface NativeChunkLayout {
|
||||
fill_pos: number | null;
|
||||
fill_idx: number | null;
|
||||
fill_batches: { start: number; count: number; color: number[] }[];
|
||||
line_vtx: number | null;
|
||||
line_idx: number | null;
|
||||
line_batches: { start: number; count: number; color: number[]; stroke_mm: number; screen_px: boolean }[];
|
||||
origin: [number, number];
|
||||
greyed: boolean;
|
||||
}
|
||||
|
||||
export class NativeGl implements BufferGl {
|
||||
readonly ARRAY_BUFFER = 0x8892;
|
||||
readonly ELEMENT_ARRAY_BUFFER = 0x8893;
|
||||
readonly STATIC_DRAW = 0x88e4;
|
||||
|
||||
private nextId = 1;
|
||||
private bound: NativeBuffer | null = null;
|
||||
private pendingDelete: number[] = [];
|
||||
|
||||
constructor(private readonly invoke: NativeInvoke) {}
|
||||
|
||||
createBuffer(): WebGLBuffer {
|
||||
return { id: this.nextId++ } as unknown as WebGLBuffer;
|
||||
}
|
||||
|
||||
bindBuffer(_target: number, buffer: WebGLBuffer | null): void {
|
||||
this.bound = buffer as unknown as NativeBuffer | null;
|
||||
}
|
||||
|
||||
bufferData(_target: number, data: ArrayBufferView, _usage: number): void {
|
||||
const buf = this.bound;
|
||||
if (!buf) return;
|
||||
// KOPIE: die Quelle ist ein wiederverwendeter Wachstumspuffer, der Aufruf
|
||||
// serialisiert asynchron.
|
||||
const bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
||||
void this.invoke('native2d_upload', bytes, { headers: { 'x-buf-id': String(buf.id) } }).catch((e) =>
|
||||
console.debug('native2d_upload fehlgeschlagen', e),
|
||||
);
|
||||
}
|
||||
|
||||
deleteBuffer(buffer: WebGLBuffer | null): void {
|
||||
if (buffer) this.pendingDelete.push((buffer as unknown as NativeBuffer).id);
|
||||
}
|
||||
|
||||
/** Geometrien (in Zeichenreihenfolge) → Layout für Rust, plus freizugebende Puffer. */
|
||||
takeLayout(geometries: readonly GpuGeometry[]): { layout: NativeChunkLayout[]; delete: number[] } {
|
||||
const id = (b: WebGLBuffer | null): number | null => (b ? (b as unknown as NativeBuffer).id : null);
|
||||
const layout = geometries.map((g) => ({
|
||||
fill_pos: id(g.fill.positionBuffer),
|
||||
fill_idx: id(g.fill.indexBuffer),
|
||||
fill_batches: g.fill.batches.map((b) => ({ start: b.startIndex, count: b.indexCount, color: b.color })),
|
||||
line_vtx: id(g.line.vertexBuffer),
|
||||
line_idx: id(g.line.indexBuffer),
|
||||
line_batches: g.line.batches.map((b) => ({
|
||||
start: b.startIndex,
|
||||
count: b.indexCount,
|
||||
color: b.color,
|
||||
stroke_mm: b.strokeMm,
|
||||
screen_px: !!b.screenPx,
|
||||
})),
|
||||
origin: [g.origin?.x ?? 0, g.origin?.y ?? 0] as [number, number],
|
||||
greyed: !!g.greyed,
|
||||
}));
|
||||
const del = this.pendingDelete;
|
||||
this.pendingDelete = [];
|
||||
return { layout, delete: del };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user