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/shader.h" | 5 #include "cc/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 <public/WebGraphicsContext3D.h> | 9 #include <public/WebGraphicsContext3D.h> |
| 10 | 10 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 void main() | 129 void main() |
| 130 { | 130 { |
| 131 gl_Position = matrix * a_position; | 131 gl_Position = matrix * a_position; |
| 132 } | 132 } |
| 133 ); | 133 ); |
| 134 } | 134 } |
| 135 | 135 |
| 136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | 136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
| 137 : m_matrixLocation(-1) | 137 : m_matrixLocation(-1) |
| 138 , m_texTransformLocation(-1) | 138 , m_texTransformLocation(-1) |
| 139 , m_vertexOpacityLocation(-1) | |
| 139 { | 140 { |
| 140 } | 141 } |
| 141 | 142 |
| 142 void VertexShaderPosTexTransform::init(WebGraphicsContext3D* context, unsigned p rogram, bool usingBindUniform, int* baseUniformIndex) | 143 void VertexShaderPosTexTransform::init(WebGraphicsContext3D* context, unsigned p rogram, bool usingBindUniform, int* baseUniformIndex) |
| 143 { | 144 { |
| 144 static const char* shaderUniforms[] = { | 145 static const char* shaderUniforms[] = { |
| 145 "matrix", | 146 "matrix", |
| 146 "texTransform", | 147 "texTransform", |
| 148 "opacity", | |
| 147 }; | 149 }; |
| 148 int locations[2]; | 150 int locations[3]; |
| 149 | 151 |
| 150 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 152 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 151 | 153 |
| 152 m_matrixLocation = locations[0]; | 154 m_matrixLocation = locations[0]; |
| 153 m_texTransformLocation = locations[1]; | 155 m_texTransformLocation = locations[1]; |
| 154 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1); | 156 m_vertexOpacityLocation = locations[2]; |
| 157 DCHECK(m_matrixLocation != -1 | |
| 158 && m_texTransformLocation != -1 | |
|
jamesr
2012/12/14 21:18:20
&&s on previous line
Jerome
2012/12/14 21:48:47
Done.
| |
| 159 && m_vertexOpacityLocation != -1); | |
| 155 } | 160 } |
| 156 | 161 |
| 157 std::string VertexShaderPosTexTransform::getShaderString() const | 162 std::string VertexShaderPosTexTransform::getShaderString() const |
| 158 { | 163 { |
| 159 return SHADER( | 164 return SHADER( |
| 160 attribute vec4 a_position; | 165 attribute vec4 a_position; |
| 161 attribute vec2 a_texCoord; | 166 attribute vec2 a_texCoord; |
| 162 attribute float a_index; | 167 attribute float a_index; |
| 163 uniform mat4 matrix[8]; | 168 uniform mat4 matrix[8]; |
| 164 uniform vec4 texTransform[8]; | 169 uniform vec4 texTransform[8]; |
| 170 uniform float opacity[32]; | |
| 165 varying vec2 v_texCoord; | 171 varying vec2 v_texCoord; |
| 172 varying float v_alpha; | |
| 166 void main() | 173 void main() |
| 167 { | 174 { |
| 168 gl_Position = matrix[int(a_index)] * a_position; | 175 gl_Position = matrix[int(a_index) / 4] * a_position; |
| 169 v_texCoord = a_texCoord * texTransform[int(a_index)].zw + texTransfo rm[int(a_index)].xy; | 176 vec4 texTrans = texTransform[int(a_index) / 4]; |
| 177 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | |
| 178 v_alpha = opacity[int(a_index)]; | |
| 170 } | 179 } |
| 171 ); | 180 ); |
| 172 } | 181 } |
| 173 | 182 |
| 174 VertexShaderQuad::VertexShaderQuad() | 183 VertexShaderQuad::VertexShaderQuad() |
| 175 : m_matrixLocation(-1) | 184 : m_matrixLocation(-1) |
| 176 , m_pointLocation(-1) | 185 , m_pointLocation(-1) |
| 177 { | 186 { |
| 178 } | 187 } |
| 179 | 188 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 "s_texture", | 352 "s_texture", |
| 344 }; | 353 }; |
| 345 int locations[1]; | 354 int locations[1]; |
| 346 | 355 |
| 347 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 356 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 348 | 357 |
| 349 m_samplerLocation = locations[0]; | 358 m_samplerLocation = locations[0]; |
| 350 DCHECK(m_samplerLocation != -1); | 359 DCHECK(m_samplerLocation != -1); |
| 351 } | 360 } |
| 352 | 361 |
| 353 std::string FragmentShaderRGBATexFlipAlpha::getShaderString() const | 362 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const |
| 354 { | 363 { |
| 355 return SHADER( | 364 return SHADER( |
| 356 precision mediump float; | 365 precision mediump float; |
| 357 varying vec2 v_texCoord; | 366 varying vec2 v_texCoord; |
| 367 varying float v_alpha; | |
| 358 uniform sampler2D s_texture; | 368 uniform sampler2D s_texture; |
| 359 uniform float alpha; | |
| 360 void main() | 369 void main() |
| 361 { | 370 { |
| 362 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC oord.y)); | 371 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC oord.y)); |
| 363 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; | 372 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * v_alpha; |
| 364 } | 373 } |
| 365 ); | 374 ); |
| 366 } | 375 } |
| 367 | 376 |
| 368 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne d program, bool usingBindUniform, int* baseUniformIndex) | 377 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne d program, bool usingBindUniform, int* baseUniformIndex) |
| 369 { | 378 { |
| 370 static const char* shaderUniforms[] = { | 379 static const char* shaderUniforms[] = { |
| 371 "s_texture", | 380 "s_texture", |
| 372 }; | 381 }; |
| 373 int locations[1]; | 382 int locations[1]; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 400 uniform sampler2D s_texture; | 409 uniform sampler2D s_texture; |
| 401 uniform float alpha; | 410 uniform float alpha; |
| 402 void main() | 411 void main() |
| 403 { | 412 { |
| 404 vec4 texColor = texture2D(s_texture, v_texCoord); | 413 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 405 gl_FragColor = texColor * alpha; | 414 gl_FragColor = texColor * alpha; |
| 406 } | 415 } |
| 407 ); | 416 ); |
| 408 } | 417 } |
| 409 | 418 |
| 410 std::string FragmentShaderRGBATexRectFlipAlpha::getShaderString() const | 419 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const |
| 420 { | |
| 421 return SHADER( | |
| 422 precision mediump float; | |
| 423 varying vec2 v_texCoord; | |
| 424 varying float v_alpha; | |
| 425 uniform sampler2D s_texture; | |
| 426 void main() | |
| 427 { | |
| 428 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 429 gl_FragColor = texColor * v_alpha; | |
| 430 } | |
| 431 ); | |
| 432 } | |
| 433 | |
| 434 std::string FragmentShaderRGBATexRectFlipVaryingAlpha::getShaderString() const | |
| 411 { | 435 { |
| 412 // This must be paired with VertexShaderPosTexTransform to pick up the texTr ansform uniform. | 436 // This must be paired with VertexShaderPosTexTransform to pick up the texTr ansform uniform. |
| 413 // The necessary #extension preprocessing directive breaks the SHADER and SH ADER0 macros. | 437 // The necessary #extension preprocessing directive breaks the SHADER and SH ADER0 macros. |
| 414 return "#extension GL_ARB_texture_rectangle : require\n" | 438 return "#extension GL_ARB_texture_rectangle : require\n" |
| 415 "precision mediump float;\n" | 439 "precision mediump float;\n" |
| 416 "varying vec2 v_texCoord;\n" | 440 "varying vec2 v_texCoord;\n" |
| 441 "varying float v_alpha;\n" | |
| 417 "uniform vec4 texTransform;\n" | 442 "uniform vec4 texTransform;\n" |
| 418 "uniform sampler2DRect s_texture;\n" | 443 "uniform sampler2DRect s_texture;\n" |
| 419 "uniform float alpha;\n" | |
| 420 "void main()\n" | 444 "void main()\n" |
| 421 "{\n" | 445 "{\n" |
| 422 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex Transform.w - v_texCoord.y));\n" | 446 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex Transform.w - v_texCoord.y));\n" |
| 423 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo r.w) * alpha;\n" | 447 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo r.w) * v_alpha;\n" |
| 424 "}\n"; | 448 "}\n"; |
| 425 } | 449 } |
| 426 | 450 |
| 427 std::string FragmentShaderRGBATexRectAlpha::getShaderString() const | 451 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const |
| 428 { | 452 { |
| 429 return "#extension GL_ARB_texture_rectangle : require\n" | 453 return "#extension GL_ARB_texture_rectangle : require\n" |
| 430 "precision mediump float;\n" | 454 "precision mediump float;\n" |
| 431 "varying vec2 v_texCoord;\n" | 455 "varying vec2 v_texCoord;\n" |
| 456 "varying float v_alpha;\n" | |
| 432 "uniform sampler2DRect s_texture;\n" | 457 "uniform sampler2DRect s_texture;\n" |
| 433 "uniform float alpha;\n" | |
| 434 "void main()\n" | 458 "void main()\n" |
| 435 "{\n" | 459 "{\n" |
| 436 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | 460 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" |
| 437 " gl_FragColor = texColor * alpha;\n" | 461 " gl_FragColor = texColor * v_alpha;\n" |
| 438 "}\n"; | 462 "}\n"; |
| 439 } | 463 } |
| 440 | 464 |
| 441 std::string FragmentShaderRGBATexOpaque::getShaderString() const | 465 std::string FragmentShaderRGBATexOpaque::getShaderString() const |
| 442 { | 466 { |
| 443 return SHADER( | 467 return SHADER( |
| 444 precision mediump float; | 468 precision mediump float; |
| 445 varying vec2 v_texCoord; | 469 varying vec2 v_texCoord; |
| 446 uniform sampler2D s_texture; | 470 uniform sampler2D s_texture; |
| 447 void main() | 471 void main() |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 vec4 color2 = color; | 892 vec4 color2 = color; |
| 869 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; | 893 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; |
| 870 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 894 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 871 float picker = abs(coord.x - coord.y); | 895 float picker = abs(coord.x - coord.y); |
| 872 gl_FragColor = mix(color1, color2, picker) * alpha; | 896 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 873 } | 897 } |
| 874 ); | 898 ); |
| 875 } | 899 } |
| 876 | 900 |
| 877 } // namespace cc | 901 } // namespace cc |
| OLD | NEW |