Skip to content

Commit 53069a1

Browse files
committed
move drawElements() call to PShader.draw()
1 parent a2d161d commit 53069a1

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,10 +2420,7 @@ protected void flushPolys() {
24202420
shader.setTexture(tex);
24212421
}
24222422

2423-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPolyIndex);
2424-
pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
2425-
ioffset * PGL.SIZEOF_INDEX);
2426-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
2423+
shader.draw(glPolyIndex, icount, ioffset);
24272424
}
24282425

24292426
shader.unbind();
@@ -2557,10 +2554,7 @@ protected void flushLines() {
25572554
shader.setLineAttribute(glLineAttrib, 4, PGL.FLOAT, 0,
25582555
4 * voffset * PGL.SIZEOF_FLOAT);
25592556

2560-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex);
2561-
pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
2562-
ioffset * PGL.SIZEOF_INDEX);
2563-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
2557+
shader.draw(glLineIndex, icount, ioffset);
25642558
}
25652559

25662560
shader.unbind();
@@ -2661,10 +2655,7 @@ protected void flushPoints() {
26612655
shader.setPointAttribute(glPointAttrib, 2, PGL.FLOAT, 0,
26622656
2 * voffset * PGL.SIZEOF_FLOAT);
26632657

2664-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex);
2665-
pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
2666-
ioffset * PGL.SIZEOF_INDEX);
2667-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
2658+
shader.draw(glPointIndex, icount, ioffset);
26682659
}
26692660

26702661
shader.unbind();

core/src/processing/opengl/PShader.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,14 @@ protected void setup() {
579579
}
580580

581581

582+
protected void draw(int idxId, int count, int offset) {
583+
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, idxId);
584+
pgl.drawElements(PGL.TRIANGLES, count, PGL.INDEX_TYPE,
585+
offset * PGL.SIZEOF_INDEX);
586+
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
587+
}
588+
589+
582590
/**
583591
* Returns the ID location of the attribute parameter given its name.
584592
*
@@ -1149,7 +1157,7 @@ protected void loadUniforms() {
11491157

11501158
textureLoc = getUniformLoc("texture");
11511159
if (textureLoc == -1) {
1152-
textureLoc = getUniformLoc("texSampler");
1160+
textureLoc = getUniformLoc("texMap");
11531161
}
11541162

11551163
texMatrixLoc = getUniformLoc("texMatrix");

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4681,10 +4681,7 @@ protected void renderPolys(PGraphicsOpenGL g, PImage textureImage) {
46814681
shader.setTexture(tex);
46824682
}
46834683

4684-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, root.glPolyIndex);
4685-
pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
4686-
ioffset * PGL.SIZEOF_INDEX);
4687-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
4684+
shader.draw(root.glPolyIndex, icount, ioffset);
46884685
}
46894686

46904687
if (shader != null && shader.bound()) {
@@ -4805,10 +4802,7 @@ protected void renderLines(PGraphicsOpenGL g) {
48054802
shader.setLineAttribute(root.glLineAttrib, 4, PGL.FLOAT,
48064803
0, 4 * voffset * PGL.SIZEOF_FLOAT);
48074804

4808-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, root.glLineIndex);
4809-
pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
4810-
ioffset * PGL.SIZEOF_INDEX);
4811-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
4805+
shader.draw(root.glLineIndex, icount, ioffset);
48124806
}
48134807

48144808
shader.unbind();
@@ -4905,10 +4899,7 @@ protected void renderPoints(PGraphicsOpenGL g) {
49054899
shader.setPointAttribute(root.glPointAttrib, 2, PGL.FLOAT,
49064900
0, 2 * voffset * PGL.SIZEOF_FLOAT);
49074901

4908-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, root.glPointIndex);
4909-
pgl.drawElements(PGL.TRIANGLES, icount, PGL.INDEX_TYPE,
4910-
ioffset * PGL.SIZEOF_INDEX);
4911-
pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
4902+
shader.draw(root.glPointIndex, icount, ioffset);
49124903
}
49134904

49144905
shader.unbind();

0 commit comments

Comments
 (0)