From 19ff731e7c057e94a7b1e8ad98201ea6a47d9239 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 12 Sep 2015 14:10:01 -0400 Subject: [PATCH] changes to facilitate android port, update copyright notices --- core/src/processing/opengl/FontTexture.java | 12 +- core/src/processing/opengl/FrameBuffer.java | 37 +- core/src/processing/opengl/PGL.java | 157 ++-- core/src/processing/opengl/PGraphics2D.java | 7 +- core/src/processing/opengl/PGraphics3D.java | 7 +- .../processing/opengl/PGraphicsOpenGL.java | 803 ++---------------- core/src/processing/opengl/PJOGL.java | 80 +- core/src/processing/opengl/PShader.java | 32 +- core/src/processing/opengl/PShapeOpenGL.java | 105 +-- core/src/processing/opengl/PSurfaceJOGL.java | 2 +- core/src/processing/opengl/Texture.java | 28 +- core/src/processing/opengl/VertexBuffer.java | 25 + .../processing/opengl/shaders/ColorFrag.glsl | 7 +- .../processing/opengl/shaders/ColorVert.glsl | 9 +- .../processing/opengl/shaders/LightFrag.glsl | 9 +- .../opengl/shaders/LightVert-vc4.glsl | 9 +- .../processing/opengl/shaders/LightVert.glsl | 20 +- .../processing/opengl/shaders/LineFrag.glsl | 7 +- .../processing/opengl/shaders/LineVert.glsl | 7 +- .../processing/opengl/shaders/MaskFrag.glsl | 7 +- .../processing/opengl/shaders/PointFrag.glsl | 7 +- .../processing/opengl/shaders/PointVert.glsl | 9 +- .../processing/opengl/shaders/TexFrag.glsl | 7 +- .../opengl/shaders/TexLightFrag.glsl | 7 +- .../opengl/shaders/TexLightVert-vc4.glsl | 9 +- .../opengl/shaders/TexLightVert.glsl | 20 +- .../processing/opengl/shaders/TexVert.glsl | 9 +- 27 files changed, 361 insertions(+), 1077 deletions(-) diff --git a/core/src/processing/opengl/FontTexture.java b/core/src/processing/opengl/FontTexture.java index 950e2f0c0..d5754b701 100644 --- a/core/src/processing/opengl/FontTexture.java +++ b/core/src/processing/opengl/FontTexture.java @@ -1,14 +1,16 @@ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-12 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,7 +21,7 @@ Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + */ package processing.opengl; diff --git a/core/src/processing/opengl/FrameBuffer.java b/core/src/processing/opengl/FrameBuffer.java index 550ed248a..3c6b927b2 100644 --- a/core/src/processing/opengl/FrameBuffer.java +++ b/core/src/processing/opengl/FrameBuffer.java @@ -1,14 +1,16 @@ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-12 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,7 +21,7 @@ Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + */ package processing.opengl; @@ -150,31 +152,6 @@ public class FrameBuffer implements PConstants { } -// @Override -// protected void finalize() throws Throwable { -// try { -// if (!screenFb) { -// if (glFbo != 0) { -// PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context); -// } -// if (glDepth != 0) { -// PGraphicsOpenGL.finalizeRenderBufferObject(glDepth, context); -// } -// if (glStencil != 0) { -// PGraphicsOpenGL.finalizeRenderBufferObject(glStencil, context); -// } -// if (glMultisample != 0) { -// PGraphicsOpenGL.finalizeRenderBufferObject(glMultisample, context); -// } -// if (glDepthStencil != 0) { -// PGraphicsOpenGL.finalizeRenderBufferObject(glDepthStencil, context); -// } -// } -// } finally { -// super.finalize(); -// } -// } - public void clear() { pg.pushFramebuffer(); pg.setFramebuffer(this); diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 672bd745a..523b62ba9 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -35,7 +35,6 @@ import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.nio.ShortBuffer; import java.util.Arrays; - import processing.core.PApplet; import processing.core.PConstants; import processing.core.PGraphics; @@ -70,7 +69,6 @@ public abstract class PGL { // Parameters - protected static boolean USE_FBOLAYER_BY_DEFAULT = false; public static int REQUESTED_DEPTH_BITS = 24; public static int REQUESTED_STENCIL_BITS = 8; public static int REQUESTED_ALPHA_BITS = 8; @@ -129,16 +127,17 @@ public abstract class PGL { * order to make sure the lines are always on top of the fill geometry */ protected static float STROKE_DISPLACEMENT = 0.999f; + protected static boolean DOUBLE_BUFFERED = true; // ........................................................ // FBO layer - protected boolean requestedFBOLayer = false; - protected boolean requestedFBOLayerReset = false; + protected boolean fboLayerEnabled = false; protected boolean fboLayerCreated = false; - protected boolean fboLayerInUse = false; - protected boolean firstFrame = true; + protected boolean fboLayerEnabledReq = false; + protected boolean fboLayerDisableReq = false; + protected boolean fbolayerResetReq = false; public int reqNumSamples; protected int numSamples; @@ -443,10 +442,6 @@ public abstract class PGL { glMultiDepthStencil = allocateIntBuffer(1); glMultiDepth = allocateIntBuffer(1); glMultiStencil = allocateIntBuffer(1); - - fboLayerCreated = false; - fboLayerInUse = false; - firstFrame = false; } byteBuffer = allocateByteBuffer(1); @@ -478,55 +473,61 @@ public abstract class PGL { } } -// public abstract Object getCanvas(); -// -// -// protected abstract void setFps(float fps); -// -// -// protected abstract void initSurface(int antialias); -// -// -// protected abstract void reinitSurface(); -// -// -// protected abstract void registerListeners(); + + abstract public Object getNative(); + + + abstract protected void setFrameRate(float fps); + + + abstract protected void initSurface(int antialias); + + + abstract protected void reinitSurface(); + + + abstract protected void registerListeners(); protected int getReadFramebuffer() { - return fboLayerInUse ? glColorFbo.get(0) : 0; + return fboLayerEnabled ? glColorFbo.get(0) : 0; } protected int getDrawFramebuffer() { - if (fboLayerInUse) return 1 < numSamples ? glMultiFbo.get(0) : - glColorFbo.get(0); + if (fboLayerEnabled) return 1 < numSamples ? glMultiFbo.get(0) : + glColorFbo.get(0); else return 0; } protected int getDefaultDrawBuffer() { - return fboLayerInUse ? COLOR_ATTACHMENT0 : BACK; + return fboLayerEnabled ? COLOR_ATTACHMENT0 : BACK; } protected int getDefaultReadBuffer() { - return fboLayerInUse ? COLOR_ATTACHMENT0 : FRONT; + return fboLayerEnabled ? COLOR_ATTACHMENT0 : FRONT; } protected boolean isFBOBacked() {; - return fboLayerInUse; + return fboLayerEnabled; } - public void requestFBOLayer() { - requestedFBOLayer = true; + public void enableFBOLayer() { + fboLayerEnabledReq = true; } - public void requestFBOLayerReset() { - requestedFBOLayerReset = true; + public void disableFBOLayer() { + fboLayerDisableReq = true; + } + + + public void resetFBOLayer() { + fbolayerResetReq = true; } @@ -628,6 +629,8 @@ public abstract class PGL { } + abstract protected float getPixelScale(); + /////////////////////////////////////////////////////////// // Present mode @@ -637,7 +640,7 @@ public abstract class PGL { presentMode = true; presentX = x; presentY = y; - requestFBOLayer(); + enableFBOLayer(); } @@ -691,12 +694,17 @@ public abstract class PGL { pclearColor = clearColor; clearColor = false; - if (requestedFBOLayer) { - if (requestedFBOLayerReset) { + if (fboLayerEnabledReq) { + fboLayerEnabled = true; + fboLayerEnabledReq = false; + } + + if (fboLayerEnabled) { + if (fbolayerResetReq) { destroyFBOLayer(); - requestedFBOLayerReset = false; + fbolayerResetReq = false; } - if (!fboLayerCreated) { + if (!fboLayerCreated && DOUBLE_BUFFERED) { createFBOLayer(); } @@ -709,7 +717,7 @@ public abstract class PGL { bindFramebufferImpl(FRAMEBUFFER, glMultiFbo.get(0)); } - if (firstFrame) { + if (sketch.frameCount == 0) { // No need to draw back color buffer because we are in the first frame. int argb = graphics.backgroundColor; float a = ((argb >> 24) & 0xff) / 255.0f; @@ -727,24 +735,18 @@ public abstract class PGL { x = (int)presentX; y = (int)presentY; } - float scale = graphics.getPixelScale(); + float scale = getPixelScale(); drawTexture(TEXTURE_2D, glColorTex.get(frontTex), fboWidth, fboHeight, x, y, graphics.width, graphics.height, 0, 0, (int)(scale * graphics.width), (int)(scale * graphics.height), 0, 0, graphics.width, graphics.height); } - - fboLayerInUse = true; - } else { - fboLayerInUse = false; } - - firstFrame = false; } protected void endRender(int windowColor) { - if (fboLayerInUse) { + if (fboLayerEnabled) { syncBackTexture(); // Draw the contents of the back texture to the screen framebuffer. @@ -791,7 +793,7 @@ public abstract class PGL { x = (int)presentX; y = (int)presentY; } - float scale = graphics.getPixelScale(); + float scale = getPixelScale(); drawTexture(TEXTURE_2D, glColorTex.get(backTex), fboWidth, fboHeight, x, y, graphics.width, graphics.height, @@ -802,8 +804,17 @@ public abstract class PGL { int temp = frontTex; frontTex = backTex; backTex = temp; + + if (fboLayerDisableReq) { + fboLayerEnabled = false; + fboLayerDisableReq = false; + } } else if (!clearColor && 0 < sketch.frameCount || !sketch.isLooping()) { - requestFBOLayer(); + enableFBOLayer(); + } + + if (fboLayerEnabledReq && !fboLayerCreated && !DOUBLE_BUFFERED) { + createFBOLayer(); } } @@ -840,7 +851,7 @@ public abstract class PGL { private void createFBOLayer() { - float scale = graphics.getPixelScale(); + float scale = getPixelScale(); if (hasNpotTexSupport()) { fboWidth = (int)(scale * graphics.width); @@ -921,45 +932,12 @@ public abstract class PGL { clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT); bindFramebufferImpl(FRAMEBUFFER, 0); - - if (0 < sketch.frameCount) { - // Copy the contents of the front and back screen buffers to the textures - // of the FBO, so they are properly initialized. Note that the front buffer - // of the default framebuffer (the screen) contains the previous frame: - // https://www.opengl.org/wiki/Default_Framebuffer - // so it is copied to the front texture of the FBO layer: - if (pclearColor || 0 < pgeomCount || !sketch.isLooping()) { - readBuffer(FRONT); - } else { - // ...except when the previous frame has not been cleared and nothing was - // renderered while looping. In this case the back buffer, which holds the - // initial state of the previous frame, still contains the most up-to-date - // screen state. - readBuffer(BACK); - } - bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0)); - framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, - TEXTURE_2D, glColorTex.get(frontTex), 0); - drawBuffer(COLOR_ATTACHMENT0); - blitFramebuffer(0, 0, fboWidth, fboHeight, - 0, 0, fboWidth, fboHeight, - COLOR_BUFFER_BIT, NEAREST); - - readBuffer(BACK); - bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0)); - framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, - TEXTURE_2D, glColorTex.get(backTex), 0); - drawBuffer(COLOR_ATTACHMENT0); - blitFramebuffer(0, 0, fboWidth, fboHeight, - 0, 0, fboWidth, fboHeight, - COLOR_BUFFER_BIT, NEAREST); - - bindFramebufferImpl(FRAMEBUFFER, 0); - } + initFBOLayer(); fboLayerCreated = true; } + protected abstract void initFBOLayer(); protected void destroyFBOLayer() { if (threadIsCurrent() && fboLayerCreated) { @@ -975,10 +953,7 @@ public abstract class PGL { deleteRenderbuffers(1, glMultiDepth); deleteRenderbuffers(1, glMultiStencil); } - fboLayerCreated = false; - fboLayerInUse = false; -// firstFrame = false; } @@ -1188,7 +1163,7 @@ public abstract class PGL { int viewX, int viewY, int viewW, int viewH, int texX0, int texY0, int texX1, int texY1, int scrX0, int scrY0, int scrX1, int scrY1) { - int viewF = (int)graphics.getPixelScale(); + int viewF = (int)getPixelScale(); drawTexture(target, id, texW, texH, viewX, viewY, viewW, viewH, viewF, texX0, texY0, texX1, texY1, @@ -1773,9 +1748,7 @@ public abstract class PGL { } - protected int getGLSLVersion() { - return 120; - } + abstract protected int getGLSLVersion(); protected String[] loadVertexShader(String filename) { diff --git a/core/src/processing/opengl/PGraphics2D.java b/core/src/processing/opengl/PGraphics2D.java index daa5b8611..e26ac1a04 100644 --- a/core/src/processing/opengl/PGraphics2D.java +++ b/core/src/processing/opengl/PGraphics2D.java @@ -1,9 +1,12 @@ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2012 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/core/src/processing/opengl/PGraphics3D.java b/core/src/processing/opengl/PGraphics3D.java index ec4cb81dc..ce60d19d0 100644 --- a/core/src/processing/opengl/PGraphics3D.java +++ b/core/src/processing/opengl/PGraphics3D.java @@ -1,9 +1,12 @@ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2012 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index c925ee6de..b3e9171ee 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -27,7 +27,6 @@ package processing.opengl; import processing.core.*; -import java.awt.Font; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.net.URL; @@ -602,12 +601,6 @@ public class PGraphicsOpenGL extends PGraphics { //public void setAntiAlias(int samples) // PGraphics -// @Override -// public void setFrameRate(float frameRate) { -// pgl.setFps(frameRate); -// } - - @Override public void setSize(int iwidth, int iheight) { width = iwidth; @@ -638,13 +631,9 @@ public class PGraphicsOpenGL extends PGraphics { // render only 1 frame, so no enough rendering // iterations have been conducted so far to properly // initialize all the buffers. -// pgl.swapBuffers(); + pgl.swapBuffers(); } -// finalizePolyBuffers(); -// finalizeLineBuffers(); -// finalizePointBuffers(); - deleteSurfaceTextures(); if (primaryGraphics) { deleteDefaultShaders(); @@ -662,44 +651,65 @@ public class PGraphicsOpenGL extends PGraphics { } } -// @Override -// protected void finalize() throws Throwable { -// try { -// finalizePolyBuffers(); -// finalizeLineBuffers(); -// finalizePointBuffers(); -// -// deleteSurfaceTextures(); -// if (!primaryGraphics) { -// if (offscreenFramebuffer != null) { -// offscreenFramebuffer.dispose(); -// offscreenFramebuffer = null; -// } -// if (multisampleFramebuffer != null) { -// multisampleFramebuffer.dispose(); -// multisampleFramebuffer = null; -// } -// } -// } finally { -// super.finalize(); -// } -// } protected void setFlushMode(int mode) { flushMode = mode; } - @Override - public PSurface createSurface() { // ignore - return new PSurfaceJOGL(this); + protected void updatePixelSize() { + float f = pgl.getPixelScale(); + pixelWidth = (int)(width * f); + pixelHeight = (int)(height * f); } - protected void updatePixelSize() { - float f = getPixelScale(); - pixelWidth = (int)(width * f); - pixelHeight = (int)(height * f); + ////////////////////////////////////////////////////////////// + + // PLATFORM-SPECIFIC CODE (Java, Android, etc.). Needs to be manually edited. + + + // Factory method + protected PGL createPGL(PGraphicsOpenGL pg) { + return new PJOGL(pg); +// return new PGLES(pg); + } + + +/* + @Override + // Android only + public void setFrameRate(float frameRate) { + pgl.setFrameRate(frameRate); + } + + + @Override + // Android only + public boolean canDraw() { + return pgl.canDraw(); + } + + + @Override + // Android only + public void requestDraw() { + if (primaryGraphics) { + if (initialized) { + if (sized) pgl.reinitSurface(); + if (parent.canDraw()) pgl.requestDraw(); + } else { + initPrimary(); + } + } + } +*/ + + + @Override + // Java only + public PSurface createSurface() { // ignore + return new PSurfaceJOGL(this); } @@ -726,18 +736,6 @@ public class PGraphicsOpenGL extends PGraphics { } - public float getPixelScale() { - PSurface surf = parent.getSurface(); - if (surf == null) { - return pixelDensity; - } else if (surf instanceof PSurfaceJOGL) { - return ((PSurfaceJOGL)surf).getPixelScale(); - } else { - throw new RuntimeException("Renderer cannot find a JOGL surface"); - } - } - - ////////////////////////////////////////////////////////////// @@ -1008,7 +1006,6 @@ public class PGraphicsOpenGL extends PGraphics { } - protected static class GLResourceFrameBuffer extends WeakReference { int glFbo; int glDepth; @@ -1143,497 +1140,6 @@ public class PGraphicsOpenGL extends PGraphics { } - - - // http://www.oracle.com/technetwork/articles/java/finalization-137655.html -// protected static class GLResource { -// int id; -// int context; -// -// GLResource(int id, int context) { -// this.id = id; -// this.context = context; -// } -// -// @Override -// public boolean equals(Object obj) { -// GLResource other = (GLResource)obj; -// return other.id == id && other.context == context; -// } -// -// @Override -// public int hashCode() { -// int result = 17; -// result = 31 * result + id; -// result = 31 * result + context; -// return result; -// } -// } - - - // Texture Objects ----------------------------------------------------------- - - /* - protected static int createTextureObject(int context, PGL pgl) { - deleteFinalizedTextureObjects(pgl); - - pgl.genTextures(1, intBuffer); - int id = intBuffer.get(0); - - GLResource res = new GLResource(id, context); - if (!glTextureObjects.containsKey(res)) { - glTextureObjects.put(res, false); - } - - return id; - } - - protected static void deleteTextureObject(int id, int context, PGL pgl) { - GLResource res = new GLResource(id, context); - if (glTextureObjects.containsKey(res)) { - intBuffer.put(0, id); - if (pgl.threadIsCurrent()) pgl.deleteTextures(1, intBuffer); - glTextureObjects.remove(res); - } - } - - protected static void deleteAllTextureObjects(PGL pgl) { - for (GLResource res : glTextureObjects.keySet()) { - intBuffer.put(0, res.id); - if (pgl.threadIsCurrent()) pgl.deleteTextures(1, intBuffer); - } - glTextureObjects.clear(); - } - - // This is synchronized because it is called from the GC thread. - synchronized protected static void finalizeTextureObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glTextureObjects.containsKey(res)) { - glTextureObjects.put(res, true); - } - } - - protected static void deleteFinalizedTextureObjects(PGL pgl) { - Set finalized = new HashSet(); - - for (GLResource res : glTextureObjects.keySet()) { - if (glTextureObjects.get(res)) { - finalized.add(res); - intBuffer.put(0, res.id); - if (pgl.threadIsCurrent()) pgl.deleteTextures(1, intBuffer); - } - } - - for (GLResource res : finalized) { - glTextureObjects.remove(res); - } - } - - protected static void removeTextureObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glTextureObjects.containsKey(res)) { - glTextureObjects.remove(res); - } - } -*/ - - // Vertex Buffer Objects ----------------------------------------------------- - - /* - protected static int createVertexBufferObject(int context, PGL pgl) { - deleteFinalizedVertexBufferObjects(pgl); - - pgl.genBuffers(1, intBuffer); - int id = intBuffer.get(0); - - GLResource res = new GLResource(id, context); - if (!glVertexBuffers.containsKey(res)) { - glVertexBuffers.put(res, false); - } - - return id; - } - - protected static void deleteVertexBufferObject(int id, int context, PGL pgl) { - GLResource res = new GLResource(id, context); - if (glVertexBuffers.containsKey(res)) { - intBuffer.put(0, id); - if (pgl.threadIsCurrent()) pgl.deleteBuffers(1, intBuffer); - glVertexBuffers.remove(res); - } - } - - protected static void deleteAllVertexBufferObjects(PGL pgl) { - for (GLResource res : glVertexBuffers.keySet()) { - intBuffer.put(0, res.id); - if (pgl.threadIsCurrent()) pgl.deleteBuffers(1, intBuffer); - } - glVertexBuffers.clear(); - } - - // This is synchronized because it is called from the GC thread. - synchronized static protected void finalizeVertexBufferObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glVertexBuffers.containsKey(res)) { - glVertexBuffers.put(res, true); - } - } - - protected static void deleteFinalizedVertexBufferObjects(PGL pgl) { - Set finalized = new HashSet(); - - for (GLResource res : glVertexBuffers.keySet()) { - if (glVertexBuffers.get(res)) { - finalized.add(res); - intBuffer.put(0, res.id); - if (pgl.threadIsCurrent()) pgl.deleteBuffers(1, intBuffer); - } - } - - for (GLResource res : finalized) { - glVertexBuffers.remove(res); - } - } - - protected static void removeVertexBufferObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glVertexBuffers.containsKey(res)) { - glVertexBuffers.remove(res); - } - } - */ - - // FrameBuffer Objects ------------------------------------------------------- - - /* - protected static int createFrameBufferObject(int context, PGL pgl) { - deleteFinalizedFrameBufferObjects(pgl); - - pgl.genFramebuffers(1, intBuffer); - int id = intBuffer.get(0); - - GLResource res = new GLResource(id, context); - if (!glFrameBuffers.containsKey(res)) { - glFrameBuffers.put(res, false); - } - - return id; - } - - protected static void deleteFrameBufferObject(int id, int context, PGL pgl) { - GLResource res = new GLResource(id, context); - if (glFrameBuffers.containsKey(res)) { - intBuffer.put(0, id); - if (pgl.threadIsCurrent()) pgl.deleteFramebuffers(1, intBuffer); - glFrameBuffers.remove(res); - } - } - - protected static void deleteAllFrameBufferObjects(PGL pgl) { - for (GLResource res : glFrameBuffers.keySet()) { - intBuffer.put(0, res.id); - if (pgl.threadIsCurrent()) pgl.deleteFramebuffers(1, intBuffer); - } - glFrameBuffers.clear(); - } - - // This is synchronized because it is called from the GC thread. - synchronized static protected void finalizeFrameBufferObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glFrameBuffers.containsKey(res)) { - glFrameBuffers.put(res, true); - } - } - - protected static void deleteFinalizedFrameBufferObjects(PGL pgl) { - Set finalized = new HashSet(); - - for (GLResource res : glFrameBuffers.keySet()) { - if (glFrameBuffers.get(res)) { - finalized.add(res); - intBuffer.put(0, res.id); - if (pgl.threadIsCurrent()) { - pgl.deleteFramebuffers(1, intBuffer); - } - } - } - - for (GLResource res : finalized) { - glFrameBuffers.remove(res); - } - } - - protected static void removeFrameBufferObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glFrameBuffers.containsKey(res)) { - glFrameBuffers.remove(res); - } - } -*/ - - // RenderBuffer Objects ------------------------------------------------------ - - /* - protected static int createRenderBufferObject(int context, PGL pgl) { - deleteFinalizedRenderBufferObjects(pgl); - - pgl.genRenderbuffers(1, intBuffer); - int id = intBuffer.get(0); - - GLResource res = new GLResource(id, context); - if (!glRenderBuffers.containsKey(res)) { - glRenderBuffers.put(res, false); - } - - return id; - } - - protected static void deleteRenderBufferObject(int id, int context, PGL pgl) { - GLResource res = new GLResource(id, context); - if (glRenderBuffers.containsKey(res)) { - intBuffer.put(0, id); - if (pgl.threadIsCurrent()) pgl.deleteRenderbuffers(1, intBuffer); - glRenderBuffers.remove(res); - } - } - - protected static void deleteAllRenderBufferObjects(PGL pgl) { - for (GLResource res : glRenderBuffers.keySet()) { - intBuffer.put(0, res.id); - if (pgl.threadIsCurrent()) pgl.deleteRenderbuffers(1, intBuffer); - } - glRenderBuffers.clear(); - } - - // This is synchronized because it is called from the GC thread. - synchronized static protected void finalizeRenderBufferObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glRenderBuffers.containsKey(res)) { - glRenderBuffers.put(res, true); - } - } - - protected static void deleteFinalizedRenderBufferObjects(PGL pgl) { - Set finalized = new HashSet(); - - for (GLResource res : glRenderBuffers.keySet()) { - if (glRenderBuffers.get(res)) { - finalized.add(res); - intBuffer.put(0, res.id); - if (pgl.threadIsCurrent()) pgl.deleteRenderbuffers(1, intBuffer); - } - } - - for (GLResource res : finalized) { - glRenderBuffers.remove(res); - } - } - - protected static void removeRenderBufferObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glRenderBuffers.containsKey(res)) { - glRenderBuffers.remove(res); - } - } - */ - - /* - // GLSL Program Objects ------------------------------------------------------ - - protected static int createGLSLProgramObject(int context, PGL pgl) { - deleteFinalizedGLSLProgramObjects(pgl); - - int id = pgl.createProgram(); - - GLResource res = new GLResource(id, context); - if (!glslPrograms.containsKey(res)) { - glslPrograms.put(res, false); - } - - return id; - } - - protected static void deleteGLSLProgramObject(int id, int context, PGL pgl) { - GLResource res = new GLResource(id, context); - if (glslPrograms.containsKey(res)) { - if (pgl.threadIsCurrent()) pgl.deleteProgram(res.id); - glslPrograms.remove(res); - } - } - - protected static void deleteAllGLSLProgramObjects(PGL pgl) { - for (GLResource res : glslPrograms.keySet()) { - if (pgl.threadIsCurrent()) pgl.deleteProgram(res.id); - } - glslPrograms.clear(); - } - - // This is synchronized because it is called from the GC thread. - synchronized static protected void finalizeGLSLProgramObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glslPrograms.containsKey(res)) { - glslPrograms.put(res, true); - } - } - - protected static void deleteFinalizedGLSLProgramObjects(PGL pgl) { - Set finalized = new HashSet(); - - for (GLResource res : glslPrograms.keySet()) { - if (glslPrograms.get(res)) { - finalized.add(res); - if (pgl.threadIsCurrent()) pgl.deleteProgram(res.id); - } - } - - for (GLResource res : finalized) { - glslPrograms.remove(res); - } - } - - protected static void removeGLSLProgramObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glslPrograms.containsKey(res)) { - glslPrograms.remove(res); - } - } - - // GLSL Vertex Shader Objects ------------------------------------------------ - - protected static int createGLSLVertShaderObject(int context, PGL pgl) { - deleteFinalizedGLSLVertShaderObjects(pgl); - - int id = pgl.createShader(PGL.VERTEX_SHADER); - - GLResource res = new GLResource(id, context); - if (!glslVertexShaders.containsKey(res)) { - glslVertexShaders.put(res, false); - } - - return id; - } - - protected static void deleteGLSLVertShaderObject(int id, int context, PGL pgl) { - GLResource res = new GLResource(id, context); - if (glslVertexShaders.containsKey(res)) { - if (pgl.threadIsCurrent()) pgl.deleteShader(res.id); - glslVertexShaders.remove(res); - } - } - - protected static void deleteAllGLSLVertShaderObjects(PGL pgl) { - for (GLResource res : glslVertexShaders.keySet()) { - if (pgl.threadIsCurrent()) pgl.deleteShader(res.id); - } - glslVertexShaders.clear(); - } - - // This is synchronized because it is called from the GC thread. - synchronized static protected void finalizeGLSLVertShaderObject(int id, - int context) { - GLResource res = new GLResource(id, context); - if (glslVertexShaders.containsKey(res)) { - glslVertexShaders.put(res, true); - } - } - - protected static void deleteFinalizedGLSLVertShaderObjects(PGL pgl) { - Set finalized = new HashSet(); - - for (GLResource res : glslVertexShaders.keySet()) { - if (glslVertexShaders.get(res)) { - finalized.add(res); - if (pgl.threadIsCurrent()) pgl.deleteShader(res.id); - } - } - - for (GLResource res : finalized) { - glslVertexShaders.remove(res); - } - } - - protected static void removeGLSLVertShaderObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glslVertexShaders.containsKey(res)) { - glslVertexShaders.remove(res); - } - } - - // GLSL Fragment Shader Objects ---------------------------------------------- - - protected static int createGLSLFragShaderObject(int context, PGL pgl) { - deleteFinalizedGLSLFragShaderObjects(pgl); - - int id = pgl.createShader(PGL.FRAGMENT_SHADER); - - GLResource res = new GLResource(id, context); - if (!glslFragmentShaders.containsKey(res)) { - glslFragmentShaders.put(res, false); - } - - return id; - } - - protected static void deleteGLSLFragShaderObject(int id, int context, PGL pgl) { - GLResource res = new GLResource(id, context); - if (glslFragmentShaders.containsKey(res)) { - if (pgl.threadIsCurrent()) pgl.deleteShader(res.id); - glslFragmentShaders.remove(res); - } - } - - protected static void deleteAllGLSLFragShaderObjects(PGL pgl) { - for (GLResource res : glslFragmentShaders.keySet()) { - if (pgl.threadIsCurrent()) pgl.deleteShader(res.id); - } - glslFragmentShaders.clear(); - } - - // This is synchronized because it is called from the GC thread. - synchronized static protected void finalizeGLSLFragShaderObject(int id, - int context) { - GLResource res = new GLResource(id, context); - if (glslFragmentShaders.containsKey(res)) { - glslFragmentShaders.put(res, true); - } - } - - protected static void deleteFinalizedGLSLFragShaderObjects(PGL pgl) { - Set finalized = new HashSet(); - - for (GLResource res : glslFragmentShaders.keySet()) { - if (glslFragmentShaders.get(res)) { - finalized.add(res); - if (pgl.threadIsCurrent()) pgl.deleteShader(res.id); - } - } - - for (GLResource res : finalized) { - glslFragmentShaders.remove(res); - } - } - - protected static void removeGLSLFragShaderObject(int id, int context) { - GLResource res = new GLResource(id, context); - if (glslFragmentShaders.containsKey(res)) { - glslFragmentShaders.remove(res); - } - } - */ - - // All OpenGL resources ------------------------------------------------------ - -// protected static void deleteFinalizedGLResources(PGL pgl) { -// deleteFinalizedTextureObjects(pgl); -// deleteFinalizedVertexBufferObjects(pgl); -// deleteFinalizedFrameBufferObjects(pgl); -// deleteFinalizedRenderBufferObjects(pgl); -// deleteFinalizedGLSLProgramObjects(pgl); -// deleteFinalizedGLSLVertShaderObjects(pgl); -// deleteFinalizedGLSLFragShaderObjects(pgl); -// } - - ////////////////////////////////////////////////////////////// // FRAMEBUFFERS @@ -1838,72 +1344,10 @@ public class PGraphicsOpenGL extends PGraphics { } -// protected void finalizePolyBuffers() { -// if (glPolyVertex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyVertex, polyBuffersContext); -// glPolyVertex = 0; -// } -// -// if (glPolyColor != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyColor, polyBuffersContext); -// glPolyColor = 0; -// } -// -// if (glPolyNormal != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyNormal, polyBuffersContext); -// glPolyNormal = 0; -// } -// -// if (glPolyTexcoord != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyTexcoord, polyBuffersContext); -// glPolyTexcoord = 0; -// } -// -// if (glPolyAmbient != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyAmbient, polyBuffersContext); -// glPolyAmbient = 0; -// } -// -// if (glPolySpecular != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolySpecular, polyBuffersContext); -// glPolySpecular = 0; -// } -// -// if (glPolyEmissive != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyEmissive, polyBuffersContext); -// glPolyEmissive = 0; -// } -// -// if (glPolyShininess != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyShininess, polyBuffersContext); -// glPolyShininess = 0; -// } -// -// for (String name: polyAttribs.keySet()) { -// VertexAttribute attrib = polyAttribs.get(name); -// if (attrib.glName != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(attrib.glName, polyBuffersContext); -// attrib.glName = 0; -// } -// } -// -// if (glPolyIndex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyIndex, polyBuffersContext); -// glPolyIndex = 0; -// } -// -// polyBuffersCreated = false; -// } - - protected void createLineBuffers() { if (!lineBuffersCreated || lineBufferContextIsOutdated()) { lineBuffersContext = pgl.getCurrentContext(); -// int sizef = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_FLOAT; -// int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; -// int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - bufLineVertex = new VertexBuffer(this, PGL.ARRAY_BUFFER, 3, PGL.SIZEOF_FLOAT); bufLineColor = new VertexBuffer(this, PGL.ARRAY_BUFFER, 1, PGL.SIZEOF_INT); bufLineAttrib = new VertexBuffer(this, PGL.ARRAY_BUFFER, 4, PGL.SIZEOF_FLOAT); @@ -1911,26 +1355,6 @@ public class PGraphicsOpenGL extends PGraphics { bufLineIndex = new VertexBuffer(this, PGL.ELEMENT_ARRAY_BUFFER, 1, PGL.SIZEOF_INDEX, true); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0); -// glLineVertex = createVertexBufferObject(lineBuffersContext, pgl); -// pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex); -// pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW); -// -// glLineColor = createVertexBufferObject(lineBuffersContext, pgl); -// pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor); -// pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW); -// -// glLineAttrib = createVertexBufferObject(lineBuffersContext, pgl); -// pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib); -// pgl.bufferData(PGL.ARRAY_BUFFER, 4 * sizef, null, PGL.STATIC_DRAW); -// -// pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); -// -// glLineIndex = createVertexBufferObject(lineBuffersContext, pgl); -// pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glLineIndex); -// pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW); -// -// pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0); - lineBuffersCreated = true; } } @@ -1979,39 +1403,10 @@ public class PGraphicsOpenGL extends PGraphics { } -// protected void finalizeLineBuffers() { -// if (glLineVertex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glLineVertex, lineBuffersContext); -// glLineVertex = 0; -// } -// -// if (glLineColor != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glLineColor, lineBuffersContext); -// glLineColor = 0; -// } -// -// if (glLineAttrib != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glLineAttrib, lineBuffersContext); -// glLineAttrib = 0; -// } -// -// if (glLineIndex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glLineIndex, lineBuffersContext); -// glLineIndex = 0; -// } -// -// lineBuffersCreated = false; -// } - - protected void createPointBuffers() { if (!pointBuffersCreated || pointBuffersContextIsOutdated()) { pointBuffersContext = pgl.getCurrentContext(); -// int sizef = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_FLOAT; -// int sizei = INIT_VERTEX_BUFFER_SIZE * PGL.SIZEOF_INT; -// int sizex = INIT_INDEX_BUFFER_SIZE * PGL.SIZEOF_INDEX; - bufPointVertex = new VertexBuffer(this, PGL.ARRAY_BUFFER, 3, PGL.SIZEOF_FLOAT); bufPointColor = new VertexBuffer(this, PGL.ARRAY_BUFFER, 1, PGL.SIZEOF_INT); bufPointAttrib = new VertexBuffer(this, PGL.ARRAY_BUFFER, 2, PGL.SIZEOF_FLOAT); @@ -2019,26 +1414,6 @@ public class PGraphicsOpenGL extends PGraphics { bufPointIndex = new VertexBuffer(this, PGL.ELEMENT_ARRAY_BUFFER, 1, PGL.SIZEOF_INDEX, true); pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0); -// glPointVertex = createVertexBufferObject(pointBuffersContext, pgl); -// pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex); -// pgl.bufferData(PGL.ARRAY_BUFFER, 3 * sizef, null, PGL.STATIC_DRAW); -// -// glPointColor = createVertexBufferObject(pointBuffersContext, pgl); -// pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor); -// pgl.bufferData(PGL.ARRAY_BUFFER, sizei, null, PGL.STATIC_DRAW); -// -// glPointAttrib = createVertexBufferObject(pointBuffersContext, pgl); -// pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib); -// pgl.bufferData(PGL.ARRAY_BUFFER, 2 * sizef, null, PGL.STATIC_DRAW); -// -// pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); -// -// glPointIndex = createVertexBufferObject(pointBuffersContext, pgl); -// pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, glPointIndex); -// pgl.bufferData(PGL.ELEMENT_ARRAY_BUFFER, sizex, null, PGL.STATIC_DRAW); -// -// pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0); - pointBuffersCreated = true; } } @@ -2085,60 +1460,6 @@ public class PGraphicsOpenGL extends PGraphics { } -// protected void finalizePointBuffers() { -// if (glPointVertex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPointVertex, pointBuffersContext); -// glPointVertex = 0; -// } -// -// if (glPointColor != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPointColor, pointBuffersContext); -// glPointColor = 0; -// } -// -// if (glPointAttrib != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPointAttrib, pointBuffersContext); -// glPointAttrib = 0; -// } -// -// if (glPointIndex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPointIndex, pointBuffersContext); -// glPointIndex = 0; -// } -// -// pointBuffersCreated = false; -// } - - -// @Override -// public void requestFocus() { -// pgl.requestFocus(); -// } - - - /** - * OpenGL cannot draw until a proper native peer is available, so this - * returns the value of PApplet.isDisplayable() (inherited from Component). - */ -// @Override -// public boolean canDraw() { -// return pgl.canDraw(); -// } - - -// @Override -// public void requestDraw() { -// if (primarySurface) { -// if (initialized) { -// if (sized) pgl.reinitSurface(); -// if (parent.canDraw()) pgl.requestDraw(); -// } else { -// initPrimary(); -// } -// } -// } - - @Override public void beginDraw() { if (primaryGraphics) { @@ -2216,12 +1537,6 @@ public class PGraphicsOpenGL extends PGraphics { } - // Factory method - protected PGL createPGL(PGraphicsOpenGL pg) { - return new PJOGL(pg); - } - - protected PGraphicsOpenGL getPrimaryPG() { if (primaryGraphics) { return this; @@ -4168,7 +3483,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override public float textAscent() { if (textFont == null) defaultFontOrDeath("textAscent"); - Font font = (Font) textFont.getNative(); + Object font = textFont.getNative(); float ascent = 0; if (font != null) ascent = pgl.getFontAscent(font); if (ascent == 0) ascent = super.textAscent(); @@ -4179,7 +3494,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override public float textDescent() { if (textFont == null) defaultFontOrDeath("textDescent"); - Font font = (Font) textFont.getNative(); + Object font = textFont.getNative(); float descent = 0; if (font != null) descent = pgl.getFontDescent(font); if (descent == 0) descent = super.textDescent(); @@ -4189,7 +3504,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected float textWidthImpl(char buffer[], int start, int stop) { - Font font = (Font) textFont.getNative(); + Object font = textFont.getNative(); float twidth = 0; if (font != null) twidth = pgl.getTextWidth(font, buffer, start, stop); if (twidth == 0) twidth = super.textWidthImpl(buffer, start, stop); @@ -4199,7 +3514,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected void handleTextSize(float size) { - Font font = (Font) textFont.getNative(); + Object font = textFont.getNative(); if (font != null) { Object dfont = pgl.getDerivedFont(font, size); textFont.setNative(dfont); @@ -6094,7 +5409,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void drawPixels(int x, int y, int w, int h) { - int f = (int)getPixelScale(); + int f = (int)pgl.getPixelScale(); int len = f * w * f * h; if (nativePixels == null || nativePixels.length < len) { nativePixels = new int[len]; @@ -6452,7 +5767,7 @@ public class PGraphicsOpenGL extends PGraphics { boolean needEndDraw = false; if (primaryGraphics) { - pgl.requestFBOLayer(); + pgl.enableFBOLayer(); } else if (!drawing) { beginDraw(); needEndDraw = true; @@ -6528,7 +5843,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void copy(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) { - if (primaryGraphics) pgl.requestFBOLayer(); + if (primaryGraphics) pgl.enableFBOLayer(); loadTexture(); if (filterTexture == null || filterTexture.contextIsOutdated()) { filterTexture = new Texture(this, texture.width, texture.height, @@ -6947,7 +6262,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void initPrimary() { -// pgl.initSurface(quality); + pgl.initSurface(smooth); if (texture != null) { removeCache(this); texture = ptexture = null; diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index 7b7473e75..2ac187ebc 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -58,6 +58,7 @@ import com.jogamp.opengl.glu.GLUtessellatorCallbackAdapter; import processing.core.PApplet; import processing.core.PGraphics; +import processing.core.PSurface; public class PJOGL extends PGL { @@ -142,6 +143,28 @@ public class PJOGL extends PGL { } + @Override + public Object getNative() { + return sketch.getSurface().getNative(); + } + + + @Override + protected void setFrameRate(float fps) {} + + + @Override + protected void initSurface(int antialias) {} + + + @Override + protected void reinitSurface() {} + + + @Override + protected void registerListeners() {} + + /////////////////////////////////////////////////////////////// // Public methods to get/set renderer's properties @@ -186,6 +209,19 @@ public class PJOGL extends PGL { } + @Override + protected float getPixelScale() { + PSurface surf = sketch.getSurface(); + if (surf == null) { + return graphics.pixelDensity; + } else if (surf instanceof PSurfaceJOGL) { + return ((PSurfaceJOGL)surf).getPixelScale(); + } else { + throw new RuntimeException("Renderer cannot find a JOGL surface"); + } + } + + @Override protected void getGL(PGL pgl) { PJOGL pjogl = (PJOGL)pgl; @@ -241,6 +277,45 @@ public class PJOGL extends PGL { } + @Override + protected void initFBOLayer() { + if (0 < sketch.frameCount) { + // Copy the contents of the front and back screen buffers to the textures + // of the FBO, so they are properly initialized. Note that the front buffer + // of the default framebuffer (the screen) contains the previous frame: + // https://www.opengl.org/wiki/Default_Framebuffer + // so it is copied to the front texture of the FBO layer: + if (pclearColor || 0 < pgeomCount || !sketch.isLooping()) { + readBuffer(FRONT); + } else { + // ...except when the previous frame has not been cleared and nothing was + // rendered while looping. In this case the back buffer, which holds the + // initial state of the previous frame, still contains the most up-to-date + // screen state. + readBuffer(BACK); + } + bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0)); + framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, + TEXTURE_2D, glColorTex.get(frontTex), 0); + drawBuffer(COLOR_ATTACHMENT0); + blitFramebuffer(0, 0, fboWidth, fboHeight, + 0, 0, fboWidth, fboHeight, + COLOR_BUFFER_BIT, NEAREST); + + readBuffer(BACK); + bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0)); + framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, + TEXTURE_2D, glColorTex.get(backTex), 0); + drawBuffer(COLOR_ATTACHMENT0); + blitFramebuffer(0, 0, fboWidth, fboHeight, + 0, 0, fboWidth, fboHeight, + COLOR_BUFFER_BIT, NEAREST); + + bindFramebufferImpl(FRAMEBUFFER, 0); + } + } + + @Override protected void beginGL() { if (gl2x != null) { @@ -306,7 +381,6 @@ public class PJOGL extends PGL { public void init(GLAutoDrawable glDrawable) { - firstFrame = true; capabilities = glDrawable.getChosenGLCapabilities(); if (!hasFBOs()) { throw new RuntimeException(MISSING_FBO_ERROR); @@ -1051,7 +1125,7 @@ public class PJOGL extends PGL { @Override public void viewport(int x, int y, int w, int h) { - float scale = graphics.getPixelScale(); + float scale = getPixelScale(); viewportImpl((int)scale * x, (int)(scale * y), (int)(scale * w), (int)(scale * h)); } @@ -1561,7 +1635,7 @@ public class PJOGL extends PGL { @Override public void scissor(int x, int y, int w, int h) { - float scale = graphics.getPixelScale(); + float scale = getPixelScale(); gl.glScissor((int)scale * x, (int)(scale * y), (int)(scale * w), (int)(scale * h)); // gl.glScissor(x, y, w, h); } diff --git a/core/src/processing/opengl/PShader.java b/core/src/processing/opengl/PShader.java index a05531fce..0d460c124 100644 --- a/core/src/processing/opengl/PShader.java +++ b/core/src/processing/opengl/PShader.java @@ -1,14 +1,16 @@ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,7 +21,7 @@ Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + */ package processing.opengl; @@ -305,24 +307,6 @@ public class PShader implements PConstants { } -// @Override -// protected void finalize() throws Throwable { -// try { -// if (glVertex != 0) { -// PGraphicsOpenGL.finalizeGLSLVertShaderObject(glVertex, context); -// } -// if (glFragment != 0) { -// PGraphicsOpenGL.finalizeGLSLFragShaderObject(glFragment, context); -// } -// if (glProgram != 0) { -// PGraphicsOpenGL.finalizeGLSLProgramObject(glProgram, context); -// } -// } finally { -// super.finalize(); -// } -// } - - public void setVertexShader(String vertFilename) { this.vertexFilename = vertFilename; vertexShaderSource = pgl.loadVertexShader(vertFilename); @@ -1336,7 +1320,7 @@ public class PShader implements PConstants { if (-1 < normalLoc) pgl.disableVertexAttribArray(normalLoc); if (-1 < ppixelsLoc) { - pgl.requestFBOLayer(); + pgl.enableFBOLayer(); pgl.activeTexture(PGL.TEXTURE0 + ppixelsUnit); currentPG.unbindFrontTexture(); pgl.activeTexture(PGL.TEXTURE0); diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 2a5ad03f8..d62f19f3f 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -1,14 +1,16 @@ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas Copyright (c) 2012-15 The Processing Foundation - Copyright (c) 2011-12 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, version 2.1. + License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,7 +21,7 @@ Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + */ package processing.opengl; @@ -518,101 +520,6 @@ public class PShapeOpenGL extends PShape { } -// @Override -// protected void finalize() throws Throwable { -// try { -// finalizePolyBuffers(); -// finalizeLineBuffers(); -// finalizePointBuffers(); -// } finally { -// super.finalize(); -// } -// } - - -// protected void finalizePolyBuffers() { -// if (glPolyVertex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyVertex, context); -// } -// -// if (glPolyColor != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyColor, context); -// } -// -// if (glPolyNormal != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyNormal, context); -// } -// -// if (glPolyTexcoord != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyTexcoord, context); -// } -// -// if (glPolyAmbient != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyAmbient, context); -// } -// -// if (glPolySpecular != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolySpecular, context); -// } -// -// if (glPolyEmissive != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyEmissive, context); -// } -// -// if (glPolyShininess != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyShininess, context); -// } -// -// for (VertexAttribute attrib: polyAttribs.values()) { -// if (attrib.glName != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(attrib.glName, context); -// } -// } -// -// -// if (glPolyIndex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPolyIndex, context); -// } -// } - - -// protected void finalizeLineBuffers() { -// if (glLineVertex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glLineVertex, context); -// } -// -// if (glLineColor != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glLineColor, context); -// } -// -// if (glLineAttrib != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glLineAttrib, context); -// } -// -// if (glLineIndex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glLineIndex, context); -// } -// } -// -// -// protected void finalizePointBuffers() { -// if (glPointVertex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPointVertex, context); -// } -// -// if (glPointColor != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPointColor, context); -// } -// -// if (glPointAttrib != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPointAttrib, context); -// } -// -// if (glPointIndex != 0) { -// PGraphicsOpenGL.finalizeVertexBufferObject(glPointIndex, context); -// } -// } - /////////////////////////////////////////////////////////// // diff --git a/core/src/processing/opengl/PSurfaceJOGL.java b/core/src/processing/opengl/PSurfaceJOGL.java index 9eea45ea9..7fdf86fc2 100644 --- a/core/src/processing/opengl/PSurfaceJOGL.java +++ b/core/src/processing/opengl/PSurfaceJOGL.java @@ -758,7 +758,7 @@ public class PSurfaceJOGL implements PSurface { // ((c >> 0) & 0xff) / 255f, // ((c >> 24) & 0xff) / 255f); // pgl.clear(PGL.COLOR_BUFFER_BIT); - pgl.requestFBOLayerReset(); + pgl.resetFBOLayer(); // final float[] valReqSurfacePixelScale = window.getRequestedSurfaceScale(new float[2]); window.getCurrentSurfaceScale(currentPixelScale); // final float[] nativeSurfacePixelScale = window.getMaximumSurfaceScale(new float[2]); diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 446a99349..c0e188b4d 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -1,12 +1,16 @@ -/* - Part of the Processing project - http://processing.org +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - Copyright (c) 2011-12 Ben Fry and Casey Reas +/* + Processing OpenGL (c) 2011-2015 Andres Colubri + + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -17,7 +21,7 @@ Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + */ package processing.opengl; @@ -169,18 +173,6 @@ public class Texture implements PConstants { } -// @Override -// protected void finalize() throws Throwable { -// try { -// if (glName != 0) { -// PGraphicsOpenGL.finalizeTextureObject(glName, context); -// } -// } finally { -// super.finalize(); -// } -// } - - //////////////////////////////////////////////////////////// // Init, resize methods diff --git a/core/src/processing/opengl/VertexBuffer.java b/core/src/processing/opengl/VertexBuffer.java index 0fb55a874..f3982c846 100644 --- a/core/src/processing/opengl/VertexBuffer.java +++ b/core/src/processing/opengl/VertexBuffer.java @@ -1,3 +1,28 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Processing OpenGL (c) 2011-2015 Andres Colubri + + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + */ + package processing.opengl; import processing.opengl.PGraphicsOpenGL.GLResourceVertexBuffer; diff --git a/core/src/processing/opengl/shaders/ColorFrag.glsl b/core/src/processing/opengl/shaders/ColorFrag.glsl index d5d23ae22..92cb66a3c 100644 --- a/core/src/processing/opengl/shaders/ColorFrag.glsl +++ b/core/src/processing/opengl/shaders/ColorFrag.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/core/src/processing/opengl/shaders/ColorVert.glsl b/core/src/processing/opengl/shaders/ColorVert.glsl index 3736ffd2e..7788e7075 100644 --- a/core/src/processing/opengl/shaders/ColorVert.glsl +++ b/core/src/processing/opengl/shaders/ColorVert.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,8 +21,6 @@ Boston, MA 02111-1307 USA */ -#define PROCESSING_COLOR_SHADER - uniform mat4 transformMatrix; attribute vec4 position; diff --git a/core/src/processing/opengl/shaders/LightFrag.glsl b/core/src/processing/opengl/shaders/LightFrag.glsl index b566c8e5b..b8fa80b48 100644 --- a/core/src/processing/opengl/shaders/LightFrag.glsl +++ b/core/src/processing/opengl/shaders/LightFrag.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -17,7 +20,7 @@ Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - + #ifdef GL_ES precision mediump float; precision mediump int; diff --git a/core/src/processing/opengl/shaders/LightVert-vc4.glsl b/core/src/processing/opengl/shaders/LightVert-vc4.glsl index 38366fee1..f7984da81 100644 --- a/core/src/processing/opengl/shaders/LightVert-vc4.glsl +++ b/core/src/processing/opengl/shaders/LightVert-vc4.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,8 +21,6 @@ Boston, MA 02111-1307 USA */ -#define PROCESSING_LIGHT_SHADER - uniform mat4 modelviewMatrix; uniform mat4 transformMatrix; uniform mat3 normalMatrix; diff --git a/core/src/processing/opengl/shaders/LightVert.glsl b/core/src/processing/opengl/shaders/LightVert.glsl index 0c351aab7..d4ca719d3 100644 --- a/core/src/processing/opengl/shaders/LightVert.glsl +++ b/core/src/processing/opengl/shaders/LightVert.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,8 +21,6 @@ Boston, MA 02111-1307 USA */ -#define PROCESSING_LIGHT_SHADER - uniform mat4 modelviewMatrix; uniform mat4 transformMatrix; uniform mat3 normalMatrix; @@ -29,7 +30,7 @@ uniform vec4 lightPosition[8]; uniform vec3 lightNormal[8]; uniform vec3 lightAmbient[8]; uniform vec3 lightDiffuse[8]; -uniform vec3 lightSpecular[8]; +uniform vec3 lightSpecular[8]; uniform vec3 lightFalloff[8]; uniform vec2 lightSpot[8]; @@ -47,8 +48,7 @@ varying vec4 backVertColor; const float zero_float = 0.0; const float one_float = 1.0; -const vec3 zero_vec3 = vec3(0.0); -const vec3 minus_one_vec3 = vec3(0.0-1.0); +const vec3 zero_vec3 = vec3(0); float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) { vec3 lpv = lightPos - vertPos; @@ -60,7 +60,7 @@ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) { float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) { vec3 lpv = normalize(lightPos - vertPos); - vec3 nln = minus_one_vec3 * lightNorm; + vec3 nln = -one_float * lightNorm; float spotCos = dot(nln, lpv); return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); } @@ -84,7 +84,7 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * normal); - vec3 ecNormalInv = ecNormal * minus_one_vec3; + vec3 ecNormalInv = ecNormal * -one_float; // Light calculations vec3 totalAmbient = vec3(0, 0, 0); @@ -109,7 +109,7 @@ void main() { if (isDir) { falloff = one_float; - lightDir = minus_one_vec3 * lightNormal[i]; + lightDir = -one_float * lightNormal[i]; } else { falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]); lightDir = normalize(lightPos - ecVertex); diff --git a/core/src/processing/opengl/shaders/LineFrag.glsl b/core/src/processing/opengl/shaders/LineFrag.glsl index dc08a3fa2..a91a87ff6 100644 --- a/core/src/processing/opengl/shaders/LineFrag.glsl +++ b/core/src/processing/opengl/shaders/LineFrag.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/core/src/processing/opengl/shaders/LineVert.glsl b/core/src/processing/opengl/shaders/LineVert.glsl index d16f4d519..7c7da5164 100644 --- a/core/src/processing/opengl/shaders/LineVert.glsl +++ b/core/src/processing/opengl/shaders/LineVert.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/core/src/processing/opengl/shaders/MaskFrag.glsl b/core/src/processing/opengl/shaders/MaskFrag.glsl index 508a39649..c6e67b86d 100644 --- a/core/src/processing/opengl/shaders/MaskFrag.glsl +++ b/core/src/processing/opengl/shaders/MaskFrag.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2012-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/core/src/processing/opengl/shaders/PointFrag.glsl b/core/src/processing/opengl/shaders/PointFrag.glsl index d5d23ae22..92cb66a3c 100644 --- a/core/src/processing/opengl/shaders/PointFrag.glsl +++ b/core/src/processing/opengl/shaders/PointFrag.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/core/src/processing/opengl/shaders/PointVert.glsl b/core/src/processing/opengl/shaders/PointVert.glsl index c677ce75b..a2682c379 100644 --- a/core/src/processing/opengl/shaders/PointVert.glsl +++ b/core/src/processing/opengl/shaders/PointVert.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,8 +21,6 @@ Boston, MA 02111-1307 USA */ -#define PROCESSING_POINT_SHADER - uniform mat4 projectionMatrix; uniform mat4 modelviewMatrix; diff --git a/core/src/processing/opengl/shaders/TexFrag.glsl b/core/src/processing/opengl/shaders/TexFrag.glsl index f041e61d1..e6e245daf 100644 --- a/core/src/processing/opengl/shaders/TexFrag.glsl +++ b/core/src/processing/opengl/shaders/TexFrag.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/core/src/processing/opengl/shaders/TexLightFrag.glsl b/core/src/processing/opengl/shaders/TexLightFrag.glsl index f423e49d3..3d22df7bd 100644 --- a/core/src/processing/opengl/shaders/TexLightFrag.glsl +++ b/core/src/processing/opengl/shaders/TexLightFrag.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/core/src/processing/opengl/shaders/TexLightVert-vc4.glsl b/core/src/processing/opengl/shaders/TexLightVert-vc4.glsl index daa4680fb..d34e4f876 100644 --- a/core/src/processing/opengl/shaders/TexLightVert-vc4.glsl +++ b/core/src/processing/opengl/shaders/TexLightVert-vc4.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,8 +21,6 @@ Boston, MA 02111-1307 USA */ -#define PROCESSING_TEXLIGHT_SHADER - uniform mat4 modelviewMatrix; uniform mat4 transformMatrix; uniform mat3 normalMatrix; diff --git a/core/src/processing/opengl/shaders/TexLightVert.glsl b/core/src/processing/opengl/shaders/TexLightVert.glsl index 478c91ca2..5deb09956 100644 --- a/core/src/processing/opengl/shaders/TexLightVert.glsl +++ b/core/src/processing/opengl/shaders/TexLightVert.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,8 +21,6 @@ Boston, MA 02111-1307 USA */ -#define PROCESSING_TEXLIGHT_SHADER - uniform mat4 modelviewMatrix; uniform mat4 transformMatrix; uniform mat3 normalMatrix; @@ -30,7 +31,7 @@ uniform vec4 lightPosition[8]; uniform vec3 lightNormal[8]; uniform vec3 lightAmbient[8]; uniform vec3 lightDiffuse[8]; -uniform vec3 lightSpecular[8]; +uniform vec3 lightSpecular[8]; uniform vec3 lightFalloff[8]; uniform vec2 lightSpot[8]; @@ -50,8 +51,7 @@ varying vec4 vertTexCoord; const float zero_float = 0.0; const float one_float = 1.0; -const vec3 zero_vec3 = vec3(0.0); -const vec3 minus_one_vec3 = vec3(0.0-1.0); +const vec3 zero_vec3 = vec3(0); float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) { vec3 lpv = lightPos - vertPos; @@ -63,7 +63,7 @@ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) { float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) { vec3 lpv = normalize(lightPos - vertPos); - vec3 nln = minus_one_vec3 * lightNorm; + vec3 nln = -one_float * lightNorm; float spotCos = dot(nln, lpv); return spotCos <= minCos ? zero_float : pow(spotCos, spotExp); } @@ -87,7 +87,7 @@ void main() { // Normal vector in eye coordinates vec3 ecNormal = normalize(normalMatrix * normal); - vec3 ecNormalInv = ecNormal * minus_one_vec3; + vec3 ecNormalInv = ecNormal * -one_float; // Light calculations vec3 totalAmbient = vec3(0, 0, 0); @@ -112,7 +112,7 @@ void main() { if (isDir) { falloff = one_float; - lightDir = minus_one_vec3 * lightNormal[i]; + lightDir = -one_float * lightNormal[i]; } else { falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]); lightDir = normalize(lightPos - ecVertex); diff --git a/core/src/processing/opengl/shaders/TexVert.glsl b/core/src/processing/opengl/shaders/TexVert.glsl index 87f101536..44889eb40 100644 --- a/core/src/processing/opengl/shaders/TexVert.glsl +++ b/core/src/processing/opengl/shaders/TexVert.glsl @@ -1,7 +1,10 @@ /* - Part of the Processing project - http://processing.org + Processing OpenGL (c) 2011-2015 Andres Colubri - Copyright (c) 2011-13 Ben Fry and Casey Reas + Part of the Processing project - http://processing.org + Copyright (c) 2001-04 Massachusetts Institute of Technology + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,8 +21,6 @@ Boston, MA 02111-1307 USA */ -#define PROCESSING_TEXTURE_SHADER - uniform mat4 transformMatrix; uniform mat4 texMatrix;