From 66a5b214544f6558bb30bc84cf8b123794162289 Mon Sep 17 00:00:00 2001 From: u7310220 Date: Tue, 25 Oct 2022 21:32:56 +1100 Subject: [PATCH 1/5] Added isWebGL flag --- src/core/main.js | 5 ++++- src/core/rendering.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/core/main.js b/src/core/main.js index 6a3290b4a0..c53ea99367 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -387,7 +387,7 @@ class p5 { this._frameRate = 1000.0 / (now - this._lastFrameTime); this.deltaTime = now - this._lastFrameTime; this._setProperty('deltaTime', this.deltaTime); - this._lastFrameTime = now; + this._lastFrameTime = this._lastFrameTime+target_time_between_frames; // If the user is actually using mouse module, then update // coordinates, otherwise skip. We can test this by simply @@ -689,6 +689,9 @@ class p5 { } }; } + isWebGL() { + return Graphics.isWebGL; + } } // This is a pointer to our global mode p5 instance, if we're in diff --git a/src/core/rendering.js b/src/core/rendering.js index 391987a409..f5a3e6b034 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -119,6 +119,21 @@ p5.prototype.createCanvas = function(w, h, renderer) { } this._renderer.resize(w, h); this._renderer._applyDefaults(); + + //isWebGL flag is set and made read-only + if (this.isWebGL == 1) { + Object.defineProperty(this,"isWebGL" , { + value: this._renderer.drawingContext instanceof WebGLRenderingContext, + writable: false + }); + } + //createCanvas runs twice when called. The first call sets the renderer to 2D + //even if WEBGL is specified in the arguments. There only on the + //second call does createCanvas check, set and lock isWebGL + if (this.isWebGL === undefined) { + this.isWebGL = 1; + } + return this._renderer; }; From 9a8069114624cfeb8ea42725c416dd8288b2035a Mon Sep 17 00:00:00 2001 From: u7310220 Date: Tue, 25 Oct 2022 21:39:49 +1100 Subject: [PATCH 2/5] Removed unrelated changes --- src/core/main.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core/main.js b/src/core/main.js index c53ea99367..6a3290b4a0 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -387,7 +387,7 @@ class p5 { this._frameRate = 1000.0 / (now - this._lastFrameTime); this.deltaTime = now - this._lastFrameTime; this._setProperty('deltaTime', this.deltaTime); - this._lastFrameTime = this._lastFrameTime+target_time_between_frames; + this._lastFrameTime = now; // If the user is actually using mouse module, then update // coordinates, otherwise skip. We can test this by simply @@ -689,9 +689,6 @@ class p5 { } }; } - isWebGL() { - return Graphics.isWebGL; - } } // This is a pointer to our global mode p5 instance, if we're in From 23d37661575b4ea3cbc00d01b0c93cda4bebd31c Mon Sep 17 00:00:00 2001 From: u7310220 Date: Tue, 25 Oct 2022 21:45:22 +1100 Subject: [PATCH 3/5] Tweaked comments --- src/core/rendering.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index f5a3e6b034..bf98f4ef07 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -127,9 +127,10 @@ p5.prototype.createCanvas = function(w, h, renderer) { writable: false }); } - //createCanvas runs twice when called. The first call sets the renderer to 2D - //even if WEBGL is specified in the arguments. There only on the - //second call does createCanvas check, set and lock isWebGL + //createCanvas runs twice. The first call sets the renderer to + //2D even if WEBGL is specified in the arguments, on the second call it + //uses the correct renderer. Therefore only on the second call does + //createCanvas check, set and lock isWebGL if (this.isWebGL === undefined) { this.isWebGL = 1; } From df6dd2bb60333091015d93182f0dbeeff193d1f8 Mon Sep 17 00:00:00 2001 From: u7310220 Date: Tue, 25 Oct 2022 22:21:48 +1100 Subject: [PATCH 4/5] Fixed if statement --- src/core/rendering.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index bf98f4ef07..1cd2c8de4f 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -121,7 +121,7 @@ p5.prototype.createCanvas = function(w, h, renderer) { this._renderer._applyDefaults(); //isWebGL flag is set and made read-only - if (this.isWebGL == 1) { + if (this.isWebGL == false) { Object.defineProperty(this,"isWebGL" , { value: this._renderer.drawingContext instanceof WebGLRenderingContext, writable: false @@ -132,7 +132,7 @@ p5.prototype.createCanvas = function(w, h, renderer) { //uses the correct renderer. Therefore only on the second call does //createCanvas check, set and lock isWebGL if (this.isWebGL === undefined) { - this.isWebGL = 1; + this.isWebGL = false; } return this._renderer; From ddb81e650bf790941cba0877c9d38314be84c827 Mon Sep 17 00:00:00 2001 From: u7310220 Date: Tue, 25 Oct 2022 22:49:14 +1100 Subject: [PATCH 5/5] Fixed if statement again --- src/core/rendering.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index 1cd2c8de4f..c8cee90286 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -127,10 +127,8 @@ p5.prototype.createCanvas = function(w, h, renderer) { writable: false }); } - //createCanvas runs twice. The first call sets the renderer to - //2D even if WEBGL is specified in the arguments, on the second call it - //uses the correct renderer. Therefore only on the second call does - //createCanvas check, set and lock isWebGL + //createCanvas is run automatically with the 2D renderer. + //Auto-set isWebGL to false if undefined because of this if (this.isWebGL === undefined) { this.isWebGL = false; }