|
18 | 18 | import android.view.SurfaceHolder;
|
19 | 19 | import processing.core.PConstants;
|
20 | 20 | import processing.core.PApplet;
|
| 21 | +import processing.core.PGraphics; |
21 | 22 | import processing.core.PImage;
|
| 23 | +import processing.opengl.PGL; |
22 | 24 | import processing.opengl.PGraphicsOpenGL;
|
23 | 25 | import processing.opengl.Texture;
|
24 | 26 |
|
@@ -53,6 +55,9 @@ public static void log(String log) {
|
53 | 55 | private Texture customTexture;
|
54 | 56 | private PGraphicsOpenGL pg;
|
55 | 57 | private IntBuffer pixelBuffer;
|
| 58 | + |
| 59 | + private PGraphicsOpenGL destpg; |
| 60 | + PGL pgl; |
56 | 61 |
|
57 | 62 | private CameraHandler mCameraHandler;
|
58 | 63 |
|
@@ -82,7 +87,7 @@ public Capture(final PApplet applet, int width, int height) {
|
82 | 87 | customTexture = new Texture(pg, width, height);
|
83 | 88 | customTexture.invertedY(true);
|
84 | 89 | log("cusotm texture address = " + customTexture.glName);
|
85 |
| - pg.setCache(this, customTexture); |
| 90 | +// pg.setCache(this, customTexture); |
86 | 91 | applet.runOnUiThread(new Runnable() {
|
87 | 92 | @Override
|
88 | 93 | public void run() {
|
@@ -291,11 +296,36 @@ public void run() {
|
291 | 296 | surfaceTexture.getTransformMatrix(mSTMatrix);
|
292 | 297 | mFullScreen.drawFrame(mTextureId, mSTMatrix);
|
293 | 298 |
|
| 299 | + if (destpg == null) { |
| 300 | + destpg = (PGraphicsOpenGL) parent.createGraphics(width, height, P2D); |
| 301 | + |
| 302 | + destpg.beginDraw(); |
| 303 | + destpg.background(0, 0); |
| 304 | + pgl = destpg.beginPGL(); |
| 305 | + pgl.drawTexture(PGL.TEXTURE_2D, customTexture.glName, width, height, |
| 306 | + 0, 0, width, height); |
| 307 | + destpg.endPGL(); |
| 308 | + destpg.endDraw(); |
| 309 | + |
| 310 | + // Uses the PGraphics texture as the cache object for the image |
| 311 | + Texture tex = destpg.getTexture(); |
| 312 | + pg.setCache(Capture.this, tex); |
| 313 | + } else { |
| 314 | + destpg.beginDraw(); |
| 315 | + destpg.background(0, 0); |
| 316 | + pgl = destpg.beginPGL(); |
| 317 | + pgl.drawTexture(PGL.TEXTURE_2D, customTexture.glName, width, height, |
| 318 | + 0, 0, width, height); |
| 319 | + destpg.endPGL(); |
| 320 | + destpg.endDraw(); |
| 321 | + } |
| 322 | + |
| 323 | + /* |
294 | 324 | pixelBuffer.position(0);
|
295 | 325 | GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer);
|
296 | 326 | pixelBuffer.position(0);
|
297 | 327 | pixelBuffer.get(Capture.this.pixels);
|
298 |
| - updatePixels(); |
| 328 | + updatePixels(); */ |
299 | 329 |
|
300 | 330 | //Fall back to default frame buffer
|
301 | 331 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
|
|
0 commit comments