commit a4b182d481d762b518cf8dcc67c9c47426f21950
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Apr 6 13:21:54 2018 +0100

    Introduce possibility that an OutputSurface is backed up by a larger texture than necessary and the 'cloneSize()' method.

diff --git a/src/main/java/org/distorted/library/main/DistortedFramebuffer.java b/src/main/java/org/distorted/library/main/DistortedFramebuffer.java
index 3303d2e..c60f388 100644
--- a/src/main/java/org/distorted/library/main/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/main/DistortedFramebuffer.java
@@ -54,7 +54,7 @@ public class DistortedFramebuffer extends DistortedOutputSurface implements Dist
         GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT);
         GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST);
         GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_LINEAR);
-        GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_RGBA, mWidth, mHeight, 0, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, null);
+        GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_RGBA, mRealWidth, mRealHeight, 0, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, null);
         }
       GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[0], 0);
       GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
@@ -73,11 +73,11 @@ public class DistortedFramebuffer extends DistortedOutputSurface implements Dist
 
       if( mDepthStencil==DEPTH_NO_STENCIL )
         {
-        GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH_COMPONENT, mWidth, mHeight, 0, GLES31.GL_DEPTH_COMPONENT, GLES31.GL_UNSIGNED_INT, null);
+        GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH_COMPONENT, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_COMPONENT, GLES31.GL_UNSIGNED_INT, null);
         }
       else if( mDepthStencil==BOTH_DEPTH_STENCIL )
         {
-        GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH24_STENCIL8, mWidth, mHeight, 0, GLES31.GL_DEPTH_STENCIL, GLES31.GL_UNSIGNED_INT_24_8, null);
+        GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH24_STENCIL8, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_STENCIL, GLES31.GL_UNSIGNED_INT_24_8, null);
         }
 
       GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0);
diff --git a/src/main/java/org/distorted/library/main/DistortedInputSurface.java b/src/main/java/org/distorted/library/main/DistortedInputSurface.java
index f6dcc8e..a0da9f3 100644
--- a/src/main/java/org/distorted/library/main/DistortedInputSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedInputSurface.java
@@ -24,6 +24,8 @@ package org.distorted.library.main;
  * A Surface that we can set as an Input (take its rectangle of pixels and skin a Mesh with it).
  */
 
+// This really ought to be an abstract class instead, but effing Java has no multiple inheritance...
+
 public interface DistortedInputSurface
 {
 /**
diff --git a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
index 77507c8..afe6c62 100644
--- a/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/DistortedOutputSurface.java
@@ -99,6 +99,11 @@ public static final int DEBUG_FPS = 1;
 
   private int mDebugLevel;
 
+  protected int mRealWidth;   // the Surface can be backed up with a texture that is
+  protected int mRealHeight;  // larger than the viewport we have to it.
+                              // mWidth,mHeight are the sizes of the Viewport, those -
+                              // sizes of the backing up texture.
+
   ////////////////////////////////////////////////////////////////////////////////
   // section dealing with Shader Storage Buffer Object (for counting transparency)
   private static final int FRAME_DELAY = 3;
@@ -138,6 +143,9 @@ public static final int DEBUG_FPS = 1;
     {
     super(width,height,createColor,numcolors,type);
 
+    mRealWidth = width;
+    mRealHeight= height;
+
     mProjectionMatrix = new float[16];
 
     mFOV = 60.0f;
@@ -290,6 +298,7 @@ public static final int DEBUG_FPS = 1;
       mBuffer[j].mMipmap = mipmap;
       mBuffer[j].mNear   = mNear;  // copy mNear as well (for blitting- see PostprocessEffect.apply() )
       mBuffer[j].glClearColor(1.0f,1.0f,1.0f,0.0f);
+
       mipmap *= EffectQuality.MULTIPLIER;
       }
 
@@ -314,6 +323,28 @@ public static final int DEBUG_FPS = 1;
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void cloneSize(DistortedOutputSurface from)
+    {
+    mWidth = from.mWidth;
+    mHeight= from.mHeight;
+
+    createProjection();
+
+    int maxw = mWidth >mRealWidth  ? mWidth :mRealWidth ;
+    int maxh = mHeight>mRealHeight ? mHeight:mRealHeight;
+
+    if( maxw>mRealWidth || maxh>mRealHeight )
+      {
+      mRealWidth = maxw;
+      mRealHeight= maxh;
+
+      recreateSurface();
+      createSurface();
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private int blitWithDepth(long currTime, DistortedOutputSurface buffer)
@@ -534,7 +565,7 @@ public static final int DEBUG_FPS = 1;
           {
           android.util.Log.d("surface", "id " + mSurfaceID +
               (mType == TYPE_USER ? " USER" : (mType == TYPE_SYST ? " SYST" : " TREE")) +
-              " (" + mWidth + "x" + mHeight + ") last frame: " + (value - mLastValue[mLastIndex])
+              "viewport: (" + mWidth + "x" + mHeight + ") last frame: " + (value - mLastValue[mLastIndex])
               + " avg: " + (mAvgSum/RUNNING_AVERAGE)
           );
           }
@@ -706,8 +737,8 @@ public static final int DEBUG_FPS = 1;
     {
     if( mWidth!=width || mHeight!=height )
       {
-      mWidth = width;
-      mHeight= height;
+      mWidth = mRealWidth = width;
+      mHeight= mRealHeight= height;
 
       createProjection();
 
