summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Peiyong Lin <lpy@google.com> 2018-01-18 15:32:21 -0800
committer Peiyong Lin <lpy@google.com> 2018-01-19 10:05:30 -0800
commit4caf5da048ea205f9e07a31c82a419ea8f1a7247 (patch)
tree63816f16a9ee639a15bad5579d09f736ee808325
parent1e9044f1be9c2cbcc524d625edb000ea6ca77b28 (diff)
[GLUtils] Pass the correct format into glTexImage2D and glTexSubImage2D.
Previously, the format and internal format are the same, however, per https://www.khronos.org/registry/OpenGL-Refpages/es3.1/html/glTexImage2D.xhtml, this is no longer the case, thus we need to convert to proper format when we have the sized format. BUG: 72065799 Test: none Change-Id: Ib1f90db6692b3629928ed664e5c775adfb4f63dd
-rw-r--r--core/jni/android/opengl/util.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp
index f3aeb32f3f86..888db32fdfac 100644
--- a/core/jni/android/opengl/util.cpp
+++ b/core/jni/android/opengl/util.cpp
@@ -622,7 +622,7 @@ void util_multiplyMV(JNIEnv *env, jclass clazz,
// ---------------------------------------------------------------------------
-static int checkFormat(SkColorType colorType, int format, int type)
+static int checkInternalFormat(SkColorType colorType, int format, int type)
{
switch(colorType) {
case kN32_SkColorType:
@@ -651,6 +651,20 @@ static int checkFormat(SkColorType colorType, int format, int type)
return -1;
}
+// The internal format is no longer the same as pixel format, per Table 2 in
+// https://www.khronos.org/registry/OpenGL-Refpages/es3.1/html/glTexImage2D.xhtml
+static int getPixelFormatFromInternalFormat(uint32_t internalFormat) {
+ switch (internalFormat) {
+ // For sized internal format.
+ case GL_RGBA16F:
+ return GL_RGBA;
+ // Base internal formats and pixel formats are still the same, see Table 1 in
+ // https://www.khronos.org/registry/OpenGL-Refpages/es3.1/html/glTexImage2D.xhtml
+ default:
+ return internalFormat;
+ }
+}
+
static int getInternalFormat(SkColorType colorType)
{
switch(colorType) {
@@ -716,7 +730,7 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz,
if (type < 0) {
type = getType(colorType);
}
- int err = checkFormat(colorType, internalformat, type);
+ int err = checkInternalFormat(colorType, internalformat, type);
if (err)
return err;
const int w = bitmap.width();
@@ -725,7 +739,8 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz,
if (internalformat == GL_PALETTE8_RGBA8_OES) {
err = -1;
} else {
- glTexImage2D(target, level, internalformat, w, h, border, internalformat, type, p);
+ glTexImage2D(target, level, internalformat, w, h, border,
+ getPixelFormatFromInternalFormat(internalformat), type, p);
}
return err;
}
@@ -737,12 +752,13 @@ static jint util_texSubImage2D(JNIEnv *env, jclass clazz,
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
SkColorType colorType = bitmap.colorType();
+ int internalFormat = getInternalFormat(colorType);
if (format < 0) {
- format = getInternalFormat(colorType);
+ format = getPixelFormatFromInternalFormat(internalFormat);
if (format == GL_PALETTE8_RGBA8_OES)
return -1; // glCompressedTexSubImage2D() not supported
}
- int err = checkFormat(colorType, format, type);
+ int err = checkInternalFormat(colorType, internalFormat, type);
if (err)
return err;
const int w = bitmap.width();