Skip to content

Commit

Permalink
Merge pull request #6366 from davepagurek/fix/texture-mode-image
Browse files Browse the repository at this point in the history
Fix textureMode(IMAGE) + beginShape(TESS)
  • Loading branch information
Qianqianye committed Aug 20, 2023
2 parents d7ccce3 + 9ec2d09 commit ad5c51a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/webgl/p5.RendererGL.Immediate.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,13 @@ p5.RendererGL.prototype.vertex = function(x, y) {
lineVertexColor[3]
);

if (this.textureMode === constants.IMAGE) {
if (this.textureMode === constants.IMAGE && !this.isProcessingVertices) {
if (this._tex !== null) {
if (this._tex.width > 0 && this._tex.height > 0) {
u /= this._tex.width;
v /= this._tex.height;
}
} else if (
!this.isProcessingVertices &&
this._tex === null &&
arguments.length >= 4
) {
Expand Down
25 changes: 25 additions & 0 deletions test/unit/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,31 @@ suite('p5.RendererGL', function() {
done();
});

test('TESS does not affect texture coordinates', function(done) {
var renderer = myp5.createCanvas(10, 10, myp5.WEBGL);
const texture = new p5.Image(25, 25);

myp5.textureMode(myp5.IMAGE);
myp5.texture(texture);
renderer.beginShape(myp5.TESS);
myp5.noFill();
renderer.vertex(-10, -10, 0, 0);
renderer.vertex(10, -10, 25, 0);
renderer.vertex(10, 10, 25, 25);
renderer.vertex(-10, 10, 0, 25);
renderer.endShape(myp5.CLOSE);

// UVs are correctly translated through tessy
assert.deepEqual(renderer.immediateMode.geometry.uvs, [
0, 0,
1, 0,
1, 1,
0, 1
]);

done();
});

test('TESS interpolates vertex data at intersections', function(done) {
var renderer = myp5.createCanvas(10, 10, myp5.WEBGL);

Expand Down

0 comments on commit ad5c51a

Please sign in to comment.