| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 int* base_uniform_index) { | 53 int* base_uniform_index) { |
| 54 for (size_t i = 0; i < count; i++) { | 54 for (size_t i = 0; i < count; i++) { |
| 55 locations[i] = (*base_uniform_index)++; | 55 locations[i] = (*base_uniform_index)++; |
| 56 context->BindUniformLocationCHROMIUM(program, locations[i], uniforms[i]); | 56 context->BindUniformLocationCHROMIUM(program, locations[i], uniforms[i]); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 static std::string SetFragmentTexCoordPrecision( | 60 static std::string SetFragmentTexCoordPrecision( |
| 61 TexCoordPrecision requested_precision, | 61 TexCoordPrecision requested_precision, |
| 62 std::string shader_string) { | 62 std::string shader_string) { |
| 63 std::string prefix; |
| 63 switch (requested_precision) { | 64 switch (requested_precision) { |
| 64 case TEX_COORD_PRECISION_HIGH: | 65 case TEX_COORD_PRECISION_HIGH: |
| 65 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); | 66 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); |
| 66 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" | 67 prefix = |
| 67 " #define TexCoordPrecision highp\n" | 68 "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" |
| 68 "#else\n" | 69 " #define TexCoordPrecision highp\n" |
| 69 " #define TexCoordPrecision mediump\n" | 70 "#else\n" |
| 70 "#endif\n" + | 71 " #define TexCoordPrecision mediump\n" |
| 71 shader_string; | 72 "#endif\n"; |
| 73 break; |
| 72 case TEX_COORD_PRECISION_MEDIUM: | 74 case TEX_COORD_PRECISION_MEDIUM: |
| 73 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); | 75 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); |
| 74 return "#define TexCoordPrecision mediump\n" + shader_string; | 76 prefix = "#define TexCoordPrecision mediump\n"; |
| 77 break; |
| 75 case TEX_COORD_PRECISION_NA: | 78 case TEX_COORD_PRECISION_NA: |
| 76 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos); | 79 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos); |
| 77 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); | 80 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); |
| 78 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); | 81 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); |
| 79 return shader_string; | 82 break; |
| 80 default: | 83 default: |
| 81 NOTREACHED(); | 84 NOTREACHED(); |
| 82 break; | 85 break; |
| 83 } | 86 } |
| 84 return shader_string; | 87 std::string lut_prefix = "#define LutLookup texture2D\n"; |
| 88 return prefix + lut_prefix + shader_string; |
| 85 } | 89 } |
| 86 | 90 |
| 87 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, | 91 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, |
| 88 int* highp_threshold_cache, | 92 int* highp_threshold_cache, |
| 89 int highp_threshold_min, | 93 int highp_threshold_min, |
| 90 int x, | 94 int x, |
| 91 int y) { | 95 int y) { |
| 92 if (*highp_threshold_cache == 0) { | 96 if (*highp_threshold_cache == 0) { |
| 93 // Initialize range and precision with minimum spec values for when | 97 // Initialize range and precision with minimum spec values for when |
| 94 // GetShaderPrecisionFormat is a test stub. | 98 // GetShaderPrecisionFormat is a test stub. |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 HDR("uniform sampler2D lut_texture;"); | 881 HDR("uniform sampler2D lut_texture;"); |
| 878 HDR("uniform float lut_size;"); | 882 HDR("uniform float lut_size;"); |
| 879 HDR("vec4 LUT(sampler2D sampler, vec3 pos, float size) {"); | 883 HDR("vec4 LUT(sampler2D sampler, vec3 pos, float size) {"); |
| 880 HDR(" pos *= size - 1.0;"); | 884 HDR(" pos *= size - 1.0;"); |
| 881 HDR(" // Select layer"); | 885 HDR(" // Select layer"); |
| 882 HDR(" float layer = min(floor(pos.z), size - 2.0);"); | 886 HDR(" float layer = min(floor(pos.z), size - 2.0);"); |
| 883 HDR(" // Compress the xy coordinates so they stay within"); | 887 HDR(" // Compress the xy coordinates so they stay within"); |
| 884 HDR(" // [0.5 .. 31.5] / N (assuming a LUT size of 17^3)"); | 888 HDR(" // [0.5 .. 31.5] / N (assuming a LUT size of 17^3)"); |
| 885 HDR(" pos.xy = (pos.xy + vec2(0.5)) / size;"); | 889 HDR(" pos.xy = (pos.xy + vec2(0.5)) / size;"); |
| 886 HDR(" pos.y = (pos.y + layer) / size;"); | 890 HDR(" pos.y = (pos.y + layer) / size;"); |
| 887 HDR(" return mix(texture2D(sampler, pos.xy),"); | 891 HDR(" return mix(LutLookup(sampler, pos.xy),"); |
| 888 HDR(" texture2D(sampler, pos.xy + vec2(0, 1.0 / size)),"); | 892 HDR(" LutLookup(sampler, pos.xy + vec2(0, 1.0 / size)),"); |
| 889 HDR(" pos.z - layer);"); | 893 HDR(" pos.z - layer);"); |
| 890 HDR("}"); | 894 HDR("}"); |
| 891 SRC("texColor.xyz = LUT(lut_texture, texColor.xyz, lut_size).xyz;"); | 895 SRC("texColor.xyz = LUT(lut_texture, texColor.xyz, lut_size).xyz;"); |
| 892 } | 896 } |
| 893 | 897 |
| 894 // Apply the color matrix to texColor. | 898 // Apply the color matrix to texColor. |
| 895 if (has_color_matrix_) { | 899 if (has_color_matrix_) { |
| 896 HDR("uniform mat4 colorMatrix;"); | 900 HDR("uniform mat4 colorMatrix;"); |
| 897 HDR("uniform vec4 colorOffset;"); | 901 HDR("uniform vec4 colorOffset;"); |
| 898 SRC("// Apply color matrix"); | 902 SRC("// Apply color matrix"); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 else | 991 else |
| 988 SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);"); | 992 SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);"); |
| 989 break; | 993 break; |
| 990 } | 994 } |
| 991 source += "}\n"; | 995 source += "}\n"; |
| 992 | 996 |
| 993 return header + source; | 997 return header + source; |
| 994 } | 998 } |
| 995 | 999 |
| 996 } // namespace cc | 1000 } // namespace cc |
| OLD | NEW |