commit f85f2943bbfa69a603117fa25accf7bdf5ef6149
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Apr 19 14:47:08 2022 +0200

    FactorySticker: further improvements.

diff --git a/src/main/java/org/distorted/library/main/DistortedTexture.java b/src/main/java/org/distorted/library/main/DistortedTexture.java
index 15cb6c6..4cf2335 100644
--- a/src/main/java/org/distorted/library/main/DistortedTexture.java
+++ b/src/main/java/org/distorted/library/main/DistortedTexture.java
@@ -35,16 +35,17 @@ import android.opengl.GLUtils;
 public class DistortedTexture extends InternalSurface
   {
   private Bitmap mBmp;
+  private boolean mBitmapInverted;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// We have to flip vertically every single Bitmap that we get fed with.
+// We have to vertically flip all the bitmaps passed here via setTexture().
 //
 // Reason: textures read from files are the only objects in OpenGL which have their origins at the
 // upper-left corner. Everywhere else the origin is in the lower-left corner. Thus we have to flip.
 // The alternative solution, namely inverting the y-coordinate of the TexCoord does not really work-
 // i.e. it works only in case of rendering directly to the screen, but if we render to an FBO and
 // then take the FBO and render to screen, (DistortedNode does so!) things get inverted as textures
-// created from FBO have their origins in the lower-left... Mindfuck!
+// created from FBO have their origins in the lower-left...
 
   private static Bitmap flipBitmap(Bitmap src)
     {
@@ -72,7 +73,7 @@ public class DistortedTexture extends InternalSurface
       GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR );
       GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE );
       GLES30.glTexParameteri ( GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE );
-      GLUtils.texImage2D(GLES30.GL_TEXTURE_2D, 0, flipBitmap(mBmp), 0);
+      GLUtils.texImage2D(GLES30.GL_TEXTURE_2D, 0, mBitmapInverted ? mBmp : flipBitmap(mBmp), 0);
       GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0);
 
       mBmp = null;
@@ -150,6 +151,38 @@ public class DistortedTexture extends InternalSurface
       }
     else
       {
+      mBitmapInverted = false;
+      mBmp= bmp;
+      markForCreation();
+      return true;
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Sets the underlying android.graphics.Bitmap object - this version assumes the object is already
+ * flipped upside down.
+ * <p>
+ * You can only recycle() the passed Bitmap once the OpenGL context gets created (i.e. after call
+ * to GLSurfaceView.onSurfaceCreated) because only after this point can the Library upload it to the GPU!
+ *
+ * @param bmp The (vertically flipped!) android.graphics.Bitmap object to apply effects to and display.
+ * @return true if successful, false if texture too large.
+ */
+  public boolean setTextureAlreadyInverted(Bitmap bmp)
+    {
+    int width = bmp.getWidth();
+    int height= bmp.getHeight();
+    int max   = DistortedLibrary.getMaxTextureSize();
+
+    if( width>max || height>max )
+      {
+      android.util.Log.e("texture","error, trying to upload too large texture of size "+width+" x "+height+". Max is "+max);
+      return false;
+      }
+    else
+      {
+      mBitmapInverted = true;
       mBmp= bmp;
       markForCreation();
       return true;
