mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 02:28:18 -05:00
wip: renderer redone completely
This commit is contained in:
parent
39b627cb1a
commit
cf8b62f1a8
5 changed files with 1001 additions and 4119 deletions
|
@ -2,12 +2,8 @@
|
|||
(function (Renderer) {
|
||||
console.log("preamble", Renderer);
|
||||
|
||||
//
|
||||
let gr;
|
||||
let surface;
|
||||
|
||||
// Sets canvas.
|
||||
Renderer.setCanvas = function setCanvas(canvas, attrs) {
|
||||
console.log("GL", GL);
|
||||
const context = GL.createContext(canvas, attrs);
|
||||
if (!context) {
|
||||
throw new Error('Could not create a new WebGL context')
|
||||
|
@ -18,78 +14,24 @@
|
|||
// to handle certain GPU corner cases.
|
||||
GL.currentContext.GLctx.getExtension('WEBGL_debug_renderer_info');
|
||||
|
||||
console.log("setCanvas", canvas, attrs);
|
||||
gr = this._MakeGrContext();
|
||||
console.log("gr", gr);
|
||||
|
||||
surface = this._MakeOnScreenGLSurface(gr, canvas.width, canvas.height);
|
||||
console.log("surface", surface);
|
||||
if (!surface) {
|
||||
throw new Error('Cannot initialize surface')
|
||||
}
|
||||
// Initializes everything needed.
|
||||
this._InitCanvas(canvas.width, canvas.height);
|
||||
};
|
||||
|
||||
function wasMalloced(obj) {
|
||||
return obj && obj['_ck'];
|
||||
}
|
||||
|
||||
function copy1dArray(arr, dest, ptr) {
|
||||
if (!arr || !arr.length) return null;
|
||||
if (wasMalloced(arr)) {
|
||||
return arr.byteOffset;
|
||||
Renderer.setObjects = function setObjects(vbox, zoom, objects) {
|
||||
this._SetObjects(objects.cnt);
|
||||
for (let index = 0; index < objects.cnt; index++) {
|
||||
const object = objects.arr[index * 2 + 1];
|
||||
this._SetObject(
|
||||
index,
|
||||
object.selrect.x,
|
||||
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) {
|
||||
console.log("vbox", vbox);
|
||||
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);
|
||||
}
|
||||
this._DrawCanvas(vbox.x, vbox.y, zoom);
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -53,4 +53,7 @@
|
|||
(cond
|
||||
;; Rust
|
||||
(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
|
||||
[canvas vbox zoom base-objects]
|
||||
(js/console.log "setting canvas" canvas)
|
||||
(.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))
|
||||
|
||||
(defn draw-canvas
|
||||
[vbox zoom base-objects]
|
||||
(js/console.log "draw canvas" 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
|
||||
[module']
|
||||
(set! internal-module module')
|
||||
(js/console.log "internal-module" internal-module module')
|
||||
(js/console.log "add 2 + 2" (._add ^js module' 2 2)))
|
||||
(js/console.log "internal-module" internal-module module'))
|
||||
|
||||
(defn init
|
||||
[]
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue