Skip to content

Commit

Permalink
Christianh104 patch 1 (#1)
Browse files Browse the repository at this point in the history
Resolves cropped rendering when WebGL drawing buffer is smaller than canvas due to hardware constraints by scaling viewport to drawing buffer rather than canvas size.
See:
https://stackoverflow.com/questions/29710696/webgl-drawing-buffer-size-does-not-equal-canvas-size
https://registry.khronos.org/webgl/specs/latest/1.0/#2.2
  • Loading branch information
christianh104 authored Aug 18, 2023
1 parent 6d7dde3 commit 4cc91c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/backend/gl/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,9 @@ class GLKernel extends Kernel {
this.updateMaxTexSize();
this.framebuffer.width = this.texSize[0];
this.framebuffer.height = this.texSize[1];
gl.viewport(0, 0, this.maxTexSize[0], this.maxTexSize[1]);
this.canvas.width = this.maxTexSize[0];
this.canvas.height = this.maxTexSize[1];
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
if (this.texture) {
this.texture.delete();
}
Expand Down Expand Up @@ -1056,4 +1056,4 @@ const typeMap = {

module.exports = {
GLKernel
};
};
14 changes: 4 additions & 10 deletions src/backend/web-gl/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,9 @@ class WebGLKernel extends GLKernel {
}
const { texSize, context: gl, canvas } = this;
gl.enable(gl.SCISSOR_TEST);
if (this.pipeline && this.precision === 'single') {
gl.viewport(0, 0, this.maxTexSize[0], this.maxTexSize[1]);
canvas.width = this.maxTexSize[0];
canvas.height = this.maxTexSize[1];
} else {
gl.viewport(0, 0, this.maxTexSize[0], this.maxTexSize[1]);
canvas.width = this.maxTexSize[0];
canvas.height = this.maxTexSize[1];
}
canvas.width = this.maxTexSize[0];
canvas.height = this.maxTexSize[1];
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
const threadDim = this.threadDim = Array.from(this.output);
while (threadDim.length < 3) {
threadDim.push(1);
Expand Down Expand Up @@ -1604,4 +1598,4 @@ float integerCorrectionModulo(float number, float divisor) {

module.exports = {
WebGLKernel
};
};

0 comments on commit 4cc91c3

Please sign in to comment.