Skip to content

Commit b5762ff

Browse files
committed
Fix autoSized for framebuffers
1 parent e6053b5 commit b5762ff

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/webgl/p5.Framebuffer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class Framebuffer {
139139
target._renderer._adjustDimensions(settings.width, settings.height);
140140
this.width = dimensions.adjustedWidth;
141141
this.height = dimensions.adjustedHeight;
142-
this.autoSized = false;
142+
this._autoSized = false;
143143
} else {
144144
if ((settings.width === undefined) !== (settings.height === undefined)) {
145145
console.warn(
@@ -150,7 +150,7 @@ class Framebuffer {
150150
}
151151
this.width = target.width;
152152
this.height = target.height;
153-
this.autoSized = true;
153+
this._autoSized = true;
154154
}
155155
this._checkIfFormatsAvailable();
156156

@@ -226,7 +226,7 @@ class Framebuffer {
226226
* the user's mouse
227227
*/
228228
resize(width, height) {
229-
this.autoSized = false;
229+
this._autoSized = false;
230230
const dimensions =
231231
this.target._renderer._adjustDimensions(width, height);
232232
width = dimensions.adjustedWidth;
@@ -250,7 +250,7 @@ class Framebuffer {
250250
*/
251251
pixelDensity(density) {
252252
if (density) {
253-
this.autoSized = false;
253+
this._autoSized = false;
254254
this.density = density;
255255
this._handleResize();
256256
} else {
@@ -271,9 +271,9 @@ class Framebuffer {
271271
*/
272272
autoSized(autoSized) {
273273
if (autoSized === undefined) {
274-
return this.autoSized;
274+
return this._autoSized;
275275
} else {
276-
this.autoSized = autoSized;
276+
this._autoSized = autoSized;
277277
this._handleResize();
278278
}
279279
}
@@ -655,7 +655,7 @@ class Framebuffer {
655655
* @private
656656
*/
657657
_updateSize() {
658-
if (this.autoSized) {
658+
if (this._autoSized) {
659659
this.width = this.target.width;
660660
this.height = this.target.height;
661661
this.density = this.target.pixelDensity();
@@ -670,7 +670,7 @@ class Framebuffer {
670670
* @private
671671
*/
672672
_canvasSizeChanged() {
673-
if (this.autoSized) {
673+
if (this._autoSized) {
674674
this._handleResize();
675675
}
676676
}

test/unit/webgl/p5.Framebuffer.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ suite('p5.Framebuffer', function() {
103103
myp5.pixelDensity(1);
104104
const fbo = myp5.createFramebuffer();
105105
const oldTexture = fbo.color.rawTexture();
106+
expect(fbo.autoSized()).to.equal(true);
106107
expect(fbo.width).to.equal(10);
107108
expect(fbo.height).to.equal(10);
108109
expect(fbo.density).to.equal(1);
@@ -122,6 +123,7 @@ suite('p5.Framebuffer', function() {
122123
myp5.pixelDensity(3);
123124
const fbo = myp5.createFramebuffer({ width: 20, height: 20, density: 1 });
124125
const oldTexture = fbo.color.rawTexture();
126+
expect(fbo.autoSized()).to.equal(false);
125127
expect(fbo.width).to.equal(20);
126128
expect(fbo.height).to.equal(20);
127129
expect(fbo.density).to.equal(1);
@@ -136,6 +138,30 @@ suite('p5.Framebuffer', function() {
136138
expect(fbo.color.rawTexture()).to.equal(oldTexture);
137139
});
138140

141+
test('manually-sized framebuffers can be made auto-sized', function() {
142+
myp5.createCanvas(10, 10, myp5.WEBGL);
143+
myp5.pixelDensity(3);
144+
const fbo = myp5.createFramebuffer({ width: 20, height: 20, density: 1 });
145+
const oldTexture = fbo.color.rawTexture();
146+
expect(fbo.autoSized()).to.equal(false);
147+
expect(fbo.width).to.equal(20);
148+
expect(fbo.height).to.equal(20);
149+
expect(fbo.density).to.equal(1);
150+
151+
// Make it auto-sized
152+
fbo.autoSized(true);
153+
expect(fbo.autoSized()).to.equal(true);
154+
155+
myp5.resizeCanvas(5, 15);
156+
myp5.pixelDensity(2);
157+
expect(fbo.width).to.equal(5);
158+
expect(fbo.height).to.equal(15);
159+
expect(fbo.density).to.equal(2);
160+
161+
// The texture should be recreated
162+
expect(fbo.color.rawTexture()).not.to.equal(oldTexture);
163+
});
164+
139165
suite('resizing', function() {
140166
let fbo;
141167
let oldTexture;

0 commit comments

Comments
 (0)