From a23acca86314b04b8e96e6573cf1c3019a537900 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 17 Jan 2012 03:26:32 +0000 Subject: [PATCH] Added PGL layer --- .../src/processing/opengl/PFramebuffer.java | 192 ++- .../opengl/src/processing/opengl/PGLJava.java | 1032 ++++++++++++ .../processing/opengl/PGraphicsOpenGL.java | 1424 ++++++++++------- .../opengl/src/processing/opengl/PShader.java | 167 +- .../src/processing/opengl/PShape3D.java | 651 +++++--- .../src/processing/opengl/PTexture.java | 124 +- 6 files changed, 2598 insertions(+), 992 deletions(-) create mode 100644 java/libraries/opengl/src/processing/opengl/PGLJava.java diff --git a/java/libraries/opengl/src/processing/opengl/PFramebuffer.java b/java/libraries/opengl/src/processing/opengl/PFramebuffer.java index 192251e7a..054c651e0 100644 --- a/java/libraries/opengl/src/processing/opengl/PFramebuffer.java +++ b/java/libraries/opengl/src/processing/opengl/PFramebuffer.java @@ -23,9 +23,6 @@ package processing.opengl; import java.nio.IntBuffer; -import javax.media.opengl.GL; -import javax.media.opengl.GL2; -import javax.media.opengl.GL2GL3; import processing.core.PApplet; import processing.core.PConstants; @@ -42,6 +39,7 @@ import processing.core.PConstants; public class PFramebuffer implements PConstants { protected PApplet parent; protected PGraphicsOpenGL ogl; + protected PGLJava pgl; public int glFboID; public int glDepthBufferID; @@ -59,7 +57,7 @@ public class PFramebuffer implements PConstants { protected int nsamples; protected int numColorBuffers; - protected int[] colorBufferAttchPoints; + //protected int[] colorBufferAttchPoints; protected PTexture[] colorBufferTex; protected boolean screenFb; @@ -82,6 +80,7 @@ public class PFramebuffer implements PConstants { boolean screen) { this.parent = parent; ogl = (PGraphicsOpenGL)parent.g; + pgl = ogl.pgl; //gl.registerPGLObject(this); glFboID = 0; @@ -111,10 +110,10 @@ public class PFramebuffer implements PConstants { } numColorBuffers = colorBuffers; - colorBufferAttchPoints = new int[numColorBuffers]; + //colorBufferAttchPoints = new int[numColorBuffers]; colorBufferTex = new PTexture[numColorBuffers]; for (int i = 0; i < numColorBuffers; i++) { - colorBufferAttchPoints[i] = GL.GL_COLOR_ATTACHMENT0 + i; + //colorBufferAttchPoints[i] = GL.GL_COLOR_ATTACHMENT0 + i; colorBufferTex[i] = null; } @@ -178,25 +177,32 @@ public class PFramebuffer implements PConstants { public void clear() { ogl.pushFramebuffer(); ogl.setFramebuffer(this); - getGl().glClearColor(0f, 0f, 0f, 0.0f); - getGl().glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); +// getGl().glClearColor(0f, 0f, 0f, 0.0f); +// getGl().glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); + pgl.setClearColor(0, 0, 0, 0); + pgl.clearAllBuffers(); ogl.popFramebuffer(); } public void copy(PFramebuffer dest) { - getGl().glBindFramebuffer(GL2.GL_READ_FRAMEBUFFER, this.glFboID); - getGl().glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, dest.glFboID); - getGl2().glBlitFramebuffer(0, 0, this.width, this.height, 0, 0, dest.width, dest.height, - GL.GL_COLOR_BUFFER_BIT, GL.GL_NEAREST); +// getGl().glBindFramebuffer(GL2.GL_READ_FRAMEBUFFER, this.glFboID); +// getGl().glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, dest.glFboID); + pgl.bindReadFramebuffer(this.glFboID); + pgl.bindWriteFramebuffer(dest.glFboID); + +// getGl2().glBlitFramebuffer(0, 0, this.width, this.height, 0, 0, dest.width, dest.height, GL.GL_COLOR_BUFFER_BIT, GL.GL_NEAREST); + pgl.copyFramebuffer(this.width, this.height, dest.width, dest.height); } public void bind() { if (screenFb) { if (PGraphicsOpenGL.fboSupported) { - getGl().glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); +// getGl().glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); + pgl.bindFramebuffer(0); } } else if (fboMode) { - getGl().glBindFramebuffer(GL.GL_FRAMEBUFFER, glFboID); +// getGl().glBindFramebuffer(GL.GL_FRAMEBUFFER, glFboID); + pgl.bindFramebuffer(glFboID); } else { backupScreen(); @@ -207,7 +213,8 @@ public class PFramebuffer implements PConstants { } if (noDepth) { - getGl().glDisable(GL.GL_DEPTH_TEST); +// getGl().glDisable(GL.GL_DEPTH_TEST); + pgl.disableDepthTest(); } } } @@ -220,9 +227,11 @@ public class PFramebuffer implements PConstants { if (noDepth) { // No need to clear depth buffer because depth testing was disabled. if (ogl.hintEnabled(DISABLE_DEPTH_TEST)) { - getGl().glDisable(GL.GL_DEPTH_TEST); +// getGl().glDisable(GL.GL_DEPTH_TEST); + pgl.disableDepthTest(); } else { - getGl().glEnable(GL.GL_DEPTH_TEST); +// getGl().glEnable(GL.GL_DEPTH_TEST); + pgl.enableDepthTest(); } } @@ -237,8 +246,10 @@ public class PFramebuffer implements PConstants { // after this offscreen render. // A consequence of this behavior is that all the offscreen rendering when // no FBOs are available should be done before any onscreen drawing. - getGl().glClearColor(0, 0, 0, 0); - getGl().glClear(GL.GL_DEPTH_BUFFER_BIT); + pgl.setClearColor(0, 0, 0, 0); + pgl.clearDepthBuffer(); +// getGl().glClearColor(0, 0, 0, 0); +// getGl().glClear(GL.GL_DEPTH_BUFFER_BIT); } } } @@ -247,7 +258,9 @@ public class PFramebuffer implements PConstants { public void backupScreen() { if (pixelBuffer == null) createPixelBuffer(); pixelBuffer.rewind(); - getGl().glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelBuffer); + //getGl().glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelBuffer); + pgl.readPixels(pixelBuffer, 0, 0, width, height); + copyToTexture(pixelBuffer, backupTexture.glID, backupTexture.glTarget); } @@ -260,7 +273,8 @@ public class PFramebuffer implements PConstants { public void copyToColorBuffers() { if (pixelBuffer == null) createPixelBuffer(); pixelBuffer.rewind(); - getGl().glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelBuffer); + //getGl().glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelBuffer); + pgl.readPixels(pixelBuffer, 0, 0, width, height); for (int i = 0; i < numColorBuffers; i++) { copyToTexture(pixelBuffer, colorBufferTex[i].glID, colorBufferTex[i].glTarget); } @@ -269,7 +283,8 @@ public class PFramebuffer implements PConstants { public void readPixels() { if (pixelBuffer == null) createPixelBuffer(); pixelBuffer.rewind(); - getGl().glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelBuffer); +// getGl().glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelBuffer); + pgl.readPixels(pixelBuffer, 0, 0, width, height); } public void getPixels(int[] pixels) { @@ -323,13 +338,13 @@ public class PFramebuffer implements PConstants { // Making sure nothing is attached. for (int i = 0; i < numColorBuffers; i++) { - getGl().glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0 + i, - GL.GL_TEXTURE_2D, 0, 0); +// getGl().glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0 + i, GL.GL_TEXTURE_2D, 0, 0); + pgl.cleanFramebufferTexture(i); } for (int i = 0; i < numColorBuffers; i++) { - getGl().glFramebufferTexture2D(GL.GL_FRAMEBUFFER, colorBufferAttchPoints[i], - colorBufferTex[i].glTarget, colorBufferTex[i].glID, 0); + pgl.setFramebufferTexture(i, colorBufferTex[i].glTarget, colorBufferTex[i].glID); +// getGl().glFramebufferTexture2D(GL.GL_FRAMEBUFFER, colorBufferAttchPoints[i], colorBufferTex[i].glTarget, colorBufferTex[i].glID, 0); } validateFbo(); @@ -403,15 +418,16 @@ public class PFramebuffer implements PConstants { if (fboMode) { ogl.pushFramebuffer(); - ogl.setFramebuffer(this); - - //glColorBufferMultisampleID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER); + ogl.setFramebuffer(this); + glColorBufferMultisampleID = ogl.createRenderBufferObject(); - getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glColorBufferMultisampleID); - getGl2().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, nsamples, - GL.GL_RGBA8, width, height); - getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, - GL.GL_RENDERBUFFER, glColorBufferMultisampleID); + pgl.bindRenderbuffer(glColorBufferMultisampleID); + pgl.setRenderbufferNumSamples(nsamples, width, height); + pgl.setRenderbufferColorAttachment(glColorBufferMultisampleID); + +// getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glColorBufferMultisampleID); +// getGl2().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, nsamples, GL.GL_RGBA8, width, height); +// getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_RENDERBUFFER, glColorBufferMultisampleID); ogl.popFramebuffer(); } @@ -429,20 +445,22 @@ public class PFramebuffer implements PConstants { ogl.pushFramebuffer(); ogl.setFramebuffer(this); - //glDepthStencilBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER); glDepthStencilBufferID = ogl.createRenderBufferObject(); - getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glDepthStencilBufferID); + pgl.bindRenderbuffer(glDepthStencilBufferID); + //getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glDepthStencilBufferID); if (multisample) { - getGl2().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, nsamples, GL.GL_DEPTH24_STENCIL8, width, height); +// getGl2().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, nsamples, GL.GL_DEPTH24_STENCIL8, width, height); + pgl.setRenderbufferNumSamples(nsamples, width, height); } else { - getGl().glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH24_STENCIL8, width, height); + pgl.setRenderbufferStorage(PGLJava.DEPTH_24BIT_STENCIL_8BIT, width, height); +// getGl().glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH24_STENCIL8, width, height); } - getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, - GL.GL_RENDERBUFFER, glDepthStencilBufferID); - getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, - GL.GL_RENDERBUFFER, glDepthStencilBufferID); + pgl.setRenderbufferDepthAttachment(glDepthStencilBufferID); + pgl.setRenderbufferStencilAttachment(glDepthStencilBufferID); +// getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, glDepthStencilBufferID); +// getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, glDepthStencilBufferID); ogl.popFramebuffer(); } @@ -460,27 +478,29 @@ public class PFramebuffer implements PConstants { ogl.pushFramebuffer(); ogl.setFramebuffer(this); - //glDepthBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER); glDepthBufferID = ogl.createRenderBufferObject(); - getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glDepthBufferID); + //getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glDepthBufferID); + pgl.bindRenderbuffer(glDepthBufferID); - int glConst = GL.GL_DEPTH_COMPONENT16; + int glConst = PGLJava.DEPTH_16BIT; if (depthBits == 16) { - glConst = GL.GL_DEPTH_COMPONENT16; + glConst = PGLJava.DEPTH_16BIT; } else if (depthBits == 24) { - glConst = GL.GL_DEPTH_COMPONENT24; + glConst = PGLJava.DEPTH_24BIT; } else if (depthBits == 32) { - glConst = GL.GL_DEPTH_COMPONENT32; + glConst = PGLJava.DEPTH_32BIT; } if (multisample) { - getGl2().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, nsamples, glConst, width, height); + //getGl2().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, nsamples, glConst, width, height); + pgl.setRenderbufferNumSamples(nsamples, width, height); } else { - getGl().glRenderbufferStorage(GL.GL_RENDERBUFFER, glConst, width, height); + //getGl().glRenderbufferStorage(GL.GL_RENDERBUFFER, glConst, width, height); + pgl.setRenderbufferStorage(glConst, width, height); } - getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, - GL.GL_RENDERBUFFER, glDepthBufferID); + pgl.setRenderbufferDepthAttachment(glDepthBufferID); + //getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, glDepthBufferID); ogl.popFramebuffer(); } @@ -498,25 +518,28 @@ public class PFramebuffer implements PConstants { ogl.pushFramebuffer(); ogl.setFramebuffer(this); - //glStencilBufferID = ogl.createGLResource(PGraphicsOpenGL.GL_RENDER_BUFFER); glStencilBufferID = ogl.createRenderBufferObject(); - getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glStencilBufferID); +// getGl().glBindRenderbuffer(GL.GL_RENDERBUFFER, glStencilBufferID); + pgl.bindRenderbuffer(glStencilBufferID); - int glConst = GL.GL_STENCIL_INDEX1; + int glConst = PGLJava.STENCIL_1BIT; if (stencilBits == 1) { - glConst = GL.GL_STENCIL_INDEX1; + glConst = PGLJava.STENCIL_1BIT; } else if (stencilBits == 4) { - glConst = GL.GL_STENCIL_INDEX4; + glConst = PGLJava.STENCIL_4BIT; } else if (stencilBits == 8) { - glConst = GL.GL_STENCIL_INDEX8; + glConst = PGLJava.STENCIL_8BIT; } if (multisample) { - getGl2().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, nsamples, glConst, width, height); +// getGl2().glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, nsamples, glConst, width, height); + pgl.setRenderbufferNumSamples(nsamples, width, height); } else { - getGl().glRenderbufferStorage(GL.GL_RENDERBUFFER, glConst, width, height); +// getGl().glRenderbufferStorage(GL.GL_RENDERBUFFER, glConst, width, height); + pgl.setRenderbufferStorage(glConst, width, height); } - getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, - GL.GL_RENDERBUFFER, glStencilBufferID); + + pgl.setRenderbufferStencilAttachment(glStencilBufferID); +// getGl().glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, glStencilBufferID); ogl.popFramebuffer(); } @@ -534,37 +557,44 @@ public class PFramebuffer implements PConstants { // Internal copy to texture method. protected void copyToTexture(IntBuffer buffer, int glid, int gltarget) { - getGl().glEnable(gltarget); - getGl().glBindTexture(gltarget, glid); - getGl().glTexSubImage2D(gltarget, 0, 0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer); - getGl().glBindTexture(gltarget, 0); - getGl().glDisable(gltarget); + pgl.enableTexturing(gltarget); + pgl.bindTexture(gltarget, glid); + pgl.copyTexSubImage(buffer, gltarget, 0, 0, width, height); + pgl.unbindTexture(gltarget); + pgl.disableTexturing(gltarget); + +// getGl().glEnable(gltarget); +// getGl().glBindTexture(gltarget, glid); +// getGl().glTexSubImage2D(gltarget, 0, 0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer); +// getGl().glBindTexture(gltarget, 0); +// getGl().glDisable(gltarget); } public boolean validateFbo() { - int status = getGl().glCheckFramebufferStatus(GL.GL_FRAMEBUFFER); - if (status == GL.GL_FRAMEBUFFER_COMPLETE) { +// int status = getGl().glCheckFramebufferStatus(GL.GL_FRAMEBUFFER); + int status = pgl.getFramebufferStatus(); + if (status == PGLJava.FRAMEBUFFER_COMPLETE) { return true; - } else if (status == GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) { + } else if (status == PGLJava.FRAMEBUFFER_INCOMPLETE_ATTACHMENT) { throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT (" + Integer.toHexString(status) + ")"); - } else if (status == GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) { + } else if (status == PGLJava.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) { throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT (" + Integer.toHexString(status) + ")"); - } else if (status == GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS) { + } else if (status == PGLJava.FRAMEBUFFER_INCOMPLETE_DIMENSIONS) { throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS (" + Integer.toHexString(status) + ")"); - } else if (status == GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS) { + } else if (status == PGLJava.FRAMEBUFFER_INCOMPLETE_FORMATS) { throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_INCOMPLETE_FORMATS (" + Integer.toHexString(status) + ")"); - } else if (status == GL.GL_FRAMEBUFFER_UNSUPPORTED) { + } else if (status == PGLJava.FRAMEBUFFER_UNSUPPORTED) { throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_UNSUPPORTED" + Integer.toHexString(status)); } else { throw new RuntimeException("PFramebuffer: unknown framebuffer error (" + Integer.toHexString(status) + ")"); } } - protected GL getGl() { - return ogl.gl; - } - - protected GL2GL3 getGl2() { - return ogl.gl2x; - } +// protected GL getGl() { +// return ogl.gl; +// } +// +// protected GL2GL3 getGl2() { +// return ogl.gl2x; +// } } diff --git a/java/libraries/opengl/src/processing/opengl/PGLJava.java b/java/libraries/opengl/src/processing/opengl/PGLJava.java new file mode 100644 index 000000000..9efe9ab4f --- /dev/null +++ b/java/libraries/opengl/src/processing/opengl/PGLJava.java @@ -0,0 +1,1032 @@ +package processing.opengl; + +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GL2GL3; +import javax.media.opengl.GL3; +import javax.media.opengl.GL4; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLException; +import javax.media.opengl.glu.GLU; + +import processing.core.PApplet; + +/** + * How the P3D renderer handles the different OpenGL profiles? Basically, + * P3D has two pipeline modes: fixed or programmable. In the fixed mode, + * only the gl and gl2f objects are available. The gl2f object contains the + * intersection between OpenGL 2.x desktop and OpenGL 1.1 embedded, and in this + * way it ensures the functionality parity between the P3D render (PC/MAC) + * and A3D (Android) in the fixed pipeline mode. + * In the programmable mode, there further options: GL2, GL3 and GL4. + * GL2 corresponds to the basic programmable profile that results from the common + * functionality between OpenGL 3.0 desktop and OpenGL 2.0 embedded. As said just + * before, since P3D and A3D aim at feature parity as much as possible, this is + * the only programmable-pipeline GL object that the P3D renderer uses. + * The gl3 and gl4 objects will be available when the pipeline mode is PROG_GL3 or + * PROG_GL4, respectively. Although P3D doens't make any use of these objects, + * they are part of the API nonetheless for users (or libraries) requiring advanced + * functionality introduced with OpenGL 3 or OpenGL 4. + * By default, P3D tries to auto-select the pipeline mode by with the following + * priority order: PROG_GL4, PROG_GL3, PROG_GL2, FIXED. In all the programmable modes, + * the gl2p object is always available. This auto-selection can be optionally + * overridden when creating the renderer object, so that a specific mode is set. + * Note that the programmable mode uses the non-backward compatible GL objects + * (GL3, GL4, and not GL3bc, GL4bc) so no fixed mode calls are possible under this mode. + */ +public class PGLJava { + /** Size of an int (in bytes). */ + static final int SIZEOF_INT = Integer.SIZE / 8; + + /** Size of a float (in bytes). */ + static final int SIZEOF_FLOAT = Float.SIZE / 8; + + public static final int LESS = GL.GL_LESS; + public static final int LESS_OR_EQUAL = GL.GL_LEQUAL; + public static final int COUNTER_CLOCKWISE = GL.GL_CCW; + public static final int CLOCKWISE = GL.GL_CW; + public static final int FRONT = GL.GL_FRONT; + public static final int BACK = GL.GL_BACK; + public static final int BLEND_EQ_ADD = GL.GL_FUNC_ADD; + public static final int BLEND_EQ_MIN = GL2.GL_MIN; + public static final int BLEND_EQ_MAX = GL2.GL_MAX; + public static final int BLEND_EQ_REVERSE_SUBTRACT = GL.GL_FUNC_REVERSE_SUBTRACT; + public static final int REPLACE = GL2.GL_REPLACE; + public static final int MODULATE = GL2.GL_MODULATE; + public static final int FLAT = GL2.GL_FLAT; + public static final int SMOOTH = GL2.GL_SMOOTH; + + public static final int TEXTURE_2D = GL.GL_TEXTURE_2D; + public static final int RGB = GL.GL_RGB; + public static final int RGBA = GL.GL_RGBA; + public static final int ALPHA = GL.GL_ALPHA; + + public static final int NEAREST = GL.GL_NEAREST; + public static final int LINEAR = GL.GL_LINEAR; + public static final int LINEAR_MIPMAP_LINEAR = GL.GL_LINEAR_MIPMAP_LINEAR; + + public static final int CLAMP_TO_EDGE = GL.GL_CLAMP_TO_EDGE; + public static final int REPEAT = GL.GL_REPEAT; + + public static final int DEPTH_24BIT_STENCIL_8BIT = GL.GL_DEPTH24_STENCIL8; + + public static final int DEPTH_16BIT = GL.GL_DEPTH_COMPONENT16; + public static final int DEPTH_24BIT = GL.GL_DEPTH_COMPONENT24; + public static final int DEPTH_32BIT = GL.GL_DEPTH_COMPONENT32; + + public static final int STENCIL_1BIT = GL.GL_STENCIL_INDEX1; + public static final int STENCIL_4BIT = GL.GL_STENCIL_INDEX4; + public static final int STENCIL_8BIT = GL.GL_STENCIL_INDEX8; + + public static final int FRAMEBUFFER_COMPLETE = GL.GL_FRAMEBUFFER_COMPLETE; + public static final int FRAMEBUFFER_INCOMPLETE_ATTACHMENT = GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT; + public static final int FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT; + public static final int FRAMEBUFFER_INCOMPLETE_DIMENSIONS = GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS; + public static final int FRAMEBUFFER_INCOMPLETE_FORMATS = GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS; + public static final int FRAMEBUFFER_UNSUPPORTED = GL.GL_FRAMEBUFFER_UNSUPPORTED; + + public static final int STATIC_DRAW = GL.GL_STATIC_DRAW; + public static final int DYNAMIC_DRAW = GL.GL_DYNAMIC_DRAW; + public static final int STREAM_DRAW = GL2.GL_STREAM_DRAW; + + // Rendering pipeline modes + public static final int FIXED = 0; + public static final int PROG_GL2 = 1; + public static final int PROG_GL3 = 2; + public static final int PROG_GL4 = 3; + + /** Pipeline mode: FIXED, PROG_GL2, PROG_GL3 or PROG_GL4 */ + public int pipeline; + + /** Basic GL functionality, common to all profiles */ + public GL gl; + + public GL2 gl2; + + /** Advanced GL functionality (usually, things available as extensions in JOGL1). + * This profile is the intersection between GL 2.0 and GL 3.0 */ + public GL2GL3 gl2x; + + /** Fixed GL pipeline, with the functionality common to the GL2 desktop and GLES 1.1 profiles */ + public GL2ES1 gl2f; + + /** Basic programmable GL pipeline: intersection of desktop GL3, GL2 and embedded ES2 profile */ + public GL2ES2 gl2p; + + /** GL3 programmable pipeline, not backwards compatible with GL2 fixed */ + public GL3 gl3p; + + /** GL4 programmable pipeline, not backwards compatible with GL2 fixed */ + public GL4 gl4p; + + public GLU glu; + + public PGLJava() { + glu = new GLU(); + } + + public String getVendorString() { + return gl.glGetString(GL.GL_VENDOR); + } + + public String getRendererString() { + return gl.glGetString(GL.GL_RENDERER); + } + + public String getVersionString() { + return gl.glGetString(GL.GL_VERSION); + } + + public String getExtensionsString() { + return gl.glGetString(GL.GL_EXTENSIONS); + } + + public boolean isNpotTexSupported() { + // Better way to check for extensions and related functions (taken from jMonkeyEngine): + // renderbufferStorageMultisample = gl.isExtensionAvailable("GL_EXT_framebuffer_multisample") && + // gl.isFunctionAvailable("glRenderbufferStorageMultisample"); + // For more details on GL properties initialization in jMonkey using JOGL2, take a look at: + // http://code.google.com/p/jmonkeyengine/source/browse/branches/jme3/src/jogl2/com/jme3/renderer/jogl/JoglRenderer.java + + String ext = gl.glGetString(GL.GL_EXTENSIONS); + if (-1 < ext.indexOf("texture_non_power_of_two")) { + return true; + } + return false; + } + + public boolean hasMipmapGeneration() { + String ext = gl.glGetString(GL.GL_EXTENSIONS); + if (-1 < ext.indexOf("generate_mipmap")) { + return true; + } + return false; + } + + public boolean isMatrixGetSupported() { + String ext = gl.glGetString(GL.GL_EXTENSIONS); + if (-1 < ext.indexOf("matrix_get")) { + return true; + } + return false; + } + + public boolean isTexenvCrossbarSupported() { + String ext = gl.glGetString(GL.GL_EXTENSIONS); + if (-1 < ext.indexOf("texture_env_crossbar")) { + return true; + } + return false; + } + + public boolean isVboSupported() { + String ext = gl.glGetString(GL.GL_EXTENSIONS); + if (-1 < ext.indexOf("vertex_buffer_object")) { + return true; + } + return false; + } + + public boolean isFboSupported() { + String ext = gl.glGetString(GL.GL_EXTENSIONS); + if (-1 < ext.indexOf("framebuffer_object")) { + return true; + } + return false; + } + + public boolean isFboMultisampleSupported() { + String ext = gl.glGetString(GL.GL_EXTENSIONS); + if (-1 < ext.indexOf("framebuffer_multisample")) { + return true; + } + return false; + } + + public boolean isBlendEqSupported() { + return true; + } + + public int getMaxTexureSize() { + int temp[] = new int[1]; + gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, temp, 0); + return temp[0]; + } + + public int getMaxAliasedLineWidth() { + int temp[] = new int[2]; + gl.glGetIntegerv(GL.GL_ALIASED_LINE_WIDTH_RANGE, temp, 0); + return temp[1]; + } + + public int getMaxAliasedPointSize() { + int temp[] = new int[2]; + gl.glGetIntegerv(GL.GL_ALIASED_POINT_SIZE_RANGE, temp, 0); + return temp[1]; + } + + public int getMaxTextureUnits() { + // The maximum number of texture units only makes sense in the + // fixed pipeline. + int temp[] = new int[1]; + gl.glGetIntegerv(GL2.GL_MAX_TEXTURE_UNITS, temp, 0); + return temp[0]; + } + + public void flush() { + gl.glFlush(); + } + + public void finish() { + gl.glFinish(); + } + + void update(GLContext context) { + gl = context.getGL(); + + if (pipeline == PROG_GL4) { + gl4p = gl.getGL4(); + gl3p = gl4p; + gl2p = gl4p; + gl2f = null; + } else if (pipeline == PROG_GL3) { + gl4p = null; + gl3p = gl.getGL3(); + gl2p = gl3p; + gl2f = null; + } else if (pipeline == PROG_GL2) { + gl4p = null; + gl3p = null; + gl2p = gl.getGL2ES2(); + gl2f = null; + } else if (pipeline == FIXED) { + gl4p = null; + gl3p = null; + gl2p = null; + gl2f = gl.getGL2ES1(); + gl2 = gl.getGL2(); + } + + try { + gl2x = gl.getGL2GL3(); + } catch (GLException e) {} + } + + public int getError() { + return gl.glGetError(); + } + + public String getErrorString(int err) { + return glu.gluErrorString(err); + } + + public void setShadeModel(int model) { + gl2f.glShadeModel(model); + } + + public void enableColorMaterial() { + gl2f.glEnable(GL2.GL_COLOR_MATERIAL); + } + + public void enableNormalization() { + gl2f.glEnable(GL2.GL_NORMALIZE); + } + + public void enableRescaleNormals() { + gl2f.glEnable(GL2.GL_RESCALE_NORMAL); + } + + + void genVertexArray(int[] id) { + gl2x.glGenVertexArrays(1, id, 0); + } + + void delVertexArray(int[] id) { + gl2x.glDeleteVertexArrays(1, id, 0); + } + + void genTexture(int[] id) { + gl.glGenTextures(1, id, 0); + } + + void delTexture(int[] id) { + gl.glDeleteTextures(1, id, 0); + } + + void genBuffer(int[] id) { + gl.glGenBuffers(1, id, 0); + } + + void delBuffer(int[] id) { + gl.glDeleteBuffers(1, id, 0); + } + + void genFramebuffer(int[] id) { + gl.glGenFramebuffers(1, id, 0); + } + + void delFramebuffer(int[] id) { + gl.glDeleteFramebuffers(1, id, 0); + } + + void genRenderbuffer(int[] id) { + gl.glGenRenderbuffers(1, id, 0); + } + + void delRenderbuffer(int[] id) { + gl.glGenRenderbuffers(1, id, 0); + } + + void genProgram(int[] id) { + id[0] = gl2x.glCreateProgram(); + } + + void delProgram(int[] id) { + gl2x.glDeleteProgram(id[0]); + } + + void genVertexShader(int[] id) { + id[0] = gl2x.glCreateShader(GL2.GL_VERTEX_SHADER); + } + + void delVertexShader(int[] id) { + gl2x.glDeleteShader(id[0]); + } + + void genFragmentShader(int[] id) { + id[0] = gl2x.glCreateShader(GL2.GL_FRAGMENT_SHADER); + } + + void delFragmentShader(int[] id) { + gl2x.glDeleteShader(id[0]); + } + + void bindVertexBuffer(int id) { + gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, id); + } + + void initVertexBuffer(int size, int mode) { + gl2f.glBufferData(GL.GL_ARRAY_BUFFER, size * SIZEOF_FLOAT, null, mode); + } + + void copyVertexBufferData(float[] data, int size, int mode) { + gl2f.glBufferData(GL.GL_ARRAY_BUFFER, size * SIZEOF_FLOAT, FloatBuffer.wrap(data, 0, size), mode); + } + + void copyVertexBufferData(float[] data, int offset, int size, int mode) { + gl2f.glBufferData(GL.GL_ARRAY_BUFFER, size * SIZEOF_FLOAT, FloatBuffer.wrap(data, offset, size), mode); + } + + void copyVertexBufferSubData(float[] data, int offset, int size, int mode) { + gl2f.glBufferSubData(GL.GL_ARRAY_BUFFER, offset * SIZEOF_FLOAT, size * SIZEOF_FLOAT, FloatBuffer.wrap(data, 0, size)); + } + + void setVertexFormat(int size, int stride, long offset) { + gl2f.glVertexPointer(size, GL.GL_FLOAT, stride, offset); + } + + void setColorFormat(int size, int stride, long offset) { + gl2f.glColorPointer(size, GL.GL_FLOAT, stride, offset); + } + + void setNormalFormat(int size, int stride, long offset) { + gl2f.glNormalPointer(GL.GL_FLOAT, 0, 0); + } + + void setTexCoordFormat(int size, int stride, long offset) { + gl2f.glTexCoordPointer(size, GL.GL_FLOAT, stride, offset); + } + + void unbindVertexBuffer() { + gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + } + + void bindIndexBuffer(int id) { + gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, id); + } + + void initIndexBuffer(int size, int mode) { + gl2f.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, size * SIZEOF_INT, null, mode); + } + + void copyIndexBufferData(int[] data, int size, int mode) { + gl2f.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, size * SIZEOF_INT, IntBuffer.wrap(data, 0, size), mode); + } + + void copyIndexBufferData(int[] data, int offset, int size, int mode) { + gl2f.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, size * SIZEOF_INT, IntBuffer.wrap(data, offset, size), mode); + } + + void copyIndexBufferSubData(int[] data, int offset, int size, int mode) { + gl2f.glBufferSubData(GL.GL_ELEMENT_ARRAY_BUFFER, offset * SIZEOF_INT, size * SIZEOF_INT, IntBuffer.wrap(data, 0, size)); + } + + void renderIndexBuffer(int size) { + gl2f.glDrawElements(GL.GL_TRIANGLES, size, GL.GL_UNSIGNED_INT, 0); + } + + void renderIndexBuffer(int offset, int size) { + gl2f.glDrawElements(GL.GL_TRIANGLES, size, GL.GL_UNSIGNED_INT, offset * PGraphicsOpenGL.SIZEOF_INT); + } + + void unbindIndexBuffer() { + gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); + } + + public void enableDepthTest() { + gl.glEnable(GL.GL_DEPTH_TEST); + } + + public void disableDepthTest() { + gl.glEnable(GL.GL_DEPTH_TEST); + } + + public void enableDepthMask() { + gl.glDepthMask(true); + } + + public void disableDepthMask() { + gl.glDepthMask(false); + } + + public void setDepthFunc(int func) { + gl.glDepthFunc(func); + } + + public void getNumSamples(int[] num) { + gl.glGetIntegerv(GL.GL_SAMPLES, num, 0); + } + + public void getViweport(int[] viewport) { + gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); + } + + public void setViewport(int[] viewport) { + gl.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); + } + + public void setFrontFace(int mode) { + gl.glFrontFace(mode); + } + + public void enableMultisample() { + gl2f.glEnable(GL2.GL_MULTISAMPLE); + } + + public void disableMultisample() { + gl2f.glDisable(GL2.GL_MULTISAMPLE); + } + + public void enablePointSmooth() { + gl2f.glEnable(GL2.GL_POINT_SMOOTH); + } + + public void disablePointSmooth() { + gl2f.glDisable(GL2.GL_POINT_SMOOTH); + } + + public void enableLineSmooth() { + gl2f.glEnable(GL2.GL_LINE_SMOOTH); + } + + public void disableLineSmooth() { + gl2f.glDisable(GL2.GL_LINE_SMOOTH); + } + + public void enablePolygonSmooth() { + gl2f.glEnable(GL2.GL_POLYGON_SMOOTH); + } + + public void disablePolygonSmooth() { + gl2f.glDisable(GL2.GL_POLYGON_SMOOTH); + } + + public void setDrawBuffer(int buf) { + gl2x.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0 + buf); + } + + public void setClearColor(float r, float g, float b, float a) { + gl.glClearColor(r, g, b, a); + } + + public void clearDepthBuffer() { + gl.glClear(GL.GL_DEPTH_BUFFER_BIT); + } + + public void clearStencilBuffer() { + gl.glClear(GL.GL_STENCIL_BUFFER_BIT); + } + + public void clearDepthAndStencilBuffers() { + gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); + } + + public void clearColorBuffer() { + gl.glClear(GL.GL_COLOR_BUFFER_BIT); + } + + public void clearAllBuffers() { + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); + } + + public void enableClipping() { + gl.glEnable(GL.GL_SCISSOR_TEST); + } + + public void disableClipping() { + gl.glDisable(GL.GL_SCISSOR_TEST); + } + + public void setClipRect(int x, int y, int w, int h) { + gl.glScissor(x, y, w, h); + } + + public void setNormal(float nx, float ny, float nz) { + gl2f.glNormal3f(nx, ny, nz); + } + + public void setProjectionMode() { + gl2f.glMatrixMode(GL2.GL_PROJECTION); + } + + public void setModelviewMode() { + gl2f.glMatrixMode(GL2.GL_MODELVIEW); + } + + public void pushMatrix() { + gl2f.glPushMatrix(); + } + + public void popMatrix() { + gl2f.glPopMatrix(); + } + + public void loadIdentity() { + gl2f.glLoadIdentity(); + } + + public void multMatrix(float[] mat) { + gl2f.glMultMatrixf(mat, 0); + } + + public void loadMatrix(float[] mat) { + gl2f.glLoadMatrixf(mat, 0); + } + + public void translate(float tx, float ty, float tz) { + gl2f.glTranslatef(tx, ty, tz); + } + + public void rotate(float angle, float vx, float vy, float vz) { + gl2f.glRotatef(PApplet.degrees(angle), vx, vy, vz); + } + + public void scale(float sx, float sy, float sz) { + gl2f.glScalef(sx, sy, sz); + } + + public void enableVertexArrays() { + gl2f.glEnableClientState(GL2.GL_VERTEX_ARRAY); + } + + public void enableColorArrays() { + gl2f.glEnableClientState(GL2.GL_COLOR_ARRAY); + } + + public void enableNormalArrays() { + gl2f.glEnableClientState(GL2.GL_NORMAL_ARRAY); + } + + public void enableTexCoordArrays() { + gl2f.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + } + + public void disableVertexArrays() { + gl2f.glDisableClientState(GL2.GL_VERTEX_ARRAY); + } + + public void disableColorArrays() { + gl2f.glDisableClientState(GL2.GL_COLOR_ARRAY); + } + + public void disableNormalArrays() { + gl2f.glDisableClientState(GL2.GL_NORMAL_ARRAY); + } + + public void disableTexCoordArrays() { + gl2f.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + } + + public void enableTexturing(int target) { + gl2f.glEnable(target); + } + + public void setActiveTexUnit(int tu) { + gl2f.glActiveTexture(GL.GL_TEXTURE0 + tu); + } + + public void bindTexture(int target, int id) { + gl2f.glBindTexture(target, id); + } + + public void unbindTexture(int target) { + gl2f.glBindTexture(target, 0); + } + + public void disableTexturing(int target) { + gl2f.glDisable(target); + } + + public void enableAttribsArray(int loc) { + gl2x.glEnableVertexAttribArray(loc); + } + + public void setAttribsFormat(int loc, int size, int stride, long offset) { + gl2x.glVertexAttribPointer(loc, size, GL.GL_FLOAT, false, stride, offset); + } + + public void disableAttribsArray(int loc) { + gl2x.glDisableVertexAttribArray(loc); + } + + public void setColor(float r, float g, float b, float a) { + gl2f.glColor4f(r, g, b, a); + } + + public void setMaterialAmbient(float[] color) { + gl2f.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, color, 0); + } + + public void setMaterialSpecular(float[] color) { + gl2f.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, color, 0); + } + + public void setMaterialEmission(float[] color) { + gl2f.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_EMISSION, color, 0); + } + + public void setMaterialShininess(float shine) { + gl2f.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, shine); + } + + public void enableLighting() { + gl2f.glEnable(GL2.GL_LIGHTING); + } + + public void disableLighting() { + gl2f.glDisable(GL2.GL_LIGHTING); + } + + public void setTwoSidedLightModel() { + gl2f.glLightModelf(GL2.GL_LIGHT_MODEL_TWO_SIDE, 0); + } + + public void setDefaultAmbientLight(float[] color) { + gl2f.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, color, 0); + } + + public void enableLight(int light) { + gl2f.glEnable(GL2.GL_LIGHT0 + light); + } + + public void disableLight(int light) { + gl2f.glDisable(GL2.GL_LIGHT0 + light); + } + + public void setLightPosition(int light, float[] pos) { + gl2f.glLightfv(GL2.GL_LIGHT0 + light, GL2.GL_POSITION, pos, 0); + } + + public void setAmbientLight(int light, float[] color) { + gl2f.glLightfv(GL2.GL_LIGHT0 + light, GL2.GL_AMBIENT, color, 0); + } + + public void setDiffuseLight(int light, float[] color) { + gl2f.glLightfv(GL2.GL_LIGHT0 + light, GL2.GL_DIFFUSE, color, 0); + } + + public void setSpecularLight(int light, float[] color) { + gl2f.glLightfv(GL2.GL_LIGHT0 + light, GL2.GL_SPECULAR, color, 0); + } + + public void setLightDirection(int light, float[] dir) { + // The w component of lightNormal[num] is zero, so the light is considered as + // a directional source because the position effectively becomes a direction + // in homogeneous coordinates: + // http://glprogramming.com/red/appendixf.html + dir[3] = 0; + gl2f.glLightfv(GL2.GL_LIGHT0 + light, GL2.GL_POSITION, dir, 0); + } + + public void setSpotLightCutoff(int light, float cutoff) { + gl2f.glLightf(GL2.GL_LIGHT0 + light, GL2.GL_SPOT_CUTOFF, cutoff); + } + + public void setSpotLightExponent(int light, float exp) { + gl2f.glLightf(GL2.GL_LIGHT0 + light, GL2.GL_SPOT_EXPONENT, exp); + } + + public void setSpotLightDirection(int light, float[] dir) { + gl2f.glLightfv(GL2.GL_LIGHT0 + light, GL2.GL_POSITION, dir, 0); + } + + public void setLightConstantAttenuation(int light, float attn) { + gl2f.glLightf(GL2.GL_LIGHT0 + light, GL2.GL_CONSTANT_ATTENUATION, attn); + } + + public void setLightLinearAttenuation(int light, float attn) { + gl2f.glLightf(GL2.GL_LIGHT0 + light, GL2.GL_LINEAR_ATTENUATION, attn); + } + + public void setLightQuadraticAttenuation(int light, float attn) { + gl2f.glLightf(GL2.GL_LIGHT0 + light, GL2.GL_QUADRATIC_ATTENUATION, attn); + } + + public void setReadBuffer(int buf) { + gl2x.glReadBuffer(buf); + } + + public void readPixels(Buffer buffer, int x, int y, int w, int h) { + gl.glReadPixels(x, y, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer); + } + + public void enableBlend() { + gl.glEnable(GL.GL_BLEND); + } + + public void setBlendEquation(int eq) { + gl.glBlendEquation(eq); + } + + public void setReplaceBlend() { + gl.glBlendFunc(GL.GL_ONE, GL.GL_ZERO); + } + + public void setDefaultBlend() { + gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + } + + public void setAdditiveBlend() { + gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + } + + public void setSubstractiveBlend() { + gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ZERO); + } + + public void setLightestBlend() { + gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_DST_ALPHA); + } + + public void setDarkestBlend() { + gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_DST_ALPHA); + } + + public void setDifferenceBlend() { + gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE); + } + + public void setExclussionBlend() { + gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE_MINUS_SRC_COLOR); + } + + public void setMultiplyBlend() { + gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_SRC_COLOR); + } + + public void setScreenBlend() { + gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE); + } + + public void initTex(int target, int format, int w, int h) { + gl.glTexImage2D(target, 0, format, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null); + } + + public void copyTexSubImage(Buffer image, int target, int x, int y, int w, int h) { + gl.glTexSubImage2D(target, 0, x, y, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, image); + } + + public void copyTexSubPixels(int[] pixels, int target, int x, int y, int w, int h) { + gl.glTexSubImage2D(target, 0, x, y, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(pixels)); + } + + public void copyTexImage(Buffer image, int target, int format, int w, int h) { + gl.glTexImage2D(target, 0, format, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, image); + } + + public void setTexEnvironmentMode(int mode) { + gl2f.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, mode); + } + + public void enableTexMipmapGen(int target) { + gl.glTexParameteri(target, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE); + } + + public void disableTexMipmapGen(int target) { + gl.glTexParameteri(target, GL2.GL_GENERATE_MIPMAP, GL.GL_FALSE); + } + + public void setTexMinFilter(int target, int filter) { + gl.glTexParameteri(target, GL.GL_TEXTURE_MIN_FILTER, filter); + } + + public void setTexMagFilter(int target, int filter) { + gl.glTexParameteri(target, GL.GL_TEXTURE_MAG_FILTER, filter); + } + + public void setTexWrapS(int target, int wrap) { + gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_S, wrap); + } + + public void setTexWrapT(int target, int wrap) { + gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_T, wrap); + } + + public void setOrthographicProjection(float left, float right, float bottom, float top, float near, float far) { + gl2f.glOrthof(left, right, bottom, top, near, far); + } + + public void bindFramebuffer(int id) { + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, id); + } + + public void bindReadFramebuffer(int id) { + gl.glBindFramebuffer(GL2.GL_READ_FRAMEBUFFER, id); + } + + public void bindWriteFramebuffer(int id) { + gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, id); + } + + public void copyFramebuffer(int srcW, int srcH, int destW, int destH) { + gl2x.glBlitFramebuffer(0, 0, srcW, srcH, 0, 0, destW, destH, GL.GL_COLOR_BUFFER_BIT, GL.GL_NEAREST); + } + + public void cleanFramebufferTexture(int fb) { + gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0 + fb, GL.GL_TEXTURE_2D, 0, 0); + } + + public void setFramebufferTexture(int fb, int target, int id) { + gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0 + fb, target, id, 0); + } + + public void bindRenderbuffer(int id) { + gl.glBindRenderbuffer(GL.GL_RENDERBUFFER,id); + } + + public void setRenderbufferNumSamples(int samples, int w, int h) { + gl2x.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, samples, GL.GL_RGBA8, w, h); + } + + public void setRenderbufferStorage(int format, int w, int h) { + gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, format, w, h); + } + + public void setRenderbufferColorAttachment(int id) { + gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_RENDERBUFFER, id); + } + + public void setRenderbufferDepthAttachment(int id) { + gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, id); + } + + public void setRenderbufferStencilAttachment(int id) { + gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, id); + } + + public int getFramebufferStatus() { + return gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER); + } + + public void linkProgram(int prog) { + gl2.glLinkProgram(prog); + } + + public void validateProgram(int prog) { + gl2.glValidateProgram(prog); + } + + public void startProgram(int prog) { + gl2.glUseProgramObjectARB(prog); + } + + public void stopProgram() { + gl2.glUseProgramObjectARB(0); + } + + public int getAttribLocation(int prog, String name) { + return gl2.glGetAttribLocation(prog, name); + } + + public int getUniformLocation(int prog, String name) { + return gl2.glGetUniformLocation(prog, name); + } + + public void setIntUniform(int loc, int value) { + gl2.glUniform1i(loc, value); + } + + public void setFloatUniform(int loc, float value) { + gl2.glUniform1f(loc, value); + } + + public void setFloatUniform(int loc, float value0, float value1) { + gl2.glUniform2f(loc, value0, value1); + } + + public void setFloatUniform(int loc, float value0, float value1, float value2) { + gl2.glUniform3f(loc, value0, value1, value2); + } + + public void setFloatUniform(int loc, float value0, float value1, float value2, float value3) { + gl2.glUniform4f(loc, value0, value1, value2, value3); + } + + public void setMatUniform(int loc, float m00, float m01, + float m10, float m11) { + float[] mat = new float[4]; + mat[0] = m00; mat[4] = m01; + mat[1] = m10; mat[5] = m11; + gl2.glUniformMatrix2fv(loc, 1, false, mat, 0); + } + + public void setMatUniform(int loc, float m00, float m01, float m02, + float m10, float m11, float m12, + float m20, float m21, float m22) { + float[] mat = new float[9]; + mat[0] = m00; mat[4] = m01; mat[ 8] = m02; + mat[1] = m10; mat[5] = m11; mat[ 9] = m12; + mat[2] = m20; mat[6] = m21; mat[10] = m22; + gl2.glUniformMatrix3fv(loc, 1, false, mat, 0); + } + + public void setMatUniform(int loc, float m00, float m01, float m02, float m03, + float m10, float m11, float m12, float m13, + float m20, float m21, float m22, float m23, + float m30, float m31, float m32, float m33) { + float[] mat = new float[16]; + mat[0] = m00; mat[4] = m01; mat[ 8] = m02; mat[12] = m03; + mat[1] = m10; mat[5] = m11; mat[ 9] = m12; mat[13] = m13; + mat[2] = m20; mat[6] = m21; mat[10] = m22; mat[14] = m23; + mat[3] = m30; mat[7] = m31; mat[11] = m32; mat[15] = m33; + gl2.glUniformMatrix4fv(loc, 1, false, mat, 0); + } + + public void setFloatAttrib(int loc, float value) { + gl2.glVertexAttrib1f(loc, value); + } + + public void setFloatAttrib(int loc, float value0, float value1) { + gl2.glVertexAttrib2f(loc, value0, value1); + } + + public void setFloatAttrib(int loc, float value0, float value1, float value2) { + gl2.glVertexAttrib3f(loc, value0, value1, value2); + } + + public void setFloatAttrib(int loc, float value0, float value1, float value2, float value3) { + gl2.glVertexAttrib4f(loc, value0, value1, value2, value3); + } + + public void setShaderSource(int id, String source) { + gl2.glShaderSource(id, 1, new String[] { source }, (int[]) null, 0); + } + + public void compileShader(int id) { + gl2.glCompileShader(id); + } + + public void attachShader(int prog, int shader) { + gl2.glAttachObjectARB(prog, shader); + } + + public String getShaderLog(int id) { + IntBuffer val = IntBuffer.allocate(1); + gl2.glGetObjectParameterivARB(id, GL2.GL_OBJECT_INFO_LOG_LENGTH_ARB, val); + + int length = val.get(); + + if (length <= 1) { + return ""; + } + + // Some error occurred... + ByteBuffer infoLog = ByteBuffer.allocate(length); + val.flip(); + + gl2.glGetInfoLogARB(id, length, val, infoLog); + + byte[] infoBytes = new byte[length]; + infoLog.get(infoBytes); + return new String(infoBytes); + } + + +} diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index f184dc5e3..f6f8e0499 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -40,16 +40,9 @@ import javax.media.nativewindow.awt.AWTGraphicsConfiguration; import javax.media.nativewindow.awt.AWTGraphicsDevice; import javax.media.nativewindow.awt.AWTGraphicsScreen; import javax.media.opengl.GL; -import javax.media.opengl.GL2; -import javax.media.opengl.GL2ES1; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GL2GL3; -import javax.media.opengl.GL3; -import javax.media.opengl.GL4; import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawable; import javax.media.opengl.GLDrawableFactory; -import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; import javax.media.opengl.GLCapabilities; import javax.media.opengl.glu.GLU; @@ -65,57 +58,20 @@ import processing.core.PApplet; * */ public class PGraphicsOpenGL extends PGraphics { - // JOGL2 objects: - - /** - * How the P3D renderer handles the different OpenGL profiles? Basically, - * P3D has two pipeline modes: fixed or programmable. In the fixed mode, - * only the gl and gl2f objects are available. The gl2f object contains the - * intersection between OpenGL 2.x desktop and OpenGL 1.1 embedded, and in this - * way it ensures the functionality parity between the P3D render (PC/MAC) - * and A3D (Android) in the fixed pipeline mode. - * In the programmable mode, there further options: GL2, GL3 and GL4. - * GL2 corresponds to the basic programmable profile that results from the common - * functionality between OpenGL 3.0 desktop and OpenGL 2.0 embedded. As said just - * before, since P3D and A3D aim at feature parity as much as possible, this is - * the only programmable-pipeline GL object that the P3D renderer uses. - * The gl3 and gl4 objects will be available when the pipeline mode is PROG_GL3 or - * PROG_GL4, respectively. Although P3D doens't make any use of these objects, - * they are part of the API nonetheless for users (or libraries) requiring advanced - * functionality introduced with OpenGL 3 or OpenGL 4. - * By default, P3D tries to auto-select the pipeline mode by with the following - * priority order: PROG_GL4, PROG_GL3, PROG_GL2, FIXED. In all the programmable modes, - * the gl2p object is always available. This auto-selection can be optionally - * overridden when creating the renderer object, so that a specific mode is set. - * Note that the programmable mode uses the non-backward compatible GL objects - * (GL3, GL4, and not GL3bc, GL4bc) so no fixed mode calls are possible under this mode. - */ - - /** Pipeline mode: FIXED, PROG_GL2, PROG_GL3 or PROG_GL4 */ - public int pipeline; - - /** Basic GL functionality, common to all profiles */ - public GL gl; - + /* + public int pipeline; + public GL gl; public GL2 gl2; - - /** Advanced GL functionality (usually, things available as extensions in JOGL1). - * This profile is the intersection between GL 2.0 and GL 3.0 */ public GL2GL3 gl2x; - - /** Fixed GL pipeline, with the functionality common to the GL2 desktop and GLES 1.1 profiles */ public GL2ES1 gl2f; - - /** Basic programmable GL pipeline: intersection of desktop GL3, GL2 and embedded ES2 profile */ public GL2ES2 gl2p; - - /** GL3 programmable pipeline, not backwards compatible with GL2 fixed */ public GL3 gl3p; - - /** GL4 programmable pipeline, not backwards compatible with GL2 fixed */ public GL4 gl4p; + */ + + protected PGLJava pgl; + - public GLU glu; /** Selected GL profile */ protected GLProfile profile; @@ -129,6 +85,8 @@ public class PGraphicsOpenGL extends PGraphics { /** The rendering context (holds rendering state info) */ protected GLContext context; + + /** The PApplet renderer. For the primary surface, pgl == this. */ protected PGraphicsOpenGL ogl; @@ -324,12 +282,6 @@ public class PGraphicsOpenGL extends PGraphics { /** Font texture of currently selected font. */ PFontTexture textTex; - // ....................................................... - - // Utility textured quad: - - static protected FloatBuffer quadVertexBuffer = null; - static protected FloatBuffer quadTexCoordBuffer = null; // ....................................................... @@ -388,6 +340,7 @@ public class PGraphicsOpenGL extends PGraphics { /** Stores previous viewport dimensions. */ protected int[] savedViewport = {0, 0, 0, 0}; + protected int[] viewport = {0, 0, 0, 0}; // ........................................................ @@ -469,8 +422,8 @@ public class PGraphicsOpenGL extends PGraphics { static protected PShader lineShader; static protected PShader pointShader; - static protected int lineAttribsID; - static protected int pointAttribsID; + static protected int lineAttribsLoc; + static protected int pointAttribsLoc; protected PImage textureImage0; @@ -478,7 +431,7 @@ public class PGraphicsOpenGL extends PGraphics { protected boolean defaultEdges = false; - protected int vboMode = GL.GL_STATIC_DRAW; + protected int vboMode = PGLJava.STATIC_DRAW; static public float FLOAT_EPS = Float.MIN_VALUE; // Calculation of the Machine Epsilon for float precision. From: @@ -499,7 +452,7 @@ public class PGraphicsOpenGL extends PGraphics { // INIT/ALLOCATE/FINISH public PGraphicsOpenGL() { - glu = new GLU(); + pgl = new PGLJava(); tessellator = new Tessellator(); @@ -651,7 +604,8 @@ public class PGraphicsOpenGL extends PGraphics { deleteFinalizedVertexArrayObjects(); int[] temp = new int[1]; - gl2x.glGenVertexArrays(1, temp, 0); + pgl.genVertexArray(temp); + //gl2x.glGenVertexArrays(1, temp, 0); int id = temp[0]; if (glVertexArrays.containsKey(id)) { @@ -666,7 +620,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteVertexArrayObject(int id) { if (glVertexArrays.containsKey(id)) { int[] temp = { id }; - gl2x.glDeleteVertexArrays(1, temp, 0); + pgl.delVertexArray(temp); + //gl2x.glDeleteVertexArrays(1, temp, 0); glVertexArrays.remove(id); } } @@ -674,7 +629,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteAllVertexArrayObjects() { for (Integer id : glVertexArrays.keySet()) { int[] temp = { id.intValue() }; - gl2x.glDeleteVertexArrays(1, temp, 0); + pgl.delVertexArray(temp); + //gl2x.glDeleteVertexArrays(1, temp, 0); } glVertexArrays.clear(); } @@ -695,7 +651,8 @@ public class PGraphicsOpenGL extends PGraphics { if (glVertexArrays.get(id)) { finalized.add(id); int[] temp = { id.intValue() }; - gl2x.glDeleteVertexArrays(1, temp, 0); + //gl2x.glDeleteVertexArrays(1, temp, 0); + pgl.delVertexArray(temp); } } @@ -711,7 +668,8 @@ public class PGraphicsOpenGL extends PGraphics { deleteFinalizedTextureObjects(); int[] temp = new int[1]; - gl.glGenTextures(1, temp, 0); + //gl.glGenTextures(1, temp, 0); + pgl.genTexture(temp); int id = temp[0]; if (glTextureObjects.containsKey(id)) { @@ -726,7 +684,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteTextureObject(int id) { if (glTextureObjects.containsKey(id)) { int[] temp = { id }; - gl.glDeleteTextures(1, temp, 0); + pgl.delTexture(temp); + //gl.glDeleteTextures(1, temp, 0); glTextureObjects.remove(id); } } @@ -734,7 +693,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteAllTextureObjects() { for (Integer id : glTextureObjects.keySet()) { int[] temp = { id.intValue() }; - gl.glDeleteTextures(1, temp, 0); + //gl.glDeleteTextures(1, temp, 0); + pgl.delTexture(temp); } glTextureObjects.clear(); } @@ -755,7 +715,8 @@ public class PGraphicsOpenGL extends PGraphics { if (glTextureObjects.get(id)) { finalized.add(id); int[] temp = { id.intValue() }; - gl.glDeleteTextures(1, temp, 0); + //gl.glDeleteTextures(1, temp, 0); + pgl.delTexture(temp); } } @@ -770,7 +731,8 @@ public class PGraphicsOpenGL extends PGraphics { deleteFinalizedVertexBufferObjects(); int[] temp = new int[1]; - gl.glGenBuffers(1, temp, 0); + //gl.glGenBuffers(1, temp, 0); + pgl.genBuffer(temp); int id = temp[0]; if (glVertexBuffers.containsKey(id)) { @@ -785,7 +747,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteVertexBufferObject(int id) { if (glVertexBuffers.containsKey(id)) { int[] temp = { id }; - gl.glDeleteBuffers(1, temp, 0); + //gl.glDeleteBuffers(1, temp, 0); + pgl.delBuffer(temp); glVertexBuffers.remove(id); } } @@ -793,7 +756,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteAllVertexBufferObjects() { for (Integer id : glVertexBuffers.keySet()) { int[] temp = { id.intValue() }; - gl.glDeleteBuffers(1, temp, 0); + //gl.glDeleteBuffers(1, temp, 0); + pgl.delBuffer(temp); } glVertexBuffers.clear(); } @@ -814,7 +778,8 @@ public class PGraphicsOpenGL extends PGraphics { if (glVertexBuffers.get(id)) { finalized.add(id); int[] temp = { id.intValue() }; - gl.glDeleteBuffers(1, temp, 0); + //gl.glDeleteBuffers(1, temp, 0); + pgl.delBuffer(temp); } } @@ -829,7 +794,8 @@ public class PGraphicsOpenGL extends PGraphics { deleteFinalizedFrameBufferObjects(); int[] temp = new int[1]; - gl.glGenFramebuffers(1, temp, 0); + //gl.glGenFramebuffers(1, temp, 0); + pgl.genFramebuffer(temp); int id = temp[0]; if (glFrameBuffers.containsKey(id)) { @@ -844,7 +810,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteFrameBufferObject(int id) { if (glFrameBuffers.containsKey(id)) { int[] temp = { id }; - gl.glDeleteFramebuffers(1, temp, 0); + //gl.glDeleteFramebuffers(1, temp, 0); + pgl.delFramebuffer(temp); glFrameBuffers.remove(id); } } @@ -852,7 +819,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteAllFrameBufferObjects() { for (Integer id : glFrameBuffers.keySet()) { int[] temp = { id.intValue() }; - gl.glDeleteFramebuffers(1, temp, 0); + //gl.glDeleteFramebuffers(1, temp, 0); + pgl.delFramebuffer(temp); } glFrameBuffers.clear(); } @@ -873,7 +841,8 @@ public class PGraphicsOpenGL extends PGraphics { if (glFrameBuffers.get(id)) { finalized.add(id); int[] temp = { id.intValue() }; - gl.glDeleteFramebuffers(1, temp, 0); + //gl.glDeleteFramebuffers(1, temp, 0); + pgl.delFramebuffer(temp); } } @@ -888,7 +857,8 @@ public class PGraphicsOpenGL extends PGraphics { deleteFinalizedRenderBufferObjects(); int[] temp = new int[1]; - gl.glGenRenderbuffers(1, temp, 0); + //gl.glGenRenderbuffers(1, temp, 0); + pgl.genRenderbuffer(temp); int id = temp[0]; if (glRenderBuffers.containsKey(id)) { @@ -903,7 +873,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteRenderBufferObject(int id) { if (glRenderBuffers.containsKey(id)) { int[] temp = { id }; - gl.glDeleteRenderbuffers(1, temp, 0); + //gl.glDeleteRenderbuffers(1, temp, 0); + pgl.delRenderbuffer(temp); glRenderBuffers.remove(id); } } @@ -911,7 +882,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteAllRenderBufferObjects() { for (Integer id : glRenderBuffers.keySet()) { int[] temp = { id.intValue() }; - gl.glDeleteRenderbuffers(1, temp, 0); + //gl.glDeleteRenderbuffers(1, temp, 0); + pgl.delRenderbuffer(temp); } glRenderBuffers.clear(); } @@ -932,7 +904,8 @@ public class PGraphicsOpenGL extends PGraphics { if (glRenderBuffers.get(id)) { finalized.add(id); int[] temp = { id.intValue() }; - gl.glDeleteRenderbuffers(1, temp, 0); + //gl.glDeleteRenderbuffers(1, temp, 0); + pgl.delRenderbuffer(temp); } } @@ -948,7 +921,10 @@ public class PGraphicsOpenGL extends PGraphics { ogl.report("before delete"); deleteFinalizedGLSLProgramObjects(); - int id = gl2x.glCreateProgram(); + int[] temp = new int[1]; + //int id = gl2x.glCreateProgram(); + pgl.genProgram(temp); + int id = temp[0]; if (glslPrograms.containsKey(id)) { showWarning("Adding same glsl program twice"); @@ -961,14 +937,18 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteGLSLProgramObject(int id) { if (glslPrograms.containsKey(id)) { - gl2x.glDeleteProgram(id); + int[] temp = { id }; + pgl.delProgram(temp); + //gl2x.glDeleteProgram(id); glslPrograms.remove(id); } } protected void deleteAllGLSLProgramObjects() { for (Integer id : glslPrograms.keySet()) { - gl2x.glDeleteProgram(id); + int[] temp = { id.intValue() }; + //gl2x.glDeleteProgram(id); + pgl.delProgram(temp); } glslPrograms.clear(); } @@ -988,7 +968,9 @@ public class PGraphicsOpenGL extends PGraphics { for (Integer id : glslPrograms.keySet()) { if (glslPrograms.get(id)) { finalized.add(id); - gl2x.glDeleteProgram(id.intValue()); + int[] temp = { id.intValue() }; + //gl2x.glDeleteProgram(id.intValue()); + pgl.delProgram(temp); } } @@ -1002,7 +984,10 @@ public class PGraphicsOpenGL extends PGraphics { protected int createGLSLVertShaderObject() { deleteFinalizedGLSLVertShaderObjects(); - int id = gl2x.glCreateShader(GL2.GL_VERTEX_SHADER); + int[] temp = new int[1]; + //int id = gl2x.glCreateShader(GL2.GL_VERTEX_SHADER); + pgl.genVertexShader(temp); + int id = temp[0]; if (glslVertexShaders.containsKey(id)) { showWarning("Adding same glsl vertex shader twice"); @@ -1015,14 +1000,18 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteGLSLVertShaderObject(int id) { if (glslVertexShaders.containsKey(id)) { - gl2x.glDeleteShader(id); + int[] temp = { id }; + pgl.delVertexShader(temp); + //gl2x.glDeleteShader(id); glslVertexShaders.remove(id); } } protected void deleteAllGLSLVertShaderObjects() { for (Integer id : glslVertexShaders.keySet()) { - gl2x.glDeleteShader(id); + int[] temp = { id.intValue() }; + //gl2x.glDeleteShader(id); + pgl.delVertexShader(temp); } glslVertexShaders.clear(); } @@ -1042,7 +1031,9 @@ public class PGraphicsOpenGL extends PGraphics { for (Integer id : glslVertexShaders.keySet()) { if (glslVertexShaders.get(id)) { finalized.add(id); - gl2x.glDeleteShader(id.intValue()); + int[] temp = { id.intValue() }; + //gl2x.glDeleteShader(id.intValue()); + pgl.delVertexShader(temp); } } @@ -1057,7 +1048,10 @@ public class PGraphicsOpenGL extends PGraphics { protected int createGLSLFragShaderObject() { deleteFinalizedGLSLFragShaderObjects(); - int id = gl2x.glCreateShader(GL2.GL_FRAGMENT_SHADER); + int[] temp = new int[1]; + //int id = gl2x.glCreateShader(GL2.GL_FRAGMENT_SHADER); + pgl.genFragmentShader(temp); + int id = temp[0]; if (glslFragmentShaders.containsKey(id)) { showWarning("Adding same glsl fragment shader twice"); @@ -1070,14 +1064,18 @@ public class PGraphicsOpenGL extends PGraphics { protected void deleteGLSLFragShaderObject(int id) { if (glslFragmentShaders.containsKey(id)) { - gl2x.glDeleteShader(id); + int[] temp = { id }; + //gl2x.glDeleteShader(id); + pgl.delFragmentShader(temp); glslFragmentShaders.remove(id); } } protected void deleteAllGLSLFragShaderObjects() { for (Integer id : glslFragmentShaders.keySet()) { - gl2x.glDeleteShader(id); + int[] temp = { id.intValue() }; + pgl.delFragmentShader(temp); + //gl2x.glDeleteShader(id); } glslFragmentShaders.clear(); } @@ -1097,7 +1095,9 @@ public class PGraphicsOpenGL extends PGraphics { for (Integer id : glslFragmentShaders.keySet()) { if (glslFragmentShaders.get(id)) { finalized.add(id); - gl2x.glDeleteShader(id.intValue()); + int[] temp = { id.intValue() }; + //gl2x.glDeleteShader(id.intValue()); + pgl.delFragmentShader(temp); } } @@ -1252,39 +1252,51 @@ public class PGraphicsOpenGL extends PGraphics { */ public void restartContext() { releaseResources(); - //deleteFinalizedGLResources(); releaseContext(); context.destroy(); context = null; + allocate(); - detainContext(); - + detainContext(); updateGLInterfaces(); } protected void createFillBuffers() { glFillVertexBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); - + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glFillVertexBufferID); + pgl.initVertexBuffer(3 * MAX_TESS_VERTICES, vboMode); + glFillColorBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); - + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * MAX_TESS_VERTICES * SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glFillColorBufferID); + pgl.initVertexBuffer(4 * MAX_TESS_VERTICES, vboMode); + glFillNormalBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glFillNormalBufferID); + pgl.initVertexBuffer(3 * MAX_TESS_VERTICES, vboMode); glFillTexCoordBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 2 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 2 * MAX_TESS_VERTICES * SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glFillTexCoordBufferID); + pgl.initVertexBuffer(2 * MAX_TESS_VERTICES, vboMode); + + pgl.unbindVertexBuffer(); glFillIndexBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillIndexBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, MAX_TESS_INDICES * PGraphicsOpenGL.SIZEOF_INT, null, vboMode); - - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillIndexBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, MAX_TESS_INDICES * SIZEOF_INT, null, vboMode); + pgl.bindIndexBuffer(glFillIndexBufferID); + pgl.initIndexBuffer(MAX_TESS_INDICES, vboMode); + + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); } protected void releaseFillBuffers() { @@ -1306,26 +1318,39 @@ public class PGraphicsOpenGL extends PGraphics { protected void createLineBuffers() { glLineVertexBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glLineVertexBufferID); + pgl.initVertexBuffer(3 * MAX_TESS_VERTICES, vboMode); glLineColorBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); - - glLineNormalBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glLineColorBufferID); + pgl.initVertexBuffer(4 * MAX_TESS_VERTICES, vboMode); + glLineNormalBufferID = createVertexBufferObject(); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glLineNormalBufferID); + pgl.initVertexBuffer(3 * MAX_TESS_VERTICES, vboMode); + glLineAttribBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineAttribBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineAttribBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glLineAttribBufferID); + pgl.initVertexBuffer(4 * MAX_TESS_VERTICES, vboMode); + + pgl.unbindVertexBuffer(); glLineIndexBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineIndexBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, MAX_TESS_INDICES * PGraphicsOpenGL.SIZEOF_INT, null, vboMode); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineIndexBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, MAX_TESS_INDICES * PGraphicsOpenGL.SIZEOF_INT, null, vboMode); + pgl.bindIndexBuffer(glLineIndexBufferID); + pgl.initIndexBuffer(MAX_TESS_INDICES, vboMode); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); } protected void releaseLineBuffers() { @@ -1347,26 +1372,39 @@ public class PGraphicsOpenGL extends PGraphics { protected void createPointBuffers() { glPointVertexBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); - + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glPointVertexBufferID); + pgl.initVertexBuffer(3 * MAX_TESS_VERTICES, vboMode); + glPointColorBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glPointColorBufferID); + pgl.initVertexBuffer(4 * MAX_TESS_VERTICES, vboMode); glPointNormalBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); - + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glPointNormalBufferID); + pgl.initVertexBuffer(3 * MAX_TESS_VERTICES, vboMode); + glPointAttribBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointAttribBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 2 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointAttribBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 2 * MAX_TESS_VERTICES * PGraphicsOpenGL.SIZEOF_FLOAT, null, vboMode); + pgl.bindVertexBuffer(glPointAttribBufferID); + pgl.initVertexBuffer(2 * MAX_TESS_VERTICES, vboMode); + + pgl.unbindVertexBuffer(); glPointIndexBufferID = createVertexBufferObject(); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointIndexBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, MAX_TESS_INDICES * PGraphicsOpenGL.SIZEOF_INT, null, vboMode); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointIndexBufferID); + //gl2f.glBufferData(GL.GL_ARRAY_BUFFER, MAX_TESS_INDICES * PGraphicsOpenGL.SIZEOF_INT, null, vboMode); + pgl.bindIndexBuffer(glPointIndexBufferID); + pgl.initIndexBuffer(MAX_TESS_INDICES, vboMode); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); } protected void releasePointBuffers() { @@ -1452,17 +1490,22 @@ public class PGraphicsOpenGL extends PGraphics { // this is necessary for 3D drawing if (hints[DISABLE_DEPTH_TEST]) { - gl.glDisable(GL.GL_DEPTH_TEST); + pgl.disableDepthTest(); + //gl.glDisable(GL.GL_DEPTH_TEST); } else { - gl.glEnable(GL.GL_DEPTH_TEST); + //gl.glEnable(GL.GL_DEPTH_TEST); + pgl.enableDepthTest(); } // use <= since that's what processing.core does - gl.glDepthFunc(GL.GL_LEQUAL); + //gl.glDepthFunc(GL.GL_LEQUAL); + pgl.setDepthFunc(PGLJava.LESS_OR_EQUAL); if (hints[DISABLE_DEPTH_MASK]) { - gl.glDepthMask(false); + //gl.glDepthMask(false); + pgl.disableDepthMask(); } else { - gl.glDepthMask(true); + //gl.glDepthMask(true); + pgl.enableDepthMask(); } if (hints[ENABLE_ACCURATE_2D]) { @@ -1472,8 +1515,11 @@ public class PGraphicsOpenGL extends PGraphics { } // setup opengl viewport. - gl.glGetIntegerv(GL.GL_VIEWPORT, savedViewport, 0); - gl.glViewport(0, 0, width, height); + pgl.getViweport(savedViewport); + //gl.glGetIntegerv(GL.GL_VIEWPORT, savedViewport, 0); + viewport[0] = 0; viewport[1] = 0; viewport[2] = width; viewport[3] = height; + //gl.glViewport(0, 0, width, height); + pgl.setViewport(viewport); if (resized) { // To avoid having garbage in the screen after a resize, // in the case background is not called in draw(). @@ -1515,7 +1561,8 @@ public class PGraphicsOpenGL extends PGraphics { lightSpecular(0, 0, 0); // because y is flipped - gl.glFrontFace(GL.GL_CW); + pgl.setFrontFace(PGLJava.CLOCKWISE); + //gl.glFrontFace(GL.GL_CW); setSurfaceParams(); @@ -1529,16 +1576,19 @@ public class PGraphicsOpenGL extends PGraphics { } else { pushFramebuffer(); if (offscreenMultisample) { - setFramebuffer(offscreenFramebufferMultisample); - gl2x.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0); + setFramebuffer(offscreenFramebufferMultisample); + //gl2x.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0); + pgl.setDrawBuffer(0); } else { setFramebuffer(offscreenFramebuffer); } } // Clear depth and stencil buffers. - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); + pgl.setClearColor(0, 0, 0, 0); + pgl.clearDepthAndStencilBuffers(); + //gl.glClearColor(0, 0, 0, 0); + //gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); drawing = true; @@ -1564,14 +1614,16 @@ public class PGraphicsOpenGL extends PGraphics { } // Restoring previous viewport. - gl.glViewport(savedViewport[0], savedViewport[1], savedViewport[2], savedViewport[3]); + //gl.glViewport(savedViewport[0], savedViewport[1], savedViewport[2], savedViewport[3]); + pgl.setViewport(savedViewport); if (primarySurface) { // glFlush should be called only once, since it is an expensive // operation. Thus, only the main renderer (the primary surface) // should call it at the end of draw, and none of the offscreen // renderers... - gl.glFlush(); + //gl.glFlush(); + pgl.flush(); if (drawable != null) { drawable.swapBuffers(); @@ -1599,7 +1651,7 @@ public class PGraphicsOpenGL extends PGraphics { // The user is free to change anything she wants, endGL will // try to do its best to restore things to the Processing // settings valid at the time of calling beginGL(). - return gl; // which one to return? + return pgl.gl; } @@ -1609,34 +1661,7 @@ public class PGraphicsOpenGL extends PGraphics { public void updateGLInterfaces() { - gl = context.getGL(); - - if (pipeline == PROG_GL4) { - gl4p = gl.getGL4(); - gl3p = gl4p; - gl2p = gl4p; - gl2f = null; - } else if (pipeline == PROG_GL3) { - gl4p = null; - gl3p = gl.getGL3(); - gl2p = gl3p; - gl2f = null; - } else if (pipeline == PROG_GL2) { - gl4p = null; - gl3p = null; - gl2p = gl.getGL2ES2(); - gl2f = null; - } else if (pipeline == FIXED) { - gl4p = null; - gl3p = null; - gl2p = null; - gl2f = gl.getGL2ES1(); - gl2 = gl.getGL2(); - } - - try { - gl2x = gl.getGL2GL3(); - } catch (GLException e) {} + pgl.update(context); } @@ -1645,25 +1670,32 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void restoreGLState() { + protected void restoreGLState() { // Restoring viewport. - gl.glViewport(0, 0, width, height); + pgl.setViewport(viewport); + //gl.glViewport(0, 0, width, height); restoreGLMatrices(); // Restoring hints. if (hints[DISABLE_DEPTH_TEST]) { - gl.glDisable(GL.GL_DEPTH_TEST); - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL.GL_DEPTH_BUFFER_BIT); + pgl.disableDepthTest(); + pgl.setClearColor(0, 0, 0, 0); + pgl.clearDepthBuffer(); +// gl.glDisable(GL.GL_DEPTH_TEST); +// gl.glClearColor(0, 0, 0, 0); +// gl.glClear(GL.GL_DEPTH_BUFFER_BIT); } else { - gl.glEnable(GL.GL_DEPTH_TEST); + //gl.glEnable(GL.GL_DEPTH_TEST); + pgl.enableDepthTest(); } if (hints[DISABLE_DEPTH_MASK]) { - gl.glDepthMask(false); + //gl.glDepthMask(false); + pgl.disableDepthMask(); } else { - gl.glDepthMask(true); + //gl.glDepthMask(true); + pgl.enableDepthMask(); } // Restoring blending. @@ -1745,9 +1777,11 @@ public class PGraphicsOpenGL extends PGraphics { // but we want to make sure they return to the Processing // defaults (plus these cannot be changed through the API // so they should remain constant anyways): - gl.glFrontFace(GL.GL_CW); - gl.glDepthFunc(GL.GL_LEQUAL); - + //gl.glFrontFace(GL.GL_CW); + pgl.setFrontFace(PGLJava.CLOCKWISE); + //gl.glDepthFunc(GL.GL_LEQUAL); + pgl.setDepthFunc(PGLJava.LESS_OR_EQUAL); + setSurfaceParams(); } @@ -1820,21 +1854,27 @@ public class PGraphicsOpenGL extends PGraphics { if (which == DISABLE_DEPTH_TEST) { flush(); - gl.glDisable(GL.GL_DEPTH_TEST); - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL.GL_DEPTH_BUFFER_BIT); + pgl.disableDepthTest(); + pgl.setClearColor(0, 0, 0, 0); + pgl.clearDepthBuffer(); +// gl.glDisable(GL.GL_DEPTH_TEST); +// gl.glClearColor(0, 0, 0, 0); +// gl.glClear(GL.GL_DEPTH_BUFFER_BIT); } else if (which == ENABLE_DEPTH_TEST) { flush(); - gl.glEnable(GL.GL_DEPTH_TEST); + //gl.glEnable(GL.GL_DEPTH_TEST); + pgl.enableDepthTest(); } else if (which == DISABLE_DEPTH_MASK) { flush(); - gl.glDepthMask(false); + //gl.glDepthMask(false); + pgl.disableDepthMask(); } else if (which == ENABLE_DEPTH_MASK) { flush(); - gl.glDepthMask(true); + //gl.glDepthMask(true); + pgl.enableDepthMask(); } else if (which == DISABLE_ACCURATE_2D) { flush(); @@ -2170,10 +2210,12 @@ public class PGraphicsOpenGL extends PGraphics { protected void clipImpl(float x1, float y1, float x2, float y2) { flush(); - gl.glEnable(GL.GL_SCISSOR_TEST); +// gl.glEnable(GL.GL_SCISSOR_TEST); + pgl.enableClipping(); float h = y2 - y1; - gl.glScissor((int)x1, (int)(height - y1 - h), (int)(x2 - x1), (int)h); +// gl.glScissor((int)x1, (int)(height - y1 - h), (int)(x2 - x1), (int)h); + pgl.setClipRect((int)x1, (int)(height - y1 - h), (int)(x2 - x1), (int)h); clip = true; } @@ -2182,7 +2224,8 @@ public class PGraphicsOpenGL extends PGraphics { public void noClip() { if (clip) { flush(); - gl.glDisable(GL.GL_SCISSOR_TEST); + //gl.glDisable(GL.GL_SCISSOR_TEST); + pgl.disableClipping(); clip = false; } @@ -2259,8 +2302,10 @@ public class PGraphicsOpenGL extends PGraphics { // The modelview transformation has been applied already to the // tessellated vertices, so we set the OpenGL modelview matrix as // the identity to avoid applying the model transformations twice. - gl2f.glPushMatrix(); - gl2f.glLoadIdentity(); + //gl2f.glPushMatrix(); + //gl2f.glLoadIdentity(); + pgl.pushMatrix(); + pgl.loadIdentity(); } if (hasFill) { @@ -2276,7 +2321,8 @@ public class PGraphicsOpenGL extends PGraphics { } if (flushMode == FLUSH_WHEN_FULL && !hints[DISABLE_TRANSFORM_CACHE]) { - gl2f.glPopMatrix(); + //gl2f.glPopMatrix(); + pgl.popMatrix(); } } @@ -2293,37 +2339,57 @@ public class PGraphicsOpenGL extends PGraphics { startPointShader(); - gl2f.glEnableClientState(GL2.GL_VERTEX_ARRAY); - gl2f.glEnableClientState(GL2.GL_COLOR_ARRAY); - gl2f.glEnableClientState(GL2.GL_NORMAL_ARRAY); + pgl.enableVertexArrays(); + pgl.enableColorArrays(); + pgl.enableNormalArrays(); +// gl2f.glEnableClientState(GL2.GL_VERTEX_ARRAY); +// gl2f.glEnableClientState(GL2.GL_COLOR_ARRAY); +// gl2f.glEnableClientState(GL2.GL_NORMAL_ARRAY); int size = tessGeo.pointVertexCount; - - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointVertices, 0, 3 * size), vboMode); - gl2f.glVertexPointer(3, GL.GL_FLOAT, 0, 0); - - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointColors, 0, 4 * size), vboMode); - gl2f.glColorPointer(4, GL.GL_FLOAT, 0, 0); - - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointNormals, 0, 3 * size), vboMode); - gl2f.glNormalPointer(GL.GL_FLOAT, 0, 0); + +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointVertices, 0, 3 * size), vboMode); +// gl2f.glVertexPointer(3, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(glPointVertexBufferID); + pgl.copyVertexBufferData(tessGeo.pointVertices, 3 * size, vboMode); + pgl.setVertexFormat(3, 0, 0); + +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointColors, 0, 4 * size), vboMode); +// gl2f.glColorPointer(4, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(glPointColorBufferID); + pgl.copyVertexBufferData(tessGeo.pointColors, 4 * size, vboMode); + pgl.setColorFormat(4, 0, 0); + +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.pointNormals, 0, 3 * size), vboMode); +// gl2f.glNormalPointer(GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(glPointNormalBufferID); + pgl.copyVertexBufferData(tessGeo.pointNormals, 3 * size, vboMode); + pgl.setNormalFormat(3, 0, 0); setupPointShader(glPointAttribBufferID, tessGeo.pointAttributes, size); size = tessGeo.pointIndexCount; - gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); - gl2f.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.pointIndices, 0, size), vboMode); - gl2f.glDrawElements(GL.GL_TRIANGLES, size, GL.GL_UNSIGNED_INT, 0); +// gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, glPointIndexBufferID); +// gl2f.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.pointIndices, 0, size), vboMode); +// gl2f.glDrawElements(GL.GL_TRIANGLES, size, GL.GL_UNSIGNED_INT, 0); + pgl.bindIndexBuffer(glPointIndexBufferID); + pgl.copyIndexBufferData(tessGeo.pointIndices, size, vboMode); + pgl.renderIndexBuffer(size); + + pgl.unbindIndexBuffer(); + pgl.unbindVertexBuffer(); + //gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - - gl2f.glDisableClientState(GL2.GL_VERTEX_ARRAY); - gl2f.glDisableClientState(GL2.GL_COLOR_ARRAY); - gl2f.glDisableClientState(GL2.GL_NORMAL_ARRAY); +// gl2f.glDisableClientState(GL2.GL_VERTEX_ARRAY); +// gl2f.glDisableClientState(GL2.GL_COLOR_ARRAY); +// gl2f.glDisableClientState(GL2.GL_NORMAL_ARRAY); + pgl.disableVertexArrays(); + pgl.disableColorArrays(); + pgl.disableNormalArrays(); stopPointShader(); } @@ -2336,37 +2402,58 @@ public class PGraphicsOpenGL extends PGraphics { startLineShader(); - gl2f.glEnableClientState(GL2.GL_VERTEX_ARRAY); - gl2f.glEnableClientState(GL2.GL_COLOR_ARRAY); - gl2f.glEnableClientState(GL2.GL_NORMAL_ARRAY); +// gl2f.glEnableClientState(GL2.GL_VERTEX_ARRAY); +// gl2f.glEnableClientState(GL2.GL_COLOR_ARRAY); +// gl2f.glEnableClientState(GL2.GL_NORMAL_ARRAY); + pgl.enableVertexArrays(); + pgl.enableColorArrays(); + pgl.enableNormalArrays(); int size = tessGeo.lineVertexCount; - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineVertices, 0, 3 * size), vboMode); - gl2f.glVertexPointer(3, GL.GL_FLOAT, 0, 0); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineVertices, 0, 3 * size), vboMode); +// gl2f.glVertexPointer(3, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(glLineVertexBufferID); + pgl.copyVertexBufferData(tessGeo.lineVertices, 3 * size, vboMode); + pgl.setVertexFormat(3, 0, 0); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineColors, 0, 4 * size), vboMode); - gl2f.glColorPointer(4, GL.GL_FLOAT, 0, 0); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineColors, 0, 4 * size), vboMode); +// gl2f.glColorPointer(4, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(glLineColorBufferID); + pgl.copyVertexBufferData(tessGeo.lineColors, 4 * size, vboMode); + pgl.setColorFormat(4, 0, 0); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineNormals, 0, 3 * size), vboMode); - gl2f.glNormalPointer(GL.GL_FLOAT, 0, 0); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.lineNormals, 0, 3 * size), vboMode); +// gl2f.glNormalPointer(GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(glLineNormalBufferID); + pgl.copyVertexBufferData(tessGeo.lineNormals, 3 * size, vboMode); + pgl.setNormalFormat(3, 0, 0); setupLineShader(glLineAttribBufferID, tessGeo.lineAttributes, size); size = tessGeo.lineIndexCount; - gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); - gl2f.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.lineIndices, 0, size), vboMode); - gl2f.glDrawElements(GL.GL_TRIANGLES, size, GL.GL_UNSIGNED_INT, 0); +// gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, glLineIndexBufferID); +// gl2f.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.lineIndices, 0, size), vboMode); +// gl2f.glDrawElements(GL.GL_TRIANGLES, size, GL.GL_UNSIGNED_INT, 0); + pgl.bindIndexBuffer(glLineIndexBufferID); + pgl.copyIndexBufferData(tessGeo.lineIndices, size, vboMode); + pgl.renderIndexBuffer(size); - gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - gl2f.glDisableClientState(GL2.GL_VERTEX_ARRAY); - gl2f.glDisableClientState(GL2.GL_COLOR_ARRAY); - gl2f.glDisableClientState(GL2.GL_NORMAL_ARRAY); +// gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); + pgl.unbindVertexBuffer(); + +// gl2f.glDisableClientState(GL2.GL_VERTEX_ARRAY); +// gl2f.glDisableClientState(GL2.GL_COLOR_ARRAY); +// gl2f.glDisableClientState(GL2.GL_NORMAL_ARRAY); + pgl.disableVertexArrays(); + pgl.disableColorArrays(); + pgl.disableNormalArrays(); stopLineShader(); } @@ -2378,33 +2465,51 @@ public class PGraphicsOpenGL extends PGraphics { fillVBOsCreated = true; } - gl2f.glEnableClientState(GL2.GL_VERTEX_ARRAY); - gl2f.glEnableClientState(GL2.GL_COLOR_ARRAY); - gl2f.glEnableClientState(GL2.GL_NORMAL_ARRAY); +// gl2f.glEnableClientState(GL2.GL_VERTEX_ARRAY); +// gl2f.glEnableClientState(GL2.GL_COLOR_ARRAY); +// gl2f.glEnableClientState(GL2.GL_NORMAL_ARRAY); + pgl.enableVertexArrays(); + pgl.enableColorArrays(); + pgl.enableNormalArrays(); int size = tessGeo.fillVertexCount; +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.fillVertices, 0, 3 * size), vboMode); +// gl2f.glVertexPointer(3, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(glFillVertexBufferID); + pgl.copyVertexBufferData(tessGeo.fillVertices, 3 * size, vboMode); + pgl.setVertexFormat(3, 0, 0); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.fillVertices, 0, 3 * size), vboMode); - gl2f.glVertexPointer(3, GL.GL_FLOAT, 0, 0); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.fillColors, 0, 4 * size), vboMode); +// gl2f.glColorPointer(4, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(glFillColorBufferID); + pgl.copyVertexBufferData(tessGeo.fillColors, 4 * size, vboMode); + pgl.setColorFormat(4, 0, 0); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.fillColors, 0, 4 * size), vboMode); - gl2f.glColorPointer(4, GL.GL_FLOAT, 0, 0); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.fillNormals, 0, 3 * size), vboMode); +// gl2f.glNormalPointer(GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(glFillNormalBufferID); + pgl.copyVertexBufferData(tessGeo.fillNormals, 3 * size, vboMode); + pgl.setNormalFormat(3, 0, 0); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.fillNormals, 0, 3 * size), vboMode); - gl2f.glNormalPointer(GL.GL_FLOAT, 0, 0); - if (texCache.hasTexture) { - gl2f.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.fillTexcoords, 0, 2 * size), vboMode); - gl2f.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0); +// gl2f.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(tessGeo.fillTexcoords, 0, 2 * size), vboMode); +// gl2f.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0); + pgl.enableTexCoordArrays(); + pgl.bindVertexBuffer(glFillTexCoordBufferID); + pgl.copyVertexBufferData(tessGeo.fillTexcoords, 2 * size, vboMode); + pgl.setTexCoordFormat(2, 0, 0); } - gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, glFillIndexBufferID); - + //gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, glFillIndexBufferID); + pgl.bindIndexBuffer(glFillIndexBufferID); + + pgl.setActiveTexUnit(0); + PTexture tex0 = null; for (int i = 0; i < texCache.count; i++) { PImage img = texCache.textures[i]; @@ -2413,49 +2518,131 @@ public class PGraphicsOpenGL extends PGraphics { if (img != null) { tex = ogl.getTexture(img); if (tex != null) { - gl2f.glEnable(tex.glTarget); - gl2f.glActiveTexture(GL.GL_TEXTURE0); - gl2f.glBindTexture(tex.glTarget, tex.glID); +// gl2f.glEnable(tex.glTarget); +// gl2f.glActiveTexture(GL.GL_TEXTURE0); +// gl2f.glBindTexture(tex.glTarget, tex.glID); + tex.bind(); +// pgl.enableTexturing(tex.glTarget); +// pgl.bindTexture(tex.glTarget, tex.glID); tex0 = tex; } } if (tex == null && tex0 != null) { - gl2f.glDisable(tex0.glTarget); + //gl2f.glDisable(tex0.glTarget); + tex0.unbind(); + pgl.disableTexturing(tex0.glTarget); } int offset = texCache.firstIndex[i]; size = texCache.lastIndex[i] - texCache.firstIndex[i] + 1; - gl2f.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.fillIndices, offset, size), vboMode); - gl2f.glDrawElements(GL.GL_TRIANGLES, size, GL.GL_UNSIGNED_INT, 0); + pgl.copyIndexBufferData(tessGeo.fillIndices, offset, size, vboMode); + pgl.renderIndexBuffer(size); + //gl2f.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(tessGeo.fillIndices, offset, size), vboMode); + //gl2f.glDrawElements(GL.GL_TRIANGLES, size, GL.GL_UNSIGNED_INT, 0); } if (texCache.hasTexture) { - tex0 = null; + //tex0 = null; + + // Unbinding all the textures in the cache. for (int i = 0; i < texCache.count; i++) { PImage img = texCache.textures[i]; if (img != null) { PTexture tex = ogl.getTexture(img); - if (tex0 != tex) { - gl2f.glDisable(tex.glTarget); - tex0 = tex; - } + if (tex != null) { + tex.unbind(); + } + + //if (tex0 != tex) { + //gl2f.glDisable(tex.glTarget); + //pgl.disableTexturing(tex.glTarget); + //tex0 = tex; + + //} } } - if (tex0 != null) { - gl2f.glActiveTexture(GL.GL_TEXTURE0); - gl2f.glBindTexture(tex0.glTarget, 0); - } - gl2f.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); +// if (tex0 != null) { +// gl2f.glActiveTexture(GL.GL_TEXTURE0); +// gl2f.glBindTexture(tex0.glTarget, 0); +// } + // Disabling texturing for each of the targets used + // by textures in the cache. + for (int i = 0; i < texCache.count; i++) { + PImage img = texCache.textures[i]; + if (img != null) { + PTexture tex = ogl.getTexture(img); + if (tex != null) { + pgl.disableTexturing(tex.glTarget); + } + //if (tex0 != tex) { + //gl2f.glDisable(tex.glTarget); + //pgl.disableTexturing(tex.glTarget); + //tex0 = tex; + + //} + } + } + + //gl2f.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + pgl.disableTexCoordArrays(); } - gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// gl2f.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); + pgl.unbindVertexBuffer(); - gl2f.glDisableClientState(GL2.GL_VERTEX_ARRAY); - gl2f.glDisableClientState(GL2.GL_COLOR_ARRAY); - gl2f.glDisableClientState(GL2.GL_NORMAL_ARRAY); +// gl2f.glDisableClientState(GL2.GL_VERTEX_ARRAY); +// gl2f.glDisableClientState(GL2.GL_COLOR_ARRAY); +// gl2f.glDisableClientState(GL2.GL_NORMAL_ARRAY); + pgl.disableVertexArrays(); + pgl.disableColorArrays(); + pgl.disableNormalArrays(); } + + // Utility function to render current tessellated geometry, under the assumption that + // the texture is already bound. + protected void renderTexFill() { + if (!fillVBOsCreated) { + createFillBuffers(); + fillVBOsCreated = true; + } + pgl.enableVertexArrays(); + pgl.enableColorArrays(); + pgl.enableNormalArrays(); + pgl.enableTexCoordArrays(); + + int size = tessGeo.fillVertexCount; + pgl.bindVertexBuffer(glFillVertexBufferID); + pgl.copyVertexBufferData(tessGeo.fillVertices, 3 * size, vboMode); + pgl.setVertexFormat(3, 0, 0); + + pgl.bindVertexBuffer(glFillColorBufferID); + pgl.copyVertexBufferData(tessGeo.fillColors, 4 * size, vboMode); + pgl.setColorFormat(4, 0, 0); + + pgl.bindVertexBuffer(glFillNormalBufferID); + pgl.copyVertexBufferData(tessGeo.fillNormals, 3 * size, vboMode); + pgl.setNormalFormat(3, 0, 0); + + pgl.bindVertexBuffer(glFillTexCoordBufferID); + pgl.copyVertexBufferData(tessGeo.fillTexcoords, 2 * size, vboMode); + pgl.setTexCoordFormat(2, 0, 0); + + size = tessGeo.fillIndexCount; + pgl.bindIndexBuffer(glFillIndexBufferID); + pgl.copyIndexBufferData(tessGeo.fillIndices, size, vboMode); + pgl.renderIndexBuffer(size); + + pgl.unbindIndexBuffer(); + pgl.unbindVertexBuffer(); + + pgl.disableTexCoordArrays(); + pgl.disableVertexArrays(); + pgl.disableColorArrays(); + pgl.disableNormalArrays(); + } protected void startLineShader() { if (lineShader == null) { @@ -2470,40 +2657,49 @@ public class PGraphicsOpenGL extends PGraphics { protected void setupLineShader(int attrBufID, float[] attribs, int nvert) { - int[] viewport = {0, 0, 0, 0}; - gl2f.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); + int[] viewport = {0, 0, 0, 0}; + //gl2f.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); lineShader.setVecUniform("viewport", viewport[0], viewport[1], viewport[2], viewport[3]); lineShader.setIntUniform("lights", lightCount); lineShader.setVecUniform("eye", cameraEyeX, cameraEyeY, cameraEyeZ, 0); - lineAttribsID = lineShader.getAttribLocation("attribs"); - gl2x.glEnableVertexAttribArray(lineAttribsID); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs, 0, 4 * nvert), vboMode); - gl2x.glVertexAttribPointer(lineAttribsID, 4, GL.GL_FLOAT, false, 0, 0); + lineAttribsLoc = lineShader.getAttribLocation("attribs"); + +// gl2x.glEnableVertexAttribArray(lineAttribsLoc); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs, 0, 4 * nvert), vboMode); +// gl2x.glVertexAttribPointer(lineAttribsLoc, 4, GL.GL_FLOAT, false, 0, 0); + pgl.enableAttribsArray(lineAttribsLoc); + pgl.bindVertexBuffer(attrBufID); + pgl.copyVertexBufferData(attribs, 4 * nvert, vboMode); + pgl.setAttribsFormat(lineAttribsLoc, 4, 0, 0); } protected void setupLineShader(int attrBufID) { int[] viewport = {0, 0, 0, 0}; - gl2f.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); + //gl2f.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); lineShader.setVecUniform("viewport", viewport[0], viewport[1], viewport[2], viewport[3]); lineShader.setIntUniform("lights", lightCount); lineShader.setVecUniform("eye", cameraEyeX, cameraEyeY, cameraEyeZ, 0); - lineAttribsID = lineShader.getAttribLocation("attribs"); - gl2x.glEnableVertexAttribArray(lineAttribsID); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID); - gl2x.glVertexAttribPointer(lineAttribsID, 4, GL.GL_FLOAT, false, 0, 0); + lineAttribsLoc = lineShader.getAttribLocation("attribs"); + //gl2x.glEnableVertexAttribArray(lineAttribsID); + //gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID); + //gl2x.glVertexAttribPointer(lineAttribsID, 4, GL.GL_FLOAT, false, 0, 0); + pgl.enableAttribsArray(lineAttribsLoc); + pgl.bindVertexBuffer(attrBufID); + pgl.setAttribsFormat(lineAttribsLoc, 4, 0, 0); } protected void stopLineShader() { - gl2x.glDisableVertexAttribArray(lineAttribsID); + //gl2x.glDisableVertexAttribArray(lineAttribsLoc); + pgl.disableAttribsArray(lineAttribsLoc); lineShader.stop(); } @@ -2525,11 +2721,15 @@ public class PGraphicsOpenGL extends PGraphics { pointShader.setVecUniform("eye", cameraEyeX, cameraEyeY, cameraEyeZ, 0); - pointAttribsID = PGraphicsOpenGL.pointShader.getAttribLocation("vertDisp"); - gl2x.glEnableVertexAttribArray(pointAttribsID); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID); - gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 2 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs, 0, 2 * nvert), vboMode); - ogl.gl2x.glVertexAttribPointer(pointAttribsID, 2, GL.GL_FLOAT, false, 0, 0); + pointAttribsLoc = PGraphicsOpenGL.pointShader.getAttribLocation("vertDisp"); +// gl2x.glEnableVertexAttribArray(pointAttribsID); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID); +// gl2f.glBufferData(GL.GL_ARRAY_BUFFER, 2 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs, 0, 2 * nvert), vboMode); +// ogl.gl2x.glVertexAttribPointer(pointAttribsID, 2, GL.GL_FLOAT, false, 0, 0); + pgl.enableAttribsArray(pointAttribsLoc); + pgl.bindVertexBuffer(attrBufID); + pgl.copyVertexBufferData(attribs, 2 * nvert, vboMode); + pgl.setAttribsFormat(pointAttribsLoc, 2, 0, 0); } @@ -2538,15 +2738,19 @@ public class PGraphicsOpenGL extends PGraphics { pointShader.setVecUniform("eye", cameraEyeX, cameraEyeY, cameraEyeZ, 0); - pointAttribsID = PGraphicsOpenGL.pointShader.getAttribLocation("vertDisp"); - gl2x.glEnableVertexAttribArray(pointAttribsID); - gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID); - ogl.gl2x.glVertexAttribPointer(pointAttribsID, 2, GL.GL_FLOAT, false, 0, 0); + pointAttribsLoc = PGraphicsOpenGL.pointShader.getAttribLocation("vertDisp"); +// gl2x.glEnableVertexAttribArray(pointAttribsID); +// gl2f.glBindBuffer(GL.GL_ARRAY_BUFFER, attrBufID); +// ogl.gl2x.glVertexAttribPointer(pointAttribsID, 2, GL.GL_FLOAT, false, 0, 0); + pgl.enableAttribsArray(pointAttribsLoc); + pgl.bindVertexBuffer(attrBufID); + pgl.setAttribsFormat(pointAttribsLoc, 2, 0, 0); } protected void stopPointShader() { - gl2x.glDisableVertexAttribArray(pointAttribsID); + //gl2x.glDisableVertexAttribArray(pointAttribsID); + pgl.disableAttribsArray(pointAttribsLoc); pointShader.stop(); } @@ -3088,17 +3292,21 @@ public class PGraphicsOpenGL extends PGraphics { } int[] temp = { 0 }; - gl.glGetIntegerv(GL.GL_SAMPLES, temp, 0); + pgl.getNumSamples(temp); if (antialias != temp[0]) { antialias = temp[0]; PApplet.println("Effective multisampling level: " + antialias); } if (antialias < 2) { - gl2f.glEnable(GL2.GL_MULTISAMPLE); - gl2f.glEnable(GL2.GL_POINT_SMOOTH); - gl2f.glEnable(GL2.GL_LINE_SMOOTH); - gl2f.glEnable(GL2.GL_POLYGON_SMOOTH); + pgl.enableMultisample(); + pgl.enablePointSmooth(); + pgl.enableLineSmooth(); + pgl.enablePolygonSmooth(); +// gl2f.glEnable(GL2.GL_MULTISAMPLE); +// gl2f.glEnable(GL2.GL_POINT_SMOOTH); +// gl2f.glEnable(GL2.GL_LINE_SMOOTH); +// gl2f.glEnable(GL2.GL_POLYGON_SMOOTH); } } @@ -3116,10 +3324,14 @@ public class PGraphicsOpenGL extends PGraphics { } } - gl2f.glDisable(GL2.GL_MULTISAMPLE); - gl2f.glDisable(GL2.GL_POINT_SMOOTH); - gl2f.glDisable(GL.GL_LINE_SMOOTH); - gl2f.glDisable(GL2.GL_POLYGON_SMOOTH); +// gl2f.glDisable(GL2.GL_MULTISAMPLE); +// gl2f.glDisable(GL2.GL_POINT_SMOOTH); +// gl2f.glDisable(GL.GL_LINE_SMOOTH); +// gl2f.glDisable(GL2.GL_POLYGON_SMOOTH); + pgl.disableMultisample(); + pgl.disablePointSmooth(); + pgl.disableLineSmooth(); + pgl.disablePolygonSmooth(); } ////////////////////////////////////////////////////////////// @@ -3304,7 +3516,8 @@ public class PGraphicsOpenGL extends PGraphics { public void pushMatrix() { - gl2f.glPushMatrix(); + //gl2f.glPushMatrix(); + pgl.pushMatrix(); modelviewStack.push(new PMatrix3D(modelview)); } @@ -3313,7 +3526,8 @@ public class PGraphicsOpenGL extends PGraphics { if (hints[DISABLE_TRANSFORM_CACHE]) { flush(); } - gl2f.glPopMatrix(); + //gl2f.glPopMatrix(); + pgl.popMatrix(); PMatrix3D mat = modelviewStack.pop(); modelview.set(mat); } @@ -3334,7 +3548,8 @@ public class PGraphicsOpenGL extends PGraphics { flush(); } - gl2f.glTranslatef(tx, ty, tz); + //gl2f.glTranslatef(tx, ty, tz); + pgl.translate(tx, ty, tz); modelview.translate(tx, ty, tz); } @@ -3374,7 +3589,8 @@ public class PGraphicsOpenGL extends PGraphics { flush(); } - gl2f.glRotatef(PApplet.degrees(angle), v0, v1, v2); + //gl2f.glRotatef(PApplet.degrees(angle), v0, v1, v2); + pgl.rotate(angle, v0, v1, v2); modelview.rotate(angle, v0, v1, v2); } @@ -3403,7 +3619,8 @@ public class PGraphicsOpenGL extends PGraphics { flush(); } - gl2f.glScalef(sx, sy, sz); + //gl2f.glScalef(sx, sy, sz); + pgl.scale(sx, sy, sz); modelview.scale(sx, sy, sz); } @@ -3432,7 +3649,8 @@ public class PGraphicsOpenGL extends PGraphics { public void resetMatrix() { - gl2f.glLoadIdentity(); + //gl2f.glLoadIdentity(); + pgl.loadIdentity(); modelview.reset(); } @@ -3477,7 +3695,8 @@ public class PGraphicsOpenGL extends PGraphics { glMatrix[ 2] = n20; glMatrix[ 6] = n21; glMatrix[10] = n22; glMatrix[14] = n23; glMatrix[ 3] = n30; glMatrix[ 7] = n31; glMatrix[11] = n32; glMatrix[15] = n33; - gl2f.glMultMatrixf(glMatrix, 0); + //gl2f.glMultMatrixf(glMatrix, 0); + pgl.multMatrix(glMatrix); modelview.apply(n00, n01, n02, n03, n10, n11, n12, n13, @@ -3487,20 +3706,24 @@ public class PGraphicsOpenGL extends PGraphics { protected void loadProjection() { - gl2f.glMatrixMode(GL2.GL_PROJECTION); + pgl.setProjectionMode(); + //gl2f.glMatrixMode(GL2.GL_PROJECTION); loadMatrix(projection); - gl2f.glMatrixMode(GL2.GL_MODELVIEW); + //gl2f.glMatrixMode(GL2.GL_MODELVIEW); + pgl.setModelviewMode(); } protected void loadCamera() { - gl2f.glMatrixMode(GL2.GL_MODELVIEW); + //gl2f.glMatrixMode(GL2.GL_MODELVIEW); + pgl.setModelviewMode(); loadMatrix(camera); } protected void loadModelview() { - gl2f.glMatrixMode(GL2.GL_MODELVIEW); + //gl2f.glMatrixMode(GL2.GL_MODELVIEW); + pgl.setModelviewMode(); loadMatrix(modelview); } @@ -3511,7 +3734,8 @@ public class PGraphicsOpenGL extends PGraphics { glMatrix[ 2] = pMatrix.m20; glMatrix[ 6] = pMatrix.m21; glMatrix[10] = pMatrix.m22; glMatrix[14] = pMatrix.m23; glMatrix[ 3] = pMatrix.m30; glMatrix[ 7] = pMatrix.m31; glMatrix[11] = pMatrix.m32; glMatrix[15] = pMatrix.m33; - gl2f.glLoadMatrixf(glMatrix, 0); + //gl2f.glLoadMatrixf(glMatrix, 0); + pgl.loadMatrix(glMatrix); } @@ -3561,19 +3785,25 @@ public class PGraphicsOpenGL extends PGraphics { public void pushProjection() { - gl2f.glMatrixMode(GL2.GL_PROJECTION); - gl2f.glPushMatrix(); + pgl.setProjectionMode(); + pgl.pushMatrix(); + //gl2f.glMatrixMode(GL2.GL_PROJECTION); + //gl2f.glPushMatrix(); projectionStack.push(new PMatrix3D(projection)); - gl2f.glMatrixMode(GL2.GL_MODELVIEW); + //gl2f.glMatrixMode(GL2.GL_MODELVIEW); + pgl.setModelviewMode(); } public void popProjection() { - gl2f.glMatrixMode(GL2.GL_PROJECTION); - gl2f.glPopMatrix(); + //gl2f.glMatrixMode(GL2.GL_PROJECTION); + pgl.setProjectionMode(); + pgl.popMatrix(); + //gl2f.glPopMatrix(); PMatrix3D mat = projectionStack.pop(); projection.set(mat); - gl2f.glMatrixMode(GL2.GL_MODELVIEW); + //gl2f.glMatrixMode(GL2.GL_MODELVIEW); + pgl.setModelviewMode(); } @@ -4173,11 +4403,13 @@ public class PGraphicsOpenGL extends PGraphics { } protected void setFillColor() { - gl2f.glColor4f(fillR, fillG, fillB, fillA); + pgl.setColor(fillR, fillG, fillB, fillA); + //gl2f.glColor4f(fillR, fillG, fillB, fillA); } protected void setTintColor() { - gl2f.glColor4f(tintR, tintG, tintB, tintA); + pgl.setColor(tintR, tintG, tintB, tintA); + //gl2f.glColor4f(tintR, tintG, tintB, tintA); } ////////////////////////////////////////////////////////////// @@ -4208,7 +4440,10 @@ public class PGraphicsOpenGL extends PGraphics { // OPENGL uses GL_COLOR_MATERIAL mode, so the ambient and diffuse components // for all vertices are taken from the glColor/color buffer settings. - gl2f.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, colorFloats, 0); + //gl2f.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, colorFloats, 0); + + pgl.setMaterialAmbient(colorFloats); + } // public void specular(int rgb) { @@ -4232,12 +4467,14 @@ public class PGraphicsOpenGL extends PGraphics { protected void specularFromCalc() { super.specularFromCalc(); calcColorBuffer(); - gl2f.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, colorFloats, 0); + //gl2f.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, colorFloats, 0); + pgl.setMaterialSpecular(colorFloats); } public void shininess(float shine) { super.shininess(shine); - gl2f.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, shine); + //gl2f.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, shine); + pgl.setMaterialShininess(shine); } // public void emissive(int rgb) { @@ -4261,7 +4498,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void emissiveFromCalc() { super.emissiveFromCalc(); calcColorBuffer(); - gl2f.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_EMISSION, colorFloats, 0); + //gl2f.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_EMISSION, colorFloats, 0); + pgl.setMaterialEmission(colorFloats); } ////////////////////////////////////////////////////////////// @@ -4594,7 +4832,8 @@ public class PGraphicsOpenGL extends PGraphics { flush(); lights = true; - gl2f.glEnable(GL2.GL_LIGHTING); + //gl2f.glEnable(GL2.GL_LIGHTING); + pgl.enableLighting(); } } @@ -4604,79 +4843,94 @@ public class PGraphicsOpenGL extends PGraphics { flush(); lights = false; - gl2f.glDisable(GL2.GL_LIGHTING); + //gl2f.glDisable(GL2.GL_LIGHTING); + pgl.disableLighting(); } } protected void lightAmbient(int num) { - gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_AMBIENT, lightDiffuse[num], 0); + //gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_AMBIENT, lightDiffuse[num], 0); + pgl.setAmbientLight(num, lightDiffuse[num]); + } protected void lightNoAmbient(int num) { - gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_AMBIENT, zeroLight, 0); + //gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_AMBIENT, zeroLight, 0); + pgl.setAmbientLight(num, zeroLight); } protected void lightNoSpot(int num) { - gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_CUTOFF, 180); - gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_EXPONENT, 0); + pgl.setSpotLightCutoff(num, 180); + pgl.setSpotLightExponent(num, 0); +// gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_CUTOFF, 180); +// gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_EXPONENT, 0); } protected void lightDiffuse(int num) { - gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_DIFFUSE, lightDiffuse[num], 0); + pgl.setDiffuseLight(num, lightDiffuse[num]); +// gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_DIFFUSE, lightDiffuse[num], 0); } protected void lightNoDiffuse(int num) { - gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_DIFFUSE, zeroLight, 0); + //gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_DIFFUSE, zeroLight, 0); + pgl.setDiffuseLight(num, zeroLight); } protected void lightDirection(int num) { if (lightType[num] == DIRECTIONAL) { - // The w component of lightNormal[num] is zero, so the light is considered as - // a directional source because the position effectively becomes a direction - // in homogeneous coordinates: - // http://glprogramming.com/red/appendixf.html - gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_POSITION, lightNormal[num], 0); +// gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_POSITION, lightNormal[num], 0); + pgl.setLightDirection(num, lightNormal[num]); + } else { // spotlight - gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_DIRECTION, lightNormal[num], 0); + pgl.setSpotLightDirection(num, lightNormal[num]); + //gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_DIRECTION, lightNormal[num], 0); } } protected void lightEnable(int num) { - gl2f.glEnable(GL2.GL_LIGHT0 + num); +// gl2f.glEnable(GL2.GL_LIGHT0 + num); + pgl.enableLight(num); } protected void lightDisable(int num) { - gl2f.glDisable(GL2.GL_LIGHT0 + num); + //gl2f.glDisable(GL2.GL_LIGHT0 + num); + pgl.disableLight(num); } protected void lightFalloff(int num) { - gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_CONSTANT_ATTENUATION, - lightFalloffConstant[num]); - gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_LINEAR_ATTENUATION, - lightFalloffLinear[num]); - gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_QUADRATIC_ATTENUATION, - lightFalloffQuadratic[num]); + pgl.setLightConstantAttenuation(num, lightFalloffConstant[num]); + pgl.setLightLinearAttenuation(num, lightFalloffLinear[num]); + pgl.setLightQuadraticAttenuation(num, lightFalloffQuadratic[num]); + +// gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_CONSTANT_ATTENUATION, lightFalloffConstant[num]); +// gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_LINEAR_ATTENUATION, lightFalloffLinear[num]); +// gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_QUADRATIC_ATTENUATION, lightFalloffQuadratic[num]); } protected void lightPosition(int num) { - gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_POSITION, lightPosition[num], 0); + pgl.setLightPosition(num, lightPosition[num]); +// gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_POSITION, lightPosition[num], 0); } protected void lightSpecular(int num) { - gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_SPECULAR, lightSpecular[num], 0); + pgl.setSpecularLight(num, lightSpecular[num]); +// gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_SPECULAR, lightSpecular[num], 0); } protected void lightNoSpecular(int num) { - gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_SPECULAR, zeroLight, 0); +// gl2f.glLightfv(GL2.GL_LIGHT0 + num, GL2.GL_SPECULAR, zeroLight, 0); + pgl.setSpecularLight(num, zeroLight); } protected void lightSpotAngle(int num) { - gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_CUTOFF, lightSpotAngle[num]); + pgl.setSpotLightCutoff(num, lightSpotAngle[num]); + //gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_CUTOFF, lightSpotAngle[num]); + } protected void lightSpotConcentration(int num) { - gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_EXPONENT, - lightSpotConcentration[num]); + pgl.setSpotLightExponent(num, lightSpotConcentration[num]); + //gl2f.glLightf(GL2.GL_LIGHT0 + num, GL2.GL_SPOT_EXPONENT, lightSpotConcentration[num]); } ////////////////////////////////////////////////////////////// @@ -4692,11 +4946,15 @@ public class PGraphicsOpenGL extends PGraphics { tessGeo.reset(); texCache.reset(); - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL.GL_DEPTH_BUFFER_BIT); + pgl.setClearColor(0, 0, 0, 0); + pgl.clearDepthBuffer(); + //gl.glClearColor(0, 0, 0, 0); + //gl.glClear(GL.GL_DEPTH_BUFFER_BIT); - gl.glClearColor(backgroundR, backgroundG, backgroundB, 1); - gl.glClear(GL.GL_COLOR_BUFFER_BIT); + //gl.glClearColor(backgroundR, backgroundG, backgroundB, 1); + //gl.glClear(GL.GL_COLOR_BUFFER_BIT); + pgl.setClearColor(backgroundR, backgroundG, backgroundB, 1); + pgl.clearColorBuffer(); } ////////////////////////////////////////////////////////////// @@ -4764,9 +5022,11 @@ public class PGraphicsOpenGL extends PGraphics { */ public void report(String where) { if (!hints[DISABLE_OPENGL_ERROR_REPORT]) { - int err = gl.glGetError(); + //int err = gl.glGetError(); + int err = pgl.getError(); if (err != 0) { - String errString = glu.gluErrorString(err); + //String errString = glu.gluErrorString(err); + String errString = pgl.getErrorString(err); String msg = "OpenGL error " + err + " at " + where + ": " + errString; PGraphics.showWarning(msg); } @@ -4831,8 +5091,12 @@ public class PGraphicsOpenGL extends PGraphics { } pixelBuffer.rewind(); - if (primarySurface) gl2x.glReadBuffer(GL.GL_FRONT); - gl.glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelBuffer); + if (primarySurface) { + pgl.setReadBuffer(PGLJava.FRONT); +// gl2x.glReadBuffer(GL.GL_FRONT); + } + pgl.readPixels(pixelBuffer, 0, 0, width, height); +// gl.glReadPixels(0, 0, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelBuffer); if (notCurrent) { popFramebuffer(); @@ -5223,7 +5487,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void copyFrameToTexture() { // Make sure that the execution off all the openGL commands is // finished before loading the texture. - gl.glFinish(); + //gl.glFinish(); + pgl.finish(); loadTexture(); } @@ -5270,8 +5535,12 @@ public class PGraphicsOpenGL extends PGraphics { } getsetBuffer.rewind(); - if (primarySurface) gl2x.glReadBuffer(GL.GL_FRONT); - gl.glReadPixels(x, height - y - 1, 1, 1, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, getsetBuffer); + if (primarySurface) { +// gl2x.glReadBuffer(GL.GL_FRONT); + pgl.setReadBuffer(PGLJava.FRONT); + } + //gl.glReadPixels(x, height - y - 1, 1, 1, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, getsetBuffer); + pgl.readPixels(getsetBuffer, x, height - y - 1, 1, 1); if (notCurrent) { popFramebuffer(); @@ -5308,8 +5577,12 @@ public class PGraphicsOpenGL extends PGraphics { } newbieBuffer.rewind(); - if (primarySurface) gl2x.glReadBuffer(GL.GL_FRONT); - gl.glReadPixels(x, height - y - h, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, newbieBuffer); + if (primarySurface) { +// gl2x.glReadBuffer(GL.GL_FRONT); + pgl.setReadBuffer(PGLJava.FRONT); + } +// gl.glReadPixels(x, height - y - h, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, newbieBuffer); + pgl.readPixels(newbieBuffer, x, height - y - h, w, h); if (notCurrent) { popFramebuffer(); @@ -5515,51 +5788,88 @@ public class PGraphicsOpenGL extends PGraphics { flush(); blendMode = mode; - gl.glEnable(GL.GL_BLEND); +// gl.glEnable(GL.GL_BLEND); + pgl.enableBlend(); + if (mode == REPLACE) { // This is equivalent to disable blending. - if (blendEqSupported) gl.glBlendEquation(GL.GL_FUNC_ADD); - gl.glBlendFunc(GL.GL_ONE, GL.GL_ZERO); + if (blendEqSupported) { + pgl.setBlendEquation(PGLJava.BLEND_EQ_ADD); + //gl.glBlendEquation(GL.GL_FUNC_ADD); + } + //gl.glBlendFunc(GL.GL_ONE, GL.GL_ZERO); + pgl.setReplaceBlend(); } else if (mode == BLEND) { - if (blendEqSupported) gl.glBlendEquation(GL.GL_FUNC_ADD); - gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + if (blendEqSupported) { + //gl.glBlendEquation(GL.GL_FUNC_ADD); + pgl.setBlendEquation(PGLJava.BLEND_EQ_ADD); + } + //gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + pgl.setDefaultBlend(); } else if (mode == ADD) { - if (blendEqSupported) gl.glBlendEquation(GL.GL_FUNC_ADD); - gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); + if (blendEqSupported) { + //gl.glBlendEquation(GL.GL_FUNC_ADD); + pgl.setBlendEquation(PGLJava.BLEND_EQ_ADD); + } + //gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); + pgl.setAdditiveBlend(); } else if (mode == SUBTRACT) { - if (blendEqSupported) gl.glBlendEquation(GL.GL_FUNC_ADD); - gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ZERO); + if (blendEqSupported) { + //gl.glBlendEquation(GL.GL_FUNC_ADD); + pgl.setBlendEquation(PGLJava.BLEND_EQ_ADD); + } + //gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ZERO); + pgl.setSubstractiveBlend(); } else if (mode == LIGHTEST) { if (blendEqSupported) { - gl.glBlendEquation(GL2.GL_MAX); - gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_DST_ALPHA); + //gl.glBlendEquation(GL2.GL_MAX); + //gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_DST_ALPHA); + pgl.setBlendEquation(PGLJava.BLEND_EQ_MAX); + pgl.setLightestBlend(); } else { PGraphics.showWarning("P3D: This blend mode is currently unsupported."); } } else if (mode == DARKEST) { if (blendEqSupported) { - gl.glBlendEquation(GL2.GL_MIN); - gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_DST_ALPHA); + //gl.glBlendEquation(GL2.GL_MIN); + //gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_DST_ALPHA); + pgl.setBlendEquation(PGLJava.BLEND_EQ_MIN); + pgl.setDarkestBlend(); } else { PGraphics.showWarning("P3D: This blend mode is currently unsupported."); } } else if (mode == DIFFERENCE) { if (blendEqSupported) { - gl.glBlendEquation(GL.GL_FUNC_REVERSE_SUBTRACT); - gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE); + //gl.glBlendEquation(GL.GL_FUNC_REVERSE_SUBTRACT); + //gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE); + pgl.setBlendEquation(PGLJava.BLEND_EQ_REVERSE_SUBTRACT); + pgl.setDifferenceBlend(); + } else { PGraphics.showWarning("P3D: This blend mode is currently unsupported."); } } else if (mode == EXCLUSION) { - if (blendEqSupported) gl.glBlendEquation(GL.GL_FUNC_ADD); - gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE_MINUS_SRC_COLOR); + if (blendEqSupported) { + //gl.glBlendEquation(GL.GL_FUNC_ADD); + pgl.setBlendEquation(PGLJava.BLEND_EQ_ADD); + } + //gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE_MINUS_SRC_COLOR); + pgl.setExclussionBlend(); } else if (mode == MULTIPLY) { - if (blendEqSupported) gl.glBlendEquation(GL.GL_FUNC_ADD); - gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_SRC_COLOR); + if (blendEqSupported) { + //gl.glBlendEquation(GL.GL_FUNC_ADD); + pgl.setBlendEquation(PGLJava.BLEND_EQ_ADD); + } + //gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_SRC_COLOR); + pgl.setMultiplyBlend(); } else if (mode == SCREEN) { - if (blendEqSupported) gl.glBlendEquation(GL.GL_FUNC_ADD); - gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE); + if (blendEqSupported) { + //gl.glBlendEquation(GL.GL_FUNC_ADD); + pgl.setBlendEquation(PGLJava.BLEND_EQ_ADD); + } +// gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE); + pgl.setScreenBlend(); } // HARD_LIGHT, SOFT_LIGHT, OVERLAY, DODGE, BURN modes cannot be implemented // in fixed-function pipeline because they require conditional blending and @@ -5569,9 +5879,14 @@ public class PGraphicsOpenGL extends PGraphics { protected void setDefaultBlend() { blendMode = BLEND; - gl.glEnable(GL.GL_BLEND); - if (blendEqSupported) gl.glBlendEquation(GL.GL_FUNC_ADD); - gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + //gl.glEnable(GL.GL_BLEND); + pgl.enableBlend(); + if (blendEqSupported) { + //gl.glBlendEquation(GL.GL_FUNC_ADD); + pgl.setBlendEquation(PGLJava.BLEND_EQ_ADD); + } + //gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + pgl.setDefaultBlend(); } @@ -5711,25 +6026,32 @@ public class PGraphicsOpenGL extends PGraphics { } - /** Utility function to render texture wihtout blend. */ + /** Utility function to render texture without blend. */ protected void drawTexture(int target, int id, int tw, int th, int[] crop, int x, int y, int w, int h) { - gl.glEnable(target); - gl.glBindTexture(target, id); +// gl.glEnable(target); +// gl.glBindTexture(target, id); + pgl.enableTexturing(target); + pgl.bindTexture(target, id); int savedBlendMode = blendMode; blendMode(REPLACE); // The texels of the texture replace the color of wherever is on the screen. - gl2f.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); +// gl2f.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); + pgl.setTexEnvironmentMode(PGLJava.REPLACE); + drawTexture(tw, th, crop, x, y, w, h); // Returning to the default texture environment mode, GL_MODULATE. This allows tinting a texture // with the current fragment color. - gl2f.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE); +// gl2f.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE); + pgl.setTexEnvironmentMode(PGLJava.MODULATE); - gl.glBindTexture(target, 0); - gl.glDisable(target); +// gl.glBindTexture(target, 0); +// gl.glDisable(target); + pgl.unbindTexture(target); + pgl.disableTexturing(target); blendMode(savedBlendMode); } @@ -5747,20 +6069,21 @@ public class PGraphicsOpenGL extends PGraphics { * in OpenGL ES. */ protected void drawTexture(int tw, int th, int[] crop, int x, int y, int w, int h) { - gl.glDepthMask(false); - - gl2f.glMatrixMode(GL2.GL_PROJECTION); - gl2f.glPushMatrix(); - gl2f.glLoadIdentity(); + flush(); - gl2f.glOrthof(0, width, 0, height, -1, 1); - - gl2f.glMatrixMode(GL2.GL_MODELVIEW); - gl2f.glPushMatrix(); - gl2f.glLoadIdentity(); + pgl.disableDepthMask(); - gl2f.glTranslatef(x, y, 0); - gl2f.glScalef(w, h, 1); + pgl.setProjectionMode(); + pgl.pushMatrix(); + pgl.loadIdentity(); + pgl.setOrthographicProjection(0, width, 0, height, -1, 1); + + pgl.setModelviewMode(); + pgl.pushMatrix(); + pgl.loadIdentity(); + + pgl.translate(x, y, 0); + pgl.scale(w, h, 1); // Rendering the quad with the appropriate texture coordinates needed for the // specified crop region float s0 = (float)crop[0] / tw; @@ -5770,65 +6093,70 @@ public class PGraphicsOpenGL extends PGraphics { drawTexQuad(s0, t0, s1, t1); // Restoring matrices. - gl2f.glMatrixMode(GL2.GL_PROJECTION); - gl2f.glPopMatrix(); - gl2f.glMatrixMode(GL2.GL_MODELVIEW); - gl2f.glPopMatrix(); + pgl.setProjectionMode(); + pgl.popMatrix(); + pgl.setModelviewMode(); + pgl.popMatrix(); if (hintEnabled(ENABLE_DEPTH_MASK)) { - gl.glDepthMask(true); - } else { - gl.glDepthMask(false); - } - } - - // TODO: re-implement using built-in quads. - protected void allocateTexQuad() { - ByteBuffer vbb = ByteBuffer.allocateDirect(4 * 3 * SIZEOF_FLOAT); - vbb.order(ByteOrder.nativeOrder()); - quadVertexBuffer = vbb.asFloatBuffer(); - - ByteBuffer tbb = ByteBuffer.allocateDirect(4 * 2 * SIZEOF_FLOAT); - tbb.order(ByteOrder.nativeOrder()); - quadTexCoordBuffer = tbb.asFloatBuffer(); + pgl.enableDepthMask(); + } - quadVertexBuffer.position(0); - quadVertexBuffer.put(new float[] {0, 0, 0, - 0, 1, 0, - 1, 0, 0, - 1, 1, 0}); + +// gl.glDepthMask(false); +// +// gl2f.glMatrixMode(GL2.GL_PROJECTION); +// gl2f.glPushMatrix(); +// gl2f.glLoadIdentity(); +// +// gl2f.glOrthof(0, width, 0, height, -1, 1); +// +// gl2f.glMatrixMode(GL2.GL_MODELVIEW); +// gl2f.glPushMatrix(); +// gl2f.glLoadIdentity(); +// +// gl2f.glTranslatef(x, y, 0); +// gl2f.glScalef(w, h, 1); +// // Rendering the quad with the appropriate texture coordinates needed for the +// // specified crop region +// float s0 = (float)crop[0] / tw; +// float s1 = (float)(crop[0] + crop[2]) / tw; +// float t0 = (float)crop[1] / th; +// float t1 = (float)(crop[1] + crop[3]) / th; +// drawTexQuad(s0, t0, s1, t1); +// +// // Restoring matrices. +// gl2f.glMatrixMode(GL2.GL_PROJECTION); +// gl2f.glPopMatrix(); +// gl2f.glMatrixMode(GL2.GL_MODELVIEW); +// gl2f.glPopMatrix(); +// +// if (hintEnabled(ENABLE_DEPTH_MASK)) { +// gl.glDepthMask(true); +// } else { +// gl.glDepthMask(false); +// } } - protected void drawTexQuad() { + + protected void drawTexQuad() { drawTexQuad(0, 0, 1, 1); } /** * Pushes a normalized (1x1) textured quad to the GPU. */ - protected void drawTexQuad(float u0, float v0, float u1, float v1) { - if (quadVertexBuffer == null) { - allocateTexQuad(); - } - - quadTexCoordBuffer.position(0); - quadTexCoordBuffer.put(new float[] {u0, v0, - u0, v1, - u1, v0, - u1, v1}); - - gl2f.glEnableClientState(GL2.GL_VERTEX_ARRAY); - gl2f.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); - - quadVertexBuffer.position(0); - quadTexCoordBuffer.position(0); - - gl2f.glVertexPointer(3, GL.GL_FLOAT, 0, quadVertexBuffer); - gl2f.glTexCoordPointer(2, GL.GL_FLOAT, 0, quadTexCoordBuffer); - gl2f.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); - - gl2f.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); - gl2f.glDisableClientState(GL2.GL_VERTEX_ARRAY); + protected void drawTexQuad(float u0, float v0, float u1, float v1) { + // TODO: need to test... + stroke = false; + beginShape(QUAD); + vertex(0, 0, u0, v0); + vertex(1, 0, u1, v0); + vertex(1, 1, u1, v1); + vertex(0, 1, u0, v1); + endShape(); + tessellate(OPEN); + renderTexFill(); } @@ -5837,11 +6165,19 @@ public class PGraphicsOpenGL extends PGraphics { */ protected void copyToTexture(PTexture tex, IntBuffer buffer, int x, int y, int w, int h) { buffer.rewind(); - gl.glEnable(tex.glTarget); - gl.glBindTexture(tex.glTarget, tex.glID); - gl.glTexSubImage2D(tex.glTarget, 0, x, y, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer); - gl.glBindTexture(tex.glTarget, 0); - gl.glDisable(tex.glTarget); + + pgl.enableTexturing(tex.glTarget); + pgl.bindTexture(tex.glTarget, tex.glID); + pgl.copyTexSubImage(buffer, tex.glTarget, x, y, w, h); + pgl.bindTexture(tex.glTarget, 0); + pgl.disableTexturing(tex.glTarget); + + +// gl.glEnable(tex.glTarget); +// gl.glBindTexture(tex.glTarget, tex.glID); +// gl.glTexSubImage2D(tex.glTarget, 0, x, y, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer); +// gl.glBindTexture(tex.glTarget, 0); +// gl.glDisable(tex.glTarget); } ////////////////////////////////////////////////////////////// @@ -5851,44 +6187,60 @@ public class PGraphicsOpenGL extends PGraphics { protected void setSurfaceParams() { // The default shade model is GL_SMOOTH, but we set // here just in case... - gl2f.glShadeModel(GL2.GL_SMOOTH); + //gl2f.glShadeModel(GL2.GL_SMOOTH); + pgl.setShadeModel(PGLJava.SMOOTH); + // The ambient and diffuse components for each vertex are taken // from the glColor/color buffer setting: - gl2f.glEnable(GL2.GL_COLOR_MATERIAL); +// gl2f.glEnable(GL2.GL_COLOR_MATERIAL); + pgl.enableColorMaterial(); + // For a quick overview of how the lighting model works in OpenGL // see this page: // http://www.sjbaker.org/steve/omniv/opengl_lighting.html // Some normal related settings: - gl2f.glEnable(GL2.GL_NORMALIZE); - gl2f.glEnable(GL2.GL_RESCALE_NORMAL); + pgl.enableNormalization(); + pgl.enableRescaleNormals(); +// gl2f.glEnable(GL2.GL_NORMALIZE); +// gl2f.glEnable(GL2.GL_RESCALE_NORMAL); // Light model defaults: // The default opengl ambient light is (0.2, 0.2, 0.2), so // here we set our own default value. - gl2f.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, baseLight, 0); - gl2f.glLightModelf(GL2.GL_LIGHT_MODEL_TWO_SIDE, 0); + pgl.setTwoSidedLightModel(); + pgl.setDefaultAmbientLight(baseLight); +// gl2f.glLightModelf(GL2.GL_LIGHT_MODEL_TWO_SIDE, 0); +// gl2f.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, baseLight, 0); } protected void saveGLMatrices() { - gl2f.glMatrixMode(GL2.GL_PROJECTION); - gl2f.glPushMatrix(); - gl2f.glMatrixMode(GL2.GL_MODELVIEW); - gl2f.glPushMatrix(); + pgl.setProjectionMode(); + pgl.pushMatrix(); + pgl.setModelviewMode(); + pgl.pushMatrix(); +// gl2f.glMatrixMode(GL2.GL_PROJECTION); +// gl2f.glPushMatrix(); +// gl2f.glMatrixMode(GL2.GL_MODELVIEW); +// gl2f.glPushMatrix(); } protected void restoreGLMatrices() { - // Restoring matrices. - gl2f.glMatrixMode(GL2.GL_PROJECTION); - gl2f.glPopMatrix(); - gl2f.glMatrixMode(GL2.GL_MODELVIEW); - gl2f.glPopMatrix(); + pgl.setProjectionMode(); + pgl.popMatrix(); + pgl.setModelviewMode(); + pgl.popMatrix(); +// gl2f.glMatrixMode(GL2.GL_PROJECTION); +// gl2f.glPopMatrix(); +// gl2f.glMatrixMode(GL2.GL_MODELVIEW); +// gl2f.glPopMatrix(); } protected void setDefNormals(float nx, float ny, float nz) { - gl2f.glNormal3f(nx, ny, nz); + pgl.setNormal(nx, ny, nz); +// gl2f.glNormal3f(nx, ny, nz); } ////////////////////////////////////////////////////////////// @@ -5942,10 +6294,11 @@ public class PGraphicsOpenGL extends PGraphics { profile = null; profile = GLProfile.getDefault(); + //profile = GLProfile.get(GLProfile.GL2ES1); //profile = GLProfile.get(GLProfile.GL4bc); //profile = GLProfile.getMaxProgrammable(); - pipeline = FIXED; + pgl.pipeline = PGLJava.FIXED; /* // Profile auto-selection disabled for the time being. @@ -6029,7 +6382,7 @@ public class PGraphicsOpenGL extends PGraphics { // We need the GL2GL3 profile to access the glRenderbufferStorageMultisample // function used in multisampled (antialiased) offscreen rendering. - if (PGraphicsOpenGL.fboMultisampleSupported && gl2x != null && 1 < antialias) { + if (PGraphicsOpenGL.fboMultisampleSupported && pgl.gl2x != null && 1 < antialias) { int nsamples = antialias; offscreenFramebufferMultisample = new PFramebuffer(parent, texture.glWidth, texture.glHeight, nsamples, 0, offscreenDepthBits, offscreenStencilBits, @@ -6062,63 +6415,28 @@ public class PGraphicsOpenGL extends PGraphics { } protected void getGLParameters() { - OPENGL_VENDOR = gl.glGetString(GL.GL_VENDOR); - OPENGL_RENDERER = gl.glGetString(GL.GL_RENDERER); - OPENGL_VERSION = gl.glGetString(GL.GL_VERSION); - - // Better way to check for extensions and related functions (taken from jMonkeyEngine): - // renderbufferStorageMultisample = gl.isExtensionAvailable("GL_EXT_framebuffer_multisample") && - // gl.isFunctionAvailable("glRenderbufferStorageMultisample"); - // For more details on GL properties initialiation in jMonkey using JOGL2, take a look at: - // http://code.google.com/p/jmonkeyengine/source/browse/branches/jme3/src/jogl2/com/jme3/renderer/jogl/JoglRenderer.java +// OPENGL_VENDOR = gl.glGetString(GL.GL_VENDOR); +// OPENGL_RENDERER = gl.glGetString(GL.GL_RENDERER); +// OPENGL_VERSION = gl.glGetString(GL.GL_VERSION); +// OPENGL_EXTENSIONS = gl.glGetString(GL.GL_EXTENSIONS); + OPENGL_VENDOR = pgl.getVendorString(); + OPENGL_RENDERER = pgl.getRendererString(); + OPENGL_VERSION = pgl.getVersionString(); + OPENGL_EXTENSIONS = pgl.getExtensionsString(); + + npotTexSupported = pgl.isNpotTexSupported(); + mipmapGeneration = pgl.hasMipmapGeneration(); + matrixGetSupported = pgl.isMatrixGetSupported(); + texenvCrossbarSupported = pgl.isTexenvCrossbarSupported(); + vboSupported = pgl.isVboSupported(); + fboSupported = pgl.isFboSupported(); + fboMultisampleSupported = pgl.isFboMultisampleSupported(); + blendEqSupported = pgl.isBlendEqSupported(); - npotTexSupported = false; - mipmapGeneration = false; - matrixGetSupported = false; - texenvCrossbarSupported = false; - vboSupported = false; - fboSupported = false; - fboMultisampleSupported = false; - OPENGL_EXTENSIONS = gl.glGetString(GL.GL_EXTENSIONS); - if (-1 < OPENGL_EXTENSIONS.indexOf("texture_non_power_of_two")) { - npotTexSupported = true; - } - if (-1 < OPENGL_EXTENSIONS.indexOf("generate_mipmap")) { - mipmapGeneration = true; - } - if (-1 < OPENGL_EXTENSIONS.indexOf("matrix_get")) { - matrixGetSupported = true; - } - if (-1 < OPENGL_EXTENSIONS.indexOf("texture_env_crossbar")) { - texenvCrossbarSupported = true; - } - if (-1 < OPENGL_EXTENSIONS.indexOf("vertex_buffer_object")) { - vboSupported = true; - } - if (-1 < OPENGL_EXTENSIONS.indexOf("framebuffer_object")) { - fboSupported = true; - } - if (-1 < OPENGL_EXTENSIONS.indexOf("framebuffer_multisample")) { - fboMultisampleSupported = true; - } - - blendEqSupported = true; - - int temp[] = new int[2]; - - gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, temp, 0); - maxTextureSize = temp[0]; - - gl.glGetIntegerv(GL.GL_ALIASED_LINE_WIDTH_RANGE, temp, 0); - maxLineWidth = temp[1]; - - gl.glGetIntegerv(GL.GL_ALIASED_POINT_SIZE_RANGE, temp, 0); - maxPointSize = temp[1]; - - // The maximum number of texture units only makes sense in the - // fixed pipeline. - gl.glGetIntegerv(GL2.GL_MAX_TEXTURE_UNITS, temp, 0); - maxTextureUnits = temp[0]; + maxTextureSize = pgl.getMaxTexureSize(); + maxLineWidth = pgl.getMaxAliasedLineWidth(); + maxPointSize = pgl.getMaxAliasedPointSize(); + maxTextureUnits = pgl.getMaxTextureUnits(); glParamsRead = true; } diff --git a/java/libraries/opengl/src/processing/opengl/PShader.java b/java/libraries/opengl/src/processing/opengl/PShader.java index 69b4538c8..e8a255868 100644 --- a/java/libraries/opengl/src/processing/opengl/PShader.java +++ b/java/libraries/opengl/src/processing/opengl/PShader.java @@ -24,12 +24,8 @@ package processing.opengl; import processing.core.*; - -import javax.media.opengl.*; - import java.io.IOException; import java.net.URL; -import java.nio.*; /** * This class encapsulates a glsl shader. Based in the code by JohnG @@ -38,7 +34,7 @@ import java.nio.*; public class PShader { protected PApplet parent; protected PGraphicsOpenGL ogl; - protected GL2GL3 gl; + protected PGLJava pgl; protected int programObject; protected int vertexShader; @@ -55,7 +51,7 @@ public class PShader { public PShader(PApplet parent) { this.parent = parent; ogl = (PGraphicsOpenGL) parent.g; - gl = ogl.gl2x; + pgl = ogl.pgl; programObject = ogl.createGLSLProgramObject(); @@ -163,8 +159,10 @@ public class PShader { * Links the shader program and validates it. */ public void setup() { - gl.glLinkProgram(programObject); - gl.glValidateProgram(programObject); +// gl.glLinkProgram(programObject); +// gl.glValidateProgram(programObject); + pgl.linkProgram(programObject); + pgl.validateProgram(programObject); checkLogInfo("GLSL program validation: ", programObject); initialized = true; } @@ -189,14 +187,16 @@ public class PShader { // textures. // gl.glUniform1iARB(loc, unit); - ogl.gl.getGL2().glUseProgramObjectARB(programObject); + //ogl.gl.getGL2().glUseProgramObjectARB(programObject); + pgl.startProgram(programObject); } /** * Stops the execution of the shader program. */ public void stop() { - ogl.gl.getGL2().glUseProgramObjectARB(0); + //ogl.gl.getGL2().glUseProgramObjectARB(0); + pgl.stopProgram(); } /** @@ -206,7 +206,8 @@ public class PShader { * @return int */ public int getAttribLocation(String name) { - return (gl.glGetAttribLocation(programObject, name)); +// return gl.glGetAttribLocation(programObject, name); + return pgl.getAttribLocation(programObject, name); } /** @@ -216,7 +217,8 @@ public class PShader { * @return int */ public int getUniformLocation(String name) { - return (gl.glGetUniformLocation(programObject, name)); +// return gl.glGetUniformLocation(programObject, name); + return pgl.getUniformLocation(programObject, name); } /** @@ -228,7 +230,10 @@ public class PShader { */ public void setTexUniform(String name, int unit) { int loc = getUniformLocation(name); - if (-1 < loc) gl.glUniform1i(loc, unit); + if (-1 < loc) { +// gl.glUniform1i(loc, unit); + pgl.setIntUniform(loc, unit); + } } /** @@ -261,7 +266,10 @@ public class PShader { */ public void setIntUniform(String name, int x) { int loc = getUniformLocation(name); - if (-1 < loc) gl.glUniform1i(loc, x); + if (-1 < loc) { +// gl.glUniform1i(loc, x); + pgl.setIntUniform(loc, x); + } } /** @@ -272,7 +280,10 @@ public class PShader { */ public void setFloatUniform(String name, float x) { int loc = getUniformLocation(name); - if (-1 < loc) gl.glUniform1f(loc, x); + if (-1 < loc) { + //gl.glUniform1f(loc, x); + pgl.setFloatUniform(loc, x); + } } /** @@ -284,7 +295,10 @@ public class PShader { */ public void setVecUniform(String name, float x, float y) { int loc = getUniformLocation(name); - if (-1 < loc) gl.glUniform2f(loc, x, y); + if (-1 < loc) { +// gl.glUniform2f(loc, x, y); + pgl.setFloatUniform(loc, x, y); + } } /** @@ -297,7 +311,10 @@ public class PShader { */ public void setVecUniform(String name, float x, float y, float z) { int loc = getUniformLocation(name); - if (-1 < loc) gl.glUniform3f(loc, x, y, z); + if (-1 < loc) { +// gl.glUniform3f(loc, x, y, z); + pgl.setFloatUniform(loc, x, y, z); + } } /** @@ -311,7 +328,10 @@ public class PShader { */ public void setVecUniform(String name, float x, float y, float z, float w) { int loc = getUniformLocation(name); - if (-1 < loc) gl.glUniform4f(loc, x, y, z, w); + if (-1 < loc) { +// gl.glUniform4f(loc, x, y, z, w); + pgl.setFloatUniform(loc, x, y, z, w); + } } /** @@ -325,12 +345,9 @@ public class PShader { float m10, float m11) { int loc = getUniformLocation(name); if (-1 < loc) { - float[] mat = new float[4]; - mat[0] = m00; - mat[1] = m10; - mat[4] = m01; - mat[5] = m11; - gl.glUniformMatrix2fv(loc, 1, false, mat, 0); + pgl.setMatUniform(loc, m00, m01, + m10, m11); + //gl.glUniformMatrix2fv(loc, 1, false, mat, 0); } } @@ -346,17 +363,9 @@ public class PShader { float m20, float m21, float m22) { int loc = getUniformLocation(name); if (-1 < loc) { - float[] mat = new float[9]; - mat[0] = m00; - mat[1] = m10; - mat[2] = m20; - mat[4] = m01; - mat[5] = m11; - mat[6] = m21; - mat[8] = m02; - mat[9] = m12; - mat[10] =m22; - gl.glUniformMatrix3fv(loc, 1, false, mat, 0); + pgl.setMatUniform(loc, m00, m01, m02, + m10, m11, m12, + m20, m21, m22); } } @@ -373,24 +382,10 @@ public class PShader { float m30, float m31, float m32, float m33) { int loc = getUniformLocation(name); if (-1 < loc) { - float[] mat = new float[16]; - mat[0] = m00; - mat[1] = m10; - mat[2] = m20; - mat[3] = m30; - mat[4] = m01; - mat[5] = m11; - mat[6] = m21; - mat[7] = m31; - mat[8] = m02; - mat[9] = m12; - mat[10] = m22; - mat[11] = m32; - mat[12] = m03; - mat[13] = m13; - mat[14] = m23; - mat[15] = m33; - gl.glUniformMatrix4fv(loc, 1, false, mat, 0); + pgl.setMatUniform(loc, m00, m01, m02, m03, + m10, m11, m12, m13, + m20, m21, m22, m23, + m30, m31, m32, m33); } } @@ -402,7 +397,10 @@ public class PShader { */ public void setFloatAttribute(String name, float x) { int loc = getAttribLocation(name); - if (-1 < loc) gl.glVertexAttrib1f(loc, x); + if (-1 < loc) { +// gl.glVertexAttrib1f(loc, x); + pgl.setFloatAttrib(loc, x); + } } /** @@ -414,7 +412,10 @@ public class PShader { */ public void setVecAttribute(String name, float x, float y) { int loc = getAttribLocation(name); - if (-1 < loc) gl.glVertexAttrib2f(loc, x, y); + if (-1 < loc) { +// gl.glVertexAttrib2f(loc, x, y); + pgl.setFloatAttrib(loc, x, y); + } } /** @@ -427,7 +428,10 @@ public class PShader { */ public void setVecAttribute(String name, float x, float y, float z) { int loc = getAttribLocation(name); - if (-1 < loc) gl.glVertexAttrib3f(loc, x, y, z); + if (-1 < loc) { +// gl.glVertexAttrib3f(loc, x, y, z); + pgl.setFloatAttrib(loc, x, y, z); + } } /** @@ -441,7 +445,10 @@ public class PShader { */ public void setVecAttribute(String name, float x, float y, float z, float w) { int loc = getAttribLocation(name); - if (-1 < loc) gl.glVertexAttrib4f(loc, x, y, z, w); + if (-1 < loc) { +// gl.glVertexAttrib4f(loc, x, y, z, w); + pgl.setFloatAttrib(loc, x, y, z, w); + } } /** @@ -451,11 +458,14 @@ public class PShader { private void attachVertexShader(String shaderSource, String file) { vertexShader = ogl.createGLSLVertShaderObject(); - gl.glShaderSource(vertexShader, 1, new String[] { shaderSource }, - (int[]) null, 0); - gl.glCompileShader(vertexShader); +// gl.glShaderSource(vertexShader, 1, new String[] { shaderSource }, (int[]) null, 0); +// gl.glCompileShader(vertexShader); + pgl.setShaderSource(vertexShader, shaderSource); + pgl.compileShader(vertexShader); + checkLogInfo("Vertex shader " + file + " compilation: ", vertexShader); - ogl.gl.getGL2().glAttachObjectARB(programObject, vertexShader); +// ogl.gl.getGL2().glAttachObjectARB(programObject, vertexShader); + pgl.attachShader(programObject, vertexShader); } /** @@ -465,37 +475,26 @@ public class PShader { private void attachFragmentShader(String shaderSource, String file) { fragmentShader = ogl.createGLSLFragShaderObject(); - gl.glShaderSource(fragmentShader, 1, new String[] { shaderSource }, - (int[]) null, 0); - gl.glCompileShader(fragmentShader); +// gl.glShaderSource(fragmentShader, 1, new String[] { shaderSource }, (int[]) null, 0); +// gl.glCompileShader(fragmentShader); + pgl.setShaderSource(fragmentShader, shaderSource); + pgl.compileShader(fragmentShader); + checkLogInfo("Fragment shader " + file + " compilation: ", fragmentShader); - ogl.gl.getGL2().glAttachObjectARB(programObject, fragmentShader); +// ogl.gl.getGL2().glAttachObjectARB(programObject, fragmentShader); + pgl.attachShader(programObject, fragmentShader); } /** * @invisible Check the log error for the opengl object obj. Prints error * message if needed. */ - protected void checkLogInfo(String title, int obj) { - IntBuffer iVal = IntBuffer.allocate(1); - ogl.gl.getGL2().glGetObjectParameterivARB(obj, GL2.GL_OBJECT_INFO_LOG_LENGTH_ARB, iVal); - - int length = iVal.get(); - - if (length <= 1) { - return; + protected void checkLogInfo(String title, int obj) { + String log = pgl.getShaderLog(obj); + if (!log.equals("")) { + System.out.println(title); + System.out.println(log); } - - // Some error occurred... - ByteBuffer infoLog = ByteBuffer.allocate(length); - iVal.flip(); - - ogl.gl.getGL2().glGetInfoLogARB(obj, length, iVal, infoLog); - - byte[] infoBytes = new byte[length]; - infoLog.get(infoBytes); - System.out.println(title); - System.out.println(new String(infoBytes)); } protected void release() { diff --git a/java/libraries/opengl/src/processing/opengl/PShape3D.java b/java/libraries/opengl/src/processing/opengl/PShape3D.java index af8addf58..3a536c5f7 100644 --- a/java/libraries/opengl/src/processing/opengl/PShape3D.java +++ b/java/libraries/opengl/src/processing/opengl/PShape3D.java @@ -23,10 +23,6 @@ package processing.opengl; -import javax.media.opengl.GL; -import javax.media.opengl.GL2; -import javax.media.opengl.GL2ES1; - import processing.core.PApplet; import processing.core.PGraphics; import processing.core.PImage; @@ -34,16 +30,13 @@ import processing.core.PMatrix; import processing.core.PMatrix2D; import processing.core.PMatrix3D; import processing.core.PShape; -import processing.core.PStyle; import processing.core.PVector; import processing.opengl.PGraphicsOpenGL.InGeometry; import processing.opengl.PGraphicsOpenGL.TessGeometry; import processing.opengl.PGraphicsOpenGL.Tessellator; import java.io.BufferedReader; -import java.nio.ByteBuffer; import java.nio.FloatBuffer; -import java.nio.IntBuffer; import java.util.ArrayList; import java.util.HashSet; import java.util.Hashtable; @@ -81,6 +74,7 @@ import java.util.Hashtable; public class PShape3D extends PShape { protected PGraphicsOpenGL ogl; + protected PGLJava pgl; protected PShape3D root; protected int glMode; @@ -247,8 +241,9 @@ public class PShape3D extends PShape { public PShape3D(PApplet parent, int family) { ogl = (PGraphicsOpenGL)parent.g; + pgl = ogl.pgl; - glMode = GL.GL_STATIC_DRAW; + glMode = PGLJava.STATIC_DRAW; glFillVertexBufferID = 0; glFillColorBufferID = 0; @@ -327,11 +322,11 @@ public class PShape3D extends PShape { public void setMode(int mode) { if (mode == STATIC) { - glMode = GL.GL_STATIC_DRAW; + glMode = PGLJava.STATIC_DRAW; } else if (mode == DYNAMIC) { - glMode = GL.GL_DYNAMIC_DRAW; + glMode = PGLJava.DYNAMIC_DRAW; } else if (mode == STREAM) { - glMode = GL2.GL_STREAM_COPY; + glMode = PGLJava.STREAM_DRAW; } } @@ -1889,6 +1884,7 @@ public class PShape3D extends PShape { public FloatBuffer mapFillVertices() { + /* ByteBuffer bb; getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillVertexBufferID); @@ -1898,16 +1894,21 @@ public class PShape3D extends PShape { bb = ogl.gl2x.glMapBufferRange(GL.GL_ARRAY_BUFFER, 3 * tess.firstFillVertex, 3 * tess.fillVertexCount, GL2.GL_READ_WRITE); } return bb.asFloatBuffer(); + */ + return null; } public void unmapFillVertices() { + /* getGl().glUnmapBuffer(GL.GL_ARRAY_BUFFER); getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + */ } public FloatBuffer mapLineVertices() { + /* ByteBuffer bb; getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineVertexBufferID); @@ -1917,16 +1918,21 @@ public class PShape3D extends PShape { bb = ogl.gl2x.glMapBufferRange(GL.GL_ARRAY_BUFFER, 3 * tess.firstLineVertex, 3 * tess.lineVertexCount, GL2.GL_READ_WRITE); } return bb.asFloatBuffer(); + */ + return null; } public void unmapLineVertices() { + /* getGl().glUnmapBuffer(GL.GL_ARRAY_BUFFER); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + */ } public FloatBuffer mapLineAttributes() { + /* ByteBuffer bb; getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineAttribBufferID); @@ -1936,11 +1942,15 @@ public class PShape3D extends PShape { bb = ogl.gl2x.glMapBufferRange(GL.GL_ARRAY_BUFFER, 3 * tess.firstLineVertex, 3 * tess.lineVertexCount, GL2.GL_READ_WRITE); } return bb.asFloatBuffer(); + */ + return null; } public void unmapLineAttributes() { + /* getGl().glUnmapBuffer(GL.GL_ARRAY_BUFFER); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + */ } @@ -2406,27 +2416,41 @@ public class PShape3D extends PShape { protected void initFillBuffers(int nvert, int nind) { - glFillVertexBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + glFillVertexBufferID = ogl.createVertexBufferObject(); + pgl.bindVertexBuffer(glFillVertexBufferID); + pgl.initVertexBuffer(3 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); glFillColorBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); - + pgl.bindVertexBuffer(glFillColorBufferID); + pgl.initVertexBuffer(4 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + glFillNormalBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + pgl.bindVertexBuffer(glFillNormalBufferID); + pgl.initVertexBuffer(3 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); glFillTexCoordBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 2 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + pgl.bindVertexBuffer(glFillTexCoordBufferID); + pgl.initVertexBuffer(2 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 2 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); - glFillIndexBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillIndexBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, nind * PGraphicsOpenGL.SIZEOF_INT, null, glMode); + pgl.unbindVertexBuffer(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + glFillIndexBufferID = ogl.createVertexBufferObject(); + pgl.bindIndexBuffer(glFillIndexBufferID); + pgl.initIndexBuffer(nind, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillIndexBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, nind * PGraphicsOpenGL.SIZEOF_INT, null, glMode); + + pgl.unbindIndexBuffer(); } @@ -2608,88 +2632,131 @@ public class PShape3D extends PShape { protected void copyFillGeometry(int offset, int size, float[] vertices, float[] colors, float[] normals, float[] texcoords) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); + pgl.bindVertexBuffer(glFillVertexBufferID); + pgl.copyVertexBufferSubData(vertices, 3 * offset, 3 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); + pgl.bindVertexBuffer(glFillColorBufferID); + pgl.copyVertexBufferSubData(colors, 4 * offset, 4 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); + pgl.bindVertexBuffer(glFillNormalBufferID); + pgl.copyVertexBufferSubData(normals, 3 * offset, 3 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 2 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(texcoords)); + pgl.bindVertexBuffer(glFillTexCoordBufferID); + pgl.copyVertexBufferSubData(texcoords, 2 * offset, 2 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 2 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(texcoords)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindVertexBuffer(); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); } protected void copyFillVertices(int offset, int size, float[] vertices) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillVertexBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glFillVertexBufferID); + pgl.copyVertexBufferSubData(vertices, 3 * offset, 3 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyFillColors(int offset, int size, float[] colors) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillColorBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glFillColorBufferID); + pgl.copyVertexBufferSubData(colors, 4 * offset, 4 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyFillNormals(int offset, int size, float[] normals) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillNormalBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + + pgl.bindVertexBuffer(glFillNormalBufferID); + pgl.copyVertexBufferSubData(normals, 3 * offset, 3 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyFillTexCoords(int offset, int size, float[] texcoords) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 2 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(texcoords)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillTexCoordBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 2 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(texcoords)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glFillTexCoordBufferID); + pgl.copyVertexBufferSubData(texcoords, 2 * offset, 2 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyFillIndices(int offset, int size, int[] indices) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillIndexBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, offset * PGraphicsOpenGL.SIZEOF_INT, - size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(indices)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glFillIndexBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, offset * PGraphicsOpenGL.SIZEOF_INT, +// size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(indices)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindIndexBuffer(glFillTexCoordBufferID); + pgl.copyIndexBufferSubData(indices, offset, size, glMode); + pgl.unbindVertexBuffer(); } protected void initLineBuffers(int nvert, int nind) { glLineVertexBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + pgl.bindVertexBuffer(glLineVertexBufferID); + pgl.initVertexBuffer(3 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); glLineColorBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + pgl.bindVertexBuffer(glLineColorBufferID); + pgl.initVertexBuffer(4 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); glLineNormalBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + pgl.bindVertexBuffer(glLineNormalBufferID); + pgl.initVertexBuffer(3 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); glLineAttribBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineAttribBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + pgl.bindVertexBuffer(glLineAttribBufferID); + pgl.initVertexBuffer(4 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineAttribBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + + pgl.unbindVertexBuffer(); glLineIndexBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineIndexBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, nind * PGraphicsOpenGL.SIZEOF_INT, null, glMode); + pgl.bindIndexBuffer(glLineIndexBufferID); + pgl.initIndexBuffer(nind, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineIndexBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, nind * PGraphicsOpenGL.SIZEOF_INT, null, glMode); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); } @@ -2714,88 +2781,130 @@ public class PShape3D extends PShape { protected void copyLineGeometry(int offset, int size, float[] vertices, float[] colors, float[] normals, float[] attribs) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); + pgl.bindVertexBuffer(glLineVertexBufferID); + pgl.copyVertexBufferSubData(vertices, 3 * offset, 3 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); + pgl.bindVertexBuffer(glLineColorBufferID); + pgl.copyVertexBufferSubData(colors, 4 * offset, 4 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); + pgl.bindVertexBuffer(glLineNormalBufferID); + pgl.copyVertexBufferSubData(normals, 3 * offset, 3 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineAttribBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs)); + pgl.bindVertexBuffer(glLineAttribBufferID); + pgl.copyVertexBufferSubData(attribs, 4 * offset, 4 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineAttribBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindVertexBuffer(); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); } protected void copyLineVertices(int offset, int size, float[] vertices) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineVertexBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glLineVertexBufferID); + pgl.copyVertexBufferSubData(vertices, 3 * offset, 3 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyLineColors(int offset, int size, float[] colors) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineColorBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glLineColorBufferID); + pgl.copyVertexBufferSubData(colors, 4 * offset, 4 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyLineNormals(int offset, int size, float[] normals) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineNormalBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glLineNormalBufferID); + pgl.copyVertexBufferSubData(normals, 3 * offset, 3 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyLineAttributes(int offset, int size, float[] attribs) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineAttribBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineAttribBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glLineAttribBufferID); + pgl.copyVertexBufferSubData(attribs, 4 * offset, 4 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyLineIndices(int offset, int size, int[] indices) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineIndexBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, offset * PGraphicsOpenGL.SIZEOF_INT, - size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(indices)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glLineIndexBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, offset * PGraphicsOpenGL.SIZEOF_INT, +// size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(indices)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindIndexBuffer(glLineIndexBufferID); + pgl.copyIndexBufferSubData(indices, offset, size, glMode); + pgl.unbindIndexBuffer(); } protected void initPointBuffers(int nvert, int nind) { - glPointVertexBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + glPointVertexBufferID = ogl.createVertexBufferObject(); + pgl.bindVertexBuffer(glPointVertexBufferID); + pgl.initVertexBuffer(3 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); glPointColorBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + pgl.bindVertexBuffer(glPointColorBufferID); + pgl.initVertexBuffer(4 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 4 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); glPointNormalBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + pgl.bindVertexBuffer(glPointNormalBufferID); + pgl.initVertexBuffer(3 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 3 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); glPointAttribBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointAttribBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, 2 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + pgl.bindVertexBuffer(glPointAttribBufferID); + pgl.initVertexBuffer(2 * nvert, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointAttribBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, 2 * nvert * PGraphicsOpenGL.SIZEOF_FLOAT, null, glMode); + + pgl.unbindVertexBuffer(); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + glPointIndexBufferID = ogl.createVertexBufferObject(); + pgl.bindIndexBuffer(glPointIndexBufferID); + pgl.initIndexBuffer(nind, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointIndexBufferID); +// getGl().glBufferData(GL.GL_ARRAY_BUFFER, nind * PGraphicsOpenGL.SIZEOF_INT, null, glMode); - glPointIndexBufferID = ogl.createVertexBufferObject(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointIndexBufferID); - getGl().glBufferData(GL.GL_ARRAY_BUFFER, nind * PGraphicsOpenGL.SIZEOF_INT, null, glMode); - - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); } @@ -2820,63 +2929,92 @@ public class PShape3D extends PShape { protected void copyPointGeometry(int offset, int size, float[] vertices, float[] colors, float[] normals, float[] attribs) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); + pgl.bindVertexBuffer(glPointVertexBufferID); + pgl.copyVertexBufferSubData(vertices, 3 * offset, 3 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); + pgl.bindVertexBuffer(glPointColorBufferID); + pgl.copyVertexBufferSubData(colors, 4 * offset, 4 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); + pgl.bindVertexBuffer(glPointNormalBufferID); + pgl.copyVertexBufferSubData(normals, 3 * offset, 3 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointAttribBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 2 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs)); + pgl.bindVertexBuffer(glPointAttribBufferID); + pgl.copyVertexBufferSubData(attribs, 2 * offset, 2 * size, glMode); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointAttribBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 2 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindVertexBuffer(); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); } protected void copyPointVertices(int offset, int size, float[] vertices) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointVertexBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(vertices)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glPointVertexBufferID); + pgl.copyVertexBufferSubData(vertices, 3 * offset, 3 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyPointColors(int offset, int size, float[] colors) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointColorBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 4 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 4 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(colors)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glPointColorBufferID); + pgl.copyVertexBufferSubData(colors, 4 * offset, 4 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyPointNormals(int offset, int size, float[] normals) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointNormalBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 3 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 3 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(normals)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glPointNormalBufferID); + pgl.copyVertexBufferSubData(normals, 3 * offset, 3 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyPointAttributes(int offset, int size, float[] attribs) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointAttribBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 2 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, - 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointAttribBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, 2 * offset * PGraphicsOpenGL.SIZEOF_FLOAT, +// 2 * size * PGraphicsOpenGL.SIZEOF_FLOAT, FloatBuffer.wrap(attribs)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindVertexBuffer(glPointAttribBufferID); + pgl.copyVertexBufferSubData(attribs, 2 * offset, 2 * size, glMode); + pgl.unbindVertexBuffer(); } protected void copyPointIndices(int offset, int size, int[] indices) { - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointIndexBufferID); - getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, offset * PGraphicsOpenGL.SIZEOF_INT, - size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(indices)); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, glPointIndexBufferID); +// getGl().glBufferSubData(GL.GL_ARRAY_BUFFER, offset * PGraphicsOpenGL.SIZEOF_INT, +// size * PGraphicsOpenGL.SIZEOF_INT, IntBuffer.wrap(indices)); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + + pgl.bindIndexBuffer(glPointIndexBufferID); + pgl.copyIndexBufferSubData(indices, offset, size, glMode); + pgl.unbindIndexBuffer(); } @@ -3064,31 +3202,53 @@ public class PShape3D extends PShape { protected void renderPoints() { ogl.startPointShader(); - getGl().glEnableClientState(GL2.GL_NORMAL_ARRAY); - getGl().glEnableClientState(GL2.GL_COLOR_ARRAY); - getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY); + pgl.enableVertexArrays(); + pgl.enableColorArrays(); + pgl.enableNormalArrays(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glPointNormalBufferID); - getGl().glNormalPointer(GL.GL_FLOAT, 0, 0); - - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glPointColorBufferID); - getGl().glColorPointer(4, GL.GL_FLOAT, 0, 0); +// getGl().glEnableClientState(GL2.GL_NORMAL_ARRAY); +// getGl().glEnableClientState(GL2.GL_COLOR_ARRAY); +// getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY); + - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glPointVertexBufferID); - getGl().glVertexPointer(3, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(root.glPointVertexBufferID); + pgl.setVertexFormat(3, 0, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glPointVertexBufferID); +// getGl().glVertexPointer(3, GL.GL_FLOAT, 0, 0); + + pgl.bindVertexBuffer(root.glPointColorBufferID); + pgl.setColorFormat(4, 0, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glPointColorBufferID); +// getGl().glColorPointer(4, GL.GL_FLOAT, 0, 0); + + pgl.bindVertexBuffer(root.glPointNormalBufferID); + pgl.setNormalFormat(3, 0, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glPointNormalBufferID); +// getGl().glNormalPointer(GL.GL_FLOAT, 0, 0); ogl.setupPointShader(root.glPointAttribBufferID); - getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, root.glPointIndexBufferID); - getGl().glDrawElements(GL.GL_TRIANGLES, tess.lastPointIndex - tess.firstPointIndex + 1, GL.GL_UNSIGNED_INT, - tess.firstPointIndex * PGraphicsOpenGL.SIZEOF_INT); - - getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + int offset = tess.firstPointIndex; + int size = tess.lastPointIndex - tess.firstPointIndex + 1; + pgl.bindIndexBuffer(root.glPointIndexBufferID); + pgl.renderIndexBuffer(offset, size); - getGl().glDisableClientState(GL2.GL_VERTEX_ARRAY); - getGl().glDisableClientState(GL2.GL_COLOR_ARRAY); - getGl().glDisableClientState(GL2.GL_NORMAL_ARRAY); +// getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, root.glPointIndexBufferID); +// getGl().glDrawElements(GL.GL_TRIANGLES, tess.lastPointIndex - tess.firstPointIndex + 1, GL.GL_UNSIGNED_INT, +// tess.firstPointIndex * PGraphicsOpenGL.SIZEOF_INT); + +// getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); + pgl.unbindVertexBuffer(); + + pgl.disableVertexArrays(); + pgl.disableColorArrays(); + pgl.disableNormalArrays(); + +// getGl().glDisableClientState(GL2.GL_VERTEX_ARRAY); +// getGl().glDisableClientState(GL2.GL_COLOR_ARRAY); +// getGl().glDisableClientState(GL2.GL_NORMAL_ARRAY); ogl.stopPointShader(); } @@ -3097,81 +3257,132 @@ public class PShape3D extends PShape { protected void renderLines() { ogl.startLineShader(); - getGl().glEnableClientState(GL2.GL_NORMAL_ARRAY); - getGl().glEnableClientState(GL2.GL_COLOR_ARRAY); - getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY); +// getGl().glEnableClientState(GL2.GL_NORMAL_ARRAY); +// getGl().glEnableClientState(GL2.GL_COLOR_ARRAY); +// getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY); + pgl.enableVertexArrays(); + pgl.enableColorArrays(); + pgl.enableNormalArrays(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineNormalBufferID); - getGl().glNormalPointer(GL.GL_FLOAT, 0, 0); - - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineColorBufferID); - getGl().glColorPointer(4, GL.GL_FLOAT, 0, 0); - - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineVertexBufferID); - getGl().glVertexPointer(3, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(root.glLineVertexBufferID); + pgl.setVertexFormat(3, 0, 0); - ogl.setupLineShader(root.glLineAttribBufferID); + pgl.bindVertexBuffer(root.glLineColorBufferID); + pgl.setColorFormat(4, 0, 0); - getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, root.glLineIndexBufferID); - getGl().glDrawElements(GL.GL_TRIANGLES, tess.lastLineIndex - tess.firstLineIndex + 1, GL.GL_UNSIGNED_INT, - tess.firstLineIndex * PGraphicsOpenGL.SIZEOF_INT); + pgl.bindVertexBuffer(root.glLineNormalBufferID); + pgl.setNormalFormat(3, 0, 0); - getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineNormalBufferID); +// getGl().glNormalPointer(GL.GL_FLOAT, 0, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineColorBufferID); +// getGl().glColorPointer(4, GL.GL_FLOAT, 0, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glLineVertexBufferID); +// getGl().glVertexPointer(3, GL.GL_FLOAT, 0, 0); - getGl().glDisableClientState(GL2.GL_VERTEX_ARRAY); - getGl().glDisableClientState(GL2.GL_COLOR_ARRAY); - getGl().glDisableClientState(GL2.GL_NORMAL_ARRAY); + ogl.setupLineShader(root.glLineAttribBufferID); + + int offset = tess.firstLineIndex; + int size = tess.lastLineIndex - tess.firstLineIndex + 1; + pgl.bindIndexBuffer(root.glLineIndexBufferID); + pgl.renderIndexBuffer(offset, size); + +// getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, root.glLineIndexBufferID); +// getGl().glDrawElements(GL.GL_TRIANGLES, tess.lastLineIndex - tess.firstLineIndex + 1, GL.GL_UNSIGNED_INT, +// tess.firstLineIndex * PGraphicsOpenGL.SIZEOF_INT); + +// getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); + pgl.unbindVertexBuffer(); + +// getGl().glDisableClientState(GL2.GL_VERTEX_ARRAY); +// getGl().glDisableClientState(GL2.GL_COLOR_ARRAY); +// getGl().glDisableClientState(GL2.GL_NORMAL_ARRAY); + pgl.disableVertexArrays(); + pgl.disableColorArrays(); + pgl.disableNormalArrays(); ogl.stopLineShader(); } protected void renderFill(PImage textureImage) { - getGl().glEnableClientState(GL2.GL_NORMAL_ARRAY); - getGl().glEnableClientState(GL2.GL_COLOR_ARRAY); - getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY); - getGl().glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); +// getGl().glEnableClientState(GL2.GL_NORMAL_ARRAY); +// getGl().glEnableClientState(GL2.GL_COLOR_ARRAY); +// getGl().glEnableClientState(GL2.GL_VERTEX_ARRAY); +// getGl().glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + pgl.enableVertexArrays(); + pgl.enableColorArrays(); + pgl.enableNormalArrays(); + pgl.enableTexCoordArrays(); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillNormalBufferID); - getGl().glNormalPointer(GL.GL_FLOAT, 0, 0); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillColorBufferID); - getGl().glColorPointer(4, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(root.glFillColorBufferID); + pgl.setVertexFormat(3, 0, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillColorBufferID); +// getGl().glVertexPointer(3, GL.GL_FLOAT, 0, 0); + + pgl.bindVertexBuffer(root.glFillColorBufferID); + pgl.setColorFormat(4, 0, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillColorBufferID); +// getGl().glColorPointer(4, GL.GL_FLOAT, 0, 0); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillVertexBufferID); - getGl().glVertexPointer(3, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(root.glFillNormalBufferID); + pgl.setNormalFormat(3, 0, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillNormalBufferID); +// getGl().glNormalPointer(GL.GL_FLOAT, 0, 0); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillTexCoordBufferID); - getGl().glTexCoordPointer(2, GL.GL_FLOAT, 0, 0); + pgl.bindVertexBuffer(root.glFillTexCoordBufferID); + pgl.setTexCoordFormat(2, 0, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, root.glFillTexCoordBufferID); +// getGl().glTexCoordPointer(2, GL.GL_FLOAT, 0, 0); PTexture tex = null; if (textureImage != null) { tex = ogl.getTexture(textureImage); if (tex != null) { - getGl().glEnable(tex.glTarget); - getGl().glActiveTexture(GL.GL_TEXTURE0); - getGl().glBindTexture(tex.glTarget, tex.glID); + pgl.enableTexturing(tex.glTarget); + pgl.setActiveTexUnit(0); + pgl.bindTexture(tex.glTarget, tex.glID); +// getGl().glEnable(tex.glTarget); +// getGl().glActiveTexture(GL.GL_TEXTURE0); +// getGl().glBindTexture(tex.glTarget, tex.glID); } } - getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, root.glFillIndexBufferID); - getGl().glDrawElements(GL.GL_TRIANGLES, tess.lastFillIndex - tess.firstFillIndex + 1, GL.GL_UNSIGNED_INT, - tess.firstFillIndex * PGraphicsOpenGL.SIZEOF_INT); + int offset = tess.firstFillIndex; + int size = tess.lastFillIndex - tess.firstFillIndex + 1; + pgl.bindIndexBuffer(root.glFillIndexBufferID); + pgl.renderIndexBuffer(offset, size); + +// getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, root.glFillIndexBufferID); +// getGl().glDrawElements(GL.GL_TRIANGLES, tess.lastFillIndex - tess.firstFillIndex + 1, GL.GL_UNSIGNED_INT, +// tess.firstFillIndex * PGraphicsOpenGL.SIZEOF_INT); if (tex != null) { - getGl().glActiveTexture(GL.GL_TEXTURE0); - getGl().glBindTexture(tex.glTarget, 0); - getGl().glDisable(tex.glTarget); + pgl.unbindTexture(tex.glTarget); + pgl.disableTexturing(tex.glTarget); +// +// getGl().glActiveTexture(GL.GL_TEXTURE0); +// getGl().glBindTexture(tex.glTarget, 0); +// getGl().glDisable(tex.glTarget); } - getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); - getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + pgl.unbindIndexBuffer(); + pgl.unbindVertexBuffer(); - getGl().glDisableClientState(GL2.GL_VERTEX_ARRAY); - getGl().glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); - getGl().glDisableClientState(GL2.GL_COLOR_ARRAY); - getGl().glDisableClientState(GL2.GL_NORMAL_ARRAY); +// getGl().glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); +// getGl().glBindBuffer(GL.GL_ARRAY_BUFFER, 0); + +// getGl().glDisableClientState(GL2.GL_VERTEX_ARRAY); +// getGl().glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); +// getGl().glDisableClientState(GL2.GL_COLOR_ARRAY); +// getGl().glDisableClientState(GL2.GL_NORMAL_ARRAY); + pgl.disableVertexArrays(); + pgl.disableColorArrays(); + pgl.disableNormalArrays(); + pgl.disableTexCoordArrays(); } /////////////////////////////////////////////////////////// @@ -3330,9 +3541,9 @@ public class PShape3D extends PShape { // Utilities methods - protected GL2ES1 getGl() { - return ogl.gl2f; - } +// protected GL2ES1 getGl() { +// return ogl.gl2f; +// } /////////////////////////////////////////////////////////////////////////// diff --git a/java/libraries/opengl/src/processing/opengl/PTexture.java b/java/libraries/opengl/src/processing/opengl/PTexture.java index 8a2427635..c4de62cc7 100644 --- a/java/libraries/opengl/src/processing/opengl/PTexture.java +++ b/java/libraries/opengl/src/processing/opengl/PTexture.java @@ -22,11 +22,7 @@ package processing.opengl; -import javax.media.opengl.GL; -import javax.media.opengl.GL2; import javax.media.opengl.GLContext; - -import java.nio.*; import processing.core.PApplet; import processing.core.PConstants; import processing.core.PGraphics; @@ -42,6 +38,7 @@ public class PTexture implements PConstants { protected PApplet parent; // The Processing applet protected PGraphicsOpenGL ogl; // The main renderer + protected PGLJava pgl; // The interface between Processing and OpenGL. protected GLContext context; // The context that created this texture. // These are public but use at your own risk! @@ -94,6 +91,7 @@ public class PTexture implements PConstants { this.parent = parent; ogl = (PGraphicsOpenGL)parent.g; + pgl = ogl.pgl; context = ogl.getContext(); glID = 0; @@ -238,15 +236,17 @@ public class PTexture implements PConstants { return; } - getGl().glEnable(glTarget); - getGl().glBindTexture(glTarget, glID); + pgl.enableTexturing(glTarget); + pgl.bindTexture(glTarget, glID); +// getGl().glEnable(glTarget); +// getGl().glBindTexture(glTarget, glID); if (usingMipmaps) { if (PGraphicsOpenGL.mipmapGeneration) { // Automatic mipmap generation. int[] rgbaPixels = new int[w * h]; - convertToRGBA(pixels, rgbaPixels, format, w, h); - getGl().glTexParameteri(GL.GL_TEXTURE_2D, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE); + convertToRGBA(pixels, rgbaPixels, format, w, h); + pgl.enableTexMipmapGen(glTarget); setTexels(x, y, w, h, rgbaPixels); rgbaPixels = null; } else { @@ -261,8 +261,10 @@ public class PTexture implements PConstants { rgbaPixels = null; } - getGl().glBindTexture(glTarget, 0); - getGl().glDisable(glTarget); +// getGl().glBindTexture(glTarget, 0); +// getGl().glDisable(glTarget); + pgl.bindTexture(glTarget, 0); + pgl.enableTexturing(glTarget); } @@ -403,13 +405,17 @@ public class PTexture implements PConstants { // Bind/unbind public void bind() { - getGl().glEnable(glTarget); - getGl().glBindTexture(glTarget, glID); + pgl.enableTexturing(glTarget); + pgl.bindTexture(glTarget, glID); +// getGl().glEnable(glTarget); +// getGl().glBindTexture(glTarget, glID); } public void unbind() { - getGl().glEnable(glTarget); - getGl().glBindTexture(glTarget, 0); + pgl.enableTexturing(glTarget); + pgl.unbindTexture(glTarget); +// getGl().glEnable(glTarget); +// getGl().glBindTexture(glTarget, 0); } //////////////////////////////////////////////////////////// @@ -698,20 +704,27 @@ public class PTexture implements PConstants { protected void allocate() { release(); // Just in the case this object is being re-allocated. - getGl().glEnable(glTarget); +// getGl().glEnable(glTarget); + pgl.enableTexturing(glTarget); glID = ogl.createTextureObject(); - getGl().glBindTexture(glTarget, glID); - getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_MIN_FILTER, glMinFilter); - getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_MAG_FILTER, glMagFilter); - getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_WRAP_S, glWrapS); - getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_WRAP_T, glWrapT); + //getGl().glBindTexture(glTarget, glID); +// getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_MIN_FILTER, glMinFilter); +// getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_MAG_FILTER, glMagFilter); +// getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_WRAP_S, glWrapS); +// getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_WRAP_T, glWrapT); + pgl.bindTexture(glTarget, glID); + pgl.setTexMinFilter(glTarget, glMinFilter); + pgl.setTexMagFilter(glTarget, glMagFilter); + pgl.setTexWrapS(glTarget, glWrapS); + pgl.setTexWrapT(glTarget, glWrapT); + // First, we use glTexImage2D to set the full size of the texture (glW/glH might be diff // from w/h in the case that the GPU doesn't support NPOT textures) - getGl().glTexImage2D(glTarget, 0, glFormat, glWidth, glHeight, 0, GL.GL_RGBA, - GL.GL_UNSIGNED_BYTE, null); + //getGl().glTexImage2D(glTarget, 0, glFormat, glWidth, glHeight, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null); + pgl.initTex(glFormat, glFormat, glWidth, glHeight); // Once OpenGL knows the size of the new texture, we make sure it doesn't // contain any garbage in the region of interest (0, 0, width, height): @@ -719,8 +732,10 @@ public class PTexture implements PConstants { setTexels(0, 0, width, height, texels); texels = null; - getGl().glBindTexture(glTarget, 0); - getGl().glDisable(glTarget); +// getGl().glBindTexture(glTarget, 0); +// getGl().glDisable(glTarget); + pgl.unbindTexture(glTarget); + pgl.disableTexturing(glTarget); } @@ -775,7 +790,8 @@ public class PTexture implements PConstants { } protected void setTexels(int level, int x, int y, int w, int h, int[] pix) { - getGl().glTexSubImage2D(glTarget, 0, x, y, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(pix)); + //getGl().glTexSubImage2D(glTarget, 0, x, y, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(pix)); + pgl.copyTexSubPixels(pix, glTarget, x, y, w, h); } protected void copyObject(PTexture src) { @@ -814,35 +830,35 @@ public class PTexture implements PConstants { public Parameters getParameters() { Parameters res = new Parameters(); - if ( glTarget == GL.GL_TEXTURE_2D ) { + if (glTarget == PGLJava.TEXTURE_2D) { res.target = TEXTURE2D; } - if (glFormat == GL.GL_RGB) { + if (glFormat == PGLJava.RGB) { res.format = RGB; - } else if (glFormat == GL.GL_RGBA) { + } else if (glFormat == PGLJava.RGBA) { res.format = ARGB; - } else if (glFormat == GL.GL_ALPHA) { + } else if (glFormat == PGLJava.ALPHA) { res.format = ALPHA; } - if (glMinFilter == GL.GL_NEAREST) { + if (glMinFilter == PGLJava.NEAREST) { res.sampling = POINT; - } else if (glMinFilter == GL.GL_LINEAR) { + } else if (glMinFilter == PGLJava.LINEAR) { res.sampling = BILINEAR; - } else if (glMinFilter == GL.GL_LINEAR_MIPMAP_LINEAR) { + } else if (glMinFilter == PGLJava.LINEAR_MIPMAP_LINEAR) { res.sampling = TRILINEAR; } - if (glWrapS == GL.GL_CLAMP_TO_EDGE) { + if (glWrapS == PGLJava.CLAMP_TO_EDGE) { res.wrapU = CLAMP; - } else if (glWrapS == GL.GL_REPEAT) { + } else if (glWrapS == PGLJava.REPEAT) { res.wrapU = REPEAT; } - if (glWrapT == GL.GL_CLAMP_TO_EDGE) { + if (glWrapT == PGLJava.CLAMP_TO_EDGE) { res.wrapV = CLAMP; - } else if (glWrapT == GL.GL_REPEAT) { + } else if (glWrapT == PGLJava.REPEAT) { res.wrapV = REPEAT; } @@ -857,51 +873,51 @@ public class PTexture implements PConstants { */ protected void setParameters(Parameters params) { if (params.target == TEXTURE2D) { - glTarget = GL.GL_TEXTURE_2D; + glTarget = PGLJava.TEXTURE_2D; } else { throw new RuntimeException("OPENGL2: Unknown texture target"); } if (params.format == RGB) { - glFormat = GL.GL_RGB; + glFormat = PGLJava.RGB; } else if (params.format == ARGB) { - glFormat = GL.GL_RGBA; + glFormat = PGLJava.RGBA; } else if (params.format == ALPHA) { - glFormat = GL.GL_ALPHA; + glFormat = PGLJava.ALPHA; } else { throw new RuntimeException("OPENGL2: Unknown texture format"); } if (params.sampling == POINT) { - glMagFilter = GL.GL_NEAREST; - glMinFilter = GL.GL_NEAREST; + glMagFilter = PGLJava.NEAREST; + glMinFilter = PGLJava.NEAREST; } else if (params.sampling == BILINEAR) { - glMagFilter = GL.GL_LINEAR; - glMinFilter = GL.GL_LINEAR; + glMagFilter = PGLJava.LINEAR; + glMinFilter = PGLJava.LINEAR; } else if (params.sampling == TRILINEAR) { - glMagFilter = GL.GL_LINEAR; - glMinFilter = GL.GL_LINEAR_MIPMAP_LINEAR; + glMagFilter = PGLJava.LINEAR; + glMinFilter = PGLJava.LINEAR_MIPMAP_LINEAR; } else { throw new RuntimeException("OPENGL2: Unknown texture filtering mode"); } if (params.wrapU == CLAMP) { - glWrapS = GL.GL_CLAMP_TO_EDGE; + glWrapS = PGLJava.CLAMP_TO_EDGE; } else if (params.wrapU == REPEAT) { - glWrapS = GL.GL_REPEAT; + glWrapS = PGLJava.REPEAT; } else { throw new RuntimeException("OPENGL2: Unknown wrapping mode"); } if (params.wrapV == CLAMP) { - glWrapT = GL.GL_CLAMP_TO_EDGE; + glWrapT = PGLJava.CLAMP_TO_EDGE; } else if (params.wrapV == REPEAT) { - glWrapT = GL.GL_REPEAT; + glWrapT = PGLJava.REPEAT; } else { throw new RuntimeException("OPENGL2: Unknown wrapping mode"); } - usingMipmaps = glMinFilter == GL.GL_LINEAR_MIPMAP_LINEAR; + usingMipmaps = glMinFilter == PGLJava.LINEAR_MIPMAP_LINEAR; flippedX = false; flippedY = false; @@ -911,9 +927,9 @@ public class PTexture implements PConstants { // Utilities - protected GL getGl() { - return ogl.gl; - } +// protected GL getGl() { +// return ogl.pgl.gl; +// } ///////////////////////////////////////////////////////////////////////////