OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/shader.h" | 5 #include "cc/output/shader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 344 |
345 std::string VertexShaderPosTexTransform::GetShaderHead() { | 345 std::string VertexShaderPosTexTransform::GetShaderHead() { |
346 return SHADER0([]() { | 346 return SHADER0([]() { |
347 attribute vec4 a_position; | 347 attribute vec4 a_position; |
348 attribute TexCoordPrecision vec2 a_texCoord; | 348 attribute TexCoordPrecision vec2 a_texCoord; |
349 attribute float a_index; | 349 attribute float a_index; |
350 uniform mat4 matrix[NUM_STATIC_QUADS]; | 350 uniform mat4 matrix[NUM_STATIC_QUADS]; |
351 uniform TexCoordPrecision vec4 texTransform[NUM_STATIC_QUADS]; | 351 uniform TexCoordPrecision vec4 texTransform[NUM_STATIC_QUADS]; |
352 uniform float opacity[NUM_STATIC_QUADS * 4]; | 352 uniform float opacity[NUM_STATIC_QUADS * 4]; |
353 varying TexCoordPrecision vec2 v_texCoord; | 353 varying TexCoordPrecision vec2 v_texCoord; |
354 varying float v_index; | |
355 varying float v_alpha; | 354 varying float v_alpha; |
356 }); | 355 }); |
357 } | 356 } |
358 | 357 |
359 std::string VertexShaderPosTexTransform::GetShaderBody() { | 358 std::string VertexShaderPosTexTransform::GetShaderBody() { |
360 return SHADER0([]() { | 359 return SHADER0([]() { |
361 void main() { | 360 void main() { |
362 int quad_index = int(a_index * 0.25); // NOLINT | 361 int quad_index = int(a_index * 0.25); // NOLINT |
363 v_index = float(quad_index); | |
364 gl_Position = matrix[quad_index] * a_position; | 362 gl_Position = matrix[quad_index] * a_position; |
365 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; | 363 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; |
366 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 364 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
367 v_alpha = opacity[int(a_index)]; // NOLINT | 365 v_alpha = opacity[int(a_index)]; // NOLINT |
368 } | 366 } |
369 }); | 367 }); |
370 } | 368 } |
371 | 369 |
372 void VertexShaderPosTexTransform::FillLocations( | 370 void VertexShaderPosTexTransform::FillLocations( |
373 ShaderLocations* locations) const { | 371 ShaderLocations* locations) const { |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( | 1209 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( |
1212 ShaderLocations* locations) const { | 1210 ShaderLocations* locations) const { |
1213 locations->sampler = sampler_location(); | 1211 locations->sampler = sampler_location(); |
1214 locations->alpha = alpha_location(); | 1212 locations->alpha = alpha_location(); |
1215 locations->color_matrix = color_matrix_location(); | 1213 locations->color_matrix = color_matrix_location(); |
1216 locations->color_offset = color_offset_location(); | 1214 locations->color_offset = color_offset_location(); |
1217 locations->backdrop = backdrop_location(); | 1215 locations->backdrop = backdrop_location(); |
1218 locations->backdrop_rect = backdrop_rect_location(); | 1216 locations->backdrop_rect = backdrop_rect_location(); |
1219 } | 1217 } |
1220 | 1218 |
1221 int FragmentTexQuadBase::background_color_location() const { | 1219 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( |
1222 return -1; | |
1223 } | |
1224 | |
1225 int FragmentTexQuadBase::tex_clamp_rect_location() const { | |
1226 return -1; | |
1227 } | |
1228 | |
1229 void FragmentTexClampBinding::Init(GLES2Interface* context, | |
1230 unsigned program, | |
1231 int* base_uniform_index) { | |
1232 static const char* uniforms[] = { | |
1233 "s_texture", "tex_clamp_rect", | |
1234 }; | |
1235 int locations[arraysize(uniforms)]; | |
1236 | |
1237 GetProgramUniformLocations(context, program, arraysize(uniforms), uniforms, | |
1238 locations, base_uniform_index); | |
1239 | |
1240 sampler_location_ = locations[0]; | |
1241 DCHECK_NE(sampler_location_, -1); | |
1242 | |
1243 tex_clamp_rect_location_ = locations[1]; | |
1244 DCHECK_NE(tex_clamp_rect_location_, -1); | |
1245 } | |
1246 | |
1247 int FragmentTexClampBinding::tex_clamp_rect_location() const { | |
1248 return tex_clamp_rect_location_; | |
1249 } | |
1250 | |
1251 std::string FragmentShaderRGBATexClampVaryingAlpha::GetShaderString( | |
1252 TexCoordPrecision precision, | 1220 TexCoordPrecision precision, |
1253 SamplerType sampler) const { | 1221 SamplerType sampler) const { |
1254 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1222 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1255 } | 1223 } |
1256 | 1224 |
1257 std::string FragmentShaderRGBATexClampVaryingAlpha::GetShaderHead() { | 1225 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderHead() { |
1258 return base::StringPrintf("#define NUM_STATIC_QUADS %d\n", | 1226 return SHADER0([]() { |
1259 StaticGeometryBinding::NUM_QUADS) + | 1227 precision mediump float; |
1260 SHADER0([]() { | 1228 varying TexCoordPrecision vec2 v_texCoord; |
1261 precision mediump float; | 1229 varying float v_alpha; |
1262 varying TexCoordPrecision vec2 v_texCoord; | 1230 uniform SamplerType s_texture; |
1263 varying float v_index; | 1231 }); |
1264 varying float v_alpha; | |
1265 uniform SamplerType s_texture; | |
1266 uniform vec4 tex_clamp_rect[NUM_STATIC_QUADS]; | |
1267 }); | |
1268 } | 1232 } |
1269 | 1233 |
1270 std::string FragmentShaderRGBATexClampVaryingAlpha::GetShaderBody() { | 1234 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderBody() { |
1271 return SHADER0([]() { | 1235 return SHADER0([]() { |
1272 void main() { | 1236 void main() { |
1273 vec2 tex_clamped = max(tex_clamp_rect[int(v_index)].xy, | 1237 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1274 min(tex_clamp_rect[int(v_index)].zw, v_texCoord)); | |
1275 vec4 texColor = TextureLookup(s_texture, tex_clamped); | |
1276 gl_FragColor = texColor * v_alpha; | 1238 gl_FragColor = texColor * v_alpha; |
1277 } | 1239 } |
1278 }); | 1240 }); |
1279 } | 1241 } |
1280 | 1242 |
1281 std::string FragmentShaderRGBATexClampPremultiplyAlpha::GetShaderString( | 1243 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( |
1282 TexCoordPrecision precision, | 1244 TexCoordPrecision precision, |
1283 SamplerType sampler) const { | 1245 SamplerType sampler) const { |
1284 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1246 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1285 } | 1247 } |
1286 | 1248 |
1287 std::string FragmentShaderRGBATexClampPremultiplyAlpha::GetShaderHead() { | 1249 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderHead() { |
1288 return base::StringPrintf("#define NUM_STATIC_QUADS %d\n", | 1250 return SHADER0([]() { |
1289 StaticGeometryBinding::NUM_QUADS) + | 1251 precision mediump float; |
1290 SHADER0([]() { | 1252 varying TexCoordPrecision vec2 v_texCoord; |
1291 precision mediump float; | 1253 varying float v_alpha; |
1292 varying TexCoordPrecision vec2 v_texCoord; | 1254 uniform SamplerType s_texture; |
1293 varying float v_index; | 1255 }); |
1294 varying float v_alpha; | |
1295 uniform SamplerType s_texture; | |
1296 uniform vec4 tex_clamp_rect[NUM_STATIC_QUADS]; | |
1297 }); | |
1298 } | 1256 } |
1299 | 1257 |
1300 std::string FragmentShaderRGBATexClampPremultiplyAlpha::GetShaderBody() { | 1258 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderBody() { |
1301 return SHADER0([]() { | 1259 return SHADER0([]() { |
1302 void main() { | 1260 void main() { |
1303 vec2 tex_clamped = max(tex_clamp_rect[int(v_index)].xy, | 1261 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1304 min(tex_clamp_rect[int(v_index)].zw, v_texCoord)); | |
1305 vec4 texColor = TextureLookup(s_texture, tex_clamped); | |
1306 texColor.rgb *= texColor.a; | 1262 texColor.rgb *= texColor.a; |
1307 gl_FragColor = texColor * v_alpha; | 1263 gl_FragColor = texColor * v_alpha; |
1308 } | 1264 } |
1309 }); | 1265 }); |
1310 } | 1266 } |
1311 | 1267 |
1312 std::string FragmentShaderRGBATexClamp::GetShaderString( | 1268 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() |
1313 TexCoordPrecision precision, | 1269 : background_color_location_(-1), sampler_location_(-1) { |
1314 SamplerType sampler) const { | |
1315 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1316 } | 1270 } |
1317 | 1271 |
1318 std::string FragmentShaderRGBATexClamp::GetShaderHead() { | |
1319 return SHADER0([]() { | |
1320 precision mediump float; | |
1321 varying TexCoordPrecision vec2 v_texCoord; | |
1322 uniform SamplerType s_texture; | |
1323 uniform vec4 tex_clamp_rect; | |
1324 }); | |
1325 } | |
1326 | |
1327 std::string FragmentShaderRGBATexClamp::GetShaderBody() { | |
1328 return SHADER0([]() { | |
1329 void main() { | |
1330 vec2 tex_clamped = | |
1331 max(tex_clamp_rect.xy, min(tex_clamp_rect.zw, v_texCoord)); | |
1332 gl_FragColor = TextureLookup(s_texture, tex_clamped); | |
1333 } | |
1334 }); | |
1335 } | |
1336 | |
1337 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() | |
1338 : background_color_location_(-1) {} | |
1339 | |
1340 void FragmentTexBackgroundBinding::Init(GLES2Interface* context, | 1272 void FragmentTexBackgroundBinding::Init(GLES2Interface* context, |
1341 unsigned program, | 1273 unsigned program, |
1342 int* base_uniform_index) { | 1274 int* base_uniform_index) { |
1343 static const char* uniforms[] = { | 1275 static const char* uniforms[] = { |
1344 "s_texture", "background_color", | 1276 "s_texture", "background_color", |
1345 }; | 1277 }; |
1346 int locations[arraysize(uniforms)]; | 1278 int locations[arraysize(uniforms)]; |
1347 | 1279 |
1348 GetProgramUniformLocations(context, | 1280 GetProgramUniformLocations(context, |
1349 program, | 1281 program, |
1350 arraysize(uniforms), | 1282 arraysize(uniforms), |
1351 uniforms, | 1283 uniforms, |
1352 locations, | 1284 locations, |
1353 base_uniform_index); | 1285 base_uniform_index); |
1354 | 1286 |
1355 sampler_location_ = locations[0]; | 1287 sampler_location_ = locations[0]; |
1356 DCHECK_NE(sampler_location_, -1); | 1288 DCHECK_NE(sampler_location_, -1); |
1357 | 1289 |
1358 background_color_location_ = locations[1]; | 1290 background_color_location_ = locations[1]; |
1359 DCHECK_NE(background_color_location_, -1); | 1291 DCHECK_NE(background_color_location_, -1); |
1360 } | 1292 } |
1361 | 1293 |
1362 int FragmentTexBackgroundBinding::background_color_location() const { | |
1363 return background_color_location_; | |
1364 } | |
1365 | |
1366 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( | 1294 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( |
1367 TexCoordPrecision precision, | 1295 TexCoordPrecision precision, |
1368 SamplerType sampler) const { | 1296 SamplerType sampler) const { |
1369 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1297 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1370 } | 1298 } |
1371 | 1299 |
1372 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderHead() { | 1300 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderHead() { |
1373 return SHADER0([]() { | 1301 return SHADER0([]() { |
1374 precision mediump float; | 1302 precision mediump float; |
1375 varying TexCoordPrecision vec2 v_texCoord; | 1303 varying TexCoordPrecision vec2 v_texCoord; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1432 | 1360 |
1433 std::string FragmentShaderRGBATexOpaque::GetShaderBody() { | 1361 std::string FragmentShaderRGBATexOpaque::GetShaderBody() { |
1434 return SHADER0([]() { | 1362 return SHADER0([]() { |
1435 void main() { | 1363 void main() { |
1436 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1364 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1437 gl_FragColor = vec4(texColor.rgb, 1.0); | 1365 gl_FragColor = vec4(texColor.rgb, 1.0); |
1438 } | 1366 } |
1439 }); | 1367 }); |
1440 } | 1368 } |
1441 | 1369 |
| 1370 std::string FragmentShaderRGBATex::GetShaderString(TexCoordPrecision precision, |
| 1371 SamplerType sampler) const { |
| 1372 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
| 1373 } |
| 1374 |
| 1375 std::string FragmentShaderRGBATex::GetShaderHead() { |
| 1376 return SHADER0([]() { |
| 1377 precision mediump float; |
| 1378 varying TexCoordPrecision vec2 v_texCoord; |
| 1379 uniform SamplerType s_texture; |
| 1380 }); |
| 1381 } |
| 1382 |
| 1383 std::string FragmentShaderRGBATex::GetShaderBody() { |
| 1384 return SHADER0([]() { |
| 1385 void main() { gl_FragColor = TextureLookup(s_texture, v_texCoord); } |
| 1386 }); |
| 1387 } |
| 1388 |
1442 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( | 1389 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( |
1443 TexCoordPrecision precision, | 1390 TexCoordPrecision precision, |
1444 SamplerType sampler) const { | 1391 SamplerType sampler) const { |
1445 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 1392 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1446 } | 1393 } |
1447 | 1394 |
1448 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderHead() { | 1395 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderHead() { |
1449 return SHADER0([]() { | 1396 return SHADER0([]() { |
1450 precision mediump float; | 1397 precision mediump float; |
1451 varying TexCoordPrecision vec2 v_texCoord; | 1398 varying TexCoordPrecision vec2 v_texCoord; |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2305 void main() { | 2252 void main() { |
2306 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 2253 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
2307 vec2 d2 = min(d4.xz, d4.yw); | 2254 vec2 d2 = min(d4.xz, d4.yw); |
2308 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 2255 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
2309 gl_FragColor = color * aa; | 2256 gl_FragColor = color * aa; |
2310 } | 2257 } |
2311 }); | 2258 }); |
2312 } | 2259 } |
2313 | 2260 |
2314 } // namespace cc | 2261 } // namespace cc |
OLD | NEW |