Skip to content

Commit

Permalink
Register enable/disable flag test
Browse files Browse the repository at this point in the history
I decided to use a global flag to manage the enabled/disabled state of the registers used to store shader attributes.
This value will be true if the geometry supplies a value, false if it does not.
Therefore, I prepared a geometry with aTexCoord and a geometry without it, and tested whether the value was properly switched.
  • Loading branch information
inaridarkfox4231 authored Jan 25, 2023
1 parent 783e765 commit c1a9c69
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/unit/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,44 @@ suite('p5.RendererGL', function() {
});
});

suite('Test for register availability', function() {
test('register enable/disable flag test', function(done) {
const renderer = myp5.createCanvas(16, 16, myp5.WEBGL);

// geometry without aTexCoord.
const myGeom = new p5.Geometry(1, 1, function() {
this.gid = 'registerEnabledTest';
this.vertices.push(createVector(-8, -8));
this.vertices.push(createVector(8, -8));
this.vertices.push(createVector(8, 8));
this.vertices.push(createVector(-8, 8));
this.faces.push([0, 1, 2]);
this.faces.push([0, 2, 3]);
this.computeNormals();
});

myp5.fill(255);
myp5.directionalLight(255, 255, 255, 0, 0, -1);

myp5.triangle(-8, -8, 8, -8, 8, 8);

// get register location of
// lightingShader's aTexCoord attribute.
const attributes = renderer._curShader.attributes;
const loc = attributes.aTexCoord.location;

assert.equal(renderer.registerEnabled[loc], true);

myp5.model(myGeom);
assert.equal(renderer.registerEnabled[loc], false);

myp5.triangle(-8, -8, 8, 8, -8, 8);
assert.equal(renderer.registerEnabled[loc], true);

done();
});
});

suite('setAttributes', function() {
test('It leaves a reference to the correct canvas', function(done) {
const renderer = myp5.createCanvas(10, 10, myp5.WEBGL);
Expand Down

0 comments on commit c1a9c69

Please sign in to comment.