commit b8f8ef5cf4998a5111dd3f8ff9269fb83bc927d6
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Jun 9 20:18:32 2020 +0100

    New option to display current frame number in the upper-left corner of a DistortedScreen.

diff --git a/src/main/java/org/distorted/library/main/DistortedScreen.java b/src/main/java/org/distorted/library/main/DistortedScreen.java
index 4e1c742..0055195 100644
--- a/src/main/java/org/distorted/library/main/DistortedScreen.java
+++ b/src/main/java/org/distorted/library/main/DistortedScreen.java
@@ -40,21 +40,27 @@ public class DistortedScreen extends DistortedFramebuffer
   {
   ///// DEBUGGING ONLY /////////////////////////
   private static final int NUM_FRAMES  = 100;
-  private static final int FPS_W       = 120;
-  private static final int FPS_H       =  70;
+  private static final int DEBUG_W     = 150;
+  private static final int DEBUG_H     =  70;
 
-  private boolean mShowFPS;
+  private static final int DEBUG_MODE_NONE = 0;
+  private static final int DEBUG_MODE_FPS  = 1;
+  private static final int DEBUG_MODE_FRAME= 2;
 
-  private MeshQuad fpsMesh;
-  private DistortedTexture fpsTexture;
-  private DistortedEffects fpsEffects;
-  private Canvas fpsCanvas;
-  private Bitmap fpsBitmap;
+  private int mDebugMode;
+  private boolean mDebugAllocated;
+
+  private MeshQuad debugMesh;
+  private DistortedTexture debugTexture;
+  private DistortedEffects debugEffects;
+  private Canvas debugCanvas;
+  private Bitmap debugBitmap;
   private Paint mPaint;
-  private String fpsString;
+  private String debugString;
   private long lastTime=0;
   private long[] durations;
   private int currDuration;
+  private int frameNumber;
   private static Static3D mMoveVector = new Static3D(0,0,0);
   private static MatrixEffectMove mMoveEffect = new MatrixEffectMove(mMoveVector);
   ///// END DEBUGGING //////////////////////////
@@ -74,12 +80,38 @@ public class DistortedScreen extends DistortedFramebuffer
   public DistortedScreen()
     {
     super(DistortedLibrary.FBO_QUEUE_SIZE,1,BOTH_DEPTH_STENCIL, TYPE_SYST, 1,1);
-    mShowFPS = false;
+    mDebugMode = DEBUG_MODE_NONE;
     mCurRenderedFBO = 0;
     mToBeBlittedFBO = 0;
     mFirstCircle = true;
+    mDebugAllocated = false;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   private void allocateDebug()
+     {
+     if( !mDebugAllocated )
+       {
+       mDebugAllocated = true;
+
+       debugString = "";
+       debugBitmap = Bitmap.createBitmap(DEBUG_W, DEBUG_H, Bitmap.Config.ARGB_8888);
+       debugMesh = new MeshQuad();
+       debugTexture = new DistortedTexture();
+       debugTexture.setTexture(debugBitmap);
+       debugCanvas = new Canvas(debugBitmap);
+       debugEffects = new DistortedEffects();
+       debugEffects.apply( new MatrixEffectScale( new Static3D(DEBUG_W,DEBUG_H,1) ) );
+       debugEffects.apply(mMoveEffect);
+
+       mPaint = new Paint();
+       mPaint.setAntiAlias(true);
+       mPaint.setTextAlign(Paint.Align.CENTER);
+       mPaint.setTextSize(0.7f * DEBUG_H);
+       }
+     }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Draws all the attached children to this OutputSurface.
@@ -91,24 +123,32 @@ public class DistortedScreen extends DistortedFramebuffer
  */
   public int render(long time)
     {
-    if( mShowFPS )
+    if( mDebugMode!=DEBUG_MODE_NONE )
       {
       if( lastTime==0 ) lastTime = time;
 
-      currDuration++;
-      if (currDuration >= NUM_FRAMES) currDuration = 0;
-      durations[NUM_FRAMES] += ((time - lastTime) - durations[currDuration]);
-      durations[currDuration] = time - lastTime;
-
-      fpsString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
+      if( mDebugMode==DEBUG_MODE_FPS )
+        {
+        currDuration++;
+        if (currDuration >= NUM_FRAMES) currDuration = 0;
+        durations[NUM_FRAMES] += ((time - lastTime) - durations[currDuration]);
+        durations[currDuration] = time - lastTime;
+
+        debugString = "" + ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
+        }
+      else if( mDebugMode==DEBUG_MODE_FRAME )
+        {
+        debugString = "" + frameNumber;
+        frameNumber++;
+        }
 
       mPaint.setColor(0xffffffff);
-      fpsCanvas.drawRect(0, 0, FPS_W, FPS_H, mPaint);
+      debugCanvas.drawRect(0, 0, DEBUG_W, DEBUG_H, mPaint);
       mPaint.setColor(0xff000000);
-      fpsCanvas.drawText(fpsString, 0.5f*FPS_W, 0.75f*FPS_H, mPaint);
-      fpsTexture.setTexture(fpsBitmap);
+      debugCanvas.drawText(debugString, 0.5f*DEBUG_W, 0.75f*DEBUG_H, mPaint);
+      debugTexture.setTexture(debugBitmap);
 
-      mMoveVector.set( (-mWidth+FPS_W)/2 +5, (mHeight-FPS_H)/2 -5, 0);
+      mMoveVector.set( (-mWidth+DEBUG_W)/2 +5, (mHeight-DEBUG_H)/2 -5, 0);
 
       lastTime = time;
       }
@@ -132,9 +172,9 @@ public class DistortedScreen extends DistortedFramebuffer
 
     DistortedLibrary.blitPriv(this);
 
-    if( mShowFPS && fpsTexture.setAsInput())
+    if( mDebugMode!=DEBUG_MODE_NONE && debugTexture.setAsInput())
       {
-      DistortedLibrary.drawPriv(fpsEffects, fpsMesh, this, time);
+      DistortedLibrary.drawPriv(debugEffects, debugMesh, this, time);
       }
 
     if( ++mCurRenderedFBO>= DistortedLibrary.FBO_QUEUE_SIZE )
@@ -157,23 +197,10 @@ public class DistortedScreen extends DistortedFramebuffer
  */
   public void showFPS()
     {
-    if( !mShowFPS )
+    if( mDebugMode!=DEBUG_MODE_FPS )
       {
-      mShowFPS = true;
-      fpsString = "";
-      fpsBitmap = Bitmap.createBitmap(FPS_W, FPS_H, Bitmap.Config.ARGB_8888);
-      fpsMesh = new MeshQuad();
-      fpsTexture = new DistortedTexture();
-      fpsTexture.setTexture(fpsBitmap);
-      fpsCanvas = new Canvas(fpsBitmap);
-      fpsEffects = new DistortedEffects();
-      fpsEffects.apply( new MatrixEffectScale( new Static3D(FPS_W,FPS_H,1) ) );
-      fpsEffects.apply(mMoveEffect);
-
-      mPaint = new Paint();
-      mPaint.setAntiAlias(true);
-      mPaint.setTextAlign(Paint.Align.CENTER);
-      mPaint.setTextSize(0.7f * FPS_H);
+      allocateDebug();
+      mDebugMode = DEBUG_MODE_FPS;
 
       durations = new long[NUM_FRAMES + 1];
       currDuration = 0;
@@ -182,4 +209,19 @@ public class DistortedScreen extends DistortedFramebuffer
       durations[NUM_FRAMES] = NUM_FRAMES * 16;               // close to 1000/16 ~ 60
       }
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Make the library show current frame number in the upper-left corner.
+ * <p>
+ */
+  public void showFrameNumber()
+    {
+    if( mDebugMode!=DEBUG_MODE_FRAME )
+      {
+      allocateDebug();
+      mDebugMode = DEBUG_MODE_FRAME;
+      frameNumber = 0;
+      }
+    }
   }
