Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: cc/shader.cc

Issue 12086036: cc: Clamp texture coordinates in all tile shaders (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snowscale
Patch Set: Complete. Use _SAT+MAD clamping again. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/shader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
348 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() 373 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding()
349 : m_samplerLocation(-1) 374 : m_samplerLocation(-1)
350 { 375 {
351 } 376 }
352 377
353 void FragmentTexOpaqueBinding::init(WebGraphicsContext3D* context, unsigned prog ram, bool usingBindUniform, int* baseUniformIndex) 378 void FragmentTexOpaqueBinding::init(WebGraphicsContext3D* context, unsigned prog ram, bool usingBindUniform, int* baseUniformIndex)
354 { 379 {
355 static const char* shaderUniforms[] = { 380 static const char* shaderUniforms[] = {
356 "s_texture", 381 "s_texture",
357 }; 382 };
358 int locations[1]; 383 int locations[1];
359 384
360 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 385 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
361 386
362 m_samplerLocation = locations[0]; 387 m_samplerLocation = locations[0];
363 DCHECK(m_samplerLocation != -1); 388 DCHECK(m_samplerLocation != -1);
364 } 389 }
365 390
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
366 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const 412 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const
367 { 413 {
368 return SHADER( 414 return SHADER(
369 precision mediump float; 415 precision mediump float;
370 varying vec2 v_texCoord; 416 varying vec2 v_texCoord;
371 varying float v_alpha; 417 varying float v_alpha;
372 uniform sampler2D s_texture; 418 uniform sampler2D s_texture;
373 void main() 419 void main()
374 { 420 {
375 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC oord.y)); 421 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
413 uniform sampler2D s_texture; 459 uniform sampler2D s_texture;
414 uniform float alpha; 460 uniform float alpha;
415 void main() 461 void main()
416 { 462 {
417 vec4 texColor = texture2D(s_texture, v_texCoord); 463 vec4 texColor = texture2D(s_texture, v_texCoord);
418 gl_FragColor = texColor * alpha; 464 gl_FragColor = texColor * alpha;
419 } 465 }
420 ); 466 );
421 } 467 }
422 468
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
423 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const 487 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const
424 { 488 {
425 return SHADER( 489 return SHADER(
426 precision mediump float; 490 precision mediump float;
427 varying vec2 v_texCoord; 491 varying vec2 v_texCoord;
428 varying float v_alpha; 492 varying float v_alpha;
429 uniform sampler2D s_texture; 493 uniform sampler2D s_texture;
430 void main() 494 void main()
431 { 495 {
432 vec4 texColor = texture2D(s_texture, v_texCoord); 496 vec4 texColor = texture2D(s_texture, v_texCoord);
(...skipping 26 matching lines...) Expand all
459 "varying vec2 v_texCoord;\n" 523 "varying vec2 v_texCoord;\n"
460 "varying float v_alpha;\n" 524 "varying float v_alpha;\n"
461 "uniform sampler2DRect s_texture;\n" 525 "uniform sampler2DRect s_texture;\n"
462 "void main()\n" 526 "void main()\n"
463 "{\n" 527 "{\n"
464 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" 528 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n"
465 " gl_FragColor = texColor * v_alpha;\n" 529 " gl_FragColor = texColor * v_alpha;\n"
466 "}\n"; 530 "}\n";
467 } 531 }
468 532
469 std::string FragmentShaderRGBATexOpaque::getShaderString() const 533 std::string FragmentShaderRGBATexClampOpaque::getShaderString() const
470 { 534 {
471 return SHADER( 535 return SHADER(
472 precision mediump float; 536 precision mediump float;
473 varying vec2 v_texCoord; 537 varying vec2 v_texCoord;
474 uniform sampler2D s_texture; 538 uniform sampler2D s_texture;
539 uniform vec4 fragmentTexTransform;
475 void main() 540 void main()
476 { 541 {
477 vec4 texColor = texture2D(s_texture, v_texCoord); 542 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy;
543 vec4 texColor = texture2D(s_texture, texCoord);
478 gl_FragColor = vec4(texColor.rgb, 1.0); 544 gl_FragColor = vec4(texColor.rgb, 1.0);
479 } 545 }
480 ); 546 );
481 } 547 }
482 548
483 std::string FragmentShaderRGBATex::getShaderString() const 549 std::string FragmentShaderRGBATex::getShaderString() const
484 { 550 {
485 return SHADER( 551 return SHADER(
486 precision mediump float; 552 precision mediump float;
487 varying vec2 v_texCoord; 553 varying vec2 v_texCoord;
488 uniform sampler2D s_texture; 554 uniform sampler2D s_texture;
489 void main() 555 void main()
490 { 556 {
491 gl_FragColor = texture2D(s_texture, v_texCoord); 557 gl_FragColor = texture2D(s_texture, v_texCoord);
492 } 558 }
493 ); 559 );
494 } 560 }
495 561
496 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const 562 std::string FragmentShaderRGBATexClampSwizzleAlpha::getShaderString() const
497 { 563 {
498 return SHADER( 564 return SHADER(
499 precision mediump float; 565 precision mediump float;
500 varying vec2 v_texCoord; 566 varying vec2 v_texCoord;
501 uniform sampler2D s_texture; 567 uniform sampler2D s_texture;
502 uniform float alpha; 568 uniform float alpha;
569 uniform vec4 fragmentTexTransform;
503 void main() 570 void main()
504 { 571 {
505 vec4 texColor = texture2D(s_texture, v_texCoord); 572 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy;
573 vec4 texColor = texture2D(s_texture, texCoord);
506 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; 574 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha;
507 } 575 }
508 ); 576 );
509 } 577 }
510 578
511 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const 579 std::string FragmentShaderRGBATexClampSwizzleOpaque::getShaderString() const
512 { 580 {
513 return SHADER( 581 return SHADER(
514 precision mediump float; 582 precision mediump float;
515 varying vec2 v_texCoord; 583 varying vec2 v_texCoord;
516 uniform sampler2D s_texture; 584 uniform sampler2D s_texture;
585 uniform vec4 fragmentTexTransform;
517 void main() 586 void main()
518 { 587 {
519 vec4 texColor = texture2D(s_texture, v_texCoord); 588 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy;
589 vec4 texColor = texture2D(s_texture, texCoord);
520 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); 590 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0);
521 } 591 }
522 ); 592 );
523 } 593 }
524 594
525 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() 595 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA()
526 : m_samplerLocation(-1) 596 : m_samplerLocation(-1)
527 , m_alphaLocation(-1) 597 , m_alphaLocation(-1)
528 , m_edgeLocation(-1) 598 , m_edgeLocation(-1)
529 { 599 {
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 vec4 color2 = color; 966 vec4 color2 = color;
897 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; 967 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy;
898 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 968 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
899 float picker = abs(coord.x - coord.y); 969 float picker = abs(coord.x - coord.y);
900 gl_FragColor = mix(color1, color2, picker) * alpha; 970 gl_FragColor = mix(color1, color2, picker) * alpha;
901 } 971 }
902 ); 972 );
903 } 973 }
904 974
905 } // namespace cc 975 } // namespace cc
OLDNEW
« no previous file with comments | « cc/shader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698