From 720d1ef25ca8c8a9c6359779bf26c702af628118 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 2 Sep 2012 15:59:25 +0000 Subject: [PATCH] hintEnabled is a utility protected method in PGraphicsOpenGL --- android/core/src/processing/core/PApplet.java | 5 -- .../core/src/processing/core/PGraphics.java | 9 --- .../processing/opengl/PGraphicsOpenGL.java | 9 +++ .../src/processing/opengl/PShapeOpenGL.java | 15 +++-- core/src/processing/core/PApplet.java | 5 -- core/src/processing/core/PGraphics.java | 8 --- core/src/processing/opengl/PGL.java | 67 ++++++++++++------- .../processing/opengl/PGraphicsOpenGL.java | 18 +++++ core/src/processing/opengl/PShader.java | 6 ++ core/src/processing/opengl/PShapeOpenGL.java | 15 +++-- 10 files changed, 90 insertions(+), 67 deletions(-) diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index ab91e3cae..a4ec0866e 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -7306,11 +7306,6 @@ public class PApplet extends Activity implements PConstants, Runnable { } - public boolean hintEnabled(int which) { - return g.hintEnabled(which); - } - - /** * Start a new shape of type POLYGON */ diff --git a/android/core/src/processing/core/PGraphics.java b/android/core/src/processing/core/PGraphics.java index 8707c33fc..d68e54e23 100644 --- a/android/core/src/processing/core/PGraphics.java +++ b/android/core/src/processing/core/PGraphics.java @@ -982,15 +982,6 @@ public class PGraphics extends PImage implements PConstants { } - public boolean hintEnabled(int which) { - if (which > 0) { - return hints[which]; - } else { - return !hints[-which]; - } - } - - ////////////////////////////////////////////////////////////// // VERTEX SHAPES diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 69d744503..3ae0d757a 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2153,6 +2153,15 @@ public class PGraphicsOpenGL extends PGraphics { } + protected boolean hintEnabled(int which) { + if (which > 0) { + return hints[which]; + } else { + return !hints[-which]; + } + } + + ////////////////////////////////////////////////////////////// // VERTEX SHAPES diff --git a/android/core/src/processing/opengl/PShapeOpenGL.java b/android/core/src/processing/opengl/PShapeOpenGL.java index 3240e7e08..850a9a75f 100644 --- a/android/core/src/processing/opengl/PShapeOpenGL.java +++ b/android/core/src/processing/opengl/PShapeOpenGL.java @@ -4076,30 +4076,31 @@ public class PShapeOpenGL extends PShape { @Override public void draw(PGraphics g) { if (g instanceof PGraphicsOpenGL) { + PGraphicsOpenGL gl = (PGraphicsOpenGL)g; if (visible) { - pre(g); + pre(gl); updateTessellation(); updateGeometry(); if (family == GROUP) { - if (fragmentedGroup(g)) { + if (fragmentedGroup(gl)) { for (int i = 0; i < childCount; i++) { - ((PShapeOpenGL) children[i]).draw(g); + ((PShapeOpenGL) children[i]).draw(gl); } } else { PImage tex = null; if (textures != null && textures.size() == 1) { tex = (PImage)textures.toArray()[0]; } - render((PGraphicsOpenGL)g, tex); + render(gl, tex); } } else { - render((PGraphicsOpenGL)g, texture); + render(gl, texture); } - post(g); + post(gl); } } else { // The renderer is not PGraphicsOpenGL, which probably @@ -4116,7 +4117,7 @@ public class PShapeOpenGL extends PShape { // so they cannot rendered in a single call. // Or accurate 2D mode is enabled, which forces each // shape to be rendered separately. - protected boolean fragmentedGroup(PGraphics g) { + protected boolean fragmentedGroup(PGraphicsOpenGL g) { return g.hintEnabled(ENABLE_ACCURATE_2D) || (textures != null && 1 < textures.size()) || strokedTexture; diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 407c509f1..44388e1e7 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -10031,11 +10031,6 @@ public class PApplet extends Applet } - public boolean hintEnabled(int which) { - return g.hintEnabled(which); - } - - /** * Start a new shape of type POLYGON */ diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index a861a44f5..e3324f325 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -1083,14 +1083,6 @@ public class PGraphics extends PImage implements PConstants { } } - public boolean hintEnabled(int which) { - if (which > 0) { - return hints[which]; - } else { - return !hints[-which]; - } - } - ////////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index d4dbcde54..b02afe148 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -396,7 +396,8 @@ public class PGL { protected int numSamples; protected boolean multisample; protected boolean packedDepthStencil; - protected int[] glColorTex = { 0 }; + protected int backTex, frontTex; + protected int[] glColorTex = { 0, 0 }; protected int[] glColorFbo = { 0 }; protected int[] glMultiFbo = { 0 }; protected int[] glColorRenderBuffer = { 0 }; @@ -504,6 +505,7 @@ public class PGL { protected void initPrimarySurface(int antialias) { +/* if (ENABLE_OSX_SCREEN_FBO) { needScreenFBO = false; glColorFbo[0] = 0; @@ -525,16 +527,14 @@ public class PGL { } } } +*/ + needScreenFBO = true; if (profile == null) { profile = GLProfile.getDefault(); } else { // Restarting... if (canvasAWT != null) { - // TODO: Even if the GLCanvas is put inside an animator, the rendering - // runs inside the EDT, ask the JOGL guys about this. -// animator.stop(); -// animator.remove(canvasAWT); canvasAWT.removeGLEventListener(listener); pg.parent.removeListeners(canvasAWT); pg.parent.remove(canvasAWT); @@ -573,9 +573,6 @@ public class PGL { listener = new PGLListener(); canvasAWT.addGLEventListener(listener); -// animator = new PGLAnimator(canvasAWT); -// animator.start(); - capabilities = canvasAWT.getChosenGLCapabilities(); canvas = canvasAWT; canvasNEWT = null; @@ -636,29 +633,32 @@ public class PGL { contextHashCode = context.hashCode(); // Create the color texture... - gl.glGenTextures(1, glColorTex, 0); - gl.glBindTexture(GL.GL_TEXTURE_2D, glColorTex[0]); - gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, - GL.GL_NEAREST); - gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, - GL.GL_NEAREST); - gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, - GL.GL_CLAMP_TO_EDGE); - gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, - GL.GL_CLAMP_TO_EDGE); - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, fboWidth, fboHeight, - 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null); + gl.glGenTextures(2, glColorTex, 0); + for (int i = 0; i < 2; i++) { + gl.glBindTexture(GL.GL_TEXTURE_2D, glColorTex[0]); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, + GL.GL_NEAREST); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, + GL.GL_NEAREST); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, + GL.GL_CLAMP_TO_EDGE); + gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, + GL.GL_CLAMP_TO_EDGE); + gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, fboWidth, fboHeight, + 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null); + initTexture(GL.GL_TEXTURE_2D, PGL.RGBA, fboWidth, fboHeight); + } gl.glBindTexture(GL.GL_TEXTURE_2D, 0); // ...and attach to the color framebuffer. gl.glGenFramebuffers(1, glColorFbo, 0); gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFbo[0]); - gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, - GL.GL_TEXTURE_2D, glColorTex[0], 0); + //gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, + // GL.GL_TEXTURE_2D, glColorTex[0], 0); // Clear the color buffer in the color FBO - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL.GL_COLOR_BUFFER_BIT); + //gl.glClearColor(0, 0, 0, 0); + //gl.glClear(GL.GL_COLOR_BUFFER_BIT); if (multisample) { // We need multisampled FBO: @@ -773,6 +773,9 @@ public class PGL { // to update the screenFramebuffer object so when the framebuffer // is popped back to the screen, the correct id is set. PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFbo[0]; + + backTex = 1; + frontTex = 0; } else { // To make sure that the default screen buffer is used, specially after // doing screen rendering on an FBO (the OSX 10.7+ above). @@ -886,6 +889,14 @@ public class PGL { protected void beginOnscreenDraw(boolean clear) { if (glColorFbo[0] != 0) { + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFbo[0]); + pg.report("HERE"); + gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, + GL.GL_COLOR_ATTACHMENT0, + GL.GL_TEXTURE_2D, + glColorTex[frontTex], 0); + validateFramebuffer(); + if (multisample) { // Render the scene to the mutisampled buffer... gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glMultiFbo[0]); @@ -894,12 +905,12 @@ public class PGL { // Now the screen buffer is the multisample FBO. PGraphicsOpenGL.screenFramebuffer.glFbo = glMultiFbo[0]; } else { - gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFbo[0]); if (gl2x != null) gl2x.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0); PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFbo[0]; } } + } @@ -928,6 +939,11 @@ public class PGL { // Leaving the color FBO currently bound as the screen FB. gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFbo[0]); PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFbo[0]; + + // Swapping front and back textures. + int temp = frontTex; + frontTex = backTex; + backTex = temp; } } @@ -948,7 +964,6 @@ public class PGL { protected void requestDraw() { if (initialized) { try { - //animator.requestDisplay(); if (toolkit == AWT) { canvasAWT.display(); } else if (toolkit == NEWT) { diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 54c72517f..8731ec8ea 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2154,6 +2154,15 @@ public class PGraphicsOpenGL extends PGraphics { } + protected boolean hintEnabled(int which) { + if (which > 0) { + return hints[which]; + } else { + return !hints[-which]; + } + } + + ////////////////////////////////////////////////////////////// // VERTEX SHAPES @@ -6766,6 +6775,8 @@ public class PGraphicsOpenGL extends PGraphics { protected int textureSamplerLoc; protected int texcoordMatrixLoc; protected int texcoordOffsetLoc; + protected int backbufferSamplerLoc; + protected int resolutionLoc; protected float[] tcmat; @@ -6789,6 +6800,9 @@ public class PGraphicsOpenGL extends PGraphics { textureSamplerLoc = getUniformLoc("textureSampler"); texcoordMatrixLoc = getUniformLoc("texcoordMatrix"); texcoordOffsetLoc = getUniformLoc("texcoordOffset"); + + backbufferSamplerLoc = getUniformLoc("backbufferSampler"); + resolutionLoc = getUniformLoc("resolution"); } @Override @@ -6849,6 +6863,10 @@ public class PGraphicsOpenGL extends PGraphics { super.bind(); if (-1 < inTexcoordLoc) pgl.enableVertexAttribArray(inTexcoordLoc); + + if (-1 < backbufferSamplerLoc) { + // ... + } } @Override diff --git a/core/src/processing/opengl/PShader.java b/core/src/processing/opengl/PShader.java index c1eb3e566..835ced1d7 100644 --- a/core/src/processing/opengl/PShader.java +++ b/core/src/processing/opengl/PShader.java @@ -473,6 +473,12 @@ public class PShader { } + protected void setUniformTex(int loc, Texture tex) { + // get unit from last value in bindTextures ... + // pgl.activeTexture(PGL.TEXTURE0 + unit); + tex.bind(); + } + /* // The individual attribute setters are not really needed, read this: diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 87bd8e3c6..55bc1c5e2 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -4078,30 +4078,31 @@ public class PShapeOpenGL extends PShape { @Override public void draw(PGraphics g) { if (g instanceof PGraphicsOpenGL) { + PGraphicsOpenGL gl = (PGraphicsOpenGL)g; if (visible) { - pre(g); + pre(gl); updateTessellation(); updateGeometry(); if (family == GROUP) { - if (fragmentedGroup(g)) { + if (fragmentedGroup(gl)) { for (int i = 0; i < childCount; i++) { - ((PShapeOpenGL) children[i]).draw(g); + ((PShapeOpenGL) children[i]).draw(gl); } } else { PImage tex = null; if (textures != null && textures.size() == 1) { tex = (PImage)textures.toArray()[0]; } - render((PGraphicsOpenGL)g, tex); + render(gl, tex); } } else { - render((PGraphicsOpenGL)g, texture); + render(gl, texture); } - post(g); + post(gl); } } else { // The renderer is not PGraphicsOpenGL, which probably @@ -4118,7 +4119,7 @@ public class PShapeOpenGL extends PShape { // so they cannot rendered in a single call. // Or accurate 2D mode is enabled, which forces each // shape to be rendered separately. - protected boolean fragmentedGroup(PGraphics g) { + protected boolean fragmentedGroup(PGraphicsOpenGL g) { return g.hintEnabled(ENABLE_ACCURATE_2D) || (textures != null && 1 < textures.size()) || strokedTexture;