Skip to content

Commit

Permalink
fix(graphics): rendering textured meshes on some machines
Browse files Browse the repository at this point in the history
Some machines seem to have an issue with not passing the instance UVs.
It should default to zero, but it seems to not work as expected. Not
sure if this a difference in behaviour from the GPU/OS/something else.
  • Loading branch information
tomaisthorpe committed Sep 30, 2024
1 parent 2febb7b commit 0f08b43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-falcons-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tedengine/ted': patch
---

Fix rendering problems with textured meshes on some machines
14 changes: 12 additions & 2 deletions packages/ted/src/renderer/renderable-textured-mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default class TRenderableTexturedMesh {
!this.indexBuffer ||
!this.uvBuffer ||
!this.normalBuffer ||
!this.colorFilterUniformLocation
!this.colorFilterUniformLocation ||
!this.instanceUVBuffer
) {
return;
}
Expand All @@ -76,13 +77,22 @@ export default class TRenderableTexturedMesh {
instanceUVs ? 1 : 0,
);

if (instanceUVs && this.instanceUVBuffer) {
if (instanceUVs) {
gl.bindBuffer(gl.ARRAY_BUFFER, this.instanceUVBuffer);
gl.bufferData(
gl.ARRAY_BUFFER,
new Float32Array(instanceUVs),
gl.STATIC_DRAW,
);
} else {
// Even if instanceUVs are not provided, we need to bind the buffer
// Some machines seem to require this, otherwise the shader will fail.
gl.bindBuffer(gl.ARRAY_BUFFER, this.instanceUVBuffer);
gl.bufferData(
gl.ARRAY_BUFFER,
new Float32Array(this.uvs),
gl.STATIC_DRAW,
);
}

const vertexCount = this.indexes.length;
Expand Down

0 comments on commit 0f08b43

Please sign in to comment.