diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index e7bacae17..3720b9218 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -1585,11 +1585,6 @@ public class PApplet extends Activity implements PConstants, Runnable { pg.setPrimary(false); pg.setSize(iwidth, iheight); - // In the case of A3D, the first beginDraw/endDraw - // call is needed to initialize the offscreen buffers. - pg.beginDraw(); - pg.endDraw(); - return pg; } diff --git a/android/core/src/processing/core/PGL.java b/android/core/src/processing/core/PGL.java index 6daa63997..34dd75b67 100644 --- a/android/core/src/processing/core/PGL.java +++ b/android/core/src/processing/core/PGL.java @@ -305,8 +305,6 @@ public class PGL { // Intialization, finalization - // TODO: implement double buffering support in offscreen rendering. - public PGL(PGraphicsAndroid3D pg) { this.pg = pg; @@ -320,6 +318,19 @@ public class PGL { } + public void initPrimarySurface(int antialias) { + // We do the initialization in updatePrimary() because + // at the moment initPrimarySurface() gets called we + // cannot rely on the GL surface actually being + // available. + } + + + public void initOffscreenSurface(PGL primary) { + initialized = true; + } + + public void updatePrimary() { if (!initialized) { String ext = GLES20.glGetString(GLES20.GL_EXTENSIONS); @@ -374,61 +385,6 @@ public class PGL { gl = primary.gl; } - - - public void initPrimarySurface(int antialias) { - } - - - public void initOffscreenSurface(PGL primary) { - - /* - offscreenTexCrop = new int[4]; - offscreenTexCrop[0] = 0; - offscreenTexCrop[1] = 0; - offscreenTexCrop[2] = width; - offscreenTexCrop[3] = height; - - offscreenImages = new PImage[2]; - offscreenParams = new PTexture.Parameters[2]; - // Linear filtering is needed to keep decent image quality when rendering - // texture at a size different from its original resolution. This is expected - // to happen for offscreen rendering. - offscreenParams[0] = new PTexture.Parameters(ARGB, BILINEAR); - offscreenParams[1] = new PTexture.Parameters(ARGB, BILINEAR); - offscreenImages[0] = parent.createImage(width, height, ARGB, offscreenParams[0]); - offscreenImages[1] = parent.createImage(width, height, ARGB, offscreenParams[1]); - - - offscreenTextures = new PTexture[2]; - offscreenTextures[0] = addTexture(offscreenImages[0]); - offscreenTextures[1] = addTexture(offscreenImages[1]); - - // Drawing textures are marked as flipped along Y to ensure they are properly - // rendered by Processing, which has inverted Y axis with respect to - // OpenGL. - offscreenTextures[0].setFlippedY(true); - offscreenTextures[1].setFlippedY(true); - - offscreenIndex = 0; - - - - - - offscreenFramebuffer = new PFramebuffer(parent, offscreenTextures[0].glWidth, offscreenTextures[0].glHeight, - 1, 1, offscreenDepthBits, offscreenStencilBits, false); - - // The image texture points to the current offscreen texture. - texture = offscreenTextures[offscreenIndex]; - this.setCache(a3d, offscreenTextures[offscreenIndex]); - this.setParams(a3d, offscreenParams[offscreenIndex]); - */ - - - initialized = true; - } - /////////////////////////////////////////////////////////////////////////////////// @@ -488,23 +444,10 @@ public class PGL { public void beginOffscreenDraw(boolean clear) { - /* - // Drawing contents of back color buffer as background. - gl.glClearColor(0, 0, 0, 0); - if (clear || frame == 0) { - // No need to draw back color buffer. - GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); - } else { - GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT); - // Render previous draw texture as background. - drawOffscreenTexture((offscreenIndex + 1) % 2); - } - */ } public void endOffscreenDraw(boolean clear0) { - //swapOffscreenIndex(); } @@ -795,7 +738,7 @@ public class PGL { public void glRenderbufferStorage(int target, int format, int width, int height) { -// GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, format, w, h); + GLES20.glRenderbufferStorage(target, format, width, height); } diff --git a/android/core/src/processing/core/PGraphicsAndroid3D.java b/android/core/src/processing/core/PGraphicsAndroid3D.java index 5324e2d22..5e2f86636 100644 --- a/android/core/src/processing/core/PGraphicsAndroid3D.java +++ b/android/core/src/processing/core/PGraphicsAndroid3D.java @@ -299,8 +299,7 @@ public class PGraphicsAndroid3D extends PGraphics { /** Used to detect the occurrence of a frame resize event. */ protected boolean resized = false; - /** Stores previous viewport dimensions. */ - protected int[] savedViewport = {0, 0, 0, 0}; + /** Viewport dimensions. */ protected int[] viewport = {0, 0, 0, 0}; /** Used to register calls to glClear. */ @@ -1443,8 +1442,8 @@ public class PGraphicsAndroid3D extends PGraphics { pgl.glDisable(PGL.GL_POLYGON_SMOOTH); } - // setup opengl viewport. - pgl.glGetIntegerv(PGL.GL_VIEWPORT, savedViewport, 0); + + // setup opengl viewport. viewport[0] = 0; viewport[1] = 0; viewport[2] = width; viewport[3] = height; pgl.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); if (resized) { @@ -1504,7 +1503,10 @@ public class PGraphicsAndroid3D extends PGraphics { if (primarySurface) { pgl.beginOnscreenDraw(clearColorBuffer); } else { - pgl.beginOffscreenDraw(clearColorBuffer); + pgl.beginOffscreenDraw(clearColorBuffer); + + // Just in case the texture was recreated (in a resize event for example) + offscreenFramebuffer.setColorBuffer(texture); } if (hints[DISABLE_DEPTH_MASK]) { @@ -1539,9 +1541,6 @@ public class PGraphicsAndroid3D extends PGraphics { return; } - // Restoring previous viewport. - pgl.glViewport(savedViewport[0], savedViewport[1], savedViewport[2], savedViewport[3]); - if (primarySurface) { pgl.endOnscreenDraw(clearColorBuffer0); pgl.glFlush(); @@ -1555,7 +1554,7 @@ public class PGraphicsAndroid3D extends PGraphics { pg.restoreGL(); } - + drawing = false; report("bot endDraw()"); @@ -5587,7 +5586,7 @@ public class PGraphicsAndroid3D extends PGraphics { pgl.updateOffscreen(pg.pgl); loadTextureImpl(BILINEAR); - + // In case of reinitialization (for example, when the smooth level // is changed), we make sure that all the OpenGL resources associated // to the surface are released by calling delete(). @@ -5598,8 +5597,6 @@ public class PGraphicsAndroid3D extends PGraphics { offscreenFramebufferMultisample.release(); } - // We need the GL2GL3 profile to access the glRenderbufferStorageMultisample - // function used in multisampled (antialiased) offscreen rendering. if (PGraphicsAndroid3D.fboMultisampleSupported && 1 < antialias) { offscreenFramebufferMultisample = new PFramebuffer(parent, texture.glWidth, texture.glHeight, antialias, 0, PGL.DEFAULT_DEPTH_BITS, PGL.DEFAULT_STENCIL_BITS, @@ -5623,7 +5620,7 @@ public class PGraphicsAndroid3D extends PGraphics { } offscreenFramebuffer.setColorBuffer(texture); - offscreenFramebuffer.clear(); + offscreenFramebuffer.clear(); } @@ -6109,16 +6106,26 @@ public class PGraphicsAndroid3D extends PGraphics { } public void setTexture(PTexture tex) { - float scaleu = tex.maxTexCoordU; - float scalev = tex.maxTexCoordV; + float scaleu = 1; + float scalev = 1; float dispu = 0; float dispv = 0; + + if (tex.isFlippedX()) { + scaleu = -1; + dispu = 1; + } if (tex.isFlippedY()) { - scalev *= -1; + scalev = -1; dispv = 1; } + scaleu *= tex.maxTexCoordU; + dispu *= tex.maxTexCoordU; + scalev *= tex.maxTexCoordV; + dispv *= tex.maxTexCoordV; + if (tcmat == null) { tcmat = new float[16]; } @@ -6184,16 +6191,26 @@ public class PGraphicsAndroid3D extends PGraphics { } public void setTexture(PTexture tex) { - float scaleu = tex.maxTexCoordU; - float scalev = tex.maxTexCoordV; + float scaleu = 1; + float scalev = 1; float dispu = 0; float dispv = 0; + + if (tex.isFlippedX()) { + scaleu = -1; + dispu = 1; + } if (tex.isFlippedY()) { - scalev *= -1; + scalev = -1; dispv = 1; } + scaleu *= tex.maxTexCoordU; + dispu *= tex.maxTexCoordU; + scalev *= tex.maxTexCoordV; + dispv *= tex.maxTexCoordV; + if (tcmat == null) { tcmat = new float[16]; } diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index 6375c335b..b4e510c57 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -359,20 +359,7 @@ public class PGL { setFramerate = true; } - - public void updatePrimary() { - if (!setFramerate) { - setFramerate(targetFramerate); - } - } - - public void updateOffscreen(PGL primary) { - gl = primary.gl; - gl2 = primary.gl2; - } - - public void initPrimarySurface(int antialias) { if (profile == null) { profile = GLProfile.getDefault(); @@ -439,7 +426,20 @@ public class PGL { capabilities = primary.capabilities; drawable = null; initialized = true; - } + } + + + public void updatePrimary() { + if (!setFramerate) { + setFramerate(targetFramerate); + } + } + + + public void updateOffscreen(PGL primary) { + gl = primary.gl; + gl2 = primary.gl2; + } /////////////////////////////////////////////////////////////////////////////////// diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 054ba335e..b9ad2a650 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -305,8 +305,7 @@ public class PGraphicsOpenGL extends PGraphics { /** Used to detect the occurrence of a frame resize event. */ protected boolean resized = false; - /** Stores previous viewport dimensions. */ - protected int[] savedViewport = {0, 0, 0, 0}; + /** Viewport dimensions. */ protected int[] viewport = {0, 0, 0, 0}; /** Used to register calls to glClear. */ @@ -1449,8 +1448,7 @@ public class PGraphicsOpenGL extends PGraphics { pgl.glDisable(PGL.GL_POLYGON_SMOOTH); } - // setup opengl viewport. - pgl.glGetIntegerv(PGL.GL_VIEWPORT, savedViewport, 0); + // setup opengl viewport. viewport[0] = 0; viewport[1] = 0; viewport[2] = width; viewport[3] = height; pgl.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); if (resized) { @@ -1510,7 +1508,10 @@ public class PGraphicsOpenGL extends PGraphics { if (primarySurface) { pgl.beginOnscreenDraw(clearColorBuffer); } else { - pgl.beginOffscreenDraw(clearColorBuffer); + pgl.beginOffscreenDraw(clearColorBuffer); + + // Just in case the texture was recreated (in a resize event for example) + offscreenFramebuffer.setColorBuffer(texture); } if (hints[DISABLE_DEPTH_MASK]) { @@ -1545,9 +1546,6 @@ public class PGraphicsOpenGL extends PGraphics { return; } - // Restoring previous viewport. - pgl.glViewport(savedViewport[0], savedViewport[1], savedViewport[2], savedViewport[3]); - if (primarySurface) { pgl.endOnscreenDraw(clearColorBuffer0); pgl.glFlush(); @@ -5604,8 +5602,6 @@ public class PGraphicsOpenGL extends PGraphics { offscreenFramebufferMultisample.release(); } - // We need the GL2GL3 profile to access the glRenderbufferStorageMultisample - // function used in multisampled (antialiased) offscreen rendering. if (PGraphicsOpenGL.fboMultisampleSupported && 1 < antialias) { offscreenFramebufferMultisample = new PFramebuffer(parent, texture.glWidth, texture.glHeight, antialias, 0, PGL.DEFAULT_DEPTH_BITS, PGL.DEFAULT_STENCIL_BITS, @@ -6115,16 +6111,26 @@ public class PGraphicsOpenGL extends PGraphics { } public void setTexture(PTexture tex) { - float scaleu = tex.maxTexCoordU; - float scalev = tex.maxTexCoordV; + float scaleu = 1; + float scalev = 1; float dispu = 0; float dispv = 0; + + if (tex.isFlippedX()) { + scaleu = -1; + dispu = 1; + } if (tex.isFlippedY()) { - scalev *= -1; + scalev = -1; dispv = 1; } + scaleu *= tex.maxTexCoordU; + dispu *= tex.maxTexCoordU; + scalev *= tex.maxTexCoordV; + dispv *= tex.maxTexCoordV; + if (tcmat == null) { tcmat = new float[16]; } @@ -6190,16 +6196,26 @@ public class PGraphicsOpenGL extends PGraphics { } public void setTexture(PTexture tex) { - float scaleu = tex.maxTexCoordU; - float scalev = tex.maxTexCoordV; + float scaleu = 1; + float scalev = 1; float dispu = 0; float dispv = 0; + + if (tex.isFlippedX()) { + scaleu = -1; + dispu = 1; + } if (tex.isFlippedY()) { - scalev *= -1; + scalev = -1; dispv = 1; } + scaleu *= tex.maxTexCoordU; + dispu *= tex.maxTexCoordU; + scalev *= tex.maxTexCoordV; + dispv *= tex.maxTexCoordV; + if (tcmat == null) { tcmat = new float[16]; }