| 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" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 static std::string SetVertexTexCoordPrecision(const char* shader_string) { | 72 static std::string SetVertexTexCoordPrecision(const char* shader_string) { |
| 73 // We unconditionally use highp in the vertex shader since | 73 // We unconditionally use highp in the vertex shader since |
| 74 // we are unlikely to be vertex shader bound when drawing large quads. | 74 // we are unlikely to be vertex shader bound when drawing large quads. |
| 75 // Also, some vertex shaders mutate the texture coordinate in such a | 75 // Also, some vertex shaders mutate the texture coordinate in such a |
| 76 // way that the effective precision might be lower than expected. | 76 // way that the effective precision might be lower than expected. |
| 77 return "#define TexCoordPrecision highp\n" + | 77 return "#define TexCoordPrecision highp\n" + |
| 78 std::string(shader_string); | 78 std::string(shader_string); |
| 79 } | 79 } |
| 80 | 80 |
| 81 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, | 81 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, |
| 82 int *highp_threshold_cache, |
| 82 int highp_threshold_min, | 83 int highp_threshold_min, |
| 83 int x, int y) { | 84 int x, int y) { |
| 84 // Initialize range and precision with minimum spec values for when | 85 if (*highp_threshold_cache == 0) { |
| 85 // GetShaderPrecisionFormat is a test stub. | 86 // Initialize range and precision with minimum spec values for when |
| 86 // TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat | 87 // GetShaderPrecisionFormat is a test stub. |
| 87 // everywhere. | 88 // TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat |
| 88 GLint range[2] = { 14, 14 }; | 89 // everywhere. |
| 89 GLint precision = 10; | 90 GLint range[2] = { 14, 14 }; |
| 90 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER, | 91 GLint precision = 10; |
| 91 GL_MEDIUM_FLOAT, | 92 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER, |
| 92 range, &precision)); | 93 GL_MEDIUM_FLOAT, |
| 93 int highp_threshold = std::max(1 << precision, highp_threshold_min); | 94 range, &precision)); |
| 95 *highp_threshold_cache = 1 << precision; |
| 96 } |
| 97 |
| 98 int highp_threshold = std::max(*highp_threshold_cache, highp_threshold_min); |
| 94 if (x > highp_threshold || y > highp_threshold) | 99 if (x > highp_threshold || y > highp_threshold) |
| 95 return TexCoordPrecisionHigh; | 100 return TexCoordPrecisionHigh; |
| 96 return TexCoordPrecisionMedium; | 101 return TexCoordPrecisionMedium; |
| 97 } | 102 } |
| 98 | 103 |
| 99 } // namespace | 104 } // namespace |
| 100 | 105 |
| 101 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, | 106 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, |
| 107 int *highp_threshold_cache, |
| 102 int highp_threshold_min, | 108 int highp_threshold_min, |
| 103 gfx::Point max_coordinate) { | 109 gfx::Point max_coordinate) { |
| 104 return TexCoordPrecisionRequired(context, highp_threshold_min, | 110 return TexCoordPrecisionRequired(context, |
| 111 highp_threshold_cache, highp_threshold_min, |
| 105 max_coordinate.x(), max_coordinate.y()); | 112 max_coordinate.x(), max_coordinate.y()); |
| 106 } | 113 } |
| 107 | 114 |
| 108 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, | 115 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, |
| 116 int *highp_threshold_cache, |
| 109 int highp_threshold_min, | 117 int highp_threshold_min, |
| 110 gfx::Size max_size) { | 118 gfx::Size max_size) { |
| 111 return TexCoordPrecisionRequired(context, highp_threshold_min, | 119 return TexCoordPrecisionRequired(context, |
| 120 highp_threshold_cache, highp_threshold_min, |
| 112 max_size.width(), max_size.height()); | 121 max_size.width(), max_size.height()); |
| 113 } | 122 } |
| 114 | 123 |
| 115 VertexShaderPosTex::VertexShaderPosTex() | 124 VertexShaderPosTex::VertexShaderPosTex() |
| 116 : matrix_location_(-1) {} | 125 : matrix_location_(-1) {} |
| 117 | 126 |
| 118 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, | 127 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, |
| 119 unsigned program, | 128 unsigned program, |
| 120 bool using_bind_uniform, | 129 bool using_bind_uniform, |
| 121 int* base_uniform_index) { | 130 int* base_uniform_index) { |
| (...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 vec2 texCoord = | 1438 vec2 texCoord = |
| 1430 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 1439 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
| 1431 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1440 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 1432 float picker = abs(coord.x - coord.y); | 1441 float picker = abs(coord.x - coord.y); |
| 1433 gl_FragColor = mix(color1, color2, picker) * alpha; | 1442 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 1434 } | 1443 } |
| 1435 ); // NOLINT(whitespace/parens) | 1444 ); // NOLINT(whitespace/parens) |
| 1436 } | 1445 } |
| 1437 | 1446 |
| 1438 } // namespace cc | 1447 } // namespace cc |
| OLD | NEW |