MCPcopy
hub / github.com/processing/p5.js / _shouldUpdate

Method _shouldUpdate

src/webgl/p5.Texture.js:197–279  ·  view source on GitHub ↗
(textureData)

Source from the content-addressed store, hash-verified

195 }
196
197 _shouldUpdate(textureData) {
198 const data = this.src;
199 if (data.width === 0 || data.height === 0) {
200 return false; // nothing to do!
201 }
202
203 // FramebufferTexture instances wrap raw WebGL textures already, which
204 // don't need any extra updating, as they already live on the GPU
205 if (this.isFramebufferTexture) {
206 this.src.update();
207 return false;
208 }
209
210 let updated = false;
211 // pull texture from data, make sure width & height are appropriate
212 if (
213 textureData.width !== this.width ||
214 textureData.height !== this.height
215 ) {
216 updated = true;
217
218 // make sure that if the width and height of this.src have changed
219 // for some reason, we update our metadata and upload the texture again
220 this.width = textureData.width || data.width;
221 this.height = textureData.height || data.height;
222
223 if (this.isSrcP5Image) {
224 data.setModified(false);
225 } else if (this.isSrcMediaElement || this.isSrcHTMLElement) {
226 // on the first frame the metadata comes in, the size will be changed
227 // from 0 to actual size, but pixels may not be available.
228 // flag for update in a future frame.
229 // if we don't do this, a paused video, for example, may not
230 // send the first frame to texture memory.
231 data.setModified && data.setModified(true);
232 }
233 } else if (this.isSrcP5Image) {
234 if (data.gifProperties) {
235 data._animateGif(this._renderer._pInst);
236 }
237 // for an image, we only update if the modified field has been set,
238 // for example, by a call to p5.Image.set
239 if (data.isModified()) {
240 updated = true;
241 data.setModified(false);
242 }
243 } else if (this.isSrcMediaElement) {
244 // for a media element (video), we'll check if the current time in
245 // the video frame matches the last time. if it doesn't match, the
246 // video has advanced or otherwise been taken to a new frame,
247 // and we need to upload it.
248 if (data.isModified()) {
249 // p5.MediaElement may have also had set/updatePixels, etc. called
250 // on it and should be updated, or may have been set for the first
251 // time!
252 updated = true;
253 data.setModified(false);
254 } else if (data.loadedmetadata) {

Callers 1

updateMethod · 0.95

Calls 5

_animateGifMethod · 0.80
timeMethod · 0.80
updateMethod · 0.45
setModifiedMethod · 0.45
isModifiedMethod · 0.45

Tested by

no test coverage detected