Skip to content

Commit 5579eaa

Browse files
committed
approach as suggested by @codeanticode
Signed-off-by: Umair Khan <[email protected]>
1 parent e324198 commit 5579eaa

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/in/omerjerk/processing/video/android/Capture.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import android.view.SurfaceHolder;
1919
import processing.core.PConstants;
2020
import processing.core.PApplet;
21+
import processing.core.PGraphics;
2122
import processing.core.PImage;
23+
import processing.opengl.PGL;
2224
import processing.opengl.PGraphicsOpenGL;
2325
import processing.opengl.Texture;
2426

@@ -53,6 +55,9 @@ public static void log(String log) {
5355
private Texture customTexture;
5456
private PGraphicsOpenGL pg;
5557
private IntBuffer pixelBuffer;
58+
59+
private PGraphicsOpenGL destpg;
60+
PGL pgl;
5661

5762
private CameraHandler mCameraHandler;
5863

@@ -82,7 +87,7 @@ public Capture(final PApplet applet, int width, int height) {
8287
customTexture = new Texture(pg, width, height);
8388
customTexture.invertedY(true);
8489
log("cusotm texture address = " + customTexture.glName);
85-
pg.setCache(this, customTexture);
90+
// pg.setCache(this, customTexture);
8691
applet.runOnUiThread(new Runnable() {
8792
@Override
8893
public void run() {
@@ -291,11 +296,36 @@ public void run() {
291296
surfaceTexture.getTransformMatrix(mSTMatrix);
292297
mFullScreen.drawFrame(mTextureId, mSTMatrix);
293298

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+
/*
294324
pixelBuffer.position(0);
295325
GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer);
296326
pixelBuffer.position(0);
297327
pixelBuffer.get(Capture.this.pixels);
298-
updatePixels();
328+
updatePixels(); */
299329

300330
//Fall back to default frame buffer
301331
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

0 commit comments

Comments
 (0)