From 032d47af737d803e841ab79f38ac9068a46c9aeb Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Mon, 8 Apr 2013 19:45:40 -0700 Subject: [PATCH] Change the dither texture's swizzling This is a more elegant way to sample from a float alpha texture. Instead of sampling from the red channel in the fragment shader we can set the alpha channel swizzle to redirect it to the red channel. This lets us sample from the alpha channel in the fragment shader and get the correct value. Change-Id: I95bbf7a82964e1bf42c0fee1b782b6bdbbcef618 --- libs/hwui/Dither.cpp | 4 ++++ libs/hwui/ProgramCache.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/hwui/Dither.cpp b/libs/hwui/Dither.cpp index 9bc5c140e8d58..51f1e39c15010 100644 --- a/libs/hwui/Dither.cpp +++ b/libs/hwui/Dither.cpp @@ -38,6 +38,10 @@ void Dither::bindDitherTexture() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); if (useFloatTexture) { + // We use a R16F texture, let's remap the alpha channel to the + // red channel to avoid changing the shader sampling code on GL ES 3.0+ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_RED); + float dither = 1.0f / (255.0f * DITHER_KERNEL_SIZE * DITHER_KERNEL_SIZE); const GLfloat pattern[] = { 0 * dither, 8 * dither, 2 * dither, 10 * dither, diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp index 2479630daea5c..8eb85e5547eb3 100644 --- a/libs/hwui/ProgramCache.cpp +++ b/libs/hwui/ProgramCache.cpp @@ -186,7 +186,7 @@ const char* gFS_Main_Dither[2] = { // ES 2.0 "texture2D(ditherSampler, ditherTexCoords).a * " STR(DITHER_KERNEL_SIZE_INV_SQUARE), // ES 3.0 - "texture2D(ditherSampler, ditherTexCoords).r" + "texture2D(ditherSampler, ditherTexCoords).a" }; const char* gFS_Main_AddDitherToGradient = " gradientColor += %s;\n";