From 309d95b0cbed47db25bea5c4596df450010efeb9 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 18 Jul 2012 20:27:29 +0000 Subject: [PATCH] PShader updates --- .../core/src/processing/core/PGraphics.java | 51 +- android/core/src/processing/core/PImage.java | 34 +- .../src/processing/opengl/FrameBuffer.java | 128 ++-- .../src/processing/opengl/PFontTexture.java | 4 +- android/core/src/processing/opengl/PGL.java | 36 +- .../processing/opengl/PGraphicsOpenGL.java | 702 ++++++++++-------- .../core/src/processing/opengl/PShader.java | 176 +++-- .../src/processing/opengl/PShapeOpenGL.java | 438 +++++------ .../core/src/processing/opengl/Texture.java | 37 +- core/src/processing/core/PApplet.java | 37 + core/src/processing/core/PGraphics.java | 48 +- core/src/processing/core/PImage.java | 34 +- .../examples/Shaders/BadPrint/BadPrint.pde | 21 +- .../Shaders/EdgeDetect/EdgeDetect.pde | 12 +- .../opengl/examples/Shaders/FXAA/FXAA.pde | 18 +- .../examples/Shaders/FishEye/FishEye.pde | 6 +- .../Shaders/GlossyFishEye/GlossyFishEye.pde | 15 +- .../Shaders/LowLevelGL/LowLevelGL.pde | 15 +- .../examples/Shaders/SepBlur/SepBlur.pde | 46 +- .../Shaders/ToonShading/ToonShading.pde | 12 +- .../src/processing/opengl/FrameBuffer.java | 128 ++-- .../src/processing/opengl/PFontTexture.java | 4 +- .../opengl/src/processing/opengl/PGL.java | 42 +- .../processing/opengl/PGraphicsOpenGL.java | 702 ++++++++++-------- .../opengl/src/processing/opengl/PShader.java | 176 +++-- .../src/processing/opengl/PShapeOpenGL.java | 438 +++++------ .../opengl/src/processing/opengl/Texture.java | 37 +- 27 files changed, 1821 insertions(+), 1576 deletions(-) diff --git a/android/core/src/processing/core/PGraphics.java b/android/core/src/processing/core/PGraphics.java index 7cf888e51..adb8f45ee 100644 --- a/android/core/src/processing/core/PGraphics.java +++ b/android/core/src/processing/core/PGraphics.java @@ -1288,6 +1288,52 @@ public class PGraphics extends PImage implements PConstants { } + + ////////////////////////////////////////////////////////////// + + // SHADERS + + + public Object loadShader(String vertFilename, String fragFilename, int kind) { + showMissingWarning("loadShader"); + return null; + } + + + public Object loadShader(String fragFilename, int kind) { + showMissingWarning("loadShader"); + return null; + } + + + public Object loadShader(String vertFilename, String fragFilename) { + showMissingWarning("loadShader"); + return null; + } + + + public Object loadShader(String fragFilename) { + showMissingWarning("loadShader"); + return null; + } + + + public void shader(Object shader, int kind) { + showMissingWarning("shader"); + } + + + public void resetShader(int kind) { + showMissingWarning("resetShader"); + } + + + public Object getShader(int kind) { + showMissingWarning("getShader"); + return null; + } + + ////////////////////////////////////////////////////////////// // CURVE/BEZIER VERTEX HANDLING @@ -2542,8 +2588,9 @@ public class PGraphics extends PImage implements PConstants { } - public void initCache(PImage img) { // ignore - } + public Object initCache(PImage img) { // ignore + return null; + } ////////////////////////////////////////////////////////////// diff --git a/android/core/src/processing/core/PImage.java b/android/core/src/processing/core/PImage.java index 6756ff747..188a671c8 100644 --- a/android/core/src/processing/core/PImage.java +++ b/android/core/src/processing/core/PImage.java @@ -352,26 +352,22 @@ public class PImage implements PConstants, Cloneable { } if (parent == null) return; - parent.g.initCache(this); - if (cacheMap != null) { - for (PGraphics pg: cacheMap.keySet()) { - Object obj = cacheMap.get(pg); - - Method loadPixelsMethod = null; - try { - loadPixelsMethod = obj.getClass().getMethod("loadPixels", new Class[] { int[].class }); - } catch (Exception e) { + Object cache = parent.g.initCache(this); + if (cache != null) { + Method loadPixelsMethod = null; + try { + loadPixelsMethod = cache.getClass().getMethod("loadPixels", new Class[] { int[].class }); + } catch (Exception e) { + } + + if (loadPixelsMethod != null) { + try { + loadPixelsMethod.invoke(cache, new Object[] { pixels }); + } catch (Exception e) { + e.printStackTrace(); } - - if (loadPixelsMethod != null) { - try { - loadPixelsMethod.invoke(obj, new Object[] { pixels }); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } + } + } } diff --git a/android/core/src/processing/opengl/FrameBuffer.java b/android/core/src/processing/opengl/FrameBuffer.java index b836b32e9..c28cd3489 100644 --- a/android/core/src/processing/opengl/FrameBuffer.java +++ b/android/core/src/processing/opengl/FrameBuffer.java @@ -45,11 +45,11 @@ public class FrameBuffer implements PConstants { protected PGL pgl; protected PGL.Context context; // The context that created this framebuffer. - public int glFboID; - public int glDepthBufferID; - public int glStencilBufferID; - public int glDepthStencilBufferID; - public int glColorBufferMultisampleID; + public int glFbo; + public int glDepth; + public int glStencil; + public int glDepthStencil; + public int glMultisample; public int width; public int height; @@ -84,11 +84,11 @@ public class FrameBuffer implements PConstants { pgl = pg.pgl; context = pgl.createEmptyContext(); - glFboID = 0; - glDepthBufferID = 0; - glStencilBufferID = 0; - glDepthStencilBufferID = 0; - glColorBufferMultisampleID = 0; + glFbo = 0; + glDepth = 0; + glStencil = 0; + glDepthStencil = 0; + glMultisample = 0; if (screen) { // If this framebuffer is used to represent a on-screen buffer, @@ -143,20 +143,20 @@ public class FrameBuffer implements PConstants { protected void finalize() throws Throwable { try { - if (glFboID != 0) { - pg.finalizeFrameBufferObject(glFboID, context.code()); + if (glFbo != 0) { + pg.finalizeFrameBufferObject(glFbo, context.code()); } - if (glDepthBufferID != 0) { - pg.finalizeRenderBufferObject(glDepthBufferID, context.code()); + if (glDepth != 0) { + pg.finalizeRenderBufferObject(glDepth, context.code()); } - if (glStencilBufferID != 0) { - pg.finalizeRenderBufferObject(glStencilBufferID, context.code()); + if (glStencil != 0) { + pg.finalizeRenderBufferObject(glStencil, context.code()); } - if (glColorBufferMultisampleID != 0) { - pg.finalizeRenderBufferObject(glColorBufferMultisampleID, context.code()); + if (glMultisample != 0) { + pg.finalizeRenderBufferObject(glMultisample, context.code()); } - if (glDepthStencilBufferID != 0) { - pg.finalizeRenderBufferObject(glDepthStencilBufferID, context.code()); + if (glDepthStencil != 0) { + pg.finalizeRenderBufferObject(glDepthStencil, context.code()); } } finally { super.finalize(); @@ -174,15 +174,15 @@ public class FrameBuffer implements PConstants { } public void copy(FrameBuffer dest) { - pgl.glBindFramebuffer(PGL.GL_READ_FRAMEBUFFER, this.glFboID); - pgl.glBindFramebuffer(PGL.GL_DRAW_FRAMEBUFFER, dest.glFboID); + pgl.glBindFramebuffer(PGL.GL_READ_FRAMEBUFFER, this.glFbo); + pgl.glBindFramebuffer(PGL.GL_DRAW_FRAMEBUFFER, dest.glFbo); pgl.glBlitFramebuffer(0, 0, this.width, this.height, 0, 0, dest.width, dest.height, PGL.GL_COLOR_BUFFER_BIT, PGL.GL_NEAREST); } public void bind() { - pgl.glBindFramebuffer(PGL.GL_FRAMEBUFFER, glFboID); + pgl.glBindFramebuffer(PGL.GL_FRAMEBUFFER, glFbo); } public void disableDepthTest() { @@ -260,7 +260,7 @@ public class FrameBuffer implements PConstants { } for (int i = 0; i < numColorBuffers; i++) { - pgl.glFramebufferTexture2D(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0 + i, colorBufferTex[i].glTarget, colorBufferTex[i].glID, 0); + pgl.glFramebufferTexture2D(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0 + i, colorBufferTex[i].glTarget, colorBufferTex[i].glName, 0); } pgl.validateFramebuffer(); @@ -280,9 +280,9 @@ public class FrameBuffer implements PConstants { context = pgl.getCurrentContext(); if (screenFb) { - glFboID = 0; + glFbo = 0; } else { - glFboID = pg.createFrameBufferObject(context.code()); + glFbo = pg.createFrameBufferObject(context.code()); } // create the rest of the stuff... @@ -304,25 +304,25 @@ public class FrameBuffer implements PConstants { protected void release() { - if (glFboID != 0) { - pg.finalizeFrameBufferObject(glFboID, context.code()); - glFboID = 0; + if (glFbo != 0) { + pg.finalizeFrameBufferObject(glFbo, context.code()); + glFbo = 0; } - if (glDepthBufferID != 0) { - pg.finalizeRenderBufferObject(glDepthBufferID, context.code()); - glDepthBufferID = 0; + if (glDepth != 0) { + pg.finalizeRenderBufferObject(glDepth, context.code()); + glDepth = 0; } - if (glStencilBufferID != 0) { - pg.finalizeRenderBufferObject(glStencilBufferID, context.code()); - glStencilBufferID = 0; + if (glStencil != 0) { + pg.finalizeRenderBufferObject(glStencil, context.code()); + glStencil = 0; } - if (glColorBufferMultisampleID != 0) { - pg.finalizeRenderBufferObject(glColorBufferMultisampleID, context.code()); - glColorBufferMultisampleID = 0; + if (glMultisample != 0) { + pg.finalizeRenderBufferObject(glMultisample, context.code()); + glMultisample = 0; } - if (glDepthStencilBufferID != 0) { - pg.finalizeRenderBufferObject(glDepthStencilBufferID, context.code()); - glDepthStencilBufferID = 0; + if (glDepthStencil != 0) { + pg.finalizeRenderBufferObject(glDepthStencil, context.code()); + glDepthStencil = 0; } } @@ -330,17 +330,17 @@ public class FrameBuffer implements PConstants { protected boolean contextIsOutdated() { boolean outdated = !pgl.contextIsCurrent(context); if (outdated) { - pg.removeFrameBufferObject(glFboID, context.code()); - pg.removeRenderBufferObject(glDepthBufferID, context.code()); - pg.removeRenderBufferObject(glStencilBufferID, context.code()); - pg.removeRenderBufferObject(glDepthStencilBufferID, context.code()); - pg.removeRenderBufferObject(glColorBufferMultisampleID, context.code()); + pg.removeFrameBufferObject(glFbo, context.code()); + pg.removeRenderBufferObject(glDepth, context.code()); + pg.removeRenderBufferObject(glStencil, context.code()); + pg.removeRenderBufferObject(glDepthStencil, context.code()); + pg.removeRenderBufferObject(glMultisample, context.code()); - glFboID = 0; - glDepthBufferID = 0; - glStencilBufferID = 0; - glDepthStencilBufferID = 0; - glColorBufferMultisampleID = 0; + glFbo = 0; + glDepth = 0; + glStencil = 0; + glDepthStencil = 0; + glMultisample = 0; for (int i = 0; i < numColorBuffers; i++) { colorBufferTex[i] = null; @@ -356,10 +356,10 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glColorBufferMultisampleID = pg.createRenderBufferObject(context.code()); - pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glColorBufferMultisampleID); + glMultisample = pg.createRenderBufferObject(context.code()); + pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glMultisample); pgl.glRenderbufferStorageMultisample(PGL.GL_RENDERBUFFER, nsamples, PGL.GL_RGBA8, width, height); - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0, PGL.GL_RENDERBUFFER, glColorBufferMultisampleID); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0, PGL.GL_RENDERBUFFER, glMultisample); pg.popFramebuffer(); } @@ -375,8 +375,8 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glDepthStencilBufferID = pg.createRenderBufferObject(context.code()); - pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthStencilBufferID); + glDepthStencil = pg.createRenderBufferObject(context.code()); + pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthStencil); if (multisample) { pgl.glRenderbufferStorageMultisample(PGL.GL_RENDERBUFFER, nsamples, PGL.GL_DEPTH24_STENCIL8, width, height); @@ -384,8 +384,8 @@ public class FrameBuffer implements PConstants { pgl.glRenderbufferStorage(PGL.GL_RENDERBUFFER, PGL.GL_DEPTH24_STENCIL8, width, height); } - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencilBufferID); - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencilBufferID); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencil); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencil); pg.popFramebuffer(); } @@ -401,8 +401,8 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glDepthBufferID = pg.createRenderBufferObject(context.code()); - pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthBufferID); + glDepth = pg.createRenderBufferObject(context.code()); + pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepth); int glConst = PGL.GL_DEPTH_COMPONENT16; if (depthBits == 16) { @@ -419,7 +419,7 @@ public class FrameBuffer implements PConstants { pgl.glRenderbufferStorage(PGL.GL_RENDERBUFFER, glConst, width, height); } - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthBufferID); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepth); pg.popFramebuffer(); } @@ -435,8 +435,8 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glStencilBufferID = pg.createRenderBufferObject(context.code()); - pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glStencilBufferID); + glStencil = pg.createRenderBufferObject(context.code()); + pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glStencil); int glConst = PGL.GL_STENCIL_INDEX1; if (stencilBits == 1) { @@ -452,7 +452,7 @@ public class FrameBuffer implements PConstants { pgl.glRenderbufferStorage(PGL.GL_RENDERBUFFER, glConst, width, height); } - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glStencilBufferID); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glStencil); pg.popFramebuffer(); } diff --git a/android/core/src/processing/opengl/PFontTexture.java b/android/core/src/processing/opengl/PFontTexture.java index be5c9e73a..e8342b76a 100644 --- a/android/core/src/processing/opengl/PFontTexture.java +++ b/android/core/src/processing/opengl/PFontTexture.java @@ -238,8 +238,8 @@ class PFontTexture implements PConstants { } if (outdated) { for (int i = 0; i < textures.length; i++) { - pg.removeTextureObject(textures[i].glID, textures[i].context.code()); - textures[i].glID = 0; + pg.removeTextureObject(textures[i].glName, textures[i].context.code()); + textures[i].glName = 0; } } return outdated; diff --git a/android/core/src/processing/opengl/PGL.java b/android/core/src/processing/opengl/PGL.java index f41d80065..c87f96ae5 100644 --- a/android/core/src/processing/opengl/PGL.java +++ b/android/core/src/processing/opengl/PGL.java @@ -488,7 +488,7 @@ public class PGL { // to update the screenFramebuffer object so when the // framebuffer is popped back to the screen, the correct // id is set. - PGraphicsOpenGL.screenFramebuffer.glFboID = colorFBO[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = colorFBO[0]; initialized = true; } @@ -512,13 +512,13 @@ public class PGL { public void bindPrimaryColorFBO() { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, colorFBO[0]); - PGraphicsOpenGL.screenFramebuffer.glFboID = colorFBO[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = colorFBO[0]; } public void bindPrimaryMultiFBO() { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, colorFBO[0]); - PGraphicsOpenGL.screenFramebuffer.glFboID = colorFBO[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = colorFBO[0]; } @@ -533,7 +533,7 @@ public class PGL { // No need for saving front color buffer, etc. GLES20.glClearColor(0, 0, 0, 0); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); - PGraphicsOpenGL.screenFramebuffer.glFboID = 0; + PGraphicsOpenGL.screenFramebuffer.glFbo = 0; } else { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, colorFBO[0]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, colorTex[frontTex], 0); @@ -550,7 +550,7 @@ public class PGL { // Render previous draw texture as background. drawTexture(GLES20.GL_TEXTURE_2D, colorTex[backTex], texWidth, texHeight, 0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height); } - PGraphicsOpenGL.screenFramebuffer.glFboID = colorFBO[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = colorFBO[0]; } if (firstOnscreenFrame) { @@ -1058,6 +1058,26 @@ public class PGL { } + public void glVertexAttrib1fv(int loc, float[] v, int offset) { + GLES20.glVertexAttrib1fv(loc, v, offset); + } + + + public void glVertexAttrib2fv(int loc, float[] v, int offset) { + GLES20.glVertexAttrib2fv(loc, v, offset); + } + + + public void glVertexAttrib3fv(int loc, float[] v, int offset) { + GLES20.glVertexAttrib3fv(loc, v, offset); + } + + + public void glVertexAttrib4fv(int loc, float[] v, int offset) { + GLES20.glVertexAttrib4fv(loc, v, offset); + } + + public void glShaderSource(int id, String source) { GLES20.glShaderSource(id, source); } @@ -1436,6 +1456,12 @@ public class PGL { } + public void drawTextureCustom(int target, int id, int width, int height, + int X0, int Y0, int X1, int Y1, int program) { + // ... + } + + public void drawRectangle(float r, float g, float b, float a, int scrX0, int scrY0, int scrX1, int scrY1) { if (!loadedRectShader) { diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 31274164b..5459d6966 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -77,29 +77,29 @@ public class PGraphicsOpenGL extends PGraphics { // VBOs for immediate rendering: - public int glPolyVertexBufferID; - public int glPolyColorBufferID; - public int glPolyNormalBufferID; - public int glPolyTexcoordBufferID; - public int glPolyAmbientBufferID; - public int glPolySpecularBufferID; - public int glPolyEmissiveBufferID; - public int glPolyShininessBufferID; - public int glPolyIndexBufferID; + public int glPolyVertex; + public int glPolyColor; + public int glPolyNormal; + public int glPolyTexcoord; + public int glPolyAmbient; + public int glPolySpecular; + public int glPolyEmissive; + public int glPolyShininess; + public int glPolyIndex; protected boolean polyBuffersCreated = false; protected PGL.Context polyBuffersContext; - public int glLineVertexBufferID; - public int glLineColorBufferID; - public int glLineAttribBufferID; - public int glLineIndexBufferID; + public int glLineVertex; + public int glLineColor; + public int glLineAttrib; + public int glLineIndex; protected boolean lineBuffersCreated = false; protected PGL.Context lineBuffersContext; - public int glPointVertexBufferID; - public int glPointColorBufferID; - public int glPointAttribBufferID; - public int glPointIndexBufferID; + public int glPointVertex; + public int glPointColor; + public int glPointAttrib; + public int glPointIndex; protected boolean pointBuffersCreated = false; protected PGL.Context pointBuffersContext; @@ -358,6 +358,10 @@ public class PGraphicsOpenGL extends PGraphics { /** A handy reference to the PTexture bound to the drawing surface * (off or on-screen) */ protected Texture texture; + + /** Used to create a temporary copy of the color buffer of this + * rendering surface when applying a filter */ + protected Texture textureCopy; /** IntBuffer wrapping the pixels array. */ protected IntBuffer pixelBuffer; @@ -445,25 +449,25 @@ public class PGraphicsOpenGL extends PGraphics { tessGeo = newTessGeometry(IMMEDIATE); texCache = newTexCache(); - glPolyVertexBufferID = 0; - glPolyColorBufferID = 0; - glPolyNormalBufferID = 0; - glPolyTexcoordBufferID = 0; - glPolyAmbientBufferID = 0; - glPolySpecularBufferID = 0; - glPolyEmissiveBufferID = 0; - glPolyShininessBufferID = 0; - glPolyIndexBufferID = 0; + glPolyVertex = 0; + glPolyColor = 0; + glPolyNormal = 0; + glPolyTexcoord = 0; + glPolyAmbient = 0; + glPolySpecular = 0; + glPolyEmissive = 0; + glPolyShininess = 0; + glPolyIndex = 0; - glLineVertexBufferID = 0; - glLineColorBufferID = 0; - glLineAttribBufferID = 0; - glLineIndexBufferID = 0; + glLineVertex = 0; + glLineColor = 0; + glLineAttrib = 0; + glLineIndex = 0; - glPointVertexBufferID = 0; - glPointColorBufferID = 0; - glPointAttribBufferID = 0; - glPointIndexBufferID = 0; + glPointVertex = 0; + glPointColor = 0; + glPointAttrib = 0; + glPointIndex = 0; } @@ -1114,42 +1118,42 @@ public class PGraphicsOpenGL extends PGraphics { int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - glPolyVertexBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID); + glPolyVertex = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW); - glPolyColorBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID); + glPolyColor = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPolyNormalBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID); + glPolyNormal = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW); - glPolyTexcoordBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID); + glPolyTexcoord = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, null, PGL.GL_STATIC_DRAW); - glPolyAmbientBufferID = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID); + glPolyAmbient = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPolySpecularBufferID = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID); + glPolySpecular = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPolyEmissiveBufferID = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID); + glPolyEmissive = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPolyShininessBufferID = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID); + glPolyShininess = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizef, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glPolyIndexBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndexBufferID); + glPolyIndex = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, sizex, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); @@ -1166,36 +1170,36 @@ public class PGraphicsOpenGL extends PGraphics { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.polyVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyColors, 0, size), PGL.GL_STATIC_DRAW); if (lit) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, FloatBuffer.wrap(tessGeo.polyNormals, 0, 3 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyAmbient, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polySpecular, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyEmissive, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizef, FloatBuffer.wrap(tessGeo.polyShininess, 0, size), PGL.GL_STATIC_DRAW); } if (tex) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.polyTexcoords, 0, 2 * size), PGL.GL_STATIC_DRAW); } - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.polyIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.polyIndices, 0, tessGeo.polyIndexCount), PGL.GL_STATIC_DRAW); } @@ -1214,32 +1218,32 @@ public class PGraphicsOpenGL extends PGraphics { protected void deletePolyBuffers() { if (polyBuffersCreated) { - deleteVertexBufferObject(glPolyVertexBufferID, polyBuffersContext.code()); - glPolyVertexBufferID = 0; + deleteVertexBufferObject(glPolyVertex, polyBuffersContext.code()); + glPolyVertex = 0; - deleteVertexBufferObject(glPolyColorBufferID, polyBuffersContext.code()); - glPolyColorBufferID = 0; + deleteVertexBufferObject(glPolyColor, polyBuffersContext.code()); + glPolyColor = 0; - deleteVertexBufferObject(glPolyNormalBufferID, polyBuffersContext.code()); - glPolyNormalBufferID = 0; + deleteVertexBufferObject(glPolyNormal, polyBuffersContext.code()); + glPolyNormal = 0; - deleteVertexBufferObject(glPolyTexcoordBufferID, polyBuffersContext.code()); - glPolyTexcoordBufferID = 0; + deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext.code()); + glPolyTexcoord = 0; - deleteVertexBufferObject(glPolyAmbientBufferID, polyBuffersContext.code()); - glPolyAmbientBufferID = 0; + deleteVertexBufferObject(glPolyAmbient, polyBuffersContext.code()); + glPolyAmbient = 0; - deleteVertexBufferObject(glPolySpecularBufferID, polyBuffersContext.code()); - glPolySpecularBufferID = 0; + deleteVertexBufferObject(glPolySpecular, polyBuffersContext.code()); + glPolySpecular = 0; - deleteVertexBufferObject(glPolyEmissiveBufferID, polyBuffersContext.code()); - glPolyEmissiveBufferID = 0; + deleteVertexBufferObject(glPolyEmissive, polyBuffersContext.code()); + glPolyEmissive = 0; - deleteVertexBufferObject(glPolyShininessBufferID, polyBuffersContext.code()); - glPolyShininessBufferID = 0; + deleteVertexBufferObject(glPolyShininess, polyBuffersContext.code()); + glPolyShininess = 0; - deleteVertexBufferObject(glPolyIndexBufferID, polyBuffersContext.code()); - glPolyIndexBufferID = 0; + deleteVertexBufferObject(glPolyIndex, polyBuffersContext.code()); + glPolyIndex = 0; polyBuffersCreated = false; } @@ -1254,23 +1258,23 @@ public class PGraphicsOpenGL extends PGraphics { int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - glLineVertexBufferID = createVertexBufferObject(lineBuffersContext.code()); + glLineVertex = createVertexBufferObject(lineBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW); - glLineColorBufferID = createVertexBufferObject(lineBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID); + glLineColor = createVertexBufferObject(lineBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glLineAttribBufferID = createVertexBufferObject(lineBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID); + glLineAttrib = createVertexBufferObject(lineBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glLineIndexBufferID = createVertexBufferObject(lineBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); + glLineIndex = createVertexBufferObject(lineBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, sizex, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); @@ -1287,16 +1291,16 @@ public class PGraphicsOpenGL extends PGraphics { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.lineColors, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineAttribs, 0, 4 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.lineIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.lineIndices, 0, tessGeo.lineIndexCount), PGL.GL_STATIC_DRAW); } @@ -1315,17 +1319,17 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteLineBuffers() { if (lineBuffersCreated) { - deleteVertexBufferObject(glLineVertexBufferID, lineBuffersContext.code()); - glLineVertexBufferID = 0; + deleteVertexBufferObject(glLineVertex, lineBuffersContext.code()); + glLineVertex = 0; - deleteVertexBufferObject(glLineColorBufferID, lineBuffersContext.code()); - glLineColorBufferID = 0; + deleteVertexBufferObject(glLineColor, lineBuffersContext.code()); + glLineColor = 0; - deleteVertexBufferObject(glLineAttribBufferID, lineBuffersContext.code()); - glLineAttribBufferID = 0; + deleteVertexBufferObject(glLineAttrib, lineBuffersContext.code()); + glLineAttrib = 0; - deleteVertexBufferObject(glLineIndexBufferID, lineBuffersContext.code()); - glLineIndexBufferID = 0; + deleteVertexBufferObject(glLineIndex, lineBuffersContext.code()); + glLineIndex = 0; lineBuffersCreated = false; } @@ -1340,22 +1344,22 @@ public class PGraphicsOpenGL extends PGraphics { int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - glPointVertexBufferID = createVertexBufferObject(pointBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID); + glPointVertex = createVertexBufferObject(pointBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW); - glPointColorBufferID = createVertexBufferObject(pointBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID); + glPointColor = createVertexBufferObject(pointBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPointAttribBufferID = createVertexBufferObject(pointBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID); + glPointAttrib = createVertexBufferObject(pointBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glPointIndexBufferID = createVertexBufferObject(pointBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); + glPointIndex = createVertexBufferObject(pointBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, sizex, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); @@ -1372,16 +1376,16 @@ public class PGraphicsOpenGL extends PGraphics { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.pointVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.pointColors, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.pointAttribs, 0, 2 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.pointIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.pointIndices, 0, tessGeo.pointIndexCount), PGL.GL_STATIC_DRAW); } @@ -1400,17 +1404,17 @@ public class PGraphicsOpenGL extends PGraphics { protected void deletePointBuffers() { if (pointBuffersCreated) { - deleteVertexBufferObject(glPointVertexBufferID, pointBuffersContext.code()); - glPointVertexBufferID = 0; + deleteVertexBufferObject(glPointVertex, pointBuffersContext.code()); + glPointVertex = 0; - deleteVertexBufferObject(glPointColorBufferID, pointBuffersContext.code()); - glPointColorBufferID = 0; + deleteVertexBufferObject(glPointColor, pointBuffersContext.code()); + glPointColor = 0; - deleteVertexBufferObject(glPointAttribBufferID, pointBuffersContext.code()); - glPointAttribBufferID = 0; + deleteVertexBufferObject(glPointAttrib, pointBuffersContext.code()); + glPointAttrib = 0; - deleteVertexBufferObject(glPointIndexBufferID, pointBuffersContext.code()); - glPointIndexBufferID = 0; + deleteVertexBufferObject(glPointIndex, pointBuffersContext.code()); + glPointIndex = 0; pointBuffersCreated = false; } @@ -2475,23 +2479,23 @@ public class PGraphicsOpenGL extends PGraphics { cache.indexOffset[n] + cache.indexCount[n] - ioffset; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(glPolyVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(glPolyColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setVertexAttribute(glPolyVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(glPolyColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); if (lights) { - shader.setNormalAttribute(glPolyNormalBufferID, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT); - shader.setAmbientAttribute(glPolyAmbientBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setSpecularAttribute(glPolySpecularBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setEmissiveAttribute(glPolyEmissiveBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setShininessAttribute(glPolyShininessBufferID, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); + shader.setNormalAttribute(glPolyNormal, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT); + shader.setAmbientAttribute(glPolyAmbient, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setSpecularAttribute(glPolySpecular, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setEmissiveAttribute(glPolyEmissive, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setShininessAttribute(glPolyShininess, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); } if (tex != null) { - shader.setTexcoordAttribute(glPolyTexcoordBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); + shader.setTexcoordAttribute(glPolyTexcoord, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); shader.setTexture(tex); } - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -2613,11 +2617,11 @@ public class PGraphicsOpenGL extends PGraphics { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(glLineVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(glLineColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setLineAttribute(glLineAttribBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setVertexAttribute(glLineVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(glLineColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setLineAttribute(glLineAttrib, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -2711,11 +2715,11 @@ public class PGraphicsOpenGL extends PGraphics { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(glPointVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(glPointColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setPointAttribute(glPointAttribBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); + shader.setVertexAttribute(glPointVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(glPointColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setPointAttribute(glPointAttrib, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -4977,7 +4981,7 @@ public class PGraphicsOpenGL extends PGraphics { if (primarySurface) { loadTextureImpl(POINT, false); // (first making sure that the screen texture is valid). } - pgl.copyToTexture(texture.glTarget, texture.glFormat, texture.glID, + pgl.copyToTexture(texture.glTarget, texture.glFormat, texture.glName, x, y, w, h, IntBuffer.wrap(rgbaPixels)); if (primarySurface || offscreenMultisample) { @@ -5096,14 +5100,14 @@ public class PGraphicsOpenGL extends PGraphics { protected void drawTexture() { - pgl.drawTexture(texture.glTarget, texture.glID, + pgl.drawTexture(texture.glTarget, texture.glName, texture.glWidth, texture.glHeight, 0, 0, width, height); } protected void drawTexture(int x, int y, int w, int h) { - pgl.drawTexture(texture.glTarget, texture.glID, + pgl.drawTexture(texture.glTarget, texture.glName, texture.glWidth, texture.glHeight, x, y, x + w, y + h); } @@ -5194,6 +5198,57 @@ public class PGraphicsOpenGL extends PGraphics { temp.filter(kind, param); set(0, 0, temp); } + + + public void filter(Object shader) { + if (!(shader instanceof PolyTexShader)) { + PGraphics.showWarning("Object is not a valid shader"); + return; + } + + PolyTexShader texShader = (PolyTexShader)shader; + +// if (shader instanceof FilterShader) { +// +// } + + if (primarySurface) { + + + } else { + if (textureCopy == null) { + Texture.Parameters params = new Texture.Parameters(ARGB, Texture.BILINEAR, false); + textureCopy = new Texture(parent, width, height, params); + textureCopy.setFlippedY(true); + } + + flush(); + + // Disable writing to the depth buffer, so that after applying the filter we can + // still use the depth information to properly add geometry to the scene. + + offscreenFramebuffer.setColorBuffer(textureCopy); + offscreenFramebuffer.clear(); + + // Disable depth test so the texture overwrites everything else. + + beginPGL(); + pgl.drawTexture(texture.glTarget, texture.glName, + texture.glWidth, texture.glHeight, + 0, 0, width, height); + endPGL(); + + offscreenFramebuffer.setColorBuffer(texture); + offscreenFramebuffer.clear(); + + beginPGL(); + pgl.drawTextureCustom(textureCopy.glTarget, textureCopy.glName, + textureCopy.glWidth, textureCopy.glHeight, + 0, 0, width, height, texShader.glProgram); + endPGL(); + } + + } ////////////////////////////////////////////////////////////// @@ -5367,38 +5422,31 @@ public class PGraphicsOpenGL extends PGraphics { * @param img the image to have a texture metadata associated to it */ public Texture getTexture(PImage img) { - Texture tex = (Texture)img.getCache(pgPrimary); - if (tex == null) { - tex = addTexture(img); - } else { - if (tex.contextIsOutdated()) { - tex = addTexture(img); + Texture tex = (Texture)initCache(img); + + if (img.isModified()) { + if (img.width != tex.width || img.height != tex.height) { + tex.init(img.width, img.height); } + updateTexture(img, tex); + } - if (img.isModified()) { - if (img.width != tex.width || img.height != tex.height) { - tex.init(img.width, img.height); - } - updateTexture(img, tex); - } - - if (tex.hasBuffers()) { - tex.bufferUpdate(); - } + if (tex.hasBuffers()) { + tex.bufferUpdate(); } return tex; } - public void initCache(PImage img) { + public Object initCache(PImage img) { Texture tex = (Texture)img.getCache(pgPrimary); - if (tex == null) { + if (tex == null || tex.contextIsOutdated()) { tex = addTexture(img); - } else { - if (tex.contextIsOutdated()) { - tex = addTexture(img); + if (img.pixels != null) { + tex.set(img.pixels); } - } + } + return tex; } @@ -5419,32 +5467,22 @@ public class PGraphicsOpenGL extends PGraphics { params.sampling = textureSampling; if (params.sampling == Texture.TRILINEAR && !params.mipmaps) { params.sampling = Texture.BILINEAR; - PGraphics.showWarning("TRILINEAR texture sampling requires mipmaps, which are disabled. Will use BILINEAR instead."); + PGraphics.showWarning("TRILINEAR texture sampling requires mipmaps, which are disabled. I will use BILINEAR instead."); } params.wrapU = textureWrap; - params.wrapV = textureWrap; - img.setParams(pgPrimary, params); - } - if (img.parent == null) { - img.parent = parent; - } - Texture tex = new Texture(img.parent, img.width, img.height, params); - if (img.pixels == null) { - img.loadPixels(); - } - if (img.pixels != null) tex.set(img.pixels); - img.setCache(pgPrimary, tex); - return tex; + params.wrapV = textureWrap; + } + return addTexture(img, params); } protected Texture addTexture(PImage img, Texture.Parameters params) { - Texture tex = new Texture(img.parent, img.width, img.height, params); - if (img.pixels == null) { - img.loadPixels(); + if (img.parent == null) { + img.parent = parent; } - if (img.pixels != null) tex.set(img.pixels); + Texture tex = new Texture(img.parent, img.width, img.height, params); img.setCache(pgPrimary, tex); + img.setParams(pgPrimary, params); return tex; } @@ -5458,6 +5496,7 @@ public class PGraphicsOpenGL extends PGraphics { img.height = tex.height; img.format = ARGB; img.setCache(pgPrimary, tex); + img.setParams(pgPrimary, tex.getParameters()); return img; } @@ -5590,8 +5629,8 @@ public class PGraphicsOpenGL extends PGraphics { // SHADER HANDLING - public PShader loadShader(String vertFilename, String fragFilename, int kind) { - if (kind == PShader.FLAT) { + public Object loadShader(String vertFilename, String fragFilename, int kind) { + if (kind == PShader.FLAT) { return new PolyFlatShader(parent, vertFilename, fragFilename); } else if (kind == PShader.LIT) { return new PolyLightShader(parent, vertFilename, fragFilename); @@ -5610,7 +5649,7 @@ public class PGraphicsOpenGL extends PGraphics { } - public PShader loadShader(String fragFilename, int kind) { + public Object loadShader(String fragFilename, int kind) { PShader shader; if (kind == PShader.FLAT) { shader = new PolyFlatShader(parent); @@ -5637,9 +5676,23 @@ public class PGraphicsOpenGL extends PGraphics { shader.setFragmentShader(fragFilename); return shader; } + + + public Object loadShader(String vertFilename, String fragFilename) { + return loadShader(vertFilename, fragFilename, PShader.TEXTURED); + } + + + public Object loadShader(String fragFilename) { + return loadShader(fragFilename, PShader.TEXTURED); + } - public void setShader(PShader shader, int kind) { + public void shader(Object shader, int kind) { + if (!(shader instanceof PShader)) { + PGraphics.showWarning("Object is not a valid shader!"); + return; + } flush(); // Flushing geometry with a different shader. if (kind == PShader.FLAT) { polyFlatShader = (PolyFlatShader) shader; @@ -5659,7 +5712,45 @@ public class PGraphicsOpenGL extends PGraphics { } - public PShader getShader(int kind) { + public void resetShader(int kind) { + flush(); // Flushing geometry with a different shader. + if (kind == PShader.FLAT) { + if (defPolyFlatShader == null) { + defPolyFlatShader = new PolyFlatShader(parent, defPolyFlatShaderVertURL, defPolyNoTexShaderFragURL); + } + polyFlatShader = defPolyFlatShader; + } else if (kind == PShader.LIT) { + if (defPolyLightShader == null) { + defPolyLightShader = new PolyLightShader(parent, defPolyLightShaderVertURL, defPolyNoTexShaderFragURL); + } + polyLightShader = defPolyLightShader; + } else if (kind == PShader.TEXTURED) { + if (defPolyTexShader == null) { + defPolyTexShader = new PolyTexShader(parent, defPolyTexShaderVertURL, defPolyTexShaderFragURL); + } + polyTexShader = defPolyTexShader; + } else if (kind == PShader.FULL) { + if (defPolyFullShader == null) { + defPolyFullShader = new PolyFullShader(parent, defPolyFullShaderVertURL, defPolyTexShaderFragURL); + } + polyFullShader = defPolyFullShader; + } else if (kind == PShader.LINE) { + if (defLineShader == null) { + defLineShader = new LineShader(parent, defLineShaderVertURL, defLineShaderFragURL); + } + lineShader = defLineShader; + } else if (kind == PShader.POINT) { + if (defPointShader == null) { + defPointShader = new PointShader(parent, defPointShaderVertURL, defPointShaderFragURL); + } + pointShader = defPointShader; + } else { + PGraphics.showWarning("Wrong shader type"); + } + } + + + public Object getShader(int kind) { PShader shader; if (kind == PShader.FLAT) { if (polyFlatShader == null) { @@ -5717,47 +5808,9 @@ public class PGraphicsOpenGL extends PGraphics { shader.loadAttributes(); shader.loadUniforms(); return shader; - } + } - public void defaultShader(int kind) { - flush(); // Flushing geometry with a different shader. - if (kind == PShader.FLAT) { - if (defPolyFlatShader == null) { - defPolyFlatShader = new PolyFlatShader(parent, defPolyFlatShaderVertURL, defPolyNoTexShaderFragURL); - } - polyFlatShader = defPolyFlatShader; - } else if (kind == PShader.LIT) { - if (defPolyLightShader == null) { - defPolyLightShader = new PolyLightShader(parent, defPolyLightShaderVertURL, defPolyNoTexShaderFragURL); - } - polyLightShader = defPolyLightShader; - } else if (kind == PShader.TEXTURED) { - if (defPolyTexShader == null) { - defPolyTexShader = new PolyTexShader(parent, defPolyTexShaderVertURL, defPolyTexShaderFragURL); - } - polyTexShader = defPolyTexShader; - } else if (kind == PShader.FULL) { - if (defPolyFullShader == null) { - defPolyFullShader = new PolyFullShader(parent, defPolyFullShaderVertURL, defPolyTexShaderFragURL); - } - polyFullShader = defPolyFullShader; - } else if (kind == PShader.LINE) { - if (defLineShader == null) { - defLineShader = new LineShader(parent, defLineShaderVertURL, defLineShaderFragURL); - } - lineShader = defLineShader; - } else if (kind == PShader.POINT) { - if (defPointShader == null) { - defPointShader = new PointShader(parent, defPointShaderVertURL, defPointShaderFragURL); - } - pointShader = defPointShader; - } else { - PGraphics.showWarning("Wrong shader type"); - } - } - - protected PolyShader getPolyShader(boolean lit, boolean tex) { PolyShader shader; if (lit) { @@ -5831,7 +5884,7 @@ public class PGraphicsOpenGL extends PGraphics { return pointShader; } - + protected class PolyShader extends PShader { public PolyShader(PApplet parent) { super(parent); @@ -5878,22 +5931,22 @@ public class PGraphicsOpenGL extends PGraphics { } public void loadAttributes() { - inVertexLoc = getAttribLocation("inVertex"); - inColorLoc = getAttribLocation("inColor"); + inVertexLoc = getAttributeLoc("inVertex"); + inColorLoc = getAttributeLoc("inColor"); } public void loadUniforms() { - projmodelviewMatrixLoc = getUniformLocation("projmodelviewMatrix"); - modelviewMatrixLoc = getUniformLocation("modelviewMatrix"); - projectionMatrixLoc = getUniformLocation("projectionMatrix"); + projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); + modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); + projectionMatrixLoc = getUniformLoc("projectionMatrix"); } public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); } public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); } public void bind() { @@ -5905,17 +5958,17 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent != null) { if (-1 < projmodelviewMatrixLoc) { pgCurrent.updateGLProjmodelview(); - setMat4Uniform(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); + setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); } if (-1 < modelviewMatrixLoc) { pgCurrent.updateGLModelview(); - setMat4Uniform(modelviewMatrixLoc, pgCurrent.glModelview); + setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview); } if (-1 < projectionMatrixLoc) { pgCurrent.updateGLProjection(); - setMat4Uniform(projectionMatrixLoc, pgCurrent.glProjection); + setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); } } } @@ -5968,58 +6021,58 @@ public class PGraphicsOpenGL extends PGraphics { } public void loadAttributes() { - inVertexLoc = getAttribLocation("inVertex"); - inColorLoc = getAttribLocation("inColor"); - inNormalLoc = getAttribLocation("inNormal"); + inVertexLoc = getAttributeLoc("inVertex"); + inColorLoc = getAttributeLoc("inColor"); + inNormalLoc = getAttributeLoc("inNormal"); - inAmbientLoc = getAttribLocation("inAmbient"); - inSpecularLoc = getAttribLocation("inSpecular"); - inEmissiveLoc = getAttribLocation("inEmissive"); - inShineLoc = getAttribLocation("inShine"); + inAmbientLoc = getAttributeLoc("inAmbient"); + inSpecularLoc = getAttributeLoc("inSpecular"); + inEmissiveLoc = getAttributeLoc("inEmissive"); + inShineLoc = getAttributeLoc("inShine"); } public void loadUniforms() { - projmodelviewMatrixLoc = getUniformLocation("projmodelviewMatrix"); - modelviewMatrixLoc = getUniformLocation("modelviewMatrix"); - projectionMatrixLoc = getUniformLocation("projectionMatrix"); - normalMatrixLoc = getUniformLocation("normalMatrix"); + projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); + modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); + projectionMatrixLoc = getUniformLoc("projectionMatrix"); + normalMatrixLoc = getUniformLoc("normalMatrix"); - lightCountLoc = getUniformLocation("lightCount"); - lightPositionLoc = getUniformLocation("lightPosition"); - lightNormalLoc = getUniformLocation("lightNormal"); - lightAmbientLoc = getUniformLocation("lightAmbient"); - lightDiffuseLoc = getUniformLocation("lightDiffuse"); - lightSpecularLoc = getUniformLocation("lightSpecular"); - lightFalloffCoefficientsLoc = getUniformLocation("lightFalloffCoefficients"); - lightSpotParametersLoc = getUniformLocation("lightSpotParameters"); + lightCountLoc = getUniformLoc("lightCount"); + lightPositionLoc = getUniformLoc("lightPosition"); + lightNormalLoc = getUniformLoc("lightNormal"); + lightAmbientLoc = getUniformLoc("lightAmbient"); + lightDiffuseLoc = getUniformLoc("lightDiffuse"); + lightSpecularLoc = getUniformLoc("lightSpecular"); + lightFalloffCoefficientsLoc = getUniformLoc("lightFalloffCoefficients"); + lightSpotParametersLoc = getUniformLoc("lightSpotParameters"); } public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); } public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); } public void setNormalAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inNormalLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inNormalLoc, vboId, size, type, false, stride, offset); } public void setAmbientAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inAmbientLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inAmbientLoc, vboId, size, type, true, stride, offset); } public void setSpecularAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inSpecularLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inSpecularLoc, vboId, size, type, true, stride, offset); } public void setEmissiveAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inEmissiveLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inEmissiveLoc, vboId, size, type, true, stride, offset); } public void setShininessAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inShineLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inShineLoc, vboId, size, type, false, stride, offset); } public void bind() { @@ -6037,32 +6090,32 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent != null) { if (-1 < projmodelviewMatrixLoc) { pgCurrent.updateGLProjmodelview(); - setMat4Uniform(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); + setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); } if (-1 < modelviewMatrixLoc) { pgCurrent.updateGLModelview(); - setMat4Uniform(modelviewMatrixLoc, pgCurrent.glModelview); + setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview); } if (-1 < projectionMatrixLoc) { pgCurrent.updateGLProjection(); - setMat4Uniform(projectionMatrixLoc, pgCurrent.glProjection); + setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); } if (-1 < normalMatrixLoc) { pgCurrent.updateGLNormal(); - setMat3Uniform(normalMatrixLoc, pgCurrent.glNormal); + setUniformMatrix(normalMatrixLoc, pgCurrent.glNormal); } - setIntUniform(lightCountLoc, pgCurrent.lightCount); - setFloatVecUniform(lightPositionLoc, pgCurrent.lightPosition, 4); - setFloatVecUniform(lightNormalLoc, pgCurrent.lightNormal, 3); - setFloatVecUniform(lightAmbientLoc, pgCurrent.lightAmbient, 3); - setFloatVecUniform(lightDiffuseLoc, pgCurrent.lightDiffuse, 3); - setFloatVecUniform(lightSpecularLoc, pgCurrent.lightSpecular, 3); - setFloatVecUniform(lightFalloffCoefficientsLoc, pgCurrent.lightFalloffCoefficients, 3); - setFloatVecUniform(lightSpotParametersLoc, pgCurrent.lightSpotParameters, 2); + setUniformValue(lightCountLoc, pgCurrent.lightCount); + setUniformVector(lightPositionLoc, pgCurrent.lightPosition, 4); + setUniformVector(lightNormalLoc, pgCurrent.lightNormal, 3); + setUniformVector(lightAmbientLoc, pgCurrent.lightAmbient, 3); + setUniformVector(lightDiffuseLoc, pgCurrent.lightDiffuse, 3); + setUniformVector(lightSpecularLoc, pgCurrent.lightSpecular, 3); + setUniformVector(lightFalloffCoefficientsLoc, pgCurrent.lightFalloffCoefficients, 3); + setUniformVector(lightSpotParametersLoc, pgCurrent.lightSpotParameters, 2); } } @@ -6106,18 +6159,18 @@ public class PGraphicsOpenGL extends PGraphics { public void loadUniforms() { super.loadUniforms(); - texcoordMatrixLoc = getUniformLocation("texcoordMatrix"); - texcoordOffsetLoc = getUniformLocation("texcoordOffset"); + texcoordMatrixLoc = getUniformLoc("texcoordMatrix"); + texcoordOffsetLoc = getUniformLoc("texcoordOffset"); } public void loadAttributes() { super.loadAttributes(); - inTexcoordLoc = getAttribLocation("inTexcoord"); + inTexcoordLoc = getAttributeLoc("inTexcoord"); } public void setTexcoordAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inTexcoordLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset); } public void setTexture(Texture tex) { @@ -6149,10 +6202,10 @@ public class PGraphicsOpenGL extends PGraphics { tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv; tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0; tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0; - setMat4Uniform(texcoordMatrixLoc, tcmat); + setUniformMatrix(texcoordMatrixLoc, tcmat); } - setFloatUniform(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); + setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); } public void bind() { @@ -6168,7 +6221,7 @@ public class PGraphicsOpenGL extends PGraphics { } } - + protected class PolyFullShader extends PolyLightShader { protected int inTexcoordLoc; @@ -6192,18 +6245,18 @@ public class PGraphicsOpenGL extends PGraphics { public void loadUniforms() { super.loadUniforms(); - texcoordMatrixLoc = getUniformLocation("texcoordMatrix"); - texcoordOffsetLoc = getUniformLocation("texcoordOffset"); + texcoordMatrixLoc = getUniformLoc("texcoordMatrix"); + texcoordOffsetLoc = getUniformLoc("texcoordOffset"); } public void loadAttributes() { super.loadAttributes(); - inTexcoordLoc = getAttribLocation("inTexcoord"); + inTexcoordLoc = getAttributeLoc("inTexcoord"); } public void setTexcoordAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inTexcoordLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset); } public void setTexture(Texture tex) { @@ -6235,10 +6288,10 @@ public class PGraphicsOpenGL extends PGraphics { tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv; tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0; tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0; - setMat4Uniform(texcoordMatrixLoc, tcmat); + setUniformMatrix(texcoordMatrixLoc, tcmat); } - setFloatUniform(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); + setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); } public void bind() { @@ -6281,36 +6334,31 @@ public class PGraphicsOpenGL extends PGraphics { } public void loadAttributes() { - inVertexLoc = getAttribLocation("inVertex"); - inColorLoc = getAttribLocation("inColor"); - inAttribLoc = getAttribLocation("inLine"); + inVertexLoc = getAttributeLoc("inVertex"); + inColorLoc = getAttributeLoc("inColor"); + inAttribLoc = getAttributeLoc("inLine"); } public void loadUniforms() { - projmodelviewMatrixLoc = getUniformLocation("projmodelviewMatrix"); - modelviewMatrixLoc = getUniformLocation("modelviewMatrix"); - projectionMatrixLoc = getUniformLocation("projectionMatrix"); + projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); + modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); + projectionMatrixLoc = getUniformLoc("projectionMatrix"); - viewportLoc = getUniformLocation("viewport"); - perspectiveLoc = getUniformLocation("perspective"); - zfactorLoc = getUniformLocation("zfactor"); - } - - public void setAttribute(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, vboId); - pgl.glVertexAttribPointer(loc, size, type, normalized, stride, offset); + viewportLoc = getUniformLoc("viewport"); + perspectiveLoc = getUniformLoc("perspective"); + zfactorLoc = getUniformLoc("zfactor"); } public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); } public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); } public void setLineAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inAttribLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inAttribLoc, vboId, size, type, false, stride, offset); } public void bind() { @@ -6323,31 +6371,35 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent != null) { if (-1 < projmodelviewMatrixLoc) { pgCurrent.updateGLProjmodelview(); - setMat4Uniform(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); + setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); } if (-1 < modelviewMatrixLoc) { pgCurrent.updateGLModelview(); - setMat4Uniform(modelviewMatrixLoc, pgCurrent.glModelview); + setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview); } if (-1 < projectionMatrixLoc) { pgCurrent.updateGLProjection(); - setMat4Uniform(projectionMatrixLoc, pgCurrent.glProjection); + setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); } - setFloatUniform(viewportLoc, pgCurrent.viewport[0], pgCurrent.viewport[1], pgCurrent.viewport[2], pgCurrent.viewport[3]); + float x = pgCurrent.viewport[0]; + float y = pgCurrent.viewport[1]; + float w = pgCurrent.viewport[2]; + float h = pgCurrent.viewport[3]; + setUniformValue(viewportLoc, x, y, w, h); if (pgCurrent.hintEnabled(ENABLE_PERSPECTIVE_CORRECTED_LINES)) { - setIntUniform(perspectiveLoc, 1); + setUniformValue(perspectiveLoc, 1); } else { - setIntUniform(perspectiveLoc, 0); + setUniformValue(perspectiveLoc, 0); } if (pgCurrent.hintEnabled(ENABLE_ACCURATE_2D)) { - setFloatUniform(zfactorLoc, 1); + setUniformValue(zfactorLoc, 1.0f); } else { - setFloatUniform(zfactorLoc, 0.99f); + setUniformValue(zfactorLoc, 0.99f); } } } @@ -6386,32 +6438,27 @@ public class PGraphicsOpenGL extends PGraphics { } public void loadAttributes() { - inVertexLoc = getAttribLocation("inVertex"); - inColorLoc = getAttribLocation("inColor"); - inPointLoc = getAttribLocation("inPoint"); + inVertexLoc = getAttributeLoc("inVertex"); + inColorLoc = getAttributeLoc("inColor"); + inPointLoc = getAttributeLoc("inPoint"); } public void loadUniforms() { - projmodelviewMatrixLoc = getUniformLocation("projmodelviewMatrix"); - modelviewMatrixLoc = getUniformLocation("modelviewMatrix"); - projectionMatrixLoc = getUniformLocation("projectionMatrix"); - } - - public void setAttribute(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, vboId); - pgl.glVertexAttribPointer(loc, size, type, normalized, stride, offset); + projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); + modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); + projectionMatrixLoc = getUniformLoc("projectionMatrix"); } public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); } public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); } public void setPointAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inPointLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inPointLoc, vboId, size, type, false, stride, offset); } public void bind() { @@ -6424,17 +6471,17 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent != null) { if (-1 < projmodelviewMatrixLoc) { pgCurrent.updateGLProjmodelview(); - setMat4Uniform(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); + setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); } if (-1 < modelviewMatrixLoc) { pgCurrent.updateGLModelview(); - setMat4Uniform(modelviewMatrixLoc, pgCurrent.glModelview); + setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview); } if (-1 < projectionMatrixLoc) { pgCurrent.updateGLProjection(); - setMat4Uniform(projectionMatrixLoc, pgCurrent.glProjection); + setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); } } } @@ -6450,6 +6497,7 @@ public class PGraphicsOpenGL extends PGraphics { } } + ////////////////////////////////////////////////////////////// // Utils diff --git a/android/core/src/processing/opengl/PShader.java b/android/core/src/processing/opengl/PShader.java index f839537b1..86ee6bec9 100644 --- a/android/core/src/processing/opengl/PShader.java +++ b/android/core/src/processing/opengl/PShader.java @@ -36,12 +36,13 @@ import java.util.HashMap; */ public class PShader { // shaders constants - static public final int FLAT = 0; - static public final int LIT = 1; - static public final int TEXTURED = 2; - static public final int FULL = 3; - static public final int LINE = 4; - static public final int POINT = 5; + static public final int FILTER = 0; + static public final int FLAT = 1; + static public final int LIT = 2; + static public final int TEXTURED = 3; + static public final int FULL = 4; + static public final int LINE = 5; + static public final int POINT = 6; protected PApplet parent; // The main renderer associated to the parent PApplet. @@ -55,9 +56,9 @@ public class PShader { protected PGL pgl; protected PGL.Context context; // The context that created this shader. - public int glProgramObjectID; - public int glVertexShaderID; - public int glFragmentShaderID; + public int glProgram; + public int glVertex; + public int glFragment; protected URL vertexURL; protected URL fragmentURL; @@ -83,9 +84,9 @@ public class PShader { this.vertexFilename = null; this.fragmentFilename = null; - glProgramObjectID = 0; - glVertexShaderID = 0; - glFragmentShaderID = 0; + glProgram = 0; + glVertex = 0; + glFragment = 0; bound = false; } @@ -118,9 +119,9 @@ public class PShader { this.vertexFilename = vertFilename; this.fragmentFilename = fragFilename; - glProgramObjectID = 0; - glVertexShaderID = 0; - glFragmentShaderID = 0; + glProgram = 0; + glVertex = 0; + glFragment = 0; } @@ -134,22 +135,22 @@ public class PShader { this.vertexFilename = null; this.fragmentFilename = null; - glProgramObjectID = 0; - glVertexShaderID = 0; - glFragmentShaderID = 0; + glProgram = 0; + glVertex = 0; + glFragment = 0; } protected void finalize() throws Throwable { try { - if (glVertexShaderID != 0) { - pgMain.finalizeGLSLVertShaderObject(glVertexShaderID, context.code()); + if (glVertex != 0) { + pgMain.finalizeGLSLVertShaderObject(glVertex, context.code()); } - if (glFragmentShaderID != 0) { - pgMain.finalizeGLSLFragShaderObject(glFragmentShaderID, context.code()); + if (glFragment != 0) { + pgMain.finalizeGLSLFragShaderObject(glFragment, context.code()); } - if (glProgramObjectID != 0) { - pgMain.finalizeGLSLProgramObject(glProgramObjectID, context.code()); + if (glProgram != 0) { + pgMain.finalizeGLSLProgramObject(glProgram, context.code()); } } finally { super.finalize(); @@ -182,7 +183,7 @@ public class PShader { */ public void bind() { init(); - pgl.glUseProgram(glProgramObjectID); + pgl.glUseProgram(glProgram); bound = true; consumeUniforms(); } @@ -328,9 +329,9 @@ public class PShader { * @param name String * @return int */ - protected int getAttribLocation(String name) { + protected int getAttributeLoc(String name) { init(); - return pgl.glGetAttribLocation(glProgramObjectID, name); + return pgl.glGetAttribLocation(glProgram, name); } @@ -340,13 +341,13 @@ public class PShader { * @param name String * @return int */ - protected int getUniformLocation(String name) { + protected int getUniformLoc(String name) { init(); - return pgl.glGetUniformLocation(glProgramObjectID, name); + return pgl.glGetUniformLocation(glProgram, name); } - protected void setAttribute(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) { + protected void setAttributeVBO(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) { if (-1 < loc) { pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, vboId); pgl.glVertexAttribPointer(loc, size, type, normalized, stride, offset); @@ -354,62 +355,62 @@ public class PShader { } - protected void setIntUniform(int loc, int x) { + protected void setUniformValue(int loc, int x) { if (-1 < loc) { pgl.glUniform1i(loc, x); } } - protected void setIntUniform(int loc, int x, int y) { + protected void setUniformValue(int loc, int x, int y) { if (-1 < loc) { pgl.glUniform2i(loc, x, y); } } - protected void setIntUniform(int loc, int x, int y, int z) { + protected void setUniformValue(int loc, int x, int y, int z) { if (-1 < loc) { pgl.glUniform3i(loc, x, y, z); } } - protected void setIntUniform(int loc, int x, int y, int z, int w) { + protected void setUniformValue(int loc, int x, int y, int z, int w) { if (-1 < loc) { pgl.glUniform4i(loc, x, y, z, w); } } - protected void setFloatUniform(int loc, float x) { + protected void setUniformValue(int loc, float x) { if (-1 < loc) { pgl.glUniform1f(loc, x); } } - protected void setFloatUniform(int loc, float x, float y) { + protected void setUniformValue(int loc, float x, float y) { if (-1 < loc) { pgl.glUniform2f(loc, x, y); } } - protected void setFloatUniform(int loc, float x, float y, float z) { + protected void setUniformValue(int loc, float x, float y, float z) { if (-1 < loc) { pgl.glUniform3f(loc, x, y, z); } } - protected void setFloatUniform(int loc, float x, float y, float z, float w) { + protected void setUniformValue(int loc, float x, float y, float z, float w) { if (-1 < loc) { pgl.glUniform4f(loc, x, y, z, w); } } - protected void setIntVecUniform(int loc, int[] vec, int ncoords) { + protected void setUniformVector(int loc, int[] vec, int ncoords) { if (-1 < loc) { if (ncoords == 1) { pgl.glUniform1iv(loc, vec.length, vec, 0); @@ -424,7 +425,7 @@ public class PShader { } - protected void setFloatVecUniform(int loc, float[] vec, int ncoords) { + protected void setUniformVector(int loc, float[] vec, int ncoords) { if (-1 < loc) { if (ncoords == 1) { pgl.glUniform1fv(loc, vec.length, vec, 0); @@ -439,25 +440,18 @@ public class PShader { } - protected void setMat2Uniform(int loc, float[] mat) { + protected void setUniformMatrix(int loc, float[] mat) { if (-1 < loc) { - pgl.glUniformMatrix2fv(loc, 1, false, mat, 0); + if (mat.length == 4) { + pgl.glUniformMatrix2fv(loc, 1, false, mat, 0); + } else if (mat.length == 9) { + pgl.glUniformMatrix3fv(loc, 1, false, mat, 0); + } else if (mat.length == 16) { + pgl.glUniformMatrix4fv(loc, 1, false, mat, 0); + } } } - - protected void setMat3Uniform(int loc, float[] mat) { - if (-1 < loc) { - pgl.glUniformMatrix3fv(loc, 1, false, mat, 0); - } - } - - - protected void setMat4Uniform(int loc, float[] mat) { - if (-1 < loc) { - pgl.glUniformMatrix4fv(loc, 1, false, mat, 0); - } - } /* @@ -494,7 +488,7 @@ public class PShader { protected void setUniformImpl(String name, int type, Object value) { - int loc = getUniformLocation(name); + int loc = getUniformLoc(name); if (-1 < loc) { if (uniformValues == null) { uniformValues = new HashMap(); @@ -575,9 +569,9 @@ public class PShader { protected void init() { - if (glProgramObjectID == 0 || contextIsOutdated()) { + if (glProgram == 0 || contextIsOutdated()) { context = pgl.getCurrentContext(); - glProgramObjectID = pgMain.createGLSLProgramObject(context.code()); + glProgram = pgMain.createGLSLProgramObject(context.code()); boolean hasVert = false; if (vertexFilename != null) { @@ -609,25 +603,25 @@ public class PShader { if (vertRes && fragRes) { if (hasVert) { - pgl.glAttachShader(glProgramObjectID, glVertexShaderID); + pgl.glAttachShader(glProgram, glVertex); } if (hasFrag) { - pgl.glAttachShader(glProgramObjectID, glFragmentShaderID); + pgl.glAttachShader(glProgram, glFragment); } - pgl.glLinkProgram(glProgramObjectID); + pgl.glLinkProgram(glProgram); int[] linked = new int[1]; - pgl.glGetProgramiv(glProgramObjectID, PGL.GL_LINK_STATUS, linked, 0); + pgl.glGetProgramiv(glProgram, PGL.GL_LINK_STATUS, linked, 0); if (linked[0] == PGL.GL_FALSE) { - PGraphics.showException("Cannot link shader program:\n" + pgl.glGetProgramInfoLog(glProgramObjectID)); + PGraphics.showException("Cannot link shader program:\n" + pgl.glGetProgramInfoLog(glProgram)); } - pgl.glValidateProgram(glProgramObjectID); + pgl.glValidateProgram(glProgram); int[] validated = new int[1]; - pgl.glGetProgramiv(glProgramObjectID, PGL.GL_VALIDATE_STATUS, validated, 0); + pgl.glGetProgramiv(glProgram, PGL.GL_VALIDATE_STATUS, validated, 0); if (validated[0] == PGL.GL_FALSE) { - PGraphics.showException("Cannot validate shader program:\n" + pgl.glGetProgramInfoLog(glProgramObjectID)); + PGraphics.showException("Cannot validate shader program:\n" + pgl.glGetProgramInfoLog(glProgram)); } } } @@ -637,13 +631,13 @@ public class PShader { protected boolean contextIsOutdated() { boolean outdated = !pgl.contextIsCurrent(context); if (outdated) { - pgMain.removeGLSLProgramObject(glProgramObjectID, context.code()); - pgMain.removeGLSLVertShaderObject(glVertexShaderID, context.code()); - pgMain.removeGLSLFragShaderObject(glFragmentShaderID, context.code()); + pgMain.removeGLSLProgramObject(glProgram, context.code()); + pgMain.removeGLSLVertShaderObject(glVertex, context.code()); + pgMain.removeGLSLFragShaderObject(glFragment, context.code()); - glProgramObjectID = 0; - glVertexShaderID = 0; - glFragmentShaderID = 0; + glProgram = 0; + glVertex = 0; + glFragment = 0; } return outdated; } @@ -707,15 +701,15 @@ public class PShader { * @param shaderSource a string containing the shader's code */ protected boolean compileVertexShader() { - glVertexShaderID = pgMain.createGLSLVertShaderObject(context.code()); + glVertex = pgMain.createGLSLVertShaderObject(context.code()); - pgl.glShaderSource(glVertexShaderID, vertexShaderSource); - pgl.glCompileShader(glVertexShaderID); + pgl.glShaderSource(glVertex, vertexShaderSource); + pgl.glCompileShader(glVertex); int[] compiled = new int[1]; - pgl.glGetShaderiv(glVertexShaderID, PGL.GL_COMPILE_STATUS, compiled, 0); + pgl.glGetShaderiv(glVertex, PGL.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == PGL.GL_FALSE) { - PGraphics.showException("Cannot compile vertex shader:\n" + pgl.glGetShaderInfoLog(glVertexShaderID)); + PGraphics.showException("Cannot compile vertex shader:\n" + pgl.glGetShaderInfoLog(glVertex)); return false; } else { return true; @@ -727,15 +721,15 @@ public class PShader { * @param shaderSource a string containing the shader's code */ protected boolean compileFragmentShader() { - glFragmentShaderID = pgMain.createGLSLFragShaderObject(context.code()); + glFragment = pgMain.createGLSLFragShaderObject(context.code()); - pgl.glShaderSource(glFragmentShaderID, fragmentShaderSource); - pgl.glCompileShader(glFragmentShaderID); + pgl.glShaderSource(glFragment, fragmentShaderSource); + pgl.glCompileShader(glFragment); int[] compiled = new int[1]; - pgl.glGetShaderiv(glFragmentShaderID, PGL.GL_COMPILE_STATUS, compiled, 0); + pgl.glGetShaderiv(glFragment, PGL.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == PGL.GL_FALSE) { - PGraphics.showException("Cannot compile fragment shader:\n" + pgl.glGetShaderInfoLog(glFragmentShaderID)); + PGraphics.showException("Cannot compile fragment shader:\n" + pgl.glGetShaderInfoLog(glFragment)); return false; } else { return true; @@ -754,17 +748,17 @@ public class PShader { protected void release() { - if (glVertexShaderID != 0) { - pgMain.deleteGLSLVertShaderObject(glVertexShaderID, context.code()); - glVertexShaderID = 0; + if (glVertex != 0) { + pgMain.deleteGLSLVertShaderObject(glVertex, context.code()); + glVertex = 0; } - if (glFragmentShaderID != 0) { - pgMain.deleteGLSLFragShaderObject(glFragmentShaderID, context.code()); - glFragmentShaderID = 0; + if (glFragment != 0) { + pgMain.deleteGLSLFragShaderObject(glFragment, context.code()); + glFragment = 0; } - if (glProgramObjectID != 0) { - pgMain.deleteGLSLProgramObject(glProgramObjectID, context.code()); - glProgramObjectID = 0; + if (glProgram != 0) { + pgMain.deleteGLSLProgramObject(glProgram, context.code()); + glProgram = 0; } } diff --git a/android/core/src/processing/opengl/PShapeOpenGL.java b/android/core/src/processing/opengl/PShapeOpenGL.java index 4a4454ea1..c20cdc067 100644 --- a/android/core/src/processing/opengl/PShapeOpenGL.java +++ b/android/core/src/processing/opengl/PShapeOpenGL.java @@ -92,25 +92,25 @@ public class PShapeOpenGL extends PShape { // OpenGL buffers - public int glPolyVertexBufferID; - public int glPolyColorBufferID; - public int glPolyNormalBufferID; - public int glPolyTexcoordBufferID; - public int glPolyAmbientBufferID; - public int glPolySpecularBufferID; - public int glPolyEmissiveBufferID; - public int glPolyShininessBufferID; - public int glPolyIndexBufferID; + public int glPolyVertex; + public int glPolyColor; + public int glPolyNormal; + public int glPolyTexcoord; + public int glPolyAmbient; + public int glPolySpecular; + public int glPolyEmissive; + public int glPolyShininess; + public int glPolyIndex; - public int glLineVertexBufferID; - public int glLineColorBufferID; - public int glLineAttribBufferID; - public int glLineIndexBufferID; + public int glLineVertex; + public int glLineColor; + public int glLineAttrib; + public int glLineIndex; - public int glPointVertexBufferID; - public int glPointColorBufferID; - public int glPointAttribBufferID; - public int glPointIndexBufferID; + public int glPointVertex; + public int glPointColor; + public int glPointAttrib; + public int glPointIndex; // ........................................................ @@ -281,25 +281,25 @@ public class PShapeOpenGL extends PShape { pgl = pg.pgl; context = pgl.createEmptyContext(); - glPolyVertexBufferID = 0; - glPolyColorBufferID = 0; - glPolyNormalBufferID = 0; - glPolyTexcoordBufferID = 0; - glPolyAmbientBufferID = 0; - glPolySpecularBufferID = 0; - glPolyEmissiveBufferID = 0; - glPolyShininessBufferID = 0; - glPolyIndexBufferID = 0; + glPolyVertex = 0; + glPolyColor = 0; + glPolyNormal = 0; + glPolyTexcoord = 0; + glPolyAmbient = 0; + glPolySpecular = 0; + glPolyEmissive = 0; + glPolyShininess = 0; + glPolyIndex = 0; - glLineVertexBufferID = 0; - glLineColorBufferID = 0; - glLineAttribBufferID = 0; - glLineIndexBufferID = 0; + glLineVertex = 0; + glLineColor = 0; + glLineAttrib = 0; + glLineIndex = 0; - glPointVertexBufferID = 0; - glPointColorBufferID = 0; - glPointAttribBufferID = 0; - glPointIndexBufferID = 0; + glPointVertex = 0; + glPointColor = 0; + glPointAttrib = 0; + glPointIndex = 0; this.tessellator = PGraphicsOpenGL.tessellator; this.family = family; @@ -413,78 +413,78 @@ public class PShapeOpenGL extends PShape { protected void finalizePolyBuffers() { - if (glPolyVertexBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyVertexBufferID, context.code()); + if (glPolyVertex != 0) { + pg.finalizeVertexBufferObject(glPolyVertex, context.code()); } - if (glPolyColorBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyColorBufferID, context.code()); + if (glPolyColor != 0) { + pg.finalizeVertexBufferObject(glPolyColor, context.code()); } - if (glPolyNormalBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyNormalBufferID, context.code()); + if (glPolyNormal != 0) { + pg.finalizeVertexBufferObject(glPolyNormal, context.code()); } - if (glPolyTexcoordBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyTexcoordBufferID, context.code()); + if (glPolyTexcoord != 0) { + pg.finalizeVertexBufferObject(glPolyTexcoord, context.code()); } - if (glPolyAmbientBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyAmbientBufferID, context.code()); + if (glPolyAmbient != 0) { + pg.finalizeVertexBufferObject(glPolyAmbient, context.code()); } - if (glPolySpecularBufferID != 0) { - pg.finalizeVertexBufferObject(glPolySpecularBufferID, context.code()); + if (glPolySpecular != 0) { + pg.finalizeVertexBufferObject(glPolySpecular, context.code()); } - if (glPolyEmissiveBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyEmissiveBufferID, context.code()); + if (glPolyEmissive != 0) { + pg.finalizeVertexBufferObject(glPolyEmissive, context.code()); } - if (glPolyShininessBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyShininessBufferID, context.code()); + if (glPolyShininess != 0) { + pg.finalizeVertexBufferObject(glPolyShininess, context.code()); } - if (glPolyIndexBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyIndexBufferID, context.code()); + if (glPolyIndex != 0) { + pg.finalizeVertexBufferObject(glPolyIndex, context.code()); } } protected void finalizeLineBuffers() { - if (glLineVertexBufferID != 0) { - pg.finalizeVertexBufferObject(glLineVertexBufferID, context.code()); + if (glLineVertex != 0) { + pg.finalizeVertexBufferObject(glLineVertex, context.code()); } - if (glLineColorBufferID != 0) { - pg.finalizeVertexBufferObject(glLineColorBufferID, context.code()); + if (glLineColor != 0) { + pg.finalizeVertexBufferObject(glLineColor, context.code()); } - if (glLineAttribBufferID != 0) { - pg.finalizeVertexBufferObject(glLineAttribBufferID, context.code()); + if (glLineAttrib != 0) { + pg.finalizeVertexBufferObject(glLineAttrib, context.code()); } - if (glLineIndexBufferID != 0) { - pg.finalizeVertexBufferObject(glLineIndexBufferID, context.code()); + if (glLineIndex != 0) { + pg.finalizeVertexBufferObject(glLineIndex, context.code()); } } protected void finalizePointBuffers() { - if (glPointVertexBufferID != 0) { - pg.finalizeVertexBufferObject(glPointVertexBufferID, context.code()); + if (glPointVertex != 0) { + pg.finalizeVertexBufferObject(glPointVertex, context.code()); } - if (glPointColorBufferID != 0) { - pg.finalizeVertexBufferObject(glPointColorBufferID, context.code()); + if (glPointColor != 0) { + pg.finalizeVertexBufferObject(glPointColor, context.code()); } - if (glPointAttribBufferID != 0) { - pg.finalizeVertexBufferObject(glPointAttribBufferID, context.code()); + if (glPointAttrib != 0) { + pg.finalizeVertexBufferObject(glPointAttrib, context.code()); } - if (glPointIndexBufferID != 0) { - pg.finalizeVertexBufferObject(glPointIndexBufferID, context.code()); + if (glPointIndex != 0) { + pg.finalizeVertexBufferObject(glPointIndex, context.code()); } } @@ -3114,42 +3114,42 @@ public class PShapeOpenGL extends PShape { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - glPolyVertexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID); + glPolyVertex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.polyVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - glPolyColorBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID); + glPolyColor = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyColors, 0, size), PGL.GL_STATIC_DRAW); - glPolyNormalBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID); + glPolyNormal = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, FloatBuffer.wrap(tessGeo.polyNormals, 0, 3 * size), PGL.GL_STATIC_DRAW); - glPolyTexcoordBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID); + glPolyTexcoord = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.polyTexcoords, 0, 2 * size), PGL.GL_STATIC_DRAW); - glPolyAmbientBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID); + glPolyAmbient = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyAmbient, 0, size), PGL.GL_STATIC_DRAW); - glPolySpecularBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID); + glPolySpecular = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polySpecular, 0, size), PGL.GL_STATIC_DRAW); - glPolyEmissiveBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID); + glPolyEmissive = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyEmissive, 0, size), PGL.GL_STATIC_DRAW); - glPolyShininessBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID); + glPolyShininess = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizef, FloatBuffer.wrap(tessGeo.polyShininess, 0, size), PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glPolyIndexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndexBufferID); + glPolyIndex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.polyIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.polyIndices, 0, tessGeo.polyIndexCount), PGL.GL_STATIC_DRAW); @@ -3162,22 +3162,22 @@ public class PShapeOpenGL extends PShape { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - glLineVertexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID); + glLineVertex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - glLineColorBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID); + glLineColor = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.lineColors, 0, size), PGL.GL_STATIC_DRAW); - glLineAttribBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID); + glLineAttrib = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineAttribs, 0, 4 * size), PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glLineIndexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); + glLineIndex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.lineIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.lineIndices, 0, tessGeo.lineIndexCount), PGL.GL_STATIC_DRAW); @@ -3190,22 +3190,22 @@ public class PShapeOpenGL extends PShape { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - glPointVertexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID); + glPointVertex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.pointVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - glPointColorBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID); + glPointColor = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.pointColors, 0, size), PGL.GL_STATIC_DRAW); - glPointAttribBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID); + glPointAttrib = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.pointAttribs, 0, 2 * size), PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glPointIndexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); + glPointIndex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.pointIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.pointIndices, 0, tessGeo.pointIndexCount), PGL.GL_STATIC_DRAW); @@ -3220,49 +3220,49 @@ public class PShapeOpenGL extends PShape { // doesn't get deleted by OpenGL. The VBOs were already // automatically disposed when the old context was // destroyed. - pg.removeVertexBufferObject(glPolyVertexBufferID, context.code()); - pg.removeVertexBufferObject(glPolyColorBufferID, context.code()); - pg.removeVertexBufferObject(glPolyNormalBufferID, context.code()); - pg.removeVertexBufferObject(glPolyTexcoordBufferID, context.code()); - pg.removeVertexBufferObject(glPolyAmbientBufferID, context.code()); - pg.removeVertexBufferObject(glPolySpecularBufferID, context.code()); - pg.removeVertexBufferObject(glPolyEmissiveBufferID, context.code()); - pg.removeVertexBufferObject(glPolyShininessBufferID, context.code()); - pg.removeVertexBufferObject(glPolyIndexBufferID, context.code()); + pg.removeVertexBufferObject(glPolyVertex, context.code()); + pg.removeVertexBufferObject(glPolyColor, context.code()); + pg.removeVertexBufferObject(glPolyNormal, context.code()); + pg.removeVertexBufferObject(glPolyTexcoord, context.code()); + pg.removeVertexBufferObject(glPolyAmbient, context.code()); + pg.removeVertexBufferObject(glPolySpecular, context.code()); + pg.removeVertexBufferObject(glPolyEmissive, context.code()); + pg.removeVertexBufferObject(glPolyShininess, context.code()); + pg.removeVertexBufferObject(glPolyIndex, context.code()); - pg.removeVertexBufferObject(glLineVertexBufferID, context.code()); - pg.removeVertexBufferObject(glLineColorBufferID, context.code()); - pg.removeVertexBufferObject(glLineAttribBufferID, context.code()); - pg.removeVertexBufferObject(glLineIndexBufferID, context.code()); + pg.removeVertexBufferObject(glLineVertex, context.code()); + pg.removeVertexBufferObject(glLineColor, context.code()); + pg.removeVertexBufferObject(glLineAttrib, context.code()); + pg.removeVertexBufferObject(glLineIndex, context.code()); - pg.removeVertexBufferObject(glPointVertexBufferID, context.code()); - pg.removeVertexBufferObject(glPointColorBufferID, context.code()); - pg.removeVertexBufferObject(glPointAttribBufferID, context.code()); - pg.removeVertexBufferObject(glPointIndexBufferID, context.code()); + pg.removeVertexBufferObject(glPointVertex, context.code()); + pg.removeVertexBufferObject(glPointColor, context.code()); + pg.removeVertexBufferObject(glPointAttrib, context.code()); + pg.removeVertexBufferObject(glPointIndex, context.code()); // The OpenGL resources have been already deleted // when the context changed. We only need to zero // them to avoid deleting them again when the GC // runs the finalizers of the disposed object. - glPolyVertexBufferID = 0; - glPolyColorBufferID = 0; - glPolyNormalBufferID = 0; - glPolyTexcoordBufferID = 0; - glPolyAmbientBufferID = 0; - glPolySpecularBufferID = 0; - glPolyEmissiveBufferID = 0; - glPolyShininessBufferID = 0; - glPolyIndexBufferID = 0; + glPolyVertex = 0; + glPolyColor = 0; + glPolyNormal = 0; + glPolyTexcoord = 0; + glPolyAmbient = 0; + glPolySpecular = 0; + glPolyEmissive = 0; + glPolyShininess = 0; + glPolyIndex = 0; - glLineVertexBufferID = 0; - glLineColorBufferID = 0; - glLineAttribBufferID = 0; - glLineIndexBufferID = 0; + glLineVertex = 0; + glLineColor = 0; + glLineAttrib = 0; + glLineIndex = 0; - glPointVertexBufferID = 0; - glPointColorBufferID = 0; - glPointAttribBufferID = 0; - glPointIndexBufferID = 0; + glPointVertex = 0; + glPointColor = 0; + glPointAttrib = 0; + glPointIndex = 0; } return outdated; } @@ -3283,95 +3283,95 @@ public class PShapeOpenGL extends PShape { protected void deletePolyBuffers() { - if (glPolyVertexBufferID != 0) { - pg.deleteVertexBufferObject(glPolyVertexBufferID, context.code()); - glPolyVertexBufferID = 0; + if (glPolyVertex != 0) { + pg.deleteVertexBufferObject(glPolyVertex, context.code()); + glPolyVertex = 0; } - if (glPolyColorBufferID != 0) { - pg.deleteVertexBufferObject(glPolyColorBufferID, context.code()); - glPolyColorBufferID = 0; + if (glPolyColor != 0) { + pg.deleteVertexBufferObject(glPolyColor, context.code()); + glPolyColor = 0; } - if (glPolyNormalBufferID != 0) { - pg.deleteVertexBufferObject(glPolyNormalBufferID, context.code()); - glPolyNormalBufferID = 0; + if (glPolyNormal != 0) { + pg.deleteVertexBufferObject(glPolyNormal, context.code()); + glPolyNormal = 0; } - if (glPolyTexcoordBufferID != 0) { - pg.deleteVertexBufferObject(glPolyTexcoordBufferID, context.code()); - glPolyTexcoordBufferID = 0; + if (glPolyTexcoord != 0) { + pg.deleteVertexBufferObject(glPolyTexcoord, context.code()); + glPolyTexcoord = 0; } - if (glPolyAmbientBufferID != 0) { - pg.deleteVertexBufferObject(glPolyAmbientBufferID, context.code()); - glPolyAmbientBufferID = 0; + if (glPolyAmbient != 0) { + pg.deleteVertexBufferObject(glPolyAmbient, context.code()); + glPolyAmbient = 0; } - if (glPolySpecularBufferID != 0) { - pg.deleteVertexBufferObject(glPolySpecularBufferID, context.code()); - glPolySpecularBufferID = 0; + if (glPolySpecular != 0) { + pg.deleteVertexBufferObject(glPolySpecular, context.code()); + glPolySpecular = 0; } - if (glPolyEmissiveBufferID != 0) { - pg.deleteVertexBufferObject(glPolyEmissiveBufferID, context.code()); - glPolyEmissiveBufferID = 0; + if (glPolyEmissive != 0) { + pg.deleteVertexBufferObject(glPolyEmissive, context.code()); + glPolyEmissive = 0; } - if (glPolyShininessBufferID != 0) { - pg.deleteVertexBufferObject(glPolyShininessBufferID, context.code()); - glPolyShininessBufferID = 0; + if (glPolyShininess != 0) { + pg.deleteVertexBufferObject(glPolyShininess, context.code()); + glPolyShininess = 0; } - if (glPolyIndexBufferID != 0) { - pg.deleteVertexBufferObject(glPolyIndexBufferID, context.code()); - glPolyIndexBufferID = 0; + if (glPolyIndex != 0) { + pg.deleteVertexBufferObject(glPolyIndex, context.code()); + glPolyIndex = 0; } } protected void deleteLineBuffers() { - if (glLineVertexBufferID != 0) { - pg.deleteVertexBufferObject(glLineVertexBufferID, context.code()); - glLineVertexBufferID = 0; + if (glLineVertex != 0) { + pg.deleteVertexBufferObject(glLineVertex, context.code()); + glLineVertex = 0; } - if (glLineColorBufferID != 0) { - pg.deleteVertexBufferObject(glLineColorBufferID, context.code()); - glLineColorBufferID = 0; + if (glLineColor != 0) { + pg.deleteVertexBufferObject(glLineColor, context.code()); + glLineColor = 0; } - if (glLineAttribBufferID != 0) { - pg.deleteVertexBufferObject(glLineAttribBufferID, context.code()); - glLineAttribBufferID = 0; + if (glLineAttrib != 0) { + pg.deleteVertexBufferObject(glLineAttrib, context.code()); + glLineAttrib = 0; } - if (glLineIndexBufferID != 0) { - pg.deleteVertexBufferObject(glLineIndexBufferID, context.code()); - glLineIndexBufferID = 0; + if (glLineIndex != 0) { + pg.deleteVertexBufferObject(glLineIndex, context.code()); + glLineIndex = 0; } } protected void deletePointBuffers() { - if (glPointVertexBufferID != 0) { - pg.deleteVertexBufferObject(glPointVertexBufferID, context.code()); - glPointVertexBufferID = 0; + if (glPointVertex != 0) { + pg.deleteVertexBufferObject(glPointVertex, context.code()); + glPointVertex = 0; } - if (glPointColorBufferID != 0) { - pg.deleteVertexBufferObject(glPointColorBufferID, context.code()); - glPointColorBufferID = 0; + if (glPointColor != 0) { + pg.deleteVertexBufferObject(glPointColor, context.code()); + glPointColor = 0; } - if (glPointAttribBufferID != 0) { - pg.deleteVertexBufferObject(glPointAttribBufferID, context.code()); - glPointAttribBufferID = 0; + if (glPointAttrib != 0) { + pg.deleteVertexBufferObject(glPointAttrib, context.code()); + glPointAttrib = 0; } - if (glPointIndexBufferID != 0) { - pg.deleteVertexBufferObject(glPointIndexBufferID, context.code()); - glPointIndexBufferID = 0; + if (glPointIndex != 0) { + pg.deleteVertexBufferObject(glPointIndex, context.code()); + glPointIndex = 0; } } @@ -3512,7 +3512,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyVertices(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.polyVertices, 4 * offset, 4 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3520,7 +3520,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyColors(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.polyColors, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3528,7 +3528,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyNormals(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 3 * offset * PGL.SIZEOF_FLOAT, 3 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.polyNormals, 3 * offset, 3 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3536,7 +3536,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyTexcoords(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.polyTexcoords, 2 * offset, 2 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3544,7 +3544,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyAmbient(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.polyAmbient, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3552,7 +3552,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolySpecular(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.polySpecular, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3560,7 +3560,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyEmissive(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.polyEmissive, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3568,7 +3568,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyShininess(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_FLOAT, size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.polyShininess, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3576,7 +3576,7 @@ public class PShapeOpenGL extends PShape { protected void copyLineVertices(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineVertices, 4 * offset, 4 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3584,7 +3584,7 @@ public class PShapeOpenGL extends PShape { protected void copyLineColors(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.lineColors, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3592,7 +3592,7 @@ public class PShapeOpenGL extends PShape { protected void copyLineAttributes(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineAttribs, 4 * offset, 4 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3600,7 +3600,7 @@ public class PShapeOpenGL extends PShape { protected void copyPointVertices(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointVertices, 4 * offset, 4 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3608,7 +3608,7 @@ public class PShapeOpenGL extends PShape { protected void copyPointColors(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.pointColors, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3616,7 +3616,7 @@ public class PShapeOpenGL extends PShape { protected void copyPointAttributes(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointAttribs, 2 * offset, 2 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3908,7 +3908,7 @@ public class PShapeOpenGL extends PShape { tex = g.getTexture(textureImage); if (tex != null) { pgl.enableTexturing(tex.glTarget); - pgl.glBindTexture(tex.glTarget, tex.glID); + pgl.glBindTexture(tex.glTarget, tex.glName); } } @@ -3951,23 +3951,23 @@ public class PShapeOpenGL extends PShape { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(root.glPolyVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(root.glPolyColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setVertexAttribute(root.glPolyVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(root.glPolyColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); if (g.lights) { - shader.setNormalAttribute(root.glPolyNormalBufferID, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT); - shader.setAmbientAttribute(root.glPolyAmbientBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setSpecularAttribute(root.glPolySpecularBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setEmissiveAttribute(root.glPolyEmissiveBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setShininessAttribute(root.glPolyShininessBufferID, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); + shader.setNormalAttribute(root.glPolyNormal, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT); + shader.setAmbientAttribute(root.glPolyAmbient, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setSpecularAttribute(root.glPolySpecular, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setEmissiveAttribute(root.glPolyEmissive, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setShininessAttribute(root.glPolyShininess, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); } if (tex != null) { - shader.setTexcoordAttribute(root.glPolyTexcoordBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); + shader.setTexcoordAttribute(root.glPolyTexcoord, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); shader.setTexture(tex); } - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPolyIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPolyIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -4082,11 +4082,11 @@ public class PShapeOpenGL extends PShape { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(root.glLineVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(root.glLineColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setLineAttribute(root.glLineAttribBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setVertexAttribute(root.glLineVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(root.glLineColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setLineAttribute(root.glLineAttrib, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glLineIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glLineIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -4176,11 +4176,11 @@ public class PShapeOpenGL extends PShape { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(root.glPointVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(root.glPointColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setPointAttribute(root.glPointAttribBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); + shader.setVertexAttribute(root.glPointVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(root.glPointColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setPointAttribute(root.glPointAttrib, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPointIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPointIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } diff --git a/android/core/src/processing/opengl/Texture.java b/android/core/src/processing/opengl/Texture.java index 1e532d2ca..b4751c1a6 100644 --- a/android/core/src/processing/opengl/Texture.java +++ b/android/core/src/processing/opengl/Texture.java @@ -71,8 +71,7 @@ public class Texture implements PConstants { public int width, height; - // These are public but use at your own risk! - public int glID; + public int glName; public int glTarget; public int glFormat; public int glMinFilter; @@ -137,7 +136,7 @@ public class Texture implements PConstants { pgl = pg.pgl; context = pgl.createEmptyContext(); - glID = 0; + glName = 0; init(width, height, (Parameters)params); } @@ -145,8 +144,8 @@ public class Texture implements PConstants { protected void finalize() throws Throwable { try { - if (glID != 0) { - pg.finalizeTextureObject(glID, context.code()); + if (glName != 0) { + pg.finalizeTextureObject(glName, context.code()); } } finally { super.finalize(); @@ -168,7 +167,7 @@ public class Texture implements PConstants { */ public void init(int width, int height) { Parameters params; - if (0 < glID) { + if (0 < glName) { // Re-initializing a pre-existing texture. // We use the current parameters as default: params = getParameters(); @@ -220,7 +219,7 @@ public class Texture implements PConstants { * @return boolean */ public boolean available() { - return 0 < glID; + return 0 < glName; } @@ -278,7 +277,7 @@ public class Texture implements PConstants { } pgl.enableTexturing(glTarget); - pgl.glBindTexture(glTarget, glID); + pgl.glBindTexture(glTarget, glName); if (usingMipmaps) { if (PGraphicsOpenGL.autoMipmapGenSupported) { @@ -508,7 +507,7 @@ public class Texture implements PConstants { public void bind() { pgl.enableTexturing(glTarget); - pgl.glBindTexture(glTarget, glID); + pgl.glBindTexture(glTarget, glName); } @@ -972,9 +971,9 @@ public class Texture implements PConstants { pgl.enableTexturing(glTarget); context = pgl.getCurrentContext(); - glID = pg.createTextureObject(context.code()); + glName = pg.createTextureObject(context.code()); - pgl.glBindTexture(glTarget, glID); + pgl.glBindTexture(glTarget, glName); pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MIN_FILTER, glMinFilter); pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MAG_FILTER, glMagFilter); pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_WRAP_S, glWrapS); @@ -996,9 +995,9 @@ public class Texture implements PConstants { * Marks the texture object for deletion. */ protected void release() { - if (glID != 0) { - pg.finalizeTextureObject(glID, context.code()); - glID = 0; + if (glName != 0) { + pg.finalizeTextureObject(glName, context.code()); + glName = 0; } } @@ -1009,11 +1008,11 @@ public class Texture implements PConstants { // Removing the texture object from the renderer's list so it // doesn't get deleted by OpenGL. The texture object was // automatically disposed when the old context was destroyed. - pg.removeTextureObject(glID, context.code()); + pg.removeTextureObject(glName, context.code()); // And then set the id to zero, so it doesn't try to be // deleted when the object's finalizer is invoked by the GC. - glID = 0; + glName = 0; } return outdated; } @@ -1044,14 +1043,14 @@ public class Texture implements PConstants { if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region. - pgl.drawTexture(tex.glTarget, tex.glID, tex.glWidth, tex.glHeight, + pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight, x, y, w, h, 0, 0, width, height); } else { // Rendering tex into "this" but without scaling so the contents // of the source texture fall in the corresponding texels of the // destination. - pgl.drawTexture(tex.glTarget, tex.glID, tex.glWidth, tex.glHeight, + pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight, x, y, w, h, x, y, w, h); } pg.popFramebuffer(); @@ -1092,7 +1091,7 @@ public class Texture implements PConstants { parent = src.parent; pg = src.pg; - glID = src.glID; + glName = src.glName; glTarget = src.glTarget; glFormat = src.glFormat; glMinFilter = src.glMinFilter; diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 14ca4b025..441d4dd69 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -10128,6 +10128,43 @@ public class PApplet extends Applet } + public Object loadShader(String vertFilename, String fragFilename, int kind) { + return g.loadShader(vertFilename, fragFilename, kind); + } + + + public Object loadShader(String fragFilename, int kind) { + return g.loadShader(fragFilename, kind); + } + + + public Object loadShader(String vertFilename, String fragFilename) { + return g.loadShader(vertFilename, fragFilename); + } + + + public Object loadShader(String fragFilename) { + return g.loadShader(fragFilename); + } + + + public void shader(Object shader, int kind) { + if (recorder != null) recorder.shader(shader, kind); + g.shader(shader, kind); + } + + + public void resetShader(int kind) { + if (recorder != null) recorder.resetShader(kind); + g.resetShader(kind); + } + + + public Object getShader(int kind) { + return g.getShader(kind); + } + + public void bezierVertex(float x2, float y2, float x3, float y3, float x4, float y4) { diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 313c77bd1..e6c930250 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -1491,6 +1491,51 @@ public class PGraphics extends PImage implements PConstants { } + ////////////////////////////////////////////////////////////// + + // SHADERS + + + public Object loadShader(String vertFilename, String fragFilename, int kind) { + showMissingWarning("loadShader"); + return null; + } + + + public Object loadShader(String fragFilename, int kind) { + showMissingWarning("loadShader"); + return null; + } + + + public Object loadShader(String vertFilename, String fragFilename) { + showMissingWarning("loadShader"); + return null; + } + + + public Object loadShader(String fragFilename) { + showMissingWarning("loadShader"); + return null; + } + + + public void shader(Object shader, int kind) { + showMissingWarning("shader"); + } + + + public void resetShader(int kind) { + showMissingWarning("resetShader"); + } + + + public Object getShader(int kind) { + showMissingWarning("getShader"); + return null; + } + + ////////////////////////////////////////////////////////////// // CURVE/BEZIER VERTEX HANDLING @@ -3326,7 +3371,8 @@ public class PGraphics extends PImage implements PConstants { } - public void initCache(PImage img) { // ignore + public Object initCache(PImage img) { // ignore + return null; } diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index 740f092c0..cf9904b21 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -479,26 +479,22 @@ public class PImage implements PConstants, Cloneable { pixels = new int[width*height]; } - if (parent == null) return; - parent.g.initCache(this); - if (cacheMap != null) { - for (PGraphics pg: cacheMap.keySet()) { - Object obj = cacheMap.get(pg); - - Method loadPixelsMethod = null; - try { - loadPixelsMethod = obj.getClass().getMethod("loadPixels", new Class[] { int[].class }); - } catch (Exception e) { + if (parent == null) return; + Object cache = parent.g.initCache(this); + if (cache != null) { + Method loadPixelsMethod = null; + try { + loadPixelsMethod = cache.getClass().getMethod("loadPixels", new Class[] { int[].class }); + } catch (Exception e) { + } + + if (loadPixelsMethod != null) { + try { + loadPixelsMethod.invoke(cache, new Object[] { pixels }); + } catch (Exception e) { + e.printStackTrace(); } - - if (loadPixelsMethod != null) { - try { - loadPixelsMethod.invoke(obj, new Object[] { pixels }); - } catch (Exception e) { - e.printStackTrace(); - } - } - } + } } } diff --git a/java/libraries/opengl/examples/Shaders/BadPrint/BadPrint.pde b/java/libraries/opengl/examples/Shaders/BadPrint/BadPrint.pde index ce7a85fd9..982d10203 100644 --- a/java/libraries/opengl/examples/Shaders/BadPrint/BadPrint.pde +++ b/java/libraries/opengl/examples/Shaders/BadPrint/BadPrint.pde @@ -5,8 +5,7 @@ import controlP5.*; ControlP5 controlP5; -PShader shader; -PGraphicsOpenGL pg; +PShader badPrint; boolean enabled = true; float scaleR = 1.0, scaleG = 1.0, scaleB = 1.0; @@ -20,9 +19,8 @@ public void setup() { noStroke(); fill(204); - pg = (PGraphicsOpenGL)g; - shader = pg.loadShader("BadPrintVert.glsl", "BadPrintFrag.glsl", PShader.LIT); - pg.setShader(shader, PShader.LIT); + badPrint = (PShader)loadShader("BadPrintVert.glsl", "BadPrintFrag.glsl", PShader.LIT); + shader(badPrint, PShader.LIT); sphereDetail(60); @@ -46,14 +44,14 @@ public void draw() { background(0); if (enabled) { - pg.setShader(shader, PShader.LIT); + shader(badPrint, PShader.LIT); - shader.set("Scale", scaleR, scaleG, scaleB); - shader.set("Offset", offsetR, offsetG, offsetB); - shader.set("Register", registerR, registerG, registerB); - shader.set("Size", sizeR, sizeG, sizeB); + badPrint.set("Scale", scaleR, scaleG, scaleB); + badPrint.set("Offset", offsetR, offsetG, offsetB); + badPrint.set("Register", registerR, registerG, registerB); + badPrint.set("Size", sizeR, sizeG, sizeB); } else { - pg.defaultShader(PShader.LIT); + resetShader(PShader.LIT); } noStroke(); @@ -71,4 +69,3 @@ public void draw() { controlP5.draw(); hint(ENABLE_DEPTH_TEST); } - diff --git a/java/libraries/opengl/examples/Shaders/EdgeDetect/EdgeDetect.pde b/java/libraries/opengl/examples/Shaders/EdgeDetect/EdgeDetect.pde index 2602a92d0..90feb66c5 100644 --- a/java/libraries/opengl/examples/Shaders/EdgeDetect/EdgeDetect.pde +++ b/java/libraries/opengl/examples/Shaders/EdgeDetect/EdgeDetect.pde @@ -5,17 +5,15 @@ // Press the mouse to switch between the custom and the default shader. PImage img; -PShader shader; -PGraphicsOpenGL pg; +PShader edges; boolean customShader; void setup() { size(400, 400, P2D); img = loadImage("berlin-1.jpg"); - pg = (PGraphicsOpenGL)g; - shader = pg.loadShader("edges.glsl", PShader.TEXTURED); - pg.setShader(shader, PShader.TEXTURED); + edges = (PShader)loadShader("edges.glsl", PShader.TEXTURED); + shader(edges, PShader.TEXTURED); customShader = true; } @@ -25,10 +23,10 @@ public void draw() { public void mousePressed() { if (customShader) { - pg.defaultShader(PShader.TEXTURED); + resetShader(PShader.TEXTURED); customShader = false; } else { - pg.setShader(shader, PShader.TEXTURED); + shader(edges, PShader.TEXTURED); customShader = true; } } diff --git a/java/libraries/opengl/examples/Shaders/FXAA/FXAA.pde b/java/libraries/opengl/examples/Shaders/FXAA/FXAA.pde index 72c2a15af..ad61b777f 100644 --- a/java/libraries/opengl/examples/Shaders/FXAA/FXAA.pde +++ b/java/libraries/opengl/examples/Shaders/FXAA/FXAA.pde @@ -6,8 +6,7 @@ PGraphics canvas; boolean drawing = false; -PGraphicsOpenGL pg; -PShader shader; +PShader fxaa; boolean usingShader; String message; float msgLen; @@ -19,9 +18,8 @@ void setup() { canvas = createGraphics(width, height, P2D); canvas.noSmooth(); - pg = (PGraphicsOpenGL) g; - shader = pg.loadShader("fxaa.glsl", PShader.TEXTURED); - pg.setShader(shader, PShader.TEXTURED); + fxaa = (PShader)loadShader("fxaa.glsl", PShader.TEXTURED); + shader(fxaa, PShader.TEXTURED); usingShader = true; canvas.beginDraw(); @@ -55,10 +53,10 @@ public void draw() { public void mousePressed() { if (!drawing && width - msgLen < mouseX && height - 23 < mouseY) { if (usingShader) { - pg.defaultShader(PShader.TEXTURED); + resetShader(PShader.TEXTURED); usingShader = false; } else { - pg.setShader(shader, PShader.TEXTURED); + shader(fxaa, PShader.TEXTURED); usingShader = true; } updateMessage(); @@ -84,11 +82,11 @@ void drawMessage() { if (usingShader) { // We need the default texture shader to // render text. - pg.defaultShader(PShader.TEXTURED); + resetShader(PShader.TEXTURED); } fill(0); text(message, width - msgLen, height - 5); if (usingShader) { - pg.setShader(shader, PShader.TEXTURED); + shader(fxaa, PShader.TEXTURED); } -} +} \ No newline at end of file diff --git a/java/libraries/opengl/examples/Shaders/FishEye/FishEye.pde b/java/libraries/opengl/examples/Shaders/FishEye/FishEye.pde index ab4c9182c..e3d6b7e98 100644 --- a/java/libraries/opengl/examples/Shaders/FishEye/FishEye.pde +++ b/java/libraries/opengl/examples/Shaders/FishEye/FishEye.pde @@ -8,10 +8,9 @@ void setup() { size(400, 400, P3D); canvas = createGraphics(400, 400, P3D); - PGraphicsOpenGL pg = (PGraphicsOpenGL)g; - fisheye = pg.loadShader("FishEye.glsl", PShader.TEXTURED); + fisheye = (PShader)loadShader("FishEye.glsl", PShader.TEXTURED); fisheye.set("aperture", 180.0); - pg.setShader(fisheye, PShader.TEXTURED); + shader(fisheye, PShader.TEXTURED); } void draw() { @@ -36,4 +35,3 @@ void draw() { // it was set as the PShader.TEXTURED shader of the main surface. image(canvas, 0, 0, width, height); } - diff --git a/java/libraries/opengl/examples/Shaders/GlossyFishEye/GlossyFishEye.pde b/java/libraries/opengl/examples/Shaders/GlossyFishEye/GlossyFishEye.pde index 6cbf8742c..88a0fe15e 100644 --- a/java/libraries/opengl/examples/Shaders/GlossyFishEye/GlossyFishEye.pde +++ b/java/libraries/opengl/examples/Shaders/GlossyFishEye/GlossyFishEye.pde @@ -13,13 +13,12 @@ void setup() { size(800, 800, P3D); canvas = createGraphics(800, 800, P3D); - PGraphicsOpenGL pg = (PGraphicsOpenGL)g; - fisheye = pg.loadShader("FishEye.glsl", PShader.TEXTURED); + fisheye = (PShader)loadShader("FishEye.glsl", PShader.TEXTURED); fisheye.set("aperture", 180.0); - pg.setShader(fisheye, PShader.TEXTURED); + shader(fisheye, PShader.TEXTURED); usingFishEye = true; - glossy = pg.loadShader("GlossyVert.glsl", "GlossyFrag.glsl", PShader.LIT); + glossy = (PShader)loadShader("GlossyVert.glsl", "GlossyFrag.glsl", PShader.LIT); glossy.set("AmbientColour", 0, 0, 0); glossy.set("DiffuseColour", 0.9, 0.2, 0.2); glossy.set("SpecularColour", 1.0, 1.0, 1.0); @@ -28,7 +27,7 @@ void setup() { glossy.set("SpecularIntensity", 0.7); glossy.set("Roughness", 0.7); glossy.set("Sharpness", 0.0); - ((PGraphicsOpenGL)canvas).setShader(glossy, PShader.LIT); + canvas.shader(glossy, PShader.LIT); ball = createShape(SPHERE, 50); //ball.fill(200, 50, 50); @@ -62,10 +61,10 @@ void draw() { public void mousePressed() { if (usingFishEye) { - ((PGraphicsOpenGL)g).defaultShader(PShader.TEXTURED); + resetShader(PShader.TEXTURED); usingFishEye = false; } else { - ((PGraphicsOpenGL)g).setShader(fisheye, PShader.TEXTURED); + shader(fisheye, PShader.TEXTURED); usingFishEye = true; } -} +} \ No newline at end of file diff --git a/java/libraries/opengl/examples/Shaders/LowLevelGL/LowLevelGL.pde b/java/libraries/opengl/examples/Shaders/LowLevelGL/LowLevelGL.pde index 208f74d99..6a3238f98 100644 --- a/java/libraries/opengl/examples/Shaders/LowLevelGL/LowLevelGL.pde +++ b/java/libraries/opengl/examples/Shaders/LowLevelGL/LowLevelGL.pde @@ -4,7 +4,7 @@ import java.nio.FloatBuffer; PGraphicsOpenGL pg; PGL pgl; -PShader shader; +PShader flatShader; int vertLoc; int colorLoc; @@ -19,9 +19,10 @@ void setup() { size(400, 400, P3D); pg = (PGraphicsOpenGL)g; + // Get the default shader that Processing uses to // render flat geometry (w/out textures and lights). - shader = pg.getShader(PShader.FLAT); + flatShader = (PShader)getShader(PShader.FLAT); vertices = new float[12]; vertData = PGL.allocateDirectFloatBuffer(12); @@ -40,10 +41,10 @@ void draw() { updateGeometry(); pgl = pg.beginPGL(); - shader.bind(); + flatShader.bind(); - vertLoc = pgl.glGetAttribLocation(shader.glProgramObjectID, "inVertex"); - colorLoc = pgl.glGetAttribLocation(shader.glProgramObjectID, "inColor"); + vertLoc = pgl.glGetAttribLocation(flatShader.glProgram, "inVertex"); + colorLoc = pgl.glGetAttribLocation(flatShader.glProgram, "inColor"); pgl.glEnableVertexAttribArray(vertLoc); pgl.glEnableVertexAttribArray(colorLoc); @@ -56,7 +57,7 @@ void draw() { pgl.glDisableVertexAttribArray(vertLoc); pgl.glDisableVertexAttribArray(colorLoc); - shader.unbind(); + flatShader.unbind(); pg.endPGL(); } @@ -98,4 +99,4 @@ void updateGeometry() { colorData.rewind(); colorData.put(colors); colorData.position(0); -} +} \ No newline at end of file diff --git a/java/libraries/opengl/examples/Shaders/SepBlur/SepBlur.pde b/java/libraries/opengl/examples/Shaders/SepBlur/SepBlur.pde index 607332abe..2ac750055 100644 --- a/java/libraries/opengl/examples/Shaders/SepBlur/SepBlur.pde +++ b/java/libraries/opengl/examples/Shaders/SepBlur/SepBlur.pde @@ -1,26 +1,26 @@ -// Separable-blur shader (works by applying two succesive passes +// Separable-blur shader (works by applying two successive passes // in each direction of the image) -PShader shader; -PGraphicsOpenGL src; -PGraphicsOpenGL pass1, pass2; +PShader blur; +PGraphics src; +PGraphics pass1, pass2; void setup() { size(200, 200, P2D); - shader = ((PGraphicsOpenGL)g).loadShader("blur.glsl", PShader.TEXTURED); - shader.set("blurSize", 9); - shader.set("sigma", 5.0f); + blur = (PShader)loadShader("blur.glsl", PShader.TEXTURED); + blur.set("blurSize", 9); + blur.set("sigma", 5.0f); - src = (PGraphicsOpenGL)createGraphics(width, height, P2D); + src = createGraphics(width, height, P2D); - pass1 = (PGraphicsOpenGL)createGraphics(width, height, P2D); + pass1 = createGraphics(width, height, P2D); pass1.noSmooth(); - pass1.setShader(shader, PShader.TEXTURED); + pass1.shader(blur, PShader.TEXTURED); - pass2 = (PGraphicsOpenGL)createGraphics(width, height, P2D); + pass2 = createGraphics(width, height, P2D); pass2.noSmooth(); - pass2.setShader(shader, PShader.TEXTURED); + pass2.shader(blur, PShader.TEXTURED); } void draw() { @@ -31,13 +31,13 @@ void draw() { src.endDraw(); // Applying the blur shader along the vertical direction - shader.set("horizontalPass", 0); + blur.set("horizontalPass", 0); pass1.beginDraw(); pass1.image(src, 0, 0); pass1.endDraw(); // Applying the blur shader along the horizontal direction - shader.set("horizontalPass", 1); + blur.set("horizontalPass", 1); pass2.beginDraw(); pass2.image(pass1, 0, 0); pass2.endDraw(); @@ -47,16 +47,16 @@ void draw() { void keyPressed() { if (key == '9') { - shader.set("blurSize", 9); - shader.set("sigma", 5.0); + blur.set("blurSize", 9); + blur.set("sigma", 5.0); } else if (key == '7') { - shader.set("blurSize", 7); - shader.set("sigma", 3.0); + blur.set("blurSize", 7); + blur.set("sigma", 3.0); } else if (key == '5') { - shader.set("blurSize", 5); - shader.set("sigma", 2.0); + blur.set("blurSize", 5); + blur.set("sigma", 2.0); } else if (key == '3') { - shader.set("blurSize", 5); - shader.set("sigma", 1.0); + blur.set("blurSize", 5); + blur.set("sigma", 1.0); } -} +} \ No newline at end of file diff --git a/java/libraries/opengl/examples/Shaders/ToonShading/ToonShading.pde b/java/libraries/opengl/examples/Shaders/ToonShading/ToonShading.pde index 456a93434..30ffb2009 100644 --- a/java/libraries/opengl/examples/Shaders/ToonShading/ToonShading.pde +++ b/java/libraries/opengl/examples/Shaders/ToonShading/ToonShading.pde @@ -3,8 +3,7 @@ // Based on the glsl tutorial from lighthouse 3D: // http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shader-version-ii/ -PShader shader; -PGraphicsOpenGL pg; +PShader toon; boolean customShader; public void setup() { @@ -12,9 +11,8 @@ public void setup() { noStroke(); fill(204); - pg = (PGraphicsOpenGL)g; - shader = pg.loadShader("ToonVert.glsl", "ToonFrag.glsl", PShader.LIT); - pg.setShader(shader, PShader.LIT); + toon = (PShader)loadShader("ToonVert.glsl", "ToonFrag.glsl", PShader.LIT); + shader(toon, PShader.LIT); customShader = true; } @@ -31,11 +29,11 @@ public void draw() { public void mousePressed() { if (dist(mouseX, mouseY, width/2, height/2) < 80) { if (customShader) { - pg.defaultShader(PShader.LIT); + resetShader(PShader.LIT); customShader = false; } else { - pg.setShader(shader, PShader.LIT); + shader(toon, PShader.LIT); customShader = true; } } diff --git a/java/libraries/opengl/src/processing/opengl/FrameBuffer.java b/java/libraries/opengl/src/processing/opengl/FrameBuffer.java index b836b32e9..c28cd3489 100644 --- a/java/libraries/opengl/src/processing/opengl/FrameBuffer.java +++ b/java/libraries/opengl/src/processing/opengl/FrameBuffer.java @@ -45,11 +45,11 @@ public class FrameBuffer implements PConstants { protected PGL pgl; protected PGL.Context context; // The context that created this framebuffer. - public int glFboID; - public int glDepthBufferID; - public int glStencilBufferID; - public int glDepthStencilBufferID; - public int glColorBufferMultisampleID; + public int glFbo; + public int glDepth; + public int glStencil; + public int glDepthStencil; + public int glMultisample; public int width; public int height; @@ -84,11 +84,11 @@ public class FrameBuffer implements PConstants { pgl = pg.pgl; context = pgl.createEmptyContext(); - glFboID = 0; - glDepthBufferID = 0; - glStencilBufferID = 0; - glDepthStencilBufferID = 0; - glColorBufferMultisampleID = 0; + glFbo = 0; + glDepth = 0; + glStencil = 0; + glDepthStencil = 0; + glMultisample = 0; if (screen) { // If this framebuffer is used to represent a on-screen buffer, @@ -143,20 +143,20 @@ public class FrameBuffer implements PConstants { protected void finalize() throws Throwable { try { - if (glFboID != 0) { - pg.finalizeFrameBufferObject(glFboID, context.code()); + if (glFbo != 0) { + pg.finalizeFrameBufferObject(glFbo, context.code()); } - if (glDepthBufferID != 0) { - pg.finalizeRenderBufferObject(glDepthBufferID, context.code()); + if (glDepth != 0) { + pg.finalizeRenderBufferObject(glDepth, context.code()); } - if (glStencilBufferID != 0) { - pg.finalizeRenderBufferObject(glStencilBufferID, context.code()); + if (glStencil != 0) { + pg.finalizeRenderBufferObject(glStencil, context.code()); } - if (glColorBufferMultisampleID != 0) { - pg.finalizeRenderBufferObject(glColorBufferMultisampleID, context.code()); + if (glMultisample != 0) { + pg.finalizeRenderBufferObject(glMultisample, context.code()); } - if (glDepthStencilBufferID != 0) { - pg.finalizeRenderBufferObject(glDepthStencilBufferID, context.code()); + if (glDepthStencil != 0) { + pg.finalizeRenderBufferObject(glDepthStencil, context.code()); } } finally { super.finalize(); @@ -174,15 +174,15 @@ public class FrameBuffer implements PConstants { } public void copy(FrameBuffer dest) { - pgl.glBindFramebuffer(PGL.GL_READ_FRAMEBUFFER, this.glFboID); - pgl.glBindFramebuffer(PGL.GL_DRAW_FRAMEBUFFER, dest.glFboID); + pgl.glBindFramebuffer(PGL.GL_READ_FRAMEBUFFER, this.glFbo); + pgl.glBindFramebuffer(PGL.GL_DRAW_FRAMEBUFFER, dest.glFbo); pgl.glBlitFramebuffer(0, 0, this.width, this.height, 0, 0, dest.width, dest.height, PGL.GL_COLOR_BUFFER_BIT, PGL.GL_NEAREST); } public void bind() { - pgl.glBindFramebuffer(PGL.GL_FRAMEBUFFER, glFboID); + pgl.glBindFramebuffer(PGL.GL_FRAMEBUFFER, glFbo); } public void disableDepthTest() { @@ -260,7 +260,7 @@ public class FrameBuffer implements PConstants { } for (int i = 0; i < numColorBuffers; i++) { - pgl.glFramebufferTexture2D(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0 + i, colorBufferTex[i].glTarget, colorBufferTex[i].glID, 0); + pgl.glFramebufferTexture2D(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0 + i, colorBufferTex[i].glTarget, colorBufferTex[i].glName, 0); } pgl.validateFramebuffer(); @@ -280,9 +280,9 @@ public class FrameBuffer implements PConstants { context = pgl.getCurrentContext(); if (screenFb) { - glFboID = 0; + glFbo = 0; } else { - glFboID = pg.createFrameBufferObject(context.code()); + glFbo = pg.createFrameBufferObject(context.code()); } // create the rest of the stuff... @@ -304,25 +304,25 @@ public class FrameBuffer implements PConstants { protected void release() { - if (glFboID != 0) { - pg.finalizeFrameBufferObject(glFboID, context.code()); - glFboID = 0; + if (glFbo != 0) { + pg.finalizeFrameBufferObject(glFbo, context.code()); + glFbo = 0; } - if (glDepthBufferID != 0) { - pg.finalizeRenderBufferObject(glDepthBufferID, context.code()); - glDepthBufferID = 0; + if (glDepth != 0) { + pg.finalizeRenderBufferObject(glDepth, context.code()); + glDepth = 0; } - if (glStencilBufferID != 0) { - pg.finalizeRenderBufferObject(glStencilBufferID, context.code()); - glStencilBufferID = 0; + if (glStencil != 0) { + pg.finalizeRenderBufferObject(glStencil, context.code()); + glStencil = 0; } - if (glColorBufferMultisampleID != 0) { - pg.finalizeRenderBufferObject(glColorBufferMultisampleID, context.code()); - glColorBufferMultisampleID = 0; + if (glMultisample != 0) { + pg.finalizeRenderBufferObject(glMultisample, context.code()); + glMultisample = 0; } - if (glDepthStencilBufferID != 0) { - pg.finalizeRenderBufferObject(glDepthStencilBufferID, context.code()); - glDepthStencilBufferID = 0; + if (glDepthStencil != 0) { + pg.finalizeRenderBufferObject(glDepthStencil, context.code()); + glDepthStencil = 0; } } @@ -330,17 +330,17 @@ public class FrameBuffer implements PConstants { protected boolean contextIsOutdated() { boolean outdated = !pgl.contextIsCurrent(context); if (outdated) { - pg.removeFrameBufferObject(glFboID, context.code()); - pg.removeRenderBufferObject(glDepthBufferID, context.code()); - pg.removeRenderBufferObject(glStencilBufferID, context.code()); - pg.removeRenderBufferObject(glDepthStencilBufferID, context.code()); - pg.removeRenderBufferObject(glColorBufferMultisampleID, context.code()); + pg.removeFrameBufferObject(glFbo, context.code()); + pg.removeRenderBufferObject(glDepth, context.code()); + pg.removeRenderBufferObject(glStencil, context.code()); + pg.removeRenderBufferObject(glDepthStencil, context.code()); + pg.removeRenderBufferObject(glMultisample, context.code()); - glFboID = 0; - glDepthBufferID = 0; - glStencilBufferID = 0; - glDepthStencilBufferID = 0; - glColorBufferMultisampleID = 0; + glFbo = 0; + glDepth = 0; + glStencil = 0; + glDepthStencil = 0; + glMultisample = 0; for (int i = 0; i < numColorBuffers; i++) { colorBufferTex[i] = null; @@ -356,10 +356,10 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glColorBufferMultisampleID = pg.createRenderBufferObject(context.code()); - pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glColorBufferMultisampleID); + glMultisample = pg.createRenderBufferObject(context.code()); + pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glMultisample); pgl.glRenderbufferStorageMultisample(PGL.GL_RENDERBUFFER, nsamples, PGL.GL_RGBA8, width, height); - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0, PGL.GL_RENDERBUFFER, glColorBufferMultisampleID); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_COLOR_ATTACHMENT0, PGL.GL_RENDERBUFFER, glMultisample); pg.popFramebuffer(); } @@ -375,8 +375,8 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glDepthStencilBufferID = pg.createRenderBufferObject(context.code()); - pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthStencilBufferID); + glDepthStencil = pg.createRenderBufferObject(context.code()); + pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthStencil); if (multisample) { pgl.glRenderbufferStorageMultisample(PGL.GL_RENDERBUFFER, nsamples, PGL.GL_DEPTH24_STENCIL8, width, height); @@ -384,8 +384,8 @@ public class FrameBuffer implements PConstants { pgl.glRenderbufferStorage(PGL.GL_RENDERBUFFER, PGL.GL_DEPTH24_STENCIL8, width, height); } - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencilBufferID); - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencilBufferID); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencil); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthStencil); pg.popFramebuffer(); } @@ -401,8 +401,8 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glDepthBufferID = pg.createRenderBufferObject(context.code()); - pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepthBufferID); + glDepth = pg.createRenderBufferObject(context.code()); + pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glDepth); int glConst = PGL.GL_DEPTH_COMPONENT16; if (depthBits == 16) { @@ -419,7 +419,7 @@ public class FrameBuffer implements PConstants { pgl.glRenderbufferStorage(PGL.GL_RENDERBUFFER, glConst, width, height); } - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepthBufferID); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_DEPTH_ATTACHMENT, PGL.GL_RENDERBUFFER, glDepth); pg.popFramebuffer(); } @@ -435,8 +435,8 @@ public class FrameBuffer implements PConstants { pg.pushFramebuffer(); pg.setFramebuffer(this); - glStencilBufferID = pg.createRenderBufferObject(context.code()); - pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glStencilBufferID); + glStencil = pg.createRenderBufferObject(context.code()); + pgl.glBindRenderbuffer(PGL.GL_RENDERBUFFER, glStencil); int glConst = PGL.GL_STENCIL_INDEX1; if (stencilBits == 1) { @@ -452,7 +452,7 @@ public class FrameBuffer implements PConstants { pgl.glRenderbufferStorage(PGL.GL_RENDERBUFFER, glConst, width, height); } - pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glStencilBufferID); + pgl.glFramebufferRenderbuffer(PGL.GL_FRAMEBUFFER, PGL.GL_STENCIL_ATTACHMENT, PGL.GL_RENDERBUFFER, glStencil); pg.popFramebuffer(); } diff --git a/java/libraries/opengl/src/processing/opengl/PFontTexture.java b/java/libraries/opengl/src/processing/opengl/PFontTexture.java index be5c9e73a..e8342b76a 100644 --- a/java/libraries/opengl/src/processing/opengl/PFontTexture.java +++ b/java/libraries/opengl/src/processing/opengl/PFontTexture.java @@ -238,8 +238,8 @@ class PFontTexture implements PConstants { } if (outdated) { for (int i = 0; i < textures.length; i++) { - pg.removeTextureObject(textures[i].glID, textures[i].context.code()); - textures[i].glID = 0; + pg.removeTextureObject(textures[i].glName, textures[i].context.code()); + textures[i].glName = 0; } } return outdated; diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index e87eb59a7..e89ed2ab3 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -738,11 +738,11 @@ public class PGL { // The screen framebuffer is the color FBO just created. We need // to update the screenFramebuffer object so when the framebuffer // is popped back to the screen, the correct id is set. - PGraphicsOpenGL.screenFramebuffer.glFboID = glColorFboID[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFboID[0]; } else { // To make sure that the default screen buffer is used, specially after // doing screen rendering on an FBO (the OSX 10.7+ above). - PGraphicsOpenGL.screenFramebuffer.glFboID = 0; + PGraphicsOpenGL.screenFramebuffer.glFbo = 0; } } @@ -779,14 +779,14 @@ public class PGL { } gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFboID[0]); - PGraphicsOpenGL.screenFramebuffer.glFboID = glColorFboID[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFboID[0]; } public void bindPrimaryMultiFBO() { if (multisample) { gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glMultiFboID[0]); - PGraphicsOpenGL.screenFramebuffer.glFboID = glMultiFboID[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = glMultiFboID[0]; } } @@ -831,12 +831,12 @@ public class PGL { gl2x.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0); // Now the screen buffer is the multisample FBO. - PGraphicsOpenGL.screenFramebuffer.glFboID = glMultiFboID[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = glMultiFboID[0]; } else { gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFboID[0]); if (gl2x != null) gl2x.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0); - PGraphicsOpenGL.screenFramebuffer.glFboID = glColorFboID[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFboID[0]; } } } @@ -865,7 +865,7 @@ public class PGL { // Leaving the color FBO currently bound as the screen FB. gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFboID[0]); - PGraphicsOpenGL.screenFramebuffer.glFboID = glColorFboID[0]; + PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFboID[0]; } } @@ -1358,10 +1358,30 @@ public class PGL { public void glVertexAttrib4f(int loc, float value0, float value1, float value2, float value3) { - gl2.glVertexAttrib4f(loc, value0, value1, value2, value3); + gl2.glVertexAttrib4f(loc, value0, value1, value2, value3); } + public void glVertexAttrib1fv(int loc, float[] v, int offset) { + gl2.glVertexAttrib1fv(loc, v, offset); + } + + + public void glVertexAttrib2fv(int loc, float[] v, int offset) { + gl2.glVertexAttrib2fv(loc, v, offset); + } + + + public void glVertexAttrib3fv(int loc, float[] v, int offset) { + gl2.glVertexAttrib3fv(loc, v, offset); + } + + + public void glVertexAttrib4fv(int loc, float[] v, int offset) { + gl2.glVertexAttrib4fv(loc, v, offset); + } + + public void glShaderSource(int id, String source) { gl2.glShaderSource(id, 1, new String[] { source }, (int[]) null, 0); } @@ -1779,6 +1799,12 @@ public class PGL { } } + + public void drawTextureCustom(int target, int id, int width, int height, + int X0, int Y0, int X1, int Y1, int program) { + // ... + } + public void drawTextureRect(int id, int width, int height, int texX0, int texY0, int texX1, int texY1, diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 31274164b..5459d6966 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -77,29 +77,29 @@ public class PGraphicsOpenGL extends PGraphics { // VBOs for immediate rendering: - public int glPolyVertexBufferID; - public int glPolyColorBufferID; - public int glPolyNormalBufferID; - public int glPolyTexcoordBufferID; - public int glPolyAmbientBufferID; - public int glPolySpecularBufferID; - public int glPolyEmissiveBufferID; - public int glPolyShininessBufferID; - public int glPolyIndexBufferID; + public int glPolyVertex; + public int glPolyColor; + public int glPolyNormal; + public int glPolyTexcoord; + public int glPolyAmbient; + public int glPolySpecular; + public int glPolyEmissive; + public int glPolyShininess; + public int glPolyIndex; protected boolean polyBuffersCreated = false; protected PGL.Context polyBuffersContext; - public int glLineVertexBufferID; - public int glLineColorBufferID; - public int glLineAttribBufferID; - public int glLineIndexBufferID; + public int glLineVertex; + public int glLineColor; + public int glLineAttrib; + public int glLineIndex; protected boolean lineBuffersCreated = false; protected PGL.Context lineBuffersContext; - public int glPointVertexBufferID; - public int glPointColorBufferID; - public int glPointAttribBufferID; - public int glPointIndexBufferID; + public int glPointVertex; + public int glPointColor; + public int glPointAttrib; + public int glPointIndex; protected boolean pointBuffersCreated = false; protected PGL.Context pointBuffersContext; @@ -358,6 +358,10 @@ public class PGraphicsOpenGL extends PGraphics { /** A handy reference to the PTexture bound to the drawing surface * (off or on-screen) */ protected Texture texture; + + /** Used to create a temporary copy of the color buffer of this + * rendering surface when applying a filter */ + protected Texture textureCopy; /** IntBuffer wrapping the pixels array. */ protected IntBuffer pixelBuffer; @@ -445,25 +449,25 @@ public class PGraphicsOpenGL extends PGraphics { tessGeo = newTessGeometry(IMMEDIATE); texCache = newTexCache(); - glPolyVertexBufferID = 0; - glPolyColorBufferID = 0; - glPolyNormalBufferID = 0; - glPolyTexcoordBufferID = 0; - glPolyAmbientBufferID = 0; - glPolySpecularBufferID = 0; - glPolyEmissiveBufferID = 0; - glPolyShininessBufferID = 0; - glPolyIndexBufferID = 0; + glPolyVertex = 0; + glPolyColor = 0; + glPolyNormal = 0; + glPolyTexcoord = 0; + glPolyAmbient = 0; + glPolySpecular = 0; + glPolyEmissive = 0; + glPolyShininess = 0; + glPolyIndex = 0; - glLineVertexBufferID = 0; - glLineColorBufferID = 0; - glLineAttribBufferID = 0; - glLineIndexBufferID = 0; + glLineVertex = 0; + glLineColor = 0; + glLineAttrib = 0; + glLineIndex = 0; - glPointVertexBufferID = 0; - glPointColorBufferID = 0; - glPointAttribBufferID = 0; - glPointIndexBufferID = 0; + glPointVertex = 0; + glPointColor = 0; + glPointAttrib = 0; + glPointIndex = 0; } @@ -1114,42 +1118,42 @@ public class PGraphicsOpenGL extends PGraphics { int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - glPolyVertexBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID); + glPolyVertex = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW); - glPolyColorBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID); + glPolyColor = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPolyNormalBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID); + glPolyNormal = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW); - glPolyTexcoordBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID); + glPolyTexcoord = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, null, PGL.GL_STATIC_DRAW); - glPolyAmbientBufferID = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID); + glPolyAmbient = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPolySpecularBufferID = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID); + glPolySpecular = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPolyEmissiveBufferID = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID); + glPolyEmissive = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPolyShininessBufferID = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID); + glPolyShininess = pgPrimary.createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizef, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glPolyIndexBufferID = createVertexBufferObject(polyBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndexBufferID); + glPolyIndex = createVertexBufferObject(polyBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, sizex, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); @@ -1166,36 +1170,36 @@ public class PGraphicsOpenGL extends PGraphics { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.polyVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyColors, 0, size), PGL.GL_STATIC_DRAW); if (lit) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, FloatBuffer.wrap(tessGeo.polyNormals, 0, 3 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyAmbient, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polySpecular, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyEmissive, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizef, FloatBuffer.wrap(tessGeo.polyShininess, 0, size), PGL.GL_STATIC_DRAW); } if (tex) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.polyTexcoords, 0, 2 * size), PGL.GL_STATIC_DRAW); } - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.polyIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.polyIndices, 0, tessGeo.polyIndexCount), PGL.GL_STATIC_DRAW); } @@ -1214,32 +1218,32 @@ public class PGraphicsOpenGL extends PGraphics { protected void deletePolyBuffers() { if (polyBuffersCreated) { - deleteVertexBufferObject(glPolyVertexBufferID, polyBuffersContext.code()); - glPolyVertexBufferID = 0; + deleteVertexBufferObject(glPolyVertex, polyBuffersContext.code()); + glPolyVertex = 0; - deleteVertexBufferObject(glPolyColorBufferID, polyBuffersContext.code()); - glPolyColorBufferID = 0; + deleteVertexBufferObject(glPolyColor, polyBuffersContext.code()); + glPolyColor = 0; - deleteVertexBufferObject(glPolyNormalBufferID, polyBuffersContext.code()); - glPolyNormalBufferID = 0; + deleteVertexBufferObject(glPolyNormal, polyBuffersContext.code()); + glPolyNormal = 0; - deleteVertexBufferObject(glPolyTexcoordBufferID, polyBuffersContext.code()); - glPolyTexcoordBufferID = 0; + deleteVertexBufferObject(glPolyTexcoord, polyBuffersContext.code()); + glPolyTexcoord = 0; - deleteVertexBufferObject(glPolyAmbientBufferID, polyBuffersContext.code()); - glPolyAmbientBufferID = 0; + deleteVertexBufferObject(glPolyAmbient, polyBuffersContext.code()); + glPolyAmbient = 0; - deleteVertexBufferObject(glPolySpecularBufferID, polyBuffersContext.code()); - glPolySpecularBufferID = 0; + deleteVertexBufferObject(glPolySpecular, polyBuffersContext.code()); + glPolySpecular = 0; - deleteVertexBufferObject(glPolyEmissiveBufferID, polyBuffersContext.code()); - glPolyEmissiveBufferID = 0; + deleteVertexBufferObject(glPolyEmissive, polyBuffersContext.code()); + glPolyEmissive = 0; - deleteVertexBufferObject(glPolyShininessBufferID, polyBuffersContext.code()); - glPolyShininessBufferID = 0; + deleteVertexBufferObject(glPolyShininess, polyBuffersContext.code()); + glPolyShininess = 0; - deleteVertexBufferObject(glPolyIndexBufferID, polyBuffersContext.code()); - glPolyIndexBufferID = 0; + deleteVertexBufferObject(glPolyIndex, polyBuffersContext.code()); + glPolyIndex = 0; polyBuffersCreated = false; } @@ -1254,23 +1258,23 @@ public class PGraphicsOpenGL extends PGraphics { int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - glLineVertexBufferID = createVertexBufferObject(lineBuffersContext.code()); + glLineVertex = createVertexBufferObject(lineBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW); - glLineColorBufferID = createVertexBufferObject(lineBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID); + glLineColor = createVertexBufferObject(lineBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glLineAttribBufferID = createVertexBufferObject(lineBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID); + glLineAttrib = createVertexBufferObject(lineBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glLineIndexBufferID = createVertexBufferObject(lineBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); + glLineIndex = createVertexBufferObject(lineBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, sizex, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); @@ -1287,16 +1291,16 @@ public class PGraphicsOpenGL extends PGraphics { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.lineColors, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineAttribs, 0, 4 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.lineIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.lineIndices, 0, tessGeo.lineIndexCount), PGL.GL_STATIC_DRAW); } @@ -1315,17 +1319,17 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteLineBuffers() { if (lineBuffersCreated) { - deleteVertexBufferObject(glLineVertexBufferID, lineBuffersContext.code()); - glLineVertexBufferID = 0; + deleteVertexBufferObject(glLineVertex, lineBuffersContext.code()); + glLineVertex = 0; - deleteVertexBufferObject(glLineColorBufferID, lineBuffersContext.code()); - glLineColorBufferID = 0; + deleteVertexBufferObject(glLineColor, lineBuffersContext.code()); + glLineColor = 0; - deleteVertexBufferObject(glLineAttribBufferID, lineBuffersContext.code()); - glLineAttribBufferID = 0; + deleteVertexBufferObject(glLineAttrib, lineBuffersContext.code()); + glLineAttrib = 0; - deleteVertexBufferObject(glLineIndexBufferID, lineBuffersContext.code()); - glLineIndexBufferID = 0; + deleteVertexBufferObject(glLineIndex, lineBuffersContext.code()); + glLineIndex = 0; lineBuffersCreated = false; } @@ -1340,22 +1344,22 @@ public class PGraphicsOpenGL extends PGraphics { int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - glPointVertexBufferID = createVertexBufferObject(pointBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID); + glPointVertex = createVertexBufferObject(pointBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, null, PGL.GL_STATIC_DRAW); - glPointColorBufferID = createVertexBufferObject(pointBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID); + glPointColor = createVertexBufferObject(pointBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, null, PGL.GL_STATIC_DRAW); - glPointAttribBufferID = createVertexBufferObject(pointBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID); + glPointAttrib = createVertexBufferObject(pointBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glPointIndexBufferID = createVertexBufferObject(pointBuffersContext.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); + glPointIndex = createVertexBufferObject(pointBuffersContext.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, sizex, null, PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); @@ -1372,16 +1376,16 @@ public class PGraphicsOpenGL extends PGraphics { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.pointVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.pointColors, 0, size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.pointAttribs, 0, 2 * size), PGL.GL_STATIC_DRAW); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.pointIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.pointIndices, 0, tessGeo.pointIndexCount), PGL.GL_STATIC_DRAW); } @@ -1400,17 +1404,17 @@ public class PGraphicsOpenGL extends PGraphics { protected void deletePointBuffers() { if (pointBuffersCreated) { - deleteVertexBufferObject(glPointVertexBufferID, pointBuffersContext.code()); - glPointVertexBufferID = 0; + deleteVertexBufferObject(glPointVertex, pointBuffersContext.code()); + glPointVertex = 0; - deleteVertexBufferObject(glPointColorBufferID, pointBuffersContext.code()); - glPointColorBufferID = 0; + deleteVertexBufferObject(glPointColor, pointBuffersContext.code()); + glPointColor = 0; - deleteVertexBufferObject(glPointAttribBufferID, pointBuffersContext.code()); - glPointAttribBufferID = 0; + deleteVertexBufferObject(glPointAttrib, pointBuffersContext.code()); + glPointAttrib = 0; - deleteVertexBufferObject(glPointIndexBufferID, pointBuffersContext.code()); - glPointIndexBufferID = 0; + deleteVertexBufferObject(glPointIndex, pointBuffersContext.code()); + glPointIndex = 0; pointBuffersCreated = false; } @@ -2475,23 +2479,23 @@ public class PGraphicsOpenGL extends PGraphics { cache.indexOffset[n] + cache.indexCount[n] - ioffset; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(glPolyVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(glPolyColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setVertexAttribute(glPolyVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(glPolyColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); if (lights) { - shader.setNormalAttribute(glPolyNormalBufferID, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT); - shader.setAmbientAttribute(glPolyAmbientBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setSpecularAttribute(glPolySpecularBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setEmissiveAttribute(glPolyEmissiveBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setShininessAttribute(glPolyShininessBufferID, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); + shader.setNormalAttribute(glPolyNormal, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT); + shader.setAmbientAttribute(glPolyAmbient, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setSpecularAttribute(glPolySpecular, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setEmissiveAttribute(glPolyEmissive, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setShininessAttribute(glPolyShininess, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); } if (tex != null) { - shader.setTexcoordAttribute(glPolyTexcoordBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); + shader.setTexcoordAttribute(glPolyTexcoord, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); shader.setTexture(tex); } - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -2613,11 +2617,11 @@ public class PGraphicsOpenGL extends PGraphics { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(glLineVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(glLineColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setLineAttribute(glLineAttribBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setVertexAttribute(glLineVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(glLineColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setLineAttribute(glLineAttrib, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -2711,11 +2715,11 @@ public class PGraphicsOpenGL extends PGraphics { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(glPointVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(glPointColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setPointAttribute(glPointAttribBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); + shader.setVertexAttribute(glPointVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(glPointColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setPointAttribute(glPointAttrib, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -4977,7 +4981,7 @@ public class PGraphicsOpenGL extends PGraphics { if (primarySurface) { loadTextureImpl(POINT, false); // (first making sure that the screen texture is valid). } - pgl.copyToTexture(texture.glTarget, texture.glFormat, texture.glID, + pgl.copyToTexture(texture.glTarget, texture.glFormat, texture.glName, x, y, w, h, IntBuffer.wrap(rgbaPixels)); if (primarySurface || offscreenMultisample) { @@ -5096,14 +5100,14 @@ public class PGraphicsOpenGL extends PGraphics { protected void drawTexture() { - pgl.drawTexture(texture.glTarget, texture.glID, + pgl.drawTexture(texture.glTarget, texture.glName, texture.glWidth, texture.glHeight, 0, 0, width, height); } protected void drawTexture(int x, int y, int w, int h) { - pgl.drawTexture(texture.glTarget, texture.glID, + pgl.drawTexture(texture.glTarget, texture.glName, texture.glWidth, texture.glHeight, x, y, x + w, y + h); } @@ -5194,6 +5198,57 @@ public class PGraphicsOpenGL extends PGraphics { temp.filter(kind, param); set(0, 0, temp); } + + + public void filter(Object shader) { + if (!(shader instanceof PolyTexShader)) { + PGraphics.showWarning("Object is not a valid shader"); + return; + } + + PolyTexShader texShader = (PolyTexShader)shader; + +// if (shader instanceof FilterShader) { +// +// } + + if (primarySurface) { + + + } else { + if (textureCopy == null) { + Texture.Parameters params = new Texture.Parameters(ARGB, Texture.BILINEAR, false); + textureCopy = new Texture(parent, width, height, params); + textureCopy.setFlippedY(true); + } + + flush(); + + // Disable writing to the depth buffer, so that after applying the filter we can + // still use the depth information to properly add geometry to the scene. + + offscreenFramebuffer.setColorBuffer(textureCopy); + offscreenFramebuffer.clear(); + + // Disable depth test so the texture overwrites everything else. + + beginPGL(); + pgl.drawTexture(texture.glTarget, texture.glName, + texture.glWidth, texture.glHeight, + 0, 0, width, height); + endPGL(); + + offscreenFramebuffer.setColorBuffer(texture); + offscreenFramebuffer.clear(); + + beginPGL(); + pgl.drawTextureCustom(textureCopy.glTarget, textureCopy.glName, + textureCopy.glWidth, textureCopy.glHeight, + 0, 0, width, height, texShader.glProgram); + endPGL(); + } + + } ////////////////////////////////////////////////////////////// @@ -5367,38 +5422,31 @@ public class PGraphicsOpenGL extends PGraphics { * @param img the image to have a texture metadata associated to it */ public Texture getTexture(PImage img) { - Texture tex = (Texture)img.getCache(pgPrimary); - if (tex == null) { - tex = addTexture(img); - } else { - if (tex.contextIsOutdated()) { - tex = addTexture(img); + Texture tex = (Texture)initCache(img); + + if (img.isModified()) { + if (img.width != tex.width || img.height != tex.height) { + tex.init(img.width, img.height); } + updateTexture(img, tex); + } - if (img.isModified()) { - if (img.width != tex.width || img.height != tex.height) { - tex.init(img.width, img.height); - } - updateTexture(img, tex); - } - - if (tex.hasBuffers()) { - tex.bufferUpdate(); - } + if (tex.hasBuffers()) { + tex.bufferUpdate(); } return tex; } - public void initCache(PImage img) { + public Object initCache(PImage img) { Texture tex = (Texture)img.getCache(pgPrimary); - if (tex == null) { + if (tex == null || tex.contextIsOutdated()) { tex = addTexture(img); - } else { - if (tex.contextIsOutdated()) { - tex = addTexture(img); + if (img.pixels != null) { + tex.set(img.pixels); } - } + } + return tex; } @@ -5419,32 +5467,22 @@ public class PGraphicsOpenGL extends PGraphics { params.sampling = textureSampling; if (params.sampling == Texture.TRILINEAR && !params.mipmaps) { params.sampling = Texture.BILINEAR; - PGraphics.showWarning("TRILINEAR texture sampling requires mipmaps, which are disabled. Will use BILINEAR instead."); + PGraphics.showWarning("TRILINEAR texture sampling requires mipmaps, which are disabled. I will use BILINEAR instead."); } params.wrapU = textureWrap; - params.wrapV = textureWrap; - img.setParams(pgPrimary, params); - } - if (img.parent == null) { - img.parent = parent; - } - Texture tex = new Texture(img.parent, img.width, img.height, params); - if (img.pixels == null) { - img.loadPixels(); - } - if (img.pixels != null) tex.set(img.pixels); - img.setCache(pgPrimary, tex); - return tex; + params.wrapV = textureWrap; + } + return addTexture(img, params); } protected Texture addTexture(PImage img, Texture.Parameters params) { - Texture tex = new Texture(img.parent, img.width, img.height, params); - if (img.pixels == null) { - img.loadPixels(); + if (img.parent == null) { + img.parent = parent; } - if (img.pixels != null) tex.set(img.pixels); + Texture tex = new Texture(img.parent, img.width, img.height, params); img.setCache(pgPrimary, tex); + img.setParams(pgPrimary, params); return tex; } @@ -5458,6 +5496,7 @@ public class PGraphicsOpenGL extends PGraphics { img.height = tex.height; img.format = ARGB; img.setCache(pgPrimary, tex); + img.setParams(pgPrimary, tex.getParameters()); return img; } @@ -5590,8 +5629,8 @@ public class PGraphicsOpenGL extends PGraphics { // SHADER HANDLING - public PShader loadShader(String vertFilename, String fragFilename, int kind) { - if (kind == PShader.FLAT) { + public Object loadShader(String vertFilename, String fragFilename, int kind) { + if (kind == PShader.FLAT) { return new PolyFlatShader(parent, vertFilename, fragFilename); } else if (kind == PShader.LIT) { return new PolyLightShader(parent, vertFilename, fragFilename); @@ -5610,7 +5649,7 @@ public class PGraphicsOpenGL extends PGraphics { } - public PShader loadShader(String fragFilename, int kind) { + public Object loadShader(String fragFilename, int kind) { PShader shader; if (kind == PShader.FLAT) { shader = new PolyFlatShader(parent); @@ -5637,9 +5676,23 @@ public class PGraphicsOpenGL extends PGraphics { shader.setFragmentShader(fragFilename); return shader; } + + + public Object loadShader(String vertFilename, String fragFilename) { + return loadShader(vertFilename, fragFilename, PShader.TEXTURED); + } + + + public Object loadShader(String fragFilename) { + return loadShader(fragFilename, PShader.TEXTURED); + } - public void setShader(PShader shader, int kind) { + public void shader(Object shader, int kind) { + if (!(shader instanceof PShader)) { + PGraphics.showWarning("Object is not a valid shader!"); + return; + } flush(); // Flushing geometry with a different shader. if (kind == PShader.FLAT) { polyFlatShader = (PolyFlatShader) shader; @@ -5659,7 +5712,45 @@ public class PGraphicsOpenGL extends PGraphics { } - public PShader getShader(int kind) { + public void resetShader(int kind) { + flush(); // Flushing geometry with a different shader. + if (kind == PShader.FLAT) { + if (defPolyFlatShader == null) { + defPolyFlatShader = new PolyFlatShader(parent, defPolyFlatShaderVertURL, defPolyNoTexShaderFragURL); + } + polyFlatShader = defPolyFlatShader; + } else if (kind == PShader.LIT) { + if (defPolyLightShader == null) { + defPolyLightShader = new PolyLightShader(parent, defPolyLightShaderVertURL, defPolyNoTexShaderFragURL); + } + polyLightShader = defPolyLightShader; + } else if (kind == PShader.TEXTURED) { + if (defPolyTexShader == null) { + defPolyTexShader = new PolyTexShader(parent, defPolyTexShaderVertURL, defPolyTexShaderFragURL); + } + polyTexShader = defPolyTexShader; + } else if (kind == PShader.FULL) { + if (defPolyFullShader == null) { + defPolyFullShader = new PolyFullShader(parent, defPolyFullShaderVertURL, defPolyTexShaderFragURL); + } + polyFullShader = defPolyFullShader; + } else if (kind == PShader.LINE) { + if (defLineShader == null) { + defLineShader = new LineShader(parent, defLineShaderVertURL, defLineShaderFragURL); + } + lineShader = defLineShader; + } else if (kind == PShader.POINT) { + if (defPointShader == null) { + defPointShader = new PointShader(parent, defPointShaderVertURL, defPointShaderFragURL); + } + pointShader = defPointShader; + } else { + PGraphics.showWarning("Wrong shader type"); + } + } + + + public Object getShader(int kind) { PShader shader; if (kind == PShader.FLAT) { if (polyFlatShader == null) { @@ -5717,47 +5808,9 @@ public class PGraphicsOpenGL extends PGraphics { shader.loadAttributes(); shader.loadUniforms(); return shader; - } + } - public void defaultShader(int kind) { - flush(); // Flushing geometry with a different shader. - if (kind == PShader.FLAT) { - if (defPolyFlatShader == null) { - defPolyFlatShader = new PolyFlatShader(parent, defPolyFlatShaderVertURL, defPolyNoTexShaderFragURL); - } - polyFlatShader = defPolyFlatShader; - } else if (kind == PShader.LIT) { - if (defPolyLightShader == null) { - defPolyLightShader = new PolyLightShader(parent, defPolyLightShaderVertURL, defPolyNoTexShaderFragURL); - } - polyLightShader = defPolyLightShader; - } else if (kind == PShader.TEXTURED) { - if (defPolyTexShader == null) { - defPolyTexShader = new PolyTexShader(parent, defPolyTexShaderVertURL, defPolyTexShaderFragURL); - } - polyTexShader = defPolyTexShader; - } else if (kind == PShader.FULL) { - if (defPolyFullShader == null) { - defPolyFullShader = new PolyFullShader(parent, defPolyFullShaderVertURL, defPolyTexShaderFragURL); - } - polyFullShader = defPolyFullShader; - } else if (kind == PShader.LINE) { - if (defLineShader == null) { - defLineShader = new LineShader(parent, defLineShaderVertURL, defLineShaderFragURL); - } - lineShader = defLineShader; - } else if (kind == PShader.POINT) { - if (defPointShader == null) { - defPointShader = new PointShader(parent, defPointShaderVertURL, defPointShaderFragURL); - } - pointShader = defPointShader; - } else { - PGraphics.showWarning("Wrong shader type"); - } - } - - protected PolyShader getPolyShader(boolean lit, boolean tex) { PolyShader shader; if (lit) { @@ -5831,7 +5884,7 @@ public class PGraphicsOpenGL extends PGraphics { return pointShader; } - + protected class PolyShader extends PShader { public PolyShader(PApplet parent) { super(parent); @@ -5878,22 +5931,22 @@ public class PGraphicsOpenGL extends PGraphics { } public void loadAttributes() { - inVertexLoc = getAttribLocation("inVertex"); - inColorLoc = getAttribLocation("inColor"); + inVertexLoc = getAttributeLoc("inVertex"); + inColorLoc = getAttributeLoc("inColor"); } public void loadUniforms() { - projmodelviewMatrixLoc = getUniformLocation("projmodelviewMatrix"); - modelviewMatrixLoc = getUniformLocation("modelviewMatrix"); - projectionMatrixLoc = getUniformLocation("projectionMatrix"); + projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); + modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); + projectionMatrixLoc = getUniformLoc("projectionMatrix"); } public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); } public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); } public void bind() { @@ -5905,17 +5958,17 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent != null) { if (-1 < projmodelviewMatrixLoc) { pgCurrent.updateGLProjmodelview(); - setMat4Uniform(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); + setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); } if (-1 < modelviewMatrixLoc) { pgCurrent.updateGLModelview(); - setMat4Uniform(modelviewMatrixLoc, pgCurrent.glModelview); + setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview); } if (-1 < projectionMatrixLoc) { pgCurrent.updateGLProjection(); - setMat4Uniform(projectionMatrixLoc, pgCurrent.glProjection); + setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); } } } @@ -5968,58 +6021,58 @@ public class PGraphicsOpenGL extends PGraphics { } public void loadAttributes() { - inVertexLoc = getAttribLocation("inVertex"); - inColorLoc = getAttribLocation("inColor"); - inNormalLoc = getAttribLocation("inNormal"); + inVertexLoc = getAttributeLoc("inVertex"); + inColorLoc = getAttributeLoc("inColor"); + inNormalLoc = getAttributeLoc("inNormal"); - inAmbientLoc = getAttribLocation("inAmbient"); - inSpecularLoc = getAttribLocation("inSpecular"); - inEmissiveLoc = getAttribLocation("inEmissive"); - inShineLoc = getAttribLocation("inShine"); + inAmbientLoc = getAttributeLoc("inAmbient"); + inSpecularLoc = getAttributeLoc("inSpecular"); + inEmissiveLoc = getAttributeLoc("inEmissive"); + inShineLoc = getAttributeLoc("inShine"); } public void loadUniforms() { - projmodelviewMatrixLoc = getUniformLocation("projmodelviewMatrix"); - modelviewMatrixLoc = getUniformLocation("modelviewMatrix"); - projectionMatrixLoc = getUniformLocation("projectionMatrix"); - normalMatrixLoc = getUniformLocation("normalMatrix"); + projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); + modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); + projectionMatrixLoc = getUniformLoc("projectionMatrix"); + normalMatrixLoc = getUniformLoc("normalMatrix"); - lightCountLoc = getUniformLocation("lightCount"); - lightPositionLoc = getUniformLocation("lightPosition"); - lightNormalLoc = getUniformLocation("lightNormal"); - lightAmbientLoc = getUniformLocation("lightAmbient"); - lightDiffuseLoc = getUniformLocation("lightDiffuse"); - lightSpecularLoc = getUniformLocation("lightSpecular"); - lightFalloffCoefficientsLoc = getUniformLocation("lightFalloffCoefficients"); - lightSpotParametersLoc = getUniformLocation("lightSpotParameters"); + lightCountLoc = getUniformLoc("lightCount"); + lightPositionLoc = getUniformLoc("lightPosition"); + lightNormalLoc = getUniformLoc("lightNormal"); + lightAmbientLoc = getUniformLoc("lightAmbient"); + lightDiffuseLoc = getUniformLoc("lightDiffuse"); + lightSpecularLoc = getUniformLoc("lightSpecular"); + lightFalloffCoefficientsLoc = getUniformLoc("lightFalloffCoefficients"); + lightSpotParametersLoc = getUniformLoc("lightSpotParameters"); } public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); } public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); } public void setNormalAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inNormalLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inNormalLoc, vboId, size, type, false, stride, offset); } public void setAmbientAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inAmbientLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inAmbientLoc, vboId, size, type, true, stride, offset); } public void setSpecularAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inSpecularLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inSpecularLoc, vboId, size, type, true, stride, offset); } public void setEmissiveAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inEmissiveLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inEmissiveLoc, vboId, size, type, true, stride, offset); } public void setShininessAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inShineLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inShineLoc, vboId, size, type, false, stride, offset); } public void bind() { @@ -6037,32 +6090,32 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent != null) { if (-1 < projmodelviewMatrixLoc) { pgCurrent.updateGLProjmodelview(); - setMat4Uniform(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); + setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); } if (-1 < modelviewMatrixLoc) { pgCurrent.updateGLModelview(); - setMat4Uniform(modelviewMatrixLoc, pgCurrent.glModelview); + setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview); } if (-1 < projectionMatrixLoc) { pgCurrent.updateGLProjection(); - setMat4Uniform(projectionMatrixLoc, pgCurrent.glProjection); + setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); } if (-1 < normalMatrixLoc) { pgCurrent.updateGLNormal(); - setMat3Uniform(normalMatrixLoc, pgCurrent.glNormal); + setUniformMatrix(normalMatrixLoc, pgCurrent.glNormal); } - setIntUniform(lightCountLoc, pgCurrent.lightCount); - setFloatVecUniform(lightPositionLoc, pgCurrent.lightPosition, 4); - setFloatVecUniform(lightNormalLoc, pgCurrent.lightNormal, 3); - setFloatVecUniform(lightAmbientLoc, pgCurrent.lightAmbient, 3); - setFloatVecUniform(lightDiffuseLoc, pgCurrent.lightDiffuse, 3); - setFloatVecUniform(lightSpecularLoc, pgCurrent.lightSpecular, 3); - setFloatVecUniform(lightFalloffCoefficientsLoc, pgCurrent.lightFalloffCoefficients, 3); - setFloatVecUniform(lightSpotParametersLoc, pgCurrent.lightSpotParameters, 2); + setUniformValue(lightCountLoc, pgCurrent.lightCount); + setUniformVector(lightPositionLoc, pgCurrent.lightPosition, 4); + setUniformVector(lightNormalLoc, pgCurrent.lightNormal, 3); + setUniformVector(lightAmbientLoc, pgCurrent.lightAmbient, 3); + setUniformVector(lightDiffuseLoc, pgCurrent.lightDiffuse, 3); + setUniformVector(lightSpecularLoc, pgCurrent.lightSpecular, 3); + setUniformVector(lightFalloffCoefficientsLoc, pgCurrent.lightFalloffCoefficients, 3); + setUniformVector(lightSpotParametersLoc, pgCurrent.lightSpotParameters, 2); } } @@ -6106,18 +6159,18 @@ public class PGraphicsOpenGL extends PGraphics { public void loadUniforms() { super.loadUniforms(); - texcoordMatrixLoc = getUniformLocation("texcoordMatrix"); - texcoordOffsetLoc = getUniformLocation("texcoordOffset"); + texcoordMatrixLoc = getUniformLoc("texcoordMatrix"); + texcoordOffsetLoc = getUniformLoc("texcoordOffset"); } public void loadAttributes() { super.loadAttributes(); - inTexcoordLoc = getAttribLocation("inTexcoord"); + inTexcoordLoc = getAttributeLoc("inTexcoord"); } public void setTexcoordAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inTexcoordLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset); } public void setTexture(Texture tex) { @@ -6149,10 +6202,10 @@ public class PGraphicsOpenGL extends PGraphics { tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv; tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0; tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0; - setMat4Uniform(texcoordMatrixLoc, tcmat); + setUniformMatrix(texcoordMatrixLoc, tcmat); } - setFloatUniform(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); + setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); } public void bind() { @@ -6168,7 +6221,7 @@ public class PGraphicsOpenGL extends PGraphics { } } - + protected class PolyFullShader extends PolyLightShader { protected int inTexcoordLoc; @@ -6192,18 +6245,18 @@ public class PGraphicsOpenGL extends PGraphics { public void loadUniforms() { super.loadUniforms(); - texcoordMatrixLoc = getUniformLocation("texcoordMatrix"); - texcoordOffsetLoc = getUniformLocation("texcoordOffset"); + texcoordMatrixLoc = getUniformLoc("texcoordMatrix"); + texcoordOffsetLoc = getUniformLoc("texcoordOffset"); } public void loadAttributes() { super.loadAttributes(); - inTexcoordLoc = getAttribLocation("inTexcoord"); + inTexcoordLoc = getAttributeLoc("inTexcoord"); } public void setTexcoordAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inTexcoordLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inTexcoordLoc, vboId, size, type, false, stride, offset); } public void setTexture(Texture tex) { @@ -6235,10 +6288,10 @@ public class PGraphicsOpenGL extends PGraphics { tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv; tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0; tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0; - setMat4Uniform(texcoordMatrixLoc, tcmat); + setUniformMatrix(texcoordMatrixLoc, tcmat); } - setFloatUniform(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); + setUniformValue(texcoordOffsetLoc, 1.0f / tex.width, 1.0f / tex.height); } public void bind() { @@ -6281,36 +6334,31 @@ public class PGraphicsOpenGL extends PGraphics { } public void loadAttributes() { - inVertexLoc = getAttribLocation("inVertex"); - inColorLoc = getAttribLocation("inColor"); - inAttribLoc = getAttribLocation("inLine"); + inVertexLoc = getAttributeLoc("inVertex"); + inColorLoc = getAttributeLoc("inColor"); + inAttribLoc = getAttributeLoc("inLine"); } public void loadUniforms() { - projmodelviewMatrixLoc = getUniformLocation("projmodelviewMatrix"); - modelviewMatrixLoc = getUniformLocation("modelviewMatrix"); - projectionMatrixLoc = getUniformLocation("projectionMatrix"); + projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); + modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); + projectionMatrixLoc = getUniformLoc("projectionMatrix"); - viewportLoc = getUniformLocation("viewport"); - perspectiveLoc = getUniformLocation("perspective"); - zfactorLoc = getUniformLocation("zfactor"); - } - - public void setAttribute(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, vboId); - pgl.glVertexAttribPointer(loc, size, type, normalized, stride, offset); + viewportLoc = getUniformLoc("viewport"); + perspectiveLoc = getUniformLoc("perspective"); + zfactorLoc = getUniformLoc("zfactor"); } public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); } public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); } public void setLineAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inAttribLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inAttribLoc, vboId, size, type, false, stride, offset); } public void bind() { @@ -6323,31 +6371,35 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent != null) { if (-1 < projmodelviewMatrixLoc) { pgCurrent.updateGLProjmodelview(); - setMat4Uniform(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); + setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); } if (-1 < modelviewMatrixLoc) { pgCurrent.updateGLModelview(); - setMat4Uniform(modelviewMatrixLoc, pgCurrent.glModelview); + setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview); } if (-1 < projectionMatrixLoc) { pgCurrent.updateGLProjection(); - setMat4Uniform(projectionMatrixLoc, pgCurrent.glProjection); + setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); } - setFloatUniform(viewportLoc, pgCurrent.viewport[0], pgCurrent.viewport[1], pgCurrent.viewport[2], pgCurrent.viewport[3]); + float x = pgCurrent.viewport[0]; + float y = pgCurrent.viewport[1]; + float w = pgCurrent.viewport[2]; + float h = pgCurrent.viewport[3]; + setUniformValue(viewportLoc, x, y, w, h); if (pgCurrent.hintEnabled(ENABLE_PERSPECTIVE_CORRECTED_LINES)) { - setIntUniform(perspectiveLoc, 1); + setUniformValue(perspectiveLoc, 1); } else { - setIntUniform(perspectiveLoc, 0); + setUniformValue(perspectiveLoc, 0); } if (pgCurrent.hintEnabled(ENABLE_ACCURATE_2D)) { - setFloatUniform(zfactorLoc, 1); + setUniformValue(zfactorLoc, 1.0f); } else { - setFloatUniform(zfactorLoc, 0.99f); + setUniformValue(zfactorLoc, 0.99f); } } } @@ -6386,32 +6438,27 @@ public class PGraphicsOpenGL extends PGraphics { } public void loadAttributes() { - inVertexLoc = getAttribLocation("inVertex"); - inColorLoc = getAttribLocation("inColor"); - inPointLoc = getAttribLocation("inPoint"); + inVertexLoc = getAttributeLoc("inVertex"); + inColorLoc = getAttributeLoc("inColor"); + inPointLoc = getAttributeLoc("inPoint"); } public void loadUniforms() { - projmodelviewMatrixLoc = getUniformLocation("projmodelviewMatrix"); - modelviewMatrixLoc = getUniformLocation("modelviewMatrix"); - projectionMatrixLoc = getUniformLocation("projectionMatrix"); - } - - public void setAttribute(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, vboId); - pgl.glVertexAttribPointer(loc, size, type, normalized, stride, offset); + projmodelviewMatrixLoc = getUniformLoc("projmodelviewMatrix"); + modelviewMatrixLoc = getUniformLoc("modelviewMatrix"); + projectionMatrixLoc = getUniformLoc("projectionMatrix"); } public void setVertexAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inVertexLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inVertexLoc, vboId, size, type, false, stride, offset); } public void setColorAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inColorLoc, vboId, size, type, true, stride, offset); + setAttributeVBO(inColorLoc, vboId, size, type, true, stride, offset); } public void setPointAttribute(int vboId, int size, int type, int stride, int offset) { - setAttribute(inPointLoc, vboId, size, type, false, stride, offset); + setAttributeVBO(inPointLoc, vboId, size, type, false, stride, offset); } public void bind() { @@ -6424,17 +6471,17 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent != null) { if (-1 < projmodelviewMatrixLoc) { pgCurrent.updateGLProjmodelview(); - setMat4Uniform(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); + setUniformMatrix(projmodelviewMatrixLoc, pgCurrent.glProjmodelview); } if (-1 < modelviewMatrixLoc) { pgCurrent.updateGLModelview(); - setMat4Uniform(modelviewMatrixLoc, pgCurrent.glModelview); + setUniformMatrix(modelviewMatrixLoc, pgCurrent.glModelview); } if (-1 < projectionMatrixLoc) { pgCurrent.updateGLProjection(); - setMat4Uniform(projectionMatrixLoc, pgCurrent.glProjection); + setUniformMatrix(projectionMatrixLoc, pgCurrent.glProjection); } } } @@ -6450,6 +6497,7 @@ public class PGraphicsOpenGL extends PGraphics { } } + ////////////////////////////////////////////////////////////// // Utils diff --git a/java/libraries/opengl/src/processing/opengl/PShader.java b/java/libraries/opengl/src/processing/opengl/PShader.java index f839537b1..86ee6bec9 100644 --- a/java/libraries/opengl/src/processing/opengl/PShader.java +++ b/java/libraries/opengl/src/processing/opengl/PShader.java @@ -36,12 +36,13 @@ import java.util.HashMap; */ public class PShader { // shaders constants - static public final int FLAT = 0; - static public final int LIT = 1; - static public final int TEXTURED = 2; - static public final int FULL = 3; - static public final int LINE = 4; - static public final int POINT = 5; + static public final int FILTER = 0; + static public final int FLAT = 1; + static public final int LIT = 2; + static public final int TEXTURED = 3; + static public final int FULL = 4; + static public final int LINE = 5; + static public final int POINT = 6; protected PApplet parent; // The main renderer associated to the parent PApplet. @@ -55,9 +56,9 @@ public class PShader { protected PGL pgl; protected PGL.Context context; // The context that created this shader. - public int glProgramObjectID; - public int glVertexShaderID; - public int glFragmentShaderID; + public int glProgram; + public int glVertex; + public int glFragment; protected URL vertexURL; protected URL fragmentURL; @@ -83,9 +84,9 @@ public class PShader { this.vertexFilename = null; this.fragmentFilename = null; - glProgramObjectID = 0; - glVertexShaderID = 0; - glFragmentShaderID = 0; + glProgram = 0; + glVertex = 0; + glFragment = 0; bound = false; } @@ -118,9 +119,9 @@ public class PShader { this.vertexFilename = vertFilename; this.fragmentFilename = fragFilename; - glProgramObjectID = 0; - glVertexShaderID = 0; - glFragmentShaderID = 0; + glProgram = 0; + glVertex = 0; + glFragment = 0; } @@ -134,22 +135,22 @@ public class PShader { this.vertexFilename = null; this.fragmentFilename = null; - glProgramObjectID = 0; - glVertexShaderID = 0; - glFragmentShaderID = 0; + glProgram = 0; + glVertex = 0; + glFragment = 0; } protected void finalize() throws Throwable { try { - if (glVertexShaderID != 0) { - pgMain.finalizeGLSLVertShaderObject(glVertexShaderID, context.code()); + if (glVertex != 0) { + pgMain.finalizeGLSLVertShaderObject(glVertex, context.code()); } - if (glFragmentShaderID != 0) { - pgMain.finalizeGLSLFragShaderObject(glFragmentShaderID, context.code()); + if (glFragment != 0) { + pgMain.finalizeGLSLFragShaderObject(glFragment, context.code()); } - if (glProgramObjectID != 0) { - pgMain.finalizeGLSLProgramObject(glProgramObjectID, context.code()); + if (glProgram != 0) { + pgMain.finalizeGLSLProgramObject(glProgram, context.code()); } } finally { super.finalize(); @@ -182,7 +183,7 @@ public class PShader { */ public void bind() { init(); - pgl.glUseProgram(glProgramObjectID); + pgl.glUseProgram(glProgram); bound = true; consumeUniforms(); } @@ -328,9 +329,9 @@ public class PShader { * @param name String * @return int */ - protected int getAttribLocation(String name) { + protected int getAttributeLoc(String name) { init(); - return pgl.glGetAttribLocation(glProgramObjectID, name); + return pgl.glGetAttribLocation(glProgram, name); } @@ -340,13 +341,13 @@ public class PShader { * @param name String * @return int */ - protected int getUniformLocation(String name) { + protected int getUniformLoc(String name) { init(); - return pgl.glGetUniformLocation(glProgramObjectID, name); + return pgl.glGetUniformLocation(glProgram, name); } - protected void setAttribute(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) { + protected void setAttributeVBO(int loc, int vboId, int size, int type, boolean normalized, int stride, int offset) { if (-1 < loc) { pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, vboId); pgl.glVertexAttribPointer(loc, size, type, normalized, stride, offset); @@ -354,62 +355,62 @@ public class PShader { } - protected void setIntUniform(int loc, int x) { + protected void setUniformValue(int loc, int x) { if (-1 < loc) { pgl.glUniform1i(loc, x); } } - protected void setIntUniform(int loc, int x, int y) { + protected void setUniformValue(int loc, int x, int y) { if (-1 < loc) { pgl.glUniform2i(loc, x, y); } } - protected void setIntUniform(int loc, int x, int y, int z) { + protected void setUniformValue(int loc, int x, int y, int z) { if (-1 < loc) { pgl.glUniform3i(loc, x, y, z); } } - protected void setIntUniform(int loc, int x, int y, int z, int w) { + protected void setUniformValue(int loc, int x, int y, int z, int w) { if (-1 < loc) { pgl.glUniform4i(loc, x, y, z, w); } } - protected void setFloatUniform(int loc, float x) { + protected void setUniformValue(int loc, float x) { if (-1 < loc) { pgl.glUniform1f(loc, x); } } - protected void setFloatUniform(int loc, float x, float y) { + protected void setUniformValue(int loc, float x, float y) { if (-1 < loc) { pgl.glUniform2f(loc, x, y); } } - protected void setFloatUniform(int loc, float x, float y, float z) { + protected void setUniformValue(int loc, float x, float y, float z) { if (-1 < loc) { pgl.glUniform3f(loc, x, y, z); } } - protected void setFloatUniform(int loc, float x, float y, float z, float w) { + protected void setUniformValue(int loc, float x, float y, float z, float w) { if (-1 < loc) { pgl.glUniform4f(loc, x, y, z, w); } } - protected void setIntVecUniform(int loc, int[] vec, int ncoords) { + protected void setUniformVector(int loc, int[] vec, int ncoords) { if (-1 < loc) { if (ncoords == 1) { pgl.glUniform1iv(loc, vec.length, vec, 0); @@ -424,7 +425,7 @@ public class PShader { } - protected void setFloatVecUniform(int loc, float[] vec, int ncoords) { + protected void setUniformVector(int loc, float[] vec, int ncoords) { if (-1 < loc) { if (ncoords == 1) { pgl.glUniform1fv(loc, vec.length, vec, 0); @@ -439,25 +440,18 @@ public class PShader { } - protected void setMat2Uniform(int loc, float[] mat) { + protected void setUniformMatrix(int loc, float[] mat) { if (-1 < loc) { - pgl.glUniformMatrix2fv(loc, 1, false, mat, 0); + if (mat.length == 4) { + pgl.glUniformMatrix2fv(loc, 1, false, mat, 0); + } else if (mat.length == 9) { + pgl.glUniformMatrix3fv(loc, 1, false, mat, 0); + } else if (mat.length == 16) { + pgl.glUniformMatrix4fv(loc, 1, false, mat, 0); + } } } - - protected void setMat3Uniform(int loc, float[] mat) { - if (-1 < loc) { - pgl.glUniformMatrix3fv(loc, 1, false, mat, 0); - } - } - - - protected void setMat4Uniform(int loc, float[] mat) { - if (-1 < loc) { - pgl.glUniformMatrix4fv(loc, 1, false, mat, 0); - } - } /* @@ -494,7 +488,7 @@ public class PShader { protected void setUniformImpl(String name, int type, Object value) { - int loc = getUniformLocation(name); + int loc = getUniformLoc(name); if (-1 < loc) { if (uniformValues == null) { uniformValues = new HashMap(); @@ -575,9 +569,9 @@ public class PShader { protected void init() { - if (glProgramObjectID == 0 || contextIsOutdated()) { + if (glProgram == 0 || contextIsOutdated()) { context = pgl.getCurrentContext(); - glProgramObjectID = pgMain.createGLSLProgramObject(context.code()); + glProgram = pgMain.createGLSLProgramObject(context.code()); boolean hasVert = false; if (vertexFilename != null) { @@ -609,25 +603,25 @@ public class PShader { if (vertRes && fragRes) { if (hasVert) { - pgl.glAttachShader(glProgramObjectID, glVertexShaderID); + pgl.glAttachShader(glProgram, glVertex); } if (hasFrag) { - pgl.glAttachShader(glProgramObjectID, glFragmentShaderID); + pgl.glAttachShader(glProgram, glFragment); } - pgl.glLinkProgram(glProgramObjectID); + pgl.glLinkProgram(glProgram); int[] linked = new int[1]; - pgl.glGetProgramiv(glProgramObjectID, PGL.GL_LINK_STATUS, linked, 0); + pgl.glGetProgramiv(glProgram, PGL.GL_LINK_STATUS, linked, 0); if (linked[0] == PGL.GL_FALSE) { - PGraphics.showException("Cannot link shader program:\n" + pgl.glGetProgramInfoLog(glProgramObjectID)); + PGraphics.showException("Cannot link shader program:\n" + pgl.glGetProgramInfoLog(glProgram)); } - pgl.glValidateProgram(glProgramObjectID); + pgl.glValidateProgram(glProgram); int[] validated = new int[1]; - pgl.glGetProgramiv(glProgramObjectID, PGL.GL_VALIDATE_STATUS, validated, 0); + pgl.glGetProgramiv(glProgram, PGL.GL_VALIDATE_STATUS, validated, 0); if (validated[0] == PGL.GL_FALSE) { - PGraphics.showException("Cannot validate shader program:\n" + pgl.glGetProgramInfoLog(glProgramObjectID)); + PGraphics.showException("Cannot validate shader program:\n" + pgl.glGetProgramInfoLog(glProgram)); } } } @@ -637,13 +631,13 @@ public class PShader { protected boolean contextIsOutdated() { boolean outdated = !pgl.contextIsCurrent(context); if (outdated) { - pgMain.removeGLSLProgramObject(glProgramObjectID, context.code()); - pgMain.removeGLSLVertShaderObject(glVertexShaderID, context.code()); - pgMain.removeGLSLFragShaderObject(glFragmentShaderID, context.code()); + pgMain.removeGLSLProgramObject(glProgram, context.code()); + pgMain.removeGLSLVertShaderObject(glVertex, context.code()); + pgMain.removeGLSLFragShaderObject(glFragment, context.code()); - glProgramObjectID = 0; - glVertexShaderID = 0; - glFragmentShaderID = 0; + glProgram = 0; + glVertex = 0; + glFragment = 0; } return outdated; } @@ -707,15 +701,15 @@ public class PShader { * @param shaderSource a string containing the shader's code */ protected boolean compileVertexShader() { - glVertexShaderID = pgMain.createGLSLVertShaderObject(context.code()); + glVertex = pgMain.createGLSLVertShaderObject(context.code()); - pgl.glShaderSource(glVertexShaderID, vertexShaderSource); - pgl.glCompileShader(glVertexShaderID); + pgl.glShaderSource(glVertex, vertexShaderSource); + pgl.glCompileShader(glVertex); int[] compiled = new int[1]; - pgl.glGetShaderiv(glVertexShaderID, PGL.GL_COMPILE_STATUS, compiled, 0); + pgl.glGetShaderiv(glVertex, PGL.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == PGL.GL_FALSE) { - PGraphics.showException("Cannot compile vertex shader:\n" + pgl.glGetShaderInfoLog(glVertexShaderID)); + PGraphics.showException("Cannot compile vertex shader:\n" + pgl.glGetShaderInfoLog(glVertex)); return false; } else { return true; @@ -727,15 +721,15 @@ public class PShader { * @param shaderSource a string containing the shader's code */ protected boolean compileFragmentShader() { - glFragmentShaderID = pgMain.createGLSLFragShaderObject(context.code()); + glFragment = pgMain.createGLSLFragShaderObject(context.code()); - pgl.glShaderSource(glFragmentShaderID, fragmentShaderSource); - pgl.glCompileShader(glFragmentShaderID); + pgl.glShaderSource(glFragment, fragmentShaderSource); + pgl.glCompileShader(glFragment); int[] compiled = new int[1]; - pgl.glGetShaderiv(glFragmentShaderID, PGL.GL_COMPILE_STATUS, compiled, 0); + pgl.glGetShaderiv(glFragment, PGL.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == PGL.GL_FALSE) { - PGraphics.showException("Cannot compile fragment shader:\n" + pgl.glGetShaderInfoLog(glFragmentShaderID)); + PGraphics.showException("Cannot compile fragment shader:\n" + pgl.glGetShaderInfoLog(glFragment)); return false; } else { return true; @@ -754,17 +748,17 @@ public class PShader { protected void release() { - if (glVertexShaderID != 0) { - pgMain.deleteGLSLVertShaderObject(glVertexShaderID, context.code()); - glVertexShaderID = 0; + if (glVertex != 0) { + pgMain.deleteGLSLVertShaderObject(glVertex, context.code()); + glVertex = 0; } - if (glFragmentShaderID != 0) { - pgMain.deleteGLSLFragShaderObject(glFragmentShaderID, context.code()); - glFragmentShaderID = 0; + if (glFragment != 0) { + pgMain.deleteGLSLFragShaderObject(glFragment, context.code()); + glFragment = 0; } - if (glProgramObjectID != 0) { - pgMain.deleteGLSLProgramObject(glProgramObjectID, context.code()); - glProgramObjectID = 0; + if (glProgram != 0) { + pgMain.deleteGLSLProgramObject(glProgram, context.code()); + glProgram = 0; } } diff --git a/java/libraries/opengl/src/processing/opengl/PShapeOpenGL.java b/java/libraries/opengl/src/processing/opengl/PShapeOpenGL.java index 4a4454ea1..c20cdc067 100644 --- a/java/libraries/opengl/src/processing/opengl/PShapeOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PShapeOpenGL.java @@ -92,25 +92,25 @@ public class PShapeOpenGL extends PShape { // OpenGL buffers - public int glPolyVertexBufferID; - public int glPolyColorBufferID; - public int glPolyNormalBufferID; - public int glPolyTexcoordBufferID; - public int glPolyAmbientBufferID; - public int glPolySpecularBufferID; - public int glPolyEmissiveBufferID; - public int glPolyShininessBufferID; - public int glPolyIndexBufferID; + public int glPolyVertex; + public int glPolyColor; + public int glPolyNormal; + public int glPolyTexcoord; + public int glPolyAmbient; + public int glPolySpecular; + public int glPolyEmissive; + public int glPolyShininess; + public int glPolyIndex; - public int glLineVertexBufferID; - public int glLineColorBufferID; - public int glLineAttribBufferID; - public int glLineIndexBufferID; + public int glLineVertex; + public int glLineColor; + public int glLineAttrib; + public int glLineIndex; - public int glPointVertexBufferID; - public int glPointColorBufferID; - public int glPointAttribBufferID; - public int glPointIndexBufferID; + public int glPointVertex; + public int glPointColor; + public int glPointAttrib; + public int glPointIndex; // ........................................................ @@ -281,25 +281,25 @@ public class PShapeOpenGL extends PShape { pgl = pg.pgl; context = pgl.createEmptyContext(); - glPolyVertexBufferID = 0; - glPolyColorBufferID = 0; - glPolyNormalBufferID = 0; - glPolyTexcoordBufferID = 0; - glPolyAmbientBufferID = 0; - glPolySpecularBufferID = 0; - glPolyEmissiveBufferID = 0; - glPolyShininessBufferID = 0; - glPolyIndexBufferID = 0; + glPolyVertex = 0; + glPolyColor = 0; + glPolyNormal = 0; + glPolyTexcoord = 0; + glPolyAmbient = 0; + glPolySpecular = 0; + glPolyEmissive = 0; + glPolyShininess = 0; + glPolyIndex = 0; - glLineVertexBufferID = 0; - glLineColorBufferID = 0; - glLineAttribBufferID = 0; - glLineIndexBufferID = 0; + glLineVertex = 0; + glLineColor = 0; + glLineAttrib = 0; + glLineIndex = 0; - glPointVertexBufferID = 0; - glPointColorBufferID = 0; - glPointAttribBufferID = 0; - glPointIndexBufferID = 0; + glPointVertex = 0; + glPointColor = 0; + glPointAttrib = 0; + glPointIndex = 0; this.tessellator = PGraphicsOpenGL.tessellator; this.family = family; @@ -413,78 +413,78 @@ public class PShapeOpenGL extends PShape { protected void finalizePolyBuffers() { - if (glPolyVertexBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyVertexBufferID, context.code()); + if (glPolyVertex != 0) { + pg.finalizeVertexBufferObject(glPolyVertex, context.code()); } - if (glPolyColorBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyColorBufferID, context.code()); + if (glPolyColor != 0) { + pg.finalizeVertexBufferObject(glPolyColor, context.code()); } - if (glPolyNormalBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyNormalBufferID, context.code()); + if (glPolyNormal != 0) { + pg.finalizeVertexBufferObject(glPolyNormal, context.code()); } - if (glPolyTexcoordBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyTexcoordBufferID, context.code()); + if (glPolyTexcoord != 0) { + pg.finalizeVertexBufferObject(glPolyTexcoord, context.code()); } - if (glPolyAmbientBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyAmbientBufferID, context.code()); + if (glPolyAmbient != 0) { + pg.finalizeVertexBufferObject(glPolyAmbient, context.code()); } - if (glPolySpecularBufferID != 0) { - pg.finalizeVertexBufferObject(glPolySpecularBufferID, context.code()); + if (glPolySpecular != 0) { + pg.finalizeVertexBufferObject(glPolySpecular, context.code()); } - if (glPolyEmissiveBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyEmissiveBufferID, context.code()); + if (glPolyEmissive != 0) { + pg.finalizeVertexBufferObject(glPolyEmissive, context.code()); } - if (glPolyShininessBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyShininessBufferID, context.code()); + if (glPolyShininess != 0) { + pg.finalizeVertexBufferObject(glPolyShininess, context.code()); } - if (glPolyIndexBufferID != 0) { - pg.finalizeVertexBufferObject(glPolyIndexBufferID, context.code()); + if (glPolyIndex != 0) { + pg.finalizeVertexBufferObject(glPolyIndex, context.code()); } } protected void finalizeLineBuffers() { - if (glLineVertexBufferID != 0) { - pg.finalizeVertexBufferObject(glLineVertexBufferID, context.code()); + if (glLineVertex != 0) { + pg.finalizeVertexBufferObject(glLineVertex, context.code()); } - if (glLineColorBufferID != 0) { - pg.finalizeVertexBufferObject(glLineColorBufferID, context.code()); + if (glLineColor != 0) { + pg.finalizeVertexBufferObject(glLineColor, context.code()); } - if (glLineAttribBufferID != 0) { - pg.finalizeVertexBufferObject(glLineAttribBufferID, context.code()); + if (glLineAttrib != 0) { + pg.finalizeVertexBufferObject(glLineAttrib, context.code()); } - if (glLineIndexBufferID != 0) { - pg.finalizeVertexBufferObject(glLineIndexBufferID, context.code()); + if (glLineIndex != 0) { + pg.finalizeVertexBufferObject(glLineIndex, context.code()); } } protected void finalizePointBuffers() { - if (glPointVertexBufferID != 0) { - pg.finalizeVertexBufferObject(glPointVertexBufferID, context.code()); + if (glPointVertex != 0) { + pg.finalizeVertexBufferObject(glPointVertex, context.code()); } - if (glPointColorBufferID != 0) { - pg.finalizeVertexBufferObject(glPointColorBufferID, context.code()); + if (glPointColor != 0) { + pg.finalizeVertexBufferObject(glPointColor, context.code()); } - if (glPointAttribBufferID != 0) { - pg.finalizeVertexBufferObject(glPointAttribBufferID, context.code()); + if (glPointAttrib != 0) { + pg.finalizeVertexBufferObject(glPointAttrib, context.code()); } - if (glPointIndexBufferID != 0) { - pg.finalizeVertexBufferObject(glPointIndexBufferID, context.code()); + if (glPointIndex != 0) { + pg.finalizeVertexBufferObject(glPointIndex, context.code()); } } @@ -3114,42 +3114,42 @@ public class PShapeOpenGL extends PShape { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - glPolyVertexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID); + glPolyVertex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.polyVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - glPolyColorBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID); + glPolyColor = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyColors, 0, size), PGL.GL_STATIC_DRAW); - glPolyNormalBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID); + glPolyNormal = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 3 * sizef, FloatBuffer.wrap(tessGeo.polyNormals, 0, 3 * size), PGL.GL_STATIC_DRAW); - glPolyTexcoordBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID); + glPolyTexcoord = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.polyTexcoords, 0, 2 * size), PGL.GL_STATIC_DRAW); - glPolyAmbientBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID); + glPolyAmbient = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyAmbient, 0, size), PGL.GL_STATIC_DRAW); - glPolySpecularBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID); + glPolySpecular = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polySpecular, 0, size), PGL.GL_STATIC_DRAW); - glPolyEmissiveBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID); + glPolyEmissive = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.polyEmissive, 0, size), PGL.GL_STATIC_DRAW); - glPolyShininessBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID); + glPolyShininess = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizef, FloatBuffer.wrap(tessGeo.polyShininess, 0, size), PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glPolyIndexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndexBufferID); + glPolyIndex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPolyIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.polyIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.polyIndices, 0, tessGeo.polyIndexCount), PGL.GL_STATIC_DRAW); @@ -3162,22 +3162,22 @@ public class PShapeOpenGL extends PShape { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - glLineVertexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID); + glLineVertex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - glLineColorBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID); + glLineColor = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.lineColors, 0, size), PGL.GL_STATIC_DRAW); - glLineAttribBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID); + glLineAttrib = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.lineAttribs, 0, 4 * size), PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glLineIndexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); + glLineIndex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glLineIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.lineIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.lineIndices, 0, tessGeo.lineIndexCount), PGL.GL_STATIC_DRAW); @@ -3190,22 +3190,22 @@ public class PShapeOpenGL extends PShape { int sizef = size * PGL.SIZEOF_FLOAT; int sizei = size * PGL.SIZEOF_INT; - glPointVertexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID); + glPointVertex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 4 * sizef, FloatBuffer.wrap(tessGeo.pointVertices, 0, 4 * size), PGL.GL_STATIC_DRAW); - glPointColorBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID); + glPointColor = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, sizei, IntBuffer.wrap(tessGeo.pointColors, 0, size), PGL.GL_STATIC_DRAW); - glPointAttribBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID); + glPointAttrib = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib); pgl.glBufferData(PGL.GL_ARRAY_BUFFER, 2 * sizef, FloatBuffer.wrap(tessGeo.pointAttribs, 0, 2 * size), PGL.GL_STATIC_DRAW); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); - glPointIndexBufferID = pg.createVertexBufferObject(context.code()); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); + glPointIndex = pg.createVertexBufferObject(context.code()); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, glPointIndex); pgl.glBufferData(PGL.GL_ELEMENT_ARRAY_BUFFER, tessGeo.pointIndexCount * PGL.SIZEOF_INDEX, ShortBuffer.wrap(tessGeo.pointIndices, 0, tessGeo.pointIndexCount), PGL.GL_STATIC_DRAW); @@ -3220,49 +3220,49 @@ public class PShapeOpenGL extends PShape { // doesn't get deleted by OpenGL. The VBOs were already // automatically disposed when the old context was // destroyed. - pg.removeVertexBufferObject(glPolyVertexBufferID, context.code()); - pg.removeVertexBufferObject(glPolyColorBufferID, context.code()); - pg.removeVertexBufferObject(glPolyNormalBufferID, context.code()); - pg.removeVertexBufferObject(glPolyTexcoordBufferID, context.code()); - pg.removeVertexBufferObject(glPolyAmbientBufferID, context.code()); - pg.removeVertexBufferObject(glPolySpecularBufferID, context.code()); - pg.removeVertexBufferObject(glPolyEmissiveBufferID, context.code()); - pg.removeVertexBufferObject(glPolyShininessBufferID, context.code()); - pg.removeVertexBufferObject(glPolyIndexBufferID, context.code()); + pg.removeVertexBufferObject(glPolyVertex, context.code()); + pg.removeVertexBufferObject(glPolyColor, context.code()); + pg.removeVertexBufferObject(glPolyNormal, context.code()); + pg.removeVertexBufferObject(glPolyTexcoord, context.code()); + pg.removeVertexBufferObject(glPolyAmbient, context.code()); + pg.removeVertexBufferObject(glPolySpecular, context.code()); + pg.removeVertexBufferObject(glPolyEmissive, context.code()); + pg.removeVertexBufferObject(glPolyShininess, context.code()); + pg.removeVertexBufferObject(glPolyIndex, context.code()); - pg.removeVertexBufferObject(glLineVertexBufferID, context.code()); - pg.removeVertexBufferObject(glLineColorBufferID, context.code()); - pg.removeVertexBufferObject(glLineAttribBufferID, context.code()); - pg.removeVertexBufferObject(glLineIndexBufferID, context.code()); + pg.removeVertexBufferObject(glLineVertex, context.code()); + pg.removeVertexBufferObject(glLineColor, context.code()); + pg.removeVertexBufferObject(glLineAttrib, context.code()); + pg.removeVertexBufferObject(glLineIndex, context.code()); - pg.removeVertexBufferObject(glPointVertexBufferID, context.code()); - pg.removeVertexBufferObject(glPointColorBufferID, context.code()); - pg.removeVertexBufferObject(glPointAttribBufferID, context.code()); - pg.removeVertexBufferObject(glPointIndexBufferID, context.code()); + pg.removeVertexBufferObject(glPointVertex, context.code()); + pg.removeVertexBufferObject(glPointColor, context.code()); + pg.removeVertexBufferObject(glPointAttrib, context.code()); + pg.removeVertexBufferObject(glPointIndex, context.code()); // The OpenGL resources have been already deleted // when the context changed. We only need to zero // them to avoid deleting them again when the GC // runs the finalizers of the disposed object. - glPolyVertexBufferID = 0; - glPolyColorBufferID = 0; - glPolyNormalBufferID = 0; - glPolyTexcoordBufferID = 0; - glPolyAmbientBufferID = 0; - glPolySpecularBufferID = 0; - glPolyEmissiveBufferID = 0; - glPolyShininessBufferID = 0; - glPolyIndexBufferID = 0; + glPolyVertex = 0; + glPolyColor = 0; + glPolyNormal = 0; + glPolyTexcoord = 0; + glPolyAmbient = 0; + glPolySpecular = 0; + glPolyEmissive = 0; + glPolyShininess = 0; + glPolyIndex = 0; - glLineVertexBufferID = 0; - glLineColorBufferID = 0; - glLineAttribBufferID = 0; - glLineIndexBufferID = 0; + glLineVertex = 0; + glLineColor = 0; + glLineAttrib = 0; + glLineIndex = 0; - glPointVertexBufferID = 0; - glPointColorBufferID = 0; - glPointAttribBufferID = 0; - glPointIndexBufferID = 0; + glPointVertex = 0; + glPointColor = 0; + glPointAttrib = 0; + glPointIndex = 0; } return outdated; } @@ -3283,95 +3283,95 @@ public class PShapeOpenGL extends PShape { protected void deletePolyBuffers() { - if (glPolyVertexBufferID != 0) { - pg.deleteVertexBufferObject(glPolyVertexBufferID, context.code()); - glPolyVertexBufferID = 0; + if (glPolyVertex != 0) { + pg.deleteVertexBufferObject(glPolyVertex, context.code()); + glPolyVertex = 0; } - if (glPolyColorBufferID != 0) { - pg.deleteVertexBufferObject(glPolyColorBufferID, context.code()); - glPolyColorBufferID = 0; + if (glPolyColor != 0) { + pg.deleteVertexBufferObject(glPolyColor, context.code()); + glPolyColor = 0; } - if (glPolyNormalBufferID != 0) { - pg.deleteVertexBufferObject(glPolyNormalBufferID, context.code()); - glPolyNormalBufferID = 0; + if (glPolyNormal != 0) { + pg.deleteVertexBufferObject(glPolyNormal, context.code()); + glPolyNormal = 0; } - if (glPolyTexcoordBufferID != 0) { - pg.deleteVertexBufferObject(glPolyTexcoordBufferID, context.code()); - glPolyTexcoordBufferID = 0; + if (glPolyTexcoord != 0) { + pg.deleteVertexBufferObject(glPolyTexcoord, context.code()); + glPolyTexcoord = 0; } - if (glPolyAmbientBufferID != 0) { - pg.deleteVertexBufferObject(glPolyAmbientBufferID, context.code()); - glPolyAmbientBufferID = 0; + if (glPolyAmbient != 0) { + pg.deleteVertexBufferObject(glPolyAmbient, context.code()); + glPolyAmbient = 0; } - if (glPolySpecularBufferID != 0) { - pg.deleteVertexBufferObject(glPolySpecularBufferID, context.code()); - glPolySpecularBufferID = 0; + if (glPolySpecular != 0) { + pg.deleteVertexBufferObject(glPolySpecular, context.code()); + glPolySpecular = 0; } - if (glPolyEmissiveBufferID != 0) { - pg.deleteVertexBufferObject(glPolyEmissiveBufferID, context.code()); - glPolyEmissiveBufferID = 0; + if (glPolyEmissive != 0) { + pg.deleteVertexBufferObject(glPolyEmissive, context.code()); + glPolyEmissive = 0; } - if (glPolyShininessBufferID != 0) { - pg.deleteVertexBufferObject(glPolyShininessBufferID, context.code()); - glPolyShininessBufferID = 0; + if (glPolyShininess != 0) { + pg.deleteVertexBufferObject(glPolyShininess, context.code()); + glPolyShininess = 0; } - if (glPolyIndexBufferID != 0) { - pg.deleteVertexBufferObject(glPolyIndexBufferID, context.code()); - glPolyIndexBufferID = 0; + if (glPolyIndex != 0) { + pg.deleteVertexBufferObject(glPolyIndex, context.code()); + glPolyIndex = 0; } } protected void deleteLineBuffers() { - if (glLineVertexBufferID != 0) { - pg.deleteVertexBufferObject(glLineVertexBufferID, context.code()); - glLineVertexBufferID = 0; + if (glLineVertex != 0) { + pg.deleteVertexBufferObject(glLineVertex, context.code()); + glLineVertex = 0; } - if (glLineColorBufferID != 0) { - pg.deleteVertexBufferObject(glLineColorBufferID, context.code()); - glLineColorBufferID = 0; + if (glLineColor != 0) { + pg.deleteVertexBufferObject(glLineColor, context.code()); + glLineColor = 0; } - if (glLineAttribBufferID != 0) { - pg.deleteVertexBufferObject(glLineAttribBufferID, context.code()); - glLineAttribBufferID = 0; + if (glLineAttrib != 0) { + pg.deleteVertexBufferObject(glLineAttrib, context.code()); + glLineAttrib = 0; } - if (glLineIndexBufferID != 0) { - pg.deleteVertexBufferObject(glLineIndexBufferID, context.code()); - glLineIndexBufferID = 0; + if (glLineIndex != 0) { + pg.deleteVertexBufferObject(glLineIndex, context.code()); + glLineIndex = 0; } } protected void deletePointBuffers() { - if (glPointVertexBufferID != 0) { - pg.deleteVertexBufferObject(glPointVertexBufferID, context.code()); - glPointVertexBufferID = 0; + if (glPointVertex != 0) { + pg.deleteVertexBufferObject(glPointVertex, context.code()); + glPointVertex = 0; } - if (glPointColorBufferID != 0) { - pg.deleteVertexBufferObject(glPointColorBufferID, context.code()); - glPointColorBufferID = 0; + if (glPointColor != 0) { + pg.deleteVertexBufferObject(glPointColor, context.code()); + glPointColor = 0; } - if (glPointAttribBufferID != 0) { - pg.deleteVertexBufferObject(glPointAttribBufferID, context.code()); - glPointAttribBufferID = 0; + if (glPointAttrib != 0) { + pg.deleteVertexBufferObject(glPointAttrib, context.code()); + glPointAttrib = 0; } - if (glPointIndexBufferID != 0) { - pg.deleteVertexBufferObject(glPointIndexBufferID, context.code()); - glPointIndexBufferID = 0; + if (glPointIndex != 0) { + pg.deleteVertexBufferObject(glPointIndex, context.code()); + glPointIndex = 0; } } @@ -3512,7 +3512,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyVertices(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyVertex); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.polyVertices, 4 * offset, 4 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3520,7 +3520,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyColors(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyColor); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.polyColors, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3528,7 +3528,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyNormals(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormalBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyNormal); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 3 * offset * PGL.SIZEOF_FLOAT, 3 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.polyNormals, 3 * offset, 3 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3536,7 +3536,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyTexcoords(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoordBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyTexcoord); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.polyTexcoords, 2 * offset, 2 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3544,7 +3544,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyAmbient(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbientBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyAmbient); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.polyAmbient, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3552,7 +3552,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolySpecular(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecularBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolySpecular); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.polySpecular, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3560,7 +3560,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyEmissive(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissiveBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyEmissive); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.polyEmissive, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3568,7 +3568,7 @@ public class PShapeOpenGL extends PShape { protected void copyPolyShininess(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininessBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPolyShininess); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_FLOAT, size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.polyShininess, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3576,7 +3576,7 @@ public class PShapeOpenGL extends PShape { protected void copyLineVertices(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineVertex); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineVertices, 4 * offset, 4 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3584,7 +3584,7 @@ public class PShapeOpenGL extends PShape { protected void copyLineColors(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineColor); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.lineColors, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3592,7 +3592,7 @@ public class PShapeOpenGL extends PShape { protected void copyLineAttributes(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttribBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glLineAttrib); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineAttribs, 4 * offset, 4 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3600,7 +3600,7 @@ public class PShapeOpenGL extends PShape { protected void copyPointVertices(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertexBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointVertex); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointVertices, 4 * offset, 4 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3608,7 +3608,7 @@ public class PShapeOpenGL extends PShape { protected void copyPointColors(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColorBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointColor); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.pointColors, offset, size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3616,7 +3616,7 @@ public class PShapeOpenGL extends PShape { protected void copyPointAttributes(int offset, int size) { - pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttribBufferID); + pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, glPointAttrib); pgl.glBufferSubData(PGL.GL_ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointAttribs, 2 * offset, 2 * size)); pgl.glBindBuffer(PGL.GL_ARRAY_BUFFER, 0); @@ -3908,7 +3908,7 @@ public class PShapeOpenGL extends PShape { tex = g.getTexture(textureImage); if (tex != null) { pgl.enableTexturing(tex.glTarget); - pgl.glBindTexture(tex.glTarget, tex.glID); + pgl.glBindTexture(tex.glTarget, tex.glName); } } @@ -3951,23 +3951,23 @@ public class PShapeOpenGL extends PShape { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(root.glPolyVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(root.glPolyColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setVertexAttribute(root.glPolyVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(root.glPolyColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); if (g.lights) { - shader.setNormalAttribute(root.glPolyNormalBufferID, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT); - shader.setAmbientAttribute(root.glPolyAmbientBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setSpecularAttribute(root.glPolySpecularBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setEmissiveAttribute(root.glPolyEmissiveBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setShininessAttribute(root.glPolyShininessBufferID, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); + shader.setNormalAttribute(root.glPolyNormal, 3, PGL.GL_FLOAT, 0, 3 * voffset * PGL.SIZEOF_FLOAT); + shader.setAmbientAttribute(root.glPolyAmbient, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setSpecularAttribute(root.glPolySpecular, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setEmissiveAttribute(root.glPolyEmissive, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setShininessAttribute(root.glPolyShininess, 1, PGL.GL_FLOAT, 0, voffset * PGL.SIZEOF_FLOAT); } if (tex != null) { - shader.setTexcoordAttribute(root.glPolyTexcoordBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); + shader.setTexcoordAttribute(root.glPolyTexcoord, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); shader.setTexture(tex); } - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPolyIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPolyIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -4082,11 +4082,11 @@ public class PShapeOpenGL extends PShape { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(root.glLineVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(root.glLineColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setLineAttribute(root.glLineAttribBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setVertexAttribute(root.glLineVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(root.glLineColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setLineAttribute(root.glLineAttrib, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glLineIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glLineIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -4176,11 +4176,11 @@ public class PShapeOpenGL extends PShape { int icount = cache.indexCount[n]; int voffset = cache.vertexOffset[n]; - shader.setVertexAttribute(root.glPointVertexBufferID, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); - shader.setColorAttribute(root.glPointColorBufferID, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); - shader.setPointAttribute(root.glPointAttribBufferID, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); + shader.setVertexAttribute(root.glPointVertex, 4, PGL.GL_FLOAT, 0, 4 * voffset * PGL.SIZEOF_FLOAT); + shader.setColorAttribute(root.glPointColor, 4, PGL.GL_UNSIGNED_BYTE, 0, 4 * voffset * PGL.SIZEOF_BYTE); + shader.setPointAttribute(root.glPointAttrib, 2, PGL.GL_FLOAT, 0, 2 * voffset * PGL.SIZEOF_FLOAT); - pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPointIndexBufferID); + pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, root.glPointIndex); pgl.glDrawElements(PGL.GL_TRIANGLES, icount, PGL.INDEX_TYPE, ioffset * PGL.SIZEOF_INDEX); pgl.glBindBuffer(PGL.GL_ELEMENT_ARRAY_BUFFER, 0); } diff --git a/java/libraries/opengl/src/processing/opengl/Texture.java b/java/libraries/opengl/src/processing/opengl/Texture.java index 1e532d2ca..b4751c1a6 100644 --- a/java/libraries/opengl/src/processing/opengl/Texture.java +++ b/java/libraries/opengl/src/processing/opengl/Texture.java @@ -71,8 +71,7 @@ public class Texture implements PConstants { public int width, height; - // These are public but use at your own risk! - public int glID; + public int glName; public int glTarget; public int glFormat; public int glMinFilter; @@ -137,7 +136,7 @@ public class Texture implements PConstants { pgl = pg.pgl; context = pgl.createEmptyContext(); - glID = 0; + glName = 0; init(width, height, (Parameters)params); } @@ -145,8 +144,8 @@ public class Texture implements PConstants { protected void finalize() throws Throwable { try { - if (glID != 0) { - pg.finalizeTextureObject(glID, context.code()); + if (glName != 0) { + pg.finalizeTextureObject(glName, context.code()); } } finally { super.finalize(); @@ -168,7 +167,7 @@ public class Texture implements PConstants { */ public void init(int width, int height) { Parameters params; - if (0 < glID) { + if (0 < glName) { // Re-initializing a pre-existing texture. // We use the current parameters as default: params = getParameters(); @@ -220,7 +219,7 @@ public class Texture implements PConstants { * @return boolean */ public boolean available() { - return 0 < glID; + return 0 < glName; } @@ -278,7 +277,7 @@ public class Texture implements PConstants { } pgl.enableTexturing(glTarget); - pgl.glBindTexture(glTarget, glID); + pgl.glBindTexture(glTarget, glName); if (usingMipmaps) { if (PGraphicsOpenGL.autoMipmapGenSupported) { @@ -508,7 +507,7 @@ public class Texture implements PConstants { public void bind() { pgl.enableTexturing(glTarget); - pgl.glBindTexture(glTarget, glID); + pgl.glBindTexture(glTarget, glName); } @@ -972,9 +971,9 @@ public class Texture implements PConstants { pgl.enableTexturing(glTarget); context = pgl.getCurrentContext(); - glID = pg.createTextureObject(context.code()); + glName = pg.createTextureObject(context.code()); - pgl.glBindTexture(glTarget, glID); + pgl.glBindTexture(glTarget, glName); pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MIN_FILTER, glMinFilter); pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_MAG_FILTER, glMagFilter); pgl.glTexParameterf(glTarget, PGL.GL_TEXTURE_WRAP_S, glWrapS); @@ -996,9 +995,9 @@ public class Texture implements PConstants { * Marks the texture object for deletion. */ protected void release() { - if (glID != 0) { - pg.finalizeTextureObject(glID, context.code()); - glID = 0; + if (glName != 0) { + pg.finalizeTextureObject(glName, context.code()); + glName = 0; } } @@ -1009,11 +1008,11 @@ public class Texture implements PConstants { // Removing the texture object from the renderer's list so it // doesn't get deleted by OpenGL. The texture object was // automatically disposed when the old context was destroyed. - pg.removeTextureObject(glID, context.code()); + pg.removeTextureObject(glName, context.code()); // And then set the id to zero, so it doesn't try to be // deleted when the object's finalizer is invoked by the GC. - glID = 0; + glName = 0; } return outdated; } @@ -1044,14 +1043,14 @@ public class Texture implements PConstants { if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region. - pgl.drawTexture(tex.glTarget, tex.glID, tex.glWidth, tex.glHeight, + pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight, x, y, w, h, 0, 0, width, height); } else { // Rendering tex into "this" but without scaling so the contents // of the source texture fall in the corresponding texels of the // destination. - pgl.drawTexture(tex.glTarget, tex.glID, tex.glWidth, tex.glHeight, + pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight, x, y, w, h, x, y, w, h); } pg.popFramebuffer(); @@ -1092,7 +1091,7 @@ public class Texture implements PConstants { parent = src.parent; pg = src.pg; - glID = src.glID; + glName = src.glName; glTarget = src.glTarget; glFormat = src.glFormat; glMinFilter = src.glMinFilter;