Skip to content

Commit 5da26a3

Browse files
committed
Make sure text binds an index buffer
1 parent 9799ead commit 5da26a3

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

src/webgl/p5.RendererGL.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class RendererGL extends Renderer3D {
257257
}
258258
} else if (this._curShader.shaderType === 'text') {
259259
// Text rendering uses a fixed quad geometry with 6 indices
260+
this._bindBuffer(glBuffers.indexBuffer, gl.ELEMENT_ARRAY_BUFFER);
260261
gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0);
261262
} else if (glBuffers.indexBuffer) {
262263
this._bindBuffer(glBuffers.indexBuffer, gl.ELEMENT_ARRAY_BUFFER);
@@ -1049,7 +1050,8 @@ class RendererGL extends Renderer3D {
10491050
const gl = this.GL;
10501051

10511052
if (indices) {
1052-
const buffer = gl.createBuffer();
1053+
let buffer = buffers.indexBuffer;
1054+
if (!buffer) buffer = gl.createBuffer();
10531055
this._bindBuffer(buffer, gl.ELEMENT_ARRAY_BUFFER, indices, indexType);
10541056

10551057
buffers.indexBuffer = buffer;

src/webgl/text.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ function text(p5, fn) {
766766

767767
// this will have to do for now...
768768
sh.setUniform('uMaterialColor', curFillColor);
769+
this._disableRemainingAttributes(sh);
769770
this._beforeDrawText();
770771
this.glyphDataCache = this.glyphDataCache || new Set();
771772

test/unit/visual/cases/webgl.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,33 @@ visualSuite('WebGL', function() {
790790

791791
screenshot();
792792
});
793+
794+
visualTest('text renders correctly after geometry with many indices', async (p5, screenshot) => {
795+
p5.createCanvas(100, 100, p5.WEBGL);
796+
const font = await p5.loadFont(
797+
'/unit/assets/Inconsolata-Bold.ttf'
798+
);
799+
800+
p5.background(255);
801+
p5.noStroke();
802+
803+
p5.textFont(font);
804+
p5.textSize(20);
805+
p5.textAlign(p5.CENTER, p5.CENTER);
806+
p5.text('Test 1', 0, -20);
807+
808+
// Draw a sphere which has many more indices than text
809+
p5.fill(200, 200, 255);
810+
p5.sphere(30);
811+
812+
p5.clearDepth();
813+
814+
// Draw text - should bind its own index buffer
815+
p5.fill(0);
816+
p5.text('Test 2', 0, 20);
817+
818+
screenshot();
819+
});
793820
});
794821

795822
visualSuite('texture()', () => {
2.49 KB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)