Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class RendererGL extends Renderer3D {
}
} else if (this._curShader.shaderType === 'text') {
// Text rendering uses a fixed quad geometry with 6 indices
this._bindBuffer(glBuffers.indexBuffer, gl.ELEMENT_ARRAY_BUFFER);
gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0);
} else if (glBuffers.indexBuffer) {
this._bindBuffer(glBuffers.indexBuffer, gl.ELEMENT_ARRAY_BUFFER);
Expand Down Expand Up @@ -1049,7 +1050,8 @@ class RendererGL extends Renderer3D {
const gl = this.GL;

if (indices) {
const buffer = gl.createBuffer();
let buffer = buffers.indexBuffer;
if (!buffer) buffer = gl.createBuffer();
this._bindBuffer(buffer, gl.ELEMENT_ARRAY_BUFFER, indices, indexType);

buffers.indexBuffer = buffer;
Expand Down
1 change: 1 addition & 0 deletions src/webgl/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ function text(p5, fn) {

// this will have to do for now...
sh.setUniform('uMaterialColor', curFillColor);
this._disableRemainingAttributes(sh);
this._beforeDrawText();
this.glyphDataCache = this.glyphDataCache || new Set();

Expand Down
27 changes: 27 additions & 0 deletions test/unit/visual/cases/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,33 @@ visualSuite('WebGL', function() {

screenshot();
});

visualTest('text renders correctly after geometry with many indices', async (p5, screenshot) => {
p5.createCanvas(100, 100, p5.WEBGL);
const font = await p5.loadFont(
'/unit/assets/Inconsolata-Bold.ttf'
);

p5.background(255);
p5.noStroke();

p5.textFont(font);
p5.textSize(20);
p5.textAlign(p5.CENTER, p5.CENTER);
p5.text('Test 1', 0, -20);

// Draw a sphere which has many more indices than text
p5.fill(200, 200, 255);
p5.sphere(30);

p5.clearDepth();

// Draw text - should bind its own index buffer
p5.fill(0);
p5.text('Test 2', 0, 20);

screenshot();
});
});

visualSuite('texture()', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Loading