Skip to content

Commit a5f210b

Browse files
authored
Merge pull request #30 from codewithkyle/webgl-rewrite
Fixing large mipmap issue on chrome
2 parents a4c1fdf + ff029e5 commit a5f210b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

client/src/pages/tabletop-page/tabletop-component/table-canvas/table-canvas.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,18 @@ export default class TableCanvas extends SuperComponent<ITableCanvas> {
397397
this.gl.bindTexture(this.gl.TEXTURE_2D, this.imgProgram.get_texture());
398398
this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, this.gl.RGBA, this.gl.UNSIGNED_BYTE, this.image);
399399

400-
if ((this.image.width % 2) === 0 && (this.image.height % 2) === 0) {
400+
if (this.isPowerOfTwo(this.image.width) && this.isPowerOfTwo(this.image.height)) {
401401
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR_MIPMAP_NEAREST);
402402
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST);
403403
this.gl.generateMipmap(this.gl.TEXTURE_2D);
404+
405+
const error = this.gl.getError();
406+
if (error !== this.gl.NO_ERROR) {
407+
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
408+
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
409+
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.NEAREST);
410+
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST);
411+
}
404412
} else {
405413
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
406414
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
@@ -679,5 +687,9 @@ export default class TableCanvas extends SuperComponent<ITableCanvas> {
679687
const clipY = (y / h) * 2 - 1;
680688
return [clipX, clipY];
681689
}
690+
691+
private isPowerOfTwo(value) {
692+
return (value & (value - 1)) === 0; // Check if the value is a power of 2
693+
}
682694
}
683695
env.bind("table-canvas", TableCanvas);

server/views/layouts/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
66

7-
<title>Tabletopper v0.7.0</title>
7+
<title>Tabletopper v0.7.1</title>
88
<meta name="description" content="Jump into a D&D tabletop session with your friends, hassle free.">
99

1010
<link rel="icon" href="/static/favicon.png" sizes="any">

server/views/layouts/vtt.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
66

7-
<title>Tabletopper v0.7.0</title>
7+
<title>Tabletopper v0.7.1</title>
88
<meta name="description" content="Jump into a D&D tabletop session with your friends, hassle free.">
99

1010
<link rel="icon" href="/static/favicon.png" sizes="any">

0 commit comments

Comments
 (0)