mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
wip: renderer redone completely
This commit is contained in:
@@ -2,12 +2,8 @@
|
|||||||
(function (Renderer) {
|
(function (Renderer) {
|
||||||
console.log("preamble", Renderer);
|
console.log("preamble", Renderer);
|
||||||
|
|
||||||
//
|
// Sets canvas.
|
||||||
let gr;
|
|
||||||
let surface;
|
|
||||||
|
|
||||||
Renderer.setCanvas = function setCanvas(canvas, attrs) {
|
Renderer.setCanvas = function setCanvas(canvas, attrs) {
|
||||||
console.log("GL", GL);
|
|
||||||
const context = GL.createContext(canvas, attrs);
|
const context = GL.createContext(canvas, attrs);
|
||||||
if (!context) {
|
if (!context) {
|
||||||
throw new Error('Could not create a new WebGL context')
|
throw new Error('Could not create a new WebGL context')
|
||||||
@@ -18,78 +14,24 @@
|
|||||||
// to handle certain GPU corner cases.
|
// to handle certain GPU corner cases.
|
||||||
GL.currentContext.GLctx.getExtension('WEBGL_debug_renderer_info');
|
GL.currentContext.GLctx.getExtension('WEBGL_debug_renderer_info');
|
||||||
|
|
||||||
console.log("setCanvas", canvas, attrs);
|
// Initializes everything needed.
|
||||||
gr = this._MakeGrContext();
|
this._InitCanvas(canvas.width, canvas.height);
|
||||||
console.log("gr", gr);
|
|
||||||
|
|
||||||
surface = this._MakeOnScreenGLSurface(gr, canvas.width, canvas.height);
|
|
||||||
console.log("surface", surface);
|
|
||||||
if (!surface) {
|
|
||||||
throw new Error('Cannot initialize surface')
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function wasMalloced(obj) {
|
Renderer.setObjects = function setObjects(vbox, zoom, objects) {
|
||||||
return obj && obj['_ck'];
|
this._SetObjects(objects.cnt);
|
||||||
}
|
for (let index = 0; index < objects.cnt; index++) {
|
||||||
|
const object = objects.arr[index * 2 + 1];
|
||||||
function copy1dArray(arr, dest, ptr) {
|
this._SetObject(
|
||||||
if (!arr || !arr.length) return null;
|
index,
|
||||||
if (wasMalloced(arr)) {
|
object.selrect.x,
|
||||||
return arr.byteOffset;
|
object.selrect.y,
|
||||||
|
object.selrect.width,
|
||||||
|
object.selrect.height,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const bytesPerElement = Renderer[dest].BYTES_PER_ELEMENT;
|
};
|
||||||
if (!ptr) {
|
|
||||||
ptr = Renderer._malloc(arr.length * bytesPerElement);
|
|
||||||
}
|
|
||||||
Renderer[dest].set(arr, ptr / bytesPerElement);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyRectToWasm(fourFloats, ptr) {
|
|
||||||
return copy1dArray(fourFloats, 'HEAPF32', ptr || null);
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyColorToWasm(color4f, ptr) {
|
|
||||||
return copy1dArray(color4f, 'HEAPF32', ptr || null);
|
|
||||||
}
|
|
||||||
|
|
||||||
Renderer.drawCanvas = function drawCanvas(vbox, zoom, objects) {
|
Renderer.drawCanvas = function drawCanvas(vbox, zoom, objects) {
|
||||||
console.log("vbox", vbox);
|
this._DrawCanvas(vbox.x, vbox.y, zoom);
|
||||||
console.log("zoom", zoom);
|
|
||||||
if (!surface) {
|
|
||||||
throw new Error('Surface uninitialized');
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("renderer", Renderer);
|
|
||||||
console.log("surface", surface);
|
|
||||||
|
|
||||||
// Esto es una ÑAPA terrible, no me gusta.
|
|
||||||
if (!Renderer.Paint.prototype.setColor) {
|
|
||||||
Renderer.Paint.prototype.setColor = function(color4f, colorSpace = null) {
|
|
||||||
const cPtr = copyColorToWasm(color4f);
|
|
||||||
this._setColor(cPtr, colorSpace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const paint = new Renderer.Paint();
|
|
||||||
paint.setColor(Float32Array.of(1.0, 0, 0, 1.0));
|
|
||||||
paint.setStyle(Renderer.PaintStyle.Fill);
|
|
||||||
paint.setAntiAlias(true);
|
|
||||||
console.log("paint", paint);
|
|
||||||
|
|
||||||
const canvas = surface._getCanvas();
|
|
||||||
console.log("canvas", canvas);
|
|
||||||
|
|
||||||
const cPtr = copyColorToWasm(Float32Array.of(0.0, 0.0, 0.0, 1.0))
|
|
||||||
canvas._clear(cPtr);
|
|
||||||
console.log("canvas cleared");
|
|
||||||
|
|
||||||
for (const { val: object } of objects) {
|
|
||||||
console.log("object", object);
|
|
||||||
const rr = Float32Array.of(object.selrect.x, object.selrect.y, object.selrect.width, object.selrect.height);
|
|
||||||
|
|
||||||
const rPtr = copyRectToWasm(rr);
|
|
||||||
canvas._drawRect(rPtr, paint);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -53,4 +53,7 @@
|
|||||||
(cond
|
(cond
|
||||||
;; Rust
|
;; Rust
|
||||||
(contains? cf/flags :render-v2-rs)
|
(contains? cf/flags :render-v2-rs)
|
||||||
(render-v2-rs/set-objects vbox zoom base-objects)))
|
(render-v2-rs/set-objects vbox zoom base-objects)
|
||||||
|
|
||||||
|
(contains? cf/flags :render-v2-cpp)
|
||||||
|
(render-v2-cpp/set-objects vbox zoom base-objects)))
|
||||||
|
|||||||
@@ -15,21 +15,22 @@
|
|||||||
|
|
||||||
(defn set-canvas
|
(defn set-canvas
|
||||||
[canvas vbox zoom base-objects]
|
[canvas vbox zoom base-objects]
|
||||||
(js/console.log "setting canvas" canvas)
|
|
||||||
(.setCanvas ^js internal-module canvas #js {:antialias false})
|
(.setCanvas ^js internal-module canvas #js {:antialias false})
|
||||||
(js/console.log "canvas set")
|
(.setObjects ^js internal-module vbox zoom base-objects)
|
||||||
(.drawCanvas ^js internal-module vbox zoom base-objects))
|
(.drawCanvas ^js internal-module vbox zoom base-objects))
|
||||||
|
|
||||||
(defn draw-canvas
|
(defn draw-canvas
|
||||||
[vbox zoom base-objects]
|
[vbox zoom base-objects]
|
||||||
(js/console.log "draw canvas" vbox zoom base-objects)
|
|
||||||
(.drawCanvas ^js internal-module vbox zoom base-objects))
|
(.drawCanvas ^js internal-module vbox zoom base-objects))
|
||||||
|
|
||||||
|
(defn set-objects
|
||||||
|
[vbox zoom base-objects]
|
||||||
|
(.setObjects ^js internal-module vbox zoom base-objects))
|
||||||
|
|
||||||
(defn on-init
|
(defn on-init
|
||||||
[module']
|
[module']
|
||||||
(set! internal-module module')
|
(set! internal-module module')
|
||||||
(js/console.log "internal-module" internal-module module')
|
(js/console.log "internal-module" internal-module module'))
|
||||||
(js/console.log "add 2 + 2" (._add ^js module' 2 2)))
|
|
||||||
|
|
||||||
(defn init
|
(defn init
|
||||||
[]
|
[]
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user