Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/output/shader.h" | 5 #include "cc/output/shader.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/output/gl_renderer.h" // For the GLC() macro. | |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" |
| 11 #include "third_party/khronos/GLES2/gl2.h" | |
| 10 | 12 |
| 11 #define SHADER0(Src) #Src | 13 #define SHADER0(Src) #Src |
| 12 #define SHADER(Src) SHADER0(Src) | 14 #define VERTEX_SHADER(Src) setVertexTexCoordPrecision(SHADER0(Src)) |
| 15 #define FRAGMENT_SHADER(Src) setFragTexCoordPrecision(precision, SHADER0(Src)) | |
| 13 | 16 |
| 14 using WebKit::WebGraphicsContext3D; | 17 using WebKit::WebGraphicsContext3D; |
| 15 | 18 |
| 16 namespace cc { | 19 namespace cc { |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 static void getProgramUniformLocations(WebGraphicsContext3D* context, unsigned p rogram, const char** shaderUniforms, size_t count, size_t maxLocations, int* loc ations, bool usingBindUniform, int* baseUniformIndex) | 23 static void getProgramUniformLocations(WebGraphicsContext3D* context, unsigned p rogram, const char** shaderUniforms, size_t count, size_t maxLocations, int* loc ations, bool usingBindUniform, int* baseUniformIndex) |
| 21 { | 24 { |
| 22 for (size_t uniformIndex = 0; uniformIndex < count; uniformIndex ++) { | 25 for (size_t uniformIndex = 0; uniformIndex < count; uniformIndex ++) { |
| 23 DCHECK(uniformIndex < maxLocations); | 26 DCHECK(uniformIndex < maxLocations); |
| 24 | 27 |
| 25 if (usingBindUniform) { | 28 if (usingBindUniform) { |
| 26 locations[uniformIndex] = (*baseUniformIndex)++; | 29 locations[uniformIndex] = (*baseUniformIndex)++; |
| 27 context->bindUniformLocationCHROMIUM(program, locations[uniformIndex ], shaderUniforms[uniformIndex]); | 30 context->bindUniformLocationCHROMIUM(program, locations[uniformIndex ], shaderUniforms[uniformIndex]); |
| 28 } else | 31 } else |
| 29 locations[uniformIndex] = context->getUniformLocation(program, shade rUniforms[uniformIndex]); | 32 locations[uniformIndex] = context->getUniformLocation(program, shade rUniforms[uniformIndex]); |
| 30 } | 33 } |
| 31 } | 34 } |
| 32 | 35 |
| 36 static std::string setFragTexCoordPrecision(TexCoordPrecision requestedPrecision , | |
| 37 const char* shaderString) | |
| 38 { | |
| 39 std::string shaderStdString(shaderString); | |
| 40 | |
| 41 switch (requestedPrecision) { | |
| 42 case TexCoordPrecisionHigh: | |
| 43 DCHECK_NE(shaderStdString.find("TexCoordPrecision"), std::string::npos); | |
| 44 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" | |
| 45 " #define TexCoordPrecision highp\n" | |
| 46 "#else\n" | |
| 47 " #define TexCoordPrecision mediump\n" | |
| 48 "#endif\n" + | |
| 49 shaderStdString; | |
| 50 case TexCoordPrecisionMedium: | |
| 51 DCHECK_NE(shaderStdString.find("TexCoordPrecision"), std::string::npos); | |
| 52 return "#define TexCoordPrecision mediump\n" + | |
| 53 shaderStdString; | |
| 54 case TexCoordPrecisionNA: | |
| 55 DCHECK_EQ(shaderStdString.find("TexCoordPrecision"), std::string::npos); | |
| 56 return shaderStdString; | |
| 57 default: | |
| 58 NOTREACHED(); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 static std::string setVertexTexCoordPrecision(const char* shaderString) | |
| 63 { | |
| 64 // We unconditionally use highp in the vertex shader since | |
| 65 // we are unlikely to be vertex shader bound when drawing large quads. | |
| 66 // Also, some vertex shaders mutate the texture coordinate in such a | |
| 67 // way that the effective precision might be lower than expected. | |
| 68 return "#define TexCoordPrecision highp\n" + | |
| 69 std::string(shaderString); | |
| 70 } | |
| 71 | |
| 33 } | 72 } |
| 34 | 73 |
| 74 int TexCoordHighpThreshold(WebKit::WebGraphicsContext3D* context) { | |
| 75 GLint range[2]; | |
| 76 GLint precision = 0; | |
| 77 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER, | |
| 78 GL_MEDIUM_FLOAT, | |
| 79 range, &precision)); | |
| 80 #if defined(OS_ANDROID) | |
| 81 // We bias the threshold on Android to be more conservative, so as to avoid | |
| 82 // performance regressions. There has been obvious corruption with 2560 pixel | |
| 83 // displays, but none has been reported with lower resolution displays. | |
| 84 return std::max(1 << precision, 2048); | |
|
brianderson
2013/03/22 22:57:07
Alex, what do you think of this way of being conse
| |
| 85 #else | |
| 86 return 1 << precision; | |
| 87 #endif | |
| 88 } | |
| 89 | |
| 90 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, | |
| 91 const gfx::Point& max_coordinate) { | |
| 92 int highp_threshold = TexCoordHighpThreshold(context); | |
| 93 if (max_coordinate.x() > highp_threshold || | |
| 94 max_coordinate.y() > highp_threshold) | |
| 95 return TexCoordPrecisionHigh; | |
| 96 return TexCoordPrecisionMedium; | |
| 97 } | |
| 98 | |
| 35 VertexShaderPosTex::VertexShaderPosTex() | 99 VertexShaderPosTex::VertexShaderPosTex() |
| 36 : m_matrixLocation(-1) | 100 : m_matrixLocation(-1) |
| 37 { | 101 { |
| 38 } | 102 } |
| 39 | 103 |
| 40 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b ool usingBindUniform, int* baseUniformIndex) | 104 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b ool usingBindUniform, int* baseUniformIndex) |
| 41 { | 105 { |
| 42 static const char* shaderUniforms[] = { | 106 static const char* shaderUniforms[] = { |
| 43 "matrix", | 107 "matrix", |
| 44 }; | 108 }; |
| 45 int locations[1]; | 109 int locations[1]; |
| 46 | 110 |
| 47 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 111 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 48 | 112 |
| 49 m_matrixLocation = locations[0]; | 113 m_matrixLocation = locations[0]; |
| 50 DCHECK(m_matrixLocation != -1); | 114 DCHECK(m_matrixLocation != -1); |
| 51 } | 115 } |
| 52 | 116 |
| 53 std::string VertexShaderPosTex::getShaderString() const | 117 std::string VertexShaderPosTex::getShaderString() const |
| 54 { | 118 { |
| 55 return SHADER( | 119 return VERTEX_SHADER( |
| 56 attribute vec4 a_position; | 120 attribute vec4 a_position; |
| 57 attribute vec2 a_texCoord; | 121 attribute TexCoordPrecision vec2 a_texCoord; |
| 58 uniform mat4 matrix; | 122 uniform mat4 matrix; |
| 59 varying vec2 v_texCoord; | 123 varying TexCoordPrecision vec2 v_texCoord; |
| 60 void main() | 124 void main() |
| 61 { | 125 { |
| 62 gl_Position = matrix * a_position; | 126 gl_Position = matrix * a_position; |
| 63 v_texCoord = a_texCoord; | 127 v_texCoord = a_texCoord; |
| 64 } | 128 } |
| 65 ); | 129 ); |
| 66 } | 130 } |
| 67 | 131 |
| 68 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() | 132 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() |
| 69 : m_matrixLocation(-1) | 133 : m_matrixLocation(-1) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 81 | 145 |
| 82 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 146 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 83 | 147 |
| 84 m_matrixLocation = locations[0]; | 148 m_matrixLocation = locations[0]; |
| 85 m_texScaleLocation = locations[1]; | 149 m_texScaleLocation = locations[1]; |
| 86 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1); | 150 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1); |
| 87 } | 151 } |
| 88 | 152 |
| 89 std::string VertexShaderPosTexYUVStretch::getShaderString() const | 153 std::string VertexShaderPosTexYUVStretch::getShaderString() const |
| 90 { | 154 { |
| 91 return SHADER( | 155 return VERTEX_SHADER( |
| 92 precision mediump float; | 156 precision mediump float; |
| 93 attribute vec4 a_position; | 157 attribute vec4 a_position; |
| 94 attribute vec2 a_texCoord; | 158 attribute TexCoordPrecision vec2 a_texCoord; |
| 95 uniform mat4 matrix; | 159 uniform mat4 matrix; |
| 96 varying vec2 v_texCoord; | 160 varying TexCoordPrecision vec2 v_texCoord; |
| 97 uniform vec2 texScale; | 161 uniform TexCoordPrecision vec2 texScale; |
| 98 void main() | 162 void main() |
| 99 { | 163 { |
| 100 gl_Position = matrix * a_position; | 164 gl_Position = matrix * a_position; |
| 101 v_texCoord = a_texCoord * texScale; | 165 v_texCoord = a_texCoord * texScale; |
| 102 } | 166 } |
| 103 ); | 167 ); |
| 104 } | 168 } |
| 105 | 169 |
| 106 VertexShaderPos::VertexShaderPos() | 170 VertexShaderPos::VertexShaderPos() |
| 107 : m_matrixLocation(-1) | 171 : m_matrixLocation(-1) |
| 108 { | 172 { |
| 109 } | 173 } |
| 110 | 174 |
| 111 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) | 175 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) |
| 112 { | 176 { |
| 113 static const char* shaderUniforms[] = { | 177 static const char* shaderUniforms[] = { |
| 114 "matrix", | 178 "matrix", |
| 115 }; | 179 }; |
| 116 int locations[1]; | 180 int locations[1]; |
| 117 | 181 |
| 118 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 182 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 119 | 183 |
| 120 m_matrixLocation = locations[0]; | 184 m_matrixLocation = locations[0]; |
| 121 DCHECK(m_matrixLocation != -1); | 185 DCHECK(m_matrixLocation != -1); |
| 122 } | 186 } |
| 123 | 187 |
| 124 std::string VertexShaderPos::getShaderString() const | 188 std::string VertexShaderPos::getShaderString() const |
| 125 { | 189 { |
| 126 return SHADER( | 190 return VERTEX_SHADER( |
| 127 attribute vec4 a_position; | 191 attribute vec4 a_position; |
| 128 uniform mat4 matrix; | 192 uniform mat4 matrix; |
| 129 void main() | 193 void main() |
| 130 { | 194 { |
| 131 gl_Position = matrix * a_position; | 195 gl_Position = matrix * a_position; |
| 132 } | 196 } |
| 133 ); | 197 ); |
| 134 } | 198 } |
| 135 | 199 |
| 136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | 200 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 152 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 216 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 153 | 217 |
| 154 m_matrixLocation = locations[0]; | 218 m_matrixLocation = locations[0]; |
| 155 m_texTransformLocation = locations[1]; | 219 m_texTransformLocation = locations[1]; |
| 156 m_vertexOpacityLocation = locations[2]; | 220 m_vertexOpacityLocation = locations[2]; |
| 157 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1); | 221 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1); |
| 158 } | 222 } |
| 159 | 223 |
| 160 std::string VertexShaderPosTexTransform::getShaderString() const | 224 std::string VertexShaderPosTexTransform::getShaderString() const |
| 161 { | 225 { |
| 162 return SHADER( | 226 return VERTEX_SHADER( |
| 163 attribute vec4 a_position; | 227 attribute vec4 a_position; |
| 164 attribute vec2 a_texCoord; | 228 attribute TexCoordPrecision vec2 a_texCoord; |
| 165 attribute float a_index; | 229 attribute float a_index; |
| 166 uniform mat4 matrix[8]; | 230 uniform mat4 matrix[8]; |
| 167 uniform vec4 texTransform[8]; | 231 uniform TexCoordPrecision vec4 texTransform[8]; |
| 168 uniform float opacity[32]; | 232 uniform float opacity[32]; |
| 169 varying vec2 v_texCoord; | 233 varying TexCoordPrecision vec2 v_texCoord; |
| 170 varying float v_alpha; | 234 varying float v_alpha; |
| 171 void main() | 235 void main() |
| 172 { | 236 { |
| 173 gl_Position = matrix[int(a_index * 0.25)] * a_position; | 237 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
| 174 vec4 texTrans = texTransform[int(a_index * 0.25)]; | 238 TexCoordPrecision vec4 texTrans = texTransform[int(a_index * 0.25)]; |
| 175 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 239 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 176 v_alpha = opacity[int(a_index)]; | 240 v_alpha = opacity[int(a_index)]; |
| 177 } | 241 } |
| 178 ); | 242 ); |
| 179 } | 243 } |
| 180 | 244 |
| 181 std::string VertexShaderPosTexTransformFlip::getShaderString() const | 245 std::string VertexShaderPosTexTransformFlip::getShaderString() const |
| 182 { | 246 { |
| 183 return SHADER( | 247 return VERTEX_SHADER( |
| 184 attribute vec4 a_position; | 248 attribute vec4 a_position; |
| 185 attribute vec2 a_texCoord; | 249 attribute TexCoordPrecision vec2 a_texCoord; |
| 186 attribute float a_index; | 250 attribute float a_index; |
| 187 uniform mat4 matrix[8]; | 251 uniform mat4 matrix[8]; |
| 188 uniform vec4 texTransform[8]; | 252 uniform TexCoordPrecision vec4 texTransform[8]; |
| 189 uniform float opacity[32]; | 253 uniform float opacity[32]; |
| 190 varying vec2 v_texCoord; | 254 varying TexCoordPrecision vec2 v_texCoord; |
| 191 varying float v_alpha; | 255 varying float v_alpha; |
| 192 void main() | 256 void main() |
| 193 { | 257 { |
| 194 gl_Position = matrix[int(a_index * 0.25)] * a_position; | 258 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
| 195 vec4 texTrans = texTransform[int(a_index * 0.25)]; | 259 TexCoordPrecision vec4 texTrans = texTransform[int(a_index * 0.25)]; |
| 196 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 260 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 197 v_texCoord.y = 1.0 - v_texCoord.y; | 261 v_texCoord.y = 1.0 - v_texCoord.y; |
| 198 v_alpha = opacity[int(a_index)]; | 262 v_alpha = opacity[int(a_index)]; |
| 199 } | 263 } |
| 200 ); | 264 ); |
| 201 } | 265 } |
| 202 | 266 |
| 203 std::string VertexShaderPosTexIdentity::getShaderString() const | 267 std::string VertexShaderPosTexIdentity::getShaderString() const |
| 204 { | 268 { |
| 205 return SHADER( | 269 return VERTEX_SHADER( |
| 206 attribute vec4 a_position; | 270 attribute vec4 a_position; |
| 207 varying vec2 v_texCoord; | 271 varying TexCoordPrecision vec2 v_texCoord; |
| 208 void main() | 272 void main() |
| 209 { | 273 { |
| 210 gl_Position = a_position; | 274 gl_Position = a_position; |
| 211 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 275 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
| 212 } | 276 } |
| 213 ); | 277 ); |
| 214 } | 278 } |
| 215 | 279 |
| 216 VertexShaderQuad::VertexShaderQuad() | 280 VertexShaderQuad::VertexShaderQuad() |
| 217 : m_matrixLocation(-1) | 281 : m_matrixLocation(-1) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 236 m_matrixLocation = locations[0]; | 300 m_matrixLocation = locations[0]; |
| 237 m_pointLocation = locations[1]; | 301 m_pointLocation = locations[1]; |
| 238 m_texScaleLocation = locations[2]; | 302 m_texScaleLocation = locations[2]; |
| 239 DCHECK_NE(m_matrixLocation, -1); | 303 DCHECK_NE(m_matrixLocation, -1); |
| 240 DCHECK_NE(m_pointLocation, -1); | 304 DCHECK_NE(m_pointLocation, -1); |
| 241 DCHECK_NE(m_texScaleLocation, -1); | 305 DCHECK_NE(m_texScaleLocation, -1); |
| 242 } | 306 } |
| 243 | 307 |
| 244 std::string VertexShaderQuad::getShaderString() const | 308 std::string VertexShaderQuad::getShaderString() const |
| 245 { | 309 { |
| 246 return SHADER( | 310 return VERTEX_SHADER( |
| 247 attribute vec4 a_position; | 311 attribute TexCoordPrecision vec4 a_position; |
| 248 attribute vec2 a_texCoord; | 312 attribute TexCoordPrecision vec2 a_texCoord; |
| 249 uniform mat4 matrix; | 313 uniform mat4 matrix; |
| 250 uniform vec2 point_bug223014[4]; | 314 uniform TexCoordPrecision vec2 point_bug223014[4]; |
| 251 uniform vec2 texScale; | 315 uniform TexCoordPrecision vec2 texScale; |
| 252 varying vec2 v_texCoord; | 316 varying TexCoordPrecision vec2 v_texCoord; |
| 253 void main() | 317 void main() |
| 254 { | 318 { |
| 255 vec2 complement = abs(a_texCoord - 1.0); | 319 TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0); |
| 256 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 320 TexCoordPrecision vec4 pos = |
| 321 vec4(0.0, 0.0, a_position.z, a_position.w); | |
| 257 pos.xy += (complement.x * complement.y) * point_bug223014[0]; | 322 pos.xy += (complement.x * complement.y) * point_bug223014[0]; |
| 258 pos.xy += (a_texCoord.x * complement.y) * point_bug223014[1]; | 323 pos.xy += (a_texCoord.x * complement.y) * point_bug223014[1]; |
| 259 pos.xy += (a_texCoord.x * a_texCoord.y) * point_bug223014[2]; | 324 pos.xy += (a_texCoord.x * a_texCoord.y) * point_bug223014[2]; |
| 260 pos.xy += (complement.x * a_texCoord.y) * point_bug223014[3]; | 325 pos.xy += (complement.x * a_texCoord.y) * point_bug223014[3]; |
| 261 gl_Position = matrix * pos; | 326 gl_Position = matrix * pos; |
| 262 v_texCoord = (pos.xy + vec2(0.5)) * texScale; | 327 v_texCoord = (pos.xy + vec2(0.5)) * texScale; |
| 263 } | 328 } |
| 264 ); | 329 ); |
| 265 } | 330 } |
| 266 | 331 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 283 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 348 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 284 | 349 |
| 285 m_matrixLocation = locations[0]; | 350 m_matrixLocation = locations[0]; |
| 286 m_pointLocation = locations[1]; | 351 m_pointLocation = locations[1]; |
| 287 m_vertexTexTransformLocation = locations[2]; | 352 m_vertexTexTransformLocation = locations[2]; |
| 288 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1); | 353 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1); |
| 289 } | 354 } |
| 290 | 355 |
| 291 std::string VertexShaderTile::getShaderString() const | 356 std::string VertexShaderTile::getShaderString() const |
| 292 { | 357 { |
| 293 return SHADER( | 358 return VERTEX_SHADER( |
| 294 attribute vec4 a_position; | 359 attribute TexCoordPrecision vec4 a_position; |
| 295 attribute vec2 a_texCoord; | 360 attribute TexCoordPrecision vec2 a_texCoord; |
| 296 uniform mat4 matrix; | 361 uniform mat4 matrix; |
| 297 uniform vec2 point_bug223014[4]; | 362 uniform TexCoordPrecision vec2 point_bug223014[4]; |
| 298 uniform vec4 vertexTexTransform; | 363 uniform TexCoordPrecision vec4 vertexTexTransform; |
| 299 varying vec2 v_texCoord; | 364 varying TexCoordPrecision vec2 v_texCoord; |
| 300 void main() | 365 void main() |
| 301 { | 366 { |
| 302 vec2 complement = abs(a_texCoord - 1.0); | 367 vec2 complement = abs(a_texCoord - 1.0); |
| 303 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 368 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 304 pos.xy += (complement.x * complement.y) * point_bug223014[0]; | 369 pos.xy += (complement.x * complement.y) * point_bug223014[0]; |
| 305 pos.xy += (a_texCoord.x * complement.y) * point_bug223014[1]; | 370 pos.xy += (a_texCoord.x * complement.y) * point_bug223014[1]; |
| 306 pos.xy += (a_texCoord.x * a_texCoord.y) * point_bug223014[2]; | 371 pos.xy += (a_texCoord.x * a_texCoord.y) * point_bug223014[2]; |
| 307 pos.xy += (complement.x * a_texCoord.y) * point_bug223014[3]; | 372 pos.xy += (complement.x * a_texCoord.y) * point_bug223014[3]; |
| 308 gl_Position = matrix * pos; | 373 gl_Position = matrix * pos; |
| 309 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | 374 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 327 | 392 |
| 328 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 393 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 329 | 394 |
| 330 m_matrixLocation = locations[0]; | 395 m_matrixLocation = locations[0]; |
| 331 m_texMatrixLocation = locations[1]; | 396 m_texMatrixLocation = locations[1]; |
| 332 return m_matrixLocation != -1 && m_texMatrixLocation != -1; | 397 return m_matrixLocation != -1 && m_texMatrixLocation != -1; |
| 333 } | 398 } |
| 334 | 399 |
| 335 std::string VertexShaderVideoTransform::getShaderString() const | 400 std::string VertexShaderVideoTransform::getShaderString() const |
| 336 { | 401 { |
| 337 return SHADER( | 402 return VERTEX_SHADER( |
| 338 attribute vec4 a_position; | 403 attribute vec4 a_position; |
| 339 attribute vec2 a_texCoord; | 404 attribute TexCoordPrecision vec2 a_texCoord; |
| 340 uniform mat4 matrix; | 405 uniform mat4 matrix; |
| 341 uniform mat4 texMatrix; | 406 uniform TexCoordPrecision mat4 texMatrix; |
| 342 varying vec2 v_texCoord; | 407 varying TexCoordPrecision vec2 v_texCoord; |
| 343 void main() | 408 void main() |
| 344 { | 409 { |
| 345 gl_Position = matrix * a_position; | 410 gl_Position = matrix * a_position; |
| 346 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 411 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
| 347 } | 412 } |
| 348 ); | 413 ); |
| 349 } | 414 } |
| 350 | 415 |
| 351 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | 416 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
| 352 : m_samplerLocation(-1) | 417 : m_samplerLocation(-1) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 "s_texture", | 458 "s_texture", |
| 394 }; | 459 }; |
| 395 int locations[1]; | 460 int locations[1]; |
| 396 | 461 |
| 397 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 462 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 398 | 463 |
| 399 m_samplerLocation = locations[0]; | 464 m_samplerLocation = locations[0]; |
| 400 return m_samplerLocation != -1; | 465 return m_samplerLocation != -1; |
| 401 } | 466 } |
| 402 | 467 |
| 403 std::string FragmentShaderOESImageExternal::getShaderString() const | 468 std::string FragmentShaderOESImageExternal::getShaderString( |
| 469 TexCoordPrecision precision) const | |
| 404 { | 470 { |
| 405 // Cannot use the SHADER() macro because of the '#' char | 471 // Cannot use the FRAGMENT_SHADER() macro because of the '#' char |
| 406 return "#extension GL_OES_EGL_image_external : require \n" | 472 return setFragTexCoordPrecision(precision, |
| 473 "#extension GL_OES_EGL_image_external : require \n" | |
| 407 "precision mediump float;\n" | 474 "precision mediump float;\n" |
| 408 "varying vec2 v_texCoord;\n" | 475 "varying TexCoordPrecision vec2 v_texCoord;\n" |
| 409 "uniform samplerExternalOES s_texture;\n" | 476 "uniform samplerExternalOES s_texture;\n" |
| 410 "void main()\n" | 477 "void main()\n" |
| 411 "{\n" | 478 "{\n" |
| 412 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" | 479 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" |
| 413 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor .w);\n" | 480 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor .w);\n" |
| 414 "}\n"; | 481 "}\n"); |
| 415 } | 482 } |
| 416 | 483 |
| 417 std::string FragmentShaderRGBATexAlpha::getShaderString() const | 484 std::string FragmentShaderRGBATexAlpha::getShaderString( |
| 485 TexCoordPrecision precision) const | |
| 418 { | 486 { |
| 419 return SHADER( | 487 return FRAGMENT_SHADER( |
| 420 precision mediump float; | 488 precision mediump float; |
| 421 varying vec2 v_texCoord; | 489 varying TexCoordPrecision vec2 v_texCoord; |
| 422 uniform sampler2D s_texture; | 490 uniform sampler2D s_texture; |
| 423 uniform float alpha; | 491 uniform float alpha; |
| 424 void main() | 492 void main() |
| 425 { | 493 { |
| 426 vec4 texColor = texture2D(s_texture, v_texCoord); | 494 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 427 gl_FragColor = texColor * alpha; | 495 gl_FragColor = texColor * alpha; |
| 428 } | 496 } |
| 429 ); | 497 ); |
| 430 } | 498 } |
| 431 | 499 |
| 432 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const | 500 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString( |
| 501 TexCoordPrecision precision) const | |
| 433 { | 502 { |
| 434 return SHADER( | 503 return FRAGMENT_SHADER( |
| 435 precision mediump float; | 504 precision mediump float; |
| 436 varying vec2 v_texCoord; | 505 varying TexCoordPrecision vec2 v_texCoord; |
| 437 varying float v_alpha; | 506 varying float v_alpha; |
| 438 uniform sampler2D s_texture; | 507 uniform sampler2D s_texture; |
| 439 void main() | 508 void main() |
| 440 { | 509 { |
| 441 vec4 texColor = texture2D(s_texture, v_texCoord); | 510 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 442 gl_FragColor = texColor * v_alpha; | 511 gl_FragColor = texColor * v_alpha; |
| 443 } | 512 } |
| 444 ); | 513 ); |
| 445 } | 514 } |
| 446 | 515 |
| 447 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const | 516 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString( |
| 517 TexCoordPrecision precision) const | |
| 448 { | 518 { |
| 449 return "#extension GL_ARB_texture_rectangle : require\n" | 519 return setFragTexCoordPrecision(precision, |
| 520 "#extension GL_ARB_texture_rectangle : require\n" | |
| 450 "precision mediump float;\n" | 521 "precision mediump float;\n" |
| 451 "varying vec2 v_texCoord;\n" | 522 "varying TexCoordPrecision vec2 v_texCoord;\n" |
| 452 "varying float v_alpha;\n" | 523 "varying float v_alpha;\n" |
| 453 "uniform sampler2DRect s_texture;\n" | 524 "uniform sampler2DRect s_texture;\n" |
| 454 "void main()\n" | 525 "void main()\n" |
| 455 "{\n" | 526 "{\n" |
| 456 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | 527 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" |
| 457 " gl_FragColor = texColor * v_alpha;\n" | 528 " gl_FragColor = texColor * v_alpha;\n" |
| 458 "}\n"; | 529 "}\n"); |
| 459 } | 530 } |
| 460 | 531 |
| 461 std::string FragmentShaderRGBATexOpaque::getShaderString() const | 532 std::string FragmentShaderRGBATexOpaque::getShaderString( |
| 533 TexCoordPrecision precision) const | |
| 462 { | 534 { |
| 463 return SHADER( | 535 return FRAGMENT_SHADER( |
| 464 precision mediump float; | 536 precision mediump float; |
| 465 varying vec2 v_texCoord; | 537 varying TexCoordPrecision vec2 v_texCoord; |
| 466 uniform sampler2D s_texture; | 538 uniform sampler2D s_texture; |
| 467 void main() | 539 void main() |
| 468 { | 540 { |
| 469 vec4 texColor = texture2D(s_texture, v_texCoord); | 541 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 470 gl_FragColor = vec4(texColor.rgb, 1.0); | 542 gl_FragColor = vec4(texColor.rgb, 1.0); |
| 471 } | 543 } |
| 472 ); | 544 ); |
| 473 } | 545 } |
| 474 | 546 |
| 475 std::string FragmentShaderRGBATex::getShaderString() const | 547 std::string FragmentShaderRGBATex::getShaderString( |
| 548 TexCoordPrecision precision) const | |
| 476 { | 549 { |
| 477 return SHADER( | 550 return FRAGMENT_SHADER( |
| 478 precision mediump float; | 551 precision mediump float; |
| 479 varying vec2 v_texCoord; | 552 varying TexCoordPrecision vec2 v_texCoord; |
| 480 uniform sampler2D s_texture; | 553 uniform sampler2D s_texture; |
| 481 void main() | 554 void main() |
| 482 { | 555 { |
| 483 gl_FragColor = texture2D(s_texture, v_texCoord); | 556 gl_FragColor = texture2D(s_texture, v_texCoord); |
| 484 } | 557 } |
| 485 ); | 558 ); |
| 486 } | 559 } |
| 487 | 560 |
| 488 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const | 561 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString( |
| 562 TexCoordPrecision precision) const | |
| 489 { | 563 { |
| 490 return SHADER( | 564 return FRAGMENT_SHADER( |
| 491 precision mediump float; | 565 precision mediump float; |
| 492 varying vec2 v_texCoord; | 566 varying TexCoordPrecision vec2 v_texCoord; |
| 493 uniform sampler2D s_texture; | 567 uniform sampler2D s_texture; |
| 494 uniform float alpha; | 568 uniform float alpha; |
| 495 void main() | 569 void main() |
| 496 { | 570 { |
| 497 vec4 texColor = texture2D(s_texture, v_texCoord); | 571 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 498 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; | 572 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; |
| 499 } | 573 } |
| 500 ); | 574 ); |
| 501 } | 575 } |
| 502 | 576 |
| 503 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const | 577 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString( |
| 578 TexCoordPrecision precision) const | |
| 504 { | 579 { |
| 505 return SHADER( | 580 return FRAGMENT_SHADER( |
| 506 precision mediump float; | 581 precision mediump float; |
| 507 varying vec2 v_texCoord; | 582 varying TexCoordPrecision vec2 v_texCoord; |
| 508 uniform sampler2D s_texture; | 583 uniform sampler2D s_texture; |
| 509 void main() | 584 void main() |
| 510 { | 585 { |
| 511 vec4 texColor = texture2D(s_texture, v_texCoord); | 586 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 512 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 587 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
| 513 } | 588 } |
| 514 ); | 589 ); |
| 515 } | 590 } |
| 516 | 591 |
| 517 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 592 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 531 int locations[3]; | 606 int locations[3]; |
| 532 | 607 |
| 533 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 608 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 534 | 609 |
| 535 m_samplerLocation = locations[0]; | 610 m_samplerLocation = locations[0]; |
| 536 m_alphaLocation = locations[1]; | 611 m_alphaLocation = locations[1]; |
| 537 m_edgeLocation = locations[2]; | 612 m_edgeLocation = locations[2]; |
| 538 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1); | 613 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1); |
| 539 } | 614 } |
| 540 | 615 |
| 541 std::string FragmentShaderRGBATexAlphaAA::getShaderString() const | 616 std::string FragmentShaderRGBATexAlphaAA::getShaderString( |
| 617 TexCoordPrecision precision) const | |
| 542 { | 618 { |
| 543 return SHADER( | 619 return FRAGMENT_SHADER( |
| 544 precision mediump float; | 620 precision mediump float; |
| 545 varying vec2 v_texCoord; | 621 varying TexCoordPrecision vec2 v_texCoord; |
| 546 uniform sampler2D s_texture; | 622 uniform sampler2D s_texture; |
| 547 uniform float alpha; | 623 uniform float alpha; |
| 548 uniform vec3 edge[8]; | 624 uniform vec3 edge[8]; |
| 549 void main() | 625 void main() |
| 550 { | 626 { |
| 551 vec4 texColor = texture2D(s_texture, v_texCoord); | 627 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 552 vec3 pos = vec3(gl_FragCoord.xy, 1); | 628 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 553 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 629 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 554 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 630 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 555 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 631 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 583 | 659 |
| 584 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 660 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 585 | 661 |
| 586 m_samplerLocation = locations[0]; | 662 m_samplerLocation = locations[0]; |
| 587 m_alphaLocation = locations[1]; | 663 m_alphaLocation = locations[1]; |
| 588 m_fragmentTexTransformLocation = locations[2]; | 664 m_fragmentTexTransformLocation = locations[2]; |
| 589 m_edgeLocation = locations[3]; | 665 m_edgeLocation = locations[3]; |
| 590 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1); | 666 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1); |
| 591 } | 667 } |
| 592 | 668 |
| 593 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString() const | 669 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString( |
| 670 TexCoordPrecision precision) const | |
| 594 { | 671 { |
| 595 return SHADER( | 672 return FRAGMENT_SHADER( |
| 596 precision mediump float; | 673 precision mediump float; |
| 597 varying vec2 v_texCoord; | 674 varying TexCoordPrecision vec2 v_texCoord; |
| 598 uniform sampler2D s_texture; | 675 uniform sampler2D s_texture; |
| 599 uniform float alpha; | 676 uniform float alpha; |
| 600 uniform vec4 fragmentTexTransform; | 677 uniform TexCoordPrecision vec4 fragmentTexTransform; |
| 601 uniform vec3 edge[8]; | 678 uniform vec3 edge[8]; |
| 602 void main() | 679 void main() |
| 603 { | 680 { |
| 604 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy; | 681 TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * frag mentTexTransform.zw + fragmentTexTransform.xy; |
| 605 vec4 texColor = texture2D(s_texture, texCoord); | 682 vec4 texColor = texture2D(s_texture, texCoord); |
| 606 vec3 pos = vec3(gl_FragCoord.xy, 1); | 683 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 607 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 684 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 608 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 685 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 609 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 686 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 610 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 687 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 611 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 688 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 612 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 689 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 613 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 690 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 614 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 691 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| 615 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min (a4, a6) * min(a5, a7)); | 692 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min (a4, a6) * min(a5, a7)); |
| 616 } | 693 } |
| 617 ); | 694 ); |
| 618 } | 695 } |
| 619 | 696 |
| 620 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const | 697 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString( |
| 698 TexCoordPrecision precision) const | |
| 621 { | 699 { |
| 622 return SHADER( | 700 return FRAGMENT_SHADER( |
| 623 precision mediump float; | 701 precision mediump float; |
| 624 varying vec2 v_texCoord; | 702 varying TexCoordPrecision vec2 v_texCoord; |
| 625 uniform sampler2D s_texture; | 703 uniform sampler2D s_texture; |
| 626 uniform float alpha; | 704 uniform float alpha; |
| 627 uniform vec4 fragmentTexTransform; | 705 uniform TexCoordPrecision vec4 fragmentTexTransform; |
| 628 uniform vec3 edge[8]; | 706 uniform vec3 edge[8]; |
| 629 void main() | 707 void main() |
| 630 { | 708 { |
| 631 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy; | 709 TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * frag mentTexTransform.zw + fragmentTexTransform.xy; |
| 632 vec4 texColor = texture2D(s_texture, texCoord); | 710 vec4 texColor = texture2D(s_texture, texCoord); |
| 633 vec3 pos = vec3(gl_FragCoord.xy, 1); | 711 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 634 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 712 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 635 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 713 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 636 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 714 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 637 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 715 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 638 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 716 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 639 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 717 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 640 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 718 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 641 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 719 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 666 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 744 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 667 | 745 |
| 668 m_samplerLocation = locations[0]; | 746 m_samplerLocation = locations[0]; |
| 669 m_maskSamplerLocation = locations[1]; | 747 m_maskSamplerLocation = locations[1]; |
| 670 m_alphaLocation = locations[2]; | 748 m_alphaLocation = locations[2]; |
| 671 m_maskTexCoordScaleLocation = locations[3]; | 749 m_maskTexCoordScaleLocation = locations[3]; |
| 672 m_maskTexCoordOffsetLocation = locations[4]; | 750 m_maskTexCoordOffsetLocation = locations[4]; |
| 673 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1); | 751 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1); |
| 674 } | 752 } |
| 675 | 753 |
| 676 std::string FragmentShaderRGBATexAlphaMask::getShaderString() const | 754 std::string FragmentShaderRGBATexAlphaMask::getShaderString( |
| 755 TexCoordPrecision precision) const | |
| 677 { | 756 { |
| 678 return SHADER( | 757 return FRAGMENT_SHADER( |
| 679 precision mediump float; | 758 precision mediump float; |
| 680 varying vec2 v_texCoord; | 759 varying TexCoordPrecision vec2 v_texCoord; |
| 681 uniform sampler2D s_texture; | 760 uniform sampler2D s_texture; |
| 682 uniform sampler2D s_mask; | 761 uniform sampler2D s_mask; |
| 683 uniform vec2 maskTexCoordScale; | 762 uniform TexCoordPrecision vec2 maskTexCoordScale; |
| 684 uniform vec2 maskTexCoordOffset; | 763 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
| 685 uniform float alpha; | 764 uniform float alpha; |
| 686 void main() | 765 void main() |
| 687 { | 766 { |
| 688 vec4 texColor = texture2D(s_texture, v_texCoord); | 767 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 689 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 768 TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_ texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexC oordScale.y); |
| 690 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 769 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 691 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w; | 770 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w; |
| 692 } | 771 } |
| 693 ); | 772 ); |
| 694 } | 773 } |
| 695 | 774 |
| 696 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 775 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
| 697 : m_samplerLocation(-1) | 776 : m_samplerLocation(-1) |
| 698 , m_maskSamplerLocation(-1) | 777 , m_maskSamplerLocation(-1) |
| 699 , m_alphaLocation(-1) | 778 , m_alphaLocation(-1) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 718 | 797 |
| 719 m_samplerLocation = locations[0]; | 798 m_samplerLocation = locations[0]; |
| 720 m_maskSamplerLocation = locations[1]; | 799 m_maskSamplerLocation = locations[1]; |
| 721 m_alphaLocation = locations[2]; | 800 m_alphaLocation = locations[2]; |
| 722 m_edgeLocation = locations[3]; | 801 m_edgeLocation = locations[3]; |
| 723 m_maskTexCoordScaleLocation = locations[4]; | 802 m_maskTexCoordScaleLocation = locations[4]; |
| 724 m_maskTexCoordOffsetLocation = locations[5]; | 803 m_maskTexCoordOffsetLocation = locations[5]; |
| 725 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1 && m_edgeLocation != -1); | 804 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1 && m_edgeLocation != -1); |
| 726 } | 805 } |
| 727 | 806 |
| 728 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString() const | 807 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString( |
| 808 TexCoordPrecision precision) const | |
| 729 { | 809 { |
| 730 return SHADER( | 810 return FRAGMENT_SHADER( |
| 731 precision mediump float; | 811 precision mediump float; |
| 732 varying vec2 v_texCoord; | 812 varying TexCoordPrecision vec2 v_texCoord; |
| 733 uniform sampler2D s_texture; | 813 uniform sampler2D s_texture; |
| 734 uniform sampler2D s_mask; | 814 uniform sampler2D s_mask; |
| 735 uniform vec2 maskTexCoordScale; | 815 uniform TexCoordPrecision vec2 maskTexCoordScale; |
| 736 uniform vec2 maskTexCoordOffset; | 816 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
| 737 uniform float alpha; | 817 uniform float alpha; |
| 738 uniform vec3 edge[8]; | 818 uniform vec3 edge[8]; |
| 739 void main() | 819 void main() |
| 740 { | 820 { |
| 741 vec4 texColor = texture2D(s_texture, v_texCoord); | 821 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 742 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 822 TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_ texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexC oordScale.y); |
| 743 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 823 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 744 vec3 pos = vec3(gl_FragCoord.xy, 1); | 824 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 745 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 825 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 746 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 826 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 747 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 827 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 748 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 828 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 749 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 829 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 750 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 830 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 751 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 831 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 752 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 832 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 783 m_uTextureLocation = locations[1]; | 863 m_uTextureLocation = locations[1]; |
| 784 m_vTextureLocation = locations[2]; | 864 m_vTextureLocation = locations[2]; |
| 785 m_alphaLocation = locations[3]; | 865 m_alphaLocation = locations[3]; |
| 786 m_yuvMatrixLocation = locations[4]; | 866 m_yuvMatrixLocation = locations[4]; |
| 787 m_yuvAdjLocation = locations[5]; | 867 m_yuvAdjLocation = locations[5]; |
| 788 | 868 |
| 789 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1 | 869 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1 |
| 790 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1); | 870 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1); |
| 791 } | 871 } |
| 792 | 872 |
| 793 std::string FragmentShaderYUVVideo::getShaderString() const | 873 std::string FragmentShaderYUVVideo::getShaderString( |
| 874 TexCoordPrecision precision) const | |
| 794 { | 875 { |
| 795 return SHADER( | 876 return FRAGMENT_SHADER( |
| 796 precision mediump float; | 877 precision mediump float; |
| 797 precision mediump int; | 878 precision mediump int; |
| 798 varying vec2 v_texCoord; | 879 varying TexCoordPrecision vec2 v_texCoord; |
| 799 uniform sampler2D y_texture; | 880 uniform sampler2D y_texture; |
| 800 uniform sampler2D u_texture; | 881 uniform sampler2D u_texture; |
| 801 uniform sampler2D v_texture; | 882 uniform sampler2D v_texture; |
| 802 uniform float alpha; | 883 uniform float alpha; |
| 803 uniform vec3 yuv_adj; | 884 uniform vec3 yuv_adj; |
| 804 uniform mat3 yuv_matrix; | 885 uniform mat3 yuv_matrix; |
| 805 void main() | 886 void main() |
| 806 { | 887 { |
| 807 float y_raw = texture2D(y_texture, v_texCoord).x; | 888 float y_raw = texture2D(y_texture, v_texCoord).x; |
| 808 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 889 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 825 "color", | 906 "color", |
| 826 }; | 907 }; |
| 827 int locations[1]; | 908 int locations[1]; |
| 828 | 909 |
| 829 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 910 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 830 | 911 |
| 831 m_colorLocation = locations[0]; | 912 m_colorLocation = locations[0]; |
| 832 DCHECK(m_colorLocation != -1); | 913 DCHECK(m_colorLocation != -1); |
| 833 } | 914 } |
| 834 | 915 |
| 835 std::string FragmentShaderColor::getShaderString() const | 916 std::string FragmentShaderColor::getShaderString( |
| 917 TexCoordPrecision precision) const | |
| 836 { | 918 { |
| 837 return SHADER( | 919 return FRAGMENT_SHADER( |
| 838 precision mediump float; | 920 precision mediump float; |
| 839 uniform vec4 color; | 921 uniform vec4 color; |
| 840 void main() | 922 void main() |
| 841 { | 923 { |
| 842 gl_FragColor = color; | 924 gl_FragColor = color; |
| 843 } | 925 } |
| 844 ); | 926 ); |
| 845 } | 927 } |
| 846 | 928 |
| 847 FragmentShaderColorAA::FragmentShaderColorAA() | 929 FragmentShaderColorAA::FragmentShaderColorAA() |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 858 }; | 940 }; |
| 859 int locations[2]; | 941 int locations[2]; |
| 860 | 942 |
| 861 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 943 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 862 | 944 |
| 863 m_edgeLocation = locations[0]; | 945 m_edgeLocation = locations[0]; |
| 864 m_colorLocation = locations[1]; | 946 m_colorLocation = locations[1]; |
| 865 DCHECK(m_edgeLocation != -1 && m_colorLocation != -1); | 947 DCHECK(m_edgeLocation != -1 && m_colorLocation != -1); |
| 866 } | 948 } |
| 867 | 949 |
| 868 std::string FragmentShaderColorAA::getShaderString() const | 950 std::string FragmentShaderColorAA::getShaderString( |
| 951 TexCoordPrecision precision) const | |
| 869 { | 952 { |
| 870 return SHADER( | 953 return FRAGMENT_SHADER( |
| 871 precision mediump float; | 954 precision mediump float; |
| 872 uniform vec4 color; | 955 uniform vec4 color; |
| 873 uniform vec3 edge[8]; | 956 uniform vec3 edge[8]; |
| 874 void main() | 957 void main() |
| 875 { | 958 { |
| 876 vec3 pos = vec3(gl_FragCoord.xy, 1); | 959 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 877 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 960 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 878 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 961 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 879 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 962 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 880 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 963 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 906 | 989 |
| 907 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 990 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 908 | 991 |
| 909 m_alphaLocation = locations[0]; | 992 m_alphaLocation = locations[0]; |
| 910 m_texTransformLocation = locations[1]; | 993 m_texTransformLocation = locations[1]; |
| 911 m_frequencyLocation = locations[2]; | 994 m_frequencyLocation = locations[2]; |
| 912 m_colorLocation = locations[3]; | 995 m_colorLocation = locations[3]; |
| 913 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL ocation != -1 && m_colorLocation != -1); | 996 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL ocation != -1 && m_colorLocation != -1); |
| 914 } | 997 } |
| 915 | 998 |
| 916 std::string FragmentShaderCheckerboard::getShaderString() const | 999 std::string FragmentShaderCheckerboard::getShaderString( |
| 1000 TexCoordPrecision precision) const | |
| 917 { | 1001 { |
| 918 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | 1002 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
| 919 // by Munshi, Ginsburg, Shreiner. | 1003 // by Munshi, Ginsburg, Shreiner. |
| 920 return SHADER( | 1004 return FRAGMENT_SHADER( |
| 921 precision mediump float; | 1005 precision mediump float; |
| 922 precision mediump int; | 1006 precision mediump int; |
| 923 varying vec2 v_texCoord; | 1007 varying TexCoordPrecision vec2 v_texCoord; |
| 924 uniform float alpha; | 1008 uniform float alpha; |
| 925 uniform float frequency; | 1009 uniform float frequency; |
| 926 uniform vec4 texTransform; | 1010 uniform vec4 texTransform; |
| 927 uniform vec4 color; | 1011 uniform vec4 color; |
| 928 void main() | 1012 void main() |
| 929 { | 1013 { |
| 930 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | 1014 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
| 931 vec4 color2 = color; | 1015 vec4 color2 = color; |
| 932 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; | 1016 TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texT ransform.zw + texTransform.xy; |
| 933 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1017 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 934 float picker = abs(coord.x - coord.y); | 1018 float picker = abs(coord.x - coord.y); |
| 935 gl_FragColor = mix(color1, color2, picker) * alpha; | 1019 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 936 } | 1020 } |
| 937 ); | 1021 ); |
| 938 } | 1022 } |
| 939 | 1023 |
| 940 } // namespace cc | 1024 } // namespace cc |
| OLD | NEW |