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

Side by Side Diff: cc/output/shader.cc

Issue 658153003: cc: clang-format shader.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final formatting Created 6 years, 2 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 | « no previous file | 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/output/shader.h" 5 #include "cc/output/shader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "cc/output/gl_renderer.h" // For the GLC() macro. 11 #include "cc/output/gl_renderer.h" // For the GLC() macro.
12 #include "gpu/command_buffer/client/gles2_interface.h" 12 #include "gpu/command_buffer/client/gles2_interface.h"
13 13
14 #define SHADER0(Src) #Src 14 #define SHADER0(Src) #Src
15 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src)) 15 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src))
16 #define FRAGMENT_SHADER(Src) SetFragmentTexCoordPrecision( \ 16 #define FRAGMENT_SHADER(Src) \
17 precision, SetFragmentSamplerType(sampler, SHADER0(Src))) 17 SetFragmentTexCoordPrecision(precision, \
18 SetFragmentSamplerType(sampler, SHADER0(Src)))
18 19
19 using gpu::gles2::GLES2Interface; 20 using gpu::gles2::GLES2Interface;
20 21
21 namespace cc { 22 namespace cc {
22 23
23 namespace { 24 namespace {
24 25
25 static void GetProgramUniformLocations(GLES2Interface* context, 26 static void GetProgramUniformLocations(GLES2Interface* context,
26 unsigned program, 27 unsigned program,
27 size_t count, 28 size_t count,
28 const char** uniforms, 29 const char** uniforms,
29 int* locations, 30 int* locations,
30 int* base_uniform_index) { 31 int* base_uniform_index) {
31 for (size_t i = 0; i < count; i++) { 32 for (size_t i = 0; i < count; i++) {
32 locations[i] = (*base_uniform_index)++; 33 locations[i] = (*base_uniform_index)++;
33 context->BindUniformLocationCHROMIUM(program, locations[i], uniforms[i]); 34 context->BindUniformLocationCHROMIUM(program, locations[i], uniforms[i]);
34 } 35 }
35 } 36 }
36 37
37 static std::string SetFragmentTexCoordPrecision( 38 static std::string SetFragmentTexCoordPrecision(
38 TexCoordPrecision requested_precision, std::string shader_string) { 39 TexCoordPrecision requested_precision,
40 std::string shader_string) {
39 switch (requested_precision) { 41 switch (requested_precision) {
40 case TexCoordPrecisionHigh: 42 case TexCoordPrecisionHigh:
41 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); 43 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos);
42 return 44 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
43 "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" 45 " #define TexCoordPrecision highp\n"
44 " #define TexCoordPrecision highp\n" 46 "#else\n"
45 "#else\n" 47 " #define TexCoordPrecision mediump\n"
46 " #define TexCoordPrecision mediump\n" 48 "#endif\n" +
47 "#endif\n" + 49 shader_string;
48 shader_string;
49 case TexCoordPrecisionMedium: 50 case TexCoordPrecisionMedium:
50 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); 51 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos);
51 return "#define TexCoordPrecision mediump\n" + 52 return "#define TexCoordPrecision mediump\n" + shader_string;
52 shader_string;
53 case TexCoordPrecisionNA: 53 case TexCoordPrecisionNA:
54 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos); 54 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos);
55 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); 55 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos);
56 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); 56 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos);
57 return shader_string; 57 return shader_string;
58 default: 58 default:
59 NOTREACHED(); 59 NOTREACHED();
60 break; 60 break;
61 } 61 }
62 return shader_string; 62 return shader_string;
63 } 63 }
64 64
65 static std::string SetVertexTexCoordPrecision(const char* shader_string) { 65 static std::string SetVertexTexCoordPrecision(const char* shader_string) {
66 // We unconditionally use highp in the vertex shader since 66 // We unconditionally use highp in the vertex shader since
67 // we are unlikely to be vertex shader bound when drawing large quads. 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 68 // Also, some vertex shaders mutate the texture coordinate in such a
69 // way that the effective precision might be lower than expected. 69 // way that the effective precision might be lower than expected.
70 return "#define TexCoordPrecision highp\n" + 70 return "#define TexCoordPrecision highp\n" + std::string(shader_string);
71 std::string(shader_string);
72 } 71 }
73 72
74 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, 73 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context,
75 int *highp_threshold_cache, 74 int* highp_threshold_cache,
76 int highp_threshold_min, 75 int highp_threshold_min,
77 int x, int y) { 76 int x,
77 int y) {
78 if (*highp_threshold_cache == 0) { 78 if (*highp_threshold_cache == 0) {
79 // Initialize range and precision with minimum spec values for when 79 // Initialize range and precision with minimum spec values for when
80 // GetShaderPrecisionFormat is a test stub. 80 // GetShaderPrecisionFormat is a test stub.
81 // TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat 81 // TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat
82 // everywhere. 82 // everywhere.
83 GLint range[2] = { 14, 14 }; 83 GLint range[2] = {14, 14};
84 GLint precision = 10; 84 GLint precision = 10;
85 GLC(context, context->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, 85 GLC(context,
86 GL_MEDIUM_FLOAT, 86 context->GetShaderPrecisionFormat(
87 range, &precision)); 87 GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, range, &precision));
88 *highp_threshold_cache = 1 << precision; 88 *highp_threshold_cache = 1 << precision;
89 } 89 }
90 90
91 int highp_threshold = std::max(*highp_threshold_cache, highp_threshold_min); 91 int highp_threshold = std::max(*highp_threshold_cache, highp_threshold_min);
92 if (x > highp_threshold || y > highp_threshold) 92 if (x > highp_threshold || y > highp_threshold)
93 return TexCoordPrecisionHigh; 93 return TexCoordPrecisionHigh;
94 return TexCoordPrecisionMedium; 94 return TexCoordPrecisionMedium;
95 } 95 }
96 96
97 static std::string SetFragmentSamplerType( 97 static std::string SetFragmentSamplerType(SamplerType requested_type,
98 SamplerType requested_type, std::string shader_string) { 98 std::string shader_string) {
99 switch (requested_type) { 99 switch (requested_type) {
100 case SamplerType2D: 100 case SamplerType2D:
101 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); 101 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos);
102 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); 102 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos);
103 return 103 return "#define SamplerType sampler2D\n"
104 "#define SamplerType sampler2D\n" 104 "#define TextureLookup texture2D\n" +
105 "#define TextureLookup texture2D\n" + 105 shader_string;
106 shader_string;
107 case SamplerType2DRect: 106 case SamplerType2DRect:
108 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); 107 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos);
109 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); 108 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos);
110 return 109 return "#extension GL_ARB_texture_rectangle : require\n"
111 "#extension GL_ARB_texture_rectangle : require\n" 110 "#define SamplerType sampler2DRect\n"
112 "#define SamplerType sampler2DRect\n" 111 "#define TextureLookup texture2DRect\n" +
113 "#define TextureLookup texture2DRect\n" + 112 shader_string;
114 shader_string;
115 case SamplerTypeExternalOES: 113 case SamplerTypeExternalOES:
116 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); 114 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos);
117 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); 115 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos);
118 return 116 return "#extension GL_OES_EGL_image_external : require\n"
119 "#extension GL_OES_EGL_image_external : require\n" 117 "#define SamplerType samplerExternalOES\n"
120 "#define SamplerType samplerExternalOES\n" 118 "#define TextureLookup texture2D\n" +
121 "#define TextureLookup texture2D\n" + 119 shader_string;
122 shader_string;
123 case SamplerTypeNA: 120 case SamplerTypeNA:
124 DCHECK_EQ(shader_string.find("SamplerType"), std::string::npos); 121 DCHECK_EQ(shader_string.find("SamplerType"), std::string::npos);
125 DCHECK_EQ(shader_string.find("TextureLookup"), std::string::npos); 122 DCHECK_EQ(shader_string.find("TextureLookup"), std::string::npos);
126 return shader_string; 123 return shader_string;
127 default: 124 default:
128 NOTREACHED(); 125 NOTREACHED();
129 break; 126 break;
130 } 127 }
131 return shader_string; 128 return shader_string;
132 } 129 }
133 130
134 } // namespace 131 } // namespace
135 132
136 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, 133 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context,
137 int* highp_threshold_cache, 134 int* highp_threshold_cache,
138 int highp_threshold_min, 135 int highp_threshold_min,
139 const gfx::Point& max_coordinate) { 136 const gfx::Point& max_coordinate) {
140 return TexCoordPrecisionRequired(context, 137 return TexCoordPrecisionRequired(context,
141 highp_threshold_cache, highp_threshold_min, 138 highp_threshold_cache,
142 max_coordinate.x(), max_coordinate.y()); 139 highp_threshold_min,
140 max_coordinate.x(),
141 max_coordinate.y());
143 } 142 }
144 143
145 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, 144 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context,
146 int *highp_threshold_cache, 145 int* highp_threshold_cache,
147 int highp_threshold_min, 146 int highp_threshold_min,
148 const gfx::Size& max_size) { 147 const gfx::Size& max_size) {
149 return TexCoordPrecisionRequired(context, 148 return TexCoordPrecisionRequired(context,
150 highp_threshold_cache, highp_threshold_min, 149 highp_threshold_cache,
151 max_size.width(), max_size.height()); 150 highp_threshold_min,
151 max_size.width(),
152 max_size.height());
152 } 153 }
153 154
154 VertexShaderPosTex::VertexShaderPosTex() 155 VertexShaderPosTex::VertexShaderPosTex() : matrix_location_(-1) {
155 : matrix_location_(-1) {} 156 }
156 157
157 void VertexShaderPosTex::Init(GLES2Interface* context, 158 void VertexShaderPosTex::Init(GLES2Interface* context,
158 unsigned program, 159 unsigned program,
159 int* base_uniform_index) { 160 int* base_uniform_index) {
160 static const char* uniforms[] = { 161 static const char* uniforms[] = {
161 "matrix", 162 "matrix",
162 }; 163 };
163 int locations[arraysize(uniforms)]; 164 int locations[arraysize(uniforms)];
164 165
165 GetProgramUniformLocations(context, 166 GetProgramUniformLocations(context,
166 program, 167 program,
167 arraysize(uniforms), 168 arraysize(uniforms),
168 uniforms, 169 uniforms,
169 locations, 170 locations,
170 base_uniform_index); 171 base_uniform_index);
171 matrix_location_ = locations[0]; 172 matrix_location_ = locations[0];
172 } 173 }
173 174
174 std::string VertexShaderPosTex::GetShaderString() const { 175 std::string VertexShaderPosTex::GetShaderString() const {
176 // clang-format off
175 return VERTEX_SHADER( 177 return VERTEX_SHADER(
176 attribute vec4 a_position; 178 // clang-format on
177 attribute TexCoordPrecision vec2 a_texCoord; 179 attribute vec4 a_position;
178 uniform mat4 matrix; 180 attribute TexCoordPrecision vec2 a_texCoord;
179 varying TexCoordPrecision vec2 v_texCoord; 181 uniform mat4 matrix;
180 void main() { 182 varying TexCoordPrecision vec2 v_texCoord;
181 gl_Position = matrix * a_position; 183 void main() {
182 v_texCoord = a_texCoord; 184 gl_Position = matrix * a_position;
183 } 185 v_texCoord = a_texCoord;
186 }
187 // clang-format off
184 ); // NOLINT(whitespace/parens) 188 ); // NOLINT(whitespace/parens)
189 // clang-format on
185 } 190 }
186 191
187 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() 192 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset()
188 : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) {} 193 : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) {
194 }
189 195
190 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, 196 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context,
191 unsigned program, 197 unsigned program,
192 int* base_uniform_index) { 198 int* base_uniform_index) {
193 static const char* uniforms[] = { 199 static const char* uniforms[] = {
194 "matrix", 200 "matrix", "texScale", "texOffset",
195 "texScale",
196 "texOffset",
197 }; 201 };
198 int locations[arraysize(uniforms)]; 202 int locations[arraysize(uniforms)];
199 203
200 GetProgramUniformLocations(context, 204 GetProgramUniformLocations(context,
201 program, 205 program,
202 arraysize(uniforms), 206 arraysize(uniforms),
203 uniforms, 207 uniforms,
204 locations, 208 locations,
205 base_uniform_index); 209 base_uniform_index);
206 matrix_location_ = locations[0]; 210 matrix_location_ = locations[0];
207 tex_scale_location_ = locations[1]; 211 tex_scale_location_ = locations[1];
208 tex_offset_location_ = locations[2]; 212 tex_offset_location_ = locations[2];
209 } 213 }
210 214
211 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { 215 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const {
216 // clang-format off
212 return VERTEX_SHADER( 217 return VERTEX_SHADER(
213 precision mediump float; 218 // clang-format on
214 attribute vec4 a_position; 219 precision mediump float;
215 attribute TexCoordPrecision vec2 a_texCoord; 220 attribute vec4 a_position;
216 uniform mat4 matrix; 221 attribute TexCoordPrecision vec2 a_texCoord;
217 varying TexCoordPrecision vec2 v_texCoord; 222 uniform mat4 matrix;
218 uniform TexCoordPrecision vec2 texScale; 223 varying TexCoordPrecision vec2 v_texCoord;
219 uniform TexCoordPrecision vec2 texOffset; 224 uniform TexCoordPrecision vec2 texScale;
220 void main() { 225 uniform TexCoordPrecision vec2 texOffset;
226 void main() {
221 gl_Position = matrix * a_position; 227 gl_Position = matrix * a_position;
222 v_texCoord = a_texCoord * texScale + texOffset; 228 v_texCoord = a_texCoord * texScale + texOffset;
223 } 229 }
230 // clang-format off
224 ); // NOLINT(whitespace/parens) 231 ); // NOLINT(whitespace/parens)
232 // clang-format on
225 } 233 }
226 234
227 VertexShaderPos::VertexShaderPos() 235 VertexShaderPos::VertexShaderPos() : matrix_location_(-1) {
228 : matrix_location_(-1) {} 236 }
229 237
230 void VertexShaderPos::Init(GLES2Interface* context, 238 void VertexShaderPos::Init(GLES2Interface* context,
231 unsigned program, 239 unsigned program,
232 int* base_uniform_index) { 240 int* base_uniform_index) {
233 static const char* uniforms[] = { 241 static const char* uniforms[] = {
234 "matrix", 242 "matrix",
235 }; 243 };
236 int locations[arraysize(uniforms)]; 244 int locations[arraysize(uniforms)];
237 245
238 GetProgramUniformLocations(context, 246 GetProgramUniformLocations(context,
239 program, 247 program,
240 arraysize(uniforms), 248 arraysize(uniforms),
241 uniforms, 249 uniforms,
242 locations, 250 locations,
243 base_uniform_index); 251 base_uniform_index);
244 matrix_location_ = locations[0]; 252 matrix_location_ = locations[0];
245 } 253 }
246 254
247 std::string VertexShaderPos::GetShaderString() const { 255 std::string VertexShaderPos::GetShaderString() const {
256 // clang-format off
248 return VERTEX_SHADER( 257 return VERTEX_SHADER(
249 attribute vec4 a_position; 258 // clang-format on
250 uniform mat4 matrix; 259 attribute vec4 a_position;
251 void main() { 260 uniform mat4 matrix;
252 gl_Position = matrix * a_position; 261 void main() { gl_Position = matrix * a_position; }
253 } 262 // clang-format off
254 ); // NOLINT(whitespace/parens) 263 ); // NOLINT(whitespace/parens)
264 // clang-format on
255 } 265 }
256 266
257 VertexShaderPosTexTransform::VertexShaderPosTexTransform() 267 VertexShaderPosTexTransform::VertexShaderPosTexTransform()
258 : matrix_location_(-1), 268 : matrix_location_(-1),
259 tex_transform_location_(-1), 269 tex_transform_location_(-1),
260 vertex_opacity_location_(-1) {} 270 vertex_opacity_location_(-1) {
271 }
261 272
262 void VertexShaderPosTexTransform::Init(GLES2Interface* context, 273 void VertexShaderPosTexTransform::Init(GLES2Interface* context,
263 unsigned program, 274 unsigned program,
264 int* base_uniform_index) { 275 int* base_uniform_index) {
265 static const char* uniforms[] = { 276 static const char* uniforms[] = {
266 "matrix", 277 "matrix", "texTransform", "opacity",
267 "texTransform",
268 "opacity",
269 }; 278 };
270 int locations[arraysize(uniforms)]; 279 int locations[arraysize(uniforms)];
271 280
272 GetProgramUniformLocations(context, 281 GetProgramUniformLocations(context,
273 program, 282 program,
274 arraysize(uniforms), 283 arraysize(uniforms),
275 uniforms, 284 uniforms,
276 locations, 285 locations,
277 base_uniform_index); 286 base_uniform_index);
278 matrix_location_ = locations[0]; 287 matrix_location_ = locations[0];
279 tex_transform_location_ = locations[1]; 288 tex_transform_location_ = locations[1];
280 vertex_opacity_location_ = locations[2]; 289 vertex_opacity_location_ = locations[2];
281 } 290 }
282 291
283 std::string VertexShaderPosTexTransform::GetShaderString() const { 292 std::string VertexShaderPosTexTransform::GetShaderString() const {
293 // clang-format off
284 return VERTEX_SHADER( 294 return VERTEX_SHADER(
285 attribute vec4 a_position; 295 // clang-format on
286 attribute TexCoordPrecision vec2 a_texCoord; 296 attribute vec4 a_position;
287 attribute float a_index; 297 attribute TexCoordPrecision vec2 a_texCoord;
288 uniform mat4 matrix[8]; 298 attribute float a_index;
289 uniform TexCoordPrecision vec4 texTransform[8]; 299 uniform mat4 matrix[8];
290 uniform float opacity[32]; 300 uniform TexCoordPrecision vec4 texTransform[8];
291 varying TexCoordPrecision vec2 v_texCoord; 301 uniform float opacity[32];
292 varying float v_alpha; 302 varying TexCoordPrecision vec2 v_texCoord;
293 void main() { 303 varying float v_alpha;
294 int quad_index = int(a_index * 0.25); // NOLINT 304 void main() {
295 gl_Position = matrix[quad_index] * a_position; 305 int quad_index = int(a_index * 0.25); // NOLINT
296 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; 306 gl_Position = matrix[quad_index] * a_position;
297 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; 307 TexCoordPrecision vec4 texTrans = texTransform[quad_index];
298 v_alpha = opacity[int(a_index)]; // NOLINT 308 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy;
299 } 309 v_alpha = opacity[int(a_index)]; // NOLINT
310 }
311 // clang-format off
300 ); // NOLINT(whitespace/parens) 312 ); // NOLINT(whitespace/parens)
313 // clang-format on
301 } 314 }
302 315
303 std::string VertexShaderPosTexIdentity::GetShaderString() const { 316 std::string VertexShaderPosTexIdentity::GetShaderString() const {
317 // clang-format off
304 return VERTEX_SHADER( 318 return VERTEX_SHADER(
305 attribute vec4 a_position; 319 // clang-format on
306 varying TexCoordPrecision vec2 v_texCoord; 320 attribute vec4 a_position;
307 void main() { 321 varying TexCoordPrecision vec2 v_texCoord;
308 gl_Position = a_position; 322 void main() {
309 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; 323 gl_Position = a_position;
310 } 324 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5;
325 }
326 // clang-format off
311 ); // NOLINT(whitespace/parens) 327 ); // NOLINT(whitespace/parens)
328 // clang-format on
312 } 329 }
313 330
314 VertexShaderQuad::VertexShaderQuad() 331 VertexShaderQuad::VertexShaderQuad()
315 : matrix_location_(-1), 332 : matrix_location_(-1), quad_location_(-1) {
316 quad_location_(-1) {} 333 }
317 334
318 void VertexShaderQuad::Init(GLES2Interface* context, 335 void VertexShaderQuad::Init(GLES2Interface* context,
319 unsigned program, 336 unsigned program,
320 int* base_uniform_index) { 337 int* base_uniform_index) {
321 static const char* uniforms[] = { 338 static const char* uniforms[] = {
322 "matrix", 339 "matrix", "quad",
323 "quad",
324 }; 340 };
325 int locations[arraysize(uniforms)]; 341 int locations[arraysize(uniforms)];
326 342
327 GetProgramUniformLocations(context, 343 GetProgramUniformLocations(context,
328 program, 344 program,
329 arraysize(uniforms), 345 arraysize(uniforms),
330 uniforms, 346 uniforms,
331 locations, 347 locations,
332 base_uniform_index); 348 base_uniform_index);
333 matrix_location_ = locations[0]; 349 matrix_location_ = locations[0];
334 quad_location_ = locations[1]; 350 quad_location_ = locations[1];
335 } 351 }
336 352
337 std::string VertexShaderQuad::GetShaderString() const { 353 std::string VertexShaderQuad::GetShaderString() const {
338 #if defined(OS_ANDROID) 354 #if defined(OS_ANDROID)
339 // TODO(epenner): Find the cause of this 'quad' uniform 355 // TODO(epenner): Find the cause of this 'quad' uniform
340 // being missing if we don't add dummy variables. 356 // being missing if we don't add dummy variables.
341 // http://crbug.com/240602 357 // http://crbug.com/240602
358 // clang-format off
342 return VERTEX_SHADER( 359 return VERTEX_SHADER(
343 attribute TexCoordPrecision vec4 a_position; 360 // clang-format on
344 attribute float a_index; 361 attribute TexCoordPrecision vec4 a_position;
345 uniform mat4 matrix; 362 attribute float a_index;
346 uniform TexCoordPrecision vec2 quad[4]; 363 uniform mat4 matrix;
347 uniform TexCoordPrecision vec2 dummy_uniform; 364 uniform TexCoordPrecision vec2 quad[4];
348 varying TexCoordPrecision vec2 dummy_varying; 365 uniform TexCoordPrecision vec2 dummy_uniform;
349 void main() { 366 varying TexCoordPrecision vec2 dummy_varying;
350 vec2 pos = quad[int(a_index)]; // NOLINT 367 void main() {
351 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); 368 vec2 pos = quad[int(a_index)]; // NOLINT
352 dummy_varying = dummy_uniform; 369 gl_Position = matrix * vec4(pos, a_position.z, a_position.w);
353 } 370 dummy_varying = dummy_uniform;
371 }
372 // clang-format off
354 ); // NOLINT(whitespace/parens) 373 ); // NOLINT(whitespace/parens)
374 // clang-format on
355 #else 375 #else
376 // clang-format off
356 return VERTEX_SHADER( 377 return VERTEX_SHADER(
357 attribute TexCoordPrecision vec4 a_position; 378 // clang-format on
358 attribute float a_index; 379 attribute TexCoordPrecision vec4 a_position;
359 uniform mat4 matrix; 380 attribute float a_index;
360 uniform TexCoordPrecision vec2 quad[4]; 381 uniform mat4 matrix;
361 void main() { 382 uniform TexCoordPrecision vec2 quad[4];
362 vec2 pos = quad[int(a_index)]; // NOLINT 383 void main() {
363 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); 384 vec2 pos = quad[int(a_index)]; // NOLINT
364 } 385 gl_Position = matrix * vec4(pos, a_position.z, a_position.w);
386 }
387 // clang-format off
365 ); // NOLINT(whitespace/parens) 388 ); // NOLINT(whitespace/parens)
389 // clang-format on
366 #endif 390 #endif
367 } 391 }
368 392
369 VertexShaderQuadAA::VertexShaderQuadAA() 393 VertexShaderQuadAA::VertexShaderQuadAA()
370 : matrix_location_(-1), 394 : matrix_location_(-1),
371 viewport_location_(-1), 395 viewport_location_(-1),
372 quad_location_(-1), 396 quad_location_(-1),
373 edge_location_(-1) {} 397 edge_location_(-1) {
398 }
374 399
375 void VertexShaderQuadAA::Init(GLES2Interface* context, 400 void VertexShaderQuadAA::Init(GLES2Interface* context,
376 unsigned program, 401 unsigned program,
377 int* base_uniform_index) { 402 int* base_uniform_index) {
378 static const char* uniforms[] = { 403 static const char* uniforms[] = {
379 "matrix", 404 "matrix", "viewport", "quad", "edge",
380 "viewport",
381 "quad",
382 "edge",
383 }; 405 };
384 int locations[arraysize(uniforms)]; 406 int locations[arraysize(uniforms)];
385 407
386 GetProgramUniformLocations(context, 408 GetProgramUniformLocations(context,
387 program, 409 program,
388 arraysize(uniforms), 410 arraysize(uniforms),
389 uniforms, 411 uniforms,
390 locations, 412 locations,
391 base_uniform_index); 413 base_uniform_index);
392 matrix_location_ = locations[0]; 414 matrix_location_ = locations[0];
393 viewport_location_ = locations[1]; 415 viewport_location_ = locations[1];
394 quad_location_ = locations[2]; 416 quad_location_ = locations[2];
395 edge_location_ = locations[3]; 417 edge_location_ = locations[3];
396 } 418 }
397 419
398 std::string VertexShaderQuadAA::GetShaderString() const { 420 std::string VertexShaderQuadAA::GetShaderString() const {
421 // clang-format off
399 return VERTEX_SHADER( 422 return VERTEX_SHADER(
400 attribute TexCoordPrecision vec4 a_position; 423 // clang-format on
401 attribute float a_index; 424 attribute TexCoordPrecision vec4 a_position;
402 uniform mat4 matrix; 425 attribute float a_index;
403 uniform vec4 viewport; 426 uniform mat4 matrix;
404 uniform TexCoordPrecision vec2 quad[4]; 427 uniform vec4 viewport;
405 uniform TexCoordPrecision vec3 edge[8]; 428 uniform TexCoordPrecision vec2 quad[4];
406 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 429 uniform TexCoordPrecision vec3 edge[8];
430 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
407 431
408 void main() { 432 void main() {
409 vec2 pos = quad[int(a_index)]; // NOLINT 433 vec2 pos = quad[int(a_index)]; // NOLINT
410 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); 434 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); 435 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); 436 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0);
413 edge_dist[0] = vec4(dot(edge[0], screen_pos), 437 edge_dist[0] = vec4(dot(edge[0], screen_pos),
414 dot(edge[1], screen_pos), 438 dot(edge[1], screen_pos),
415 dot(edge[2], screen_pos), 439 dot(edge[2], screen_pos),
416 dot(edge[3], screen_pos)) * gl_Position.w; 440 dot(edge[3], screen_pos)) *
417 edge_dist[1] = vec4(dot(edge[4], screen_pos), 441 gl_Position.w;
418 dot(edge[5], screen_pos), 442 edge_dist[1] = vec4(dot(edge[4], screen_pos),
419 dot(edge[6], screen_pos), 443 dot(edge[5], screen_pos),
420 dot(edge[7], screen_pos)) * gl_Position.w; 444 dot(edge[6], screen_pos),
421 } 445 dot(edge[7], screen_pos)) *
446 gl_Position.w;
447 }
448 // clang-format off
422 ); // NOLINT(whitespace/parens) 449 ); // NOLINT(whitespace/parens)
450 // clang-format on
423 } 451 }
424 452
425 VertexShaderQuadTexTransformAA::VertexShaderQuadTexTransformAA() 453 VertexShaderQuadTexTransformAA::VertexShaderQuadTexTransformAA()
426 : matrix_location_(-1), 454 : matrix_location_(-1),
427 viewport_location_(-1), 455 viewport_location_(-1),
428 quad_location_(-1), 456 quad_location_(-1),
429 edge_location_(-1), 457 edge_location_(-1),
430 tex_transform_location_(-1) {} 458 tex_transform_location_(-1) {
459 }
431 460
432 void VertexShaderQuadTexTransformAA::Init(GLES2Interface* context, 461 void VertexShaderQuadTexTransformAA::Init(GLES2Interface* context,
433 unsigned program, 462 unsigned program,
434 int* base_uniform_index) { 463 int* base_uniform_index) {
435 static const char* uniforms[] = { 464 static const char* uniforms[] = {
436 "matrix", 465 "matrix", "viewport", "quad", "edge", "texTrans",
437 "viewport",
438 "quad",
439 "edge",
440 "texTrans",
441 }; 466 };
442 int locations[arraysize(uniforms)]; 467 int locations[arraysize(uniforms)];
443 468
444 GetProgramUniformLocations(context, 469 GetProgramUniformLocations(context,
445 program, 470 program,
446 arraysize(uniforms), 471 arraysize(uniforms),
447 uniforms, 472 uniforms,
448 locations, 473 locations,
449 base_uniform_index); 474 base_uniform_index);
450 matrix_location_ = locations[0]; 475 matrix_location_ = locations[0];
451 viewport_location_ = locations[1]; 476 viewport_location_ = locations[1];
452 quad_location_ = locations[2]; 477 quad_location_ = locations[2];
453 edge_location_ = locations[3]; 478 edge_location_ = locations[3];
454 tex_transform_location_ = locations[4]; 479 tex_transform_location_ = locations[4];
455 } 480 }
456 481
457 std::string VertexShaderQuadTexTransformAA::GetShaderString() const { 482 std::string VertexShaderQuadTexTransformAA::GetShaderString() const {
483 // clang-format off
458 return VERTEX_SHADER( 484 return VERTEX_SHADER(
459 attribute TexCoordPrecision vec4 a_position; 485 // clang-format on
460 attribute float a_index; 486 attribute TexCoordPrecision vec4 a_position;
461 uniform mat4 matrix; 487 attribute float a_index;
462 uniform vec4 viewport; 488 uniform mat4 matrix;
463 uniform TexCoordPrecision vec2 quad[4]; 489 uniform vec4 viewport;
464 uniform TexCoordPrecision vec3 edge[8]; 490 uniform TexCoordPrecision vec2 quad[4];
465 uniform TexCoordPrecision vec4 texTrans; 491 uniform TexCoordPrecision vec3 edge[8];
466 varying TexCoordPrecision vec2 v_texCoord; 492 uniform TexCoordPrecision vec4 texTrans;
467 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 493 varying TexCoordPrecision vec2 v_texCoord;
494 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
468 495
469 void main() { 496 void main() {
470 vec2 pos = quad[int(a_index)]; // NOLINT 497 vec2 pos = quad[int(a_index)]; // NOLINT
471 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); 498 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); 499 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); 500 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0);
474 edge_dist[0] = vec4(dot(edge[0], screen_pos), 501 edge_dist[0] = vec4(dot(edge[0], screen_pos),
475 dot(edge[1], screen_pos), 502 dot(edge[1], screen_pos),
476 dot(edge[2], screen_pos), 503 dot(edge[2], screen_pos),
477 dot(edge[3], screen_pos)) * gl_Position.w; 504 dot(edge[3], screen_pos)) *
478 edge_dist[1] = vec4(dot(edge[4], screen_pos), 505 gl_Position.w;
479 dot(edge[5], screen_pos), 506 edge_dist[1] = vec4(dot(edge[4], screen_pos),
480 dot(edge[6], screen_pos), 507 dot(edge[5], screen_pos),
481 dot(edge[7], screen_pos)) * gl_Position.w; 508 dot(edge[6], screen_pos),
482 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy; 509 dot(edge[7], screen_pos)) *
483 } 510 gl_Position.w;
511 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy;
512 }
513 // clang-format off
484 ); // NOLINT(whitespace/parens) 514 ); // NOLINT(whitespace/parens)
515 // clang-format on
485 } 516 }
486 517
487 VertexShaderTile::VertexShaderTile() 518 VertexShaderTile::VertexShaderTile()
488 : matrix_location_(-1), 519 : matrix_location_(-1),
489 quad_location_(-1), 520 quad_location_(-1),
490 vertex_tex_transform_location_(-1) {} 521 vertex_tex_transform_location_(-1) {
522 }
491 523
492 void VertexShaderTile::Init(GLES2Interface* context, 524 void VertexShaderTile::Init(GLES2Interface* context,
493 unsigned program, 525 unsigned program,
494 int* base_uniform_index) { 526 int* base_uniform_index) {
495 static const char* uniforms[] = { 527 static const char* uniforms[] = {
496 "matrix", 528 "matrix", "quad", "vertexTexTransform",
497 "quad",
498 "vertexTexTransform",
499 }; 529 };
500 int locations[arraysize(uniforms)]; 530 int locations[arraysize(uniforms)];
501 531
502 GetProgramUniformLocations(context, 532 GetProgramUniformLocations(context,
503 program, 533 program,
504 arraysize(uniforms), 534 arraysize(uniforms),
505 uniforms, 535 uniforms,
506 locations, 536 locations,
507 base_uniform_index); 537 base_uniform_index);
508 matrix_location_ = locations[0]; 538 matrix_location_ = locations[0];
509 quad_location_ = locations[1]; 539 quad_location_ = locations[1];
510 vertex_tex_transform_location_ = locations[2]; 540 vertex_tex_transform_location_ = locations[2];
511 } 541 }
512 542
513 std::string VertexShaderTile::GetShaderString() const { 543 std::string VertexShaderTile::GetShaderString() const {
544 // clang-format off
514 return VERTEX_SHADER( 545 return VERTEX_SHADER(
515 attribute TexCoordPrecision vec4 a_position; 546 // clang-format on
516 attribute float a_index; 547 attribute TexCoordPrecision vec4 a_position;
517 uniform mat4 matrix; 548 attribute float a_index;
518 uniform TexCoordPrecision vec2 quad[4]; 549 uniform mat4 matrix;
519 uniform TexCoordPrecision vec4 vertexTexTransform; 550 uniform TexCoordPrecision vec2 quad[4];
520 varying TexCoordPrecision vec2 v_texCoord; 551 uniform TexCoordPrecision vec4 vertexTexTransform;
521 void main() { 552 varying TexCoordPrecision vec2 v_texCoord;
522 vec2 pos = quad[int(a_index)]; // NOLINT 553 void main() {
523 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); 554 vec2 pos = quad[int(a_index)]; // NOLINT
524 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; 555 gl_Position = matrix * vec4(pos, a_position.z, a_position.w);
525 } 556 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy;
557 }
558 // clang-format off
526 ); // NOLINT(whitespace/parens) 559 ); // NOLINT(whitespace/parens)
560 // clang-format on
527 } 561 }
528 562
529 VertexShaderTileAA::VertexShaderTileAA() 563 VertexShaderTileAA::VertexShaderTileAA()
530 : matrix_location_(-1), 564 : matrix_location_(-1),
531 viewport_location_(-1), 565 viewport_location_(-1),
532 quad_location_(-1), 566 quad_location_(-1),
533 edge_location_(-1), 567 edge_location_(-1),
534 vertex_tex_transform_location_(-1) {} 568 vertex_tex_transform_location_(-1) {
569 }
535 570
536 void VertexShaderTileAA::Init(GLES2Interface* context, 571 void VertexShaderTileAA::Init(GLES2Interface* context,
537 unsigned program, 572 unsigned program,
538 int* base_uniform_index) { 573 int* base_uniform_index) {
539 static const char* uniforms[] = { 574 static const char* uniforms[] = {
540 "matrix", 575 "matrix", "viewport", "quad", "edge", "vertexTexTransform",
541 "viewport",
542 "quad",
543 "edge",
544 "vertexTexTransform",
545 }; 576 };
546 int locations[arraysize(uniforms)]; 577 int locations[arraysize(uniforms)];
547 578
548 GetProgramUniformLocations(context, 579 GetProgramUniformLocations(context,
549 program, 580 program,
550 arraysize(uniforms), 581 arraysize(uniforms),
551 uniforms, 582 uniforms,
552 locations, 583 locations,
553 base_uniform_index); 584 base_uniform_index);
554 matrix_location_ = locations[0]; 585 matrix_location_ = locations[0];
555 viewport_location_ = locations[1]; 586 viewport_location_ = locations[1];
556 quad_location_ = locations[2]; 587 quad_location_ = locations[2];
557 edge_location_ = locations[3]; 588 edge_location_ = locations[3];
558 vertex_tex_transform_location_ = locations[4]; 589 vertex_tex_transform_location_ = locations[4];
559 } 590 }
560 591
561 std::string VertexShaderTileAA::GetShaderString() const { 592 std::string VertexShaderTileAA::GetShaderString() const {
593 // clang-format off
562 return VERTEX_SHADER( 594 return VERTEX_SHADER(
563 attribute TexCoordPrecision vec4 a_position; 595 // clang-format on
564 attribute float a_index; 596 attribute TexCoordPrecision vec4 a_position;
565 uniform mat4 matrix; 597 attribute float a_index;
566 uniform vec4 viewport; 598 uniform mat4 matrix;
567 uniform TexCoordPrecision vec2 quad[4]; 599 uniform vec4 viewport;
568 uniform TexCoordPrecision vec3 edge[8]; 600 uniform TexCoordPrecision vec2 quad[4];
569 uniform TexCoordPrecision vec4 vertexTexTransform; 601 uniform TexCoordPrecision vec3 edge[8];
570 varying TexCoordPrecision vec2 v_texCoord; 602 uniform TexCoordPrecision vec4 vertexTexTransform;
571 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 603 varying TexCoordPrecision vec2 v_texCoord;
604 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
572 605
573 void main() { 606 void main() {
574 vec2 pos = quad[int(a_index)]; // NOLINT 607 vec2 pos = quad[int(a_index)]; // NOLINT
575 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); 608 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); 609 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); 610 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0);
578 edge_dist[0] = vec4(dot(edge[0], screen_pos), 611 edge_dist[0] = vec4(dot(edge[0], screen_pos),
579 dot(edge[1], screen_pos), 612 dot(edge[1], screen_pos),
580 dot(edge[2], screen_pos), 613 dot(edge[2], screen_pos),
581 dot(edge[3], screen_pos)) * gl_Position.w; 614 dot(edge[3], screen_pos)) *
582 edge_dist[1] = vec4(dot(edge[4], screen_pos), 615 gl_Position.w;
583 dot(edge[5], screen_pos), 616 edge_dist[1] = vec4(dot(edge[4], screen_pos),
584 dot(edge[6], screen_pos), 617 dot(edge[5], screen_pos),
585 dot(edge[7], screen_pos)) * gl_Position.w; 618 dot(edge[6], screen_pos),
586 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; 619 dot(edge[7], screen_pos)) *
587 } 620 gl_Position.w;
621 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy;
622 }
623 // clang-format off
588 ); // NOLINT(whitespace/parens) 624 ); // NOLINT(whitespace/parens)
625 // clang-format on
589 } 626 }
590 627
591 VertexShaderVideoTransform::VertexShaderVideoTransform() 628 VertexShaderVideoTransform::VertexShaderVideoTransform()
592 : matrix_location_(-1), 629 : matrix_location_(-1), tex_matrix_location_(-1) {
593 tex_matrix_location_(-1) {} 630 }
594 631
595 void VertexShaderVideoTransform::Init(GLES2Interface* context, 632 void VertexShaderVideoTransform::Init(GLES2Interface* context,
596 unsigned program, 633 unsigned program,
597 int* base_uniform_index) { 634 int* base_uniform_index) {
598 static const char* uniforms[] = { 635 static const char* uniforms[] = {
599 "matrix", 636 "matrix", "texMatrix",
600 "texMatrix",
601 }; 637 };
602 int locations[arraysize(uniforms)]; 638 int locations[arraysize(uniforms)];
603 639
604 GetProgramUniformLocations(context, 640 GetProgramUniformLocations(context,
605 program, 641 program,
606 arraysize(uniforms), 642 arraysize(uniforms),
607 uniforms, 643 uniforms,
608 locations, 644 locations,
609 base_uniform_index); 645 base_uniform_index);
610 matrix_location_ = locations[0]; 646 matrix_location_ = locations[0];
611 tex_matrix_location_ = locations[1]; 647 tex_matrix_location_ = locations[1];
612 } 648 }
613 649
614 std::string VertexShaderVideoTransform::GetShaderString() const { 650 std::string VertexShaderVideoTransform::GetShaderString() const {
651 // clang-format off
615 return VERTEX_SHADER( 652 return VERTEX_SHADER(
616 attribute vec4 a_position; 653 // clang-format on
617 attribute TexCoordPrecision vec2 a_texCoord; 654 attribute vec4 a_position;
618 uniform mat4 matrix; 655 attribute TexCoordPrecision vec2 a_texCoord;
619 uniform TexCoordPrecision mat4 texMatrix; 656 uniform mat4 matrix;
620 varying TexCoordPrecision vec2 v_texCoord; 657 uniform TexCoordPrecision mat4 texMatrix;
621 void main() { 658 varying TexCoordPrecision vec2 v_texCoord;
659 void main() {
622 gl_Position = matrix * a_position; 660 gl_Position = matrix * a_position;
623 v_texCoord = 661 v_texCoord =
624 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); 662 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0));
625 } 663 }
664 // clang-format off
626 ); // NOLINT(whitespace/parens) 665 ); // NOLINT(whitespace/parens)
666 // clang-format on
627 } 667 }
628 668
629 FragmentTexAlphaBinding::FragmentTexAlphaBinding() 669 FragmentTexAlphaBinding::FragmentTexAlphaBinding()
630 : sampler_location_(-1), 670 : sampler_location_(-1), alpha_location_(-1) {
631 alpha_location_(-1) {} 671 }
632 672
633 void FragmentTexAlphaBinding::Init(GLES2Interface* context, 673 void FragmentTexAlphaBinding::Init(GLES2Interface* context,
634 unsigned program, 674 unsigned program,
635 int* base_uniform_index) { 675 int* base_uniform_index) {
636 static const char* uniforms[] = { 676 static const char* uniforms[] = {
637 "s_texture", 677 "s_texture", "alpha",
638 "alpha",
639 }; 678 };
640 int locations[arraysize(uniforms)]; 679 int locations[arraysize(uniforms)];
641 680
642 GetProgramUniformLocations(context, 681 GetProgramUniformLocations(context,
643 program, 682 program,
644 arraysize(uniforms), 683 arraysize(uniforms),
645 uniforms, 684 uniforms,
646 locations, 685 locations,
647 base_uniform_index); 686 base_uniform_index);
648 sampler_location_ = locations[0]; 687 sampler_location_ = locations[0];
649 alpha_location_ = locations[1]; 688 alpha_location_ = locations[1];
650 } 689 }
651 690
652 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding() 691 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding()
653 : sampler_location_(-1), 692 : sampler_location_(-1),
654 alpha_location_(-1), 693 alpha_location_(-1),
655 color_matrix_location_(-1), 694 color_matrix_location_(-1),
656 color_offset_location_(-1) {} 695 color_offset_location_(-1) {
696 }
657 697
658 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context, 698 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context,
659 unsigned program, 699 unsigned program,
660 int* base_uniform_index) { 700 int* base_uniform_index) {
661 static const char* uniforms[] = { 701 static const char* uniforms[] = {
662 "s_texture", 702 "s_texture", "alpha", "colorMatrix", "colorOffset",
663 "alpha",
664 "colorMatrix",
665 "colorOffset",
666 }; 703 };
667 int locations[arraysize(uniforms)]; 704 int locations[arraysize(uniforms)];
668 705
669 GetProgramUniformLocations(context, 706 GetProgramUniformLocations(context,
670 program, 707 program,
671 arraysize(uniforms), 708 arraysize(uniforms),
672 uniforms, 709 uniforms,
673 locations, 710 locations,
674 base_uniform_index); 711 base_uniform_index);
675 sampler_location_ = locations[0]; 712 sampler_location_ = locations[0];
676 alpha_location_ = locations[1]; 713 alpha_location_ = locations[1];
677 color_matrix_location_ = locations[2]; 714 color_matrix_location_ = locations[2];
678 color_offset_location_ = locations[3]; 715 color_offset_location_ = locations[3];
679 } 716 }
680 717
681 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() 718 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() : sampler_location_(-1) {
682 : sampler_location_(-1) {} 719 }
683 720
684 void FragmentTexOpaqueBinding::Init(GLES2Interface* context, 721 void FragmentTexOpaqueBinding::Init(GLES2Interface* context,
685 unsigned program, 722 unsigned program,
686 int* base_uniform_index) { 723 int* base_uniform_index) {
687 static const char* uniforms[] = { 724 static const char* uniforms[] = {
688 "s_texture", 725 "s_texture",
689 }; 726 };
690 int locations[arraysize(uniforms)]; 727 int locations[arraysize(uniforms)];
691 728
692 GetProgramUniformLocations(context, 729 GetProgramUniformLocations(context,
693 program, 730 program,
694 arraysize(uniforms), 731 arraysize(uniforms),
695 uniforms, 732 uniforms,
696 locations, 733 locations,
697 base_uniform_index); 734 base_uniform_index);
698 sampler_location_ = locations[0]; 735 sampler_location_ = locations[0];
699 } 736 }
700 737
701 std::string FragmentShaderRGBATexAlpha::GetShaderString( 738 std::string FragmentShaderRGBATexAlpha::GetShaderString(
702 TexCoordPrecision precision, SamplerType sampler) const { 739 TexCoordPrecision precision,
740 SamplerType sampler) const {
741 // clang-format off
703 return FRAGMENT_SHADER( 742 return FRAGMENT_SHADER(
704 precision mediump float; 743 // clang-format on
705 varying TexCoordPrecision vec2 v_texCoord; 744 precision mediump float;
706 uniform SamplerType s_texture; 745 varying TexCoordPrecision vec2 v_texCoord;
707 uniform float alpha; 746 uniform SamplerType s_texture;
708 void main() { 747 uniform float alpha;
709 vec4 texColor = TextureLookup(s_texture, v_texCoord); 748 void main() {
710 gl_FragColor = texColor * alpha; 749 vec4 texColor = TextureLookup(s_texture, v_texCoord);
711 } 750 gl_FragColor = texColor * alpha;
751 }
752 // clang-format off
712 ); // NOLINT(whitespace/parens) 753 ); // NOLINT(whitespace/parens)
754 // clang-format on
713 } 755 }
714 756
715 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( 757 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString(
716 TexCoordPrecision precision, SamplerType sampler) const { 758 TexCoordPrecision precision,
759 SamplerType sampler) const {
760 // clang-format off
717 return FRAGMENT_SHADER( 761 return FRAGMENT_SHADER(
718 precision mediump float; 762 // clang-format on
719 varying TexCoordPrecision vec2 v_texCoord; 763 precision mediump float;
720 uniform SamplerType s_texture; 764 varying TexCoordPrecision vec2 v_texCoord;
721 uniform float alpha; 765 uniform SamplerType s_texture;
722 uniform mat4 colorMatrix; 766 uniform float alpha;
723 uniform vec4 colorOffset; 767 uniform mat4 colorMatrix;
724 void main() { 768 uniform vec4 colorOffset;
725 vec4 texColor = TextureLookup(s_texture, v_texCoord); 769 void main() {
726 float nonZeroAlpha = max(texColor.a, 0.00001); 770 vec4 texColor = TextureLookup(s_texture, v_texCoord);
727 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 771 float nonZeroAlpha = max(texColor.a, 0.00001);
728 texColor = colorMatrix * texColor + colorOffset; 772 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
729 texColor.rgb *= texColor.a; 773 texColor = colorMatrix * texColor + colorOffset;
730 texColor = clamp(texColor, 0.0, 1.0); 774 texColor.rgb *= texColor.a;
731 gl_FragColor = texColor * alpha; 775 texColor = clamp(texColor, 0.0, 1.0);
732 } 776 gl_FragColor = texColor * alpha;
777 }
778 // clang-format off
733 ); // NOLINT(whitespace/parens) 779 ); // NOLINT(whitespace/parens)
780 // clang-format on
734 } 781 }
735 782
736 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( 783 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString(
737 TexCoordPrecision precision, SamplerType sampler) const { 784 TexCoordPrecision precision,
785 SamplerType sampler) const {
786 // clang-format off
738 return FRAGMENT_SHADER( 787 return FRAGMENT_SHADER(
739 precision mediump float; 788 // clang-format on
740 varying TexCoordPrecision vec2 v_texCoord; 789 precision mediump float;
741 varying float v_alpha; 790 varying TexCoordPrecision vec2 v_texCoord;
742 uniform SamplerType s_texture; 791 varying float v_alpha;
743 void main() { 792 uniform SamplerType s_texture;
744 vec4 texColor = TextureLookup(s_texture, v_texCoord); 793 void main() {
745 gl_FragColor = texColor * v_alpha; 794 vec4 texColor = TextureLookup(s_texture, v_texCoord);
746 } 795 gl_FragColor = texColor * v_alpha;
796 }
797 // clang-format off
747 ); // NOLINT(whitespace/parens) 798 ); // NOLINT(whitespace/parens)
799 // clang-format on
748 } 800 }
749 801
750 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( 802 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString(
751 TexCoordPrecision precision, SamplerType sampler) const { 803 TexCoordPrecision precision,
804 SamplerType sampler) const {
805 // clang-format off
752 return FRAGMENT_SHADER( 806 return FRAGMENT_SHADER(
753 precision mediump float; 807 // clang-format on
754 varying TexCoordPrecision vec2 v_texCoord; 808 precision mediump float;
755 varying float v_alpha; 809 varying TexCoordPrecision vec2 v_texCoord;
756 uniform SamplerType s_texture; 810 varying float v_alpha;
757 void main() { 811 uniform SamplerType s_texture;
758 vec4 texColor = TextureLookup(s_texture, v_texCoord); 812 void main() {
759 texColor.rgb *= texColor.a; 813 vec4 texColor = TextureLookup(s_texture, v_texCoord);
760 gl_FragColor = texColor * v_alpha; 814 texColor.rgb *= texColor.a;
761 } 815 gl_FragColor = texColor * v_alpha;
816 }
817 // clang-format off
762 ); // NOLINT(whitespace/parens) 818 ); // NOLINT(whitespace/parens)
819 // clang-format on
763 } 820 }
764 821
765 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() 822 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding()
766 : background_color_location_(-1), 823 : background_color_location_(-1), sampler_location_(-1) {
767 sampler_location_(-1) {
768 } 824 }
769 825
770 void FragmentTexBackgroundBinding::Init(GLES2Interface* context, 826 void FragmentTexBackgroundBinding::Init(GLES2Interface* context,
771 unsigned program, 827 unsigned program,
772 int* base_uniform_index) { 828 int* base_uniform_index) {
773 static const char* uniforms[] = { 829 static const char* uniforms[] = {
774 "s_texture", 830 "s_texture", "background_color",
775 "background_color",
776 }; 831 };
777 int locations[arraysize(uniforms)]; 832 int locations[arraysize(uniforms)];
778 833
779 GetProgramUniformLocations(context, 834 GetProgramUniformLocations(context,
780 program, 835 program,
781 arraysize(uniforms), 836 arraysize(uniforms),
782 uniforms, 837 uniforms,
783 locations, 838 locations,
784 base_uniform_index); 839 base_uniform_index);
785 840
786 sampler_location_ = locations[0]; 841 sampler_location_ = locations[0];
787 DCHECK_NE(sampler_location_, -1); 842 DCHECK_NE(sampler_location_, -1);
788 843
789 background_color_location_ = locations[1]; 844 background_color_location_ = locations[1];
790 DCHECK_NE(background_color_location_, -1); 845 DCHECK_NE(background_color_location_, -1);
791 } 846 }
792 847
793 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( 848 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString(
794 TexCoordPrecision precision, SamplerType sampler) const { 849 TexCoordPrecision precision,
850 SamplerType sampler) const {
851 // clang-format off
795 return FRAGMENT_SHADER( 852 return FRAGMENT_SHADER(
796 precision mediump float; 853 // clang-format on
797 varying TexCoordPrecision vec2 v_texCoord; 854 precision mediump float;
798 varying float v_alpha; 855 varying TexCoordPrecision vec2 v_texCoord;
799 uniform vec4 background_color; 856 varying float v_alpha;
800 uniform SamplerType s_texture; 857 uniform vec4 background_color;
801 void main() { 858 uniform SamplerType s_texture;
802 vec4 texColor = TextureLookup(s_texture, v_texCoord); 859 void main() {
803 texColor += background_color * (1.0 - texColor.a); 860 vec4 texColor = TextureLookup(s_texture, v_texCoord);
804 gl_FragColor = texColor * v_alpha; 861 texColor += background_color * (1.0 - texColor.a);
805 } 862 gl_FragColor = texColor * v_alpha;
863 }
864 // clang-format off
806 ); // NOLINT(whitespace/parens) 865 ); // NOLINT(whitespace/parens)
866 // clang-format on
807 } 867 }
808 868
809 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( 869 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString(
810 TexCoordPrecision precision, SamplerType sampler) const { 870 TexCoordPrecision precision,
871 SamplerType sampler) const {
872 // clang-format off
811 return FRAGMENT_SHADER( 873 return FRAGMENT_SHADER(
812 precision mediump float; 874 // clang-format on
813 varying TexCoordPrecision vec2 v_texCoord; 875 precision mediump float;
814 varying float v_alpha; 876 varying TexCoordPrecision vec2 v_texCoord;
815 uniform vec4 background_color; 877 varying float v_alpha;
816 uniform SamplerType s_texture; 878 uniform vec4 background_color;
817 void main() { 879 uniform SamplerType s_texture;
818 vec4 texColor = TextureLookup(s_texture, v_texCoord); 880 void main() {
819 texColor.rgb *= texColor.a; 881 vec4 texColor = TextureLookup(s_texture, v_texCoord);
820 texColor += background_color * (1.0 - texColor.a); 882 texColor.rgb *= texColor.a;
821 gl_FragColor = texColor * v_alpha; 883 texColor += background_color * (1.0 - texColor.a);
822 } 884 gl_FragColor = texColor * v_alpha;
885 }
886 // clang-format off
823 ); // NOLINT(whitespace/parens) 887 ); // NOLINT(whitespace/parens)
888 // clang-format on
824 } 889 }
825 890
826 std::string FragmentShaderRGBATexOpaque::GetShaderString( 891 std::string FragmentShaderRGBATexOpaque::GetShaderString(
827 TexCoordPrecision precision, SamplerType sampler) const { 892 TexCoordPrecision precision,
893 SamplerType sampler) const {
894 // clang-format off
828 return FRAGMENT_SHADER( 895 return FRAGMENT_SHADER(
829 precision mediump float; 896 // clang-format on
830 varying TexCoordPrecision vec2 v_texCoord; 897 precision mediump float;
831 uniform SamplerType s_texture; 898 varying TexCoordPrecision vec2 v_texCoord;
832 void main() { 899 uniform SamplerType s_texture;
833 vec4 texColor = TextureLookup(s_texture, v_texCoord); 900 void main() {
834 gl_FragColor = vec4(texColor.rgb, 1.0); 901 vec4 texColor = TextureLookup(s_texture, v_texCoord);
835 } 902 gl_FragColor = vec4(texColor.rgb, 1.0);
903 }
904 // clang-format off
836 ); // NOLINT(whitespace/parens) 905 ); // NOLINT(whitespace/parens)
906 // clang-format on
837 } 907 }
838 908
839 std::string FragmentShaderRGBATex::GetShaderString( 909 std::string FragmentShaderRGBATex::GetShaderString(TexCoordPrecision precision,
840 TexCoordPrecision precision, SamplerType sampler) const { 910 SamplerType sampler) const {
911 // clang-format off
841 return FRAGMENT_SHADER( 912 return FRAGMENT_SHADER(
842 precision mediump float; 913 // clang-format on
843 varying TexCoordPrecision vec2 v_texCoord; 914 precision mediump float;
844 uniform SamplerType s_texture; 915 varying TexCoordPrecision vec2 v_texCoord;
845 void main() { 916 uniform SamplerType s_texture;
846 gl_FragColor = TextureLookup(s_texture, v_texCoord); 917 void main() { gl_FragColor = TextureLookup(s_texture, v_texCoord); }
847 } 918 // clang-format off
848 ); // NOLINT(whitespace/parens) 919 ); // NOLINT(whitespace/parens)
920 // clang-format on
849 } 921 }
850 922
851 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( 923 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString(
852 TexCoordPrecision precision, SamplerType sampler) const { 924 TexCoordPrecision precision,
925 SamplerType sampler) const {
926 // clang-format off
853 return FRAGMENT_SHADER( 927 return FRAGMENT_SHADER(
854 precision mediump float; 928 // clang-format on
855 varying TexCoordPrecision vec2 v_texCoord; 929 precision mediump float;
856 uniform SamplerType s_texture; 930 varying TexCoordPrecision vec2 v_texCoord;
857 uniform float alpha; 931 uniform SamplerType s_texture;
858 void main() { 932 uniform float alpha;
933 void main() {
859 vec4 texColor = TextureLookup(s_texture, v_texCoord); 934 vec4 texColor = TextureLookup(s_texture, v_texCoord);
860 gl_FragColor = 935 gl_FragColor =
861 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; 936 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha;
862 } 937 }
938 // clang-format off
863 ); // NOLINT(whitespace/parens) 939 ); // NOLINT(whitespace/parens)
940 // clang-format on
864 } 941 }
865 942
866 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( 943 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString(
867 TexCoordPrecision precision, SamplerType sampler) const { 944 TexCoordPrecision precision,
945 SamplerType sampler) const {
946 // clang-format off
868 return FRAGMENT_SHADER( 947 return FRAGMENT_SHADER(
869 precision mediump float; 948 // clang-format on
870 varying TexCoordPrecision vec2 v_texCoord; 949 precision mediump float;
871 uniform SamplerType s_texture; 950 varying TexCoordPrecision vec2 v_texCoord;
872 void main() { 951 uniform SamplerType s_texture;
873 vec4 texColor = TextureLookup(s_texture, v_texCoord); 952 void main() {
874 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); 953 vec4 texColor = TextureLookup(s_texture, v_texCoord);
875 } 954 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0);
955 }
956 // clang-format off
876 ); // NOLINT(whitespace/parens) 957 ); // NOLINT(whitespace/parens)
958 // clang-format on
877 } 959 }
878 960
879 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() 961 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA()
880 : sampler_location_(-1), 962 : sampler_location_(-1), alpha_location_(-1) {
881 alpha_location_(-1) {} 963 }
882 964
883 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context, 965 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context,
884 unsigned program, 966 unsigned program,
885 int* base_uniform_index) { 967 int* base_uniform_index) {
886 static const char* uniforms[] = { 968 static const char* uniforms[] = {
887 "s_texture", 969 "s_texture", "alpha",
888 "alpha",
889 }; 970 };
890 int locations[arraysize(uniforms)]; 971 int locations[arraysize(uniforms)];
891 972
892 GetProgramUniformLocations(context, 973 GetProgramUniformLocations(context,
893 program, 974 program,
894 arraysize(uniforms), 975 arraysize(uniforms),
895 uniforms, 976 uniforms,
896 locations, 977 locations,
897 base_uniform_index); 978 base_uniform_index);
898 sampler_location_ = locations[0]; 979 sampler_location_ = locations[0];
899 alpha_location_ = locations[1]; 980 alpha_location_ = locations[1];
900 } 981 }
901 982
902 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( 983 std::string FragmentShaderRGBATexAlphaAA::GetShaderString(
903 TexCoordPrecision precision, SamplerType sampler) const { 984 TexCoordPrecision precision,
985 SamplerType sampler) const {
986 // clang-format off
904 return FRAGMENT_SHADER( 987 return FRAGMENT_SHADER(
905 precision mediump float; 988 // clang-format on
906 uniform SamplerType s_texture; 989 precision mediump float;
907 uniform float alpha; 990 uniform SamplerType s_texture;
908 varying TexCoordPrecision vec2 v_texCoord; 991 uniform float alpha;
909 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 992 varying TexCoordPrecision vec2 v_texCoord;
993 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
910 994
911 void main() { 995 void main() {
912 vec4 texColor = TextureLookup(s_texture, v_texCoord); 996 vec4 texColor = TextureLookup(s_texture, v_texCoord);
913 vec4 d4 = min(edge_dist[0], edge_dist[1]); 997 vec4 d4 = min(edge_dist[0], edge_dist[1]);
914 vec2 d2 = min(d4.xz, d4.yw); 998 vec2 d2 = min(d4.xz, d4.yw);
915 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 999 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
916 gl_FragColor = texColor * alpha * aa; 1000 gl_FragColor = texColor * alpha * aa;
917 } 1001 }
1002 // clang-format off
918 ); // NOLINT(whitespace/parens) 1003 ); // NOLINT(whitespace/parens)
1004 // clang-format on
919 } 1005 }
920 1006
921 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() 1007 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding()
922 : sampler_location_(-1), 1008 : sampler_location_(-1),
923 alpha_location_(-1), 1009 alpha_location_(-1),
924 fragment_tex_transform_location_(-1) {} 1010 fragment_tex_transform_location_(-1) {
1011 }
925 1012
926 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, 1013 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context,
927 unsigned program, 1014 unsigned program,
928 int* base_uniform_index) { 1015 int* base_uniform_index) {
929 static const char* uniforms[] = { 1016 static const char* uniforms[] = {
930 "s_texture", 1017 "s_texture", "alpha", "fragmentTexTransform",
931 "alpha",
932 "fragmentTexTransform",
933 }; 1018 };
934 int locations[arraysize(uniforms)]; 1019 int locations[arraysize(uniforms)];
935 1020
936 GetProgramUniformLocations(context, 1021 GetProgramUniformLocations(context,
937 program, 1022 program,
938 arraysize(uniforms), 1023 arraysize(uniforms),
939 uniforms, 1024 uniforms,
940 locations, 1025 locations,
941 base_uniform_index); 1026 base_uniform_index);
942 sampler_location_ = locations[0]; 1027 sampler_location_ = locations[0];
943 alpha_location_ = locations[1]; 1028 alpha_location_ = locations[1];
944 fragment_tex_transform_location_ = locations[2]; 1029 fragment_tex_transform_location_ = locations[2];
945 } 1030 }
946 1031
947 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( 1032 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString(
948 TexCoordPrecision precision, SamplerType sampler) const { 1033 TexCoordPrecision precision,
1034 SamplerType sampler) const {
1035 // clang-format off
949 return FRAGMENT_SHADER( 1036 return FRAGMENT_SHADER(
950 precision mediump float; 1037 // clang-format on
951 uniform SamplerType s_texture; 1038 precision mediump float;
952 uniform float alpha; 1039 uniform SamplerType s_texture;
953 uniform TexCoordPrecision vec4 fragmentTexTransform; 1040 uniform float alpha;
954 varying TexCoordPrecision vec2 v_texCoord; 1041 uniform TexCoordPrecision vec4 fragmentTexTransform;
955 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1042 varying TexCoordPrecision vec2 v_texCoord;
1043 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
956 1044
957 void main() { 1045 void main() {
958 TexCoordPrecision vec2 texCoord = 1046 TexCoordPrecision vec2 texCoord =
959 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + 1047 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw +
960 fragmentTexTransform.xy; 1048 fragmentTexTransform.xy;
961 vec4 texColor = TextureLookup(s_texture, texCoord); 1049 vec4 texColor = TextureLookup(s_texture, texCoord);
962 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1050 vec4 d4 = min(edge_dist[0], edge_dist[1]);
963 vec2 d2 = min(d4.xz, d4.yw); 1051 vec2 d2 = min(d4.xz, d4.yw);
964 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1052 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
965 gl_FragColor = texColor * alpha * aa; 1053 gl_FragColor = texColor * alpha * aa;
966 } 1054 }
1055 // clang-format off
967 ); // NOLINT(whitespace/parens) 1056 ); // NOLINT(whitespace/parens)
1057 // clang-format on
968 } 1058 }
969 1059
970 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( 1060 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString(
971 TexCoordPrecision precision, SamplerType sampler) const { 1061 TexCoordPrecision precision,
1062 SamplerType sampler) const {
1063 // clang-format off
972 return FRAGMENT_SHADER( 1064 return FRAGMENT_SHADER(
973 precision mediump float; 1065 // clang-format on
974 uniform SamplerType s_texture; 1066 precision mediump float;
975 uniform float alpha; 1067 uniform SamplerType s_texture;
976 uniform TexCoordPrecision vec4 fragmentTexTransform; 1068 uniform float alpha;
977 varying TexCoordPrecision vec2 v_texCoord; 1069 uniform TexCoordPrecision vec4 fragmentTexTransform;
978 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1070 varying TexCoordPrecision vec2 v_texCoord;
1071 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
979 1072
980 void main() { 1073 void main() {
981 TexCoordPrecision vec2 texCoord = 1074 TexCoordPrecision vec2 texCoord =
982 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + 1075 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw +
983 fragmentTexTransform.xy; 1076 fragmentTexTransform.xy;
984 vec4 texColor = TextureLookup(s_texture, texCoord); 1077 vec4 texColor = TextureLookup(s_texture, texCoord);
985 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1078 vec4 d4 = min(edge_dist[0], edge_dist[1]);
986 vec2 d2 = min(d4.xz, d4.yw); 1079 vec2 d2 = min(d4.xz, d4.yw);
987 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1080 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) * 1081 gl_FragColor =
989 alpha * aa; 1082 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * aa;
990 } 1083 }
1084 // clang-format off
991 ); // NOLINT(whitespace/parens) 1085 ); // NOLINT(whitespace/parens)
1086 // clang-format on
992 } 1087 }
993 1088
994 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() 1089 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask()
995 : sampler_location_(-1), 1090 : sampler_location_(-1),
996 mask_sampler_location_(-1), 1091 mask_sampler_location_(-1),
997 alpha_location_(-1), 1092 alpha_location_(-1),
998 mask_tex_coord_scale_location_(-1) {} 1093 mask_tex_coord_scale_location_(-1) {
1094 }
999 1095
1000 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context, 1096 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context,
1001 unsigned program, 1097 unsigned program,
1002 int* base_uniform_index) { 1098 int* base_uniform_index) {
1003 static const char* uniforms[] = { 1099 static const char* uniforms[] = {
1004 "s_texture", 1100 "s_texture", "s_mask", "alpha", "maskTexCoordScale", "maskTexCoordOffset",
1005 "s_mask",
1006 "alpha",
1007 "maskTexCoordScale",
1008 "maskTexCoordOffset",
1009 }; 1101 };
1010 int locations[arraysize(uniforms)]; 1102 int locations[arraysize(uniforms)];
1011 1103
1012 GetProgramUniformLocations(context, 1104 GetProgramUniformLocations(context,
1013 program, 1105 program,
1014 arraysize(uniforms), 1106 arraysize(uniforms),
1015 uniforms, 1107 uniforms,
1016 locations, 1108 locations,
1017 base_uniform_index); 1109 base_uniform_index);
1018 sampler_location_ = locations[0]; 1110 sampler_location_ = locations[0];
1019 mask_sampler_location_ = locations[1]; 1111 mask_sampler_location_ = locations[1];
1020 alpha_location_ = locations[2]; 1112 alpha_location_ = locations[2];
1021 mask_tex_coord_scale_location_ = locations[3]; 1113 mask_tex_coord_scale_location_ = locations[3];
1022 mask_tex_coord_offset_location_ = locations[4]; 1114 mask_tex_coord_offset_location_ = locations[4];
1023 } 1115 }
1024 1116
1025 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( 1117 std::string FragmentShaderRGBATexAlphaMask::GetShaderString(
1026 TexCoordPrecision precision, SamplerType sampler) const { 1118 TexCoordPrecision precision,
1119 SamplerType sampler) const {
1120 // clang-format off
1027 return FRAGMENT_SHADER( 1121 return FRAGMENT_SHADER(
1028 precision mediump float; 1122 // clang-format on
1029 varying TexCoordPrecision vec2 v_texCoord; 1123 precision mediump float;
1030 uniform SamplerType s_texture; 1124 varying TexCoordPrecision vec2 v_texCoord;
1031 uniform SamplerType s_mask; 1125 uniform SamplerType s_texture;
1032 uniform TexCoordPrecision vec2 maskTexCoordScale; 1126 uniform SamplerType s_mask;
1033 uniform TexCoordPrecision vec2 maskTexCoordOffset; 1127 uniform TexCoordPrecision vec2 maskTexCoordScale;
1034 uniform float alpha; 1128 uniform TexCoordPrecision vec2 maskTexCoordOffset;
1035 void main() { 1129 uniform float alpha;
1036 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1130 void main() {
1037 TexCoordPrecision vec2 maskTexCoord = 1131 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1038 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1132 TexCoordPrecision vec2 maskTexCoord =
1039 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1133 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1040 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1134 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1041 gl_FragColor = texColor * alpha * maskColor.w; 1135 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1042 } 1136 gl_FragColor = texColor * alpha * maskColor.w;
1137 }
1138 // clang-format off
1043 ); // NOLINT(whitespace/parens) 1139 ); // NOLINT(whitespace/parens)
1140 // clang-format on
1044 } 1141 }
1045 1142
1046 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() 1143 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
1047 : sampler_location_(-1), 1144 : sampler_location_(-1),
1048 mask_sampler_location_(-1), 1145 mask_sampler_location_(-1),
1049 alpha_location_(-1), 1146 alpha_location_(-1),
1050 mask_tex_coord_scale_location_(-1), 1147 mask_tex_coord_scale_location_(-1),
1051 mask_tex_coord_offset_location_(-1) {} 1148 mask_tex_coord_offset_location_(-1) {
1149 }
1052 1150
1053 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context, 1151 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context,
1054 unsigned program, 1152 unsigned program,
1055 int* base_uniform_index) { 1153 int* base_uniform_index) {
1056 static const char* uniforms[] = { 1154 static const char* uniforms[] = {
1057 "s_texture", 1155 "s_texture", "s_mask", "alpha", "maskTexCoordScale", "maskTexCoordOffset",
1058 "s_mask",
1059 "alpha",
1060 "maskTexCoordScale",
1061 "maskTexCoordOffset",
1062 }; 1156 };
1063 int locations[arraysize(uniforms)]; 1157 int locations[arraysize(uniforms)];
1064 1158
1065 GetProgramUniformLocations(context, 1159 GetProgramUniformLocations(context,
1066 program, 1160 program,
1067 arraysize(uniforms), 1161 arraysize(uniforms),
1068 uniforms, 1162 uniforms,
1069 locations, 1163 locations,
1070 base_uniform_index); 1164 base_uniform_index);
1071 sampler_location_ = locations[0]; 1165 sampler_location_ = locations[0];
1072 mask_sampler_location_ = locations[1]; 1166 mask_sampler_location_ = locations[1];
1073 alpha_location_ = locations[2]; 1167 alpha_location_ = locations[2];
1074 mask_tex_coord_scale_location_ = locations[3]; 1168 mask_tex_coord_scale_location_ = locations[3];
1075 mask_tex_coord_offset_location_ = locations[4]; 1169 mask_tex_coord_offset_location_ = locations[4];
1076 } 1170 }
1077 1171
1078 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( 1172 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString(
1079 TexCoordPrecision precision, SamplerType sampler) const { 1173 TexCoordPrecision precision,
1174 SamplerType sampler) const {
1175 // clang-format off
1080 return FRAGMENT_SHADER( 1176 return FRAGMENT_SHADER(
1081 precision mediump float; 1177 // clang-format on
1082 uniform SamplerType s_texture; 1178 precision mediump float;
1083 uniform SamplerType s_mask; 1179 uniform SamplerType s_texture;
1084 uniform TexCoordPrecision vec2 maskTexCoordScale; 1180 uniform SamplerType s_mask;
1085 uniform TexCoordPrecision vec2 maskTexCoordOffset; 1181 uniform TexCoordPrecision vec2 maskTexCoordScale;
1086 uniform float alpha; 1182 uniform TexCoordPrecision vec2 maskTexCoordOffset;
1087 varying TexCoordPrecision vec2 v_texCoord; 1183 uniform float alpha;
1088 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1184 varying TexCoordPrecision vec2 v_texCoord;
1185 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1089 1186
1090 void main() { 1187 void main() {
1091 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1188 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1092 TexCoordPrecision vec2 maskTexCoord = 1189 TexCoordPrecision vec2 maskTexCoord =
1093 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1190 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1094 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1191 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1095 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1192 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1096 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1193 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1097 vec2 d2 = min(d4.xz, d4.yw); 1194 vec2 d2 = min(d4.xz, d4.yw);
1098 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1195 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1099 gl_FragColor = texColor * alpha * maskColor.w * aa; 1196 gl_FragColor = texColor * alpha * maskColor.w * aa;
1100 } 1197 }
1198 // clang-format off
1101 ); // NOLINT(whitespace/parens) 1199 ); // NOLINT(whitespace/parens)
1200 // clang-format on
1102 } 1201 }
1103 1202
1104 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: 1203 FragmentShaderRGBATexAlphaMaskColorMatrixAA::
1105 FragmentShaderRGBATexAlphaMaskColorMatrixAA() 1204 FragmentShaderRGBATexAlphaMaskColorMatrixAA()
1106 : sampler_location_(-1), 1205 : sampler_location_(-1),
1107 mask_sampler_location_(-1), 1206 mask_sampler_location_(-1),
1108 alpha_location_(-1), 1207 alpha_location_(-1),
1109 mask_tex_coord_scale_location_(-1), 1208 mask_tex_coord_scale_location_(-1),
1110 color_matrix_location_(-1), 1209 color_matrix_location_(-1),
1111 color_offset_location_(-1) {} 1210 color_offset_location_(-1) {
1211 }
1112 1212
1113 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init( 1213 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init(
1114 GLES2Interface* context, 1214 GLES2Interface* context,
1115 unsigned program, 1215 unsigned program,
1116 int* base_uniform_index) { 1216 int* base_uniform_index) {
1117 static const char* uniforms[] = { 1217 static const char* uniforms[] = {
1118 "s_texture", 1218 "s_texture",
1119 "s_mask", 1219 "s_mask",
1120 "alpha", 1220 "alpha",
1121 "maskTexCoordScale", 1221 "maskTexCoordScale",
1122 "maskTexCoordOffset", 1222 "maskTexCoordOffset",
1123 "colorMatrix", 1223 "colorMatrix",
1124 "colorOffset", 1224 "colorOffset",
1125 }; 1225 };
1126 int locations[arraysize(uniforms)]; 1226 int locations[arraysize(uniforms)];
1127 1227
1128 GetProgramUniformLocations(context, 1228 GetProgramUniformLocations(context,
1129 program, 1229 program,
1130 arraysize(uniforms), 1230 arraysize(uniforms),
1131 uniforms, 1231 uniforms,
1132 locations, 1232 locations,
1133 base_uniform_index); 1233 base_uniform_index);
1134 sampler_location_ = locations[0]; 1234 sampler_location_ = locations[0];
1135 mask_sampler_location_ = locations[1]; 1235 mask_sampler_location_ = locations[1];
1136 alpha_location_ = locations[2]; 1236 alpha_location_ = locations[2];
1137 mask_tex_coord_scale_location_ = locations[3]; 1237 mask_tex_coord_scale_location_ = locations[3];
1138 mask_tex_coord_offset_location_ = locations[4]; 1238 mask_tex_coord_offset_location_ = locations[4];
1139 color_matrix_location_ = locations[5]; 1239 color_matrix_location_ = locations[5];
1140 color_offset_location_ = locations[6]; 1240 color_offset_location_ = locations[6];
1141 } 1241 }
1142 1242
1143 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( 1243 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString(
1144 TexCoordPrecision precision, SamplerType sampler) const { 1244 TexCoordPrecision precision,
1245 SamplerType sampler) const {
1246 // clang-format off
1145 return FRAGMENT_SHADER( 1247 return FRAGMENT_SHADER(
1146 precision mediump float; 1248 // clang-format on
1147 uniform SamplerType s_texture; 1249 precision mediump float;
1148 uniform SamplerType s_mask; 1250 uniform SamplerType s_texture;
1149 uniform vec2 maskTexCoordScale; 1251 uniform SamplerType s_mask;
1150 uniform vec2 maskTexCoordOffset; 1252 uniform vec2 maskTexCoordScale;
1151 uniform mat4 colorMatrix; 1253 uniform vec2 maskTexCoordOffset;
1152 uniform vec4 colorOffset; 1254 uniform mat4 colorMatrix;
1153 uniform float alpha; 1255 uniform vec4 colorOffset;
1154 varying TexCoordPrecision vec2 v_texCoord; 1256 uniform float alpha;
1155 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1257 varying TexCoordPrecision vec2 v_texCoord;
1258 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1156 1259
1157 void main() { 1260 void main() {
1158 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1261 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1159 float nonZeroAlpha = max(texColor.a, 0.00001); 1262 float nonZeroAlpha = max(texColor.a, 0.00001);
1160 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1263 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1161 texColor = colorMatrix * texColor + colorOffset; 1264 texColor = colorMatrix * texColor + colorOffset;
1162 texColor.rgb *= texColor.a; 1265 texColor.rgb *= texColor.a;
1163 texColor = clamp(texColor, 0.0, 1.0); 1266 texColor = clamp(texColor, 0.0, 1.0);
1164 TexCoordPrecision vec2 maskTexCoord = 1267 TexCoordPrecision vec2 maskTexCoord =
1165 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1268 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1166 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1269 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1167 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1270 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1168 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1271 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1169 vec2 d2 = min(d4.xz, d4.yw); 1272 vec2 d2 = min(d4.xz, d4.yw);
1170 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1273 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1171 gl_FragColor = texColor * alpha * maskColor.w * aa; 1274 gl_FragColor = texColor * alpha * maskColor.w * aa;
1172 } 1275 }
1276 // clang-format off
1173 ); // NOLINT(whitespace/parens) 1277 ); // NOLINT(whitespace/parens)
1278 // clang-format on
1174 } 1279 }
1175 1280
1176 FragmentShaderRGBATexAlphaColorMatrixAA:: 1281 FragmentShaderRGBATexAlphaColorMatrixAA::
1177 FragmentShaderRGBATexAlphaColorMatrixAA() 1282 FragmentShaderRGBATexAlphaColorMatrixAA()
1178 : sampler_location_(-1), 1283 : sampler_location_(-1),
1179 alpha_location_(-1), 1284 alpha_location_(-1),
1180 color_matrix_location_(-1), 1285 color_matrix_location_(-1),
1181 color_offset_location_(-1) {} 1286 color_offset_location_(-1) {
1287 }
1182 1288
1183 void FragmentShaderRGBATexAlphaColorMatrixAA::Init( 1289 void FragmentShaderRGBATexAlphaColorMatrixAA::Init(GLES2Interface* context,
1184 GLES2Interface* context, 1290 unsigned program,
1185 unsigned program, 1291 int* base_uniform_index) {
1186 int* base_uniform_index) {
1187 static const char* uniforms[] = { 1292 static const char* uniforms[] = {
1188 "s_texture", 1293 "s_texture", "alpha", "colorMatrix", "colorOffset",
1189 "alpha",
1190 "colorMatrix",
1191 "colorOffset",
1192 }; 1294 };
1193 int locations[arraysize(uniforms)]; 1295 int locations[arraysize(uniforms)];
1194 1296
1195 GetProgramUniformLocations(context, 1297 GetProgramUniformLocations(context,
1196 program, 1298 program,
1197 arraysize(uniforms), 1299 arraysize(uniforms),
1198 uniforms, 1300 uniforms,
1199 locations, 1301 locations,
1200 base_uniform_index); 1302 base_uniform_index);
1201 sampler_location_ = locations[0]; 1303 sampler_location_ = locations[0];
1202 alpha_location_ = locations[1]; 1304 alpha_location_ = locations[1];
1203 color_matrix_location_ = locations[2]; 1305 color_matrix_location_ = locations[2];
1204 color_offset_location_ = locations[3]; 1306 color_offset_location_ = locations[3];
1205 } 1307 }
1206 1308
1207 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( 1309 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString(
1208 TexCoordPrecision precision, SamplerType sampler) const { 1310 TexCoordPrecision precision,
1311 SamplerType sampler) const {
1312 // clang-format off
1209 return FRAGMENT_SHADER( 1313 return FRAGMENT_SHADER(
1210 precision mediump float; 1314 // clang-format on
1211 uniform SamplerType s_texture; 1315 precision mediump float;
1212 uniform float alpha; 1316 uniform SamplerType s_texture;
1213 uniform mat4 colorMatrix; 1317 uniform float alpha;
1214 uniform vec4 colorOffset; 1318 uniform mat4 colorMatrix;
1215 varying TexCoordPrecision vec2 v_texCoord; 1319 uniform vec4 colorOffset;
1216 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1320 varying TexCoordPrecision vec2 v_texCoord;
1321 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1217 1322
1218 void main() { 1323 void main() {
1219 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1324 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1220 float nonZeroAlpha = max(texColor.a, 0.00001); 1325 float nonZeroAlpha = max(texColor.a, 0.00001);
1221 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1326 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1222 texColor = colorMatrix * texColor + colorOffset; 1327 texColor = colorMatrix * texColor + colorOffset;
1223 texColor.rgb *= texColor.a; 1328 texColor.rgb *= texColor.a;
1224 texColor = clamp(texColor, 0.0, 1.0); 1329 texColor = clamp(texColor, 0.0, 1.0);
1225 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1330 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1226 vec2 d2 = min(d4.xz, d4.yw); 1331 vec2 d2 = min(d4.xz, d4.yw);
1227 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1332 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1228 gl_FragColor = texColor * alpha * aa; 1333 gl_FragColor = texColor * alpha * aa;
1229 } 1334 }
1335 // clang-format off
1230 ); // NOLINT(whitespace/parens) 1336 ); // NOLINT(whitespace/parens)
1337 // clang-format on
1231 } 1338 }
1232 1339
1233 FragmentShaderRGBATexAlphaMaskColorMatrix:: 1340 FragmentShaderRGBATexAlphaMaskColorMatrix::
1234 FragmentShaderRGBATexAlphaMaskColorMatrix() 1341 FragmentShaderRGBATexAlphaMaskColorMatrix()
1235 : sampler_location_(-1), 1342 : sampler_location_(-1),
1236 mask_sampler_location_(-1), 1343 mask_sampler_location_(-1),
1237 alpha_location_(-1), 1344 alpha_location_(-1),
1238 mask_tex_coord_scale_location_(-1) {} 1345 mask_tex_coord_scale_location_(-1) {
1346 }
1239 1347
1240 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init( 1348 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context,
1241 GLES2Interface* context, 1349 unsigned program,
1242 unsigned program, 1350 int* base_uniform_index) {
1243 int* base_uniform_index) {
1244 static const char* uniforms[] = { 1351 static const char* uniforms[] = {
1245 "s_texture", 1352 "s_texture",
1246 "s_mask", 1353 "s_mask",
1247 "alpha", 1354 "alpha",
1248 "maskTexCoordScale", 1355 "maskTexCoordScale",
1249 "maskTexCoordOffset", 1356 "maskTexCoordOffset",
1250 "colorMatrix", 1357 "colorMatrix",
1251 "colorOffset", 1358 "colorOffset",
1252 }; 1359 };
1253 int locations[arraysize(uniforms)]; 1360 int locations[arraysize(uniforms)];
1254 1361
1255 GetProgramUniformLocations(context, 1362 GetProgramUniformLocations(context,
1256 program, 1363 program,
1257 arraysize(uniforms), 1364 arraysize(uniforms),
1258 uniforms, 1365 uniforms,
1259 locations, 1366 locations,
1260 base_uniform_index); 1367 base_uniform_index);
1261 sampler_location_ = locations[0]; 1368 sampler_location_ = locations[0];
1262 mask_sampler_location_ = locations[1]; 1369 mask_sampler_location_ = locations[1];
1263 alpha_location_ = locations[2]; 1370 alpha_location_ = locations[2];
1264 mask_tex_coord_scale_location_ = locations[3]; 1371 mask_tex_coord_scale_location_ = locations[3];
1265 mask_tex_coord_offset_location_ = locations[4]; 1372 mask_tex_coord_offset_location_ = locations[4];
1266 color_matrix_location_ = locations[5]; 1373 color_matrix_location_ = locations[5];
1267 color_offset_location_ = locations[6]; 1374 color_offset_location_ = locations[6];
1268 } 1375 }
1269 1376
1270 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( 1377 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString(
1271 TexCoordPrecision precision, SamplerType sampler) const { 1378 TexCoordPrecision precision,
1379 SamplerType sampler) const {
1380 // clang-format off
1272 return FRAGMENT_SHADER( 1381 return FRAGMENT_SHADER(
1273 precision mediump float; 1382 // clang-format on
1274 varying TexCoordPrecision vec2 v_texCoord; 1383 precision mediump float;
1275 uniform SamplerType s_texture; 1384 varying TexCoordPrecision vec2 v_texCoord;
1276 uniform SamplerType s_mask; 1385 uniform SamplerType s_texture;
1277 uniform vec2 maskTexCoordScale; 1386 uniform SamplerType s_mask;
1278 uniform vec2 maskTexCoordOffset; 1387 uniform vec2 maskTexCoordScale;
1279 uniform mat4 colorMatrix; 1388 uniform vec2 maskTexCoordOffset;
1280 uniform vec4 colorOffset; 1389 uniform mat4 colorMatrix;
1281 uniform float alpha; 1390 uniform vec4 colorOffset;
1282 void main() { 1391 uniform float alpha;
1283 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1392 void main() {
1284 float nonZeroAlpha = max(texColor.a, 0.00001); 1393 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1285 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1394 float nonZeroAlpha = max(texColor.a, 0.00001);
1286 texColor = colorMatrix * texColor + colorOffset; 1395 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1287 texColor.rgb *= texColor.a; 1396 texColor = colorMatrix * texColor + colorOffset;
1288 texColor = clamp(texColor, 0.0, 1.0); 1397 texColor.rgb *= texColor.a;
1289 TexCoordPrecision vec2 maskTexCoord = 1398 texColor = clamp(texColor, 0.0, 1.0);
1290 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1399 TexCoordPrecision vec2 maskTexCoord =
1291 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1400 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1292 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1401 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1293 gl_FragColor = texColor * alpha * maskColor.w; 1402 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1294 } 1403 gl_FragColor = texColor * alpha * maskColor.w;
1404 }
1405 // clang-format off
1295 ); // NOLINT(whitespace/parens) 1406 ); // NOLINT(whitespace/parens)
1407 // clang-format on
1296 } 1408 }
1297 1409
1298 FragmentShaderYUVVideo::FragmentShaderYUVVideo() 1410 FragmentShaderYUVVideo::FragmentShaderYUVVideo()
1299 : y_texture_location_(-1), 1411 : y_texture_location_(-1),
1300 u_texture_location_(-1), 1412 u_texture_location_(-1),
1301 v_texture_location_(-1), 1413 v_texture_location_(-1),
1302 alpha_location_(-1), 1414 alpha_location_(-1),
1303 yuv_matrix_location_(-1), 1415 yuv_matrix_location_(-1),
1304 yuv_adj_location_(-1) {} 1416 yuv_adj_location_(-1) {
1417 }
1305 1418
1306 void FragmentShaderYUVVideo::Init(GLES2Interface* context, 1419 void FragmentShaderYUVVideo::Init(GLES2Interface* context,
1307 unsigned program, 1420 unsigned program,
1308 int* base_uniform_index) { 1421 int* base_uniform_index) {
1309 static const char* uniforms[] = { 1422 static const char* uniforms[] = {
1310 "y_texture", 1423 "y_texture", "u_texture", "v_texture", "alpha", "yuv_matrix", "yuv_adj",
1311 "u_texture",
1312 "v_texture",
1313 "alpha",
1314 "yuv_matrix",
1315 "yuv_adj",
1316 }; 1424 };
1317 int locations[arraysize(uniforms)]; 1425 int locations[arraysize(uniforms)];
1318 1426
1319 GetProgramUniformLocations(context, 1427 GetProgramUniformLocations(context,
1320 program, 1428 program,
1321 arraysize(uniforms), 1429 arraysize(uniforms),
1322 uniforms, 1430 uniforms,
1323 locations, 1431 locations,
1324 base_uniform_index); 1432 base_uniform_index);
1325 y_texture_location_ = locations[0]; 1433 y_texture_location_ = locations[0];
1326 u_texture_location_ = locations[1]; 1434 u_texture_location_ = locations[1];
1327 v_texture_location_ = locations[2]; 1435 v_texture_location_ = locations[2];
1328 alpha_location_ = locations[3]; 1436 alpha_location_ = locations[3];
1329 yuv_matrix_location_ = locations[4]; 1437 yuv_matrix_location_ = locations[4];
1330 yuv_adj_location_ = locations[5]; 1438 yuv_adj_location_ = locations[5];
1331 } 1439 }
1332 1440
1333 std::string FragmentShaderYUVVideo::GetShaderString( 1441 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision,
1334 TexCoordPrecision precision, SamplerType sampler) const { 1442 SamplerType sampler) const {
1443 // clang-format off
1335 return FRAGMENT_SHADER( 1444 return FRAGMENT_SHADER(
1336 precision mediump float; 1445 // clang-format on
1337 precision mediump int; 1446 precision mediump float;
1338 varying TexCoordPrecision vec2 v_texCoord; 1447 precision mediump int;
1339 uniform SamplerType y_texture; 1448 varying TexCoordPrecision vec2 v_texCoord;
1340 uniform SamplerType u_texture; 1449 uniform SamplerType y_texture;
1341 uniform SamplerType v_texture; 1450 uniform SamplerType u_texture;
1342 uniform float alpha; 1451 uniform SamplerType v_texture;
1343 uniform vec3 yuv_adj; 1452 uniform float alpha;
1344 uniform mat3 yuv_matrix; 1453 uniform vec3 yuv_adj;
1345 void main() { 1454 uniform mat3 yuv_matrix;
1346 float y_raw = TextureLookup(y_texture, v_texCoord).x; 1455 void main() {
1347 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; 1456 float y_raw = TextureLookup(y_texture, v_texCoord).x;
1348 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; 1457 float u_unsigned = TextureLookup(u_texture, v_texCoord).x;
1349 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; 1458 float v_unsigned = TextureLookup(v_texture, v_texCoord).x;
1350 vec3 rgb = yuv_matrix * yuv; 1459 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj;
1351 gl_FragColor = vec4(rgb, 1.0) * alpha; 1460 vec3 rgb = yuv_matrix * yuv;
1352 } 1461 gl_FragColor = vec4(rgb, 1.0) * alpha;
1462 }
1463 // clang-format off
1353 ); // NOLINT(whitespace/parens) 1464 ); // NOLINT(whitespace/parens)
1465 // clang-format on
1354 } 1466 }
1355 1467
1356 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() 1468 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo()
1357 : y_texture_location_(-1), 1469 : y_texture_location_(-1),
1358 u_texture_location_(-1), 1470 u_texture_location_(-1),
1359 v_texture_location_(-1), 1471 v_texture_location_(-1),
1360 a_texture_location_(-1), 1472 a_texture_location_(-1),
1361 alpha_location_(-1), 1473 alpha_location_(-1),
1362 yuv_matrix_location_(-1), 1474 yuv_matrix_location_(-1),
1363 yuv_adj_location_(-1) { 1475 yuv_adj_location_(-1) {
(...skipping 22 matching lines...) Expand all
1386 y_texture_location_ = locations[0]; 1498 y_texture_location_ = locations[0];
1387 u_texture_location_ = locations[1]; 1499 u_texture_location_ = locations[1];
1388 v_texture_location_ = locations[2]; 1500 v_texture_location_ = locations[2];
1389 a_texture_location_ = locations[3]; 1501 a_texture_location_ = locations[3];
1390 alpha_location_ = locations[4]; 1502 alpha_location_ = locations[4];
1391 yuv_matrix_location_ = locations[5]; 1503 yuv_matrix_location_ = locations[5];
1392 yuv_adj_location_ = locations[6]; 1504 yuv_adj_location_ = locations[6];
1393 } 1505 }
1394 1506
1395 std::string FragmentShaderYUVAVideo::GetShaderString( 1507 std::string FragmentShaderYUVAVideo::GetShaderString(
1396 TexCoordPrecision precision, SamplerType sampler) const { 1508 TexCoordPrecision precision,
1509 SamplerType sampler) const {
1510 // clang-format off
1397 return FRAGMENT_SHADER( 1511 return FRAGMENT_SHADER(
1398 precision mediump float; 1512 // clang-format on
1399 precision mediump int; 1513 precision mediump float;
1400 varying TexCoordPrecision vec2 v_texCoord; 1514 precision mediump int;
1401 uniform SamplerType y_texture; 1515 varying TexCoordPrecision vec2 v_texCoord;
1402 uniform SamplerType u_texture; 1516 uniform SamplerType y_texture;
1403 uniform SamplerType v_texture; 1517 uniform SamplerType u_texture;
1404 uniform SamplerType a_texture; 1518 uniform SamplerType v_texture;
1405 uniform float alpha; 1519 uniform SamplerType a_texture;
1406 uniform vec3 yuv_adj; 1520 uniform float alpha;
1407 uniform mat3 yuv_matrix; 1521 uniform vec3 yuv_adj;
1408 void main() { 1522 uniform mat3 yuv_matrix;
1409 float y_raw = TextureLookup(y_texture, v_texCoord).x; 1523 void main() {
1410 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; 1524 float y_raw = TextureLookup(y_texture, v_texCoord).x;
1411 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; 1525 float u_unsigned = TextureLookup(u_texture, v_texCoord).x;
1412 float a_raw = TextureLookup(a_texture, v_texCoord).x; 1526 float v_unsigned = TextureLookup(v_texture, v_texCoord).x;
1413 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; 1527 float a_raw = TextureLookup(a_texture, v_texCoord).x;
1414 vec3 rgb = yuv_matrix * yuv; 1528 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj;
1415 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); 1529 vec3 rgb = yuv_matrix * yuv;
1416 } 1530 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw);
1531 }
1532 // clang-format off
1417 ); // NOLINT(whitespace/parens) 1533 ); // NOLINT(whitespace/parens)
1534 // clang-format on
1418 } 1535 }
1419 1536
1420 FragmentShaderColor::FragmentShaderColor() 1537 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) {
1421 : color_location_(-1) {} 1538 }
1422 1539
1423 void FragmentShaderColor::Init(GLES2Interface* context, 1540 void FragmentShaderColor::Init(GLES2Interface* context,
1424 unsigned program, 1541 unsigned program,
1425 int* base_uniform_index) { 1542 int* base_uniform_index) {
1426 static const char* uniforms[] = { 1543 static const char* uniforms[] = {
1427 "color", 1544 "color",
1428 }; 1545 };
1429 int locations[arraysize(uniforms)]; 1546 int locations[arraysize(uniforms)];
1430 1547
1431 GetProgramUniformLocations(context, 1548 GetProgramUniformLocations(context,
1432 program, 1549 program,
1433 arraysize(uniforms), 1550 arraysize(uniforms),
1434 uniforms, 1551 uniforms,
1435 locations, 1552 locations,
1436 base_uniform_index); 1553 base_uniform_index);
1437 color_location_ = locations[0]; 1554 color_location_ = locations[0];
1438 } 1555 }
1439 1556
1440 std::string FragmentShaderColor::GetShaderString( 1557 std::string FragmentShaderColor::GetShaderString(TexCoordPrecision precision,
1441 TexCoordPrecision precision, SamplerType sampler) const { 1558 SamplerType sampler) const {
1559 // clang-format off
1442 return FRAGMENT_SHADER( 1560 return FRAGMENT_SHADER(
1443 precision mediump float; 1561 // clang-format on
1444 uniform vec4 color; 1562 precision mediump float;
1445 void main() { 1563 uniform vec4 color;
1446 gl_FragColor = color; 1564 void main() { gl_FragColor = color; }
1447 } 1565 // clang-format off
1448 ); // NOLINT(whitespace/parens) 1566 ); // NOLINT(whitespace/parens)
1567 // clang-format on
1449 } 1568 }
1450 1569
1451 FragmentShaderColorAA::FragmentShaderColorAA() 1570 FragmentShaderColorAA::FragmentShaderColorAA() : color_location_(-1) {
1452 : color_location_(-1) {} 1571 }
1453 1572
1454 void FragmentShaderColorAA::Init(GLES2Interface* context, 1573 void FragmentShaderColorAA::Init(GLES2Interface* context,
1455 unsigned program, 1574 unsigned program,
1456 int* base_uniform_index) { 1575 int* base_uniform_index) {
1457 static const char* uniforms[] = { 1576 static const char* uniforms[] = {
1458 "color", 1577 "color",
1459 }; 1578 };
1460 int locations[arraysize(uniforms)]; 1579 int locations[arraysize(uniforms)];
1461 1580
1462 GetProgramUniformLocations(context, 1581 GetProgramUniformLocations(context,
1463 program, 1582 program,
1464 arraysize(uniforms), 1583 arraysize(uniforms),
1465 uniforms, 1584 uniforms,
1466 locations, 1585 locations,
1467 base_uniform_index); 1586 base_uniform_index);
1468 color_location_ = locations[0]; 1587 color_location_ = locations[0];
1469 } 1588 }
1470 1589
1471 std::string FragmentShaderColorAA::GetShaderString( 1590 std::string FragmentShaderColorAA::GetShaderString(TexCoordPrecision precision,
1472 TexCoordPrecision precision, SamplerType sampler) const { 1591 SamplerType sampler) const {
1592 // clang-format off
1473 return FRAGMENT_SHADER( 1593 return FRAGMENT_SHADER(
1474 precision mediump float; 1594 // clang-format on
1475 uniform vec4 color; 1595 precision mediump float;
1476 varying vec4 edge_dist[2]; // 8 edge distances. 1596 uniform vec4 color;
1597 varying vec4 edge_dist[2]; // 8 edge distances.
1477 1598
1478 void main() { 1599 void main() {
1479 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1600 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1480 vec2 d2 = min(d4.xz, d4.yw); 1601 vec2 d2 = min(d4.xz, d4.yw);
1481 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1602 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1482 gl_FragColor = color * aa; 1603 gl_FragColor = color * aa;
1483 } 1604 }
1605 // clang-format off
1484 ); // NOLINT(whitespace/parens) 1606 ); // NOLINT(whitespace/parens)
1607 // clang-format on
1485 } 1608 }
1486 1609
1487 FragmentShaderCheckerboard::FragmentShaderCheckerboard() 1610 FragmentShaderCheckerboard::FragmentShaderCheckerboard()
1488 : alpha_location_(-1), 1611 : alpha_location_(-1),
1489 tex_transform_location_(-1), 1612 tex_transform_location_(-1),
1490 frequency_location_(-1) {} 1613 frequency_location_(-1) {
1614 }
1491 1615
1492 void FragmentShaderCheckerboard::Init(GLES2Interface* context, 1616 void FragmentShaderCheckerboard::Init(GLES2Interface* context,
1493 unsigned program, 1617 unsigned program,
1494 int* base_uniform_index) { 1618 int* base_uniform_index) {
1495 static const char* uniforms[] = { 1619 static const char* uniforms[] = {
1496 "alpha", 1620 "alpha", "texTransform", "frequency", "color",
1497 "texTransform",
1498 "frequency",
1499 "color",
1500 }; 1621 };
1501 int locations[arraysize(uniforms)]; 1622 int locations[arraysize(uniforms)];
1502 1623
1503 GetProgramUniformLocations(context, 1624 GetProgramUniformLocations(context,
1504 program, 1625 program,
1505 arraysize(uniforms), 1626 arraysize(uniforms),
1506 uniforms, 1627 uniforms,
1507 locations, 1628 locations,
1508 base_uniform_index); 1629 base_uniform_index);
1509 alpha_location_ = locations[0]; 1630 alpha_location_ = locations[0];
1510 tex_transform_location_ = locations[1]; 1631 tex_transform_location_ = locations[1];
1511 frequency_location_ = locations[2]; 1632 frequency_location_ = locations[2];
1512 color_location_ = locations[3]; 1633 color_location_ = locations[3];
1513 } 1634 }
1514 1635
1515 std::string FragmentShaderCheckerboard::GetShaderString( 1636 std::string FragmentShaderCheckerboard::GetShaderString(
1516 TexCoordPrecision precision, SamplerType sampler) const { 1637 TexCoordPrecision precision,
1638 SamplerType sampler) const {
1517 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" 1639 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide"
1518 // by Munshi, Ginsburg, Shreiner. 1640 // by Munshi, Ginsburg, Shreiner.
1641 // clang-format off
1519 return FRAGMENT_SHADER( 1642 return FRAGMENT_SHADER(
1520 precision mediump float; 1643 // clang-format on
1521 precision mediump int; 1644 precision mediump float;
1522 varying vec2 v_texCoord; 1645 precision mediump int;
1523 uniform float alpha; 1646 varying vec2 v_texCoord;
1524 uniform float frequency; 1647 uniform float alpha;
1525 uniform vec4 texTransform; 1648 uniform float frequency;
1526 uniform vec4 color; 1649 uniform vec4 texTransform;
1527 void main() { 1650 uniform vec4 color;
1528 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); 1651 void main() {
1529 vec4 color2 = color; 1652 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0);
1530 vec2 texCoord = 1653 vec4 color2 = color;
1531 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; 1654 vec2 texCoord =
1532 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 1655 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy;
1533 float picker = abs(coord.x - coord.y); // NOLINT 1656 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
1534 gl_FragColor = mix(color1, color2, picker) * alpha; 1657 float picker = abs(coord.x - coord.y); // NOLINT
1535 } 1658 gl_FragColor = mix(color1, color2, picker) * alpha;
1659 }
1660 // clang-format off
1536 ); // NOLINT(whitespace/parens) 1661 ); // NOLINT(whitespace/parens)
1662 // clang-format on
1537 } 1663 }
1538 1664
1539 } // namespace cc 1665 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698