Project

General

Profile

« Previous | Next » 

Revision 2bd3d0fb

Added by Leszek Koltunski over 3 years ago

Detect if the texture we are trying to upload is too large and return an error.

View differences:

src/main/java/org/distorted/library/main/DistortedLibrary.java
221 221

  
222 222
  private static ExceptionListener mListener;
223 223
  private static Resources mResources;
224
  private static int mMaxTextureSize;
224 225

  
225 226
///////////////////////////////////////////////////////////////////////////////////////////////////
226 227
// private: hide this from Javadoc
......
994 995
      mGLSL = (major==3 && minor==0) ? 300 : 310;
995 996
      }
996 997

  
998
    int[] maxTextureSize = new int[1];
999
    GLES30.glGetIntegerv(GLES30.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
1000
    mMaxTextureSize = maxTextureSize[0];
1001

  
997 1002
    android.util.Log.e("DISTORTED", "Using OpenGL ES "+major+"."+minor);
998 1003
    mGLSL_VERSION = "#version "+mGLSL+" es\n";
999 1004

  
......
1086 1091
    mBlitProgram       = null;
1087 1092
    }
1088 1093

  
1094
///////////////////////////////////////////////////////////////////////////////////////////////////
1095
/**
1096
 * Return the maximum size of the texture supported by the driver.
1097
 */
1098
  public static int getMaxTextureSize()
1099
    {
1100
    return mMaxTextureSize;
1101
    }
1102

  
1089 1103
///////////////////////////////////////////////////////////////////////////////////////////////////
1090 1104
/**
1091 1105
 * Returns the maximum number of effects of a given type that can be simultaneously applied to a
src/main/java/org/distorted/library/main/DistortedTexture.java
135 135
 * to GLSurfaceView.onSurfaceCreated) because only after this point can the Library upload it to the GPU!
136 136
 *
137 137
 * @param bmp The android.graphics.Bitmap object to apply effects to and display.
138
 * @return true if successful, false if texture too large.
138 139
 */
139
  public void setTexture(Bitmap bmp)
140
  public boolean setTexture(Bitmap bmp)
140 141
    {
141
    mBmp= bmp;
142
    markForCreation();
142
    int width = bmp.getWidth();
143
    int height= bmp.getHeight();
144
    int max   = DistortedLibrary.getMaxTextureSize();
145

  
146
    if( width>max || height>max )
147
      {
148
      android.util.Log.e("texture","error, trying to upload too large texture of size "+width+" x "+height+". Max is "+max);
149
      return false;
150
      }
151
    else
152
      {
153
      mBmp= bmp;
154
      markForCreation();
155
      return true;
156
      }
143 157
    }
144 158

  
145 159
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff