commit 5c3b92c41c522ce9ee0b4e890aa1f85c17960aac
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri May 8 01:20:27 2020 +0100

    Convert DifferentBitmaps to stretchless API.

diff --git a/src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java b/src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java
index beffcf7..c211f83 100644
--- a/src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java
+++ b/src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java
@@ -30,6 +30,7 @@ import org.distorted.examples.R;
 import org.distorted.library.effect.MatrixEffectMove;
 import org.distorted.library.effect.MatrixEffectScale;
 import org.distorted.library.effect.VertexEffectDistort;
+import org.distorted.library.effect.VertexEffectScale;
 import org.distorted.library.effect.VertexEffectSink;
 import org.distorted.library.main.DistortedLibrary;
 import org.distorted.library.main.DistortedScreen;
@@ -57,7 +58,7 @@ class DifferentBitmapsRenderer implements GLSurfaceView.Renderer
    private DistortedTexture[] mTexture;
    private MeshRectangles mMesh;
    private DistortedScreen mScreen;
-   private Static3D mScale;
+   private Static3D mScaleMatrix, mScaleVertex;
    private Static3D[] mMove;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -72,6 +73,9 @@ class DifferentBitmapsRenderer implements GLSurfaceView.Renderer
       Static3D point = new Static3D(0,-60,0);
       Static4D region= new Static4D(0,0,0,300);
 
+      mScaleMatrix = new Static3D(1,1,1);
+      mScaleVertex = new Static3D(1,1,1);
+
       mEffects = new DistortedEffects[NUM];
       mEffects[0] = new DistortedEffects();
       for(int i=1; i<NUM; i++)
@@ -79,14 +83,16 @@ class DifferentBitmapsRenderer implements GLSurfaceView.Renderer
 
       // Add the effects only to the first queue - all VERTEX and FRAGMENT effects are shared!
       // (Matrix effect cannot be shared as we have to display each Texture in a different location)
-      VertexEffectSink sink = new VertexEffectSink(new Static1D(8), point, new Static4D(0,0,0,80));
+      VertexEffectScale scale     = new VertexEffectScale(mScaleVertex);
+      VertexEffectSink sink       = new VertexEffectSink(new Static1D(8), point, new Static4D(0,0,0,80));
       VertexEffectDistort distort = new VertexEffectDistort(dDistort,point,region);
+      mEffects[0].apply(scale);   // scale the whole thing (so far by 1, but mScaleVertex will be reset once we know the size of the bitmap)
       mEffects[0].apply(sink);    // enlarge the nose
       mEffects[0].apply(distort); // keep moving the whole bitmap left and right.
 
       // Now the Matrix effects
-      mScale = new Static3D(1,1,1);
-      MatrixEffectScale scaleEffect = new MatrixEffectScale(mScale);
+
+      MatrixEffectScale scaleEffect = new MatrixEffectScale(mScaleMatrix);
       mMove  = new Static3D[NUM];
       MatrixEffectMove[] moveEffect = new MatrixEffectMove[NUM];
 
@@ -113,13 +119,13 @@ class DifferentBitmapsRenderer implements GLSurfaceView.Renderer
     
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
      {
-     float horiRatio = (float)width / (NUM*mMesh.getStretchX());
-     float vertRatio = (float)height/ (    mMesh.getStretchY());
-     float factor    = horiRatio > vertRatio ? vertRatio : horiRatio;
+     float horiRatio = (float)width / (NUM*mScaleVertex.get0());
+     float vertRatio = (float)height/ (    mScaleVertex.get1());
+     float factor    = Math.min(horiRatio, vertRatio);
 
-     mScale.set( factor,factor,factor );
+     mScaleMatrix.set( factor,factor,factor );
 
-     for(int i=NUM-1; i>=0; i--) mMove[i].set((i-(NUM-1)/2.0f)*(width/NUM), 0, 0);
+     for(int i=NUM-1; i>=0; i--) mMove[i].set((i-(NUM-1)/2.0f)*width/NUM, 0, 0);
 
      mScreen.resize(width, height);
      }
@@ -138,6 +144,8 @@ class DifferentBitmapsRenderer implements GLSurfaceView.Renderer
      int bmpHeight = bmp[0].getHeight();
      int bmpWidth  = bmp[0].getWidth();
 
+     mScaleVertex.set(bmpWidth,bmpHeight,0);
+
      if( mTexture==null )
        {
        mTexture = new DistortedTexture[NUM];
@@ -151,15 +159,12 @@ class DifferentBitmapsRenderer implements GLSurfaceView.Renderer
        mTexture[i].setTexture(bmp[i]);
        }
 
-     if( mMesh==null )
-       {
-       mMesh = new MeshRectangles(30,30*bmpHeight/bmpWidth);
-       mMesh.setStretch(bmpWidth,bmpHeight,0);
-       }
+     if( mMesh==null ) mMesh = new MeshRectangles(30,30*bmpHeight/bmpWidth);
 
      mScreen.detachAll();
      for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture[i], mEffects[i], mMesh);
 
+     VertexEffectScale.enable();
      VertexEffectSink.enable();
      VertexEffectDistort.enable();
 
