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.
5 #include "cc/output/shader.h"
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11 #include "cc/output/gl_renderer.h" // For the GLC() macro.
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
13 #include "third_party/khronos/GLES2/gl2.h"
15 #define SHADER0(Src) #Src
16 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src))
17 #define FRAGMENT_SHADER(Src) SetFragTexCoordPrecision(precision, SHADER0(Src))
19 using WebKit::WebGraphicsContext3D
;
25 static void GetProgramUniformLocations(WebGraphicsContext3D
* context
,
27 const char** shader_uniforms
,
31 bool using_bind_uniform
,
32 int* base_uniform_index
) {
33 for (size_t uniform_index
= 0; uniform_index
< count
; uniform_index
++) {
34 DCHECK(uniform_index
< max_locations
);
36 if (using_bind_uniform
) {
37 locations
[uniform_index
] = (*base_uniform_index
)++;
38 context
->bindUniformLocationCHROMIUM(program
,
39 locations
[uniform_index
],
40 shader_uniforms
[uniform_index
]);
42 locations
[uniform_index
] =
43 context
->getUniformLocation(program
, shader_uniforms
[uniform_index
]);
48 static std::string
SetFragTexCoordPrecision(
49 TexCoordPrecision requested_precision
, std::string shader_string
) {
50 switch (requested_precision
) {
51 case TexCoordPrecisionHigh
:
52 DCHECK_NE(shader_string
.find("TexCoordPrecision"), std::string::npos
);
54 "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
55 " #define TexCoordPrecision highp\n"
57 " #define TexCoordPrecision mediump\n"
60 case TexCoordPrecisionMedium
:
61 DCHECK_NE(shader_string
.find("TexCoordPrecision"), std::string::npos
);
62 return "#define TexCoordPrecision mediump\n" +
64 case TexCoordPrecisionNA
:
65 DCHECK_EQ(shader_string
.find("TexCoordPrecision"), std::string::npos
);
66 DCHECK_EQ(shader_string
.find("texture2D"), std::string::npos
);
72 static std::string
SetVertexTexCoordPrecision(const char* shader_string
) {
73 // We unconditionally use highp in the vertex shader since
74 // we are unlikely to be vertex shader bound when drawing large quads.
75 // Also, some vertex shaders mutate the texture coordinate in such a
76 // way that the effective precision might be lower than expected.
77 return "#define TexCoordPrecision highp\n" +
78 std::string(shader_string
);
81 TexCoordPrecision
TexCoordPrecisionRequired(WebGraphicsContext3D
* context
,
82 int highp_threshold_min
,
84 // Initialize range and precision with minimum spec values for when
85 // GetShaderPrecisionFormat is a test stub.
86 // TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat
88 GLint range
[2] = { 14, 14 };
90 GLC(context
, context
->getShaderPrecisionFormat(GL_FRAGMENT_SHADER
,
93 int highp_threshold
= std::max(1 << precision
, highp_threshold_min
);
94 if (x
> highp_threshold
|| y
> highp_threshold
)
95 return TexCoordPrecisionHigh
;
96 return TexCoordPrecisionMedium
;
101 TexCoordPrecision
TexCoordPrecisionRequired(WebGraphicsContext3D
* context
,
102 int highp_threshold_min
,
103 gfx::Point max_coordinate
) {
104 return TexCoordPrecisionRequired(context
, highp_threshold_min
,
105 max_coordinate
.x(), max_coordinate
.y());
108 TexCoordPrecision
TexCoordPrecisionRequired(WebGraphicsContext3D
* context
,
109 int highp_threshold_min
,
110 gfx::Size max_size
) {
111 return TexCoordPrecisionRequired(context
, highp_threshold_min
,
112 max_size
.width(), max_size
.height());
115 VertexShaderPosTex::VertexShaderPosTex()
116 : matrix_location_(-1) {}
118 void VertexShaderPosTex::Init(WebGraphicsContext3D
* context
,
120 bool using_bind_uniform
,
121 int* base_uniform_index
) {
122 static const char* shader_uniforms
[] = {
127 GetProgramUniformLocations(context
,
130 arraysize(shader_uniforms
),
131 arraysize(locations
),
136 matrix_location_
= locations
[0];
137 DCHECK_NE(matrix_location_
, -1);
140 std::string
VertexShaderPosTex::GetShaderString() const {
141 return VERTEX_SHADER(
142 attribute vec4 a_position
;
143 attribute TexCoordPrecision vec2 a_texCoord
;
145 varying TexCoordPrecision vec2 v_texCoord
;
147 gl_Position
= matrix
* a_position
;
148 v_texCoord
= a_texCoord
;
150 ); // NOLINT(whitespace/parens)
153 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch()
154 : matrix_location_(-1),
155 tex_scale_location_(-1) {}
157 void VertexShaderPosTexYUVStretch::Init(WebGraphicsContext3D
* context
,
159 bool using_bind_uniform
,
160 int* base_uniform_index
) {
161 static const char* shader_uniforms
[] = {
167 GetProgramUniformLocations(context
,
170 arraysize(shader_uniforms
),
171 arraysize(locations
),
176 matrix_location_
= locations
[0];
177 tex_scale_location_
= locations
[1];
178 DCHECK(matrix_location_
!= -1 && tex_scale_location_
!= -1);
181 std::string
VertexShaderPosTexYUVStretch::GetShaderString() const {
182 return VERTEX_SHADER(
183 precision mediump
float;
184 attribute vec4 a_position
;
185 attribute TexCoordPrecision vec2 a_texCoord
;
187 varying TexCoordPrecision vec2 v_texCoord
;
188 uniform TexCoordPrecision vec2 texScale
;
190 gl_Position
= matrix
* a_position
;
191 v_texCoord
= a_texCoord
* texScale
;
193 ); // NOLINT(whitespace/parens)
196 VertexShaderPos::VertexShaderPos()
197 : matrix_location_(-1) {}
199 void VertexShaderPos::Init(WebGraphicsContext3D
* context
,
201 bool using_bind_uniform
,
202 int* base_uniform_index
) {
203 static const char* shader_uniforms
[] = {
208 GetProgramUniformLocations(context
,
211 arraysize(shader_uniforms
),
212 arraysize(locations
),
217 matrix_location_
= locations
[0];
218 DCHECK_NE(matrix_location_
, -1);
221 std::string
VertexShaderPos::GetShaderString() const {
222 return VERTEX_SHADER(
223 attribute vec4 a_position
;
226 gl_Position
= matrix
* a_position
;
228 ); // NOLINT(whitespace/parens)
231 VertexShaderPosTexTransform::VertexShaderPosTexTransform()
232 : matrix_location_(-1),
233 tex_transform_location_(-1),
234 vertex_opacity_location_(-1) {}
236 void VertexShaderPosTexTransform::Init(WebGraphicsContext3D
* context
,
238 bool using_bind_uniform
,
239 int* base_uniform_index
) {
240 static const char* shader_uniforms
[] = {
247 GetProgramUniformLocations(context
,
250 arraysize(shader_uniforms
),
251 arraysize(locations
),
256 matrix_location_
= locations
[0];
257 tex_transform_location_
= locations
[1];
258 vertex_opacity_location_
= locations
[2];
259 DCHECK(matrix_location_
!= -1 && tex_transform_location_
!= -1 &&
260 vertex_opacity_location_
!= -1);
263 std::string
VertexShaderPosTexTransform::GetShaderString() const {
264 return VERTEX_SHADER(
265 attribute vec4 a_position
;
266 attribute TexCoordPrecision vec2 a_texCoord
;
267 attribute
float a_index
;
268 uniform mat4 matrix
[8];
269 uniform TexCoordPrecision vec4 texTransform
[8];
270 uniform
float opacity
[32];
271 varying TexCoordPrecision vec2 v_texCoord
;
272 varying
float v_alpha
;
274 gl_Position
= matrix
[int(a_index
* 0.25)] * a_position
; // NOLINT
275 TexCoordPrecision vec4 texTrans
=
276 texTransform
[int(a_index
* 0.25)]; // NOLINT
277 v_texCoord
= a_texCoord
* texTrans
.zw
+ texTrans
.xy
;
278 v_alpha
= opacity
[int(a_index
)]; // NOLINT
280 ); // NOLINT(whitespace/parens)
283 std::string
VertexShaderPosTexTransformFlip::GetShaderString() const {
284 return VERTEX_SHADER(
285 attribute vec4 a_position
;
286 attribute TexCoordPrecision vec2 a_texCoord
;
287 attribute
float a_index
;
288 uniform mat4 matrix
[8];
289 uniform TexCoordPrecision vec4 texTransform
[8];
290 uniform
float opacity
[32];
291 varying TexCoordPrecision vec2 v_texCoord
;
292 varying
float v_alpha
;
294 gl_Position
= matrix
[int(a_index
* 0.25)] * a_position
; // NOLINT
295 TexCoordPrecision vec4 texTrans
=
296 texTransform
[int(a_index
* 0.25)]; // NOLINT
297 v_texCoord
= a_texCoord
* texTrans
.zw
+ texTrans
.xy
;
298 v_texCoord
.y
= 1.0 - v_texCoord
.y
;
299 v_alpha
= opacity
[int(a_index
)]; // NOLINT
301 ); // NOLINT(whitespace/parens)
304 std::string
VertexShaderPosTexIdentity::GetShaderString() const {
305 return VERTEX_SHADER(
306 attribute vec4 a_position
;
307 varying TexCoordPrecision vec2 v_texCoord
;
309 gl_Position
= a_position
;
310 v_texCoord
= (a_position
.xy
+ vec2(1.0)) * 0.5;
312 ); // NOLINT(whitespace/parens)
315 VertexShaderQuad::VertexShaderQuad()
316 : matrix_location_(-1),
318 tex_scale_location_(-1) {}
320 void VertexShaderQuad::Init(WebGraphicsContext3D
* context
,
322 bool using_bind_uniform
,
323 int* base_uniform_index
) {
324 static const char* shader_uniforms
[] = {
331 GetProgramUniformLocations(context
,
334 arraysize(shader_uniforms
),
335 arraysize(locations
),
340 matrix_location_
= locations
[0];
341 point_location_
= locations
[1];
342 tex_scale_location_
= locations
[2];
343 DCHECK_NE(matrix_location_
, -1);
344 DCHECK_NE(point_location_
, -1);
345 DCHECK_NE(tex_scale_location_
, -1);
348 std::string
VertexShaderQuad::GetShaderString() const {
349 return VERTEX_SHADER(
350 attribute TexCoordPrecision vec4 a_position
;
351 attribute TexCoordPrecision vec2 a_texCoord
;
353 uniform TexCoordPrecision vec2 point
[4];
354 uniform TexCoordPrecision vec2 texScale
;
355 varying TexCoordPrecision vec2 v_texCoord
;
357 TexCoordPrecision vec2 complement
= abs(a_texCoord
- 1.0);
358 TexCoordPrecision vec4 pos
= vec4(0.0, 0.0, a_position
.z
, a_position
.w
);
359 pos
.xy
+= (complement
.x
* complement
.y
) * point
[0];
360 pos
.xy
+= (a_texCoord
.x
* complement
.y
) * point
[1];
361 pos
.xy
+= (a_texCoord
.x
* a_texCoord
.y
) * point
[2];
362 pos
.xy
+= (complement
.x
* a_texCoord
.y
) * point
[3];
363 gl_Position
= matrix
* pos
;
364 v_texCoord
= (pos
.xy
+ vec2(0.5)) * texScale
;
366 ); // NOLINT(whitespace/parens)
369 VertexShaderTile::VertexShaderTile()
370 : matrix_location_(-1),
372 vertex_tex_transform_location_(-1) {}
374 void VertexShaderTile::Init(WebGraphicsContext3D
* context
,
376 bool using_bind_uniform
,
377 int* base_uniform_index
) {
378 static const char* shader_uniforms
[] = {
381 "vertexTexTransform",
385 GetProgramUniformLocations(context
,
388 arraysize(shader_uniforms
),
389 arraysize(locations
),
394 matrix_location_
= locations
[0];
395 point_location_
= locations
[1];
396 vertex_tex_transform_location_
= locations
[2];
397 DCHECK(matrix_location_
!= -1 && point_location_
!= -1 &&
398 vertex_tex_transform_location_
!= -1);
401 std::string
VertexShaderTile::GetShaderString() const {
402 return VERTEX_SHADER(
403 attribute TexCoordPrecision vec4 a_position
;
404 attribute TexCoordPrecision vec2 a_texCoord
;
406 uniform TexCoordPrecision vec2 point
[4];
407 uniform TexCoordPrecision vec4 vertexTexTransform
;
408 varying TexCoordPrecision vec2 v_texCoord
;
410 TexCoordPrecision vec2 complement
= abs(a_texCoord
- 1.0);
411 TexCoordPrecision vec4 pos
= vec4(0.0, 0.0, a_position
.z
, a_position
.w
);
412 pos
.xy
+= (complement
.x
* complement
.y
) * point
[0];
413 pos
.xy
+= (a_texCoord
.x
* complement
.y
) * point
[1];
414 pos
.xy
+= (a_texCoord
.x
* a_texCoord
.y
) * point
[2];
415 pos
.xy
+= (complement
.x
* a_texCoord
.y
) * point
[3];
416 gl_Position
= matrix
* pos
;
417 v_texCoord
= pos
.xy
* vertexTexTransform
.zw
+ vertexTexTransform
.xy
;
419 ); // NOLINT(whitespace/parens)
422 VertexShaderVideoTransform::VertexShaderVideoTransform()
423 : matrix_location_(-1),
424 tex_matrix_location_(-1) {}
426 bool VertexShaderVideoTransform::Init(WebGraphicsContext3D
* context
,
428 bool using_bind_uniform
,
429 int* base_uniform_index
) {
430 static const char* shader_uniforms
[] = {
436 GetProgramUniformLocations(context
,
439 arraysize(shader_uniforms
),
440 arraysize(locations
),
445 matrix_location_
= locations
[0];
446 tex_matrix_location_
= locations
[1];
447 return matrix_location_
!= -1 && tex_matrix_location_
!= -1;
450 std::string
VertexShaderVideoTransform::GetShaderString() const {
451 return VERTEX_SHADER(
452 attribute vec4 a_position
;
453 attribute TexCoordPrecision vec2 a_texCoord
;
455 uniform TexCoordPrecision mat4 texMatrix
;
456 varying TexCoordPrecision vec2 v_texCoord
;
458 gl_Position
= matrix
* a_position
;
460 vec2(texMatrix
* vec4(a_texCoord
.x
, 1.0 - a_texCoord
.y
, 0.0, 1.0));
462 ); // NOLINT(whitespace/parens)
465 FragmentTexAlphaBinding::FragmentTexAlphaBinding()
466 : sampler_location_(-1),
467 alpha_location_(-1) {}
469 void FragmentTexAlphaBinding::Init(WebGraphicsContext3D
* context
,
471 bool using_bind_uniform
,
472 int* base_uniform_index
) {
473 static const char* shader_uniforms
[] = {
479 GetProgramUniformLocations(context
,
482 arraysize(shader_uniforms
),
483 arraysize(locations
),
488 sampler_location_
= locations
[0];
489 alpha_location_
= locations
[1];
490 DCHECK(sampler_location_
!= -1 && alpha_location_
!= -1);
493 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding()
494 : sampler_location_(-1),
496 color_matrix_location_(-1),
497 color_offset_location_(-1) {}
499 void FragmentTexColorMatrixAlphaBinding::Init(WebGraphicsContext3D
* context
,
501 bool using_bind_uniform
,
502 int* base_uniform_index
) {
503 static const char* shader_uniforms
[] = {
511 GetProgramUniformLocations(context
,
514 arraysize(shader_uniforms
),
515 arraysize(locations
),
520 sampler_location_
= locations
[0];
521 alpha_location_
= locations
[1];
522 color_matrix_location_
= locations
[2];
523 color_offset_location_
= locations
[3];
524 DCHECK(sampler_location_
!= -1 && alpha_location_
!= -1 &&
525 color_matrix_location_
!= -1 && color_offset_location_
!= -1);
528 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding()
529 : sampler_location_(-1) {}
531 void FragmentTexOpaqueBinding::Init(WebGraphicsContext3D
* context
,
533 bool using_bind_uniform
,
534 int* base_uniform_index
) {
535 static const char* shader_uniforms
[] = {
540 GetProgramUniformLocations(context
,
543 arraysize(shader_uniforms
),
544 arraysize(locations
),
549 sampler_location_
= locations
[0];
550 DCHECK_NE(sampler_location_
, -1);
553 FragmentShaderOESImageExternal::FragmentShaderOESImageExternal()
554 : sampler_location_(-1) {}
556 bool FragmentShaderOESImageExternal::Init(WebGraphicsContext3D
* context
,
558 bool using_bind_uniform
,
559 int* base_uniform_index
) {
560 static const char* shader_uniforms
[] = {
565 GetProgramUniformLocations(context
,
568 arraysize(shader_uniforms
),
569 arraysize(locations
),
574 sampler_location_
= locations
[0];
575 return sampler_location_
!= -1;
578 std::string
FragmentShaderOESImageExternal::GetShaderString(
579 TexCoordPrecision precision
) const {
580 // Cannot use the SHADER() macro because of the '#' char
581 return "#extension GL_OES_EGL_image_external : require\n" +
583 precision mediump
float;
584 varying TexCoordPrecision vec2 v_texCoord
;
585 uniform samplerExternalOES s_texture
;
587 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
588 gl_FragColor
= vec4(texColor
.x
, texColor
.y
, texColor
.z
, texColor
.w
);
590 ); // NOLINT(whitespace/parens)
593 std::string
FragmentShaderRGBATexAlpha::GetShaderString(
594 TexCoordPrecision precision
) const {
595 return FRAGMENT_SHADER(
596 precision mediump
float;
597 varying TexCoordPrecision vec2 v_texCoord
;
598 uniform sampler2D s_texture
;
601 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
602 gl_FragColor
= texColor
* alpha
;
604 ); // NOLINT(whitespace/parens)
607 std::string
FragmentShaderRGBATexColorMatrixAlpha::GetShaderString(
608 TexCoordPrecision precision
) const {
609 return FRAGMENT_SHADER(
610 precision mediump
float;
611 varying TexCoordPrecision vec2 v_texCoord
;
612 uniform sampler2D s_texture
;
614 uniform mat4 colorMatrix
;
615 uniform vec4 colorOffset
;
617 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
618 float nonZeroAlpha
= max(texColor
.a
, 0.00001);
619 texColor
= vec4(texColor
.rgb
/ nonZeroAlpha
, nonZeroAlpha
);
620 texColor
= colorMatrix
* texColor
+ colorOffset
;
621 texColor
.rgb
*= texColor
.a
;
622 texColor
= clamp(texColor
, 0.0, 1.0);
623 gl_FragColor
= texColor
* alpha
;
625 ); // NOLINT(whitespace/parens)
628 std::string
FragmentShaderRGBATexVaryingAlpha::GetShaderString(
629 TexCoordPrecision precision
) const {
630 return FRAGMENT_SHADER(
631 precision mediump
float;
632 varying TexCoordPrecision vec2 v_texCoord
;
633 varying
float v_alpha
;
634 uniform sampler2D s_texture
;
636 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
637 gl_FragColor
= texColor
* v_alpha
;
639 ); // NOLINT(whitespace/parens)
642 std::string
FragmentShaderRGBATexRectVaryingAlpha::GetShaderString(
643 TexCoordPrecision precision
) const {
644 return "#extension GL_ARB_texture_rectangle : require\n" +
646 precision mediump
float;
647 varying TexCoordPrecision vec2 v_texCoord
;
648 varying
float v_alpha
;
649 uniform sampler2DRect s_texture
;
651 vec4 texColor
= texture2DRect(s_texture
, v_texCoord
);
652 gl_FragColor
= texColor
* v_alpha
;
654 ); // NOLINT(whitespace/parens)
657 std::string
FragmentShaderRGBATexOpaque::GetShaderString(
658 TexCoordPrecision precision
) const {
659 return FRAGMENT_SHADER(
660 precision mediump
float;
661 varying TexCoordPrecision vec2 v_texCoord
;
662 uniform sampler2D s_texture
;
664 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
665 gl_FragColor
= vec4(texColor
.rgb
, 1.0);
667 ); // NOLINT(whitespace/parens)
670 std::string
FragmentShaderRGBATex::GetShaderString(
671 TexCoordPrecision precision
) const {
672 return FRAGMENT_SHADER(
673 precision mediump
float;
674 varying TexCoordPrecision vec2 v_texCoord
;
675 uniform sampler2D s_texture
;
677 gl_FragColor
= texture2D(s_texture
, v_texCoord
);
679 ); // NOLINT(whitespace/parens)
682 std::string
FragmentShaderRGBATexSwizzleAlpha::GetShaderString(
683 TexCoordPrecision precision
) const {
684 return FRAGMENT_SHADER(
685 precision mediump
float;
686 varying TexCoordPrecision vec2 v_texCoord
;
687 uniform sampler2D s_texture
;
690 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
692 vec4(texColor
.z
, texColor
.y
, texColor
.x
, texColor
.w
) * alpha
;
694 ); // NOLINT(whitespace/parens)
697 std::string
FragmentShaderRGBATexSwizzleOpaque::GetShaderString(
698 TexCoordPrecision precision
) const {
699 return FRAGMENT_SHADER(
700 precision mediump
float;
701 varying TexCoordPrecision vec2 v_texCoord
;
702 uniform sampler2D s_texture
;
704 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
705 gl_FragColor
= vec4(texColor
.z
, texColor
.y
, texColor
.x
, 1.0);
707 ); // NOLINT(whitespace/parens)
710 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA()
711 : sampler_location_(-1),
713 edge_location_(-1) {}
715 void FragmentShaderRGBATexAlphaAA::Init(WebGraphicsContext3D
* context
,
717 bool using_bind_uniform
,
718 int* base_uniform_index
) {
719 static const char* shader_uniforms
[] = {
726 GetProgramUniformLocations(context
,
729 arraysize(shader_uniforms
),
730 arraysize(locations
),
735 sampler_location_
= locations
[0];
736 alpha_location_
= locations
[1];
737 edge_location_
= locations
[2];
738 DCHECK(sampler_location_
!= -1 && alpha_location_
!= -1 &&
739 edge_location_
!= -1);
742 std::string
FragmentShaderRGBATexAlphaAA::GetShaderString(
743 TexCoordPrecision precision
) const {
744 return FRAGMENT_SHADER(
745 precision mediump
float;
746 varying TexCoordPrecision vec2 v_texCoord
;
747 uniform sampler2D s_texture
;
749 uniform vec3 edge
[8];
751 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
752 vec3 pos
= vec3(gl_FragCoord
.xy
, 1);
753 float a0
= clamp(dot(edge
[0], pos
), 0.0, 1.0);
754 float a1
= clamp(dot(edge
[1], pos
), 0.0, 1.0);
755 float a2
= clamp(dot(edge
[2], pos
), 0.0, 1.0);
756 float a3
= clamp(dot(edge
[3], pos
), 0.0, 1.0);
757 float a4
= clamp(dot(edge
[4], pos
), 0.0, 1.0);
758 float a5
= clamp(dot(edge
[5], pos
), 0.0, 1.0);
759 float a6
= clamp(dot(edge
[6], pos
), 0.0, 1.0);
760 float a7
= clamp(dot(edge
[7], pos
), 0.0, 1.0);
761 gl_FragColor
= texColor
* alpha
* min(min(a0
, a2
) * min(a1
, a3
),
762 min(a4
, a6
) * min(a5
, a7
));
764 ); // NOLINT(whitespace/parens)
767 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding()
768 : sampler_location_(-1),
770 fragment_tex_transform_location_(-1),
771 edge_location_(-1) {}
773 void FragmentTexClampAlphaAABinding::Init(WebGraphicsContext3D
* context
,
775 bool using_bind_uniform
,
776 int* base_uniform_index
) {
777 static const char* shader_uniforms
[] = {
780 "fragmentTexTransform",
785 GetProgramUniformLocations(context
,
788 arraysize(shader_uniforms
),
789 arraysize(locations
),
794 sampler_location_
= locations
[0];
795 alpha_location_
= locations
[1];
796 fragment_tex_transform_location_
= locations
[2];
797 edge_location_
= locations
[3];
798 DCHECK(sampler_location_
!= -1 && alpha_location_
!= -1 &&
799 fragment_tex_transform_location_
!= -1 && edge_location_
!= -1);
802 std::string
FragmentShaderRGBATexClampAlphaAA::GetShaderString(
803 TexCoordPrecision precision
) const {
804 return FRAGMENT_SHADER(
805 precision mediump
float;
806 varying TexCoordPrecision vec2 v_texCoord
;
807 uniform sampler2D s_texture
;
809 uniform TexCoordPrecision vec4 fragmentTexTransform
;
810 uniform vec3 edge
[8];
812 TexCoordPrecision vec2 texCoord
=
813 clamp(v_texCoord
, 0.0, 1.0) * fragmentTexTransform
.zw
+
814 fragmentTexTransform
.xy
;
815 vec4 texColor
= texture2D(s_texture
, texCoord
);
816 vec3 pos
= vec3(gl_FragCoord
.xy
, 1);
817 float a0
= clamp(dot(edge
[0], pos
), 0.0, 1.0);
818 float a1
= clamp(dot(edge
[1], pos
), 0.0, 1.0);
819 float a2
= clamp(dot(edge
[2], pos
), 0.0, 1.0);
820 float a3
= clamp(dot(edge
[3], pos
), 0.0, 1.0);
821 float a4
= clamp(dot(edge
[4], pos
), 0.0, 1.0);
822 float a5
= clamp(dot(edge
[5], pos
), 0.0, 1.0);
823 float a6
= clamp(dot(edge
[6], pos
), 0.0, 1.0);
824 float a7
= clamp(dot(edge
[7], pos
), 0.0, 1.0);
825 gl_FragColor
= texColor
* alpha
* min(min(a0
, a2
) * min(a1
, a3
),
826 min(a4
, a6
) * min(a5
, a7
));
828 ); // NOLINT(whitespace/parens)
831 std::string
FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString(
832 TexCoordPrecision precision
) const {
833 return FRAGMENT_SHADER(
834 precision mediump
float;
835 varying TexCoordPrecision vec2 v_texCoord
;
836 uniform sampler2D s_texture
;
838 uniform TexCoordPrecision vec4 fragmentTexTransform
;
839 uniform vec3 edge
[8];
841 TexCoordPrecision vec2 texCoord
=
842 clamp(v_texCoord
, 0.0, 1.0) * fragmentTexTransform
.zw
+
843 fragmentTexTransform
.xy
;
844 vec4 texColor
= texture2D(s_texture
, texCoord
);
845 vec3 pos
= vec3(gl_FragCoord
.xy
, 1);
846 float a0
= clamp(dot(edge
[0], pos
), 0.0, 1.0);
847 float a1
= clamp(dot(edge
[1], pos
), 0.0, 1.0);
848 float a2
= clamp(dot(edge
[2], pos
), 0.0, 1.0);
849 float a3
= clamp(dot(edge
[3], pos
), 0.0, 1.0);
850 float a4
= clamp(dot(edge
[4], pos
), 0.0, 1.0);
851 float a5
= clamp(dot(edge
[5], pos
), 0.0, 1.0);
852 float a6
= clamp(dot(edge
[6], pos
), 0.0, 1.0);
853 float a7
= clamp(dot(edge
[7], pos
), 0.0, 1.0);
854 gl_FragColor
= vec4(texColor
.z
, texColor
.y
, texColor
.x
, texColor
.w
) *
855 alpha
* min(min(a0
, a2
) * min(a1
, a3
), min(a4
, a6
) * min(a5
, a7
));
857 ); // NOLINT(whitespace/parens)
860 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask()
861 : sampler_location_(-1),
862 mask_sampler_location_(-1),
864 mask_tex_coord_scale_location_(-1) {}
866 void FragmentShaderRGBATexAlphaMask::Init(WebGraphicsContext3D
* context
,
868 bool using_bind_uniform
,
869 int* base_uniform_index
) {
870 static const char* shader_uniforms
[] = {
875 "maskTexCoordOffset",
879 GetProgramUniformLocations(context
,
882 arraysize(shader_uniforms
),
883 arraysize(locations
),
888 sampler_location_
= locations
[0];
889 mask_sampler_location_
= locations
[1];
890 alpha_location_
= locations
[2];
891 mask_tex_coord_scale_location_
= locations
[3];
892 mask_tex_coord_offset_location_
= locations
[4];
893 DCHECK(sampler_location_
!= -1 && mask_sampler_location_
!= -1 &&
894 alpha_location_
!= -1);
897 std::string
FragmentShaderRGBATexAlphaMask::GetShaderString(
898 TexCoordPrecision precision
) const {
899 return FRAGMENT_SHADER(
900 precision mediump
float;
901 varying TexCoordPrecision vec2 v_texCoord
;
902 uniform sampler2D s_texture
;
903 uniform sampler2D s_mask
;
904 uniform TexCoordPrecision vec2 maskTexCoordScale
;
905 uniform TexCoordPrecision vec2 maskTexCoordOffset
;
908 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
909 TexCoordPrecision vec2 maskTexCoord
=
910 vec2(maskTexCoordOffset
.x
+ v_texCoord
.x
* maskTexCoordScale
.x
,
911 maskTexCoordOffset
.y
+ v_texCoord
.y
* maskTexCoordScale
.y
);
912 vec4 maskColor
= texture2D(s_mask
, maskTexCoord
);
913 gl_FragColor
= vec4(texColor
.x
, texColor
.y
,
914 texColor
.z
, texColor
.w
) * alpha
* maskColor
.w
;
916 ); // NOLINT(whitespace/parens)
919 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
920 : sampler_location_(-1),
921 mask_sampler_location_(-1),
924 mask_tex_coord_scale_location_(-1) {}
926 void FragmentShaderRGBATexAlphaMaskAA::Init(WebGraphicsContext3D
* context
,
928 bool using_bind_uniform
,
929 int* base_uniform_index
) {
930 static const char* shader_uniforms
[] = {
936 "maskTexCoordOffset",
940 GetProgramUniformLocations(context
,
943 arraysize(shader_uniforms
),
944 arraysize(locations
),
949 sampler_location_
= locations
[0];
950 mask_sampler_location_
= locations
[1];
951 alpha_location_
= locations
[2];
952 edge_location_
= locations
[3];
953 mask_tex_coord_scale_location_
= locations
[4];
954 mask_tex_coord_offset_location_
= locations
[5];
955 DCHECK(sampler_location_
!= -1 && mask_sampler_location_
!= -1 &&
956 alpha_location_
!= -1 && edge_location_
!= -1);
959 std::string
FragmentShaderRGBATexAlphaMaskAA::GetShaderString(
960 TexCoordPrecision precision
) const {
961 return FRAGMENT_SHADER(
962 precision mediump
float;
963 varying TexCoordPrecision vec2 v_texCoord
;
964 uniform sampler2D s_texture
;
965 uniform sampler2D s_mask
;
966 uniform TexCoordPrecision vec2 maskTexCoordScale
;
967 uniform TexCoordPrecision vec2 maskTexCoordOffset
;
969 uniform vec3 edge
[8];
971 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
972 TexCoordPrecision vec2 maskTexCoord
=
973 vec2(maskTexCoordOffset
.x
+ v_texCoord
.x
* maskTexCoordScale
.x
,
974 maskTexCoordOffset
.y
+ v_texCoord
.y
* maskTexCoordScale
.y
);
975 vec4 maskColor
= texture2D(s_mask
, maskTexCoord
);
976 vec3 pos
= vec3(gl_FragCoord
.xy
, 1);
977 float a0
= clamp(dot(edge
[0], pos
), 0.0, 1.0);
978 float a1
= clamp(dot(edge
[1], pos
), 0.0, 1.0);
979 float a2
= clamp(dot(edge
[2], pos
), 0.0, 1.0);
980 float a3
= clamp(dot(edge
[3], pos
), 0.0, 1.0);
981 float a4
= clamp(dot(edge
[4], pos
), 0.0, 1.0);
982 float a5
= clamp(dot(edge
[5], pos
), 0.0, 1.0);
983 float a6
= clamp(dot(edge
[6], pos
), 0.0, 1.0);
984 float a7
= clamp(dot(edge
[7], pos
), 0.0, 1.0);
985 gl_FragColor
= vec4(texColor
.x
, texColor
.y
, texColor
.z
, texColor
.w
) *
986 alpha
* maskColor
.w
* min(min(a0
, a2
) * min(a1
, a3
),
987 min(a4
, a6
) * min(a5
, a7
));
989 ); // NOLINT(whitespace/parens)
992 FragmentShaderRGBATexAlphaMaskColorMatrixAA::
993 FragmentShaderRGBATexAlphaMaskColorMatrixAA()
994 : sampler_location_(-1),
995 mask_sampler_location_(-1),
998 mask_tex_coord_scale_location_(-1),
999 color_matrix_location_(-1),
1000 color_offset_location_(-1) {}
1002 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init(
1003 WebGraphicsContext3D
* context
,
1005 bool using_bind_uniform
,
1006 int* base_uniform_index
) {
1007 static const char* shader_uniforms
[] = {
1012 "maskTexCoordScale",
1013 "maskTexCoordOffset",
1019 GetProgramUniformLocations(context
,
1022 arraysize(shader_uniforms
),
1023 arraysize(locations
),
1026 base_uniform_index
);
1028 sampler_location_
= locations
[0];
1029 mask_sampler_location_
= locations
[1];
1030 alpha_location_
= locations
[2];
1031 edge_location_
= locations
[3];
1032 mask_tex_coord_scale_location_
= locations
[4];
1033 mask_tex_coord_offset_location_
= locations
[5];
1034 color_matrix_location_
= locations
[6];
1035 color_offset_location_
= locations
[7];
1036 DCHECK(sampler_location_
!= -1 && mask_sampler_location_
!= -1 &&
1037 alpha_location_
!= -1 && edge_location_
!= -1 &&
1038 color_matrix_location_
!= -1 && color_offset_location_
!= -1);
1041 std::string
FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString(
1042 TexCoordPrecision precision
) const {
1043 return FRAGMENT_SHADER(
1044 precision mediump
float;
1045 varying TexCoordPrecision vec2 v_texCoord
;
1046 uniform sampler2D s_texture
;
1047 uniform sampler2D s_mask
;
1048 uniform vec2 maskTexCoordScale
;
1049 uniform vec2 maskTexCoordOffset
;
1050 uniform mat4 colorMatrix
;
1051 uniform vec4 colorOffset
;
1052 uniform
float alpha
;
1053 uniform vec3 edge
[8];
1055 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
1056 float nonZeroAlpha
= max(texColor
.a
, 0.00001);
1057 texColor
= vec4(texColor
.rgb
/ nonZeroAlpha
, nonZeroAlpha
);
1058 texColor
= colorMatrix
* texColor
+ colorOffset
;
1059 texColor
.rgb
*= texColor
.a
;
1060 texColor
= clamp(texColor
, 0.0, 1.0);
1061 TexCoordPrecision vec2 maskTexCoord
=
1062 vec2(maskTexCoordOffset
.x
+ v_texCoord
.x
* maskTexCoordScale
.x
,
1063 maskTexCoordOffset
.y
+ v_texCoord
.y
* maskTexCoordScale
.y
);
1064 vec4 maskColor
= texture2D(s_mask
, maskTexCoord
);
1065 vec3 pos
= vec3(gl_FragCoord
.xy
, 1);
1066 float a0
= clamp(dot(edge
[0], pos
), 0.0, 1.0);
1067 float a1
= clamp(dot(edge
[1], pos
), 0.0, 1.0);
1068 float a2
= clamp(dot(edge
[2], pos
), 0.0, 1.0);
1069 float a3
= clamp(dot(edge
[3], pos
), 0.0, 1.0);
1070 float a4
= clamp(dot(edge
[4], pos
), 0.0, 1.0);
1071 float a5
= clamp(dot(edge
[5], pos
), 0.0, 1.0);
1072 float a6
= clamp(dot(edge
[6], pos
), 0.0, 1.0);
1073 float a7
= clamp(dot(edge
[7], pos
), 0.0, 1.0);
1075 vec4(texColor
.x
, texColor
.y
, texColor
.z
, texColor
.w
) *
1076 alpha
* maskColor
.w
* min(min(a0
, a2
) * min(a1
, a3
), min(a4
, a6
) *
1079 ); // NOLINT(whitespace/parens)
1082 FragmentShaderRGBATexAlphaColorMatrixAA::
1083 FragmentShaderRGBATexAlphaColorMatrixAA()
1084 : sampler_location_(-1),
1085 alpha_location_(-1),
1087 color_matrix_location_(-1),
1088 color_offset_location_(-1) {}
1090 void FragmentShaderRGBATexAlphaColorMatrixAA::Init(
1091 WebGraphicsContext3D
* context
,
1093 bool using_bind_uniform
,
1094 int* base_uniform_index
) {
1095 static const char* shader_uniforms
[] = {
1104 GetProgramUniformLocations(context
,
1107 arraysize(shader_uniforms
),
1108 arraysize(locations
),
1111 base_uniform_index
);
1113 sampler_location_
= locations
[0];
1114 alpha_location_
= locations
[1];
1115 edge_location_
= locations
[2];
1116 color_matrix_location_
= locations
[3];
1117 color_offset_location_
= locations
[4];
1118 DCHECK(sampler_location_
!= -1 && alpha_location_
!= -1 &&
1119 edge_location_
!= -1 && color_matrix_location_
!= -1 &&
1120 color_offset_location_
!= -1);
1123 std::string
FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString(
1124 TexCoordPrecision precision
) const {
1125 return FRAGMENT_SHADER(
1126 precision mediump
float;
1127 varying TexCoordPrecision vec2 v_texCoord
;
1128 uniform sampler2D s_texture
;
1129 uniform
float alpha
;
1130 uniform mat4 colorMatrix
;
1131 uniform vec4 colorOffset
;
1132 uniform vec3 edge
[8];
1134 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
1135 float nonZeroAlpha
= max(texColor
.a
, 0.00001);
1136 texColor
= vec4(texColor
.rgb
/ nonZeroAlpha
, nonZeroAlpha
);
1137 texColor
= colorMatrix
* texColor
+ colorOffset
;
1138 texColor
.rgb
*= texColor
.a
;
1139 texColor
= clamp(texColor
, 0.0, 1.0);
1140 vec3 pos
= vec3(gl_FragCoord
.xy
, 1);
1141 float a0
= clamp(dot(edge
[0], pos
), 0.0, 1.0);
1142 float a1
= clamp(dot(edge
[1], pos
), 0.0, 1.0);
1143 float a2
= clamp(dot(edge
[2], pos
), 0.0, 1.0);
1144 float a3
= clamp(dot(edge
[3], pos
), 0.0, 1.0);
1145 float a4
= clamp(dot(edge
[4], pos
), 0.0, 1.0);
1146 float a5
= clamp(dot(edge
[5], pos
), 0.0, 1.0);
1147 float a6
= clamp(dot(edge
[6], pos
), 0.0, 1.0);
1148 float a7
= clamp(dot(edge
[7], pos
), 0.0, 1.0);
1149 gl_FragColor
= vec4(texColor
.x
, texColor
.y
, texColor
.z
, texColor
.w
) *
1150 alpha
* min(min(a0
, a2
) * min(a1
, a3
), min(a4
, a6
) * min(a5
, a7
));
1152 ); // NOLINT(whitespace/parens)
1155 FragmentShaderRGBATexAlphaMaskColorMatrix::
1156 FragmentShaderRGBATexAlphaMaskColorMatrix()
1157 : sampler_location_(-1),
1158 mask_sampler_location_(-1),
1159 alpha_location_(-1),
1160 mask_tex_coord_scale_location_(-1) {}
1162 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(
1163 WebGraphicsContext3D
* context
,
1165 bool using_bind_uniform
,
1166 int* base_uniform_index
) {
1167 static const char* shader_uniforms
[] = {
1171 "maskTexCoordScale",
1172 "maskTexCoordOffset",
1178 GetProgramUniformLocations(context
,
1181 arraysize(shader_uniforms
),
1182 arraysize(locations
),
1185 base_uniform_index
);
1187 sampler_location_
= locations
[0];
1188 mask_sampler_location_
= locations
[1];
1189 alpha_location_
= locations
[2];
1190 mask_tex_coord_scale_location_
= locations
[3];
1191 mask_tex_coord_offset_location_
= locations
[4];
1192 color_matrix_location_
= locations
[5];
1193 color_offset_location_
= locations
[6];
1194 DCHECK(sampler_location_
!= -1 && mask_sampler_location_
!= -1 &&
1195 alpha_location_
!= -1 && color_matrix_location_
!= -1 &&
1196 color_offset_location_
!= -1);
1199 std::string
FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString(
1200 TexCoordPrecision precision
) const {
1201 return FRAGMENT_SHADER(
1202 precision mediump
float;
1203 varying TexCoordPrecision vec2 v_texCoord
;
1204 uniform sampler2D s_texture
;
1205 uniform sampler2D s_mask
;
1206 uniform vec2 maskTexCoordScale
;
1207 uniform vec2 maskTexCoordOffset
;
1208 uniform mat4 colorMatrix
;
1209 uniform vec4 colorOffset
;
1210 uniform
float alpha
;
1212 vec4 texColor
= texture2D(s_texture
, v_texCoord
);
1213 float nonZeroAlpha
= max(texColor
.a
, 0.00001);
1214 texColor
= vec4(texColor
.rgb
/ nonZeroAlpha
, nonZeroAlpha
);
1215 texColor
= colorMatrix
* texColor
+ colorOffset
;
1216 texColor
.rgb
*= texColor
.a
;
1217 texColor
= clamp(texColor
, 0.0, 1.0);
1218 TexCoordPrecision vec2 maskTexCoord
=
1219 vec2(maskTexCoordOffset
.x
+ v_texCoord
.x
* maskTexCoordScale
.x
,
1220 maskTexCoordOffset
.y
+ v_texCoord
.y
* maskTexCoordScale
.y
);
1221 vec4 maskColor
= texture2D(s_mask
, maskTexCoord
);
1222 gl_FragColor
= vec4(texColor
.x
, texColor
.y
, texColor
.z
, texColor
.w
) *
1223 alpha
* maskColor
.w
;
1225 ); // NOLINT(whitespace/parens)
1228 FragmentShaderYUVVideo::FragmentShaderYUVVideo()
1229 : y_texture_location_(-1),
1230 u_texture_location_(-1),
1231 v_texture_location_(-1),
1232 alpha_location_(-1),
1233 yuv_matrix_location_(-1),
1234 yuv_adj_location_(-1) {}
1236 void FragmentShaderYUVVideo::Init(WebGraphicsContext3D
* context
,
1238 bool using_bind_uniform
,
1239 int* base_uniform_index
) {
1240 static const char* shader_uniforms
[] = {
1250 GetProgramUniformLocations(context
,
1253 arraysize(shader_uniforms
),
1254 arraysize(locations
),
1257 base_uniform_index
);
1259 y_texture_location_
= locations
[0];
1260 u_texture_location_
= locations
[1];
1261 v_texture_location_
= locations
[2];
1262 alpha_location_
= locations
[3];
1263 yuv_matrix_location_
= locations
[4];
1264 yuv_adj_location_
= locations
[5];
1266 DCHECK(y_texture_location_
!= -1 && u_texture_location_
!= -1 &&
1267 v_texture_location_
!= -1 && alpha_location_
!= -1 &&
1268 yuv_matrix_location_
!= -1 && yuv_adj_location_
!= -1);
1271 std::string
FragmentShaderYUVVideo::GetShaderString(
1272 TexCoordPrecision precision
) const {
1273 return FRAGMENT_SHADER(
1274 precision mediump
float;
1275 precision mediump
int;
1276 varying TexCoordPrecision vec2 v_texCoord
;
1277 uniform sampler2D y_texture
;
1278 uniform sampler2D u_texture
;
1279 uniform sampler2D v_texture
;
1280 uniform
float alpha
;
1281 uniform vec3 yuv_adj
;
1282 uniform mat3 yuv_matrix
;
1284 float y_raw
= texture2D(y_texture
, v_texCoord
).x
;
1285 float u_unsigned
= texture2D(u_texture
, v_texCoord
).x
;
1286 float v_unsigned
= texture2D(v_texture
, v_texCoord
).x
;
1287 vec3 yuv
= vec3(y_raw
, u_unsigned
, v_unsigned
) + yuv_adj
;
1288 vec3 rgb
= yuv_matrix
* yuv
;
1289 gl_FragColor
= vec4(rgb
, float(1)) * alpha
; // NOLINT
1291 ); // NOLINT(whitespace/parens)
1294 FragmentShaderColor::FragmentShaderColor()
1295 : color_location_(-1) {}
1297 void FragmentShaderColor::Init(WebGraphicsContext3D
* context
,
1299 bool using_bind_uniform
,
1300 int* base_uniform_index
) {
1301 static const char* shader_uniforms
[] = {
1306 GetProgramUniformLocations(context
,
1309 arraysize(shader_uniforms
),
1310 arraysize(locations
),
1313 base_uniform_index
);
1315 color_location_
= locations
[0];
1316 DCHECK_NE(color_location_
, -1);
1319 std::string
FragmentShaderColor::GetShaderString(
1320 TexCoordPrecision precision
) const {
1321 return FRAGMENT_SHADER(
1322 precision mediump
float;
1325 gl_FragColor
= color
;
1327 ); // NOLINT(whitespace/parens)
1330 FragmentShaderColorAA::FragmentShaderColorAA()
1331 : edge_location_(-1),
1332 color_location_(-1) {}
1334 void FragmentShaderColorAA::Init(WebGraphicsContext3D
* context
,
1336 bool using_bind_uniform
,
1337 int* base_uniform_index
) {
1338 static const char* shader_uniforms
[] = {
1344 GetProgramUniformLocations(context
,
1347 arraysize(shader_uniforms
),
1348 arraysize(locations
),
1351 base_uniform_index
);
1353 edge_location_
= locations
[0];
1354 color_location_
= locations
[1];
1355 DCHECK(edge_location_
!= -1 && color_location_
!= -1);
1358 std::string
FragmentShaderColorAA::GetShaderString(
1359 TexCoordPrecision precision
) const {
1360 return FRAGMENT_SHADER(
1361 precision mediump
float;
1363 uniform vec3 edge
[8];
1365 vec3 pos
= vec3(gl_FragCoord
.xy
, 1);
1366 float a0
= clamp(dot(edge
[0], pos
), 0.0, 1.0);
1367 float a1
= clamp(dot(edge
[1], pos
), 0.0, 1.0);
1368 float a2
= clamp(dot(edge
[2], pos
), 0.0, 1.0);
1369 float a3
= clamp(dot(edge
[3], pos
), 0.0, 1.0);
1370 float a4
= clamp(dot(edge
[4], pos
), 0.0, 1.0);
1371 float a5
= clamp(dot(edge
[5], pos
), 0.0, 1.0);
1372 float a6
= clamp(dot(edge
[6], pos
), 0.0, 1.0);
1373 float a7
= clamp(dot(edge
[7], pos
), 0.0, 1.0);
1374 gl_FragColor
= color
* min(min(a0
, a2
) * min(a1
, a3
),
1375 min(a4
, a6
) * min(a5
, a7
));
1377 ); // NOLINT(whitespace/parens)
1380 FragmentShaderCheckerboard::FragmentShaderCheckerboard()
1381 : alpha_location_(-1),
1382 tex_transform_location_(-1),
1383 frequency_location_(-1) {}
1385 void FragmentShaderCheckerboard::Init(WebGraphicsContext3D
* context
,
1387 bool using_bind_uniform
,
1388 int* base_uniform_index
) {
1389 static const char* shader_uniforms
[] = {
1397 GetProgramUniformLocations(context
,
1400 arraysize(shader_uniforms
),
1401 arraysize(locations
),
1404 base_uniform_index
);
1406 alpha_location_
= locations
[0];
1407 tex_transform_location_
= locations
[1];
1408 frequency_location_
= locations
[2];
1409 color_location_
= locations
[3];
1410 DCHECK(alpha_location_
!= -1 && tex_transform_location_
!= -1 &&
1411 frequency_location_
!= -1 && color_location_
!= -1);
1414 std::string
FragmentShaderCheckerboard::GetShaderString(
1415 TexCoordPrecision precision
) const {
1416 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide"
1417 // by Munshi, Ginsburg, Shreiner.
1418 return FRAGMENT_SHADER(
1419 precision mediump
float;
1420 precision mediump
int;
1421 varying vec2 v_texCoord
;
1422 uniform
float alpha
;
1423 uniform
float frequency
;
1424 uniform vec4 texTransform
;
1427 vec4 color1
= vec4(1.0, 1.0, 1.0, 1.0);
1428 vec4 color2
= color
;
1430 clamp(v_texCoord
, 0.0, 1.0) * texTransform
.zw
+ texTransform
.xy
;
1431 vec2 coord
= mod(floor(texCoord
* frequency
* 2.0), 2.0);
1432 float picker
= abs(coord
.x
- coord
.y
);
1433 gl_FragColor
= mix(color1
, color2
, picker
) * alpha
;
1435 ); // NOLINT(whitespace/parens)