From 1d7bd062b5ac85b66f9ef25e4e29a6b4a8d30154 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 20 Oct 2013 19:15:04 -0400 Subject: [PATCH] don't use vertex arrays anymore --- core/src/processing/opengl/PGL.java | 64 ++++++++++++++----- .../processing/opengl/PGraphicsOpenGL.java | 4 -- core/src/processing/opengl/PJOGL.java | 55 +++++++++++----- 3 files changed, 86 insertions(+), 37 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index a1135d789..26d57e1fe 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -911,7 +911,7 @@ public abstract class PGL { } } - + int texGeoVBO; protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH, int texX0, int texY0, int texX1, int texY1, int scrX0, int scrY0, int scrX1, int scrY1) { @@ -927,6 +927,11 @@ public abstract class PGL { } loadedTex2DShader = true; tex2DShaderContext = glContext; + + genBuffers(1, intBuffer); + texGeoVBO = intBuffer.get(0); + bindBuffer(ARRAY_BUFFER, texGeoVBO); + bufferData(ARRAY_BUFFER, 16 * SIZEOF_FLOAT, null, STATIC_DRAW); } if (texData == null) { @@ -989,16 +994,27 @@ public abstract class PGL { } bindTexture(TEXTURE_2D, id); - bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point. - texData.position(0); - vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, - texData); - texData.position(2); - vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, - texData); + bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO); + bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW); + + pg.report("HERE 1"); + vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0); + vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT); + + +// texData.position(0); +// vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, +// texData); +// texData.position(2); +// vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, +// texData); +// pg.report("HERE 2"); drawArrays(TRIANGLE_STRIP, 0, 4); + pg.report("HERE 3"); + + bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point. bindTexture(TEXTURE_2D, 0); if (enabledTex) { @@ -1039,6 +1055,11 @@ public abstract class PGL { } loadedTexRectShader = true; texRectShaderContext = glContext; + + genBuffers(1, intBuffer); + texGeoVBO = intBuffer.get(0); + bindBuffer(ARRAY_BUFFER, texGeoVBO); + bufferData(ARRAY_BUFFER, 16 * SIZEOF_FLOAT, null, STATIC_DRAW); } if (texData == null) { @@ -1101,17 +1122,26 @@ public abstract class PGL { } bindTexture(TEXTURE_RECTANGLE, id); - bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point. - texData.position(0); - vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, - texData); - texData.position(2); - vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, - texData); + bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO); + bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW); + + pg.report("HERE 1"); + vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0); + vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT); + + +// texData.position(0); +// vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, +// texData); +// texData.position(2); +// vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, +// texData); drawArrays(TRIANGLE_STRIP, 0, 4); + bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point. + bindTexture(TEXTURE_RECTANGLE, 0); if (enabledTex) { disableTexturing(TEXTURE_RECTANGLE); @@ -2391,12 +2421,12 @@ public abstract class PGL { public abstract void vertexAttrib3fv(int index, FloatBuffer values); public abstract void vertexAttri4fv(int index, FloatBuffer values); public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset); - public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data); + //public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data); public abstract void enableVertexAttribArray(int index); public abstract void disableVertexAttribArray(int index); public abstract void drawArrays(int mode, int first, int count); public abstract void drawElements(int mode, int count, int type, int offset); - public abstract void drawElements(int mode, int count, int type, Buffer indices); + //public abstract void drawElements(int mode, int count, int type, Buffer indices); ////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index b2f1f10e5..8f8619159 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -1629,7 +1629,6 @@ public class PGraphicsOpenGL extends PGraphics { } setDrawDefaults(); // TODO: look at using checkSettings() instead... - pgCurrent = this; drawing = true; @@ -5259,7 +5258,6 @@ public class PGraphicsOpenGL extends PGraphics { // First, copy the pixels to the texture. We don't need to invert the // pixel copy because the texture will be drawn inverted. - pgl.copyToTexture(texture.glTarget, texture.glFormat, texture.glName, x, y, w, h, nativePixelBuffer); beginPixelsOp(OP_WRITE); @@ -6211,9 +6209,7 @@ public class PGraphicsOpenGL extends PGraphics { if (restoreSurface) { restoreSurfaceFromPixels(); - //if (1 < parent.frameCount) { restoreSurface = false; - //} } if (hints[DISABLE_DEPTH_MASK]) { diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index 607651709..72824a3cf 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -985,6 +985,29 @@ public class PJOGL extends PGL { // Utility functions + @Override + protected void enableTexturing(int target) { + if (PROFILE == 2) enable(target); + if (target == TEXTURE_2D) { + texturingTargets[0] = true; + } else if (target == TEXTURE_RECTANGLE) { + texturingTargets[1] = true; + } + } + + + @Override + protected void disableTexturing(int target) { + if (PROFILE == 2) disable(target); + if (target == TEXTURE_2D) { + texturingTargets[0] = false; + } else if (target == TEXTURE_RECTANGLE) { + texturingTargets[1] = false; + } + } + + + @Override protected int getFontAscent(Object font) { FontMetrics metrics = pg.parent.getFontMetrics((Font)font); @@ -1670,14 +1693,14 @@ public class PJOGL extends PGL { gl2.glVertexAttribPointer(index, size, type, normalized, stride, offset); } - @Override - public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data) { - if (gl2x != null) { - gl2x.glVertexAttribPointer(index, size, type, normalized, stride, data); - } else if (gl3bc != null) { - gl3bc.glVertexAttribPointer(index, size, type, normalized, stride, data); - } - } +// @Override +// public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, Buffer data) { +// if (gl2x != null) { +// gl2x.glVertexAttribPointer(index, size, type, normalized, stride, data); +// } else if (gl3bc != null) { +// gl3bc.glVertexAttribPointer(index, size, type, normalized, stride, data); +// } +// } @Override public void enableVertexAttribArray(int index) { @@ -1699,14 +1722,14 @@ public class PJOGL extends PGL { gl.glDrawElements(mode, count, type, offset); } - @Override - public void drawElements(int mode, int count, int type, Buffer indices) { - if (gl2x != null) { - gl2x.glDrawElements(mode, count, type, indices); - } else if (gl3bc != null) { - gl3bc.glDrawElements(mode, count, type, indices); - } - } +// @Override +// public void drawElements(int mode, int count, int type, Buffer indices) { +// if (gl2x != null) { +// gl2x.glDrawElements(mode, count, type, indices); +// } else if (gl3bc != null) { +// gl3bc.glDrawElements(mode, count, type, indices); +// } +// } //////////////////////////////////////////////////////////////////////////////