Skip to content

Commit c459196

Browse files
committed
don't use vertex arrays anymore
1 parent 444eec5 commit c459196

File tree

3 files changed

+86
-37
lines changed

3 files changed

+86
-37
lines changed

core/src/processing/opengl/PGL.java

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ public void drawTexture(int target, int id,
911911
}
912912
}
913913

914-
914+
int texGeoVBO;
915915
protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
916916
int texX0, int texY0, int texX1, int texY1,
917917
int scrX0, int scrY0, int scrX1, int scrY1) {
@@ -927,6 +927,11 @@ protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
927927
}
928928
loadedTex2DShader = true;
929929
tex2DShaderContext = glContext;
930+
931+
genBuffers(1, intBuffer);
932+
texGeoVBO = intBuffer.get(0);
933+
bindBuffer(ARRAY_BUFFER, texGeoVBO);
934+
bufferData(ARRAY_BUFFER, 16 * SIZEOF_FLOAT, null, STATIC_DRAW);
930935
}
931936

932937
if (texData == null) {
@@ -989,16 +994,27 @@ protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
989994
}
990995
bindTexture(TEXTURE_2D, id);
991996

992-
bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point.
993-
994997
texData.position(0);
995-
vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
996-
texData);
997-
texData.position(2);
998-
vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
999-
texData);
998+
bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO);
999+
bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW);
1000+
1001+
pg.report("HERE 1");
1002+
vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0);
1003+
vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT);
1004+
1005+
1006+
// texData.position(0);
1007+
// vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
1008+
// texData);
1009+
// texData.position(2);
1010+
// vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
1011+
// texData);
1012+
// pg.report("HERE 2");
10001013

10011014
drawArrays(TRIANGLE_STRIP, 0, 4);
1015+
pg.report("HERE 3");
1016+
1017+
bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point.
10021018

10031019
bindTexture(TEXTURE_2D, 0);
10041020
if (enabledTex) {
@@ -1039,6 +1055,11 @@ protected void drawTextureRect(int id, int texW, int texH, int scrW, int scrH,
10391055
}
10401056
loadedTexRectShader = true;
10411057
texRectShaderContext = glContext;
1058+
1059+
genBuffers(1, intBuffer);
1060+
texGeoVBO = intBuffer.get(0);
1061+
bindBuffer(ARRAY_BUFFER, texGeoVBO);
1062+
bufferData(ARRAY_BUFFER, 16 * SIZEOF_FLOAT, null, STATIC_DRAW);
10421063
}
10431064

10441065
if (texData == null) {
@@ -1101,17 +1122,26 @@ protected void drawTextureRect(int id, int texW, int texH, int scrW, int scrH,
11011122
}
11021123
bindTexture(TEXTURE_RECTANGLE, id);
11031124

1104-
bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point.
1105-
11061125
texData.position(0);
1107-
vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
1108-
texData);
1109-
texData.position(2);
1110-
vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
1111-
texData);
1126+
bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO);
1127+
bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW);
1128+
1129+
pg.report("HERE 1");
1130+
vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0);
1131+
vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT);
1132+
1133+
1134+
// texData.position(0);
1135+
// vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
1136+
// texData);
1137+
// texData.position(2);
1138+
// vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
1139+
// texData);
11121140

11131141
drawArrays(TRIANGLE_STRIP, 0, 4);
11141142

1143+
bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point.
1144+
11151145
bindTexture(TEXTURE_RECTANGLE, 0);
11161146
if (enabledTex) {
11171147
disableTexturing(TEXTURE_RECTANGLE);
@@ -2391,12 +2421,12 @@ public void readPixels(int x, int y, int width, int height, int format, int type
23912421
public abstract void vertexAttrib3fv(int index, FloatBuffer values);
23922422
public abstract void vertexAttri4fv(int index, FloatBuffer values);
23932423
public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset);
2394-
public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data);
2424+
//public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data);
23952425
public abstract void enableVertexAttribArray(int index);
23962426
public abstract void disableVertexAttribArray(int index);
23972427
public abstract void drawArrays(int mode, int first, int count);
23982428
public abstract void drawElements(int mode, int count, int type, int offset);
2399-
public abstract void drawElements(int mode, int count, int type, Buffer indices);
2429+
//public abstract void drawElements(int mode, int count, int type, Buffer indices);
24002430

24012431
//////////////////////////////////////////////////////////////////////////////
24022432

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,6 @@ public void beginDraw() {
16291629
}
16301630
setDrawDefaults(); // TODO: look at using checkSettings() instead...
16311631

1632-
16331632
pgCurrent = this;
16341633
drawing = true;
16351634

@@ -5259,7 +5258,6 @@ protected void drawPixels(int x, int y, int w, int h) {
52595258

52605259
// First, copy the pixels to the texture. We don't need to invert the
52615260
// pixel copy because the texture will be drawn inverted.
5262-
52635261
pgl.copyToTexture(texture.glTarget, texture.glFormat, texture.glName,
52645262
x, y, w, h, nativePixelBuffer);
52655263
beginPixelsOp(OP_WRITE);
@@ -6211,9 +6209,7 @@ protected void setDrawDefaults() {
62116209

62126210
if (restoreSurface) {
62136211
restoreSurfaceFromPixels();
6214-
//if (1 < parent.frameCount) {
62156212
restoreSurface = false;
6216-
//}
62176213
}
62186214

62196215
if (hints[DISABLE_DEPTH_MASK]) {

core/src/processing/opengl/PJOGL.java

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,29 @@ public void keyTyped(com.jogamp.newt.event.KeyEvent e) {
985985
// Utility functions
986986

987987

988+
@Override
989+
protected void enableTexturing(int target) {
990+
if (PROFILE == 2) enable(target);
991+
if (target == TEXTURE_2D) {
992+
texturingTargets[0] = true;
993+
} else if (target == TEXTURE_RECTANGLE) {
994+
texturingTargets[1] = true;
995+
}
996+
}
997+
998+
999+
@Override
1000+
protected void disableTexturing(int target) {
1001+
if (PROFILE == 2) disable(target);
1002+
if (target == TEXTURE_2D) {
1003+
texturingTargets[0] = false;
1004+
} else if (target == TEXTURE_RECTANGLE) {
1005+
texturingTargets[1] = false;
1006+
}
1007+
}
1008+
1009+
1010+
9881011
@Override
9891012
protected int getFontAscent(Object font) {
9901013
FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
@@ -1670,14 +1693,14 @@ public void vertexAttribPointer(int index, int size, int type, boolean normalize
16701693
gl2.glVertexAttribPointer(index, size, type, normalized, stride, offset);
16711694
}
16721695

1673-
@Override
1674-
public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data) {
1675-
if (gl2x != null) {
1676-
gl2x.glVertexAttribPointer(index, size, type, normalized, stride, data);
1677-
} else if (gl3bc != null) {
1678-
gl3bc.glVertexAttribPointer(index, size, type, normalized, stride, data);
1679-
}
1680-
}
1696+
// @Override
1697+
// public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data) {
1698+
// if (gl2x != null) {
1699+
// gl2x.glVertexAttribPointer(index, size, type, normalized, stride, data);
1700+
// } else if (gl3bc != null) {
1701+
// gl3bc.glVertexAttribPointer(index, size, type, normalized, stride, data);
1702+
// }
1703+
// }
16811704

16821705
@Override
16831706
public void enableVertexAttribArray(int index) {
@@ -1699,14 +1722,14 @@ public void drawElements(int mode, int count, int type, int offset) {
16991722
gl.glDrawElements(mode, count, type, offset);
17001723
}
17011724

1702-
@Override
1703-
public void drawElements(int mode, int count, int type, Buffer indices) {
1704-
if (gl2x != null) {
1705-
gl2x.glDrawElements(mode, count, type, indices);
1706-
} else if (gl3bc != null) {
1707-
gl3bc.glDrawElements(mode, count, type, indices);
1708-
}
1709-
}
1725+
// @Override
1726+
// public void drawElements(int mode, int count, int type, Buffer indices) {
1727+
// if (gl2x != null) {
1728+
// gl2x.glDrawElements(mode, count, type, indices);
1729+
// } else if (gl3bc != null) {
1730+
// gl3bc.glDrawElements(mode, count, type, indices);
1731+
// }
1732+
// }
17101733

17111734
//////////////////////////////////////////////////////////////////////////////
17121735

0 commit comments

Comments
 (0)