Skip to content

Commit 09eb345

Browse files
authored
Merge pull request #7588 from processing/webgl-matrices
Add back WebGL matrices via getters
2 parents 63746a6 + f712984 commit 09eb345

File tree

2 files changed

+102
-36
lines changed

2 files changed

+102
-36
lines changed

src/webgl/p5.RendererGL.js

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -550,41 +550,6 @@ class RendererGL extends Renderer {
550550
super.endShape(mode, count);
551551
}
552552

553-
legacyEndShape(
554-
mode,
555-
isCurve,
556-
isBezier,
557-
isQuadratic,
558-
isContour,
559-
shapeKind,
560-
count = 1
561-
) {
562-
this.shapeBuilder.endShape(
563-
mode,
564-
isCurve,
565-
isBezier,
566-
isQuadratic,
567-
isContour,
568-
shapeKind
569-
);
570-
571-
if (this.geometryBuilder) {
572-
this.geometryBuilder.addImmediate(
573-
this.shapeBuilder.geometry,
574-
this.shapeBuilder.shapeMode
575-
);
576-
} else if (this.states.fillColor || this.states.strokeColor) {
577-
this._drawGeometry(this.shapeBuilder.geometry, {
578-
mode: this.shapeBuilder.shapeMode,
579-
count,
580-
});
581-
}
582-
}
583-
584-
legacyVertex(...args) {
585-
this.shapeBuilder.vertex(...args);
586-
}
587-
588553
vertexProperty(...args) {
589554
this.currentShape.vertexProperty(...args);
590555
}
@@ -1051,6 +1016,27 @@ class RendererGL extends Renderer {
10511016
this.clear(..._col._getRGBA());
10521017
}
10531018

1019+
//////////////////////////////////////////////
1020+
// Positioning
1021+
//////////////////////////////////////////////
1022+
1023+
get uModelMatrix() {
1024+
return this.states.uModelMatrix;
1025+
}
1026+
1027+
get uViewMatrix() {
1028+
return this.states.uViewMatrix;
1029+
}
1030+
1031+
get uPMatrix() {
1032+
return this.states.uPMatrix;
1033+
}
1034+
1035+
get uMVMatrix() {
1036+
const m = this.uModelMatrix.copy();
1037+
m.mult(this.uViewMatrix);
1038+
return m;
1039+
}
10541040

10551041
/**
10561042
* Get a matrix from world-space to screen-space

test/unit/webgl/p5.RendererGL.js

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2702,5 +2702,85 @@ suite('p5.RendererGL', function() {
27022702
expect(logs.join('\n')).to.match(/One of the geometries has a custom vertex property 'aCustom' with fewer values than vertices./);
27032703
}
27042704
);
2705-
})
2705+
});
2706+
2707+
suite('Matrix getters', function() {
2708+
test('uModelMatrix', function() {
2709+
p5.registerAddon(function (p5, fn) {
2710+
fn.checkModelMatrix = function() {
2711+
assert.deepEqual(
2712+
[...this._renderer.uModelMatrix.mat4],
2713+
[
2714+
1, 0, 0, 0,
2715+
0, 1, 0, 0,
2716+
0, 0, 1, 0,
2717+
5, 0, 0, 1
2718+
]
2719+
);
2720+
}
2721+
});
2722+
myp5.createCanvas(50, 50, myp5.WEBGL);
2723+
myp5.translate(5, 0);
2724+
myp5.camera(0, 0, 500, 0, 0, 0);
2725+
myp5.checkModelMatrix();
2726+
});
2727+
2728+
test('uViewMatrix', function() {
2729+
p5.registerAddon(function (p5, fn) {
2730+
fn.checkViewMatrix = function() {
2731+
assert.deepEqual(
2732+
[...this._renderer.uViewMatrix.mat4],
2733+
[
2734+
1, 0, 0, 0,
2735+
0, 1, 0, 0,
2736+
0, 0, 1, 0,
2737+
0, 0, -500, 1
2738+
]
2739+
);
2740+
}
2741+
});
2742+
myp5.createCanvas(50, 50, myp5.WEBGL);
2743+
myp5.translate(5, 0);
2744+
myp5.camera(0, 0, 500, 0, 0, 0);
2745+
myp5.checkViewMatrix();
2746+
});
2747+
2748+
test('uMVMatrix', function() {
2749+
p5.registerAddon(function (p5, fn) {
2750+
fn.checkMVMatrix = function() {
2751+
assert.deepEqual(
2752+
[...this._renderer.uMVMatrix.mat4],
2753+
[
2754+
1, 0, 0, 0,
2755+
0, 1, 0, 0,
2756+
0, 0, 1, 0,
2757+
5, 0, -500, 1
2758+
]
2759+
);
2760+
}
2761+
});
2762+
myp5.createCanvas(50, 50, myp5.WEBGL);
2763+
myp5.translate(5, 0);
2764+
myp5.camera(0, 0, 500, 0, 0, 0);
2765+
myp5.checkMVMatrix();
2766+
});
2767+
2768+
test('uPMatrix', function() {
2769+
p5.registerAddon(function (p5, fn) {
2770+
fn.checkPMatrix = function() {
2771+
assert.deepEqual(
2772+
[...this._renderer.uPMatrix.mat4],
2773+
[
2774+
32, 0, 0, 0,
2775+
0, -32, 0, 0,
2776+
0, 0, -1.0202020406723022, -1,
2777+
0, 0, -161.6161651611328, 0
2778+
]
2779+
);
2780+
}
2781+
});
2782+
myp5.createCanvas(50, 50, myp5.WEBGL);
2783+
myp5.checkPMatrix();
2784+
});
2785+
});
27062786
});

0 commit comments

Comments
 (0)