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/shader.h" | 5 #include "cc/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 "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
10 | 10 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 }; | 338 }; |
339 int locations[2]; | 339 int locations[2]; |
340 | 340 |
341 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | 341 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; |
342 | 342 |
343 m_samplerLocation = locations[0]; | 343 m_samplerLocation = locations[0]; |
344 m_alphaLocation = locations[1]; | 344 m_alphaLocation = locations[1]; |
345 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1); | 345 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1); |
346 } | 346 } |
347 | 347 |
348 FragmentTexClampAlphaBinding::FragmentTexClampAlphaBinding() | |
349 : m_samplerLocation(-1) | |
350 , m_alphaLocation(-1) | |
351 , m_fragmentTexTransformLocation(-1) | |
352 { | |
353 } | |
354 | |
355 void FragmentTexClampAlphaBinding::init(WebGraphicsContext3D* context, unsigned
program, bool usingBindUniform, int* baseUniformIndex) | |
356 { | |
357 static const char* shaderUniforms[] = { | |
358 "s_texture", | |
359 "alpha", | |
360 "fragmentTexTransform", | |
361 }; | |
362 int locations[3]; | |
363 | |
364 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
365 | |
366 m_samplerLocation = locations[0]; | |
367 m_alphaLocation = locations[1]; | |
368 m_fragmentTexTransformLocation = locations[2]; | |
369 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1); | |
370 } | |
371 | |
372 | |
373 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() | 348 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() |
374 : m_samplerLocation(-1) | 349 : m_samplerLocation(-1) |
375 { | 350 { |
376 } | 351 } |
377 | 352 |
378 void FragmentTexOpaqueBinding::init(WebGraphicsContext3D* context, unsigned prog
ram, bool usingBindUniform, int* baseUniformIndex) | 353 void FragmentTexOpaqueBinding::init(WebGraphicsContext3D* context, unsigned prog
ram, bool usingBindUniform, int* baseUniformIndex) |
379 { | 354 { |
380 static const char* shaderUniforms[] = { | 355 static const char* shaderUniforms[] = { |
381 "s_texture", | 356 "s_texture", |
382 }; | 357 }; |
383 int locations[1]; | 358 int locations[1]; |
384 | 359 |
385 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | 360 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; |
386 | 361 |
387 m_samplerLocation = locations[0]; | 362 m_samplerLocation = locations[0]; |
388 DCHECK(m_samplerLocation != -1); | 363 DCHECK(m_samplerLocation != -1); |
389 } | 364 } |
390 | 365 |
391 FragmentTexClampOpaqueBinding::FragmentTexClampOpaqueBinding() | |
392 : m_samplerLocation(-1) | |
393 , m_fragmentTexTransformLocation(-1) | |
394 { | |
395 } | |
396 | |
397 void FragmentTexClampOpaqueBinding::init(WebGraphicsContext3D* context, unsigned
program, bool usingBindUniform, int* baseUniformIndex) | |
398 { | |
399 static const char* shaderUniforms[] = { | |
400 "s_texture", | |
401 "fragmentTexTransform", | |
402 }; | |
403 int locations[2]; | |
404 | |
405 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | |
406 | |
407 m_samplerLocation = locations[0]; | |
408 m_fragmentTexTransformLocation = locations[1]; | |
409 DCHECK(m_samplerLocation != -1); | |
410 } | |
411 | |
412 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const | 366 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const |
413 { | 367 { |
414 return SHADER( | 368 return SHADER( |
415 precision mediump float; | 369 precision mediump float; |
416 varying vec2 v_texCoord; | 370 varying vec2 v_texCoord; |
417 varying float v_alpha; | 371 varying float v_alpha; |
418 uniform sampler2D s_texture; | 372 uniform sampler2D s_texture; |
419 void main() | 373 void main() |
420 { | 374 { |
421 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC
oord.y)); | 375 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC
oord.y)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 uniform sampler2D s_texture; | 413 uniform sampler2D s_texture; |
460 uniform float alpha; | 414 uniform float alpha; |
461 void main() | 415 void main() |
462 { | 416 { |
463 vec4 texColor = texture2D(s_texture, v_texCoord); | 417 vec4 texColor = texture2D(s_texture, v_texCoord); |
464 gl_FragColor = texColor * alpha; | 418 gl_FragColor = texColor * alpha; |
465 } | 419 } |
466 ); | 420 ); |
467 } | 421 } |
468 | 422 |
469 std::string FragmentShaderRGBATexClampAlpha::getShaderString() const | |
470 { | |
471 return SHADER( | |
472 precision mediump float; | |
473 varying vec2 v_texCoord; | |
474 uniform sampler2D s_texture; | |
475 uniform float alpha; | |
476 uniform vec4 fragmentTexTransform; | |
477 void main() | |
478 { | |
479 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; | |
480 vec4 texColor = texture2D(s_texture, texCoord); | |
481 gl_FragColor = texColor * alpha; | |
482 } | |
483 ); | |
484 } | |
485 | |
486 | |
487 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const | 423 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const |
488 { | 424 { |
489 return SHADER( | 425 return SHADER( |
490 precision mediump float; | 426 precision mediump float; |
491 varying vec2 v_texCoord; | 427 varying vec2 v_texCoord; |
492 varying float v_alpha; | 428 varying float v_alpha; |
493 uniform sampler2D s_texture; | 429 uniform sampler2D s_texture; |
494 void main() | 430 void main() |
495 { | 431 { |
496 vec4 texColor = texture2D(s_texture, v_texCoord); | 432 vec4 texColor = texture2D(s_texture, v_texCoord); |
(...skipping 26 matching lines...) Expand all Loading... |
523 "varying vec2 v_texCoord;\n" | 459 "varying vec2 v_texCoord;\n" |
524 "varying float v_alpha;\n" | 460 "varying float v_alpha;\n" |
525 "uniform sampler2DRect s_texture;\n" | 461 "uniform sampler2DRect s_texture;\n" |
526 "void main()\n" | 462 "void main()\n" |
527 "{\n" | 463 "{\n" |
528 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | 464 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" |
529 " gl_FragColor = texColor * v_alpha;\n" | 465 " gl_FragColor = texColor * v_alpha;\n" |
530 "}\n"; | 466 "}\n"; |
531 } | 467 } |
532 | 468 |
533 std::string FragmentShaderRGBATexClampOpaque::getShaderString() const | 469 std::string FragmentShaderRGBATexOpaque::getShaderString() const |
534 { | 470 { |
535 return SHADER( | 471 return SHADER( |
536 precision mediump float; | 472 precision mediump float; |
537 varying vec2 v_texCoord; | 473 varying vec2 v_texCoord; |
538 uniform sampler2D s_texture; | 474 uniform sampler2D s_texture; |
539 uniform vec4 fragmentTexTransform; | |
540 void main() | 475 void main() |
541 { | 476 { |
542 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; | 477 vec4 texColor = texture2D(s_texture, v_texCoord); |
543 vec4 texColor = texture2D(s_texture, texCoord); | |
544 gl_FragColor = vec4(texColor.rgb, 1.0); | 478 gl_FragColor = vec4(texColor.rgb, 1.0); |
545 } | 479 } |
546 ); | 480 ); |
547 } | 481 } |
548 | 482 |
549 std::string FragmentShaderRGBATex::getShaderString() const | 483 std::string FragmentShaderRGBATex::getShaderString() const |
550 { | 484 { |
551 return SHADER( | 485 return SHADER( |
552 precision mediump float; | 486 precision mediump float; |
553 varying vec2 v_texCoord; | 487 varying vec2 v_texCoord; |
554 uniform sampler2D s_texture; | 488 uniform sampler2D s_texture; |
555 void main() | 489 void main() |
556 { | 490 { |
557 gl_FragColor = texture2D(s_texture, v_texCoord); | 491 gl_FragColor = texture2D(s_texture, v_texCoord); |
558 } | 492 } |
559 ); | 493 ); |
560 } | 494 } |
561 | 495 |
562 std::string FragmentShaderRGBATexClampSwizzleAlpha::getShaderString() const | 496 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const |
563 { | 497 { |
564 return SHADER( | 498 return SHADER( |
565 precision mediump float; | 499 precision mediump float; |
566 varying vec2 v_texCoord; | 500 varying vec2 v_texCoord; |
567 uniform sampler2D s_texture; | 501 uniform sampler2D s_texture; |
568 uniform float alpha; | 502 uniform float alpha; |
569 uniform vec4 fragmentTexTransform; | |
570 void main() | 503 void main() |
571 { | 504 { |
572 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; | 505 vec4 texColor = texture2D(s_texture, v_texCoord); |
573 vec4 texColor = texture2D(s_texture, texCoord); | |
574 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w)
* alpha; | 506 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w)
* alpha; |
575 } | 507 } |
576 ); | 508 ); |
577 } | 509 } |
578 | 510 |
579 std::string FragmentShaderRGBATexClampSwizzleOpaque::getShaderString() const | 511 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const |
580 { | 512 { |
581 return SHADER( | 513 return SHADER( |
582 precision mediump float; | 514 precision mediump float; |
583 varying vec2 v_texCoord; | 515 varying vec2 v_texCoord; |
584 uniform sampler2D s_texture; | 516 uniform sampler2D s_texture; |
585 uniform vec4 fragmentTexTransform; | |
586 void main() | 517 void main() |
587 { | 518 { |
588 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z
w + fragmentTexTransform.xy; | 519 vec4 texColor = texture2D(s_texture, v_texCoord); |
589 vec4 texColor = texture2D(s_texture, texCoord); | |
590 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 520 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
591 } | 521 } |
592 ); | 522 ); |
593 } | 523 } |
594 | 524 |
595 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 525 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
596 : m_samplerLocation(-1) | 526 : m_samplerLocation(-1) |
597 , m_alphaLocation(-1) | 527 , m_alphaLocation(-1) |
598 , m_edgeLocation(-1) | 528 , m_edgeLocation(-1) |
599 { | 529 { |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 vec4 color2 = color; | 896 vec4 color2 = color; |
967 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; | 897 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; |
968 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 898 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
969 float picker = abs(coord.x - coord.y); | 899 float picker = abs(coord.x - coord.y); |
970 gl_FragColor = mix(color1, color2, picker) * alpha; | 900 gl_FragColor = mix(color1, color2, picker) * alpha; |
971 } | 901 } |
972 ); | 902 ); |
973 } | 903 } |
974 | 904 |
975 } // namespace cc | 905 } // namespace cc |
OLD | NEW |