Chromium Code Reviews| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/output/gl_renderer.h" // For the GLC() macro. | |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" |
| 11 #include "third_party/khronos/GLES2/gl2.h" | |
| 10 | 12 |
| 11 #define SHADER0(Src) #Src | 13 #define SHADER0(Src) #Src |
| 12 #define SHADER(Src) SHADER0(Src) | 14 #define VERTEX_SHADER(Src) setVertexTexCoordPrecision(SHADER0(Src)) |
| 15 #define FRAGMENT_SHADER(Src) setFragTexCoordPrecision(precision, SHADER0(Src)) | |
| 13 | 16 |
| 14 using WebKit::WebGraphicsContext3D; | 17 using WebKit::WebGraphicsContext3D; |
| 15 | 18 |
| 16 namespace cc { | 19 namespace cc { |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 static void GetProgramUniformLocations(WebGraphicsContext3D* context, | 23 static void GetProgramUniformLocations(WebGraphicsContext3D* context, |
| 21 unsigned program, | 24 unsigned program, |
| 22 const char** shader_uniforms, | 25 const char** shader_uniforms, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 33 context->bindUniformLocationCHROMIUM(program, | 36 context->bindUniformLocationCHROMIUM(program, |
| 34 locations[uniform_index], | 37 locations[uniform_index], |
| 35 shader_uniforms[uniform_index]); | 38 shader_uniforms[uniform_index]); |
| 36 } else { | 39 } else { |
| 37 locations[uniform_index] = | 40 locations[uniform_index] = |
| 38 context->getUniformLocation(program, shader_uniforms[uniform_index]); | 41 context->getUniformLocation(program, shader_uniforms[uniform_index]); |
| 39 } | 42 } |
| 40 } | 43 } |
| 41 } | 44 } |
| 42 | 45 |
| 46 static std::string setFragTexCoordPrecision( | |
| 47 TexCoordPrecision requestedPrecision, std::string shaderString) | |
| 48 { | |
| 49 switch (requestedPrecision) { | |
| 50 case TexCoordPrecisionHigh: | |
| 51 DCHECK_NE(shaderString.find("TexCoordPrecision"), std::string::npos); | |
| 52 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" | |
| 53 " #define TexCoordPrecision highp\n" | |
| 54 "#else\n" | |
| 55 " #define TexCoordPrecision mediump\n" | |
| 56 "#endif\n" + | |
| 57 shaderString; | |
| 58 case TexCoordPrecisionMedium: | |
| 59 DCHECK_NE(shaderString.find("TexCoordPrecision"), std::string::npos); | |
| 60 return "#define TexCoordPrecision mediump\n" + | |
| 61 shaderString; | |
| 62 case TexCoordPrecisionNA: | |
| 63 DCHECK_EQ(shaderString.find("TexCoordPrecision"), std::string::npos); | |
| 64 return shaderString; | |
| 65 default: | |
| 66 NOTREACHED(); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 static std::string setVertexTexCoordPrecision(const char* shaderString) | |
| 71 { | |
| 72 // We unconditionally use highp in the vertex shader since | |
| 73 // we are unlikely to be vertex shader bound when drawing large quads. | |
| 74 // Also, some vertex shaders mutate the texture coordinate in such a | |
| 75 // way that the effective precision might be lower than expected. | |
| 76 return "#define TexCoordPrecision highp\n" + | |
| 77 std::string(shaderString); | |
| 78 } | |
| 79 | |
| 43 } | 80 } |
| 44 | 81 |
| 82 int TexCoordHighpThreshold(WebKit::WebGraphicsContext3D* context) { | |
| 83 GLint range[2]; | |
| 84 GLint precision = 0; | |
| 85 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER, | |
| 86 GL_MEDIUM_FLOAT, | |
| 87 range, &precision)); | |
| 88 #if defined(OS_ANDROID) | |
|
aelias_OOO_until_Jul13
2013/03/24 00:52:02
Fine functionality-wise, but there shouldn't be an
danakj
2013/03/24 17:39:58
And then running the shader compilation unit tests
| |
| 89 // We bias the threshold on Android to be more conservative, so as to avoid | |
| 90 // performance regressions. There has been obvious corruption with 2560 pixel | |
| 91 // displays, but none has been reported with lower resolution displays. | |
| 92 return std::max(1 << precision, 2048); | |
| 93 #else | |
| 94 return 1 << precision; | |
| 95 #endif | |
| 96 } | |
| 97 | |
| 98 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, | |
| 99 const gfx::Point& max_coordinate) { | |
| 100 int highp_threshold = TexCoordHighpThreshold(context); | |
| 101 if (max_coordinate.x() > highp_threshold || | |
| 102 max_coordinate.y() > highp_threshold) | |
| 103 return TexCoordPrecisionHigh; | |
| 104 return TexCoordPrecisionMedium; | |
| 105 } | |
| 106 | |
| 45 VertexShaderPosTex::VertexShaderPosTex() | 107 VertexShaderPosTex::VertexShaderPosTex() |
| 46 : matrix_location_(-1) { } | 108 : matrix_location_(-1) { } |
| 47 | 109 |
| 48 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, | 110 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, |
| 49 unsigned program, | 111 unsigned program, |
| 50 bool using_bind_uniform, | 112 bool using_bind_uniform, |
| 51 int* base_uniform_index) { | 113 int* base_uniform_index) { |
| 52 static const char* shader_uniforms[] = { | 114 static const char* shader_uniforms[] = { |
| 53 "matrix", | 115 "matrix", |
| 54 }; | 116 }; |
| 55 int locations[1]; | 117 int locations[1]; |
| 56 | 118 |
| 57 GetProgramUniformLocations(context, | 119 GetProgramUniformLocations(context, |
| 58 program, | 120 program, |
| 59 shader_uniforms, | 121 shader_uniforms, |
| 60 arraysize(shader_uniforms), | 122 arraysize(shader_uniforms), |
| 61 arraysize(locations), | 123 arraysize(locations), |
| 62 locations, | 124 locations, |
| 63 using_bind_uniform, | 125 using_bind_uniform, |
| 64 base_uniform_index); | 126 base_uniform_index); |
| 65 | 127 |
| 66 matrix_location_ = locations[0]; | 128 matrix_location_ = locations[0]; |
| 67 DCHECK(matrix_location_ != -1); | 129 DCHECK(matrix_location_ != -1); |
| 68 } | 130 } |
| 69 | 131 |
| 70 std::string VertexShaderPosTex::GetShaderString() const { | 132 std::string VertexShaderPosTex::GetShaderString() const { |
| 71 return SHADER( | 133 return VERTEX_SHADER( |
| 72 attribute vec4 a_position; | 134 attribute vec4 a_position; |
| 73 attribute vec2 a_texCoord; | 135 attribute TexCoordPrecision vec2 a_texCoord; |
| 74 uniform mat4 matrix; | 136 uniform mat4 matrix; |
| 75 varying vec2 v_texCoord; | 137 varying TexCoordPrecision vec2 v_texCoord; |
| 76 void main() { | 138 void main() { |
| 77 gl_Position = matrix * a_position; | 139 gl_Position = matrix * a_position; |
| 78 v_texCoord = a_texCoord; | 140 v_texCoord = a_texCoord; |
| 79 } | 141 } |
| 80 ); | 142 ); |
| 81 } | 143 } |
| 82 | 144 |
| 83 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() | 145 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() |
| 84 : matrix_location_(-1), | 146 : matrix_location_(-1), |
| 85 tex_scale_location_(-1) { } | 147 tex_scale_location_(-1) { } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 102 locations, | 164 locations, |
| 103 using_bind_uniform, | 165 using_bind_uniform, |
| 104 base_uniform_index); | 166 base_uniform_index); |
| 105 | 167 |
| 106 matrix_location_ = locations[0]; | 168 matrix_location_ = locations[0]; |
| 107 tex_scale_location_ = locations[1]; | 169 tex_scale_location_ = locations[1]; |
| 108 DCHECK(matrix_location_ != -1 && tex_scale_location_ != -1); | 170 DCHECK(matrix_location_ != -1 && tex_scale_location_ != -1); |
| 109 } | 171 } |
| 110 | 172 |
| 111 std::string VertexShaderPosTexYUVStretch::GetShaderString() const { | 173 std::string VertexShaderPosTexYUVStretch::GetShaderString() const { |
| 112 return SHADER( | 174 return VERTEX_SHADER( |
| 113 precision mediump float; | 175 precision mediump float; |
| 114 attribute vec4 a_position; | 176 attribute vec4 a_position; |
| 115 attribute vec2 a_texCoord; | 177 attribute TexCoordPrecision vec2 a_texCoord; |
| 116 uniform mat4 matrix; | 178 uniform mat4 matrix; |
| 117 varying vec2 v_texCoord; | 179 varying TexCoordPrecision vec2 v_texCoord; |
| 118 uniform vec2 texScale; | 180 uniform TexCoordPrecision vec2 texScale; |
| 119 void main() { | 181 void main() { |
| 120 gl_Position = matrix * a_position; | 182 gl_Position = matrix * a_position; |
| 121 v_texCoord = a_texCoord * texScale; | 183 v_texCoord = a_texCoord * texScale; |
| 122 } | 184 } |
| 123 ); | 185 ); |
| 124 } | 186 } |
| 125 | 187 |
| 126 VertexShaderPos::VertexShaderPos() | 188 VertexShaderPos::VertexShaderPos() |
| 127 : matrix_location_(-1) { } | 189 : matrix_location_(-1) { } |
| 128 | 190 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 142 arraysize(locations), | 204 arraysize(locations), |
| 143 locations, | 205 locations, |
| 144 using_bind_uniform, | 206 using_bind_uniform, |
| 145 base_uniform_index); | 207 base_uniform_index); |
| 146 | 208 |
| 147 matrix_location_ = locations[0]; | 209 matrix_location_ = locations[0]; |
| 148 DCHECK(matrix_location_ != -1); | 210 DCHECK(matrix_location_ != -1); |
| 149 } | 211 } |
| 150 | 212 |
| 151 std::string VertexShaderPos::GetShaderString() const { | 213 std::string VertexShaderPos::GetShaderString() const { |
| 152 return SHADER( | 214 return VERTEX_SHADER( |
| 153 attribute vec4 a_position; | 215 attribute vec4 a_position; |
| 154 uniform mat4 matrix; | 216 uniform mat4 matrix; |
| 155 void main() { | 217 void main() { |
| 156 gl_Position = matrix * a_position; | 218 gl_Position = matrix * a_position; |
| 157 } | 219 } |
| 158 ); | 220 ); |
| 159 } | 221 } |
| 160 | 222 |
| 161 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | 223 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
| 162 : matrix_location_(-1), | 224 : matrix_location_(-1), |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 184 base_uniform_index); | 246 base_uniform_index); |
| 185 | 247 |
| 186 matrix_location_ = locations[0]; | 248 matrix_location_ = locations[0]; |
| 187 tex_transform_location_ = locations[1]; | 249 tex_transform_location_ = locations[1]; |
| 188 vertex_opacity_location_ = locations[2]; | 250 vertex_opacity_location_ = locations[2]; |
| 189 DCHECK(matrix_location_ != -1 && tex_transform_location_ != -1 && | 251 DCHECK(matrix_location_ != -1 && tex_transform_location_ != -1 && |
| 190 vertex_opacity_location_ != -1); | 252 vertex_opacity_location_ != -1); |
| 191 } | 253 } |
| 192 | 254 |
| 193 std::string VertexShaderPosTexTransform::GetShaderString() const { | 255 std::string VertexShaderPosTexTransform::GetShaderString() const { |
| 194 return SHADER( | 256 return VERTEX_SHADER( |
| 195 attribute vec4 a_position; | 257 attribute vec4 a_position; |
| 196 attribute vec2 a_texCoord; | 258 attribute TexCoordPrecision vec2 a_texCoord; |
| 197 attribute float a_index; | 259 attribute float a_index; |
| 198 uniform mat4 matrix[8]; | 260 uniform mat4 matrix[8]; |
| 199 uniform vec4 texTransform[8]; | 261 uniform TexCoordPrecision vec4 texTransform[8]; |
| 200 uniform float opacity[32]; | 262 uniform float opacity[32]; |
| 201 varying vec2 v_texCoord; | 263 varying TexCoordPrecision vec2 v_texCoord; |
| 202 varying float v_alpha; | 264 varying float v_alpha; |
| 203 void main() { | 265 void main() { |
| 204 gl_Position = matrix[int(a_index * 0.25)] * a_position; | 266 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
| 205 vec4 texTrans = texTransform[int(a_index * 0.25)]; | 267 TexCoordPrecision vec4 texTrans = texTransform[int(a_index * 0.25)]; |
| 206 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 268 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 207 v_alpha = opacity[int(a_index)]; | 269 v_alpha = opacity[int(a_index)]; |
| 208 } | 270 } |
| 209 ); | 271 ); |
| 210 } | 272 } |
| 211 | 273 |
| 212 std::string VertexShaderPosTexTransformFlip::GetShaderString() const { | 274 std::string VertexShaderPosTexTransformFlip::GetShaderString() const { |
| 213 return SHADER( | 275 return VERTEX_SHADER( |
| 214 attribute vec4 a_position; | 276 attribute vec4 a_position; |
| 215 attribute vec2 a_texCoord; | 277 attribute TexCoordPrecision vec2 a_texCoord; |
| 216 attribute float a_index; | 278 attribute float a_index; |
| 217 uniform mat4 matrix[8]; | 279 uniform mat4 matrix[8]; |
| 218 uniform vec4 texTransform[8]; | 280 uniform TexCoordPrecision vec4 texTransform[8]; |
| 219 uniform float opacity[32]; | 281 uniform float opacity[32]; |
| 220 varying vec2 v_texCoord; | 282 varying TexCoordPrecision vec2 v_texCoord; |
| 221 varying float v_alpha; | 283 varying float v_alpha; |
| 222 void main() { | 284 void main() { |
| 223 gl_Position = matrix[int(a_index * 0.25)] * a_position; | 285 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
| 224 vec4 texTrans = texTransform[int(a_index * 0.25)]; | 286 TexCoordPrecision vec4 texTrans = texTransform[int(a_index * 0.25)]; |
| 225 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 287 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 226 v_texCoord.y = 1.0 - v_texCoord.y; | 288 v_texCoord.y = 1.0 - v_texCoord.y; |
| 227 v_alpha = opacity[int(a_index)]; | 289 v_alpha = opacity[int(a_index)]; |
| 228 } | 290 } |
| 229 ); | 291 ); |
| 230 } | 292 } |
| 231 | 293 |
| 232 std::string VertexShaderPosTexIdentity::GetShaderString() const { | 294 std::string VertexShaderPosTexIdentity::GetShaderString() const { |
| 233 return SHADER( | 295 return VERTEX_SHADER( |
| 234 attribute vec4 a_position; | 296 attribute vec4 a_position; |
| 235 varying vec2 v_texCoord; | 297 varying TexCoordPrecision vec2 v_texCoord; |
| 236 void main() { | 298 void main() { |
| 237 gl_Position = a_position; | 299 gl_Position = a_position; |
| 238 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 300 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
| 239 } | 301 } |
| 240 ); | 302 ); |
| 241 } | 303 } |
| 242 | 304 |
| 243 VertexShaderQuad::VertexShaderQuad() | 305 VertexShaderQuad::VertexShaderQuad() |
| 244 : matrix_location_(-1), | 306 : matrix_location_(-1), |
| 245 point_location_(-1), | 307 point_location_(-1), |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 269 | 331 |
| 270 matrix_location_ = locations[0]; | 332 matrix_location_ = locations[0]; |
| 271 point_location_ = locations[1]; | 333 point_location_ = locations[1]; |
| 272 tex_scale_location_ = locations[2]; | 334 tex_scale_location_ = locations[2]; |
| 273 DCHECK_NE(matrix_location_, -1); | 335 DCHECK_NE(matrix_location_, -1); |
| 274 DCHECK_NE(point_location_, -1); | 336 DCHECK_NE(point_location_, -1); |
| 275 DCHECK_NE(tex_scale_location_, -1); | 337 DCHECK_NE(tex_scale_location_, -1); |
| 276 } | 338 } |
| 277 | 339 |
| 278 std::string VertexShaderQuad::GetShaderString() const { | 340 std::string VertexShaderQuad::GetShaderString() const { |
| 279 return SHADER( | 341 return VERTEX_SHADER( |
| 280 attribute vec4 a_position; | 342 attribute TexCoordPrecision vec4 a_position; |
| 281 attribute vec2 a_texCoord; | 343 attribute TexCoordPrecision vec2 a_texCoord; |
| 282 uniform mat4 matrix; | 344 uniform mat4 matrix; |
| 283 uniform vec2 point_bug223014[4]; | 345 uniform TexCoordPrecision vec2 point_bug223014[4]; |
| 284 uniform vec2 texScale; | 346 uniform TexCoordPrecision vec2 texScale; |
| 285 varying vec2 v_texCoord; | 347 varying TexCoordPrecision vec2 v_texCoord; |
| 286 void main() { | 348 void main() { |
| 287 vec2 complement = abs(a_texCoord - 1.0); | 349 TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0); |
| 288 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 350 TexCoordPrecision vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 289 pos.xy += (complement.x * complement.y) * point_bug223014[0]; | 351 pos.xy += (complement.x * complement.y) * point_bug223014[0]; |
| 290 pos.xy += (a_texCoord.x * complement.y) * point_bug223014[1]; | 352 pos.xy += (a_texCoord.x * complement.y) * point_bug223014[1]; |
| 291 pos.xy += (a_texCoord.x * a_texCoord.y) * point_bug223014[2]; | 353 pos.xy += (a_texCoord.x * a_texCoord.y) * point_bug223014[2]; |
| 292 pos.xy += (complement.x * a_texCoord.y) * point_bug223014[3]; | 354 pos.xy += (complement.x * a_texCoord.y) * point_bug223014[3]; |
| 293 gl_Position = matrix * pos; | 355 gl_Position = matrix * pos; |
| 294 v_texCoord = (pos.xy + vec2(0.5)) * texScale; | 356 v_texCoord = (pos.xy + vec2(0.5)) * texScale; |
| 295 } | 357 } |
| 296 ); | 358 ); |
| 297 } | 359 } |
| 298 | 360 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 322 base_uniform_index); | 384 base_uniform_index); |
| 323 | 385 |
| 324 matrix_location_ = locations[0]; | 386 matrix_location_ = locations[0]; |
| 325 point_location_ = locations[1]; | 387 point_location_ = locations[1]; |
| 326 vertex_tex_transform_location_ = locations[2]; | 388 vertex_tex_transform_location_ = locations[2]; |
| 327 DCHECK(matrix_location_ != -1 && point_location_ != -1 && | 389 DCHECK(matrix_location_ != -1 && point_location_ != -1 && |
| 328 vertex_tex_transform_location_ != -1); | 390 vertex_tex_transform_location_ != -1); |
| 329 } | 391 } |
| 330 | 392 |
| 331 std::string VertexShaderTile::GetShaderString() const { | 393 std::string VertexShaderTile::GetShaderString() const { |
| 332 return SHADER( | 394 return VERTEX_SHADER( |
| 333 attribute vec4 a_position; | 395 attribute TexCoordPrecision vec4 a_position; |
| 334 attribute vec2 a_texCoord; | 396 attribute TexCoordPrecision vec2 a_texCoord; |
| 335 uniform mat4 matrix; | 397 uniform mat4 matrix; |
| 336 uniform vec2 point_bug223014[4]; | 398 uniform TexCoordPrecision vec2 point_bug223014[4]; |
| 337 uniform vec4 vertexTexTransform; | 399 uniform TexCoordPrecision vec4 vertexTexTransform; |
| 338 varying vec2 v_texCoord; | 400 varying TexCoordPrecision vec2 v_texCoord; |
| 339 void main() { | 401 void main() { |
| 340 vec2 complement = abs(a_texCoord - 1.0); | 402 TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0); |
| 341 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 403 TexCoordPrecision vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 342 pos.xy += (complement.x * complement.y) * point_bug223014[0]; | 404 pos.xy += (complement.x * complement.y) * point_bug223014[0]; |
| 343 pos.xy += (a_texCoord.x * complement.y) * point_bug223014[1]; | 405 pos.xy += (a_texCoord.x * complement.y) * point_bug223014[1]; |
| 344 pos.xy += (a_texCoord.x * a_texCoord.y) * point_bug223014[2]; | 406 pos.xy += (a_texCoord.x * a_texCoord.y) * point_bug223014[2]; |
| 345 pos.xy += (complement.x * a_texCoord.y) * point_bug223014[3]; | 407 pos.xy += (complement.x * a_texCoord.y) * point_bug223014[3]; |
| 346 gl_Position = matrix * pos; | 408 gl_Position = matrix * pos; |
| 347 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | 409 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; |
| 348 } | 410 } |
| 349 ); | 411 ); |
| 350 } | 412 } |
| 351 | 413 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 371 locations, | 433 locations, |
| 372 using_bind_uniform, | 434 using_bind_uniform, |
| 373 base_uniform_index); | 435 base_uniform_index); |
| 374 | 436 |
| 375 matrix_location_ = locations[0]; | 437 matrix_location_ = locations[0]; |
| 376 tex_matrix_location_ = locations[1]; | 438 tex_matrix_location_ = locations[1]; |
| 377 return matrix_location_ != -1 && tex_matrix_location_ != -1; | 439 return matrix_location_ != -1 && tex_matrix_location_ != -1; |
| 378 } | 440 } |
| 379 | 441 |
| 380 std::string VertexShaderVideoTransform::GetShaderString() const { | 442 std::string VertexShaderVideoTransform::GetShaderString() const { |
| 381 return SHADER( | 443 return VERTEX_SHADER( |
| 382 attribute vec4 a_position; | 444 attribute vec4 a_position; |
| 383 attribute vec2 a_texCoord; | 445 attribute TexCoordPrecision vec2 a_texCoord; |
| 384 uniform mat4 matrix; | 446 uniform mat4 matrix; |
| 385 uniform mat4 texMatrix; | 447 uniform TexCoordPrecision mat4 texMatrix; |
| 386 varying vec2 v_texCoord; | 448 varying TexCoordPrecision vec2 v_texCoord; |
| 387 void main() { | 449 void main() { |
| 388 gl_Position = matrix * a_position; | 450 gl_Position = matrix * a_position; |
| 389 v_texCoord = | 451 v_texCoord = |
| 390 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 452 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
| 391 } | 453 } |
| 392 ); | 454 ); |
| 393 } | 455 } |
| 394 | 456 |
| 395 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | 457 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
| 396 : sampler_location_(-1), | 458 : sampler_location_(-1), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 arraysize(shader_uniforms), | 522 arraysize(shader_uniforms), |
| 461 arraysize(locations), | 523 arraysize(locations), |
| 462 locations, | 524 locations, |
| 463 using_bind_uniform, | 525 using_bind_uniform, |
| 464 base_uniform_index); | 526 base_uniform_index); |
| 465 | 527 |
| 466 sampler_location_ = locations[0]; | 528 sampler_location_ = locations[0]; |
| 467 return sampler_location_ != -1; | 529 return sampler_location_ != -1; |
| 468 } | 530 } |
| 469 | 531 |
| 470 std::string FragmentShaderOESImageExternal::GetShaderString() const { | 532 std::string FragmentShaderOESImageExternal::GetShaderString( |
| 533 TexCoordPrecision precision) const { | |
| 471 // Cannot use the SHADER() macro because of the '#' char | 534 // Cannot use the SHADER() macro because of the '#' char |
| 472 return "#extension GL_OES_EGL_image_external : require\n" | 535 return "#extension GL_OES_EGL_image_external : require\n" + |
| 473 SHADER( | 536 FRAGMENT_SHADER( |
| 474 precision mediump float; | 537 precision mediump float; |
| 475 varying vec2 v_texCoord; | 538 varying TexCoordPrecision vec2 v_texCoord; |
| 476 uniform samplerExternalOES s_texture; | 539 uniform samplerExternalOES s_texture; |
| 477 void main() { | 540 void main() { |
| 478 vec4 texColor = texture2D(s_texture, v_texCoord); | 541 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 479 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w); | 542 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w); |
| 480 } | 543 } |
| 481 ); | 544 ); |
| 482 } | 545 } |
| 483 | 546 |
| 484 std::string FragmentShaderRGBATexAlpha::GetShaderString() const { | 547 std::string FragmentShaderRGBATexAlpha::GetShaderString( |
| 485 return SHADER( | 548 TexCoordPrecision precision) const { |
| 549 return FRAGMENT_SHADER( | |
| 486 precision mediump float; | 550 precision mediump float; |
| 487 varying vec2 v_texCoord; | 551 varying TexCoordPrecision vec2 v_texCoord; |
| 488 uniform sampler2D s_texture; | 552 uniform sampler2D s_texture; |
| 489 uniform float alpha; | 553 uniform float alpha; |
| 490 void main() { | 554 void main() { |
| 491 vec4 texColor = texture2D(s_texture, v_texCoord); | 555 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 492 gl_FragColor = texColor * alpha; | 556 gl_FragColor = texColor * alpha; |
| 493 } | 557 } |
| 494 ); | 558 ); |
| 495 } | 559 } |
| 496 | 560 |
| 497 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString() const { | 561 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( |
| 498 return SHADER( | 562 TexCoordPrecision precision) const { |
| 563 return FRAGMENT_SHADER( | |
| 499 precision mediump float; | 564 precision mediump float; |
| 500 varying vec2 v_texCoord; | 565 varying TexCoordPrecision vec2 v_texCoord; |
| 501 varying float v_alpha; | 566 varying float v_alpha; |
| 502 uniform sampler2D s_texture; | 567 uniform sampler2D s_texture; |
| 503 void main() { | 568 void main() { |
| 504 vec4 texColor = texture2D(s_texture, v_texCoord); | 569 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 505 gl_FragColor = texColor * v_alpha; | 570 gl_FragColor = texColor * v_alpha; |
| 506 } | 571 } |
| 507 ); | 572 ); |
| 508 } | 573 } |
| 509 | 574 |
| 510 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString() const { | 575 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString( |
| 511 return "#extension GL_ARB_texture_rectangle : require\n" | 576 TexCoordPrecision precision) const { |
| 512 SHADER( | 577 return "#extension GL_ARB_texture_rectangle : require\n" + |
| 578 FRAGMENT_SHADER( | |
| 513 precision mediump float; | 579 precision mediump float; |
| 514 varying vec2 v_texCoord; | 580 varying TexCoordPrecision vec2 v_texCoord; |
| 515 varying float v_alpha; | 581 varying float v_alpha; |
| 516 uniform sampler2DRect s_texture; | 582 uniform sampler2DRect s_texture; |
| 517 void main() { | 583 void main() { |
| 518 vec4 texColor = texture2DRect(s_texture, v_texCoord); | 584 vec4 texColor = texture2DRect(s_texture, v_texCoord); |
| 519 gl_FragColor = texColor * v_alpha; | 585 gl_FragColor = texColor * v_alpha; |
| 520 } | 586 } |
| 521 ); | 587 ); |
| 522 } | 588 } |
| 523 | 589 |
| 524 std::string FragmentShaderRGBATexOpaque::GetShaderString() const { | 590 std::string FragmentShaderRGBATexOpaque::GetShaderString( |
| 525 return SHADER( | 591 TexCoordPrecision precision) const { |
| 592 return FRAGMENT_SHADER( | |
| 526 precision mediump float; | 593 precision mediump float; |
| 527 varying vec2 v_texCoord; | 594 varying TexCoordPrecision vec2 v_texCoord; |
| 528 uniform sampler2D s_texture; | 595 uniform sampler2D s_texture; |
| 529 void main() { | 596 void main() { |
| 530 vec4 texColor = texture2D(s_texture, v_texCoord); | 597 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 531 gl_FragColor = vec4(texColor.rgb, 1.0); | 598 gl_FragColor = vec4(texColor.rgb, 1.0); |
| 532 } | 599 } |
| 533 ); | 600 ); |
| 534 } | 601 } |
| 535 | 602 |
| 536 std::string FragmentShaderRGBATex::GetShaderString() const { | 603 std::string FragmentShaderRGBATex::GetShaderString( |
| 537 return SHADER( | 604 TexCoordPrecision precision) const { |
| 605 return FRAGMENT_SHADER( | |
| 538 precision mediump float; | 606 precision mediump float; |
| 539 varying vec2 v_texCoord; | 607 varying TexCoordPrecision vec2 v_texCoord; |
| 540 uniform sampler2D s_texture; | 608 uniform sampler2D s_texture; |
| 541 void main() { | 609 void main() { |
| 542 gl_FragColor = texture2D(s_texture, v_texCoord); | 610 gl_FragColor = texture2D(s_texture, v_texCoord); |
| 543 } | 611 } |
| 544 ); | 612 ); |
| 545 } | 613 } |
| 546 | 614 |
| 547 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString() const { | 615 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( |
| 548 return SHADER( | 616 TexCoordPrecision precision) const { |
| 617 return FRAGMENT_SHADER( | |
| 549 precision mediump float; | 618 precision mediump float; |
| 550 varying vec2 v_texCoord; | 619 varying TexCoordPrecision vec2 v_texCoord; |
| 551 uniform sampler2D s_texture; | 620 uniform sampler2D s_texture; |
| 552 uniform float alpha; | 621 uniform float alpha; |
| 553 void main() { | 622 void main() { |
| 554 vec4 texColor = texture2D(s_texture, v_texCoord); | 623 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 555 gl_FragColor = | 624 gl_FragColor = |
| 556 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; | 625 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; |
| 557 } | 626 } |
| 558 ); | 627 ); |
| 559 } | 628 } |
| 560 | 629 |
| 561 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString() const { | 630 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( |
| 562 return SHADER( | 631 TexCoordPrecision precision) const { |
| 632 return FRAGMENT_SHADER( | |
| 563 precision mediump float; | 633 precision mediump float; |
| 564 varying vec2 v_texCoord; | 634 varying TexCoordPrecision vec2 v_texCoord; |
| 565 uniform sampler2D s_texture; | 635 uniform sampler2D s_texture; |
| 566 void main() { | 636 void main() { |
| 567 vec4 texColor = texture2D(s_texture, v_texCoord); | 637 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 568 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 638 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
| 569 } | 639 } |
| 570 ); | 640 ); |
| 571 } | 641 } |
| 572 | 642 |
| 573 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 643 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
| 574 : sampler_location_(-1), | 644 : sampler_location_(-1), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 595 using_bind_uniform, | 665 using_bind_uniform, |
| 596 base_uniform_index); | 666 base_uniform_index); |
| 597 | 667 |
| 598 sampler_location_ = locations[0]; | 668 sampler_location_ = locations[0]; |
| 599 alpha_location_ = locations[1]; | 669 alpha_location_ = locations[1]; |
| 600 edge_location_ = locations[2]; | 670 edge_location_ = locations[2]; |
| 601 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && | 671 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && |
| 602 edge_location_ != -1); | 672 edge_location_ != -1); |
| 603 } | 673 } |
| 604 | 674 |
| 605 std::string FragmentShaderRGBATexAlphaAA::GetShaderString() const { | 675 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( |
| 606 return SHADER( | 676 TexCoordPrecision precision) const { |
| 677 return FRAGMENT_SHADER( | |
| 607 precision mediump float; | 678 precision mediump float; |
| 608 varying vec2 v_texCoord; | 679 varying TexCoordPrecision vec2 v_texCoord; |
| 609 uniform sampler2D s_texture; | 680 uniform sampler2D s_texture; |
| 610 uniform float alpha; | 681 uniform float alpha; |
| 611 uniform vec3 edge[8]; | 682 uniform vec3 edge[8]; |
| 612 void main() { | 683 void main() { |
| 613 vec4 texColor = texture2D(s_texture, v_texCoord); | 684 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 614 vec3 pos = vec3(gl_FragCoord.xy, 1); | 685 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 615 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 686 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 616 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 687 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 617 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 688 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 618 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 689 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 base_uniform_index); | 725 base_uniform_index); |
| 655 | 726 |
| 656 sampler_location_ = locations[0]; | 727 sampler_location_ = locations[0]; |
| 657 alpha_location_ = locations[1]; | 728 alpha_location_ = locations[1]; |
| 658 fragment_tex_transform_location_ = locations[2]; | 729 fragment_tex_transform_location_ = locations[2]; |
| 659 edge_location_ = locations[3]; | 730 edge_location_ = locations[3]; |
| 660 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && | 731 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && |
| 661 fragment_tex_transform_location_ != -1 && edge_location_ != -1); | 732 fragment_tex_transform_location_ != -1 && edge_location_ != -1); |
| 662 } | 733 } |
| 663 | 734 |
| 664 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString() const { | 735 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( |
| 665 return SHADER( | 736 TexCoordPrecision precision) const { |
| 737 return FRAGMENT_SHADER( | |
| 666 precision mediump float; | 738 precision mediump float; |
| 667 varying vec2 v_texCoord; | 739 varying TexCoordPrecision vec2 v_texCoord; |
| 668 uniform sampler2D s_texture; | 740 uniform sampler2D s_texture; |
| 669 uniform float alpha; | 741 uniform float alpha; |
| 670 uniform vec4 fragmentTexTransform; | 742 uniform TexCoordPrecision vec4 fragmentTexTransform; |
| 671 uniform vec3 edge[8]; | 743 uniform vec3 edge[8]; |
| 672 void main() { | 744 void main() { |
| 673 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 745 TexCoordPrecision vec2 texCoord = |
| 746 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | |
| 674 fragmentTexTransform.xy; | 747 fragmentTexTransform.xy; |
| 675 vec4 texColor = texture2D(s_texture, texCoord); | 748 vec4 texColor = texture2D(s_texture, texCoord); |
| 676 vec3 pos = vec3(gl_FragCoord.xy, 1); | 749 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 677 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 750 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 678 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 751 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 679 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 752 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 680 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 753 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 681 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 754 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 682 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 755 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 683 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 756 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 684 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 757 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| 685 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), | 758 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), |
| 686 min(a4, a6) * min(a5, a7)); | 759 min(a4, a6) * min(a5, a7)); |
| 687 } | 760 } |
| 688 ); | 761 ); |
| 689 } | 762 } |
| 690 | 763 |
| 691 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString() const { | 764 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( |
| 692 return SHADER( | 765 TexCoordPrecision precision) const { |
| 766 return FRAGMENT_SHADER( | |
| 693 precision mediump float; | 767 precision mediump float; |
| 694 varying vec2 v_texCoord; | 768 varying TexCoordPrecision vec2 v_texCoord; |
| 695 uniform sampler2D s_texture; | 769 uniform sampler2D s_texture; |
| 696 uniform float alpha; | 770 uniform float alpha; |
| 697 uniform vec4 fragmentTexTransform; | 771 uniform TexCoordPrecision vec4 fragmentTexTransform; |
| 698 uniform vec3 edge[8]; | 772 uniform vec3 edge[8]; |
| 699 void main() { | 773 void main() { |
| 700 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 774 TexCoordPrecision vec2 texCoord = |
| 775 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | |
| 701 fragmentTexTransform.xy; | 776 fragmentTexTransform.xy; |
| 702 vec4 texColor = texture2D(s_texture, texCoord); | 777 vec4 texColor = texture2D(s_texture, texCoord); |
| 703 vec3 pos = vec3(gl_FragCoord.xy, 1); | 778 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 704 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 779 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 705 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 780 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 706 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 781 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 707 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 782 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 708 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 783 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 709 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 784 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 710 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 785 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 745 | 820 |
| 746 sampler_location_ = locations[0]; | 821 sampler_location_ = locations[0]; |
| 747 mask_sampler_location_ = locations[1]; | 822 mask_sampler_location_ = locations[1]; |
| 748 alpha_location_ = locations[2]; | 823 alpha_location_ = locations[2]; |
| 749 mask_tex_coord_scale_location_ = locations[3]; | 824 mask_tex_coord_scale_location_ = locations[3]; |
| 750 mask_tex_coord_offset_location_ = locations[4]; | 825 mask_tex_coord_offset_location_ = locations[4]; |
| 751 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && | 826 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && |
| 752 alpha_location_ != -1); | 827 alpha_location_ != -1); |
| 753 } | 828 } |
| 754 | 829 |
| 755 std::string FragmentShaderRGBATexAlphaMask::GetShaderString() const { | 830 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( |
| 756 return SHADER( | 831 TexCoordPrecision precision) const { |
| 832 return FRAGMENT_SHADER( | |
| 757 precision mediump float; | 833 precision mediump float; |
| 758 varying vec2 v_texCoord; | 834 varying TexCoordPrecision vec2 v_texCoord; |
| 759 uniform sampler2D s_texture; | 835 uniform sampler2D s_texture; |
| 760 uniform sampler2D s_mask; | 836 uniform sampler2D s_mask; |
| 761 uniform vec2 maskTexCoordScale; | 837 uniform TexCoordPrecision vec2 maskTexCoordScale; |
| 762 uniform vec2 maskTexCoordOffset; | 838 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
| 763 uniform float alpha; | 839 uniform float alpha; |
| 764 void main() { | 840 void main() { |
| 765 vec4 texColor = texture2D(s_texture, v_texCoord); | 841 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 766 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * | 842 TexCoordPrecision vec2 maskTexCoord = |
| 767 maskTexCoordScale.x, | 843 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 768 maskTexCoordOffset.y + v_texCoord.y * | 844 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 769 maskTexCoordScale.y); | |
| 770 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 845 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 771 gl_FragColor = vec4(texColor.x, texColor.y, | 846 gl_FragColor = vec4(texColor.x, texColor.y, |
| 772 texColor.z, texColor.w) * alpha * maskColor.w; | 847 texColor.z, texColor.w) * alpha * maskColor.w; |
| 773 } | 848 } |
| 774 ); | 849 ); |
| 775 } | 850 } |
| 776 | 851 |
| 777 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 852 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
| 778 : sampler_location_(-1), | 853 : sampler_location_(-1), |
| 779 mask_sampler_location_(-1), | 854 mask_sampler_location_(-1), |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 807 sampler_location_ = locations[0]; | 882 sampler_location_ = locations[0]; |
| 808 mask_sampler_location_ = locations[1]; | 883 mask_sampler_location_ = locations[1]; |
| 809 alpha_location_ = locations[2]; | 884 alpha_location_ = locations[2]; |
| 810 edge_location_ = locations[3]; | 885 edge_location_ = locations[3]; |
| 811 mask_tex_coord_scale_location_ = locations[4]; | 886 mask_tex_coord_scale_location_ = locations[4]; |
| 812 mask_tex_coord_offset_location_ = locations[5]; | 887 mask_tex_coord_offset_location_ = locations[5]; |
| 813 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && | 888 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && |
| 814 alpha_location_ != -1 && edge_location_ != -1); | 889 alpha_location_ != -1 && edge_location_ != -1); |
| 815 } | 890 } |
| 816 | 891 |
| 817 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString() const { | 892 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( |
| 818 return SHADER( | 893 TexCoordPrecision precision) const { |
| 894 return FRAGMENT_SHADER( | |
| 819 precision mediump float; | 895 precision mediump float; |
| 820 varying vec2 v_texCoord; | 896 varying TexCoordPrecision vec2 v_texCoord; |
| 821 uniform sampler2D s_texture; | 897 uniform sampler2D s_texture; |
| 822 uniform sampler2D s_mask; | 898 uniform sampler2D s_mask; |
| 823 uniform vec2 maskTexCoordScale; | 899 uniform TexCoordPrecision vec2 maskTexCoordScale; |
| 824 uniform vec2 maskTexCoordOffset; | 900 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
| 825 uniform float alpha; | 901 uniform float alpha; |
| 826 uniform vec3 edge[8]; | 902 uniform vec3 edge[8]; |
| 827 void main() { | 903 void main() { |
| 828 vec4 texColor = texture2D(s_texture, v_texCoord); | 904 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 829 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * | 905 TexCoordPrecision vec2 maskTexCoord = |
| 830 maskTexCoordScale.x, | 906 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 831 maskTexCoordOffset.y + v_texCoord.y * | 907 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 832 maskTexCoordScale.y); | |
| 833 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 908 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 834 vec3 pos = vec3(gl_FragCoord.xy, 1); | 909 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 835 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 910 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 836 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 911 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 837 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 912 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 838 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 913 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 839 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 914 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 840 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 915 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 841 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 916 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 842 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 917 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 v_texture_location_ = locations[2]; | 958 v_texture_location_ = locations[2]; |
| 884 alpha_location_ = locations[3]; | 959 alpha_location_ = locations[3]; |
| 885 yuv_matrix_location_ = locations[4]; | 960 yuv_matrix_location_ = locations[4]; |
| 886 yuv_adj_location_ = locations[5]; | 961 yuv_adj_location_ = locations[5]; |
| 887 | 962 |
| 888 DCHECK(y_texture_location_ != -1 && u_texture_location_ != -1 && | 963 DCHECK(y_texture_location_ != -1 && u_texture_location_ != -1 && |
| 889 v_texture_location_ != -1 && alpha_location_ != -1 && | 964 v_texture_location_ != -1 && alpha_location_ != -1 && |
| 890 yuv_matrix_location_ != -1 && yuv_adj_location_ != -1); | 965 yuv_matrix_location_ != -1 && yuv_adj_location_ != -1); |
| 891 } | 966 } |
| 892 | 967 |
| 893 std::string FragmentShaderYUVVideo::GetShaderString() const { | 968 std::string FragmentShaderYUVVideo::GetShaderString( |
| 894 return SHADER( | 969 TexCoordPrecision precision) const { |
| 970 return FRAGMENT_SHADER( | |
| 895 precision mediump float; | 971 precision mediump float; |
| 896 precision mediump int; | 972 precision mediump int; |
| 897 varying vec2 v_texCoord; | 973 varying TexCoordPrecision vec2 v_texCoord; |
| 898 uniform sampler2D y_texture; | 974 uniform sampler2D y_texture; |
| 899 uniform sampler2D u_texture; | 975 uniform sampler2D u_texture; |
| 900 uniform sampler2D v_texture; | 976 uniform sampler2D v_texture; |
| 901 uniform float alpha; | 977 uniform float alpha; |
| 902 uniform vec3 yuv_adj; | 978 uniform vec3 yuv_adj; |
| 903 uniform mat3 yuv_matrix; | 979 uniform mat3 yuv_matrix; |
| 904 void main() { | 980 void main() { |
| 905 float y_raw = texture2D(y_texture, v_texCoord).x; | 981 float y_raw = texture2D(y_texture, v_texCoord).x; |
| 906 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 982 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
| 907 float v_unsigned = texture2D(v_texture, v_texCoord).x; | 983 float v_unsigned = texture2D(v_texture, v_texCoord).x; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 930 arraysize(shader_uniforms), | 1006 arraysize(shader_uniforms), |
| 931 arraysize(locations), | 1007 arraysize(locations), |
| 932 locations, | 1008 locations, |
| 933 using_bind_uniform, | 1009 using_bind_uniform, |
| 934 base_uniform_index); | 1010 base_uniform_index); |
| 935 | 1011 |
| 936 color_location_ = locations[0]; | 1012 color_location_ = locations[0]; |
| 937 DCHECK(color_location_ != -1); | 1013 DCHECK(color_location_ != -1); |
| 938 } | 1014 } |
| 939 | 1015 |
| 940 std::string FragmentShaderColor::GetShaderString() const { | 1016 std::string FragmentShaderColor::GetShaderString( |
| 941 return SHADER( | 1017 TexCoordPrecision precision) const { |
| 1018 return FRAGMENT_SHADER( | |
| 942 precision mediump float; | 1019 precision mediump float; |
| 943 uniform vec4 color; | 1020 uniform vec4 color; |
| 944 void main() { | 1021 void main() { |
| 945 gl_FragColor = color; | 1022 gl_FragColor = color; |
| 946 } | 1023 } |
| 947 ); | 1024 ); |
| 948 } | 1025 } |
| 949 | 1026 |
| 950 FragmentShaderColorAA::FragmentShaderColorAA() | 1027 FragmentShaderColorAA::FragmentShaderColorAA() |
| 951 : edge_location_(-1), | 1028 : edge_location_(-1), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 968 arraysize(locations), | 1045 arraysize(locations), |
| 969 locations, | 1046 locations, |
| 970 using_bind_uniform, | 1047 using_bind_uniform, |
| 971 base_uniform_index); | 1048 base_uniform_index); |
| 972 | 1049 |
| 973 edge_location_ = locations[0]; | 1050 edge_location_ = locations[0]; |
| 974 color_location_ = locations[1]; | 1051 color_location_ = locations[1]; |
| 975 DCHECK(edge_location_ != -1 && color_location_ != -1); | 1052 DCHECK(edge_location_ != -1 && color_location_ != -1); |
| 976 } | 1053 } |
| 977 | 1054 |
| 978 std::string FragmentShaderColorAA::GetShaderString() const { | 1055 std::string FragmentShaderColorAA::GetShaderString( |
| 979 return SHADER( | 1056 TexCoordPrecision precision) const { |
| 1057 return FRAGMENT_SHADER( | |
| 980 precision mediump float; | 1058 precision mediump float; |
| 981 uniform vec4 color; | 1059 uniform vec4 color; |
| 982 uniform vec3 edge[8]; | 1060 uniform vec3 edge[8]; |
| 983 void main() { | 1061 void main() { |
| 984 vec3 pos = vec3(gl_FragCoord.xy, 1); | 1062 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 985 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 1063 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 986 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 1064 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 987 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 1065 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 988 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 1066 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 989 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 1067 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 base_uniform_index); | 1101 base_uniform_index); |
| 1024 | 1102 |
| 1025 alpha_location_ = locations[0]; | 1103 alpha_location_ = locations[0]; |
| 1026 tex_transform_location_ = locations[1]; | 1104 tex_transform_location_ = locations[1]; |
| 1027 frequency_location_ = locations[2]; | 1105 frequency_location_ = locations[2]; |
| 1028 color_location_ = locations[3]; | 1106 color_location_ = locations[3]; |
| 1029 DCHECK(alpha_location_ != -1 && tex_transform_location_ != -1 && | 1107 DCHECK(alpha_location_ != -1 && tex_transform_location_ != -1 && |
| 1030 frequency_location_ != -1 && color_location_ != -1); | 1108 frequency_location_ != -1 && color_location_ != -1); |
| 1031 } | 1109 } |
| 1032 | 1110 |
| 1033 std::string FragmentShaderCheckerboard::GetShaderString() const { | 1111 std::string FragmentShaderCheckerboard::GetShaderString( |
| 1112 TexCoordPrecision precision) const { | |
| 1034 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | 1113 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
| 1035 // by Munshi, Ginsburg, Shreiner. | 1114 // by Munshi, Ginsburg, Shreiner. |
| 1036 return SHADER( | 1115 return FRAGMENT_SHADER( |
| 1037 precision mediump float; | 1116 precision mediump float; |
| 1038 precision mediump int; | 1117 precision mediump int; |
| 1039 varying vec2 v_texCoord; | 1118 varying TexCoordPrecision vec2 v_texCoord; |
| 1040 uniform float alpha; | 1119 uniform float alpha; |
| 1041 uniform float frequency; | 1120 uniform float frequency; |
| 1042 uniform vec4 texTransform; | 1121 uniform vec4 texTransform; |
| 1043 uniform vec4 color; | 1122 uniform vec4 color; |
| 1044 void main() { | 1123 void main() { |
| 1045 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | 1124 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
| 1046 vec4 color2 = color; | 1125 vec4 color2 = color; |
| 1047 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + | 1126 TexCoordPrecision vec2 texCoord = |
| 1048 texTransform.xy; | 1127 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
| 1049 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1128 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 1050 float picker = abs(coord.x - coord.y); | 1129 float picker = abs(coord.x - coord.y); |
| 1051 gl_FragColor = mix(color1, color2, picker) * alpha; | 1130 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 1052 } | 1131 } |
| 1053 ); | 1132 ); |
| 1054 } | 1133 } |
| 1055 | 1134 |
| 1056 } // namespace cc | 1135 } // namespace cc |
| OLD | NEW |