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) { |
vangelis
2013/05/03 22:08:33
I think you'll need to add:
|| *highp_threashold_
| |
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 static GLint range[2] = { 14, 14 }; |
90 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER, | 91 static GLint precision = 10; |
vangelis
2013/05/03 22:08:33
Do these need to be static?
| |
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)); |
94 if (x > highp_threshold || y > highp_threshold) | 95 *highp_threshold_cache = std::max(1 << precision, highp_threshold_min); |
96 } | |
97 | |
98 if (x > *highp_threshold_cache || y > *highp_threshold_cache) | |
95 return TexCoordPrecisionHigh; | 99 return TexCoordPrecisionHigh; |
96 return TexCoordPrecisionMedium; | 100 return TexCoordPrecisionMedium; |
97 } | 101 } |
98 | 102 |
99 } // namespace | 103 } // namespace |
100 | 104 |
101 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, | 105 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, |
106 int *highp_threshold_cache, | |
102 int highp_threshold_min, | 107 int highp_threshold_min, |
103 gfx::Point max_coordinate) { | 108 gfx::Point max_coordinate) { |
104 return TexCoordPrecisionRequired(context, highp_threshold_min, | 109 return TexCoordPrecisionRequired(context, |
110 highp_threshold_cache, highp_threshold_min, | |
105 max_coordinate.x(), max_coordinate.y()); | 111 max_coordinate.x(), max_coordinate.y()); |
106 } | 112 } |
107 | 113 |
108 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, | 114 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, |
115 int *highp_threshold_cache, | |
109 int highp_threshold_min, | 116 int highp_threshold_min, |
110 gfx::Size max_size) { | 117 gfx::Size max_size) { |
111 return TexCoordPrecisionRequired(context, highp_threshold_min, | 118 return TexCoordPrecisionRequired(context, |
119 highp_threshold_cache, highp_threshold_min, | |
112 max_size.width(), max_size.height()); | 120 max_size.width(), max_size.height()); |
113 } | 121 } |
114 | 122 |
115 VertexShaderPosTex::VertexShaderPosTex() | 123 VertexShaderPosTex::VertexShaderPosTex() |
116 : matrix_location_(-1) {} | 124 : matrix_location_(-1) {} |
117 | 125 |
118 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, | 126 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, |
119 unsigned program, | 127 unsigned program, |
120 bool using_bind_uniform, | 128 bool using_bind_uniform, |
121 int* base_uniform_index) { | 129 int* base_uniform_index) { |
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1429 vec2 texCoord = | 1437 vec2 texCoord = |
1430 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 1438 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
1431 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1439 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1432 float picker = abs(coord.x - coord.y); | 1440 float picker = abs(coord.x - coord.y); |
1433 gl_FragColor = mix(color1, color2, picker) * alpha; | 1441 gl_FragColor = mix(color1, color2, picker) * alpha; |
1434 } | 1442 } |
1435 ); // NOLINT(whitespace/parens) | 1443 ); // NOLINT(whitespace/parens) |
1436 } | 1444 } |
1437 | 1445 |
1438 } // namespace cc | 1446 } // namespace cc |
OLD | NEW |