| 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 <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 "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
| 13 #include "third_party/khronos/GLES2/gl2.h" |
| 12 | 14 |
| 13 #define SHADER0(Src) #Src | 15 #define SHADER0(Src) #Src |
| 14 #define SHADER(Src) SHADER0(Src) | 16 #define VERTEX_SHADER(Src) setVertexTexCoordPrecision(SHADER0(Src)) |
| 17 #define FRAGMENT_SHADER(Src) setFragTexCoordPrecision(precision, SHADER0(Src)) |
| 15 | 18 |
| 16 using WebKit::WebGraphicsContext3D; | 19 using WebKit::WebGraphicsContext3D; |
| 17 | 20 |
| 18 namespace cc { | 21 namespace cc { |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| 21 | 24 |
| 22 static void GetProgramUniformLocations(WebGraphicsContext3D* context, | 25 static void GetProgramUniformLocations(WebGraphicsContext3D* context, |
| 23 unsigned program, | 26 unsigned program, |
| 24 const char** shader_uniforms, | 27 const char** shader_uniforms, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 context->bindUniformLocationCHROMIUM(program, | 38 context->bindUniformLocationCHROMIUM(program, |
| 36 locations[uniform_index], | 39 locations[uniform_index], |
| 37 shader_uniforms[uniform_index]); | 40 shader_uniforms[uniform_index]); |
| 38 } else { | 41 } else { |
| 39 locations[uniform_index] = | 42 locations[uniform_index] = |
| 40 context->getUniformLocation(program, shader_uniforms[uniform_index]); | 43 context->getUniformLocation(program, shader_uniforms[uniform_index]); |
| 41 } | 44 } |
| 42 } | 45 } |
| 43 } | 46 } |
| 44 | 47 |
| 45 } // namespace | 48 static std::string setFragTexCoordPrecision( |
| 49 TexCoordPrecision requestedPrecision, std::string shaderString) |
| 50 { |
| 51 switch (requestedPrecision) { |
| 52 case TexCoordPrecisionHigh: |
| 53 DCHECK_NE(shaderString.find("TexCoordPrecision"), std::string::npos); |
| 54 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" |
| 55 " #define TexCoordPrecision highp\n" |
| 56 "#else\n" |
| 57 " #define TexCoordPrecision mediump\n" |
| 58 "#endif\n" + |
| 59 shaderString; |
| 60 case TexCoordPrecisionMedium: |
| 61 DCHECK_NE(shaderString.find("TexCoordPrecision"), std::string::npos); |
| 62 return "#define TexCoordPrecision mediump\n" + |
| 63 shaderString; |
| 64 case TexCoordPrecisionNA: |
| 65 DCHECK_EQ(shaderString.find("TexCoordPrecision"), std::string::npos); |
| 66 DCHECK_EQ(shaderString.find("texture2D"), std::string::npos); |
| 67 return shaderString; |
| 68 } |
| 69 return shaderString; |
| 70 } |
| 71 |
| 72 static std::string setVertexTexCoordPrecision(const char* shaderString) |
| 73 { |
| 74 // We unconditionally use highp in the vertex shader since |
| 75 // we are unlikely to be vertex shader bound when drawing large quads. |
| 76 // Also, some vertex shaders mutate the texture coordinate in such a |
| 77 // way that the effective precision might be lower than expected. |
| 78 return "#define TexCoordPrecision highp\n" + |
| 79 std::string(shaderString); |
| 80 } |
| 81 |
| 82 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, |
| 83 int highp_threshold_min, |
| 84 int x, int y) { |
| 85 // Initialize range and precision with minimum spec values for when |
| 86 // getShaderPrecisionFormat is a test stub. |
| 87 // TODO: Implement better stubs of getShaderPrecisionFormat everywhere. |
| 88 GLint range[2] = { 14, 14 }; |
| 89 GLint precision = 10; |
| 90 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER, |
| 91 GL_MEDIUM_FLOAT, |
| 92 range, &precision)); |
| 93 int highp_threshold = std::max(1 << precision, highp_threshold_min); |
| 94 if (x > highp_threshold || y > highp_threshold) |
| 95 return TexCoordPrecisionHigh; |
| 96 return TexCoordPrecisionMedium; |
| 97 } |
| 98 |
| 99 } // namespace |
| 100 |
| 101 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, |
| 102 int highp_threshold_min, |
| 103 const gfx::Point& max_coordinate) { |
| 104 return TexCoordPrecisionRequired(context, highp_threshold_min, |
| 105 max_coordinate.x(), max_coordinate.y()); |
| 106 } |
| 107 |
| 108 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, |
| 109 int highp_threshold_min, |
| 110 const gfx::Size& max_size) { |
| 111 return TexCoordPrecisionRequired(context, highp_threshold_min, |
| 112 max_size.width(), max_size.height()); |
| 113 } |
| 46 | 114 |
| 47 VertexShaderPosTex::VertexShaderPosTex() | 115 VertexShaderPosTex::VertexShaderPosTex() |
| 48 : matrix_location_(-1) {} | 116 : matrix_location_(-1) {} |
| 49 | 117 |
| 50 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, | 118 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, |
| 51 unsigned program, | 119 unsigned program, |
| 52 bool using_bind_uniform, | 120 bool using_bind_uniform, |
| 53 int* base_uniform_index) { | 121 int* base_uniform_index) { |
| 54 static const char* shader_uniforms[] = { | 122 static const char* shader_uniforms[] = { |
| 55 "matrix", | 123 "matrix", |
| 56 }; | 124 }; |
| 57 int locations[1]; | 125 int locations[1]; |
| 58 | 126 |
| 59 GetProgramUniformLocations(context, | 127 GetProgramUniformLocations(context, |
| 60 program, | 128 program, |
| 61 shader_uniforms, | 129 shader_uniforms, |
| 62 arraysize(shader_uniforms), | 130 arraysize(shader_uniforms), |
| 63 arraysize(locations), | 131 arraysize(locations), |
| 64 locations, | 132 locations, |
| 65 using_bind_uniform, | 133 using_bind_uniform, |
| 66 base_uniform_index); | 134 base_uniform_index); |
| 67 | 135 |
| 68 matrix_location_ = locations[0]; | 136 matrix_location_ = locations[0]; |
| 69 DCHECK_NE(matrix_location_, -1); | 137 DCHECK_NE(matrix_location_, -1); |
| 70 } | 138 } |
| 71 | 139 |
| 72 std::string VertexShaderPosTex::GetShaderString() const { | 140 std::string VertexShaderPosTex::GetShaderString() const { |
| 73 return SHADER( | 141 return VERTEX_SHADER( |
| 74 attribute vec4 a_position; | 142 attribute vec4 a_position; |
| 75 attribute vec2 a_texCoord; | 143 attribute TexCoordPrecision vec2 a_texCoord; |
| 76 uniform mat4 matrix; | 144 uniform mat4 matrix; |
| 77 varying vec2 v_texCoord; | 145 varying TexCoordPrecision vec2 v_texCoord; |
| 78 void main() { | 146 void main() { |
| 79 gl_Position = matrix * a_position; | 147 gl_Position = matrix * a_position; |
| 80 v_texCoord = a_texCoord; | 148 v_texCoord = a_texCoord; |
| 81 } | 149 } |
| 82 ); // NOLINT(whitespace/parens) | 150 ); // NOLINT(whitespace/parens) |
| 83 } | 151 } |
| 84 | 152 |
| 85 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() | 153 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() |
| 86 : matrix_location_(-1), | 154 : matrix_location_(-1), |
| 87 tex_scale_location_(-1) {} | 155 tex_scale_location_(-1) {} |
| (...skipping 16 matching lines...) Expand all Loading... |
| 104 locations, | 172 locations, |
| 105 using_bind_uniform, | 173 using_bind_uniform, |
| 106 base_uniform_index); | 174 base_uniform_index); |
| 107 | 175 |
| 108 matrix_location_ = locations[0]; | 176 matrix_location_ = locations[0]; |
| 109 tex_scale_location_ = locations[1]; | 177 tex_scale_location_ = locations[1]; |
| 110 DCHECK(matrix_location_ != -1 && tex_scale_location_ != -1); | 178 DCHECK(matrix_location_ != -1 && tex_scale_location_ != -1); |
| 111 } | 179 } |
| 112 | 180 |
| 113 std::string VertexShaderPosTexYUVStretch::GetShaderString() const { | 181 std::string VertexShaderPosTexYUVStretch::GetShaderString() const { |
| 114 return SHADER( | 182 return VERTEX_SHADER( |
| 115 precision mediump float; | 183 precision mediump float; |
| 116 attribute vec4 a_position; | 184 attribute vec4 a_position; |
| 117 attribute vec2 a_texCoord; | 185 attribute TexCoordPrecision vec2 a_texCoord; |
| 118 uniform mat4 matrix; | 186 uniform mat4 matrix; |
| 119 varying vec2 v_texCoord; | 187 varying TexCoordPrecision vec2 v_texCoord; |
| 120 uniform vec2 texScale; | 188 uniform TexCoordPrecision vec2 texScale; |
| 121 void main() { | 189 void main() { |
| 122 gl_Position = matrix * a_position; | 190 gl_Position = matrix * a_position; |
| 123 v_texCoord = a_texCoord * texScale; | 191 v_texCoord = a_texCoord * texScale; |
| 124 } | 192 } |
| 125 ); // NOLINT(whitespace/parens) | 193 ); // NOLINT(whitespace/parens) |
| 126 } | 194 } |
| 127 | 195 |
| 128 VertexShaderPos::VertexShaderPos() | 196 VertexShaderPos::VertexShaderPos() |
| 129 : matrix_location_(-1) {} | 197 : matrix_location_(-1) {} |
| 130 | 198 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 144 arraysize(locations), | 212 arraysize(locations), |
| 145 locations, | 213 locations, |
| 146 using_bind_uniform, | 214 using_bind_uniform, |
| 147 base_uniform_index); | 215 base_uniform_index); |
| 148 | 216 |
| 149 matrix_location_ = locations[0]; | 217 matrix_location_ = locations[0]; |
| 150 DCHECK_NE(matrix_location_, -1); | 218 DCHECK_NE(matrix_location_, -1); |
| 151 } | 219 } |
| 152 | 220 |
| 153 std::string VertexShaderPos::GetShaderString() const { | 221 std::string VertexShaderPos::GetShaderString() const { |
| 154 return SHADER( | 222 return VERTEX_SHADER( |
| 155 attribute vec4 a_position; | 223 attribute vec4 a_position; |
| 156 uniform mat4 matrix; | 224 uniform mat4 matrix; |
| 157 void main() { | 225 void main() { |
| 158 gl_Position = matrix * a_position; | 226 gl_Position = matrix * a_position; |
| 159 } | 227 } |
| 160 ); // NOLINT(whitespace/parens) | 228 ); // NOLINT(whitespace/parens) |
| 161 } | 229 } |
| 162 | 230 |
| 163 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | 231 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
| 164 : matrix_location_(-1), | 232 : matrix_location_(-1), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 186 base_uniform_index); | 254 base_uniform_index); |
| 187 | 255 |
| 188 matrix_location_ = locations[0]; | 256 matrix_location_ = locations[0]; |
| 189 tex_transform_location_ = locations[1]; | 257 tex_transform_location_ = locations[1]; |
| 190 vertex_opacity_location_ = locations[2]; | 258 vertex_opacity_location_ = locations[2]; |
| 191 DCHECK(matrix_location_ != -1 && tex_transform_location_ != -1 && | 259 DCHECK(matrix_location_ != -1 && tex_transform_location_ != -1 && |
| 192 vertex_opacity_location_ != -1); | 260 vertex_opacity_location_ != -1); |
| 193 } | 261 } |
| 194 | 262 |
| 195 std::string VertexShaderPosTexTransform::GetShaderString() const { | 263 std::string VertexShaderPosTexTransform::GetShaderString() const { |
| 196 return SHADER( | 264 return VERTEX_SHADER( |
| 197 attribute vec4 a_position; | 265 attribute vec4 a_position; |
| 198 attribute vec2 a_texCoord; | 266 attribute TexCoordPrecision vec2 a_texCoord; |
| 199 attribute float a_index; | 267 attribute float a_index; |
| 200 uniform mat4 matrix[8]; | 268 uniform mat4 matrix[8]; |
| 201 uniform vec4 texTransform[8]; | 269 uniform TexCoordPrecision vec4 texTransform[8]; |
| 202 uniform float opacity[32]; | 270 uniform float opacity[32]; |
| 203 varying vec2 v_texCoord; | 271 varying TexCoordPrecision vec2 v_texCoord; |
| 204 varying float v_alpha; | 272 varying float v_alpha; |
| 205 void main() { | 273 void main() { |
| 206 gl_Position = matrix[int(a_index * 0.25)] * a_position; // NOLINT | 274 gl_Position = matrix[int(a_index * 0.25)] * a_position; // NOLINT |
| 207 vec4 texTrans = texTransform[int(a_index * 0.25)]; // NOLINT | 275 TexCoordPrecision vec4 texTrans = |
| 276 texTransform[int(a_index * 0.25)]; // NOLINT |
| 208 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 277 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 209 v_alpha = opacity[int(a_index)]; // NOLINT | 278 v_alpha = opacity[int(a_index)]; // NOLINT |
| 210 } | 279 } |
| 211 ); // NOLINT(whitespace/parens) | 280 ); // NOLINT(whitespace/parens) |
| 212 } | 281 } |
| 213 | 282 |
| 214 std::string VertexShaderPosTexTransformFlip::GetShaderString() const { | 283 std::string VertexShaderPosTexTransformFlip::GetShaderString() const { |
| 215 return SHADER( | 284 return VERTEX_SHADER( |
| 216 attribute vec4 a_position; | 285 attribute vec4 a_position; |
| 217 attribute vec2 a_texCoord; | 286 attribute TexCoordPrecision vec2 a_texCoord; |
| 218 attribute float a_index; | 287 attribute float a_index; |
| 219 uniform mat4 matrix[8]; | 288 uniform mat4 matrix[8]; |
| 220 uniform vec4 texTransform[8]; | 289 uniform TexCoordPrecision vec4 texTransform[8]; |
| 221 uniform float opacity[32]; | 290 uniform float opacity[32]; |
| 222 varying vec2 v_texCoord; | 291 varying TexCoordPrecision vec2 v_texCoord; |
| 223 varying float v_alpha; | 292 varying float v_alpha; |
| 224 void main() { | 293 void main() { |
| 225 gl_Position = matrix[int(a_index * 0.25)] * a_position; // NOLINT | 294 gl_Position = matrix[int(a_index * 0.25)] * a_position; // NOLINT |
| 226 vec4 texTrans = texTransform[int(a_index * 0.25)]; // NOLINT | 295 TexCoordPrecision vec4 texTrans = |
| 296 texTransform[int(a_index * 0.25)]; // NOLINT |
| 227 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 297 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 228 v_texCoord.y = 1.0 - v_texCoord.y; | 298 v_texCoord.y = 1.0 - v_texCoord.y; |
| 229 v_alpha = opacity[int(a_index)]; // NOLINT | 299 v_alpha = opacity[int(a_index)]; // NOLINT |
| 230 } | 300 } |
| 231 ); // NOLINT(whitespace/parens) | 301 ); // NOLINT(whitespace/parens) |
| 232 } | 302 } |
| 233 | 303 |
| 234 std::string VertexShaderPosTexIdentity::GetShaderString() const { | 304 std::string VertexShaderPosTexIdentity::GetShaderString() const { |
| 235 return SHADER( | 305 return VERTEX_SHADER( |
| 236 attribute vec4 a_position; | 306 attribute vec4 a_position; |
| 237 varying vec2 v_texCoord; | 307 varying TexCoordPrecision vec2 v_texCoord; |
| 238 void main() { | 308 void main() { |
| 239 gl_Position = a_position; | 309 gl_Position = a_position; |
| 240 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 310 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
| 241 } | 311 } |
| 242 ); // NOLINT(whitespace/parens) | 312 ); // NOLINT(whitespace/parens) |
| 243 } | 313 } |
| 244 | 314 |
| 245 VertexShaderQuad::VertexShaderQuad() | 315 VertexShaderQuad::VertexShaderQuad() |
| 246 : matrix_location_(-1), | 316 : matrix_location_(-1), |
| 247 point_location_(-1), | 317 point_location_(-1), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 269 | 339 |
| 270 matrix_location_ = locations[0]; | 340 matrix_location_ = locations[0]; |
| 271 point_location_ = locations[1]; | 341 point_location_ = locations[1]; |
| 272 tex_scale_location_ = locations[2]; | 342 tex_scale_location_ = locations[2]; |
| 273 DCHECK_NE(matrix_location_, -1); | 343 DCHECK_NE(matrix_location_, -1); |
| 274 DCHECK_NE(point_location_, -1); | 344 DCHECK_NE(point_location_, -1); |
| 275 DCHECK_NE(tex_scale_location_, -1); | 345 DCHECK_NE(tex_scale_location_, -1); |
| 276 } | 346 } |
| 277 | 347 |
| 278 std::string VertexShaderQuad::GetShaderString() const { | 348 std::string VertexShaderQuad::GetShaderString() const { |
| 279 return SHADER( | 349 return VERTEX_SHADER( |
| 280 attribute vec4 a_position; | 350 attribute TexCoordPrecision vec4 a_position; |
| 281 attribute vec2 a_texCoord; | 351 attribute TexCoordPrecision vec2 a_texCoord; |
| 282 uniform mat4 matrix; | 352 uniform mat4 matrix; |
| 283 uniform vec2 point[4]; | 353 uniform TexCoordPrecision vec2 point[4]; |
| 284 uniform vec2 texScale; | 354 uniform TexCoordPrecision vec2 texScale; |
| 285 varying vec2 v_texCoord; | 355 varying TexCoordPrecision vec2 v_texCoord; |
| 286 void main() { | 356 void main() { |
| 287 vec2 complement = abs(a_texCoord - 1.0); | 357 TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0); |
| 288 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 358 TexCoordPrecision vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 289 pos.xy += (complement.x * complement.y) * point[0]; | 359 pos.xy += (complement.x * complement.y) * point[0]; |
| 290 pos.xy += (a_texCoord.x * complement.y) * point[1]; | 360 pos.xy += (a_texCoord.x * complement.y) * point[1]; |
| 291 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | 361 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; |
| 292 pos.xy += (complement.x * a_texCoord.y) * point[3]; | 362 pos.xy += (complement.x * a_texCoord.y) * point[3]; |
| 293 gl_Position = matrix * pos; | 363 gl_Position = matrix * pos; |
| 294 v_texCoord = (pos.xy + vec2(0.5)) * texScale; | 364 v_texCoord = (pos.xy + vec2(0.5)) * texScale; |
| 295 } | 365 } |
| 296 ); // NOLINT(whitespace/parens) | 366 ); // NOLINT(whitespace/parens) |
| 297 } | 367 } |
| 298 | 368 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 322 base_uniform_index); | 392 base_uniform_index); |
| 323 | 393 |
| 324 matrix_location_ = locations[0]; | 394 matrix_location_ = locations[0]; |
| 325 point_location_ = locations[1]; | 395 point_location_ = locations[1]; |
| 326 vertex_tex_transform_location_ = locations[2]; | 396 vertex_tex_transform_location_ = locations[2]; |
| 327 DCHECK(matrix_location_ != -1 && point_location_ != -1 && | 397 DCHECK(matrix_location_ != -1 && point_location_ != -1 && |
| 328 vertex_tex_transform_location_ != -1); | 398 vertex_tex_transform_location_ != -1); |
| 329 } | 399 } |
| 330 | 400 |
| 331 std::string VertexShaderTile::GetShaderString() const { | 401 std::string VertexShaderTile::GetShaderString() const { |
| 332 return SHADER( | 402 return VERTEX_SHADER( |
| 333 attribute vec4 a_position; | 403 attribute TexCoordPrecision vec4 a_position; |
| 334 attribute vec2 a_texCoord; | 404 attribute TexCoordPrecision vec2 a_texCoord; |
| 335 uniform mat4 matrix; | 405 uniform mat4 matrix; |
| 336 uniform vec2 point[4]; | 406 uniform TexCoordPrecision vec2 point[4]; |
| 337 uniform vec4 vertexTexTransform; | 407 uniform TexCoordPrecision vec4 vertexTexTransform; |
| 338 varying vec2 v_texCoord; | 408 varying TexCoordPrecision vec2 v_texCoord; |
| 339 void main() { | 409 void main() { |
| 340 vec2 complement = abs(a_texCoord - 1.0); | 410 TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0); |
| 341 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 411 TexCoordPrecision vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 342 pos.xy += (complement.x * complement.y) * point[0]; | 412 pos.xy += (complement.x * complement.y) * point[0]; |
| 343 pos.xy += (a_texCoord.x * complement.y) * point[1]; | 413 pos.xy += (a_texCoord.x * complement.y) * point[1]; |
| 344 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | 414 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; |
| 345 pos.xy += (complement.x * a_texCoord.y) * point[3]; | 415 pos.xy += (complement.x * a_texCoord.y) * point[3]; |
| 346 gl_Position = matrix * pos; | 416 gl_Position = matrix * pos; |
| 347 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | 417 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; |
| 348 } | 418 } |
| 349 ); // NOLINT(whitespace/parens) | 419 ); // NOLINT(whitespace/parens) |
| 350 } | 420 } |
| 351 | 421 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 371 locations, | 441 locations, |
| 372 using_bind_uniform, | 442 using_bind_uniform, |
| 373 base_uniform_index); | 443 base_uniform_index); |
| 374 | 444 |
| 375 matrix_location_ = locations[0]; | 445 matrix_location_ = locations[0]; |
| 376 tex_matrix_location_ = locations[1]; | 446 tex_matrix_location_ = locations[1]; |
| 377 return matrix_location_ != -1 && tex_matrix_location_ != -1; | 447 return matrix_location_ != -1 && tex_matrix_location_ != -1; |
| 378 } | 448 } |
| 379 | 449 |
| 380 std::string VertexShaderVideoTransform::GetShaderString() const { | 450 std::string VertexShaderVideoTransform::GetShaderString() const { |
| 381 return SHADER( | 451 return VERTEX_SHADER( |
| 382 attribute vec4 a_position; | 452 attribute vec4 a_position; |
| 383 attribute vec2 a_texCoord; | 453 attribute TexCoordPrecision vec2 a_texCoord; |
| 384 uniform mat4 matrix; | 454 uniform mat4 matrix; |
| 385 uniform mat4 texMatrix; | 455 uniform TexCoordPrecision mat4 texMatrix; |
| 386 varying vec2 v_texCoord; | 456 varying TexCoordPrecision vec2 v_texCoord; |
| 387 void main() { | 457 void main() { |
| 388 gl_Position = matrix * a_position; | 458 gl_Position = matrix * a_position; |
| 389 v_texCoord = | 459 v_texCoord = |
| 390 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 460 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
| 391 } | 461 } |
| 392 ); // NOLINT(whitespace/parens) | 462 ); // NOLINT(whitespace/parens) |
| 393 } | 463 } |
| 394 | 464 |
| 395 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | 465 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
| 396 : sampler_location_(-1), | 466 : sampler_location_(-1), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 arraysize(shader_uniforms), | 568 arraysize(shader_uniforms), |
| 499 arraysize(locations), | 569 arraysize(locations), |
| 500 locations, | 570 locations, |
| 501 using_bind_uniform, | 571 using_bind_uniform, |
| 502 base_uniform_index); | 572 base_uniform_index); |
| 503 | 573 |
| 504 sampler_location_ = locations[0]; | 574 sampler_location_ = locations[0]; |
| 505 return sampler_location_ != -1; | 575 return sampler_location_ != -1; |
| 506 } | 576 } |
| 507 | 577 |
| 508 std::string FragmentShaderOESImageExternal::GetShaderString() const { | 578 std::string FragmentShaderOESImageExternal::GetShaderString( |
| 579 TexCoordPrecision precision) const { |
| 509 // Cannot use the SHADER() macro because of the '#' char | 580 // Cannot use the SHADER() macro because of the '#' char |
| 510 return "#extension GL_OES_EGL_image_external : require\n" | 581 return "#extension GL_OES_EGL_image_external : require\n" + |
| 511 SHADER( | 582 FRAGMENT_SHADER( |
| 512 precision mediump float; | 583 precision mediump float; |
| 513 varying vec2 v_texCoord; | 584 varying TexCoordPrecision vec2 v_texCoord; |
| 514 uniform samplerExternalOES s_texture; | 585 uniform samplerExternalOES s_texture; |
| 515 void main() { | 586 void main() { |
| 516 vec4 texColor = texture2D(s_texture, v_texCoord); | 587 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 517 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w); | 588 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w); |
| 518 } | 589 } |
| 519 ); // NOLINT(whitespace/parens) | 590 ); // NOLINT(whitespace/parens) |
| 520 } | 591 } |
| 521 | 592 |
| 522 std::string FragmentShaderRGBATexAlpha::GetShaderString() const { | 593 std::string FragmentShaderRGBATexAlpha::GetShaderString( |
| 523 return SHADER( | 594 TexCoordPrecision precision) const { |
| 595 return FRAGMENT_SHADER( |
| 524 precision mediump float; | 596 precision mediump float; |
| 525 varying vec2 v_texCoord; | 597 varying TexCoordPrecision vec2 v_texCoord; |
| 526 uniform sampler2D s_texture; | 598 uniform sampler2D s_texture; |
| 527 uniform float alpha; | 599 uniform float alpha; |
| 528 void main() { | 600 void main() { |
| 529 vec4 texColor = texture2D(s_texture, v_texCoord); | 601 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 530 gl_FragColor = texColor * alpha; | 602 gl_FragColor = texColor * alpha; |
| 531 } | 603 } |
| 532 ); // NOLINT(whitespace/parens) | 604 ); // NOLINT(whitespace/parens) |
| 533 } | 605 } |
| 534 | 606 |
| 535 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString() const { | 607 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( |
| 536 return SHADER( | 608 TexCoordPrecision precision) const { |
| 609 return FRAGMENT_SHADER( |
| 537 precision mediump float; | 610 precision mediump float; |
| 538 varying vec2 v_texCoord; | 611 varying TexCoordPrecision vec2 v_texCoord; |
| 539 uniform sampler2D s_texture; | 612 uniform sampler2D s_texture; |
| 540 uniform float alpha; | 613 uniform float alpha; |
| 541 uniform mat4 colorMatrix; | 614 uniform mat4 colorMatrix; |
| 542 uniform vec4 colorOffset; | 615 uniform vec4 colorOffset; |
| 543 void main() { | 616 void main() { |
| 544 vec4 texColor = texture2D(s_texture, v_texCoord); | 617 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 545 float nonZeroAlpha = max(texColor.a, 0.00001); | 618 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 546 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 619 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 547 texColor = colorMatrix * texColor + colorOffset; | 620 texColor = colorMatrix * texColor + colorOffset; |
| 548 texColor.rgb *= texColor.a; | 621 texColor.rgb *= texColor.a; |
| 549 texColor = clamp(texColor, 0.0, 1.0); | 622 texColor = clamp(texColor, 0.0, 1.0); |
| 550 gl_FragColor = texColor * alpha; | 623 gl_FragColor = texColor * alpha; |
| 551 } | 624 } |
| 552 ); // NOLINT(whitespace/parens) | 625 ); // NOLINT(whitespace/parens) |
| 553 } | 626 } |
| 554 | 627 |
| 555 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString() const { | 628 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( |
| 556 return SHADER( | 629 TexCoordPrecision precision) const { |
| 630 return FRAGMENT_SHADER( |
| 557 precision mediump float; | 631 precision mediump float; |
| 558 varying vec2 v_texCoord; | 632 varying TexCoordPrecision vec2 v_texCoord; |
| 559 varying float v_alpha; | 633 varying float v_alpha; |
| 560 uniform sampler2D s_texture; | 634 uniform sampler2D s_texture; |
| 561 void main() { | 635 void main() { |
| 562 vec4 texColor = texture2D(s_texture, v_texCoord); | 636 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 563 gl_FragColor = texColor * v_alpha; | 637 gl_FragColor = texColor * v_alpha; |
| 564 } | 638 } |
| 565 ); // NOLINT(whitespace/parens) | 639 ); // NOLINT(whitespace/parens) |
| 566 } | 640 } |
| 567 | 641 |
| 568 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString() const { | 642 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString( |
| 569 return "#extension GL_ARB_texture_rectangle : require\n" | 643 TexCoordPrecision precision) const { |
| 570 SHADER( | 644 return "#extension GL_ARB_texture_rectangle : require\n" + |
| 645 FRAGMENT_SHADER( |
| 571 precision mediump float; | 646 precision mediump float; |
| 572 varying vec2 v_texCoord; | 647 varying TexCoordPrecision vec2 v_texCoord; |
| 573 varying float v_alpha; | 648 varying float v_alpha; |
| 574 uniform sampler2DRect s_texture; | 649 uniform sampler2DRect s_texture; |
| 575 void main() { | 650 void main() { |
| 576 vec4 texColor = texture2DRect(s_texture, v_texCoord); | 651 vec4 texColor = texture2DRect(s_texture, v_texCoord); |
| 577 gl_FragColor = texColor * v_alpha; | 652 gl_FragColor = texColor * v_alpha; |
| 578 } | 653 } |
| 579 ); // NOLINT(whitespace/parens) | 654 ); // NOLINT(whitespace/parens) |
| 580 } | 655 } |
| 581 | 656 |
| 582 std::string FragmentShaderRGBATexOpaque::GetShaderString() const { | 657 std::string FragmentShaderRGBATexOpaque::GetShaderString( |
| 583 return SHADER( | 658 TexCoordPrecision precision) const { |
| 659 return FRAGMENT_SHADER( |
| 584 precision mediump float; | 660 precision mediump float; |
| 585 varying vec2 v_texCoord; | 661 varying TexCoordPrecision vec2 v_texCoord; |
| 586 uniform sampler2D s_texture; | 662 uniform sampler2D s_texture; |
| 587 void main() { | 663 void main() { |
| 588 vec4 texColor = texture2D(s_texture, v_texCoord); | 664 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 589 gl_FragColor = vec4(texColor.rgb, 1.0); | 665 gl_FragColor = vec4(texColor.rgb, 1.0); |
| 590 } | 666 } |
| 591 ); // NOLINT(whitespace/parens) | 667 ); // NOLINT(whitespace/parens) |
| 592 } | 668 } |
| 593 | 669 |
| 594 std::string FragmentShaderRGBATex::GetShaderString() const { | 670 std::string FragmentShaderRGBATex::GetShaderString( |
| 595 return SHADER( | 671 TexCoordPrecision precision) const { |
| 672 return FRAGMENT_SHADER( |
| 596 precision mediump float; | 673 precision mediump float; |
| 597 varying vec2 v_texCoord; | 674 varying TexCoordPrecision vec2 v_texCoord; |
| 598 uniform sampler2D s_texture; | 675 uniform sampler2D s_texture; |
| 599 void main() { | 676 void main() { |
| 600 gl_FragColor = texture2D(s_texture, v_texCoord); | 677 gl_FragColor = texture2D(s_texture, v_texCoord); |
| 601 } | 678 } |
| 602 ); // NOLINT(whitespace/parens) | 679 ); // NOLINT(whitespace/parens) |
| 603 } | 680 } |
| 604 | 681 |
| 605 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString() const { | 682 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( |
| 606 return SHADER( | 683 TexCoordPrecision precision) const { |
| 684 return FRAGMENT_SHADER( |
| 607 precision mediump float; | 685 precision mediump float; |
| 608 varying vec2 v_texCoord; | 686 varying TexCoordPrecision vec2 v_texCoord; |
| 609 uniform sampler2D s_texture; | 687 uniform sampler2D s_texture; |
| 610 uniform float alpha; | 688 uniform float alpha; |
| 611 void main() { | 689 void main() { |
| 612 vec4 texColor = texture2D(s_texture, v_texCoord); | 690 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 613 gl_FragColor = | 691 gl_FragColor = |
| 614 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; | 692 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; |
| 615 } | 693 } |
| 616 ); // NOLINT(whitespace/parens) | 694 ); // NOLINT(whitespace/parens) |
| 617 } | 695 } |
| 618 | 696 |
| 619 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString() const { | 697 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( |
| 620 return SHADER( | 698 TexCoordPrecision precision) const { |
| 699 return FRAGMENT_SHADER( |
| 621 precision mediump float; | 700 precision mediump float; |
| 622 varying vec2 v_texCoord; | 701 varying TexCoordPrecision vec2 v_texCoord; |
| 623 uniform sampler2D s_texture; | 702 uniform sampler2D s_texture; |
| 624 void main() { | 703 void main() { |
| 625 vec4 texColor = texture2D(s_texture, v_texCoord); | 704 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 626 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 705 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
| 627 } | 706 } |
| 628 ); // NOLINT(whitespace/parens) | 707 ); // NOLINT(whitespace/parens) |
| 629 } | 708 } |
| 630 | 709 |
| 631 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 710 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
| 632 : sampler_location_(-1), | 711 : sampler_location_(-1), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 653 using_bind_uniform, | 732 using_bind_uniform, |
| 654 base_uniform_index); | 733 base_uniform_index); |
| 655 | 734 |
| 656 sampler_location_ = locations[0]; | 735 sampler_location_ = locations[0]; |
| 657 alpha_location_ = locations[1]; | 736 alpha_location_ = locations[1]; |
| 658 edge_location_ = locations[2]; | 737 edge_location_ = locations[2]; |
| 659 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && | 738 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && |
| 660 edge_location_ != -1); | 739 edge_location_ != -1); |
| 661 } | 740 } |
| 662 | 741 |
| 663 std::string FragmentShaderRGBATexAlphaAA::GetShaderString() const { | 742 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( |
| 664 return SHADER( | 743 TexCoordPrecision precision) const { |
| 744 return FRAGMENT_SHADER( |
| 665 precision mediump float; | 745 precision mediump float; |
| 666 varying vec2 v_texCoord; | 746 varying TexCoordPrecision vec2 v_texCoord; |
| 667 uniform sampler2D s_texture; | 747 uniform sampler2D s_texture; |
| 668 uniform float alpha; | 748 uniform float alpha; |
| 669 uniform vec3 edge[8]; | 749 uniform vec3 edge[8]; |
| 670 void main() { | 750 void main() { |
| 671 vec4 texColor = texture2D(s_texture, v_texCoord); | 751 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 672 vec3 pos = vec3(gl_FragCoord.xy, 1); | 752 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 673 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 753 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 674 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 754 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 675 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 755 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 676 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 756 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 base_uniform_index); | 792 base_uniform_index); |
| 713 | 793 |
| 714 sampler_location_ = locations[0]; | 794 sampler_location_ = locations[0]; |
| 715 alpha_location_ = locations[1]; | 795 alpha_location_ = locations[1]; |
| 716 fragment_tex_transform_location_ = locations[2]; | 796 fragment_tex_transform_location_ = locations[2]; |
| 717 edge_location_ = locations[3]; | 797 edge_location_ = locations[3]; |
| 718 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && | 798 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && |
| 719 fragment_tex_transform_location_ != -1 && edge_location_ != -1); | 799 fragment_tex_transform_location_ != -1 && edge_location_ != -1); |
| 720 } | 800 } |
| 721 | 801 |
| 722 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString() const { | 802 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( |
| 723 return SHADER( | 803 TexCoordPrecision precision) const { |
| 804 return FRAGMENT_SHADER( |
| 724 precision mediump float; | 805 precision mediump float; |
| 725 varying vec2 v_texCoord; | 806 varying TexCoordPrecision vec2 v_texCoord; |
| 726 uniform sampler2D s_texture; | 807 uniform sampler2D s_texture; |
| 727 uniform float alpha; | 808 uniform float alpha; |
| 728 uniform vec4 fragmentTexTransform; | 809 uniform TexCoordPrecision vec4 fragmentTexTransform; |
| 729 uniform vec3 edge[8]; | 810 uniform vec3 edge[8]; |
| 730 void main() { | 811 void main() { |
| 731 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 812 TexCoordPrecision vec2 texCoord = |
| 813 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
| 732 fragmentTexTransform.xy; | 814 fragmentTexTransform.xy; |
| 733 vec4 texColor = texture2D(s_texture, texCoord); | 815 vec4 texColor = texture2D(s_texture, texCoord); |
| 734 vec3 pos = vec3(gl_FragCoord.xy, 1); | 816 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 735 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 817 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 736 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 818 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 737 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 819 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 738 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 820 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 739 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 821 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 740 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 822 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 741 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 823 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 742 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 824 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| 743 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), | 825 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), |
| 744 min(a4, a6) * min(a5, a7)); | 826 min(a4, a6) * min(a5, a7)); |
| 745 } | 827 } |
| 746 ); // NOLINT(whitespace/parens) | 828 ); // NOLINT(whitespace/parens) |
| 747 } | 829 } |
| 748 | 830 |
| 749 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString() const { | 831 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( |
| 750 return SHADER( | 832 TexCoordPrecision precision) const { |
| 833 return FRAGMENT_SHADER( |
| 751 precision mediump float; | 834 precision mediump float; |
| 752 varying vec2 v_texCoord; | 835 varying TexCoordPrecision vec2 v_texCoord; |
| 753 uniform sampler2D s_texture; | 836 uniform sampler2D s_texture; |
| 754 uniform float alpha; | 837 uniform float alpha; |
| 755 uniform vec4 fragmentTexTransform; | 838 uniform TexCoordPrecision vec4 fragmentTexTransform; |
| 756 uniform vec3 edge[8]; | 839 uniform vec3 edge[8]; |
| 757 void main() { | 840 void main() { |
| 758 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 841 TexCoordPrecision vec2 texCoord = |
| 842 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
| 759 fragmentTexTransform.xy; | 843 fragmentTexTransform.xy; |
| 760 vec4 texColor = texture2D(s_texture, texCoord); | 844 vec4 texColor = texture2D(s_texture, texCoord); |
| 761 vec3 pos = vec3(gl_FragCoord.xy, 1); | 845 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 762 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 846 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 763 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 847 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 764 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 848 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 765 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 849 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 766 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 850 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 767 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 851 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 768 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 852 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 | 887 |
| 804 sampler_location_ = locations[0]; | 888 sampler_location_ = locations[0]; |
| 805 mask_sampler_location_ = locations[1]; | 889 mask_sampler_location_ = locations[1]; |
| 806 alpha_location_ = locations[2]; | 890 alpha_location_ = locations[2]; |
| 807 mask_tex_coord_scale_location_ = locations[3]; | 891 mask_tex_coord_scale_location_ = locations[3]; |
| 808 mask_tex_coord_offset_location_ = locations[4]; | 892 mask_tex_coord_offset_location_ = locations[4]; |
| 809 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && | 893 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && |
| 810 alpha_location_ != -1); | 894 alpha_location_ != -1); |
| 811 } | 895 } |
| 812 | 896 |
| 813 std::string FragmentShaderRGBATexAlphaMask::GetShaderString() const { | 897 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( |
| 814 return SHADER( | 898 TexCoordPrecision precision) const { |
| 899 return FRAGMENT_SHADER( |
| 815 precision mediump float; | 900 precision mediump float; |
| 816 varying vec2 v_texCoord; | 901 varying TexCoordPrecision vec2 v_texCoord; |
| 817 uniform sampler2D s_texture; | 902 uniform sampler2D s_texture; |
| 818 uniform sampler2D s_mask; | 903 uniform sampler2D s_mask; |
| 819 uniform vec2 maskTexCoordScale; | 904 uniform TexCoordPrecision vec2 maskTexCoordScale; |
| 820 uniform vec2 maskTexCoordOffset; | 905 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
| 821 uniform float alpha; | 906 uniform float alpha; |
| 822 void main() { | 907 void main() { |
| 823 vec4 texColor = texture2D(s_texture, v_texCoord); | 908 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 824 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * | 909 TexCoordPrecision vec2 maskTexCoord = |
| 825 maskTexCoordScale.x, | 910 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 826 maskTexCoordOffset.y + v_texCoord.y * | 911 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 827 maskTexCoordScale.y); | |
| 828 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 912 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 829 gl_FragColor = vec4(texColor.x, texColor.y, | 913 gl_FragColor = vec4(texColor.x, texColor.y, |
| 830 texColor.z, texColor.w) * alpha * maskColor.w; | 914 texColor.z, texColor.w) * alpha * maskColor.w; |
| 831 } | 915 } |
| 832 ); // NOLINT(whitespace/parens) | 916 ); // NOLINT(whitespace/parens) |
| 833 } | 917 } |
| 834 | 918 |
| 835 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 919 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
| 836 : sampler_location_(-1), | 920 : sampler_location_(-1), |
| 837 mask_sampler_location_(-1), | 921 mask_sampler_location_(-1), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 865 sampler_location_ = locations[0]; | 949 sampler_location_ = locations[0]; |
| 866 mask_sampler_location_ = locations[1]; | 950 mask_sampler_location_ = locations[1]; |
| 867 alpha_location_ = locations[2]; | 951 alpha_location_ = locations[2]; |
| 868 edge_location_ = locations[3]; | 952 edge_location_ = locations[3]; |
| 869 mask_tex_coord_scale_location_ = locations[4]; | 953 mask_tex_coord_scale_location_ = locations[4]; |
| 870 mask_tex_coord_offset_location_ = locations[5]; | 954 mask_tex_coord_offset_location_ = locations[5]; |
| 871 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && | 955 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && |
| 872 alpha_location_ != -1 && edge_location_ != -1); | 956 alpha_location_ != -1 && edge_location_ != -1); |
| 873 } | 957 } |
| 874 | 958 |
| 875 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString() const { | 959 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( |
| 876 return SHADER( | 960 TexCoordPrecision precision) const { |
| 961 return FRAGMENT_SHADER( |
| 877 precision mediump float; | 962 precision mediump float; |
| 878 varying vec2 v_texCoord; | 963 varying TexCoordPrecision vec2 v_texCoord; |
| 879 uniform sampler2D s_texture; | 964 uniform sampler2D s_texture; |
| 880 uniform sampler2D s_mask; | 965 uniform sampler2D s_mask; |
| 881 uniform vec2 maskTexCoordScale; | 966 uniform TexCoordPrecision vec2 maskTexCoordScale; |
| 882 uniform vec2 maskTexCoordOffset; | 967 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
| 883 uniform float alpha; | 968 uniform float alpha; |
| 884 uniform vec3 edge[8]; | 969 uniform vec3 edge[8]; |
| 885 void main() { | 970 void main() { |
| 886 vec4 texColor = texture2D(s_texture, v_texCoord); | 971 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 887 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * | 972 TexCoordPrecision vec2 maskTexCoord = |
| 888 maskTexCoordScale.x, | 973 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 889 maskTexCoordOffset.y + v_texCoord.y * | 974 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 890 maskTexCoordScale.y); | |
| 891 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 975 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 892 vec3 pos = vec3(gl_FragCoord.xy, 1); | 976 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 893 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 977 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 894 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 978 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 895 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 979 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 896 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 980 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 897 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 981 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 898 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 982 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 899 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 983 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 900 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 984 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 edge_location_ = locations[3]; | 1031 edge_location_ = locations[3]; |
| 948 mask_tex_coord_scale_location_ = locations[4]; | 1032 mask_tex_coord_scale_location_ = locations[4]; |
| 949 mask_tex_coord_offset_location_ = locations[5]; | 1033 mask_tex_coord_offset_location_ = locations[5]; |
| 950 color_matrix_location_ = locations[6]; | 1034 color_matrix_location_ = locations[6]; |
| 951 color_offset_location_ = locations[7]; | 1035 color_offset_location_ = locations[7]; |
| 952 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && | 1036 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && |
| 953 alpha_location_ != -1 && edge_location_ != -1 && | 1037 alpha_location_ != -1 && edge_location_ != -1 && |
| 954 color_matrix_location_ != -1 && color_offset_location_ != -1); | 1038 color_matrix_location_ != -1 && color_offset_location_ != -1); |
| 955 } | 1039 } |
| 956 | 1040 |
| 957 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString() | 1041 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( |
| 958 const { | 1042 TexCoordPrecision precision) const { |
| 959 return SHADER( | 1043 return FRAGMENT_SHADER( |
| 960 precision mediump float; | 1044 precision mediump float; |
| 961 varying vec2 v_texCoord; | 1045 varying TexCoordPrecision vec2 v_texCoord; |
| 962 uniform sampler2D s_texture; | 1046 uniform sampler2D s_texture; |
| 963 uniform sampler2D s_mask; | 1047 uniform sampler2D s_mask; |
| 964 uniform vec2 maskTexCoordScale; | 1048 uniform vec2 maskTexCoordScale; |
| 965 uniform vec2 maskTexCoordOffset; | 1049 uniform vec2 maskTexCoordOffset; |
| 966 uniform mat4 colorMatrix; | 1050 uniform mat4 colorMatrix; |
| 967 uniform vec4 colorOffset; | 1051 uniform vec4 colorOffset; |
| 968 uniform float alpha; | 1052 uniform float alpha; |
| 969 uniform vec3 edge[8]; | 1053 uniform vec3 edge[8]; |
| 970 void main() { | 1054 void main() { |
| 971 vec4 texColor = texture2D(s_texture, v_texCoord); | 1055 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 972 float nonZeroAlpha = max(texColor.a, 0.00001); | 1056 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 973 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1057 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 974 texColor = colorMatrix * texColor + colorOffset; | 1058 texColor = colorMatrix * texColor + colorOffset; |
| 975 texColor.rgb *= texColor.a; | 1059 texColor.rgb *= texColor.a; |
| 976 texColor = clamp(texColor, 0.0, 1.0); | 1060 texColor = clamp(texColor, 0.0, 1.0); |
| 977 vec2 maskTexCoord = | 1061 TexCoordPrecision vec2 maskTexCoord = |
| 978 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1062 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 979 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1063 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 980 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 1064 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 981 vec3 pos = vec3(gl_FragCoord.xy, 1); | 1065 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 982 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 1066 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 983 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 1067 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 984 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 1068 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 985 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 1069 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 986 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 1070 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 987 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 1071 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 sampler_location_ = locations[0]; | 1111 sampler_location_ = locations[0]; |
| 1028 alpha_location_ = locations[1]; | 1112 alpha_location_ = locations[1]; |
| 1029 edge_location_ = locations[2]; | 1113 edge_location_ = locations[2]; |
| 1030 color_matrix_location_ = locations[3]; | 1114 color_matrix_location_ = locations[3]; |
| 1031 color_offset_location_ = locations[4]; | 1115 color_offset_location_ = locations[4]; |
| 1032 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && | 1116 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && |
| 1033 edge_location_ != -1 && color_matrix_location_ != -1 && | 1117 edge_location_ != -1 && color_matrix_location_ != -1 && |
| 1034 color_offset_location_ != -1); | 1118 color_offset_location_ != -1); |
| 1035 } | 1119 } |
| 1036 | 1120 |
| 1037 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString() const { | 1121 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( |
| 1038 return SHADER( | 1122 TexCoordPrecision precision) const { |
| 1123 return FRAGMENT_SHADER( |
| 1039 precision mediump float; | 1124 precision mediump float; |
| 1040 varying vec2 v_texCoord; | 1125 varying TexCoordPrecision vec2 v_texCoord; |
| 1041 uniform sampler2D s_texture; | 1126 uniform sampler2D s_texture; |
| 1042 uniform float alpha; | 1127 uniform float alpha; |
| 1043 uniform mat4 colorMatrix; | 1128 uniform mat4 colorMatrix; |
| 1044 uniform vec4 colorOffset; | 1129 uniform vec4 colorOffset; |
| 1045 uniform vec3 edge[8]; | 1130 uniform vec3 edge[8]; |
| 1046 void main() { | 1131 void main() { |
| 1047 vec4 texColor = texture2D(s_texture, v_texCoord); | 1132 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1048 float nonZeroAlpha = max(texColor.a, 0.00001); | 1133 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1049 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1134 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1050 texColor = colorMatrix * texColor + colorOffset; | 1135 texColor = colorMatrix * texColor + colorOffset; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 alpha_location_ = locations[2]; | 1185 alpha_location_ = locations[2]; |
| 1101 mask_tex_coord_scale_location_ = locations[3]; | 1186 mask_tex_coord_scale_location_ = locations[3]; |
| 1102 mask_tex_coord_offset_location_ = locations[4]; | 1187 mask_tex_coord_offset_location_ = locations[4]; |
| 1103 color_matrix_location_ = locations[5]; | 1188 color_matrix_location_ = locations[5]; |
| 1104 color_offset_location_ = locations[6]; | 1189 color_offset_location_ = locations[6]; |
| 1105 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && | 1190 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && |
| 1106 alpha_location_ != -1 && color_matrix_location_ != -1 && | 1191 alpha_location_ != -1 && color_matrix_location_ != -1 && |
| 1107 color_offset_location_ != -1); | 1192 color_offset_location_ != -1); |
| 1108 } | 1193 } |
| 1109 | 1194 |
| 1110 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString() const { | 1195 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( |
| 1111 return SHADER( | 1196 TexCoordPrecision precision) const { |
| 1197 return FRAGMENT_SHADER( |
| 1112 precision mediump float; | 1198 precision mediump float; |
| 1113 varying vec2 v_texCoord; | 1199 varying TexCoordPrecision vec2 v_texCoord; |
| 1114 uniform sampler2D s_texture; | 1200 uniform sampler2D s_texture; |
| 1115 uniform sampler2D s_mask; | 1201 uniform sampler2D s_mask; |
| 1116 uniform vec2 maskTexCoordScale; | 1202 uniform vec2 maskTexCoordScale; |
| 1117 uniform vec2 maskTexCoordOffset; | 1203 uniform vec2 maskTexCoordOffset; |
| 1118 uniform mat4 colorMatrix; | 1204 uniform mat4 colorMatrix; |
| 1119 uniform vec4 colorOffset; | 1205 uniform vec4 colorOffset; |
| 1120 uniform float alpha; | 1206 uniform float alpha; |
| 1121 void main() { | 1207 void main() { |
| 1122 vec4 texColor = texture2D(s_texture, v_texCoord); | 1208 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1123 float nonZeroAlpha = max(texColor.a, 0.00001); | 1209 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1124 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1210 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1125 texColor = colorMatrix * texColor + colorOffset; | 1211 texColor = colorMatrix * texColor + colorOffset; |
| 1126 texColor.rgb *= texColor.a; | 1212 texColor.rgb *= texColor.a; |
| 1127 texColor = clamp(texColor, 0.0, 1.0); | 1213 texColor = clamp(texColor, 0.0, 1.0); |
| 1128 vec2 maskTexCoord = | 1214 TexCoordPrecision vec2 maskTexCoord = |
| 1129 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1215 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1130 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1216 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1131 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 1217 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 1132 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * | 1218 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * |
| 1133 alpha * maskColor.w; | 1219 alpha * maskColor.w; |
| 1134 } | 1220 } |
| 1135 ); // NOLINT(whitespace/parens) | 1221 ); // NOLINT(whitespace/parens) |
| 1136 } | 1222 } |
| 1137 | 1223 |
| 1138 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 1224 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 v_texture_location_ = locations[2]; | 1257 v_texture_location_ = locations[2]; |
| 1172 alpha_location_ = locations[3]; | 1258 alpha_location_ = locations[3]; |
| 1173 yuv_matrix_location_ = locations[4]; | 1259 yuv_matrix_location_ = locations[4]; |
| 1174 yuv_adj_location_ = locations[5]; | 1260 yuv_adj_location_ = locations[5]; |
| 1175 | 1261 |
| 1176 DCHECK(y_texture_location_ != -1 && u_texture_location_ != -1 && | 1262 DCHECK(y_texture_location_ != -1 && u_texture_location_ != -1 && |
| 1177 v_texture_location_ != -1 && alpha_location_ != -1 && | 1263 v_texture_location_ != -1 && alpha_location_ != -1 && |
| 1178 yuv_matrix_location_ != -1 && yuv_adj_location_ != -1); | 1264 yuv_matrix_location_ != -1 && yuv_adj_location_ != -1); |
| 1179 } | 1265 } |
| 1180 | 1266 |
| 1181 std::string FragmentShaderYUVVideo::GetShaderString() const { | 1267 std::string FragmentShaderYUVVideo::GetShaderString( |
| 1182 return SHADER( | 1268 TexCoordPrecision precision) const { |
| 1269 return FRAGMENT_SHADER( |
| 1183 precision mediump float; | 1270 precision mediump float; |
| 1184 precision mediump int; | 1271 precision mediump int; |
| 1185 varying vec2 v_texCoord; | 1272 varying TexCoordPrecision vec2 v_texCoord; |
| 1186 uniform sampler2D y_texture; | 1273 uniform sampler2D y_texture; |
| 1187 uniform sampler2D u_texture; | 1274 uniform sampler2D u_texture; |
| 1188 uniform sampler2D v_texture; | 1275 uniform sampler2D v_texture; |
| 1189 uniform float alpha; | 1276 uniform float alpha; |
| 1190 uniform vec3 yuv_adj; | 1277 uniform vec3 yuv_adj; |
| 1191 uniform mat3 yuv_matrix; | 1278 uniform mat3 yuv_matrix; |
| 1192 void main() { | 1279 void main() { |
| 1193 float y_raw = texture2D(y_texture, v_texCoord).x; | 1280 float y_raw = texture2D(y_texture, v_texCoord).x; |
| 1194 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 1281 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
| 1195 float v_unsigned = texture2D(v_texture, v_texCoord).x; | 1282 float v_unsigned = texture2D(v_texture, v_texCoord).x; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1218 arraysize(shader_uniforms), | 1305 arraysize(shader_uniforms), |
| 1219 arraysize(locations), | 1306 arraysize(locations), |
| 1220 locations, | 1307 locations, |
| 1221 using_bind_uniform, | 1308 using_bind_uniform, |
| 1222 base_uniform_index); | 1309 base_uniform_index); |
| 1223 | 1310 |
| 1224 color_location_ = locations[0]; | 1311 color_location_ = locations[0]; |
| 1225 DCHECK_NE(color_location_, -1); | 1312 DCHECK_NE(color_location_, -1); |
| 1226 } | 1313 } |
| 1227 | 1314 |
| 1228 std::string FragmentShaderColor::GetShaderString() const { | 1315 std::string FragmentShaderColor::GetShaderString( |
| 1229 return SHADER( | 1316 TexCoordPrecision precision) const { |
| 1317 return FRAGMENT_SHADER( |
| 1230 precision mediump float; | 1318 precision mediump float; |
| 1231 uniform vec4 color; | 1319 uniform vec4 color; |
| 1232 void main() { | 1320 void main() { |
| 1233 gl_FragColor = color; | 1321 gl_FragColor = color; |
| 1234 } | 1322 } |
| 1235 ); // NOLINT(whitespace/parens) | 1323 ); // NOLINT(whitespace/parens) |
| 1236 } | 1324 } |
| 1237 | 1325 |
| 1238 FragmentShaderColorAA::FragmentShaderColorAA() | 1326 FragmentShaderColorAA::FragmentShaderColorAA() |
| 1239 : edge_location_(-1), | 1327 : edge_location_(-1), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1256 arraysize(locations), | 1344 arraysize(locations), |
| 1257 locations, | 1345 locations, |
| 1258 using_bind_uniform, | 1346 using_bind_uniform, |
| 1259 base_uniform_index); | 1347 base_uniform_index); |
| 1260 | 1348 |
| 1261 edge_location_ = locations[0]; | 1349 edge_location_ = locations[0]; |
| 1262 color_location_ = locations[1]; | 1350 color_location_ = locations[1]; |
| 1263 DCHECK(edge_location_ != -1 && color_location_ != -1); | 1351 DCHECK(edge_location_ != -1 && color_location_ != -1); |
| 1264 } | 1352 } |
| 1265 | 1353 |
| 1266 std::string FragmentShaderColorAA::GetShaderString() const { | 1354 std::string FragmentShaderColorAA::GetShaderString( |
| 1267 return SHADER( | 1355 TexCoordPrecision precision) const { |
| 1356 return FRAGMENT_SHADER( |
| 1268 precision mediump float; | 1357 precision mediump float; |
| 1269 uniform vec4 color; | 1358 uniform vec4 color; |
| 1270 uniform vec3 edge[8]; | 1359 uniform vec3 edge[8]; |
| 1271 void main() { | 1360 void main() { |
| 1272 vec3 pos = vec3(gl_FragCoord.xy, 1); | 1361 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 1273 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 1362 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 1274 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 1363 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 1275 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 1364 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 1276 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 1365 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 1277 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 1366 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 base_uniform_index); | 1400 base_uniform_index); |
| 1312 | 1401 |
| 1313 alpha_location_ = locations[0]; | 1402 alpha_location_ = locations[0]; |
| 1314 tex_transform_location_ = locations[1]; | 1403 tex_transform_location_ = locations[1]; |
| 1315 frequency_location_ = locations[2]; | 1404 frequency_location_ = locations[2]; |
| 1316 color_location_ = locations[3]; | 1405 color_location_ = locations[3]; |
| 1317 DCHECK(alpha_location_ != -1 && tex_transform_location_ != -1 && | 1406 DCHECK(alpha_location_ != -1 && tex_transform_location_ != -1 && |
| 1318 frequency_location_ != -1 && color_location_ != -1); | 1407 frequency_location_ != -1 && color_location_ != -1); |
| 1319 } | 1408 } |
| 1320 | 1409 |
| 1321 std::string FragmentShaderCheckerboard::GetShaderString() const { | 1410 std::string FragmentShaderCheckerboard::GetShaderString( |
| 1411 TexCoordPrecision precision) const { |
| 1322 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | 1412 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
| 1323 // by Munshi, Ginsburg, Shreiner. | 1413 // by Munshi, Ginsburg, Shreiner. |
| 1324 return SHADER( | 1414 return FRAGMENT_SHADER( |
| 1325 precision mediump float; | 1415 precision mediump float; |
| 1326 precision mediump int; | 1416 precision mediump int; |
| 1327 varying vec2 v_texCoord; | 1417 varying vec2 v_texCoord; |
| 1328 uniform float alpha; | 1418 uniform float alpha; |
| 1329 uniform float frequency; | 1419 uniform float frequency; |
| 1330 uniform vec4 texTransform; | 1420 uniform vec4 texTransform; |
| 1331 uniform vec4 color; | 1421 uniform vec4 color; |
| 1332 void main() { | 1422 void main() { |
| 1333 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | 1423 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
| 1334 vec4 color2 = color; | 1424 vec4 color2 = color; |
| 1335 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + | 1425 vec2 texCoord = |
| 1336 texTransform.xy; | 1426 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
| 1337 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1427 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 1338 float picker = abs(coord.x - coord.y); | 1428 float picker = abs(coord.x - coord.y); |
| 1339 gl_FragColor = mix(color1, color2, picker) * alpha; | 1429 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 1340 } | 1430 } |
| 1341 ); // NOLINT(whitespace/parens) | 1431 ); // NOLINT(whitespace/parens) |
| 1342 } | 1432 } |
| 1343 | 1433 |
| 1344 } // namespace cc | 1434 } // namespace cc |
| OLD | NEW |