Skip to content

Commit

Permalink
Use createImageBitmap for more efficient image texture creation/storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpm committed Aug 15, 2023
1 parent 8d2053a commit fa8e9aa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
18 changes: 10 additions & 8 deletions dlgr/griduniverse/static/scripts/dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dlgr/griduniverse/static/scripts/dist/bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dlgr/griduniverse/static/scripts/dist/difi.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dlgr/griduniverse/static/scripts/dist/questionnaire.js.map

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions dlgr/griduniverse/static/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,20 @@ Pixels.prototype.imageTexture = function(imageUrl) {
if (imageUrl in textureCache) {
return textureCache[imageUrl];
}
return new Promise (resolve => {
return new Promise ((resolve) => {
let image = new Image();
image.src = imageUrl;
image.crossOrigin = "anonymous";
image.onload = () => {
// Don't recreate the texture if we already have it cached
if (!(imageUrl in textureCache)) {
let texture = this.regl.texture(image);
textureCache[imageUrl] = texture;
}
resolve(textureCache[imageUrl]);
}
createImageBitmap(image).then((bitmap) => {
// Don't recreate the texture if we already have it cached
if (!(imageUrl in textureCache)) {
let texture = this.regl.texture(bitmap);
textureCache[imageUrl] = texture;
}
resolve(textureCache[imageUrl]);
});
};
});
}

Expand Down

0 comments on commit fa8e9aa

Please sign in to comment.