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 "gpu/command_buffer/client/gles2_interface.h"
14 #define SHADER0(Src) #Src
15 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src))
16 #define FRAGMENT_SHADER(Src) SetFragmentTexCoordPrecision( \
17 precision, SetFragmentSamplerType(sampler, SHADER0(Src)))
19 using gpu::gles2::GLES2Interface
;
25 static void GetProgramUniformLocations(GLES2Interface
* context
,
28 const char** uniforms
,
30 int* base_uniform_index
) {
31 for (size_t i
= 0; i
< count
; i
++) {
32 locations
[i
] = (*base_uniform_index
)++;
33 context
->BindUniformLocationCHROMIUM(program
, locations
[i
], uniforms
[i
]);
37 static std::string
SetFragmentTexCoordPrecision(
38 TexCoordPrecision requested_precision
, std::string shader_string
) {
39 switch (requested_precision
) {
40 case TexCoordPrecisionHigh
:
41 DCHECK_NE(shader_string
.find("TexCoordPrecision"), std::string::npos
);
43 "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
44 " #define TexCoordPrecision highp\n"
46 " #define TexCoordPrecision mediump\n"
49 case TexCoordPrecisionMedium
:
50 DCHECK_NE(shader_string
.find("TexCoordPrecision"), std::string::npos
);
51 return "#define TexCoordPrecision mediump\n" +
53 case TexCoordPrecisionNA
:
54 DCHECK_EQ(shader_string
.find("TexCoordPrecision"), std::string::npos
);
55 DCHECK_EQ(shader_string
.find("texture2D"), std::string::npos
);
56 DCHECK_EQ(shader_string
.find("texture2DRect"), std::string::npos
);
65 static std::string
SetVertexTexCoordPrecision(const char* shader_string
) {
66 // We unconditionally use highp in the vertex shader since
67 // we are unlikely to be vertex shader bound when drawing large quads.
68 // Also, some vertex shaders mutate the texture coordinate in such a
69 // way that the effective precision might be lower than expected.
70 return "#define TexCoordPrecision highp\n" +
71 std::string(shader_string
);
74 TexCoordPrecision
TexCoordPrecisionRequired(GLES2Interface
* context
,
75 int *highp_threshold_cache
,
76 int highp_threshold_min
,
78 if (*highp_threshold_cache
== 0) {
79 // Initialize range and precision with minimum spec values for when
80 // GetShaderPrecisionFormat is a test stub.
81 // TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat
83 GLint range
[2] = { 14, 14 };
85 GLC(context
, context
->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER
,
88 *highp_threshold_cache
= 1 << precision
;
91 int highp_threshold
= std::max(*highp_threshold_cache
, highp_threshold_min
);
92 if (x
> highp_threshold
|| y
> highp_threshold
)
93 return TexCoordPrecisionHigh
;
94 return TexCoordPrecisionMedium
;
97 static std::string
SetFragmentSamplerType(
98 SamplerType requested_type
, std::string shader_string
) {
99 switch (requested_type
) {
101 DCHECK_NE(shader_string
.find("SamplerType"), std::string::npos
);
102 DCHECK_NE(shader_string
.find("TextureLookup"), std::string::npos
);
104 "#define SamplerType sampler2D\n"
105 "#define TextureLookup texture2D\n" +
107 case SamplerType2DRect
:
108 DCHECK_NE(shader_string
.find("SamplerType"), std::string::npos
);
109 DCHECK_NE(shader_string
.find("TextureLookup"), std::string::npos
);
111 "#extension GL_ARB_texture_rectangle : require\n"
112 "#define SamplerType sampler2DRect\n"
113 "#define TextureLookup texture2DRect\n" +
115 case SamplerTypeExternalOES
:
116 DCHECK_NE(shader_string
.find("SamplerType"), std::string::npos
);
117 DCHECK_NE(shader_string
.find("TextureLookup"), std::string::npos
);
119 "#extension GL_OES_EGL_image_external : require\n"
120 "#define SamplerType samplerExternalOES\n"
121 "#define TextureLookup texture2D\n" +
124 DCHECK_EQ(shader_string
.find("SamplerType"), std::string::npos
);
125 DCHECK_EQ(shader_string
.find("TextureLookup"), std::string::npos
);
126 return shader_string
;
131 return shader_string
;
136 TexCoordPrecision
TexCoordPrecisionRequired(GLES2Interface
* context
,
137 int* highp_threshold_cache
,
138 int highp_threshold_min
,
139 const gfx::Point
& max_coordinate
) {
140 return TexCoordPrecisionRequired(context
,
141 highp_threshold_cache
, highp_threshold_min
,
142 max_coordinate
.x(), max_coordinate
.y());
145 TexCoordPrecision
TexCoordPrecisionRequired(GLES2Interface
* context
,
146 int *highp_threshold_cache
,
147 int highp_threshold_min
,
148 const gfx::Size
& max_size
) {
149 return TexCoordPrecisionRequired(context
,
150 highp_threshold_cache
, highp_threshold_min
,
151 max_size
.width(), max_size
.height());
154 VertexShaderPosTex::VertexShaderPosTex()
155 : matrix_location_(-1) {}
157 void VertexShaderPosTex::Init(GLES2Interface
* context
,
159 int* base_uniform_index
) {
160 static const char* uniforms
[] = {
163 int locations
[arraysize(uniforms
)];
165 GetProgramUniformLocations(context
,
171 matrix_location_
= locations
[0];
174 std::string
VertexShaderPosTex::GetShaderString() const {
175 return VERTEX_SHADER(
176 attribute vec4 a_position
;
177 attribute TexCoordPrecision vec2 a_texCoord
;
179 varying TexCoordPrecision vec2 v_texCoord
;
181 gl_Position
= matrix
* a_position
;
182 v_texCoord
= a_texCoord
;
184 ); // NOLINT(whitespace/parens)
187 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset()
188 : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) {}
190 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface
* context
,
192 int* base_uniform_index
) {
193 static const char* uniforms
[] = {
198 int locations
[arraysize(uniforms
)];
200 GetProgramUniformLocations(context
,
206 matrix_location_
= locations
[0];
207 tex_scale_location_
= locations
[1];
208 tex_offset_location_
= locations
[2];
211 std::string
VertexShaderPosTexYUVStretchOffset::GetShaderString() const {
212 return VERTEX_SHADER(
213 precision mediump
float;
214 attribute vec4 a_position
;
215 attribute TexCoordPrecision vec2 a_texCoord
;
217 varying TexCoordPrecision vec2 v_texCoord
;
218 uniform TexCoordPrecision vec2 texScale
;
219 uniform TexCoordPrecision vec2 texOffset
;
221 gl_Position
= matrix
* a_position
;
222 v_texCoord
= a_texCoord
* texScale
+ texOffset
;
224 ); // NOLINT(whitespace/parens)
227 VertexShaderPos::VertexShaderPos()
228 : matrix_location_(-1) {}
230 void VertexShaderPos::Init(GLES2Interface
* context
,
232 int* base_uniform_index
) {
233 static const char* uniforms
[] = {
236 int locations
[arraysize(uniforms
)];
238 GetProgramUniformLocations(context
,
244 matrix_location_
= locations
[0];
247 std::string
VertexShaderPos::GetShaderString() const {
248 return VERTEX_SHADER(
249 attribute vec4 a_position
;
252 gl_Position
= matrix
* a_position
;
254 ); // NOLINT(whitespace/parens)
257 VertexShaderPosTexTransform::VertexShaderPosTexTransform()
258 : matrix_location_(-1),
259 tex_transform_location_(-1),
260 vertex_opacity_location_(-1) {}
262 void VertexShaderPosTexTransform::Init(GLES2Interface
* context
,
264 int* base_uniform_index
) {
265 static const char* uniforms
[] = {
270 int locations
[arraysize(uniforms
)];
272 GetProgramUniformLocations(context
,
278 matrix_location_
= locations
[0];
279 tex_transform_location_
= locations
[1];
280 vertex_opacity_location_
= locations
[2];
283 std::string
VertexShaderPosTexTransform::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 int quad_index
= int(a_index
* 0.25); // NOLINT
295 gl_Position
= matrix
[quad_index
] * a_position
;
296 TexCoordPrecision vec4 texTrans
= texTransform
[quad_index
];
297 v_texCoord
= a_texCoord
* texTrans
.zw
+ texTrans
.xy
;
298 v_alpha
= opacity
[int(a_index
)]; // NOLINT
300 ); // NOLINT(whitespace/parens)
303 std::string
VertexShaderPosTexIdentity::GetShaderString() const {
304 return VERTEX_SHADER(
305 attribute vec4 a_position
;
306 varying TexCoordPrecision vec2 v_texCoord
;
308 gl_Position
= a_position
;
309 v_texCoord
= (a_position
.xy
+ vec2(1.0)) * 0.5;
311 ); // NOLINT(whitespace/parens)
314 VertexShaderQuad::VertexShaderQuad()
315 : matrix_location_(-1),
316 quad_location_(-1) {}
318 void VertexShaderQuad::Init(GLES2Interface
* context
,
320 int* base_uniform_index
) {
321 static const char* uniforms
[] = {
325 int locations
[arraysize(uniforms
)];
327 GetProgramUniformLocations(context
,
333 matrix_location_
= locations
[0];
334 quad_location_
= locations
[1];
337 std::string
VertexShaderQuad::GetShaderString() const {
338 #if defined(OS_ANDROID)
339 // TODO(epenner): Find the cause of this 'quad' uniform
340 // being missing if we don't add dummy variables.
341 // http://crbug.com/240602
342 return VERTEX_SHADER(
343 attribute TexCoordPrecision vec4 a_position
;
344 attribute
float a_index
;
346 uniform TexCoordPrecision vec2 quad
[4];
347 uniform TexCoordPrecision vec2 dummy_uniform
;
348 varying TexCoordPrecision vec2 dummy_varying
;
350 vec2 pos
= quad
[int(a_index
)]; // NOLINT
351 gl_Position
= matrix
* vec4(pos
, a_position
.z
, a_position
.w
);
352 dummy_varying
= dummy_uniform
;
354 ); // NOLINT(whitespace/parens)
356 return VERTEX_SHADER(
357 attribute TexCoordPrecision vec4 a_position
;
358 attribute
float a_index
;
360 uniform TexCoordPrecision vec2 quad
[4];
362 vec2 pos
= quad
[int(a_index
)]; // NOLINT
363 gl_Position
= matrix
* vec4(pos
, a_position
.z
, a_position
.w
);
365 ); // NOLINT(whitespace/parens)
369 VertexShaderQuadAA::VertexShaderQuadAA()
370 : matrix_location_(-1),
371 viewport_location_(-1),
373 edge_location_(-1) {}
375 void VertexShaderQuadAA::Init(GLES2Interface
* context
,
377 int* base_uniform_index
) {
378 static const char* uniforms
[] = {
384 int locations
[arraysize(uniforms
)];
386 GetProgramUniformLocations(context
,
392 matrix_location_
= locations
[0];
393 viewport_location_
= locations
[1];
394 quad_location_
= locations
[2];
395 edge_location_
= locations
[3];
398 std::string
VertexShaderQuadAA::GetShaderString() const {
399 return VERTEX_SHADER(
400 attribute TexCoordPrecision vec4 a_position
;
401 attribute
float a_index
;
403 uniform vec4 viewport
;
404 uniform TexCoordPrecision vec2 quad
[4];
405 uniform TexCoordPrecision vec3 edge
[8];
406 varying TexCoordPrecision vec4 edge_dist
[2]; // 8 edge distances.
409 vec2 pos
= quad
[int(a_index
)]; // NOLINT
410 gl_Position
= matrix
* vec4(pos
, a_position
.z
, a_position
.w
);
411 vec2 ndc_pos
= 0.5 * (1.0 + gl_Position
.xy
/ gl_Position
.w
);
412 vec3 screen_pos
= vec3(viewport
.xy
+ viewport
.zw
* ndc_pos
, 1.0);
413 edge_dist
[0] = vec4(dot(edge
[0], screen_pos
),
414 dot(edge
[1], screen_pos
),
415 dot(edge
[2], screen_pos
),
416 dot(edge
[3], screen_pos
)) * gl_Position
.w
;
417 edge_dist
[1] = vec4(dot(edge
[4], screen_pos
),
418 dot(edge
[5], screen_pos
),
419 dot(edge
[6], screen_pos
),
420 dot(edge
[7], screen_pos
)) * gl_Position
.w
;
422 ); // NOLINT(whitespace/parens)
425 VertexShaderQuadTexTransformAA::VertexShaderQuadTexTransformAA()
426 : matrix_location_(-1),
427 viewport_location_(-1),
430 tex_transform_location_(-1) {}
432 void VertexShaderQuadTexTransformAA::Init(GLES2Interface
* context
,
434 int* base_uniform_index
) {
435 static const char* uniforms
[] = {
442 int locations
[arraysize(uniforms
)];
444 GetProgramUniformLocations(context
,
450 matrix_location_
= locations
[0];
451 viewport_location_
= locations
[1];
452 quad_location_
= locations
[2];
453 edge_location_
= locations
[3];
454 tex_transform_location_
= locations
[4];
457 std::string
VertexShaderQuadTexTransformAA::GetShaderString() const {
458 return VERTEX_SHADER(
459 attribute TexCoordPrecision vec4 a_position
;
460 attribute
float a_index
;
462 uniform vec4 viewport
;
463 uniform TexCoordPrecision vec2 quad
[4];
464 uniform TexCoordPrecision vec3 edge
[8];
465 uniform TexCoordPrecision vec4 texTrans
;
466 varying TexCoordPrecision vec2 v_texCoord
;
467 varying TexCoordPrecision vec4 edge_dist
[2]; // 8 edge distances.
470 vec2 pos
= quad
[int(a_index
)]; // NOLINT
471 gl_Position
= matrix
* vec4(pos
, a_position
.z
, a_position
.w
);
472 vec2 ndc_pos
= 0.5 * (1.0 + gl_Position
.xy
/ gl_Position
.w
);
473 vec3 screen_pos
= vec3(viewport
.xy
+ viewport
.zw
* ndc_pos
, 1.0);
474 edge_dist
[0] = vec4(dot(edge
[0], screen_pos
),
475 dot(edge
[1], screen_pos
),
476 dot(edge
[2], screen_pos
),
477 dot(edge
[3], screen_pos
)) * gl_Position
.w
;
478 edge_dist
[1] = vec4(dot(edge
[4], screen_pos
),
479 dot(edge
[5], screen_pos
),
480 dot(edge
[6], screen_pos
),
481 dot(edge
[7], screen_pos
)) * gl_Position
.w
;
482 v_texCoord
= (pos
.xy
+ vec2(0.5)) * texTrans
.zw
+ texTrans
.xy
;
484 ); // NOLINT(whitespace/parens)
487 VertexShaderTile::VertexShaderTile()
488 : matrix_location_(-1),
490 vertex_tex_transform_location_(-1) {}
492 void VertexShaderTile::Init(GLES2Interface
* context
,
494 int* base_uniform_index
) {
495 static const char* uniforms
[] = {
498 "vertexTexTransform",
500 int locations
[arraysize(uniforms
)];
502 GetProgramUniformLocations(context
,
508 matrix_location_
= locations
[0];
509 quad_location_
= locations
[1];
510 vertex_tex_transform_location_
= locations
[2];
513 std::string
VertexShaderTile::GetShaderString() const {
514 return VERTEX_SHADER(
515 attribute TexCoordPrecision vec4 a_position
;
516 attribute
float a_index
;
518 uniform TexCoordPrecision vec2 quad
[4];
519 uniform TexCoordPrecision vec4 vertexTexTransform
;
520 varying TexCoordPrecision vec2 v_texCoord
;
522 vec2 pos
= quad
[int(a_index
)]; // NOLINT
523 gl_Position
= matrix
* vec4(pos
, a_position
.z
, a_position
.w
);
524 v_texCoord
= pos
.xy
* vertexTexTransform
.zw
+ vertexTexTransform
.xy
;
526 ); // NOLINT(whitespace/parens)
529 VertexShaderTileAA::VertexShaderTileAA()
530 : matrix_location_(-1),
531 viewport_location_(-1),
534 vertex_tex_transform_location_(-1) {}
536 void VertexShaderTileAA::Init(GLES2Interface
* context
,
538 int* base_uniform_index
) {
539 static const char* uniforms
[] = {
544 "vertexTexTransform",
546 int locations
[arraysize(uniforms
)];
548 GetProgramUniformLocations(context
,
554 matrix_location_
= locations
[0];
555 viewport_location_
= locations
[1];
556 quad_location_
= locations
[2];
557 edge_location_
= locations
[3];
558 vertex_tex_transform_location_
= locations
[4];
561 std::string
VertexShaderTileAA::GetShaderString() const {
562 return VERTEX_SHADER(
563 attribute TexCoordPrecision vec4 a_position
;
564 attribute
float a_index
;
566 uniform vec4 viewport
;
567 uniform TexCoordPrecision vec2 quad
[4];
568 uniform TexCoordPrecision vec3 edge
[8];
569 uniform TexCoordPrecision vec4 vertexTexTransform
;
570 varying TexCoordPrecision vec2 v_texCoord
;
571 varying TexCoordPrecision vec4 edge_dist
[2]; // 8 edge distances.
574 vec2 pos
= quad
[int(a_index
)]; // NOLINT
575 gl_Position
= matrix
* vec4(pos
, a_position
.z
, a_position
.w
);
576 vec2 ndc_pos
= 0.5 * (1.0 + gl_Position
.xy
/ gl_Position
.w
);
577 vec3 screen_pos
= vec3(viewport
.xy
+ viewport
.zw
* ndc_pos
, 1.0);
578 edge_dist
[0] = vec4(dot(edge
[0], screen_pos
),
579 dot(edge
[1], screen_pos
),
580 dot(edge
[2], screen_pos
),
581 dot(edge
[3], screen_pos
)) * gl_Position
.w
;
582 edge_dist
[1] = vec4(dot(edge
[4], screen_pos
),
583 dot(edge
[5], screen_pos
),
584 dot(edge
[6], screen_pos
),
585 dot(edge
[7], screen_pos
)) * gl_Position
.w
;
586 v_texCoord
= pos
.xy
* vertexTexTransform
.zw
+ vertexTexTransform
.xy
;
588 ); // NOLINT(whitespace/parens)
591 VertexShaderVideoTransform::VertexShaderVideoTransform()
592 : matrix_location_(-1),
593 tex_matrix_location_(-1) {}
595 void VertexShaderVideoTransform::Init(GLES2Interface
* context
,
597 int* base_uniform_index
) {
598 static const char* uniforms
[] = {
602 int locations
[arraysize(uniforms
)];
604 GetProgramUniformLocations(context
,
610 matrix_location_
= locations
[0];
611 tex_matrix_location_
= locations
[1];
614 std::string
VertexShaderVideoTransform::GetShaderString() const {
615 return VERTEX_SHADER(
616 attribute vec4 a_position
;
617 attribute TexCoordPrecision vec2 a_texCoord
;
619 uniform TexCoordPrecision mat4 texMatrix
;
620 varying TexCoordPrecision vec2 v_texCoord
;
622 gl_Position
= matrix
* a_position
;
624 vec2(texMatrix
* vec4(a_texCoord
.x
, 1.0 - a_texCoord
.y
, 0.0, 1.0));
626 ); // NOLINT(whitespace/parens)
629 FragmentTexAlphaBinding::FragmentTexAlphaBinding()
630 : sampler_location_(-1),
631 alpha_location_(-1) {}
633 void FragmentTexAlphaBinding::Init(GLES2Interface
* context
,
635 int* base_uniform_index
) {
636 static const char* uniforms
[] = {
640 int locations
[arraysize(uniforms
)];
642 GetProgramUniformLocations(context
,
648 sampler_location_
= locations
[0];
649 alpha_location_
= locations
[1];
652 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding()
653 : sampler_location_(-1),
655 color_matrix_location_(-1),
656 color_offset_location_(-1) {}
658 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface
* context
,
660 int* base_uniform_index
) {
661 static const char* uniforms
[] = {
667 int locations
[arraysize(uniforms
)];
669 GetProgramUniformLocations(context
,
675 sampler_location_
= locations
[0];
676 alpha_location_
= locations
[1];
677 color_matrix_location_
= locations
[2];
678 color_offset_location_
= locations
[3];
681 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding()
682 : sampler_location_(-1) {}
684 void FragmentTexOpaqueBinding::Init(GLES2Interface
* context
,
686 int* base_uniform_index
) {
687 static const char* uniforms
[] = {
690 int locations
[arraysize(uniforms
)];
692 GetProgramUniformLocations(context
,
698 sampler_location_
= locations
[0];
701 std::string
FragmentShaderRGBATexAlpha::GetShaderString(
702 TexCoordPrecision precision
, SamplerType sampler
) const {
703 return FRAGMENT_SHADER(
704 precision mediump
float;
705 varying TexCoordPrecision vec2 v_texCoord
;
706 uniform SamplerType s_texture
;
709 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
710 gl_FragColor
= texColor
* alpha
;
712 ); // NOLINT(whitespace/parens)
715 std::string
FragmentShaderRGBATexColorMatrixAlpha::GetShaderString(
716 TexCoordPrecision precision
, SamplerType sampler
) const {
717 return FRAGMENT_SHADER(
718 precision mediump
float;
719 varying TexCoordPrecision vec2 v_texCoord
;
720 uniform SamplerType s_texture
;
722 uniform mat4 colorMatrix
;
723 uniform vec4 colorOffset
;
725 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
726 float nonZeroAlpha
= max(texColor
.a
, 0.00001);
727 texColor
= vec4(texColor
.rgb
/ nonZeroAlpha
, nonZeroAlpha
);
728 texColor
= colorMatrix
* texColor
+ colorOffset
;
729 texColor
.rgb
*= texColor
.a
;
730 texColor
= clamp(texColor
, 0.0, 1.0);
731 gl_FragColor
= texColor
* alpha
;
733 ); // NOLINT(whitespace/parens)
736 std::string
FragmentShaderRGBATexVaryingAlpha::GetShaderString(
737 TexCoordPrecision precision
, SamplerType sampler
) const {
738 return FRAGMENT_SHADER(
739 precision mediump
float;
740 varying TexCoordPrecision vec2 v_texCoord
;
741 varying
float v_alpha
;
742 uniform SamplerType s_texture
;
744 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
745 gl_FragColor
= texColor
* v_alpha
;
747 ); // NOLINT(whitespace/parens)
750 std::string
FragmentShaderRGBATexPremultiplyAlpha::GetShaderString(
751 TexCoordPrecision precision
, SamplerType sampler
) const {
752 return FRAGMENT_SHADER(
753 precision mediump
float;
754 varying TexCoordPrecision vec2 v_texCoord
;
755 varying
float v_alpha
;
756 uniform SamplerType s_texture
;
758 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
759 texColor
.rgb
*= texColor
.a
;
760 gl_FragColor
= texColor
* v_alpha
;
762 ); // NOLINT(whitespace/parens)
765 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding()
766 : background_color_location_(-1),
767 sampler_location_(-1) {
770 void FragmentTexBackgroundBinding::Init(GLES2Interface
* context
,
772 int* base_uniform_index
) {
773 static const char* uniforms
[] = {
777 int locations
[arraysize(uniforms
)];
779 GetProgramUniformLocations(context
,
786 sampler_location_
= locations
[0];
787 DCHECK_NE(sampler_location_
, -1);
789 background_color_location_
= locations
[1];
790 DCHECK_NE(background_color_location_
, -1);
793 std::string
FragmentShaderTexBackgroundVaryingAlpha::GetShaderString(
794 TexCoordPrecision precision
, SamplerType sampler
) const {
795 return FRAGMENT_SHADER(
796 precision mediump
float;
797 varying TexCoordPrecision vec2 v_texCoord
;
798 varying
float v_alpha
;
799 uniform vec4 background_color
;
800 uniform SamplerType s_texture
;
802 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
803 texColor
+= background_color
* (1.0 - texColor
.a
);
804 gl_FragColor
= texColor
* v_alpha
;
806 ); // NOLINT(whitespace/parens)
809 std::string
FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString(
810 TexCoordPrecision precision
, SamplerType sampler
) const {
811 return FRAGMENT_SHADER(
812 precision mediump
float;
813 varying TexCoordPrecision vec2 v_texCoord
;
814 varying
float v_alpha
;
815 uniform vec4 background_color
;
816 uniform SamplerType s_texture
;
818 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
819 texColor
.rgb
*= texColor
.a
;
820 texColor
+= background_color
* (1.0 - texColor
.a
);
821 gl_FragColor
= texColor
* v_alpha
;
823 ); // NOLINT(whitespace/parens)
826 std::string
FragmentShaderRGBATexOpaque::GetShaderString(
827 TexCoordPrecision precision
, SamplerType sampler
) const {
828 return FRAGMENT_SHADER(
829 precision mediump
float;
830 varying TexCoordPrecision vec2 v_texCoord
;
831 uniform SamplerType s_texture
;
833 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
834 gl_FragColor
= vec4(texColor
.rgb
, 1.0);
836 ); // NOLINT(whitespace/parens)
839 std::string
FragmentShaderRGBATex::GetShaderString(
840 TexCoordPrecision precision
, SamplerType sampler
) const {
841 return FRAGMENT_SHADER(
842 precision mediump
float;
843 varying TexCoordPrecision vec2 v_texCoord
;
844 uniform SamplerType s_texture
;
846 gl_FragColor
= TextureLookup(s_texture
, v_texCoord
);
848 ); // NOLINT(whitespace/parens)
851 std::string
FragmentShaderRGBATexSwizzleAlpha::GetShaderString(
852 TexCoordPrecision precision
, SamplerType sampler
) const {
853 return FRAGMENT_SHADER(
854 precision mediump
float;
855 varying TexCoordPrecision vec2 v_texCoord
;
856 uniform SamplerType s_texture
;
859 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
861 vec4(texColor
.z
, texColor
.y
, texColor
.x
, texColor
.w
) * alpha
;
863 ); // NOLINT(whitespace/parens)
866 std::string
FragmentShaderRGBATexSwizzleOpaque::GetShaderString(
867 TexCoordPrecision precision
, SamplerType sampler
) const {
868 return FRAGMENT_SHADER(
869 precision mediump
float;
870 varying TexCoordPrecision vec2 v_texCoord
;
871 uniform SamplerType s_texture
;
873 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
874 gl_FragColor
= vec4(texColor
.z
, texColor
.y
, texColor
.x
, 1.0);
876 ); // NOLINT(whitespace/parens)
879 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA()
880 : sampler_location_(-1),
881 alpha_location_(-1) {}
883 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface
* context
,
885 int* base_uniform_index
) {
886 static const char* uniforms
[] = {
890 int locations
[arraysize(uniforms
)];
892 GetProgramUniformLocations(context
,
898 sampler_location_
= locations
[0];
899 alpha_location_
= locations
[1];
902 std::string
FragmentShaderRGBATexAlphaAA::GetShaderString(
903 TexCoordPrecision precision
, SamplerType sampler
) const {
904 return FRAGMENT_SHADER(
905 precision mediump
float;
906 uniform SamplerType s_texture
;
908 varying TexCoordPrecision vec2 v_texCoord
;
909 varying TexCoordPrecision vec4 edge_dist
[2]; // 8 edge distances.
912 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
913 vec4 d4
= min(edge_dist
[0], edge_dist
[1]);
914 vec2 d2
= min(d4
.xz
, d4
.yw
);
915 float aa
= clamp(gl_FragCoord
.w
* min(d2
.x
, d2
.y
), 0.0, 1.0);
916 gl_FragColor
= texColor
* alpha
* aa
;
918 ); // NOLINT(whitespace/parens)
921 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding()
922 : sampler_location_(-1),
924 fragment_tex_transform_location_(-1) {}
926 void FragmentTexClampAlphaAABinding::Init(GLES2Interface
* context
,
928 int* base_uniform_index
) {
929 static const char* uniforms
[] = {
932 "fragmentTexTransform",
934 int locations
[arraysize(uniforms
)];
936 GetProgramUniformLocations(context
,
942 sampler_location_
= locations
[0];
943 alpha_location_
= locations
[1];
944 fragment_tex_transform_location_
= locations
[2];
947 std::string
FragmentShaderRGBATexClampAlphaAA::GetShaderString(
948 TexCoordPrecision precision
, SamplerType sampler
) const {
949 return FRAGMENT_SHADER(
950 precision mediump
float;
951 uniform SamplerType s_texture
;
953 uniform TexCoordPrecision vec4 fragmentTexTransform
;
954 varying TexCoordPrecision vec2 v_texCoord
;
955 varying TexCoordPrecision vec4 edge_dist
[2]; // 8 edge distances.
958 TexCoordPrecision vec2 texCoord
=
959 clamp(v_texCoord
, 0.0, 1.0) * fragmentTexTransform
.zw
+
960 fragmentTexTransform
.xy
;
961 vec4 texColor
= TextureLookup(s_texture
, texCoord
);
962 vec4 d4
= min(edge_dist
[0], edge_dist
[1]);
963 vec2 d2
= min(d4
.xz
, d4
.yw
);
964 float aa
= clamp(gl_FragCoord
.w
* min(d2
.x
, d2
.y
), 0.0, 1.0);
965 gl_FragColor
= texColor
* alpha
* aa
;
967 ); // NOLINT(whitespace/parens)
970 std::string
FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString(
971 TexCoordPrecision precision
, SamplerType sampler
) const {
972 return FRAGMENT_SHADER(
973 precision mediump
float;
974 uniform SamplerType s_texture
;
976 uniform TexCoordPrecision vec4 fragmentTexTransform
;
977 varying TexCoordPrecision vec2 v_texCoord
;
978 varying TexCoordPrecision vec4 edge_dist
[2]; // 8 edge distances.
981 TexCoordPrecision vec2 texCoord
=
982 clamp(v_texCoord
, 0.0, 1.0) * fragmentTexTransform
.zw
+
983 fragmentTexTransform
.xy
;
984 vec4 texColor
= TextureLookup(s_texture
, texCoord
);
985 vec4 d4
= min(edge_dist
[0], edge_dist
[1]);
986 vec2 d2
= min(d4
.xz
, d4
.yw
);
987 float aa
= clamp(gl_FragCoord
.w
* min(d2
.x
, d2
.y
), 0.0, 1.0);
988 gl_FragColor
= vec4(texColor
.z
, texColor
.y
, texColor
.x
, texColor
.w
) *
991 ); // NOLINT(whitespace/parens)
994 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask()
995 : sampler_location_(-1),
996 mask_sampler_location_(-1),
998 mask_tex_coord_scale_location_(-1) {}
1000 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface
* context
,
1002 int* base_uniform_index
) {
1003 static const char* uniforms
[] = {
1007 "maskTexCoordScale",
1008 "maskTexCoordOffset",
1010 int locations
[arraysize(uniforms
)];
1012 GetProgramUniformLocations(context
,
1014 arraysize(uniforms
),
1017 base_uniform_index
);
1018 sampler_location_
= locations
[0];
1019 mask_sampler_location_
= locations
[1];
1020 alpha_location_
= locations
[2];
1021 mask_tex_coord_scale_location_
= locations
[3];
1022 mask_tex_coord_offset_location_
= locations
[4];
1025 std::string
FragmentShaderRGBATexAlphaMask::GetShaderString(
1026 TexCoordPrecision precision
, SamplerType sampler
) const {
1027 return FRAGMENT_SHADER(
1028 precision mediump
float;
1029 varying TexCoordPrecision vec2 v_texCoord
;
1030 uniform SamplerType s_texture
;
1031 uniform SamplerType s_mask
;
1032 uniform TexCoordPrecision vec2 maskTexCoordScale
;
1033 uniform TexCoordPrecision vec2 maskTexCoordOffset
;
1034 uniform
float alpha
;
1036 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
1037 TexCoordPrecision vec2 maskTexCoord
=
1038 vec2(maskTexCoordOffset
.x
+ v_texCoord
.x
* maskTexCoordScale
.x
,
1039 maskTexCoordOffset
.y
+ v_texCoord
.y
* maskTexCoordScale
.y
);
1040 vec4 maskColor
= TextureLookup(s_mask
, maskTexCoord
);
1041 gl_FragColor
= texColor
* alpha
* maskColor
.w
;
1043 ); // NOLINT(whitespace/parens)
1046 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
1047 : sampler_location_(-1),
1048 mask_sampler_location_(-1),
1049 alpha_location_(-1),
1050 mask_tex_coord_scale_location_(-1),
1051 mask_tex_coord_offset_location_(-1) {}
1053 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface
* context
,
1055 int* base_uniform_index
) {
1056 static const char* uniforms
[] = {
1060 "maskTexCoordScale",
1061 "maskTexCoordOffset",
1063 int locations
[arraysize(uniforms
)];
1065 GetProgramUniformLocations(context
,
1067 arraysize(uniforms
),
1070 base_uniform_index
);
1071 sampler_location_
= locations
[0];
1072 mask_sampler_location_
= locations
[1];
1073 alpha_location_
= locations
[2];
1074 mask_tex_coord_scale_location_
= locations
[3];
1075 mask_tex_coord_offset_location_
= locations
[4];
1078 std::string
FragmentShaderRGBATexAlphaMaskAA::GetShaderString(
1079 TexCoordPrecision precision
, SamplerType sampler
) const {
1080 return FRAGMENT_SHADER(
1081 precision mediump
float;
1082 uniform SamplerType s_texture
;
1083 uniform SamplerType s_mask
;
1084 uniform TexCoordPrecision vec2 maskTexCoordScale
;
1085 uniform TexCoordPrecision vec2 maskTexCoordOffset
;
1086 uniform
float alpha
;
1087 varying TexCoordPrecision vec2 v_texCoord
;
1088 varying TexCoordPrecision vec4 edge_dist
[2]; // 8 edge distances.
1091 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
1092 TexCoordPrecision vec2 maskTexCoord
=
1093 vec2(maskTexCoordOffset
.x
+ v_texCoord
.x
* maskTexCoordScale
.x
,
1094 maskTexCoordOffset
.y
+ v_texCoord
.y
* maskTexCoordScale
.y
);
1095 vec4 maskColor
= TextureLookup(s_mask
, maskTexCoord
);
1096 vec4 d4
= min(edge_dist
[0], edge_dist
[1]);
1097 vec2 d2
= min(d4
.xz
, d4
.yw
);
1098 float aa
= clamp(gl_FragCoord
.w
* min(d2
.x
, d2
.y
), 0.0, 1.0);
1099 gl_FragColor
= texColor
* alpha
* maskColor
.w
* aa
;
1101 ); // NOLINT(whitespace/parens)
1104 FragmentShaderRGBATexAlphaMaskColorMatrixAA::
1105 FragmentShaderRGBATexAlphaMaskColorMatrixAA()
1106 : sampler_location_(-1),
1107 mask_sampler_location_(-1),
1108 alpha_location_(-1),
1109 mask_tex_coord_scale_location_(-1),
1110 color_matrix_location_(-1),
1111 color_offset_location_(-1) {}
1113 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init(
1114 GLES2Interface
* context
,
1116 int* base_uniform_index
) {
1117 static const char* uniforms
[] = {
1121 "maskTexCoordScale",
1122 "maskTexCoordOffset",
1126 int locations
[arraysize(uniforms
)];
1128 GetProgramUniformLocations(context
,
1130 arraysize(uniforms
),
1133 base_uniform_index
);
1134 sampler_location_
= locations
[0];
1135 mask_sampler_location_
= locations
[1];
1136 alpha_location_
= locations
[2];
1137 mask_tex_coord_scale_location_
= locations
[3];
1138 mask_tex_coord_offset_location_
= locations
[4];
1139 color_matrix_location_
= locations
[5];
1140 color_offset_location_
= locations
[6];
1143 std::string
FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString(
1144 TexCoordPrecision precision
, SamplerType sampler
) const {
1145 return FRAGMENT_SHADER(
1146 precision mediump
float;
1147 uniform SamplerType s_texture
;
1148 uniform SamplerType s_mask
;
1149 uniform vec2 maskTexCoordScale
;
1150 uniform vec2 maskTexCoordOffset
;
1151 uniform mat4 colorMatrix
;
1152 uniform vec4 colorOffset
;
1153 uniform
float alpha
;
1154 varying TexCoordPrecision vec2 v_texCoord
;
1155 varying TexCoordPrecision vec4 edge_dist
[2]; // 8 edge distances.
1158 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
1159 float nonZeroAlpha
= max(texColor
.a
, 0.00001);
1160 texColor
= vec4(texColor
.rgb
/ nonZeroAlpha
, nonZeroAlpha
);
1161 texColor
= colorMatrix
* texColor
+ colorOffset
;
1162 texColor
.rgb
*= texColor
.a
;
1163 texColor
= clamp(texColor
, 0.0, 1.0);
1164 TexCoordPrecision vec2 maskTexCoord
=
1165 vec2(maskTexCoordOffset
.x
+ v_texCoord
.x
* maskTexCoordScale
.x
,
1166 maskTexCoordOffset
.y
+ v_texCoord
.y
* maskTexCoordScale
.y
);
1167 vec4 maskColor
= TextureLookup(s_mask
, maskTexCoord
);
1168 vec4 d4
= min(edge_dist
[0], edge_dist
[1]);
1169 vec2 d2
= min(d4
.xz
, d4
.yw
);
1170 float aa
= clamp(gl_FragCoord
.w
* min(d2
.x
, d2
.y
), 0.0, 1.0);
1171 gl_FragColor
= texColor
* alpha
* maskColor
.w
* aa
;
1173 ); // NOLINT(whitespace/parens)
1176 FragmentShaderRGBATexAlphaColorMatrixAA::
1177 FragmentShaderRGBATexAlphaColorMatrixAA()
1178 : sampler_location_(-1),
1179 alpha_location_(-1),
1180 color_matrix_location_(-1),
1181 color_offset_location_(-1) {}
1183 void FragmentShaderRGBATexAlphaColorMatrixAA::Init(
1184 GLES2Interface
* context
,
1186 int* base_uniform_index
) {
1187 static const char* uniforms
[] = {
1193 int locations
[arraysize(uniforms
)];
1195 GetProgramUniformLocations(context
,
1197 arraysize(uniforms
),
1200 base_uniform_index
);
1201 sampler_location_
= locations
[0];
1202 alpha_location_
= locations
[1];
1203 color_matrix_location_
= locations
[2];
1204 color_offset_location_
= locations
[3];
1207 std::string
FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString(
1208 TexCoordPrecision precision
, SamplerType sampler
) const {
1209 return FRAGMENT_SHADER(
1210 precision mediump
float;
1211 uniform SamplerType s_texture
;
1212 uniform
float alpha
;
1213 uniform mat4 colorMatrix
;
1214 uniform vec4 colorOffset
;
1215 varying TexCoordPrecision vec2 v_texCoord
;
1216 varying TexCoordPrecision vec4 edge_dist
[2]; // 8 edge distances.
1219 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
1220 float nonZeroAlpha
= max(texColor
.a
, 0.00001);
1221 texColor
= vec4(texColor
.rgb
/ nonZeroAlpha
, nonZeroAlpha
);
1222 texColor
= colorMatrix
* texColor
+ colorOffset
;
1223 texColor
.rgb
*= texColor
.a
;
1224 texColor
= clamp(texColor
, 0.0, 1.0);
1225 vec4 d4
= min(edge_dist
[0], edge_dist
[1]);
1226 vec2 d2
= min(d4
.xz
, d4
.yw
);
1227 float aa
= clamp(gl_FragCoord
.w
* min(d2
.x
, d2
.y
), 0.0, 1.0);
1228 gl_FragColor
= texColor
* alpha
* aa
;
1230 ); // NOLINT(whitespace/parens)
1233 FragmentShaderRGBATexAlphaMaskColorMatrix::
1234 FragmentShaderRGBATexAlphaMaskColorMatrix()
1235 : sampler_location_(-1),
1236 mask_sampler_location_(-1),
1237 alpha_location_(-1),
1238 mask_tex_coord_scale_location_(-1) {}
1240 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(
1241 GLES2Interface
* context
,
1243 int* base_uniform_index
) {
1244 static const char* uniforms
[] = {
1248 "maskTexCoordScale",
1249 "maskTexCoordOffset",
1253 int locations
[arraysize(uniforms
)];
1255 GetProgramUniformLocations(context
,
1257 arraysize(uniforms
),
1260 base_uniform_index
);
1261 sampler_location_
= locations
[0];
1262 mask_sampler_location_
= locations
[1];
1263 alpha_location_
= locations
[2];
1264 mask_tex_coord_scale_location_
= locations
[3];
1265 mask_tex_coord_offset_location_
= locations
[4];
1266 color_matrix_location_
= locations
[5];
1267 color_offset_location_
= locations
[6];
1270 std::string
FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString(
1271 TexCoordPrecision precision
, SamplerType sampler
) const {
1272 return FRAGMENT_SHADER(
1273 precision mediump
float;
1274 varying TexCoordPrecision vec2 v_texCoord
;
1275 uniform SamplerType s_texture
;
1276 uniform SamplerType s_mask
;
1277 uniform vec2 maskTexCoordScale
;
1278 uniform vec2 maskTexCoordOffset
;
1279 uniform mat4 colorMatrix
;
1280 uniform vec4 colorOffset
;
1281 uniform
float alpha
;
1283 vec4 texColor
= TextureLookup(s_texture
, v_texCoord
);
1284 float nonZeroAlpha
= max(texColor
.a
, 0.00001);
1285 texColor
= vec4(texColor
.rgb
/ nonZeroAlpha
, nonZeroAlpha
);
1286 texColor
= colorMatrix
* texColor
+ colorOffset
;
1287 texColor
.rgb
*= texColor
.a
;
1288 texColor
= clamp(texColor
, 0.0, 1.0);
1289 TexCoordPrecision vec2 maskTexCoord
=
1290 vec2(maskTexCoordOffset
.x
+ v_texCoord
.x
* maskTexCoordScale
.x
,
1291 maskTexCoordOffset
.y
+ v_texCoord
.y
* maskTexCoordScale
.y
);
1292 vec4 maskColor
= TextureLookup(s_mask
, maskTexCoord
);
1293 gl_FragColor
= texColor
* alpha
* maskColor
.w
;
1295 ); // NOLINT(whitespace/parens)
1298 FragmentShaderYUVVideo::FragmentShaderYUVVideo()
1299 : y_texture_location_(-1),
1300 u_texture_location_(-1),
1301 v_texture_location_(-1),
1302 alpha_location_(-1),
1303 yuv_matrix_location_(-1),
1304 yuv_adj_location_(-1) {}
1306 void FragmentShaderYUVVideo::Init(GLES2Interface
* context
,
1308 int* base_uniform_index
) {
1309 static const char* uniforms
[] = {
1317 int locations
[arraysize(uniforms
)];
1319 GetProgramUniformLocations(context
,
1321 arraysize(uniforms
),
1324 base_uniform_index
);
1325 y_texture_location_
= locations
[0];
1326 u_texture_location_
= locations
[1];
1327 v_texture_location_
= locations
[2];
1328 alpha_location_
= locations
[3];
1329 yuv_matrix_location_
= locations
[4];
1330 yuv_adj_location_
= locations
[5];
1333 std::string
FragmentShaderYUVVideo::GetShaderString(
1334 TexCoordPrecision precision
, SamplerType sampler
) const {
1335 return FRAGMENT_SHADER(
1336 precision mediump
float;
1337 precision mediump
int;
1338 varying TexCoordPrecision vec2 v_texCoord
;
1339 uniform SamplerType y_texture
;
1340 uniform SamplerType u_texture
;
1341 uniform SamplerType v_texture
;
1342 uniform
float alpha
;
1343 uniform vec3 yuv_adj
;
1344 uniform mat3 yuv_matrix
;
1346 float y_raw
= TextureLookup(y_texture
, v_texCoord
).x
;
1347 float u_unsigned
= TextureLookup(u_texture
, v_texCoord
).x
;
1348 float v_unsigned
= TextureLookup(v_texture
, v_texCoord
).x
;
1349 vec3 yuv
= vec3(y_raw
, u_unsigned
, v_unsigned
) + yuv_adj
;
1350 vec3 rgb
= yuv_matrix
* yuv
;
1351 gl_FragColor
= vec4(rgb
, 1.0) * alpha
;
1353 ); // NOLINT(whitespace/parens)
1356 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo()
1357 : y_texture_location_(-1),
1358 u_texture_location_(-1),
1359 v_texture_location_(-1),
1360 a_texture_location_(-1),
1361 alpha_location_(-1),
1362 yuv_matrix_location_(-1),
1363 yuv_adj_location_(-1) {
1366 void FragmentShaderYUVAVideo::Init(GLES2Interface
* context
,
1368 int* base_uniform_index
) {
1369 static const char* uniforms
[] = {
1378 int locations
[arraysize(uniforms
)];
1380 GetProgramUniformLocations(context
,
1382 arraysize(uniforms
),
1385 base_uniform_index
);
1386 y_texture_location_
= locations
[0];
1387 u_texture_location_
= locations
[1];
1388 v_texture_location_
= locations
[2];
1389 a_texture_location_
= locations
[3];
1390 alpha_location_
= locations
[4];
1391 yuv_matrix_location_
= locations
[5];
1392 yuv_adj_location_
= locations
[6];
1395 std::string
FragmentShaderYUVAVideo::GetShaderString(
1396 TexCoordPrecision precision
, SamplerType sampler
) const {
1397 return FRAGMENT_SHADER(
1398 precision mediump
float;
1399 precision mediump
int;
1400 varying TexCoordPrecision vec2 v_texCoord
;
1401 uniform SamplerType y_texture
;
1402 uniform SamplerType u_texture
;
1403 uniform SamplerType v_texture
;
1404 uniform SamplerType a_texture
;
1405 uniform
float alpha
;
1406 uniform vec3 yuv_adj
;
1407 uniform mat3 yuv_matrix
;
1409 float y_raw
= TextureLookup(y_texture
, v_texCoord
).x
;
1410 float u_unsigned
= TextureLookup(u_texture
, v_texCoord
).x
;
1411 float v_unsigned
= TextureLookup(v_texture
, v_texCoord
).x
;
1412 float a_raw
= TextureLookup(a_texture
, v_texCoord
).x
;
1413 vec3 yuv
= vec3(y_raw
, u_unsigned
, v_unsigned
) + yuv_adj
;
1414 vec3 rgb
= yuv_matrix
* yuv
;
1415 gl_FragColor
= vec4(rgb
, 1.0) * (alpha
* a_raw
);
1417 ); // NOLINT(whitespace/parens)
1420 FragmentShaderColor::FragmentShaderColor()
1421 : color_location_(-1) {}
1423 void FragmentShaderColor::Init(GLES2Interface
* context
,
1425 int* base_uniform_index
) {
1426 static const char* uniforms
[] = {
1429 int locations
[arraysize(uniforms
)];
1431 GetProgramUniformLocations(context
,
1433 arraysize(uniforms
),
1436 base_uniform_index
);
1437 color_location_
= locations
[0];
1440 std::string
FragmentShaderColor::GetShaderString(
1441 TexCoordPrecision precision
, SamplerType sampler
) const {
1442 return FRAGMENT_SHADER(
1443 precision mediump
float;
1446 gl_FragColor
= color
;
1448 ); // NOLINT(whitespace/parens)
1451 FragmentShaderColorAA::FragmentShaderColorAA()
1452 : color_location_(-1) {}
1454 void FragmentShaderColorAA::Init(GLES2Interface
* context
,
1456 int* base_uniform_index
) {
1457 static const char* uniforms
[] = {
1460 int locations
[arraysize(uniforms
)];
1462 GetProgramUniformLocations(context
,
1464 arraysize(uniforms
),
1467 base_uniform_index
);
1468 color_location_
= locations
[0];
1471 std::string
FragmentShaderColorAA::GetShaderString(
1472 TexCoordPrecision precision
, SamplerType sampler
) const {
1473 return FRAGMENT_SHADER(
1474 precision mediump
float;
1476 varying vec4 edge_dist
[2]; // 8 edge distances.
1479 vec4 d4
= min(edge_dist
[0], edge_dist
[1]);
1480 vec2 d2
= min(d4
.xz
, d4
.yw
);
1481 float aa
= clamp(gl_FragCoord
.w
* min(d2
.x
, d2
.y
), 0.0, 1.0);
1482 gl_FragColor
= color
* aa
;
1484 ); // NOLINT(whitespace/parens)
1487 FragmentShaderCheckerboard::FragmentShaderCheckerboard()
1488 : alpha_location_(-1),
1489 tex_transform_location_(-1),
1490 frequency_location_(-1) {}
1492 void FragmentShaderCheckerboard::Init(GLES2Interface
* context
,
1494 int* base_uniform_index
) {
1495 static const char* uniforms
[] = {
1501 int locations
[arraysize(uniforms
)];
1503 GetProgramUniformLocations(context
,
1505 arraysize(uniforms
),
1508 base_uniform_index
);
1509 alpha_location_
= locations
[0];
1510 tex_transform_location_
= locations
[1];
1511 frequency_location_
= locations
[2];
1512 color_location_
= locations
[3];
1515 std::string
FragmentShaderCheckerboard::GetShaderString(
1516 TexCoordPrecision precision
, SamplerType sampler
) const {
1517 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide"
1518 // by Munshi, Ginsburg, Shreiner.
1519 return FRAGMENT_SHADER(
1520 precision mediump
float;
1521 precision mediump
int;
1522 varying vec2 v_texCoord
;
1523 uniform
float alpha
;
1524 uniform
float frequency
;
1525 uniform vec4 texTransform
;
1528 vec4 color1
= vec4(1.0, 1.0, 1.0, 1.0);
1529 vec4 color2
= color
;
1531 clamp(v_texCoord
, 0.0, 1.0) * texTransform
.zw
+ texTransform
.xy
;
1532 vec2 coord
= mod(floor(texCoord
* frequency
* 2.0), 2.0);
1533 float picker
= abs(coord
.x
- coord
.y
); // NOLINT
1534 gl_FragColor
= mix(color1
, color2
, picker
) * alpha
;
1536 ); // NOLINT(whitespace/parens)