| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/shader.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | |
| 10 | |
| 11 #define SHADER0(Src) #Src | |
| 12 #define SHADER(Src) SHADER0(Src) | |
| 13 | |
| 14 using WebKit::WebGraphicsContext3D; | |
| 15 | |
| 16 namespace cc { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 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) | |
| 21 { | |
| 22 for (size_t uniformIndex = 0; uniformIndex < count; uniformIndex ++) { | |
| 23 DCHECK(uniformIndex < maxLocations); | |
| 24 | |
| 25 if (usingBindUniform) { | |
| 26 locations[uniformIndex] = (*baseUniformIndex)++; | |
| 27 context->bindUniformLocationCHROMIUM(program, locations[uniformIndex
], shaderUniforms[uniformIndex]); | |
| 28 } else | |
| 29 locations[uniformIndex] = context->getUniformLocation(program, shade
rUniforms[uniformIndex]); | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 } | |
| 34 | |
| 35 VertexShaderPosTex::VertexShaderPosTex() | |
| 36 : m_matrixLocation(-1) | |
| 37 { | |
| 38 } | |
| 39 | |
| 40 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b
ool usingBindUniform, int* baseUniformIndex) | |
| 41 { | |
| 42 static const char* shaderUniforms[] = { | |
| 43 "matrix", | |
| 44 }; | |
| 45 int locations[1]; | |
| 46 | |
| 47 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 48 | |
| 49 m_matrixLocation = locations[0]; | |
| 50 DCHECK(m_matrixLocation != -1); | |
| 51 } | |
| 52 | |
| 53 std::string VertexShaderPosTex::getShaderString() const | |
| 54 { | |
| 55 return SHADER( | |
| 56 attribute vec4 a_position; | |
| 57 attribute vec2 a_texCoord; | |
| 58 uniform mat4 matrix; | |
| 59 varying vec2 v_texCoord; | |
| 60 void main() | |
| 61 { | |
| 62 gl_Position = matrix * a_position; | |
| 63 v_texCoord = a_texCoord; | |
| 64 } | |
| 65 ); | |
| 66 } | |
| 67 | |
| 68 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() | |
| 69 : m_matrixLocation(-1) | |
| 70 , m_texScaleLocation(-1) | |
| 71 { | |
| 72 } | |
| 73 | |
| 74 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned
program, bool usingBindUniform, int* baseUniformIndex) | |
| 75 { | |
| 76 static const char* shaderUniforms[] = { | |
| 77 "matrix", | |
| 78 "texScale", | |
| 79 }; | |
| 80 int locations[2]; | |
| 81 | |
| 82 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 83 | |
| 84 m_matrixLocation = locations[0]; | |
| 85 m_texScaleLocation = locations[1]; | |
| 86 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1); | |
| 87 } | |
| 88 | |
| 89 std::string VertexShaderPosTexYUVStretch::getShaderString() const | |
| 90 { | |
| 91 return SHADER( | |
| 92 precision mediump float; | |
| 93 attribute vec4 a_position; | |
| 94 attribute vec2 a_texCoord; | |
| 95 uniform mat4 matrix; | |
| 96 varying vec2 v_texCoord; | |
| 97 uniform vec2 texScale; | |
| 98 void main() | |
| 99 { | |
| 100 gl_Position = matrix * a_position; | |
| 101 v_texCoord = a_texCoord * texScale; | |
| 102 } | |
| 103 ); | |
| 104 } | |
| 105 | |
| 106 VertexShaderPos::VertexShaderPos() | |
| 107 : m_matrixLocation(-1) | |
| 108 { | |
| 109 } | |
| 110 | |
| 111 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool
usingBindUniform, int* baseUniformIndex) | |
| 112 { | |
| 113 static const char* shaderUniforms[] = { | |
| 114 "matrix", | |
| 115 }; | |
| 116 int locations[1]; | |
| 117 | |
| 118 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 119 | |
| 120 m_matrixLocation = locations[0]; | |
| 121 DCHECK(m_matrixLocation != -1); | |
| 122 } | |
| 123 | |
| 124 std::string VertexShaderPos::getShaderString() const | |
| 125 { | |
| 126 return SHADER( | |
| 127 attribute vec4 a_position; | |
| 128 uniform mat4 matrix; | |
| 129 void main() | |
| 130 { | |
| 131 gl_Position = matrix * a_position; | |
| 132 } | |
| 133 ); | |
| 134 } | |
| 135 | |
| 136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | |
| 137 : m_matrixLocation(-1) | |
| 138 , m_texTransformLocation(-1) | |
| 139 , m_vertexOpacityLocation(-1) | |
| 140 { | |
| 141 } | |
| 142 | |
| 143 void VertexShaderPosTexTransform::init(WebGraphicsContext3D* context, unsigned p
rogram, bool usingBindUniform, int* baseUniformIndex) | |
| 144 { | |
| 145 static const char* shaderUniforms[] = { | |
| 146 "matrix", | |
| 147 "texTransform", | |
| 148 "opacity", | |
| 149 }; | |
| 150 int locations[3]; | |
| 151 | |
| 152 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 153 | |
| 154 m_matrixLocation = locations[0]; | |
| 155 m_texTransformLocation = locations[1]; | |
| 156 m_vertexOpacityLocation = locations[2]; | |
| 157 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa
cityLocation != -1); | |
| 158 } | |
| 159 | |
| 160 std::string VertexShaderPosTexTransform::getShaderString() const | |
| 161 { | |
| 162 return SHADER( | |
| 163 attribute vec4 a_position; | |
| 164 attribute vec2 a_texCoord; | |
| 165 attribute float a_index; | |
| 166 uniform mat4 matrix[8]; | |
| 167 uniform vec4 texTransform[8]; | |
| 168 uniform float opacity[32]; | |
| 169 varying vec2 v_texCoord; | |
| 170 varying float v_alpha; | |
| 171 void main() | |
| 172 { | |
| 173 gl_Position = matrix[int(a_index * 0.25)] * a_position; | |
| 174 vec4 texTrans = texTransform[int(a_index * 0.25)]; | |
| 175 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | |
| 176 v_alpha = opacity[int(a_index)]; | |
| 177 } | |
| 178 ); | |
| 179 } | |
| 180 | |
| 181 std::string VertexShaderPosTexTransformFlip::getShaderString() const | |
| 182 { | |
| 183 return SHADER( | |
| 184 attribute vec4 a_position; | |
| 185 attribute vec2 a_texCoord; | |
| 186 attribute float a_index; | |
| 187 uniform mat4 matrix[8]; | |
| 188 uniform vec4 texTransform[8]; | |
| 189 uniform float opacity[32]; | |
| 190 varying vec2 v_texCoord; | |
| 191 varying float v_alpha; | |
| 192 void main() | |
| 193 { | |
| 194 gl_Position = matrix[int(a_index * 0.25)] * a_position; | |
| 195 vec4 texTrans = texTransform[int(a_index * 0.25)]; | |
| 196 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | |
| 197 v_texCoord.y = 1.0 - v_texCoord.y; | |
| 198 v_alpha = opacity[int(a_index)]; | |
| 199 } | |
| 200 ); | |
| 201 } | |
| 202 | |
| 203 std::string VertexShaderPosTexIdentity::getShaderString() const | |
| 204 { | |
| 205 return SHADER( | |
| 206 attribute vec4 a_position; | |
| 207 varying vec2 v_texCoord; | |
| 208 void main() | |
| 209 { | |
| 210 gl_Position = a_position; | |
| 211 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | |
| 212 } | |
| 213 ); | |
| 214 } | |
| 215 | |
| 216 VertexShaderQuad::VertexShaderQuad() | |
| 217 : m_matrixLocation(-1) | |
| 218 , m_pointLocation(-1) | |
| 219 , m_texScaleLocation(-1) | |
| 220 { | |
| 221 } | |
| 222 | |
| 223 void VertexShaderQuad::init(WebGraphicsContext3D* context, unsigned program, boo
l usingBindUniform, int* baseUniformIndex) | |
| 224 { | |
| 225 static const char* shaderUniforms[] = { | |
| 226 "matrix", | |
| 227 "point", | |
| 228 "texScale", | |
| 229 }; | |
| 230 int locations[3]; | |
| 231 | |
| 232 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 233 | |
| 234 m_matrixLocation = locations[0]; | |
| 235 m_pointLocation = locations[1]; | |
| 236 m_texScaleLocation = locations[2]; | |
| 237 DCHECK_NE(m_matrixLocation, -1); | |
| 238 DCHECK_NE(m_pointLocation, -1); | |
| 239 DCHECK_NE(m_texScaleLocation, -1); | |
| 240 } | |
| 241 | |
| 242 std::string VertexShaderQuad::getShaderString() const | |
| 243 { | |
| 244 return SHADER( | |
| 245 attribute vec4 a_position; | |
| 246 attribute vec2 a_texCoord; | |
| 247 uniform mat4 matrix; | |
| 248 uniform vec2 point[4]; | |
| 249 uniform vec2 texScale; | |
| 250 varying vec2 v_texCoord; | |
| 251 void main() | |
| 252 { | |
| 253 vec2 complement = abs(a_texCoord - 1.0); | |
| 254 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | |
| 255 pos.xy += (complement.x * complement.y) * point[0]; | |
| 256 pos.xy += (a_texCoord.x * complement.y) * point[1]; | |
| 257 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | |
| 258 pos.xy += (complement.x * a_texCoord.y) * point[3]; | |
| 259 gl_Position = matrix * pos; | |
| 260 v_texCoord = (pos.xy + vec2(0.5)) * texScale; | |
| 261 } | |
| 262 ); | |
| 263 } | |
| 264 | |
| 265 VertexShaderTile::VertexShaderTile() | |
| 266 : m_matrixLocation(-1) | |
| 267 , m_pointLocation(-1) | |
| 268 , m_vertexTexTransformLocation(-1) | |
| 269 { | |
| 270 } | |
| 271 | |
| 272 void VertexShaderTile::init(WebGraphicsContext3D* context, unsigned program, boo
l usingBindUniform, int* baseUniformIndex) | |
| 273 { | |
| 274 static const char* shaderUniforms[] = { | |
| 275 "matrix", | |
| 276 "point", | |
| 277 "vertexTexTransform", | |
| 278 }; | |
| 279 int locations[3]; | |
| 280 | |
| 281 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 282 | |
| 283 m_matrixLocation = locations[0]; | |
| 284 m_pointLocation = locations[1]; | |
| 285 m_vertexTexTransformLocation = locations[2]; | |
| 286 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo
rmLocation != -1); | |
| 287 } | |
| 288 | |
| 289 std::string VertexShaderTile::getShaderString() const | |
| 290 { | |
| 291 return SHADER( | |
| 292 attribute vec4 a_position; | |
| 293 attribute vec2 a_texCoord; | |
| 294 uniform mat4 matrix; | |
| 295 uniform vec2 point[4]; | |
| 296 uniform vec4 vertexTexTransform; | |
| 297 varying vec2 v_texCoord; | |
| 298 void main() | |
| 299 { | |
| 300 vec2 complement = abs(a_texCoord - 1.0); | |
| 301 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | |
| 302 pos.xy += (complement.x * complement.y) * point[0]; | |
| 303 pos.xy += (a_texCoord.x * complement.y) * point[1]; | |
| 304 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | |
| 305 pos.xy += (complement.x * a_texCoord.y) * point[3]; | |
| 306 gl_Position = matrix * pos; | |
| 307 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | |
| 308 } | |
| 309 ); | |
| 310 } | |
| 311 | |
| 312 VertexShaderVideoTransform::VertexShaderVideoTransform() | |
| 313 : m_matrixLocation(-1) | |
| 314 , m_texMatrixLocation(-1) | |
| 315 { | |
| 316 } | |
| 317 | |
| 318 bool VertexShaderVideoTransform::init(WebGraphicsContext3D* context, unsigned pr
ogram, bool usingBindUniform, int* baseUniformIndex) | |
| 319 { | |
| 320 static const char* shaderUniforms[] = { | |
| 321 "matrix", | |
| 322 "texMatrix", | |
| 323 }; | |
| 324 int locations[2]; | |
| 325 | |
| 326 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 327 | |
| 328 m_matrixLocation = locations[0]; | |
| 329 m_texMatrixLocation = locations[1]; | |
| 330 return m_matrixLocation != -1 && m_texMatrixLocation != -1; | |
| 331 } | |
| 332 | |
| 333 std::string VertexShaderVideoTransform::getShaderString() const | |
| 334 { | |
| 335 return SHADER( | |
| 336 attribute vec4 a_position; | |
| 337 attribute vec2 a_texCoord; | |
| 338 uniform mat4 matrix; | |
| 339 uniform mat4 texMatrix; | |
| 340 varying vec2 v_texCoord; | |
| 341 void main() | |
| 342 { | |
| 343 gl_Position = matrix * a_position; | |
| 344 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y,
0.0, 1.0)); | |
| 345 } | |
| 346 ); | |
| 347 } | |
| 348 | |
| 349 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | |
| 350 : m_samplerLocation(-1) | |
| 351 , m_alphaLocation(-1) | |
| 352 { | |
| 353 } | |
| 354 | |
| 355 void FragmentTexAlphaBinding::init(WebGraphicsContext3D* context, unsigned progr
am, bool usingBindUniform, int* baseUniformIndex) | |
| 356 { | |
| 357 static const char* shaderUniforms[] = { | |
| 358 "s_texture", | |
| 359 "alpha", | |
| 360 }; | |
| 361 int locations[2]; | |
| 362 | |
| 363 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 364 | |
| 365 m_samplerLocation = locations[0]; | |
| 366 m_alphaLocation = locations[1]; | |
| 367 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1); | |
| 368 } | |
| 369 | |
| 370 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() | |
| 371 : m_samplerLocation(-1) | |
| 372 { | |
| 373 } | |
| 374 | |
| 375 void FragmentTexOpaqueBinding::init(WebGraphicsContext3D* context, unsigned prog
ram, bool usingBindUniform, int* baseUniformIndex) | |
| 376 { | |
| 377 static const char* shaderUniforms[] = { | |
| 378 "s_texture", | |
| 379 }; | |
| 380 int locations[1]; | |
| 381 | |
| 382 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 383 | |
| 384 m_samplerLocation = locations[0]; | |
| 385 DCHECK(m_samplerLocation != -1); | |
| 386 } | |
| 387 | |
| 388 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) | |
| 389 { | |
| 390 static const char* shaderUniforms[] = { | |
| 391 "s_texture", | |
| 392 }; | |
| 393 int locations[1]; | |
| 394 | |
| 395 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 396 | |
| 397 m_samplerLocation = locations[0]; | |
| 398 return m_samplerLocation != -1; | |
| 399 } | |
| 400 | |
| 401 std::string FragmentShaderOESImageExternal::getShaderString() const | |
| 402 { | |
| 403 // Cannot use the SHADER() macro because of the '#' char | |
| 404 return "#extension GL_OES_EGL_image_external : require \n" | |
| 405 "precision mediump float;\n" | |
| 406 "varying vec2 v_texCoord;\n" | |
| 407 "uniform samplerExternalOES s_texture;\n" | |
| 408 "void main()\n" | |
| 409 "{\n" | |
| 410 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" | |
| 411 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor
.w);\n" | |
| 412 "}\n"; | |
| 413 } | |
| 414 | |
| 415 std::string FragmentShaderRGBATexAlpha::getShaderString() const | |
| 416 { | |
| 417 return SHADER( | |
| 418 precision mediump float; | |
| 419 varying vec2 v_texCoord; | |
| 420 uniform sampler2D s_texture; | |
| 421 uniform float alpha; | |
| 422 void main() | |
| 423 { | |
| 424 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 425 gl_FragColor = texColor * alpha; | |
| 426 } | |
| 427 ); | |
| 428 } | |
| 429 | |
| 430 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const | |
| 431 { | |
| 432 return SHADER( | |
| 433 precision mediump float; | |
| 434 varying vec2 v_texCoord; | |
| 435 varying float v_alpha; | |
| 436 uniform sampler2D s_texture; | |
| 437 void main() | |
| 438 { | |
| 439 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 440 gl_FragColor = texColor * v_alpha; | |
| 441 } | |
| 442 ); | |
| 443 } | |
| 444 | |
| 445 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const | |
| 446 { | |
| 447 return "#extension GL_ARB_texture_rectangle : require\n" | |
| 448 "precision mediump float;\n" | |
| 449 "varying vec2 v_texCoord;\n" | |
| 450 "varying float v_alpha;\n" | |
| 451 "uniform sampler2DRect s_texture;\n" | |
| 452 "void main()\n" | |
| 453 "{\n" | |
| 454 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | |
| 455 " gl_FragColor = texColor * v_alpha;\n" | |
| 456 "}\n"; | |
| 457 } | |
| 458 | |
| 459 std::string FragmentShaderRGBATexOpaque::getShaderString() const | |
| 460 { | |
| 461 return SHADER( | |
| 462 precision mediump float; | |
| 463 varying vec2 v_texCoord; | |
| 464 uniform sampler2D s_texture; | |
| 465 void main() | |
| 466 { | |
| 467 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 468 gl_FragColor = vec4(texColor.rgb, 1.0); | |
| 469 } | |
| 470 ); | |
| 471 } | |
| 472 | |
| 473 std::string FragmentShaderRGBATex::getShaderString() const | |
| 474 { | |
| 475 return SHADER( | |
| 476 precision mediump float; | |
| 477 varying vec2 v_texCoord; | |
| 478 uniform sampler2D s_texture; | |
| 479 void main() | |
| 480 { | |
| 481 gl_FragColor = texture2D(s_texture, v_texCoord); | |
| 482 } | |
| 483 ); | |
| 484 } | |
| 485 | |
| 486 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const | |
| 487 { | |
| 488 return SHADER( | |
| 489 precision mediump float; | |
| 490 varying vec2 v_texCoord; | |
| 491 uniform sampler2D s_texture; | |
| 492 uniform float alpha; | |
| 493 void main() | |
| 494 { | |
| 495 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 496 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w)
* alpha; | |
| 497 } | |
| 498 ); | |
| 499 } | |
| 500 | |
| 501 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const | |
| 502 { | |
| 503 return SHADER( | |
| 504 precision mediump float; | |
| 505 varying vec2 v_texCoord; | |
| 506 uniform sampler2D s_texture; | |
| 507 void main() | |
| 508 { | |
| 509 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 510 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | |
| 511 } | |
| 512 ); | |
| 513 } | |
| 514 | |
| 515 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | |
| 516 : m_samplerLocation(-1) | |
| 517 , m_alphaLocation(-1) | |
| 518 , m_edgeLocation(-1) | |
| 519 { | |
| 520 } | |
| 521 | |
| 522 void FragmentShaderRGBATexAlphaAA::init(WebGraphicsContext3D* context, unsigned
program, bool usingBindUniform, int* baseUniformIndex) | |
| 523 { | |
| 524 static const char* shaderUniforms[] = { | |
| 525 "s_texture", | |
| 526 "alpha", | |
| 527 "edge", | |
| 528 }; | |
| 529 int locations[3]; | |
| 530 | |
| 531 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 532 | |
| 533 m_samplerLocation = locations[0]; | |
| 534 m_alphaLocation = locations[1]; | |
| 535 m_edgeLocation = locations[2]; | |
| 536 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation !=
-1); | |
| 537 } | |
| 538 | |
| 539 std::string FragmentShaderRGBATexAlphaAA::getShaderString() const | |
| 540 { | |
| 541 return SHADER( | |
| 542 precision mediump float; | |
| 543 varying vec2 v_texCoord; | |
| 544 uniform sampler2D s_texture; | |
| 545 uniform float alpha; | |
| 546 uniform vec3 edge[8]; | |
| 547 void main() | |
| 548 { | |
| 549 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 550 vec3 pos = vec3(gl_FragCoord.xy, 1); | |
| 551 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | |
| 552 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | |
| 553 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
| 554 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
| 555 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
| 556 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
| 557 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
| 558 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
| 559 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min
(a4, a6) * min(a5, a7)); | |
| 560 } | |
| 561 ); | |
| 562 } | |
| 563 | |
| 564 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() | |
| 565 : m_samplerLocation(-1) | |
| 566 , m_alphaLocation(-1) | |
| 567 , m_fragmentTexTransformLocation(-1) | |
| 568 , m_edgeLocation(-1) | |
| 569 { | |
| 570 } | |
| 571 | |
| 572 void FragmentTexClampAlphaAABinding::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) | |
| 573 { | |
| 574 static const char* shaderUniforms[] = { | |
| 575 "s_texture", | |
| 576 "alpha", | |
| 577 "fragmentTexTransform", | |
| 578 "edge", | |
| 579 }; | |
| 580 int locations[4]; | |
| 581 | |
| 582 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 583 | |
| 584 m_samplerLocation = locations[0]; | |
| 585 m_alphaLocation = locations[1]; | |
| 586 m_fragmentTexTransformLocation = locations[2]; | |
| 587 m_edgeLocation = locations[3]; | |
| 588 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran
sformLocation != -1 && m_edgeLocation != -1); | |
| 589 } | |
| 590 | |
| 591 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString() const | |
| 592 { | |
| 593 return SHADER( | |
| 594 precision mediump float; | |
| 595 varying vec2 v_texCoord; | |
| 596 uniform sampler2D s_texture; | |
| 597 uniform float alpha; | |
| 598 uniform vec4 fragmentTexTransform; | |
| 599 uniform vec3 edge[8]; | |
| 600 void main() | |
| 601 { | |
| 602 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; | |
| 603 vec4 texColor = texture2D(s_texture, texCoord); | |
| 604 vec3 pos = vec3(gl_FragCoord.xy, 1); | |
| 605 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | |
| 606 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | |
| 607 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
| 608 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
| 609 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
| 610 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
| 611 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
| 612 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
| 613 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min
(a4, a6) * min(a5, a7)); | |
| 614 } | |
| 615 ); | |
| 616 } | |
| 617 | |
| 618 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const | |
| 619 { | |
| 620 return SHADER( | |
| 621 precision mediump float; | |
| 622 varying vec2 v_texCoord; | |
| 623 uniform sampler2D s_texture; | |
| 624 uniform float alpha; | |
| 625 uniform vec4 fragmentTexTransform; | |
| 626 uniform vec3 edge[8]; | |
| 627 void main() | |
| 628 { | |
| 629 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; | |
| 630 vec4 texColor = texture2D(s_texture, texCoord); | |
| 631 vec3 pos = vec3(gl_FragCoord.xy, 1); | |
| 632 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | |
| 633 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | |
| 634 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
| 635 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
| 636 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
| 637 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
| 638 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
| 639 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
| 640 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w)
* alpha * min(min(a0, a2) * min(a1, a3), min(a4, a6) * min(a5, a7)); | |
| 641 } | |
| 642 ); | |
| 643 } | |
| 644 | |
| 645 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() | |
| 646 : m_samplerLocation(-1) | |
| 647 , m_maskSamplerLocation(-1) | |
| 648 , m_alphaLocation(-1) | |
| 649 , m_maskTexCoordScaleLocation(-1) | |
| 650 { | |
| 651 } | |
| 652 | |
| 653 void FragmentShaderRGBATexAlphaMask::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) | |
| 654 { | |
| 655 static const char* shaderUniforms[] = { | |
| 656 "s_texture", | |
| 657 "s_mask", | |
| 658 "alpha", | |
| 659 "maskTexCoordScale", | |
| 660 "maskTexCoordOffset", | |
| 661 }; | |
| 662 int locations[5]; | |
| 663 | |
| 664 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 665 | |
| 666 m_samplerLocation = locations[0]; | |
| 667 m_maskSamplerLocation = locations[1]; | |
| 668 m_alphaLocation = locations[2]; | |
| 669 m_maskTexCoordScaleLocation = locations[3]; | |
| 670 m_maskTexCoordOffsetLocation = locations[4]; | |
| 671 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1); | |
| 672 } | |
| 673 | |
| 674 std::string FragmentShaderRGBATexAlphaMask::getShaderString() const | |
| 675 { | |
| 676 return SHADER( | |
| 677 precision mediump float; | |
| 678 varying vec2 v_texCoord; | |
| 679 uniform sampler2D s_texture; | |
| 680 uniform sampler2D s_mask; | |
| 681 uniform vec2 maskTexCoordScale; | |
| 682 uniform vec2 maskTexCoordOffset; | |
| 683 uniform float alpha; | |
| 684 void main() | |
| 685 { | |
| 686 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 687 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT
exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | |
| 688 vec4 maskColor = texture2D(s_mask, maskTexCoord); | |
| 689 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha * maskColor.w; | |
| 690 } | |
| 691 ); | |
| 692 } | |
| 693 | |
| 694 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | |
| 695 : m_samplerLocation(-1) | |
| 696 , m_maskSamplerLocation(-1) | |
| 697 , m_alphaLocation(-1) | |
| 698 , m_edgeLocation(-1) | |
| 699 , m_maskTexCoordScaleLocation(-1) | |
| 700 { | |
| 701 } | |
| 702 | |
| 703 void FragmentShaderRGBATexAlphaMaskAA::init(WebGraphicsContext3D* context, unsig
ned program, bool usingBindUniform, int* baseUniformIndex) | |
| 704 { | |
| 705 static const char* shaderUniforms[] = { | |
| 706 "s_texture", | |
| 707 "s_mask", | |
| 708 "alpha", | |
| 709 "edge", | |
| 710 "maskTexCoordScale", | |
| 711 "maskTexCoordOffset", | |
| 712 }; | |
| 713 int locations[6]; | |
| 714 | |
| 715 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 716 | |
| 717 m_samplerLocation = locations[0]; | |
| 718 m_maskSamplerLocation = locations[1]; | |
| 719 m_alphaLocation = locations[2]; | |
| 720 m_edgeLocation = locations[3]; | |
| 721 m_maskTexCoordScaleLocation = locations[4]; | |
| 722 m_maskTexCoordOffsetLocation = locations[5]; | |
| 723 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca
tion != -1 && m_edgeLocation != -1); | |
| 724 } | |
| 725 | |
| 726 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString() const | |
| 727 { | |
| 728 return SHADER( | |
| 729 precision mediump float; | |
| 730 varying vec2 v_texCoord; | |
| 731 uniform sampler2D s_texture; | |
| 732 uniform sampler2D s_mask; | |
| 733 uniform vec2 maskTexCoordScale; | |
| 734 uniform vec2 maskTexCoordOffset; | |
| 735 uniform float alpha; | |
| 736 uniform vec3 edge[8]; | |
| 737 void main() | |
| 738 { | |
| 739 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 740 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT
exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | |
| 741 vec4 maskColor = texture2D(s_mask, maskTexCoord); | |
| 742 vec3 pos = vec3(gl_FragCoord.xy, 1); | |
| 743 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | |
| 744 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | |
| 745 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
| 746 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
| 747 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
| 748 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
| 749 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
| 750 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
| 751 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha * maskColor.w * min(min(a0, a2) * min(a1, a3), min(a4, a6) * min(a5, a7)
); | |
| 752 } | |
| 753 ); | |
| 754 } | |
| 755 | |
| 756 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | |
| 757 : m_yTextureLocation(-1) | |
| 758 , m_uTextureLocation(-1) | |
| 759 , m_vTextureLocation(-1) | |
| 760 , m_alphaLocation(-1) | |
| 761 , m_yuvMatrixLocation(-1) | |
| 762 , m_yuvAdjLocation(-1) | |
| 763 { | |
| 764 } | |
| 765 | |
| 766 void FragmentShaderYUVVideo::init(WebGraphicsContext3D* context, unsigned progra
m, bool usingBindUniform, int* baseUniformIndex) | |
| 767 { | |
| 768 static const char* shaderUniforms[] = { | |
| 769 "y_texture", | |
| 770 "u_texture", | |
| 771 "v_texture", | |
| 772 "alpha", | |
| 773 "yuv_matrix", | |
| 774 "yuv_adj", | |
| 775 }; | |
| 776 int locations[6]; | |
| 777 | |
| 778 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 779 | |
| 780 m_yTextureLocation = locations[0]; | |
| 781 m_uTextureLocation = locations[1]; | |
| 782 m_vTextureLocation = locations[2]; | |
| 783 m_alphaLocation = locations[3]; | |
| 784 m_yuvMatrixLocation = locations[4]; | |
| 785 m_yuvAdjLocation = locations[5]; | |
| 786 | |
| 787 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc
ation != -1 | |
| 788 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca
tion != -1); | |
| 789 } | |
| 790 | |
| 791 std::string FragmentShaderYUVVideo::getShaderString() const | |
| 792 { | |
| 793 return SHADER( | |
| 794 precision mediump float; | |
| 795 precision mediump int; | |
| 796 varying vec2 v_texCoord; | |
| 797 uniform sampler2D y_texture; | |
| 798 uniform sampler2D u_texture; | |
| 799 uniform sampler2D v_texture; | |
| 800 uniform float alpha; | |
| 801 uniform vec3 yuv_adj; | |
| 802 uniform mat3 yuv_matrix; | |
| 803 void main() | |
| 804 { | |
| 805 float y_raw = texture2D(y_texture, v_texCoord).x; | |
| 806 float u_unsigned = texture2D(u_texture, v_texCoord).x; | |
| 807 float v_unsigned = texture2D(v_texture, v_texCoord).x; | |
| 808 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | |
| 809 vec3 rgb = yuv_matrix * yuv; | |
| 810 gl_FragColor = vec4(rgb, float(1)) * alpha; | |
| 811 } | |
| 812 ); | |
| 813 } | |
| 814 | |
| 815 FragmentShaderColor::FragmentShaderColor() | |
| 816 : m_colorLocation(-1) | |
| 817 { | |
| 818 } | |
| 819 | |
| 820 void FragmentShaderColor::init(WebGraphicsContext3D* context, unsigned program,
bool usingBindUniform, int* baseUniformIndex) | |
| 821 { | |
| 822 static const char* shaderUniforms[] = { | |
| 823 "color", | |
| 824 }; | |
| 825 int locations[1]; | |
| 826 | |
| 827 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 828 | |
| 829 m_colorLocation = locations[0]; | |
| 830 DCHECK(m_colorLocation != -1); | |
| 831 } | |
| 832 | |
| 833 std::string FragmentShaderColor::getShaderString() const | |
| 834 { | |
| 835 return SHADER( | |
| 836 precision mediump float; | |
| 837 uniform vec4 color; | |
| 838 void main() | |
| 839 { | |
| 840 gl_FragColor = color; | |
| 841 } | |
| 842 ); | |
| 843 } | |
| 844 | |
| 845 FragmentShaderColorAA::FragmentShaderColorAA() | |
| 846 : m_edgeLocation(-1) | |
| 847 , m_colorLocation(-1) | |
| 848 { | |
| 849 } | |
| 850 | |
| 851 void FragmentShaderColorAA::init(WebGraphicsContext3D* context, unsigned program
, bool usingBindUniform, int* baseUniformIndex) | |
| 852 { | |
| 853 static const char* shaderUniforms[] = { | |
| 854 "edge", | |
| 855 "color", | |
| 856 }; | |
| 857 int locations[2]; | |
| 858 | |
| 859 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 860 | |
| 861 m_edgeLocation = locations[0]; | |
| 862 m_colorLocation = locations[1]; | |
| 863 DCHECK(m_edgeLocation != -1 && m_colorLocation != -1); | |
| 864 } | |
| 865 | |
| 866 std::string FragmentShaderColorAA::getShaderString() const | |
| 867 { | |
| 868 return SHADER( | |
| 869 precision mediump float; | |
| 870 uniform vec4 color; | |
| 871 uniform vec3 edge[8]; | |
| 872 void main() | |
| 873 { | |
| 874 vec3 pos = vec3(gl_FragCoord.xy, 1); | |
| 875 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | |
| 876 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | |
| 877 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
| 878 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
| 879 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
| 880 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
| 881 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
| 882 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
| 883 gl_FragColor = color * min(min(a0, a2) * min(a1, a3), min(a4, a6) *
min(a5, a7)); | |
| 884 } | |
| 885 ); | |
| 886 } | |
| 887 | |
| 888 FragmentShaderCheckerboard::FragmentShaderCheckerboard() | |
| 889 : m_alphaLocation(-1) | |
| 890 , m_texTransformLocation(-1) | |
| 891 , m_frequencyLocation(-1) | |
| 892 { | |
| 893 } | |
| 894 | |
| 895 void FragmentShaderCheckerboard::init(WebGraphicsContext3D* context, unsigned pr
ogram, bool usingBindUniform, int* baseUniformIndex) | |
| 896 { | |
| 897 static const char* shaderUniforms[] = { | |
| 898 "alpha", | |
| 899 "texTransform", | |
| 900 "frequency", | |
| 901 "color", | |
| 902 }; | |
| 903 int locations[4]; | |
| 904 | |
| 905 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
| 906 | |
| 907 m_alphaLocation = locations[0]; | |
| 908 m_texTransformLocation = locations[1]; | |
| 909 m_frequencyLocation = locations[2]; | |
| 910 m_colorLocation = locations[3]; | |
| 911 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL
ocation != -1 && m_colorLocation != -1); | |
| 912 } | |
| 913 | |
| 914 std::string FragmentShaderCheckerboard::getShaderString() const | |
| 915 { | |
| 916 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | |
| 917 // by Munshi, Ginsburg, Shreiner. | |
| 918 return SHADER( | |
| 919 precision mediump float; | |
| 920 precision mediump int; | |
| 921 varying vec2 v_texCoord; | |
| 922 uniform float alpha; | |
| 923 uniform float frequency; | |
| 924 uniform vec4 texTransform; | |
| 925 uniform vec4 color; | |
| 926 void main() | |
| 927 { | |
| 928 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | |
| 929 vec4 color2 = color; | |
| 930 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; | |
| 931 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | |
| 932 float picker = abs(coord.x - coord.y); | |
| 933 gl_FragColor = mix(color1, color2, picker) * alpha; | |
| 934 } | |
| 935 ); | |
| 936 } | |
| 937 | |
| 938 } // namespace cc | |
| OLD | NEW |