diff --git a/android/core/src/processing/core/PGraphics.java b/android/core/src/processing/core/PGraphics.java index 1909248f1..7cf888e51 100644 --- a/android/core/src/processing/core/PGraphics.java +++ b/android/core/src/processing/core/PGraphics.java @@ -2542,6 +2542,9 @@ public class PGraphics extends PImage implements PConstants { } + public void initCache(PImage img) { // ignore + } + ////////////////////////////////////////////////////////////// diff --git a/android/core/src/processing/core/PImage.java b/android/core/src/processing/core/PImage.java index fa16bb4bd..d6b92af80 100644 --- a/android/core/src/processing/core/PImage.java +++ b/android/core/src/processing/core/PImage.java @@ -352,6 +352,7 @@ public class PImage implements PConstants, Cloneable { } + parent.g.initCache(this); if (cacheMap != null) { for (PGraphics pg: cacheMap.keySet()) { Object obj = cacheMap.get(pg); @@ -370,7 +371,7 @@ public class PImage implements PConstants, Cloneable { } } } - } + } } diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 156057374..31274164b 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5389,6 +5389,18 @@ public class PGraphicsOpenGL extends PGraphics { return tex; } + + public void initCache(PImage img) { + Texture tex = (Texture)img.getCache(pgPrimary); + if (tex == null) { + tex = addTexture(img); + } else { + if (tex.contextIsOutdated()) { + tex = addTexture(img); + } + } + } + /** * This utility method creates a texture for the provided image, and adds it @@ -5424,7 +5436,7 @@ public class PGraphicsOpenGL extends PGraphics { img.setCache(pgPrimary, tex); return tex; } - + protected Texture addTexture(PImage img, Texture.Parameters params) { Texture tex = new Texture(img.parent, img.width, img.height, params); diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 98e5c9886..313c77bd1 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -3326,7 +3326,10 @@ public class PGraphics extends PImage implements PConstants { } - + public void initCache(PImage img) { // ignore + } + + ////////////////////////////////////////////////////////////// // SHAPE diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index b69c30a41..2b67f7e82 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -475,10 +475,11 @@ public class PImage implements PConstants, Cloneable { * @usage web_application */ public void loadPixels() { // ignore - if (pixels == null) { - pixels = new int[width * height]; - } + if (pixels == null || pixels.length != width*height) { + pixels = new int[width*height]; + } + parent.g.initCache(this); if (cacheMap != null) { for (PGraphics pg: cacheMap.keySet()) { Object obj = cacheMap.get(pg); @@ -490,7 +491,7 @@ public class PImage implements PConstants, Cloneable { } if (loadPixelsMethod != null) { - try { + try { loadPixelsMethod.invoke(obj, new Object[] { pixels }); } catch (Exception e) { e.printStackTrace(); diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 156057374..31274164b 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -5389,6 +5389,18 @@ public class PGraphicsOpenGL extends PGraphics { return tex; } + + public void initCache(PImage img) { + Texture tex = (Texture)img.getCache(pgPrimary); + if (tex == null) { + tex = addTexture(img); + } else { + if (tex.contextIsOutdated()) { + tex = addTexture(img); + } + } + } + /** * This utility method creates a texture for the provided image, and adds it @@ -5424,7 +5436,7 @@ public class PGraphicsOpenGL extends PGraphics { img.setCache(pgPrimary, tex); return tex; } - + protected Texture addTexture(PImage img, Texture.Parameters params) { Texture tex = new Texture(img.parent, img.width, img.height, params); diff --git a/java/libraries/video/src/processing/video/Capture.java b/java/libraries/video/src/processing/video/Capture.java index acecff4ff..fc9af182a 100644 --- a/java/libraries/video/src/processing/video/Capture.java +++ b/java/libraries/video/src/processing/video/Capture.java @@ -360,7 +360,6 @@ public class Capture extends PImage implements PConstants { ByteBuffer byteBuffer = natBuffer.getByteBuffer(); try { - PApplet.println("copy buffer to sink..."); sinkCopyMethod.invoke(bufferSink, new Object[] { natBuffer, byteBuffer, bufWidth, bufHeight }); } catch (Exception e) { e.printStackTrace();