initial implementation of WebGL-based brush renderer
This commit is contained in:
parent
b4c3260f49
commit
bb55e23979
14 changed files with 385 additions and 247 deletions
|
@ -1,11 +1,6 @@
|
|||
let panicImpl;
|
||||
let logImpl, log2Impl;
|
||||
let canvasBeginImpl,
|
||||
canvasLineImpl,
|
||||
canvasRectangleImpl,
|
||||
canvasCircleImpl,
|
||||
canvasFillImpl,
|
||||
canvasStrokeImpl;
|
||||
let currentBrushRenderer;
|
||||
|
||||
function allocCheck(p) {
|
||||
if (p == 0) throw new Error("out of memory");
|
||||
|
@ -47,14 +42,8 @@ let [hakuWasm, haku2Wasm] = await Promise.all([
|
|||
__haku2_log_info: makeLogFunction2("info"),
|
||||
__haku2_log_debug: makeLogFunction2("debug"),
|
||||
|
||||
__haku2_canvas_begin: (c) => canvasBeginImpl(c),
|
||||
__haku2_canvas_line: (c, x1, y1, x2, y2) => canvasLineImpl(c, x1, y1, x2, y2),
|
||||
__haku2_canvas_rectangle: (c, x, y, width, height) =>
|
||||
canvasRectangleImpl(c, x, y, width, height),
|
||||
__haku2_canvas_circle: (c, x, y, r) => canvasCircleImpl(c, x, y, r),
|
||||
__haku2_canvas_fill: (c, r, g, b, a) => canvasFillImpl(c, r, g, b, a),
|
||||
__haku2_canvas_stroke: (c, r, g, b, a, thickness) =>
|
||||
canvasStrokeImpl(c, r, g, b, a, thickness),
|
||||
__haku2_canvas_stroke: (c, r, g, b, a, thickness, x1, y1, x2, y2) =>
|
||||
currentBrushRenderer.stroke(c, r, g, b, a, thickness, x1, y1, x2, y2),
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
@ -151,13 +140,6 @@ log2Impl = (level, pScope, scopeLen, pMsg, len) => {
|
|||
);
|
||||
};
|
||||
|
||||
canvasBeginImpl = w.haku_pixmap_begin;
|
||||
canvasLineImpl = w.haku_pixmap_line;
|
||||
canvasRectangleImpl = w.haku_pixmap_rectangle;
|
||||
canvasCircleImpl = w.haku_pixmap_circle;
|
||||
canvasFillImpl = w.haku_pixmap_fill;
|
||||
canvasStrokeImpl = w.haku_pixmap_stroke;
|
||||
|
||||
w.haku_init_logging();
|
||||
|
||||
export const ContKind = {
|
||||
|
@ -386,9 +368,12 @@ export class Haku {
|
|||
else return ContKind.Scribble;
|
||||
}
|
||||
|
||||
contScribble(pixmap, translationX, translationY) {
|
||||
w.haku_pixmap_set_translation(pixmap.ptr, translationX, translationY);
|
||||
let ok = w2.haku2_render(this.#pVm2, pixmap.ptr, this.#renderMaxDepth);
|
||||
contScribble(renderer, canvas) {
|
||||
console.assert(currentBrushRenderer == null);
|
||||
currentBrushRenderer = renderer;
|
||||
let ok = w2.haku2_render(this.#pVm2, canvas, this.#renderMaxDepth);
|
||||
currentBrushRenderer = null;
|
||||
|
||||
if (!ok) {
|
||||
return this.#exceptionResult();
|
||||
} else {
|
||||
|
@ -415,8 +400,8 @@ export class Haku {
|
|||
while (true) {
|
||||
switch (this.expectedContKind()) {
|
||||
case ContKind.Scribble:
|
||||
result = await runScribble((pixmap, translationX, translationY) => {
|
||||
return this.contScribble(pixmap, translationX, translationY);
|
||||
result = await runScribble((renderer, canvas, translationX, translationY) => {
|
||||
return this.contScribble(renderer, canvas, translationX, translationY);
|
||||
});
|
||||
return result;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue