From 5da26a36c0050e64461efc0f5881ac57d813aaa5 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Fri, 9 Jan 2026 13:11:35 -0500 Subject: [PATCH] Make sure text binds an index buffer --- src/webgl/p5.RendererGL.js | 4 ++- src/webgl/text.js | 1 + test/unit/visual/cases/webgl.js | 27 ++++++++++++++++++ .../000.png | Bin 0 -> 2547 bytes .../metadata.json | 3 ++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/unit/visual/screenshots/WebGL/font data/text renders correctly after geometry with many indices/000.png create mode 100644 test/unit/visual/screenshots/WebGL/font data/text renders correctly after geometry with many indices/metadata.json diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index a7037d3759..dac757acd9 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -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); @@ -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; diff --git a/src/webgl/text.js b/src/webgl/text.js index 083ec0364b..439f209ed8 100644 --- a/src/webgl/text.js +++ b/src/webgl/text.js @@ -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(); diff --git a/test/unit/visual/cases/webgl.js b/test/unit/visual/cases/webgl.js index c2157b3d18..7462d526bb 100644 --- a/test/unit/visual/cases/webgl.js +++ b/test/unit/visual/cases/webgl.js @@ -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()', () => { diff --git a/test/unit/visual/screenshots/WebGL/font data/text renders correctly after geometry with many indices/000.png b/test/unit/visual/screenshots/WebGL/font data/text renders correctly after geometry with many indices/000.png new file mode 100644 index 0000000000000000000000000000000000000000..572f95b3e679151bad2c60d9d397ab7e396f0ed4 GIT binary patch literal 2547 zcmb7`c_0&v8^^a1Srd9I$7?p5dvYJSGDq)5C`QI|&3)uZb0nD~gs@zRjT~DjqU6p| za+a~Yv_j;VTL)f8{Jg(Ee*gdec)ri`{rvYl&p+RLSFAAnU@t!+BFc-Kf|Ef+RRO#O zwBF>jU}|Isap?)Pgp42LI*Y@sW+s7>yVG7~>G~z%({e%oDDvp>n* zAFcIFfwd2L73t~Ju;bCcHLY=3_7`>%uvil=A=6o*)G&^_YSD6~dnCN8wrhH<<`1K< zK9XI=6ik|yV24n&wG!J=^Od3?nT(va#XdR74bkgR6~}V@B-%@5#@E9^^?dc$I)L!9 z7F~&zCBM(EpG8l4e13I3J2SHwH8(eRXZI1XnjpxG7MtDiB^dt2o>D0{!u zaymb+je~=ktX1Jx8$6zadtF(XlJ_`pdu^gs9QDVCuc9Zoq2U7$Ro#6!%*WXU1(#}T zYw12d=QFGQu4{@I2Pq1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b{r!$+zxM=YNNhkfC1#f5A_;aZM%{b|AWPEz zB#}t_86(ACd{oaI&+c)6m;_DkgB+BC+S|y_JY@4U{pUB-xDEF=polyAb92|H7l#ZF zVQq&8Q5xZE_(wXS+{z}*eAB=FB3=DbuEsg;G<@FBu!uV?OZM_eW5~BFiWe<-K`2+w zw+sxjue_w|Jx%nW#Oe2t!M57ySi|rm%{||)1mD)F9F*|lUEzZc7NRkHorbj`5Te-j z<9E5!0SSuLt=e{$XLN4rdEYbhY{JpEBY zfjkl!uidGRl$XE9@Z?!#4-`swj9W3X#%AX%%S$oa8)J%5+s!^pAE)Y)Hr1Syii_b% z{R3me`#bk;u8ceDl9twOuU;i9q}-2A>0!Gv;p@xu{D0;$d0_zzvn-yGsv5d~!Ocg1 zccJ4QUU*5)#Fc{EmEl5<_%nA(IYd8?5fmu{Bs{XxEAg8^MBmt6b8?|l_$tsdGc)5&E<@64YIV3a0jRF2u+lYG3{%GOc}HJ* zsgo^Xk6%Z86}7vwkZ0pG;dE=Y9vZMcd&S&btHl@U+ESj6K z#Fw$f0=poP>C1Y*fJnGwPv>y30(bgZP?CwMgen`&#ONiCvR;9RuhridSp!w47Mj%+ z;LU5Q?Kc0nq2MaCD?ud-RF#kNaJS&*$!u^kExhXrgPhR0cnhZhzctBcLIs`TVJur# zkU5dE5E2+GQdq4$mvNNX4i60wd%&ZC=iki61$bc6K*Ea;o<1S~vx`=y)yA%I{{hQ; B#&ZAw literal 0 HcmV?d00001 diff --git a/test/unit/visual/screenshots/WebGL/font data/text renders correctly after geometry with many indices/metadata.json b/test/unit/visual/screenshots/WebGL/font data/text renders correctly after geometry with many indices/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/font data/text renders correctly after geometry with many indices/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file