Skip to content

Commit

Permalink
webgl: clip image write based on texture size (#2234)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer authored Aug 30, 2024
1 parent 61c927c commit 1344d3e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions modules/core/test/adapter/resources/texture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,22 @@ test('Texture#copyExternalImage', async t => {
`${device.info.type} Pixels were set correctly (sub image)`
);
}

// Subimage copy (smaller canvas)
canvas.width = 1;
canvas.height = 1;
ctx.fillStyle = '#00FF00';
ctx.fillRect(0, 0, 1, 1);

texture.copyExternalImage({image: canvas, x: 1});

if (device.info.type === 'webgl') {
t.deepEquals(
device.readPixelsToArrayWebGL(texture),
new Uint8Array([255, 0, 0, 255, 0, 255, 0, 255]),
`${device.info.type} Pixels were set correctly (sub image small canvas)`
);
}
}

if (device.info.type !== 'webgl') {
Expand Down
4 changes: 2 additions & 2 deletions modules/webgl/src/adapter/resources/webgl-texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export class WEBGLTexture extends Texture {
const {dimension, glTarget, glFormat, glInternalFormat, glType} = this;

// WebGL will error if we try to copy outside the bounds of the texture
width = Math.min(width, size.width - x);
height = Math.min(height, size.height - y);
width = Math.min(width, this.width - x);
height = Math.min(height, this.height - y);

if (options.sourceX || options.sourceY) {
// requires copyTexSubImage2D from a framebuffer'
Expand Down

0 comments on commit 1344d3e

Please sign in to comment.