diff options
| -rw-r--r-- | core/jni/android/opengl/util.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp index d8522658d747..17cfbfc63f65 100644 --- a/core/jni/android/opengl/util.cpp +++ b/core/jni/android/opengl/util.cpp @@ -720,19 +720,22 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz, jint target, jint level, jint internalformat, jobject bitmapObj, jint type, jint border) { graphics::Bitmap bitmap(env, bitmapObj); - AndroidBitmapInfo bitmapInfo = bitmap.getInfo(); + if (bitmap.isValid() && bitmap.getPixels() != nullptr) { + AndroidBitmapInfo bitmapInfo = bitmap.getInfo(); - if (internalformat < 0) { - internalformat = getInternalFormat(bitmapInfo.format); - } - if (type < 0) { - type = getType(bitmapInfo.format); - } + if (internalformat < 0) { + internalformat = getInternalFormat(bitmapInfo.format); + } + if (type < 0) { + type = getType(bitmapInfo.format); + } - if (checkInternalFormat(bitmapInfo.format, internalformat, type)) { - glTexImage2D(target, level, internalformat, bitmapInfo.width, bitmapInfo.height, border, - getPixelFormatFromInternalFormat(internalformat), type, bitmap.getPixels()); - return 0; + if (checkInternalFormat(bitmapInfo.format, internalformat, type)) { + glTexImage2D(target, level, internalformat, bitmapInfo.width, bitmapInfo.height, border, + getPixelFormatFromInternalFormat(internalformat), type, + bitmap.getPixels()); + return 0; + } } return -1; } @@ -741,19 +744,21 @@ static jint util_texSubImage2D(JNIEnv *env, jclass clazz, jint target, jint leve jint xoffset, jint yoffset, jobject bitmapObj, jint format, jint type) { graphics::Bitmap bitmap(env, bitmapObj); - AndroidBitmapInfo bitmapInfo = bitmap.getInfo(); - - int internalFormat = getInternalFormat(bitmapInfo.format); - if (format < 0) { - format = getPixelFormatFromInternalFormat(internalFormat); - if (format == GL_PALETTE8_RGBA8_OES) - return -1; // glCompressedTexSubImage2D() not supported - } + if (bitmap.isValid() && bitmap.getPixels() != nullptr) { + AndroidBitmapInfo bitmapInfo = bitmap.getInfo(); + + int internalFormat = getInternalFormat(bitmapInfo.format); + if (format < 0) { + format = getPixelFormatFromInternalFormat(internalFormat); + if (format == GL_PALETTE8_RGBA8_OES) + return -1; // glCompressedTexSubImage2D() not supported + } - if (checkInternalFormat(bitmapInfo.format, internalFormat, type)) { - glTexSubImage2D(target, level, xoffset, yoffset, bitmapInfo.width, bitmapInfo.height, - format, type, bitmap.getPixels()); - return 0; + if (checkInternalFormat(bitmapInfo.format, internalFormat, type)) { + glTexSubImage2D(target, level, xoffset, yoffset, bitmapInfo.width, bitmapInfo.height, + format, type, bitmap.getPixels()); + return 0; + } } return -1; } |