Skip to content

Commit

Permalink
perf(demutils): texture data read optimization in elevation measurement
Browse files Browse the repository at this point in the history
Optimize getImageData operations with willReadFrequently hint in DemUtils
getElevationValueAt and c3DEngine bufferToImage.
  • Loading branch information
jailln committed Dec 15, 2022
1 parent 059fe5e commit 9ee991c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Renderer/c3DEngine.js
Expand Up @@ -222,7 +222,7 @@ class c3DEngine {

bufferToImage(pixelBuffer, width, height) {
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var ctx = canvas.getContext('2d', { willReadFrequently: true });

// size the canvas to your desired image
canvas.width = width;
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/DEMUtils.js
Expand Up @@ -147,7 +147,7 @@ function _readTextureValueAt(metadata, texture, ...uv) {
_canvas.width = Math.max(_canvas.width, dw);
_canvas.height = Math.max(_canvas.height, dh);

const ctx = _canvas.getContext('2d');
const ctx = _canvas.getContext('2d', { willReadFrequently: true });
ctx.drawImage(texture.image, minx, miny, dw, dh, 0, 0, dw, dh);
const d = ctx.getImageData(0, 0, dw, dh);

Expand Down

0 comments on commit 9ee991c

Please sign in to comment.