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" |
11 #include "cc/output/gl_renderer.h" // For the GLC() macro. | 11 #include "cc/output/gl_renderer.h" // For the GLC() macro. |
12 #include "gpu/command_buffer/client/gles2_interface.h" | 12 #include "gpu/command_buffer/client/gles2_interface.h" |
13 | 13 |
14 #define SHADER0(Src) #Src | 14 #define SHADER0(Src) #Src |
15 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src)) | 15 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src)) |
16 #define FRAGMENT_SHADER(Src) SetFragmentTexCoordPrecision( \ | 16 #define FRAGMENT_SHADER(Src) \ |
17 precision, SetFragmentSamplerType(sampler, SHADER0(Src))) | 17 SetFragmentTexCoordPrecision(precision, \ |
18 SetFragmentSamplerType(sampler, SHADER0(Src))) | |
18 | 19 |
19 using gpu::gles2::GLES2Interface; | 20 using gpu::gles2::GLES2Interface; |
20 | 21 |
21 namespace cc { | 22 namespace cc { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 static void GetProgramUniformLocations(GLES2Interface* context, | 26 static void GetProgramUniformLocations(GLES2Interface* context, |
26 unsigned program, | 27 unsigned program, |
27 size_t count, | 28 size_t count, |
28 const char** uniforms, | 29 const char** uniforms, |
29 int* locations, | 30 int* locations, |
30 int* base_uniform_index) { | 31 int* base_uniform_index) { |
31 for (size_t i = 0; i < count; i++) { | 32 for (size_t i = 0; i < count; i++) { |
32 locations[i] = (*base_uniform_index)++; | 33 locations[i] = (*base_uniform_index)++; |
33 context->BindUniformLocationCHROMIUM(program, locations[i], uniforms[i]); | 34 context->BindUniformLocationCHROMIUM(program, locations[i], uniforms[i]); |
34 } | 35 } |
35 } | 36 } |
36 | 37 |
37 static std::string SetFragmentTexCoordPrecision( | 38 static std::string SetFragmentTexCoordPrecision( |
38 TexCoordPrecision requested_precision, std::string shader_string) { | 39 TexCoordPrecision requested_precision, |
40 std::string shader_string) { | |
39 switch (requested_precision) { | 41 switch (requested_precision) { |
40 case TexCoordPrecisionHigh: | 42 case TexCoordPrecisionHigh: |
41 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); | 43 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); |
42 return | 44 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" |
43 "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" | 45 " #define TexCoordPrecision highp\n" |
44 " #define TexCoordPrecision highp\n" | 46 "#else\n" |
45 "#else\n" | 47 " #define TexCoordPrecision mediump\n" |
46 " #define TexCoordPrecision mediump\n" | 48 "#endif\n" + |
47 "#endif\n" + | 49 shader_string; |
48 shader_string; | |
49 case TexCoordPrecisionMedium: | 50 case TexCoordPrecisionMedium: |
50 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); | 51 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); |
51 return "#define TexCoordPrecision mediump\n" + | 52 return "#define TexCoordPrecision mediump\n" + shader_string; |
52 shader_string; | |
53 case TexCoordPrecisionNA: | 53 case TexCoordPrecisionNA: |
54 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos); | 54 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos); |
55 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); | 55 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); |
56 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); | 56 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); |
57 return shader_string; | 57 return shader_string; |
58 default: | 58 default: |
59 NOTREACHED(); | 59 NOTREACHED(); |
60 break; | 60 break; |
61 } | 61 } |
62 return shader_string; | 62 return shader_string; |
63 } | 63 } |
64 | 64 |
65 static std::string SetVertexTexCoordPrecision(const char* shader_string) { | 65 static std::string SetVertexTexCoordPrecision(const char* shader_string) { |
66 // We unconditionally use highp in the vertex shader since | 66 // We unconditionally use highp in the vertex shader since |
67 // we are unlikely to be vertex shader bound when drawing large quads. | 67 // we are unlikely to be vertex shader bound when drawing large quads. |
68 // Also, some vertex shaders mutate the texture coordinate in such a | 68 // Also, some vertex shaders mutate the texture coordinate in such a |
69 // way that the effective precision might be lower than expected. | 69 // way that the effective precision might be lower than expected. |
70 return "#define TexCoordPrecision highp\n" + | 70 return "#define TexCoordPrecision highp\n" + std::string(shader_string); |
71 std::string(shader_string); | |
72 } | 71 } |
73 | 72 |
74 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, | 73 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, |
75 int *highp_threshold_cache, | 74 int* highp_threshold_cache, |
76 int highp_threshold_min, | 75 int highp_threshold_min, |
77 int x, int y) { | 76 int x, |
77 int y) { | |
78 if (*highp_threshold_cache == 0) { | 78 if (*highp_threshold_cache == 0) { |
79 // Initialize range and precision with minimum spec values for when | 79 // Initialize range and precision with minimum spec values for when |
80 // GetShaderPrecisionFormat is a test stub. | 80 // GetShaderPrecisionFormat is a test stub. |
81 // TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat | 81 // TODO(brianderson): Implement better stubs of GetShaderPrecisionFormat |
82 // everywhere. | 82 // everywhere. |
83 GLint range[2] = { 14, 14 }; | 83 GLint range[2] = {14, 14}; |
84 GLint precision = 10; | 84 GLint precision = 10; |
85 GLC(context, context->GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, | 85 GLC(context, |
86 GL_MEDIUM_FLOAT, | 86 context->GetShaderPrecisionFormat( |
87 range, &precision)); | 87 GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, range, &precision)); |
88 *highp_threshold_cache = 1 << precision; | 88 *highp_threshold_cache = 1 << precision; |
89 } | 89 } |
90 | 90 |
91 int highp_threshold = std::max(*highp_threshold_cache, highp_threshold_min); | 91 int highp_threshold = std::max(*highp_threshold_cache, highp_threshold_min); |
92 if (x > highp_threshold || y > highp_threshold) | 92 if (x > highp_threshold || y > highp_threshold) |
93 return TexCoordPrecisionHigh; | 93 return TexCoordPrecisionHigh; |
94 return TexCoordPrecisionMedium; | 94 return TexCoordPrecisionMedium; |
95 } | 95 } |
96 | 96 |
97 static std::string SetFragmentSamplerType( | 97 static std::string SetFragmentSamplerType(SamplerType requested_type, |
98 SamplerType requested_type, std::string shader_string) { | 98 std::string shader_string) { |
99 switch (requested_type) { | 99 switch (requested_type) { |
100 case SamplerType2D: | 100 case SamplerType2D: |
101 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); | 101 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); |
102 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); | 102 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); |
103 return | 103 return "#define SamplerType sampler2D\n" |
104 "#define SamplerType sampler2D\n" | 104 "#define TextureLookup texture2D\n" + |
105 "#define TextureLookup texture2D\n" + | 105 shader_string; |
106 shader_string; | |
107 case SamplerType2DRect: | 106 case SamplerType2DRect: |
108 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); | 107 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); |
109 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); | 108 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); |
110 return | 109 return "#extension GL_ARB_texture_rectangle : require\n" |
111 "#extension GL_ARB_texture_rectangle : require\n" | 110 "#define SamplerType sampler2DRect\n" |
112 "#define SamplerType sampler2DRect\n" | 111 "#define TextureLookup texture2DRect\n" + |
113 "#define TextureLookup texture2DRect\n" + | 112 shader_string; |
114 shader_string; | |
115 case SamplerTypeExternalOES: | 113 case SamplerTypeExternalOES: |
116 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); | 114 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); |
117 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); | 115 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); |
118 return | 116 return "#extension GL_OES_EGL_image_external : require\n" |
119 "#extension GL_OES_EGL_image_external : require\n" | 117 "#define SamplerType samplerExternalOES\n" |
120 "#define SamplerType samplerExternalOES\n" | 118 "#define TextureLookup texture2D\n" + |
121 "#define TextureLookup texture2D\n" + | 119 shader_string; |
122 shader_string; | |
123 case SamplerTypeNA: | 120 case SamplerTypeNA: |
124 DCHECK_EQ(shader_string.find("SamplerType"), std::string::npos); | 121 DCHECK_EQ(shader_string.find("SamplerType"), std::string::npos); |
125 DCHECK_EQ(shader_string.find("TextureLookup"), std::string::npos); | 122 DCHECK_EQ(shader_string.find("TextureLookup"), std::string::npos); |
126 return shader_string; | 123 return shader_string; |
127 default: | 124 default: |
128 NOTREACHED(); | 125 NOTREACHED(); |
129 break; | 126 break; |
130 } | 127 } |
131 return shader_string; | 128 return shader_string; |
132 } | 129 } |
133 | 130 |
134 } // namespace | 131 } // namespace |
135 | 132 |
136 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, | 133 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, |
137 int* highp_threshold_cache, | 134 int* highp_threshold_cache, |
138 int highp_threshold_min, | 135 int highp_threshold_min, |
139 const gfx::Point& max_coordinate) { | 136 const gfx::Point& max_coordinate) { |
140 return TexCoordPrecisionRequired(context, | 137 return TexCoordPrecisionRequired(context, |
141 highp_threshold_cache, highp_threshold_min, | 138 highp_threshold_cache, |
142 max_coordinate.x(), max_coordinate.y()); | 139 highp_threshold_min, |
140 max_coordinate.x(), | |
141 max_coordinate.y()); | |
143 } | 142 } |
144 | 143 |
145 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, | 144 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, |
146 int *highp_threshold_cache, | 145 int* highp_threshold_cache, |
147 int highp_threshold_min, | 146 int highp_threshold_min, |
148 const gfx::Size& max_size) { | 147 const gfx::Size& max_size) { |
149 return TexCoordPrecisionRequired(context, | 148 return TexCoordPrecisionRequired(context, |
150 highp_threshold_cache, highp_threshold_min, | 149 highp_threshold_cache, |
151 max_size.width(), max_size.height()); | 150 highp_threshold_min, |
151 max_size.width(), | |
152 max_size.height()); | |
152 } | 153 } |
153 | 154 |
154 VertexShaderPosTex::VertexShaderPosTex() | 155 VertexShaderPosTex::VertexShaderPosTex() : matrix_location_(-1) { |
155 : matrix_location_(-1) {} | 156 } |
156 | 157 |
157 void VertexShaderPosTex::Init(GLES2Interface* context, | 158 void VertexShaderPosTex::Init(GLES2Interface* context, |
158 unsigned program, | 159 unsigned program, |
159 int* base_uniform_index) { | 160 int* base_uniform_index) { |
160 static const char* uniforms[] = { | 161 static const char* uniforms[] = { |
161 "matrix", | 162 "matrix", |
162 }; | 163 }; |
163 int locations[arraysize(uniforms)]; | 164 int locations[arraysize(uniforms)]; |
164 | 165 |
165 GetProgramUniformLocations(context, | 166 GetProgramUniformLocations(context, |
166 program, | 167 program, |
167 arraysize(uniforms), | 168 arraysize(uniforms), |
168 uniforms, | 169 uniforms, |
169 locations, | 170 locations, |
170 base_uniform_index); | 171 base_uniform_index); |
171 matrix_location_ = locations[0]; | 172 matrix_location_ = locations[0]; |
172 } | 173 } |
173 | 174 |
174 std::string VertexShaderPosTex::GetShaderString() const { | 175 std::string VertexShaderPosTex::GetShaderString() const { |
176 // clang-format off | |
175 return VERTEX_SHADER( | 177 return VERTEX_SHADER( |
176 attribute vec4 a_position; | 178 attribute vec4 a_position; |
177 attribute TexCoordPrecision vec2 a_texCoord; | 179 attribute TexCoordPrecision vec2 a_texCoord; |
178 uniform mat4 matrix; | 180 uniform mat4 matrix; |
179 varying TexCoordPrecision vec2 v_texCoord; | 181 varying TexCoordPrecision vec2 v_texCoord; |
180 void main() { | 182 void main() { |
181 gl_Position = matrix * a_position; | 183 gl_Position = matrix * a_position; |
182 v_texCoord = a_texCoord; | 184 v_texCoord = a_texCoord; |
183 } | 185 } |
184 ); // NOLINT(whitespace/parens) | 186 ); // NOLINT(whitespace/parens) |
187 // clang-format on | |
185 } | 188 } |
186 | 189 |
187 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() | 190 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() |
188 : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) {} | 191 : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) { |
192 } | |
189 | 193 |
190 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, | 194 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, |
191 unsigned program, | 195 unsigned program, |
192 int* base_uniform_index) { | 196 int* base_uniform_index) { |
193 static const char* uniforms[] = { | 197 static const char* uniforms[] = { |
194 "matrix", | 198 "matrix", "texScale", "texOffset", |
195 "texScale", | |
196 "texOffset", | |
197 }; | 199 }; |
198 int locations[arraysize(uniforms)]; | 200 int locations[arraysize(uniforms)]; |
199 | 201 |
200 GetProgramUniformLocations(context, | 202 GetProgramUniformLocations(context, |
201 program, | 203 program, |
202 arraysize(uniforms), | 204 arraysize(uniforms), |
203 uniforms, | 205 uniforms, |
204 locations, | 206 locations, |
205 base_uniform_index); | 207 base_uniform_index); |
206 matrix_location_ = locations[0]; | 208 matrix_location_ = locations[0]; |
207 tex_scale_location_ = locations[1]; | 209 tex_scale_location_ = locations[1]; |
208 tex_offset_location_ = locations[2]; | 210 tex_offset_location_ = locations[2]; |
209 } | 211 } |
210 | 212 |
211 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { | 213 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { |
214 // clang-format off | |
212 return VERTEX_SHADER( | 215 return VERTEX_SHADER( |
213 precision mediump float; | 216 precision mediump float; |
214 attribute vec4 a_position; | 217 attribute vec4 a_position; |
215 attribute TexCoordPrecision vec2 a_texCoord; | 218 attribute TexCoordPrecision vec2 a_texCoord; |
216 uniform mat4 matrix; | 219 uniform mat4 matrix; |
217 varying TexCoordPrecision vec2 v_texCoord; | 220 varying TexCoordPrecision vec2 v_texCoord; |
218 uniform TexCoordPrecision vec2 texScale; | 221 uniform TexCoordPrecision vec2 texScale; |
219 uniform TexCoordPrecision vec2 texOffset; | 222 uniform TexCoordPrecision vec2 texOffset; |
220 void main() { | 223 void main() { |
221 gl_Position = matrix * a_position; | 224 gl_Position = matrix * a_position; |
222 v_texCoord = a_texCoord * texScale + texOffset; | 225 v_texCoord = a_texCoord * texScale + texOffset; |
223 } | 226 } |
224 ); // NOLINT(whitespace/parens) | 227 ); // NOLINT(whitespace/parens) |
228 // clang-format on | |
225 } | 229 } |
226 | 230 |
227 VertexShaderPos::VertexShaderPos() | 231 VertexShaderPos::VertexShaderPos() : matrix_location_(-1) { |
228 : matrix_location_(-1) {} | 232 } |
229 | 233 |
230 void VertexShaderPos::Init(GLES2Interface* context, | 234 void VertexShaderPos::Init(GLES2Interface* context, |
231 unsigned program, | 235 unsigned program, |
232 int* base_uniform_index) { | 236 int* base_uniform_index) { |
233 static const char* uniforms[] = { | 237 static const char* uniforms[] = { |
234 "matrix", | 238 "matrix", |
235 }; | 239 }; |
236 int locations[arraysize(uniforms)]; | 240 int locations[arraysize(uniforms)]; |
237 | 241 |
238 GetProgramUniformLocations(context, | 242 GetProgramUniformLocations(context, |
239 program, | 243 program, |
240 arraysize(uniforms), | 244 arraysize(uniforms), |
241 uniforms, | 245 uniforms, |
242 locations, | 246 locations, |
243 base_uniform_index); | 247 base_uniform_index); |
244 matrix_location_ = locations[0]; | 248 matrix_location_ = locations[0]; |
245 } | 249 } |
246 | 250 |
247 std::string VertexShaderPos::GetShaderString() const { | 251 std::string VertexShaderPos::GetShaderString() const { |
252 // clang-format off | |
248 return VERTEX_SHADER( | 253 return VERTEX_SHADER( |
249 attribute vec4 a_position; | 254 attribute vec4 a_position; |
250 uniform mat4 matrix; | 255 uniform mat4 matrix; |
251 void main() { | 256 void main() { |
252 gl_Position = matrix * a_position; | 257 gl_Position = matrix * a_position; |
253 } | 258 } |
254 ); // NOLINT(whitespace/parens) | 259 ); // NOLINT(whitespace/parens) |
260 // clang-format on | |
255 } | 261 } |
256 | 262 |
257 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | 263 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
258 : matrix_location_(-1), | 264 : matrix_location_(-1), |
259 tex_transform_location_(-1), | 265 tex_transform_location_(-1), |
260 vertex_opacity_location_(-1) {} | 266 vertex_opacity_location_(-1) { |
267 } | |
261 | 268 |
262 void VertexShaderPosTexTransform::Init(GLES2Interface* context, | 269 void VertexShaderPosTexTransform::Init(GLES2Interface* context, |
263 unsigned program, | 270 unsigned program, |
264 int* base_uniform_index) { | 271 int* base_uniform_index) { |
265 static const char* uniforms[] = { | 272 static const char* uniforms[] = { |
266 "matrix", | 273 "matrix", "texTransform", "opacity", |
267 "texTransform", | |
268 "opacity", | |
269 }; | 274 }; |
270 int locations[arraysize(uniforms)]; | 275 int locations[arraysize(uniforms)]; |
271 | 276 |
272 GetProgramUniformLocations(context, | 277 GetProgramUniformLocations(context, |
273 program, | 278 program, |
274 arraysize(uniforms), | 279 arraysize(uniforms), |
275 uniforms, | 280 uniforms, |
276 locations, | 281 locations, |
277 base_uniform_index); | 282 base_uniform_index); |
278 matrix_location_ = locations[0]; | 283 matrix_location_ = locations[0]; |
279 tex_transform_location_ = locations[1]; | 284 tex_transform_location_ = locations[1]; |
280 vertex_opacity_location_ = locations[2]; | 285 vertex_opacity_location_ = locations[2]; |
281 } | 286 } |
282 | 287 |
283 std::string VertexShaderPosTexTransform::GetShaderString() const { | 288 std::string VertexShaderPosTexTransform::GetShaderString() const { |
289 // clang-format off | |
284 return VERTEX_SHADER( | 290 return VERTEX_SHADER( |
285 attribute vec4 a_position; | 291 attribute vec4 a_position; |
286 attribute TexCoordPrecision vec2 a_texCoord; | 292 attribute TexCoordPrecision vec2 a_texCoord; |
287 attribute float a_index; | 293 attribute float a_index; |
288 uniform mat4 matrix[8]; | 294 uniform mat4 matrix[8]; |
289 uniform TexCoordPrecision vec4 texTransform[8]; | 295 uniform TexCoordPrecision vec4 texTransform[8]; |
290 uniform float opacity[32]; | 296 uniform float opacity[32]; |
291 varying TexCoordPrecision vec2 v_texCoord; | 297 varying TexCoordPrecision vec2 v_texCoord; |
292 varying float v_alpha; | 298 varying float v_alpha; |
293 void main() { | 299 void main() { |
294 int quad_index = int(a_index * 0.25); // NOLINT | 300 int quad_index = int(a_index * 0.25); // NOLINT |
295 gl_Position = matrix[quad_index] * a_position; | 301 gl_Position = matrix[quad_index] * a_position; |
296 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; | 302 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; |
297 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 303 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
298 v_alpha = opacity[int(a_index)]; // NOLINT | 304 v_alpha = opacity[int(a_index)]; // NOLINT |
299 } | 305 } |
300 ); // NOLINT(whitespace/parens) | 306 ); // NOLINT(whitespace/parens) |
307 // clang-format on | |
301 } | 308 } |
302 | 309 |
303 std::string VertexShaderPosTexIdentity::GetShaderString() const { | 310 std::string VertexShaderPosTexIdentity::GetShaderString() const { |
311 // clang-format off | |
304 return VERTEX_SHADER( | 312 return VERTEX_SHADER( |
305 attribute vec4 a_position; | 313 attribute vec4 a_position; |
306 varying TexCoordPrecision vec2 v_texCoord; | 314 varying TexCoordPrecision vec2 v_texCoord; |
307 void main() { | 315 void main() { |
308 gl_Position = a_position; | 316 gl_Position = a_position; |
309 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 317 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
310 } | 318 } |
311 ); // NOLINT(whitespace/parens) | 319 ); // NOLINT(whitespace/parens) |
320 // clang-format on | |
312 } | 321 } |
313 | 322 |
314 VertexShaderQuad::VertexShaderQuad() | 323 VertexShaderQuad::VertexShaderQuad() |
315 : matrix_location_(-1), | 324 : matrix_location_(-1), quad_location_(-1) { |
316 quad_location_(-1) {} | 325 } |
317 | 326 |
318 void VertexShaderQuad::Init(GLES2Interface* context, | 327 void VertexShaderQuad::Init(GLES2Interface* context, |
319 unsigned program, | 328 unsigned program, |
320 int* base_uniform_index) { | 329 int* base_uniform_index) { |
321 static const char* uniforms[] = { | 330 static const char* uniforms[] = { |
322 "matrix", | 331 "matrix", "quad", |
323 "quad", | |
324 }; | 332 }; |
325 int locations[arraysize(uniforms)]; | 333 int locations[arraysize(uniforms)]; |
326 | 334 |
327 GetProgramUniformLocations(context, | 335 GetProgramUniformLocations(context, |
328 program, | 336 program, |
329 arraysize(uniforms), | 337 arraysize(uniforms), |
330 uniforms, | 338 uniforms, |
331 locations, | 339 locations, |
332 base_uniform_index); | 340 base_uniform_index); |
333 matrix_location_ = locations[0]; | 341 matrix_location_ = locations[0]; |
334 quad_location_ = locations[1]; | 342 quad_location_ = locations[1]; |
335 } | 343 } |
336 | 344 |
337 std::string VertexShaderQuad::GetShaderString() const { | 345 std::string VertexShaderQuad::GetShaderString() const { |
338 #if defined(OS_ANDROID) | 346 #if defined(OS_ANDROID) |
339 // TODO(epenner): Find the cause of this 'quad' uniform | 347 // TODO(epenner): Find the cause of this 'quad' uniform |
340 // being missing if we don't add dummy variables. | 348 // being missing if we don't add dummy variables. |
341 // http://crbug.com/240602 | 349 // http://crbug.com/240602 |
350 // clang-format off | |
342 return VERTEX_SHADER( | 351 return VERTEX_SHADER( |
343 attribute TexCoordPrecision vec4 a_position; | 352 attribute TexCoordPrecision vec4 a_position; |
344 attribute float a_index; | 353 attribute float a_index; |
345 uniform mat4 matrix; | 354 uniform mat4 matrix; |
346 uniform TexCoordPrecision vec2 quad[4]; | 355 uniform TexCoordPrecision vec2 quad[4]; |
347 uniform TexCoordPrecision vec2 dummy_uniform; | 356 uniform TexCoordPrecision vec2 dummy_uniform; |
348 varying TexCoordPrecision vec2 dummy_varying; | 357 varying TexCoordPrecision vec2 dummy_varying; |
349 void main() { | 358 void main() { |
350 vec2 pos = quad[int(a_index)]; // NOLINT | 359 vec2 pos = quad[int(a_index)]; // NOLINT |
351 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 360 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
352 dummy_varying = dummy_uniform; | 361 dummy_varying = dummy_uniform; |
353 } | 362 } |
354 ); // NOLINT(whitespace/parens) | 363 ); // NOLINT(whitespace/parens) |
364 // clang-format on | |
danakj
2014/10/16 19:25:11
why is this at column 0 :(
| |
355 #else | 365 #else |
366 // clang-format off | |
356 return VERTEX_SHADER( | 367 return VERTEX_SHADER( |
357 attribute TexCoordPrecision vec4 a_position; | 368 attribute TexCoordPrecision vec4 a_position; |
358 attribute float a_index; | 369 attribute float a_index; |
359 uniform mat4 matrix; | 370 uniform mat4 matrix; |
360 uniform TexCoordPrecision vec2 quad[4]; | 371 uniform TexCoordPrecision vec2 quad[4]; |
361 void main() { | 372 void main() { |
362 vec2 pos = quad[int(a_index)]; // NOLINT | 373 vec2 pos = quad[int(a_index)]; // NOLINT |
363 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 374 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
364 } | 375 } |
365 ); // NOLINT(whitespace/parens) | 376 ); // NOLINT(whitespace/parens) |
377 // clang-format on | |
danakj
2014/10/16 19:25:10
and this? :(
| |
366 #endif | 378 #endif |
367 } | 379 } |
368 | 380 |
369 VertexShaderQuadAA::VertexShaderQuadAA() | 381 VertexShaderQuadAA::VertexShaderQuadAA() |
370 : matrix_location_(-1), | 382 : matrix_location_(-1), |
371 viewport_location_(-1), | 383 viewport_location_(-1), |
372 quad_location_(-1), | 384 quad_location_(-1), |
373 edge_location_(-1) {} | 385 edge_location_(-1) { |
386 } | |
374 | 387 |
375 void VertexShaderQuadAA::Init(GLES2Interface* context, | 388 void VertexShaderQuadAA::Init(GLES2Interface* context, |
376 unsigned program, | 389 unsigned program, |
377 int* base_uniform_index) { | 390 int* base_uniform_index) { |
378 static const char* uniforms[] = { | 391 static const char* uniforms[] = { |
379 "matrix", | 392 "matrix", "viewport", "quad", "edge", |
380 "viewport", | |
381 "quad", | |
382 "edge", | |
383 }; | 393 }; |
384 int locations[arraysize(uniforms)]; | 394 int locations[arraysize(uniforms)]; |
385 | 395 |
386 GetProgramUniformLocations(context, | 396 GetProgramUniformLocations(context, |
387 program, | 397 program, |
388 arraysize(uniforms), | 398 arraysize(uniforms), |
389 uniforms, | 399 uniforms, |
390 locations, | 400 locations, |
391 base_uniform_index); | 401 base_uniform_index); |
392 matrix_location_ = locations[0]; | 402 matrix_location_ = locations[0]; |
393 viewport_location_ = locations[1]; | 403 viewport_location_ = locations[1]; |
394 quad_location_ = locations[2]; | 404 quad_location_ = locations[2]; |
395 edge_location_ = locations[3]; | 405 edge_location_ = locations[3]; |
396 } | 406 } |
397 | 407 |
398 std::string VertexShaderQuadAA::GetShaderString() const { | 408 std::string VertexShaderQuadAA::GetShaderString() const { |
409 // clang-format off | |
399 return VERTEX_SHADER( | 410 return VERTEX_SHADER( |
400 attribute TexCoordPrecision vec4 a_position; | 411 attribute TexCoordPrecision vec4 a_position; |
401 attribute float a_index; | 412 attribute float a_index; |
402 uniform mat4 matrix; | 413 uniform mat4 matrix; |
403 uniform vec4 viewport; | 414 uniform vec4 viewport; |
404 uniform TexCoordPrecision vec2 quad[4]; | 415 uniform TexCoordPrecision vec2 quad[4]; |
405 uniform TexCoordPrecision vec3 edge[8]; | 416 uniform TexCoordPrecision vec3 edge[8]; |
406 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 417 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
407 | 418 |
408 void main() { | 419 void main() { |
409 vec2 pos = quad[int(a_index)]; // NOLINT | 420 vec2 pos = quad[int(a_index)]; // NOLINT |
410 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 421 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
411 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); | 422 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); |
412 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); | 423 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); |
413 edge_dist[0] = vec4(dot(edge[0], screen_pos), | 424 edge_dist[0] = vec4(dot(edge[0], screen_pos), |
414 dot(edge[1], screen_pos), | 425 dot(edge[1], screen_pos), |
415 dot(edge[2], screen_pos), | 426 dot(edge[2], screen_pos), |
416 dot(edge[3], screen_pos)) * gl_Position.w; | 427 dot(edge[3], screen_pos)) * gl_Position.w; |
417 edge_dist[1] = vec4(dot(edge[4], screen_pos), | 428 edge_dist[1] = vec4(dot(edge[4], screen_pos), |
418 dot(edge[5], screen_pos), | 429 dot(edge[5], screen_pos), |
419 dot(edge[6], screen_pos), | 430 dot(edge[6], screen_pos), |
420 dot(edge[7], screen_pos)) * gl_Position.w; | 431 dot(edge[7], screen_pos)) * gl_Position.w; |
421 } | 432 } |
422 ); // NOLINT(whitespace/parens) | 433 ); // NOLINT(whitespace/parens) |
danakj
2014/10/16 19:25:10
where's the on here?
enne (OOO)
2014/10/16 19:39:30
Done.
| |
423 } | 434 } |
424 | 435 |
425 VertexShaderQuadTexTransformAA::VertexShaderQuadTexTransformAA() | 436 VertexShaderQuadTexTransformAA::VertexShaderQuadTexTransformAA() |
426 : matrix_location_(-1), | 437 : matrix_location_(-1), |
427 viewport_location_(-1), | 438 viewport_location_(-1), |
428 quad_location_(-1), | 439 quad_location_(-1), |
429 edge_location_(-1), | 440 edge_location_(-1), |
430 tex_transform_location_(-1) {} | 441 tex_transform_location_(-1) {} |
431 | 442 |
432 void VertexShaderQuadTexTransformAA::Init(GLES2Interface* context, | 443 void VertexShaderQuadTexTransformAA::Init(GLES2Interface* context, |
(...skipping 15 matching lines...) Expand all Loading... | |
448 locations, | 459 locations, |
449 base_uniform_index); | 460 base_uniform_index); |
450 matrix_location_ = locations[0]; | 461 matrix_location_ = locations[0]; |
451 viewport_location_ = locations[1]; | 462 viewport_location_ = locations[1]; |
452 quad_location_ = locations[2]; | 463 quad_location_ = locations[2]; |
453 edge_location_ = locations[3]; | 464 edge_location_ = locations[3]; |
454 tex_transform_location_ = locations[4]; | 465 tex_transform_location_ = locations[4]; |
455 } | 466 } |
456 | 467 |
457 std::string VertexShaderQuadTexTransformAA::GetShaderString() const { | 468 std::string VertexShaderQuadTexTransformAA::GetShaderString() const { |
458 return VERTEX_SHADER( | 469 return VERTEX_SHADER( |
danakj
2014/10/16 19:25:10
off here?
enne (OOO)
2014/10/16 19:39:30
Done.
| |
459 attribute TexCoordPrecision vec4 a_position; | 470 attribute TexCoordPrecision vec4 a_position; |
460 attribute float a_index; | 471 attribute float a_index; |
461 uniform mat4 matrix; | 472 uniform mat4 matrix; |
462 uniform vec4 viewport; | 473 uniform vec4 viewport; |
463 uniform TexCoordPrecision vec2 quad[4]; | 474 uniform TexCoordPrecision vec2 quad[4]; |
464 uniform TexCoordPrecision vec3 edge[8]; | 475 uniform TexCoordPrecision vec3 edge[8]; |
465 uniform TexCoordPrecision vec4 texTrans; | 476 uniform TexCoordPrecision vec4 texTrans; |
466 varying TexCoordPrecision vec2 v_texCoord; | 477 varying TexCoordPrecision vec2 v_texCoord; |
467 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 478 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
468 | 479 |
469 void main() { | 480 void main() { |
470 vec2 pos = quad[int(a_index)]; // NOLINT | 481 vec2 pos = quad[int(a_index)]; // NOLINT |
471 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 482 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
472 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); | 483 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); |
473 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); | 484 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); |
474 edge_dist[0] = vec4(dot(edge[0], screen_pos), | 485 edge_dist[0] = vec4(dot(edge[0], screen_pos), |
475 dot(edge[1], screen_pos), | 486 dot(edge[1], screen_pos), |
476 dot(edge[2], screen_pos), | 487 dot(edge[2], screen_pos), |
477 dot(edge[3], screen_pos)) * gl_Position.w; | 488 dot(edge[3], screen_pos)) * gl_Position.w; |
478 edge_dist[1] = vec4(dot(edge[4], screen_pos), | 489 edge_dist[1] = vec4(dot(edge[4], screen_pos), |
479 dot(edge[5], screen_pos), | 490 dot(edge[5], screen_pos), |
480 dot(edge[6], screen_pos), | 491 dot(edge[6], screen_pos), |
481 dot(edge[7], screen_pos)) * gl_Position.w; | 492 dot(edge[7], screen_pos)) * gl_Position.w; |
482 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy; | 493 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy; |
483 } | 494 } |
484 ); // NOLINT(whitespace/parens) | 495 ); // NOLINT(whitespace/parens) |
496 // clang-format on | |
485 } | 497 } |
486 | 498 |
487 VertexShaderTile::VertexShaderTile() | 499 VertexShaderTile::VertexShaderTile() |
488 : matrix_location_(-1), | 500 : matrix_location_(-1), |
489 quad_location_(-1), | 501 quad_location_(-1), |
490 vertex_tex_transform_location_(-1) {} | 502 vertex_tex_transform_location_(-1) { |
503 } | |
491 | 504 |
492 void VertexShaderTile::Init(GLES2Interface* context, | 505 void VertexShaderTile::Init(GLES2Interface* context, |
493 unsigned program, | 506 unsigned program, |
494 int* base_uniform_index) { | 507 int* base_uniform_index) { |
495 static const char* uniforms[] = { | 508 static const char* uniforms[] = { |
496 "matrix", | 509 "matrix", "quad", "vertexTexTransform", |
497 "quad", | |
498 "vertexTexTransform", | |
499 }; | 510 }; |
500 int locations[arraysize(uniforms)]; | 511 int locations[arraysize(uniforms)]; |
501 | 512 |
502 GetProgramUniformLocations(context, | 513 GetProgramUniformLocations(context, |
503 program, | 514 program, |
504 arraysize(uniforms), | 515 arraysize(uniforms), |
505 uniforms, | 516 uniforms, |
506 locations, | 517 locations, |
507 base_uniform_index); | 518 base_uniform_index); |
508 matrix_location_ = locations[0]; | 519 matrix_location_ = locations[0]; |
509 quad_location_ = locations[1]; | 520 quad_location_ = locations[1]; |
510 vertex_tex_transform_location_ = locations[2]; | 521 vertex_tex_transform_location_ = locations[2]; |
511 } | 522 } |
512 | 523 |
513 std::string VertexShaderTile::GetShaderString() const { | 524 std::string VertexShaderTile::GetShaderString() const { |
525 // clang-format off | |
514 return VERTEX_SHADER( | 526 return VERTEX_SHADER( |
515 attribute TexCoordPrecision vec4 a_position; | 527 attribute TexCoordPrecision vec4 a_position; |
516 attribute float a_index; | 528 attribute float a_index; |
517 uniform mat4 matrix; | 529 uniform mat4 matrix; |
518 uniform TexCoordPrecision vec2 quad[4]; | 530 uniform TexCoordPrecision vec2 quad[4]; |
519 uniform TexCoordPrecision vec4 vertexTexTransform; | 531 uniform TexCoordPrecision vec4 vertexTexTransform; |
520 varying TexCoordPrecision vec2 v_texCoord; | 532 varying TexCoordPrecision vec2 v_texCoord; |
521 void main() { | 533 void main() { |
522 vec2 pos = quad[int(a_index)]; // NOLINT | 534 vec2 pos = quad[int(a_index)]; // NOLINT |
523 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 535 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
524 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | 536 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; |
525 } | 537 } |
526 ); // NOLINT(whitespace/parens) | 538 ); // NOLINT(whitespace/parens) |
539 // clang-format on | |
527 } | 540 } |
528 | 541 |
529 VertexShaderTileAA::VertexShaderTileAA() | 542 VertexShaderTileAA::VertexShaderTileAA() |
530 : matrix_location_(-1), | 543 : matrix_location_(-1), |
531 viewport_location_(-1), | 544 viewport_location_(-1), |
532 quad_location_(-1), | 545 quad_location_(-1), |
533 edge_location_(-1), | 546 edge_location_(-1), |
534 vertex_tex_transform_location_(-1) {} | 547 vertex_tex_transform_location_(-1) { |
548 } | |
535 | 549 |
536 void VertexShaderTileAA::Init(GLES2Interface* context, | 550 void VertexShaderTileAA::Init(GLES2Interface* context, |
537 unsigned program, | 551 unsigned program, |
538 int* base_uniform_index) { | 552 int* base_uniform_index) { |
539 static const char* uniforms[] = { | 553 static const char* uniforms[] = { |
540 "matrix", | 554 "matrix", "viewport", "quad", "edge", "vertexTexTransform", |
541 "viewport", | |
542 "quad", | |
543 "edge", | |
544 "vertexTexTransform", | |
545 }; | 555 }; |
546 int locations[arraysize(uniforms)]; | 556 int locations[arraysize(uniforms)]; |
547 | 557 |
548 GetProgramUniformLocations(context, | 558 GetProgramUniformLocations(context, |
549 program, | 559 program, |
550 arraysize(uniforms), | 560 arraysize(uniforms), |
551 uniforms, | 561 uniforms, |
552 locations, | 562 locations, |
553 base_uniform_index); | 563 base_uniform_index); |
554 matrix_location_ = locations[0]; | 564 matrix_location_ = locations[0]; |
555 viewport_location_ = locations[1]; | 565 viewport_location_ = locations[1]; |
556 quad_location_ = locations[2]; | 566 quad_location_ = locations[2]; |
557 edge_location_ = locations[3]; | 567 edge_location_ = locations[3]; |
558 vertex_tex_transform_location_ = locations[4]; | 568 vertex_tex_transform_location_ = locations[4]; |
559 } | 569 } |
560 | 570 |
561 std::string VertexShaderTileAA::GetShaderString() const { | 571 std::string VertexShaderTileAA::GetShaderString() const { |
572 // clang-format off | |
562 return VERTEX_SHADER( | 573 return VERTEX_SHADER( |
563 attribute TexCoordPrecision vec4 a_position; | 574 attribute TexCoordPrecision vec4 a_position; |
564 attribute float a_index; | 575 attribute float a_index; |
565 uniform mat4 matrix; | 576 uniform mat4 matrix; |
566 uniform vec4 viewport; | 577 uniform vec4 viewport; |
567 uniform TexCoordPrecision vec2 quad[4]; | 578 uniform TexCoordPrecision vec2 quad[4]; |
568 uniform TexCoordPrecision vec3 edge[8]; | 579 uniform TexCoordPrecision vec3 edge[8]; |
569 uniform TexCoordPrecision vec4 vertexTexTransform; | 580 uniform TexCoordPrecision vec4 vertexTexTransform; |
570 varying TexCoordPrecision vec2 v_texCoord; | 581 varying TexCoordPrecision vec2 v_texCoord; |
571 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 582 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
572 | 583 |
573 void main() { | 584 void main() { |
574 vec2 pos = quad[int(a_index)]; // NOLINT | 585 vec2 pos = quad[int(a_index)]; // NOLINT |
575 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 586 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
576 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); | 587 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); |
577 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); | 588 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); |
578 edge_dist[0] = vec4(dot(edge[0], screen_pos), | 589 edge_dist[0] = vec4(dot(edge[0], screen_pos), |
579 dot(edge[1], screen_pos), | 590 dot(edge[1], screen_pos), |
580 dot(edge[2], screen_pos), | 591 dot(edge[2], screen_pos), |
581 dot(edge[3], screen_pos)) * gl_Position.w; | 592 dot(edge[3], screen_pos)) * gl_Position.w; |
582 edge_dist[1] = vec4(dot(edge[4], screen_pos), | 593 edge_dist[1] = vec4(dot(edge[4], screen_pos), |
583 dot(edge[5], screen_pos), | 594 dot(edge[5], screen_pos), |
584 dot(edge[6], screen_pos), | 595 dot(edge[6], screen_pos), |
585 dot(edge[7], screen_pos)) * gl_Position.w; | 596 dot(edge[7], screen_pos)) * gl_Position.w; |
586 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | 597 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; |
587 } | 598 } |
588 ); // NOLINT(whitespace/parens) | 599 ); // NOLINT(whitespace/parens) |
600 // clang-format on | |
589 } | 601 } |
590 | 602 |
591 VertexShaderVideoTransform::VertexShaderVideoTransform() | 603 VertexShaderVideoTransform::VertexShaderVideoTransform() |
592 : matrix_location_(-1), | 604 : matrix_location_(-1), tex_matrix_location_(-1) { |
593 tex_matrix_location_(-1) {} | 605 } |
594 | 606 |
595 void VertexShaderVideoTransform::Init(GLES2Interface* context, | 607 void VertexShaderVideoTransform::Init(GLES2Interface* context, |
596 unsigned program, | 608 unsigned program, |
597 int* base_uniform_index) { | 609 int* base_uniform_index) { |
598 static const char* uniforms[] = { | 610 static const char* uniforms[] = { |
599 "matrix", | 611 "matrix", "texMatrix", |
600 "texMatrix", | |
601 }; | 612 }; |
602 int locations[arraysize(uniforms)]; | 613 int locations[arraysize(uniforms)]; |
603 | 614 |
604 GetProgramUniformLocations(context, | 615 GetProgramUniformLocations(context, |
605 program, | 616 program, |
606 arraysize(uniforms), | 617 arraysize(uniforms), |
607 uniforms, | 618 uniforms, |
608 locations, | 619 locations, |
609 base_uniform_index); | 620 base_uniform_index); |
610 matrix_location_ = locations[0]; | 621 matrix_location_ = locations[0]; |
611 tex_matrix_location_ = locations[1]; | 622 tex_matrix_location_ = locations[1]; |
612 } | 623 } |
613 | 624 |
614 std::string VertexShaderVideoTransform::GetShaderString() const { | 625 std::string VertexShaderVideoTransform::GetShaderString() const { |
626 // clang-format off | |
615 return VERTEX_SHADER( | 627 return VERTEX_SHADER( |
616 attribute vec4 a_position; | 628 attribute vec4 a_position; |
617 attribute TexCoordPrecision vec2 a_texCoord; | 629 attribute TexCoordPrecision vec2 a_texCoord; |
618 uniform mat4 matrix; | 630 uniform mat4 matrix; |
619 uniform TexCoordPrecision mat4 texMatrix; | 631 uniform TexCoordPrecision mat4 texMatrix; |
620 varying TexCoordPrecision vec2 v_texCoord; | 632 varying TexCoordPrecision vec2 v_texCoord; |
621 void main() { | 633 void main() { |
622 gl_Position = matrix * a_position; | 634 gl_Position = matrix * a_position; |
623 v_texCoord = | 635 v_texCoord = |
624 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 636 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
625 } | 637 } |
626 ); // NOLINT(whitespace/parens) | 638 ); // NOLINT(whitespace/parens) |
639 // clang-format on | |
627 } | 640 } |
628 | 641 |
629 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | 642 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
630 : sampler_location_(-1), | 643 : sampler_location_(-1), alpha_location_(-1) { |
631 alpha_location_(-1) {} | 644 } |
632 | 645 |
633 void FragmentTexAlphaBinding::Init(GLES2Interface* context, | 646 void FragmentTexAlphaBinding::Init(GLES2Interface* context, |
634 unsigned program, | 647 unsigned program, |
635 int* base_uniform_index) { | 648 int* base_uniform_index) { |
636 static const char* uniforms[] = { | 649 static const char* uniforms[] = { |
637 "s_texture", | 650 "s_texture", "alpha", |
638 "alpha", | |
639 }; | 651 }; |
640 int locations[arraysize(uniforms)]; | 652 int locations[arraysize(uniforms)]; |
641 | 653 |
642 GetProgramUniformLocations(context, | 654 GetProgramUniformLocations(context, |
643 program, | 655 program, |
644 arraysize(uniforms), | 656 arraysize(uniforms), |
645 uniforms, | 657 uniforms, |
646 locations, | 658 locations, |
647 base_uniform_index); | 659 base_uniform_index); |
648 sampler_location_ = locations[0]; | 660 sampler_location_ = locations[0]; |
649 alpha_location_ = locations[1]; | 661 alpha_location_ = locations[1]; |
650 } | 662 } |
651 | 663 |
652 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding() | 664 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding() |
653 : sampler_location_(-1), | 665 : sampler_location_(-1), |
654 alpha_location_(-1), | 666 alpha_location_(-1), |
655 color_matrix_location_(-1), | 667 color_matrix_location_(-1), |
656 color_offset_location_(-1) {} | 668 color_offset_location_(-1) { |
669 } | |
657 | 670 |
658 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context, | 671 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context, |
659 unsigned program, | 672 unsigned program, |
660 int* base_uniform_index) { | 673 int* base_uniform_index) { |
661 static const char* uniforms[] = { | 674 static const char* uniforms[] = { |
662 "s_texture", | 675 "s_texture", "alpha", "colorMatrix", "colorOffset", |
663 "alpha", | |
664 "colorMatrix", | |
665 "colorOffset", | |
666 }; | 676 }; |
667 int locations[arraysize(uniforms)]; | 677 int locations[arraysize(uniforms)]; |
668 | 678 |
669 GetProgramUniformLocations(context, | 679 GetProgramUniformLocations(context, |
670 program, | 680 program, |
671 arraysize(uniforms), | 681 arraysize(uniforms), |
672 uniforms, | 682 uniforms, |
673 locations, | 683 locations, |
674 base_uniform_index); | 684 base_uniform_index); |
675 sampler_location_ = locations[0]; | 685 sampler_location_ = locations[0]; |
676 alpha_location_ = locations[1]; | 686 alpha_location_ = locations[1]; |
677 color_matrix_location_ = locations[2]; | 687 color_matrix_location_ = locations[2]; |
678 color_offset_location_ = locations[3]; | 688 color_offset_location_ = locations[3]; |
679 } | 689 } |
680 | 690 |
681 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() | 691 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() : sampler_location_(-1) { |
682 : sampler_location_(-1) {} | 692 } |
683 | 693 |
684 void FragmentTexOpaqueBinding::Init(GLES2Interface* context, | 694 void FragmentTexOpaqueBinding::Init(GLES2Interface* context, |
685 unsigned program, | 695 unsigned program, |
686 int* base_uniform_index) { | 696 int* base_uniform_index) { |
687 static const char* uniforms[] = { | 697 static const char* uniforms[] = { |
688 "s_texture", | 698 "s_texture", |
689 }; | 699 }; |
690 int locations[arraysize(uniforms)]; | 700 int locations[arraysize(uniforms)]; |
691 | 701 |
692 GetProgramUniformLocations(context, | 702 GetProgramUniformLocations(context, |
693 program, | 703 program, |
694 arraysize(uniforms), | 704 arraysize(uniforms), |
695 uniforms, | 705 uniforms, |
696 locations, | 706 locations, |
697 base_uniform_index); | 707 base_uniform_index); |
698 sampler_location_ = locations[0]; | 708 sampler_location_ = locations[0]; |
699 } | 709 } |
700 | 710 |
701 std::string FragmentShaderRGBATexAlpha::GetShaderString( | 711 std::string FragmentShaderRGBATexAlpha::GetShaderString( |
702 TexCoordPrecision precision, SamplerType sampler) const { | 712 TexCoordPrecision precision, |
713 SamplerType sampler) const { | |
714 // clang-format off | |
703 return FRAGMENT_SHADER( | 715 return FRAGMENT_SHADER( |
704 precision mediump float; | 716 precision mediump float; |
705 varying TexCoordPrecision vec2 v_texCoord; | 717 varying TexCoordPrecision vec2 v_texCoord; |
706 uniform SamplerType s_texture; | 718 uniform SamplerType s_texture; |
707 uniform float alpha; | 719 uniform float alpha; |
708 void main() { | 720 void main() { |
709 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 721 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
710 gl_FragColor = texColor * alpha; | 722 gl_FragColor = texColor * alpha; |
711 } | 723 } |
712 ); // NOLINT(whitespace/parens) | 724 ); // NOLINT(whitespace/parens) |
725 // clang-format on | |
713 } | 726 } |
714 | 727 |
715 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( | 728 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( |
716 TexCoordPrecision precision, SamplerType sampler) const { | 729 TexCoordPrecision precision, |
730 SamplerType sampler) const { | |
731 // clang-format off | |
717 return FRAGMENT_SHADER( | 732 return FRAGMENT_SHADER( |
718 precision mediump float; | 733 precision mediump float; |
719 varying TexCoordPrecision vec2 v_texCoord; | 734 varying TexCoordPrecision vec2 v_texCoord; |
720 uniform SamplerType s_texture; | 735 uniform SamplerType s_texture; |
721 uniform float alpha; | 736 uniform float alpha; |
722 uniform mat4 colorMatrix; | 737 uniform mat4 colorMatrix; |
723 uniform vec4 colorOffset; | 738 uniform vec4 colorOffset; |
724 void main() { | 739 void main() { |
725 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 740 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
726 float nonZeroAlpha = max(texColor.a, 0.00001); | 741 float nonZeroAlpha = max(texColor.a, 0.00001); |
727 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 742 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
728 texColor = colorMatrix * texColor + colorOffset; | 743 texColor = colorMatrix * texColor + colorOffset; |
729 texColor.rgb *= texColor.a; | 744 texColor.rgb *= texColor.a; |
730 texColor = clamp(texColor, 0.0, 1.0); | 745 texColor = clamp(texColor, 0.0, 1.0); |
731 gl_FragColor = texColor * alpha; | 746 gl_FragColor = texColor * alpha; |
732 } | 747 } |
733 ); // NOLINT(whitespace/parens) | 748 ); // NOLINT(whitespace/parens) |
749 // clang-format on | |
734 } | 750 } |
735 | 751 |
736 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( | 752 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( |
737 TexCoordPrecision precision, SamplerType sampler) const { | 753 TexCoordPrecision precision, |
754 SamplerType sampler) const { | |
755 // clang-format off | |
738 return FRAGMENT_SHADER( | 756 return FRAGMENT_SHADER( |
739 precision mediump float; | 757 precision mediump float; |
740 varying TexCoordPrecision vec2 v_texCoord; | 758 varying TexCoordPrecision vec2 v_texCoord; |
741 varying float v_alpha; | 759 varying float v_alpha; |
742 uniform SamplerType s_texture; | 760 uniform SamplerType s_texture; |
743 void main() { | 761 void main() { |
744 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 762 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
745 gl_FragColor = texColor * v_alpha; | 763 gl_FragColor = texColor * v_alpha; |
746 } | 764 } |
747 ); // NOLINT(whitespace/parens) | 765 ); // NOLINT(whitespace/parens) |
766 // clang-format on | |
748 } | 767 } |
749 | 768 |
750 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( | 769 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( |
751 TexCoordPrecision precision, SamplerType sampler) const { | 770 TexCoordPrecision precision, |
771 SamplerType sampler) const { | |
772 // clang-format off | |
752 return FRAGMENT_SHADER( | 773 return FRAGMENT_SHADER( |
753 precision mediump float; | 774 precision mediump float; |
754 varying TexCoordPrecision vec2 v_texCoord; | 775 varying TexCoordPrecision vec2 v_texCoord; |
755 varying float v_alpha; | 776 varying float v_alpha; |
756 uniform SamplerType s_texture; | 777 uniform SamplerType s_texture; |
757 void main() { | 778 void main() { |
758 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 779 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
759 texColor.rgb *= texColor.a; | 780 texColor.rgb *= texColor.a; |
760 gl_FragColor = texColor * v_alpha; | 781 gl_FragColor = texColor * v_alpha; |
761 } | 782 } |
762 ); // NOLINT(whitespace/parens) | 783 ); // NOLINT(whitespace/parens) |
784 // clang-format on | |
763 } | 785 } |
764 | 786 |
765 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() | 787 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() |
766 : background_color_location_(-1), | 788 : background_color_location_(-1), sampler_location_(-1) { |
767 sampler_location_(-1) { | |
768 } | 789 } |
769 | 790 |
770 void FragmentTexBackgroundBinding::Init(GLES2Interface* context, | 791 void FragmentTexBackgroundBinding::Init(GLES2Interface* context, |
771 unsigned program, | 792 unsigned program, |
772 int* base_uniform_index) { | 793 int* base_uniform_index) { |
773 static const char* uniforms[] = { | 794 static const char* uniforms[] = { |
774 "s_texture", | 795 "s_texture", "background_color", |
775 "background_color", | |
776 }; | 796 }; |
777 int locations[arraysize(uniforms)]; | 797 int locations[arraysize(uniforms)]; |
778 | 798 |
779 GetProgramUniformLocations(context, | 799 GetProgramUniformLocations(context, |
780 program, | 800 program, |
781 arraysize(uniforms), | 801 arraysize(uniforms), |
782 uniforms, | 802 uniforms, |
783 locations, | 803 locations, |
784 base_uniform_index); | 804 base_uniform_index); |
785 | 805 |
786 sampler_location_ = locations[0]; | 806 sampler_location_ = locations[0]; |
787 DCHECK_NE(sampler_location_, -1); | 807 DCHECK_NE(sampler_location_, -1); |
788 | 808 |
789 background_color_location_ = locations[1]; | 809 background_color_location_ = locations[1]; |
790 DCHECK_NE(background_color_location_, -1); | 810 DCHECK_NE(background_color_location_, -1); |
791 } | 811 } |
792 | 812 |
793 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( | 813 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( |
794 TexCoordPrecision precision, SamplerType sampler) const { | 814 TexCoordPrecision precision, |
815 SamplerType sampler) const { | |
816 // clang-format off | |
795 return FRAGMENT_SHADER( | 817 return FRAGMENT_SHADER( |
796 precision mediump float; | 818 precision mediump float; |
797 varying TexCoordPrecision vec2 v_texCoord; | 819 varying TexCoordPrecision vec2 v_texCoord; |
798 varying float v_alpha; | 820 varying float v_alpha; |
799 uniform vec4 background_color; | 821 uniform vec4 background_color; |
800 uniform SamplerType s_texture; | 822 uniform SamplerType s_texture; |
801 void main() { | 823 void main() { |
802 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 824 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
803 texColor += background_color * (1.0 - texColor.a); | 825 texColor += background_color * (1.0 - texColor.a); |
804 gl_FragColor = texColor * v_alpha; | 826 gl_FragColor = texColor * v_alpha; |
805 } | 827 } |
806 ); // NOLINT(whitespace/parens) | 828 ); // NOLINT(whitespace/parens) |
829 // clang-format on | |
807 } | 830 } |
808 | 831 |
809 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( | 832 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( |
810 TexCoordPrecision precision, SamplerType sampler) const { | 833 TexCoordPrecision precision, |
834 SamplerType sampler) const { | |
835 // clang-format off | |
811 return FRAGMENT_SHADER( | 836 return FRAGMENT_SHADER( |
812 precision mediump float; | 837 precision mediump float; |
813 varying TexCoordPrecision vec2 v_texCoord; | 838 varying TexCoordPrecision vec2 v_texCoord; |
814 varying float v_alpha; | 839 varying float v_alpha; |
815 uniform vec4 background_color; | 840 uniform vec4 background_color; |
816 uniform SamplerType s_texture; | 841 uniform SamplerType s_texture; |
817 void main() { | 842 void main() { |
818 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 843 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
819 texColor.rgb *= texColor.a; | 844 texColor.rgb *= texColor.a; |
820 texColor += background_color * (1.0 - texColor.a); | 845 texColor += background_color * (1.0 - texColor.a); |
821 gl_FragColor = texColor * v_alpha; | 846 gl_FragColor = texColor * v_alpha; |
822 } | 847 } |
823 ); // NOLINT(whitespace/parens) | 848 ); // NOLINT(whitespace/parens) |
849 // clang-format on | |
824 } | 850 } |
825 | 851 |
826 std::string FragmentShaderRGBATexOpaque::GetShaderString( | 852 std::string FragmentShaderRGBATexOpaque::GetShaderString( |
827 TexCoordPrecision precision, SamplerType sampler) const { | 853 TexCoordPrecision precision, |
854 SamplerType sampler) const { | |
855 // clang-format off | |
828 return FRAGMENT_SHADER( | 856 return FRAGMENT_SHADER( |
829 precision mediump float; | 857 precision mediump float; |
830 varying TexCoordPrecision vec2 v_texCoord; | 858 varying TexCoordPrecision vec2 v_texCoord; |
831 uniform SamplerType s_texture; | 859 uniform SamplerType s_texture; |
832 void main() { | 860 void main() { |
833 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 861 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
834 gl_FragColor = vec4(texColor.rgb, 1.0); | 862 gl_FragColor = vec4(texColor.rgb, 1.0); |
835 } | 863 } |
836 ); // NOLINT(whitespace/parens) | 864 ); // NOLINT(whitespace/parens) |
865 // clang-format on | |
837 } | 866 } |
838 | 867 |
839 std::string FragmentShaderRGBATex::GetShaderString( | 868 std::string FragmentShaderRGBATex::GetShaderString(TexCoordPrecision precision, |
840 TexCoordPrecision precision, SamplerType sampler) const { | 869 SamplerType sampler) const { |
870 // clang-format off | |
841 return FRAGMENT_SHADER( | 871 return FRAGMENT_SHADER( |
842 precision mediump float; | 872 precision mediump float; |
843 varying TexCoordPrecision vec2 v_texCoord; | 873 varying TexCoordPrecision vec2 v_texCoord; |
844 uniform SamplerType s_texture; | 874 uniform SamplerType s_texture; |
845 void main() { | 875 void main() { |
846 gl_FragColor = TextureLookup(s_texture, v_texCoord); | 876 gl_FragColor = TextureLookup(s_texture, v_texCoord); |
847 } | 877 } |
848 ); // NOLINT(whitespace/parens) | 878 ); // NOLINT(whitespace/parens) |
879 // clang-format on | |
849 } | 880 } |
850 | 881 |
851 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( | 882 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( |
852 TexCoordPrecision precision, SamplerType sampler) const { | 883 TexCoordPrecision precision, |
884 SamplerType sampler) const { | |
885 // clang-format off | |
853 return FRAGMENT_SHADER( | 886 return FRAGMENT_SHADER( |
854 precision mediump float; | 887 precision mediump float; |
855 varying TexCoordPrecision vec2 v_texCoord; | 888 varying TexCoordPrecision vec2 v_texCoord; |
856 uniform SamplerType s_texture; | 889 uniform SamplerType s_texture; |
857 uniform float alpha; | 890 uniform float alpha; |
858 void main() { | 891 void main() { |
859 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 892 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
860 gl_FragColor = | 893 gl_FragColor = |
861 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; | 894 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; |
862 } | 895 } |
863 ); // NOLINT(whitespace/parens) | 896 ); // NOLINT(whitespace/parens) |
897 // clang-format on | |
864 } | 898 } |
865 | 899 |
866 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( | 900 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( |
867 TexCoordPrecision precision, SamplerType sampler) const { | 901 TexCoordPrecision precision, |
902 SamplerType sampler) const { | |
903 // clang-format off | |
868 return FRAGMENT_SHADER( | 904 return FRAGMENT_SHADER( |
869 precision mediump float; | 905 precision mediump float; |
870 varying TexCoordPrecision vec2 v_texCoord; | 906 varying TexCoordPrecision vec2 v_texCoord; |
871 uniform SamplerType s_texture; | 907 uniform SamplerType s_texture; |
872 void main() { | 908 void main() { |
873 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 909 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
874 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 910 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
875 } | 911 } |
876 ); // NOLINT(whitespace/parens) | 912 ); // NOLINT(whitespace/parens) |
913 // clang-format on | |
877 } | 914 } |
878 | 915 |
879 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 916 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
880 : sampler_location_(-1), | 917 : sampler_location_(-1), alpha_location_(-1) { |
881 alpha_location_(-1) {} | 918 } |
882 | 919 |
883 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context, | 920 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context, |
884 unsigned program, | 921 unsigned program, |
885 int* base_uniform_index) { | 922 int* base_uniform_index) { |
886 static const char* uniforms[] = { | 923 static const char* uniforms[] = { |
887 "s_texture", | 924 "s_texture", "alpha", |
888 "alpha", | |
889 }; | 925 }; |
890 int locations[arraysize(uniforms)]; | 926 int locations[arraysize(uniforms)]; |
891 | 927 |
892 GetProgramUniformLocations(context, | 928 GetProgramUniformLocations(context, |
893 program, | 929 program, |
894 arraysize(uniforms), | 930 arraysize(uniforms), |
895 uniforms, | 931 uniforms, |
896 locations, | 932 locations, |
897 base_uniform_index); | 933 base_uniform_index); |
898 sampler_location_ = locations[0]; | 934 sampler_location_ = locations[0]; |
899 alpha_location_ = locations[1]; | 935 alpha_location_ = locations[1]; |
900 } | 936 } |
901 | 937 |
902 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( | 938 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( |
903 TexCoordPrecision precision, SamplerType sampler) const { | 939 TexCoordPrecision precision, |
940 SamplerType sampler) const { | |
941 // clang-format off | |
904 return FRAGMENT_SHADER( | 942 return FRAGMENT_SHADER( |
905 precision mediump float; | 943 precision mediump float; |
906 uniform SamplerType s_texture; | 944 uniform SamplerType s_texture; |
907 uniform float alpha; | 945 uniform float alpha; |
908 varying TexCoordPrecision vec2 v_texCoord; | 946 varying TexCoordPrecision vec2 v_texCoord; |
909 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 947 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
910 | 948 |
911 void main() { | 949 void main() { |
912 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 950 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
913 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 951 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
914 vec2 d2 = min(d4.xz, d4.yw); | 952 vec2 d2 = min(d4.xz, d4.yw); |
915 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 953 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
916 gl_FragColor = texColor * alpha * aa; | 954 gl_FragColor = texColor * alpha * aa; |
917 } | 955 } |
918 ); // NOLINT(whitespace/parens) | 956 ); // NOLINT(whitespace/parens) |
957 // clang-format on | |
919 } | 958 } |
920 | 959 |
921 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() | 960 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() |
922 : sampler_location_(-1), | 961 : sampler_location_(-1), |
923 alpha_location_(-1), | 962 alpha_location_(-1), |
924 fragment_tex_transform_location_(-1) {} | 963 fragment_tex_transform_location_(-1) { |
964 } | |
925 | 965 |
926 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, | 966 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, |
927 unsigned program, | 967 unsigned program, |
928 int* base_uniform_index) { | 968 int* base_uniform_index) { |
929 static const char* uniforms[] = { | 969 static const char* uniforms[] = { |
930 "s_texture", | 970 "s_texture", "alpha", "fragmentTexTransform", |
931 "alpha", | |
932 "fragmentTexTransform", | |
933 }; | 971 }; |
934 int locations[arraysize(uniforms)]; | 972 int locations[arraysize(uniforms)]; |
935 | 973 |
936 GetProgramUniformLocations(context, | 974 GetProgramUniformLocations(context, |
937 program, | 975 program, |
938 arraysize(uniforms), | 976 arraysize(uniforms), |
939 uniforms, | 977 uniforms, |
940 locations, | 978 locations, |
941 base_uniform_index); | 979 base_uniform_index); |
942 sampler_location_ = locations[0]; | 980 sampler_location_ = locations[0]; |
943 alpha_location_ = locations[1]; | 981 alpha_location_ = locations[1]; |
944 fragment_tex_transform_location_ = locations[2]; | 982 fragment_tex_transform_location_ = locations[2]; |
945 } | 983 } |
946 | 984 |
947 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( | 985 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( |
948 TexCoordPrecision precision, SamplerType sampler) const { | 986 TexCoordPrecision precision, |
987 SamplerType sampler) const { | |
988 // clang-format off | |
949 return FRAGMENT_SHADER( | 989 return FRAGMENT_SHADER( |
950 precision mediump float; | 990 precision mediump float; |
951 uniform SamplerType s_texture; | 991 uniform SamplerType s_texture; |
952 uniform float alpha; | 992 uniform float alpha; |
953 uniform TexCoordPrecision vec4 fragmentTexTransform; | 993 uniform TexCoordPrecision vec4 fragmentTexTransform; |
954 varying TexCoordPrecision vec2 v_texCoord; | 994 varying TexCoordPrecision vec2 v_texCoord; |
955 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 995 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
956 | 996 |
957 void main() { | 997 void main() { |
958 TexCoordPrecision vec2 texCoord = | 998 TexCoordPrecision vec2 texCoord = |
959 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 999 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
960 fragmentTexTransform.xy; | 1000 fragmentTexTransform.xy; |
961 vec4 texColor = TextureLookup(s_texture, texCoord); | 1001 vec4 texColor = TextureLookup(s_texture, texCoord); |
962 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1002 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
963 vec2 d2 = min(d4.xz, d4.yw); | 1003 vec2 d2 = min(d4.xz, d4.yw); |
964 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1004 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
965 gl_FragColor = texColor * alpha * aa; | 1005 gl_FragColor = texColor * alpha * aa; |
966 } | 1006 } |
967 ); // NOLINT(whitespace/parens) | 1007 ); // NOLINT(whitespace/parens) |
1008 // clang-format on | |
968 } | 1009 } |
969 | 1010 |
970 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( | 1011 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( |
971 TexCoordPrecision precision, SamplerType sampler) const { | 1012 TexCoordPrecision precision, |
1013 SamplerType sampler) const { | |
1014 // clang-format off | |
972 return FRAGMENT_SHADER( | 1015 return FRAGMENT_SHADER( |
danakj
2014/10/16 19:25:11
could we turn format on inside the shader code som
enne (OOO)
2014/10/16 19:39:30
Done. The only weirdness (other than the growing
| |
973 precision mediump float; | 1016 precision mediump float; |
974 uniform SamplerType s_texture; | 1017 uniform SamplerType s_texture; |
975 uniform float alpha; | 1018 uniform float alpha; |
976 uniform TexCoordPrecision vec4 fragmentTexTransform; | 1019 uniform TexCoordPrecision vec4 fragmentTexTransform; |
977 varying TexCoordPrecision vec2 v_texCoord; | 1020 varying TexCoordPrecision vec2 v_texCoord; |
978 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1021 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
979 | 1022 |
980 void main() { | 1023 void main() { |
981 TexCoordPrecision vec2 texCoord = | 1024 TexCoordPrecision vec2 texCoord = |
982 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 1025 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
983 fragmentTexTransform.xy; | 1026 fragmentTexTransform.xy; |
984 vec4 texColor = TextureLookup(s_texture, texCoord); | 1027 vec4 texColor = TextureLookup(s_texture, texCoord); |
985 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1028 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
986 vec2 d2 = min(d4.xz, d4.yw); | 1029 vec2 d2 = min(d4.xz, d4.yw); |
987 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1030 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
988 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * | 1031 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * |
989 alpha * aa; | 1032 alpha * aa; |
990 } | 1033 } |
991 ); // NOLINT(whitespace/parens) | 1034 ); // NOLINT(whitespace/parens) |
1035 // clang-format on | |
992 } | 1036 } |
993 | 1037 |
994 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() | 1038 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() |
995 : sampler_location_(-1), | 1039 : sampler_location_(-1), |
996 mask_sampler_location_(-1), | 1040 mask_sampler_location_(-1), |
997 alpha_location_(-1), | 1041 alpha_location_(-1), |
998 mask_tex_coord_scale_location_(-1) {} | 1042 mask_tex_coord_scale_location_(-1) { |
1043 } | |
999 | 1044 |
1000 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context, | 1045 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context, |
1001 unsigned program, | 1046 unsigned program, |
1002 int* base_uniform_index) { | 1047 int* base_uniform_index) { |
1003 static const char* uniforms[] = { | 1048 static const char* uniforms[] = { |
1004 "s_texture", | 1049 "s_texture", "s_mask", "alpha", "maskTexCoordScale", "maskTexCoordOffset", |
1005 "s_mask", | |
1006 "alpha", | |
1007 "maskTexCoordScale", | |
1008 "maskTexCoordOffset", | |
1009 }; | 1050 }; |
1010 int locations[arraysize(uniforms)]; | 1051 int locations[arraysize(uniforms)]; |
1011 | 1052 |
1012 GetProgramUniformLocations(context, | 1053 GetProgramUniformLocations(context, |
1013 program, | 1054 program, |
1014 arraysize(uniforms), | 1055 arraysize(uniforms), |
1015 uniforms, | 1056 uniforms, |
1016 locations, | 1057 locations, |
1017 base_uniform_index); | 1058 base_uniform_index); |
1018 sampler_location_ = locations[0]; | 1059 sampler_location_ = locations[0]; |
1019 mask_sampler_location_ = locations[1]; | 1060 mask_sampler_location_ = locations[1]; |
1020 alpha_location_ = locations[2]; | 1061 alpha_location_ = locations[2]; |
1021 mask_tex_coord_scale_location_ = locations[3]; | 1062 mask_tex_coord_scale_location_ = locations[3]; |
1022 mask_tex_coord_offset_location_ = locations[4]; | 1063 mask_tex_coord_offset_location_ = locations[4]; |
1023 } | 1064 } |
1024 | 1065 |
1025 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( | 1066 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( |
1026 TexCoordPrecision precision, SamplerType sampler) const { | 1067 TexCoordPrecision precision, |
1068 SamplerType sampler) const { | |
1069 // clang-format off | |
1027 return FRAGMENT_SHADER( | 1070 return FRAGMENT_SHADER( |
1028 precision mediump float; | 1071 precision mediump float; |
1029 varying TexCoordPrecision vec2 v_texCoord; | 1072 varying TexCoordPrecision vec2 v_texCoord; |
1030 uniform SamplerType s_texture; | 1073 uniform sampler2D s_texture; |
danakj
2014/10/16 19:25:11
<_<
enne (OOO)
2014/10/16 19:39:30
I blame emacs.
| |
1031 uniform SamplerType s_mask; | 1074 uniform SamplerType s_mask; |
1032 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1075 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1033 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1076 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1034 uniform float alpha; | 1077 uniform float alpha; |
1035 void main() { | 1078 void main() { |
1036 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1079 vec4 texColor = texture2D(s_texture, v_texCoord); |
1037 TexCoordPrecision vec2 maskTexCoord = | 1080 TexCoordPrecision vec2 maskTexCoord = |
1038 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1081 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1039 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1082 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1040 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1083 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1041 gl_FragColor = texColor * alpha * maskColor.w; | 1084 gl_FragColor = texColor * alpha * maskColor.w; |
1042 } | 1085 } |
1043 ); // NOLINT(whitespace/parens) | 1086 ); // NOLINT(whitespace/parens) |
1087 // clang-format on | |
1044 } | 1088 } |
1045 | 1089 |
1046 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 1090 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
1047 : sampler_location_(-1), | 1091 : sampler_location_(-1), |
1048 mask_sampler_location_(-1), | 1092 mask_sampler_location_(-1), |
1049 alpha_location_(-1), | 1093 alpha_location_(-1), |
1050 mask_tex_coord_scale_location_(-1), | 1094 mask_tex_coord_scale_location_(-1), |
1051 mask_tex_coord_offset_location_(-1) {} | 1095 mask_tex_coord_offset_location_(-1) { |
1096 } | |
1052 | 1097 |
1053 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context, | 1098 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context, |
1054 unsigned program, | 1099 unsigned program, |
1055 int* base_uniform_index) { | 1100 int* base_uniform_index) { |
1056 static const char* uniforms[] = { | 1101 static const char* uniforms[] = { |
1057 "s_texture", | 1102 "s_texture", "s_mask", "alpha", "maskTexCoordScale", "maskTexCoordOffset", |
1058 "s_mask", | |
1059 "alpha", | |
1060 "maskTexCoordScale", | |
1061 "maskTexCoordOffset", | |
1062 }; | 1103 }; |
1063 int locations[arraysize(uniforms)]; | 1104 int locations[arraysize(uniforms)]; |
1064 | 1105 |
1065 GetProgramUniformLocations(context, | 1106 GetProgramUniformLocations(context, |
1066 program, | 1107 program, |
1067 arraysize(uniforms), | 1108 arraysize(uniforms), |
1068 uniforms, | 1109 uniforms, |
1069 locations, | 1110 locations, |
1070 base_uniform_index); | 1111 base_uniform_index); |
1071 sampler_location_ = locations[0]; | 1112 sampler_location_ = locations[0]; |
1072 mask_sampler_location_ = locations[1]; | 1113 mask_sampler_location_ = locations[1]; |
1073 alpha_location_ = locations[2]; | 1114 alpha_location_ = locations[2]; |
1074 mask_tex_coord_scale_location_ = locations[3]; | 1115 mask_tex_coord_scale_location_ = locations[3]; |
1075 mask_tex_coord_offset_location_ = locations[4]; | 1116 mask_tex_coord_offset_location_ = locations[4]; |
1076 } | 1117 } |
1077 | 1118 |
1078 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( | 1119 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( |
1079 TexCoordPrecision precision, SamplerType sampler) const { | 1120 TexCoordPrecision precision, |
1121 SamplerType sampler) const { | |
1122 // clang-format off | |
1080 return FRAGMENT_SHADER( | 1123 return FRAGMENT_SHADER( |
1081 precision mediump float; | 1124 precision mediump float; |
1082 uniform SamplerType s_texture; | 1125 uniform sampler2D s_texture; |
1083 uniform SamplerType s_mask; | 1126 uniform SamplerType s_mask; |
1084 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1127 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1085 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1128 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1086 uniform float alpha; | 1129 uniform float alpha; |
1087 varying TexCoordPrecision vec2 v_texCoord; | 1130 varying TexCoordPrecision vec2 v_texCoord; |
1088 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1131 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1089 | 1132 |
1090 void main() { | 1133 void main() { |
1091 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1134 vec4 texColor = texture2D(s_texture, v_texCoord); |
danakj
2014/10/16 19:25:10
<_<
| |
1092 TexCoordPrecision vec2 maskTexCoord = | 1135 TexCoordPrecision vec2 maskTexCoord = |
1093 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1136 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1094 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1137 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1095 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1138 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1096 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1139 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1097 vec2 d2 = min(d4.xz, d4.yw); | 1140 vec2 d2 = min(d4.xz, d4.yw); |
1098 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1141 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1099 gl_FragColor = texColor * alpha * maskColor.w * aa; | 1142 gl_FragColor = texColor * alpha * maskColor.w * aa; |
1100 } | 1143 } |
1101 ); // NOLINT(whitespace/parens) | 1144 ); // NOLINT(whitespace/parens) |
1145 // clang-format on | |
1102 } | 1146 } |
1103 | 1147 |
1104 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: | 1148 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: |
1105 FragmentShaderRGBATexAlphaMaskColorMatrixAA() | 1149 FragmentShaderRGBATexAlphaMaskColorMatrixAA() |
1106 : sampler_location_(-1), | 1150 : sampler_location_(-1), |
1107 mask_sampler_location_(-1), | 1151 mask_sampler_location_(-1), |
1108 alpha_location_(-1), | 1152 alpha_location_(-1), |
1109 mask_tex_coord_scale_location_(-1), | 1153 mask_tex_coord_scale_location_(-1), |
1110 color_matrix_location_(-1), | 1154 color_matrix_location_(-1), |
1111 color_offset_location_(-1) {} | 1155 color_offset_location_(-1) { |
1156 } | |
1112 | 1157 |
1113 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init( | 1158 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init( |
1114 GLES2Interface* context, | 1159 GLES2Interface* context, |
1115 unsigned program, | 1160 unsigned program, |
1116 int* base_uniform_index) { | 1161 int* base_uniform_index) { |
1117 static const char* uniforms[] = { | 1162 static const char* uniforms[] = { |
1118 "s_texture", | 1163 "s_texture", |
1119 "s_mask", | 1164 "s_mask", |
1120 "alpha", | 1165 "alpha", |
1121 "maskTexCoordScale", | 1166 "maskTexCoordScale", |
1122 "maskTexCoordOffset", | 1167 "maskTexCoordOffset", |
1123 "colorMatrix", | 1168 "colorMatrix", |
1124 "colorOffset", | 1169 "colorOffset", |
1125 }; | 1170 }; |
1126 int locations[arraysize(uniforms)]; | 1171 int locations[arraysize(uniforms)]; |
1127 | 1172 |
1128 GetProgramUniformLocations(context, | 1173 GetProgramUniformLocations(context, |
1129 program, | 1174 program, |
1130 arraysize(uniforms), | 1175 arraysize(uniforms), |
1131 uniforms, | 1176 uniforms, |
1132 locations, | 1177 locations, |
1133 base_uniform_index); | 1178 base_uniform_index); |
1134 sampler_location_ = locations[0]; | 1179 sampler_location_ = locations[0]; |
1135 mask_sampler_location_ = locations[1]; | 1180 mask_sampler_location_ = locations[1]; |
1136 alpha_location_ = locations[2]; | 1181 alpha_location_ = locations[2]; |
1137 mask_tex_coord_scale_location_ = locations[3]; | 1182 mask_tex_coord_scale_location_ = locations[3]; |
1138 mask_tex_coord_offset_location_ = locations[4]; | 1183 mask_tex_coord_offset_location_ = locations[4]; |
1139 color_matrix_location_ = locations[5]; | 1184 color_matrix_location_ = locations[5]; |
1140 color_offset_location_ = locations[6]; | 1185 color_offset_location_ = locations[6]; |
1141 } | 1186 } |
1142 | 1187 |
1143 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( | 1188 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( |
1144 TexCoordPrecision precision, SamplerType sampler) const { | 1189 TexCoordPrecision precision, |
1190 SamplerType sampler) const { | |
1191 // clang-format off | |
1145 return FRAGMENT_SHADER( | 1192 return FRAGMENT_SHADER( |
1146 precision mediump float; | 1193 precision mediump float; |
1147 uniform SamplerType s_texture; | 1194 uniform sampler2D s_texture; |
1148 uniform SamplerType s_mask; | 1195 uniform SamplerType s_mask; |
1149 uniform vec2 maskTexCoordScale; | 1196 uniform vec2 maskTexCoordScale; |
1150 uniform vec2 maskTexCoordOffset; | 1197 uniform vec2 maskTexCoordOffset; |
1151 uniform mat4 colorMatrix; | 1198 uniform mat4 colorMatrix; |
1152 uniform vec4 colorOffset; | 1199 uniform vec4 colorOffset; |
1153 uniform float alpha; | 1200 uniform float alpha; |
1154 varying TexCoordPrecision vec2 v_texCoord; | 1201 varying TexCoordPrecision vec2 v_texCoord; |
1155 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1202 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1156 | 1203 |
1157 void main() { | 1204 void main() { |
1158 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1205 vec4 texColor = texture2D(s_texture, v_texCoord); |
1159 float nonZeroAlpha = max(texColor.a, 0.00001); | 1206 float nonZeroAlpha = max(texColor.a, 0.00001); |
1160 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1207 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1161 texColor = colorMatrix * texColor + colorOffset; | 1208 texColor = colorMatrix * texColor + colorOffset; |
1162 texColor.rgb *= texColor.a; | 1209 texColor.rgb *= texColor.a; |
1163 texColor = clamp(texColor, 0.0, 1.0); | 1210 texColor = clamp(texColor, 0.0, 1.0); |
1164 TexCoordPrecision vec2 maskTexCoord = | 1211 TexCoordPrecision vec2 maskTexCoord = |
1165 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1212 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1166 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1213 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1167 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1214 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1168 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1215 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1169 vec2 d2 = min(d4.xz, d4.yw); | 1216 vec2 d2 = min(d4.xz, d4.yw); |
1170 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1217 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1171 gl_FragColor = texColor * alpha * maskColor.w * aa; | 1218 gl_FragColor = texColor * alpha * maskColor.w * aa; |
1172 } | 1219 } |
1173 ); // NOLINT(whitespace/parens) | 1220 ); // NOLINT(whitespace/parens) |
1221 // clang-format on | |
1174 } | 1222 } |
1175 | 1223 |
1176 FragmentShaderRGBATexAlphaColorMatrixAA:: | 1224 FragmentShaderRGBATexAlphaColorMatrixAA:: |
1177 FragmentShaderRGBATexAlphaColorMatrixAA() | 1225 FragmentShaderRGBATexAlphaColorMatrixAA() |
1178 : sampler_location_(-1), | 1226 : sampler_location_(-1), |
1179 alpha_location_(-1), | 1227 alpha_location_(-1), |
1180 color_matrix_location_(-1), | 1228 color_matrix_location_(-1), |
1181 color_offset_location_(-1) {} | 1229 color_offset_location_(-1) { |
1230 } | |
1182 | 1231 |
1183 void FragmentShaderRGBATexAlphaColorMatrixAA::Init( | 1232 void FragmentShaderRGBATexAlphaColorMatrixAA::Init(GLES2Interface* context, |
1184 GLES2Interface* context, | 1233 unsigned program, |
1185 unsigned program, | 1234 int* base_uniform_index) { |
1186 int* base_uniform_index) { | |
1187 static const char* uniforms[] = { | 1235 static const char* uniforms[] = { |
1188 "s_texture", | 1236 "s_texture", "alpha", "colorMatrix", "colorOffset", |
1189 "alpha", | |
1190 "colorMatrix", | |
1191 "colorOffset", | |
1192 }; | 1237 }; |
1193 int locations[arraysize(uniforms)]; | 1238 int locations[arraysize(uniforms)]; |
1194 | 1239 |
1195 GetProgramUniformLocations(context, | 1240 GetProgramUniformLocations(context, |
1196 program, | 1241 program, |
1197 arraysize(uniforms), | 1242 arraysize(uniforms), |
1198 uniforms, | 1243 uniforms, |
1199 locations, | 1244 locations, |
1200 base_uniform_index); | 1245 base_uniform_index); |
1201 sampler_location_ = locations[0]; | 1246 sampler_location_ = locations[0]; |
1202 alpha_location_ = locations[1]; | 1247 alpha_location_ = locations[1]; |
1203 color_matrix_location_ = locations[2]; | 1248 color_matrix_location_ = locations[2]; |
1204 color_offset_location_ = locations[3]; | 1249 color_offset_location_ = locations[3]; |
1205 } | 1250 } |
1206 | 1251 |
1207 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( | 1252 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( |
1208 TexCoordPrecision precision, SamplerType sampler) const { | 1253 TexCoordPrecision precision, |
1254 SamplerType sampler) const { | |
1255 // clang-format off | |
1209 return FRAGMENT_SHADER( | 1256 return FRAGMENT_SHADER( |
1210 precision mediump float; | 1257 precision mediump float; |
1211 uniform SamplerType s_texture; | 1258 uniform SamplerType s_texture; |
1212 uniform float alpha; | 1259 uniform float alpha; |
1213 uniform mat4 colorMatrix; | 1260 uniform mat4 colorMatrix; |
1214 uniform vec4 colorOffset; | 1261 uniform vec4 colorOffset; |
1215 varying TexCoordPrecision vec2 v_texCoord; | 1262 varying TexCoordPrecision vec2 v_texCoord; |
1216 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1263 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1217 | 1264 |
1218 void main() { | 1265 void main() { |
1219 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1266 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1220 float nonZeroAlpha = max(texColor.a, 0.00001); | 1267 float nonZeroAlpha = max(texColor.a, 0.00001); |
1221 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1268 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1222 texColor = colorMatrix * texColor + colorOffset; | 1269 texColor = colorMatrix * texColor + colorOffset; |
1223 texColor.rgb *= texColor.a; | 1270 texColor.rgb *= texColor.a; |
1224 texColor = clamp(texColor, 0.0, 1.0); | 1271 texColor = clamp(texColor, 0.0, 1.0); |
1225 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1272 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1226 vec2 d2 = min(d4.xz, d4.yw); | 1273 vec2 d2 = min(d4.xz, d4.yw); |
1227 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1274 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1228 gl_FragColor = texColor * alpha * aa; | 1275 gl_FragColor = texColor * alpha * aa; |
1229 } | 1276 } |
1230 ); // NOLINT(whitespace/parens) | 1277 ); // NOLINT(whitespace/parens) |
1278 // clang-format on | |
1231 } | 1279 } |
1232 | 1280 |
1233 FragmentShaderRGBATexAlphaMaskColorMatrix:: | 1281 FragmentShaderRGBATexAlphaMaskColorMatrix:: |
1234 FragmentShaderRGBATexAlphaMaskColorMatrix() | 1282 FragmentShaderRGBATexAlphaMaskColorMatrix() |
1235 : sampler_location_(-1), | 1283 : sampler_location_(-1), |
1236 mask_sampler_location_(-1), | 1284 mask_sampler_location_(-1), |
1237 alpha_location_(-1), | 1285 alpha_location_(-1), |
1238 mask_tex_coord_scale_location_(-1) {} | 1286 mask_tex_coord_scale_location_(-1) { |
1287 } | |
1239 | 1288 |
1240 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init( | 1289 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context, |
1241 GLES2Interface* context, | 1290 unsigned program, |
1242 unsigned program, | 1291 int* base_uniform_index) { |
1243 int* base_uniform_index) { | |
1244 static const char* uniforms[] = { | 1292 static const char* uniforms[] = { |
1245 "s_texture", | 1293 "s_texture", |
1246 "s_mask", | 1294 "s_mask", |
1247 "alpha", | 1295 "alpha", |
1248 "maskTexCoordScale", | 1296 "maskTexCoordScale", |
1249 "maskTexCoordOffset", | 1297 "maskTexCoordOffset", |
1250 "colorMatrix", | 1298 "colorMatrix", |
1251 "colorOffset", | 1299 "colorOffset", |
1252 }; | 1300 }; |
1253 int locations[arraysize(uniforms)]; | 1301 int locations[arraysize(uniforms)]; |
1254 | 1302 |
1255 GetProgramUniformLocations(context, | 1303 GetProgramUniformLocations(context, |
1256 program, | 1304 program, |
1257 arraysize(uniforms), | 1305 arraysize(uniforms), |
1258 uniforms, | 1306 uniforms, |
1259 locations, | 1307 locations, |
1260 base_uniform_index); | 1308 base_uniform_index); |
1261 sampler_location_ = locations[0]; | 1309 sampler_location_ = locations[0]; |
1262 mask_sampler_location_ = locations[1]; | 1310 mask_sampler_location_ = locations[1]; |
1263 alpha_location_ = locations[2]; | 1311 alpha_location_ = locations[2]; |
1264 mask_tex_coord_scale_location_ = locations[3]; | 1312 mask_tex_coord_scale_location_ = locations[3]; |
1265 mask_tex_coord_offset_location_ = locations[4]; | 1313 mask_tex_coord_offset_location_ = locations[4]; |
1266 color_matrix_location_ = locations[5]; | 1314 color_matrix_location_ = locations[5]; |
1267 color_offset_location_ = locations[6]; | 1315 color_offset_location_ = locations[6]; |
1268 } | 1316 } |
1269 | 1317 |
1270 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( | 1318 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( |
1271 TexCoordPrecision precision, SamplerType sampler) const { | 1319 TexCoordPrecision precision, |
1320 SamplerType sampler) const { | |
1321 // clang-format off | |
1272 return FRAGMENT_SHADER( | 1322 return FRAGMENT_SHADER( |
1273 precision mediump float; | 1323 precision mediump float; |
1274 varying TexCoordPrecision vec2 v_texCoord; | 1324 varying TexCoordPrecision vec2 v_texCoord; |
1275 uniform SamplerType s_texture; | 1325 uniform sampler2D s_texture; |
1276 uniform SamplerType s_mask; | 1326 uniform SamplerType s_mask; |
1277 uniform vec2 maskTexCoordScale; | 1327 uniform vec2 maskTexCoordScale; |
1278 uniform vec2 maskTexCoordOffset; | 1328 uniform vec2 maskTexCoordOffset; |
1279 uniform mat4 colorMatrix; | 1329 uniform mat4 colorMatrix; |
1280 uniform vec4 colorOffset; | 1330 uniform vec4 colorOffset; |
1281 uniform float alpha; | 1331 uniform float alpha; |
1282 void main() { | 1332 void main() { |
1283 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1333 vec4 texColor = texture2D(s_texture, v_texCoord); |
1284 float nonZeroAlpha = max(texColor.a, 0.00001); | 1334 float nonZeroAlpha = max(texColor.a, 0.00001); |
1285 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1335 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1286 texColor = colorMatrix * texColor + colorOffset; | 1336 texColor = colorMatrix * texColor + colorOffset; |
1287 texColor.rgb *= texColor.a; | 1337 texColor.rgb *= texColor.a; |
1288 texColor = clamp(texColor, 0.0, 1.0); | 1338 texColor = clamp(texColor, 0.0, 1.0); |
1289 TexCoordPrecision vec2 maskTexCoord = | 1339 TexCoordPrecision vec2 maskTexCoord = |
1290 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1340 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1291 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1341 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1292 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1342 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1293 gl_FragColor = texColor * alpha * maskColor.w; | 1343 gl_FragColor = texColor * alpha * maskColor.w; |
1294 } | 1344 } |
1295 ); // NOLINT(whitespace/parens) | 1345 ); // NOLINT(whitespace/parens) |
1346 // clang-format on | |
1296 } | 1347 } |
1297 | 1348 |
1298 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 1349 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
1299 : y_texture_location_(-1), | 1350 : y_texture_location_(-1), |
1300 u_texture_location_(-1), | 1351 u_texture_location_(-1), |
1301 v_texture_location_(-1), | 1352 v_texture_location_(-1), |
1302 alpha_location_(-1), | 1353 alpha_location_(-1), |
1303 yuv_matrix_location_(-1), | 1354 yuv_matrix_location_(-1), |
1304 yuv_adj_location_(-1) {} | 1355 yuv_adj_location_(-1) { |
1356 } | |
1305 | 1357 |
1306 void FragmentShaderYUVVideo::Init(GLES2Interface* context, | 1358 void FragmentShaderYUVVideo::Init(GLES2Interface* context, |
1307 unsigned program, | 1359 unsigned program, |
1308 int* base_uniform_index) { | 1360 int* base_uniform_index) { |
1309 static const char* uniforms[] = { | 1361 static const char* uniforms[] = { |
1310 "y_texture", | 1362 "y_texture", "u_texture", "v_texture", "alpha", "yuv_matrix", "yuv_adj", |
1311 "u_texture", | |
1312 "v_texture", | |
1313 "alpha", | |
1314 "yuv_matrix", | |
1315 "yuv_adj", | |
1316 }; | 1363 }; |
1317 int locations[arraysize(uniforms)]; | 1364 int locations[arraysize(uniforms)]; |
1318 | 1365 |
1319 GetProgramUniformLocations(context, | 1366 GetProgramUniformLocations(context, |
1320 program, | 1367 program, |
1321 arraysize(uniforms), | 1368 arraysize(uniforms), |
1322 uniforms, | 1369 uniforms, |
1323 locations, | 1370 locations, |
1324 base_uniform_index); | 1371 base_uniform_index); |
1325 y_texture_location_ = locations[0]; | 1372 y_texture_location_ = locations[0]; |
1326 u_texture_location_ = locations[1]; | 1373 u_texture_location_ = locations[1]; |
1327 v_texture_location_ = locations[2]; | 1374 v_texture_location_ = locations[2]; |
1328 alpha_location_ = locations[3]; | 1375 alpha_location_ = locations[3]; |
1329 yuv_matrix_location_ = locations[4]; | 1376 yuv_matrix_location_ = locations[4]; |
1330 yuv_adj_location_ = locations[5]; | 1377 yuv_adj_location_ = locations[5]; |
1331 } | 1378 } |
1332 | 1379 |
1333 std::string FragmentShaderYUVVideo::GetShaderString( | 1380 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
1334 TexCoordPrecision precision, SamplerType sampler) const { | 1381 SamplerType sampler) const { |
1382 // clang-format off | |
1335 return FRAGMENT_SHADER( | 1383 return FRAGMENT_SHADER( |
1336 precision mediump float; | 1384 precision mediump float; |
1337 precision mediump int; | 1385 precision mediump int; |
1338 varying TexCoordPrecision vec2 v_texCoord; | 1386 varying TexCoordPrecision vec2 v_texCoord; |
1339 uniform SamplerType y_texture; | 1387 uniform SamplerType y_texture; |
1340 uniform SamplerType u_texture; | 1388 uniform SamplerType u_texture; |
1341 uniform SamplerType v_texture; | 1389 uniform SamplerType v_texture; |
1342 uniform float alpha; | 1390 uniform float alpha; |
1343 uniform vec3 yuv_adj; | 1391 uniform vec3 yuv_adj; |
1344 uniform mat3 yuv_matrix; | 1392 uniform mat3 yuv_matrix; |
1345 void main() { | 1393 void main() { |
1346 float y_raw = TextureLookup(y_texture, v_texCoord).x; | 1394 float y_raw = TextureLookup(y_texture, v_texCoord).x; |
1347 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; | 1395 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; |
1348 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; | 1396 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; |
1349 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 1397 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
1350 vec3 rgb = yuv_matrix * yuv; | 1398 vec3 rgb = yuv_matrix * yuv; |
1351 gl_FragColor = vec4(rgb, 1.0) * alpha; | 1399 gl_FragColor = vec4(rgb, 1.0) * alpha; |
1352 } | 1400 } |
1353 ); // NOLINT(whitespace/parens) | 1401 ); // NOLINT(whitespace/parens) |
1402 // clang-format on | |
1354 } | 1403 } |
1355 | 1404 |
1356 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() | 1405 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() |
1357 : y_texture_location_(-1), | 1406 : y_texture_location_(-1), |
1358 u_texture_location_(-1), | 1407 u_texture_location_(-1), |
1359 v_texture_location_(-1), | 1408 v_texture_location_(-1), |
1360 a_texture_location_(-1), | 1409 a_texture_location_(-1), |
1361 alpha_location_(-1), | 1410 alpha_location_(-1), |
1362 yuv_matrix_location_(-1), | 1411 yuv_matrix_location_(-1), |
1363 yuv_adj_location_(-1) { | 1412 yuv_adj_location_(-1) { |
(...skipping 22 matching lines...) Expand all Loading... | |
1386 y_texture_location_ = locations[0]; | 1435 y_texture_location_ = locations[0]; |
1387 u_texture_location_ = locations[1]; | 1436 u_texture_location_ = locations[1]; |
1388 v_texture_location_ = locations[2]; | 1437 v_texture_location_ = locations[2]; |
1389 a_texture_location_ = locations[3]; | 1438 a_texture_location_ = locations[3]; |
1390 alpha_location_ = locations[4]; | 1439 alpha_location_ = locations[4]; |
1391 yuv_matrix_location_ = locations[5]; | 1440 yuv_matrix_location_ = locations[5]; |
1392 yuv_adj_location_ = locations[6]; | 1441 yuv_adj_location_ = locations[6]; |
1393 } | 1442 } |
1394 | 1443 |
1395 std::string FragmentShaderYUVAVideo::GetShaderString( | 1444 std::string FragmentShaderYUVAVideo::GetShaderString( |
1396 TexCoordPrecision precision, SamplerType sampler) const { | 1445 TexCoordPrecision precision, |
1446 SamplerType sampler) const { | |
1447 // clang-format off | |
1397 return FRAGMENT_SHADER( | 1448 return FRAGMENT_SHADER( |
1398 precision mediump float; | 1449 precision mediump float; |
1399 precision mediump int; | 1450 precision mediump int; |
1400 varying TexCoordPrecision vec2 v_texCoord; | 1451 varying TexCoordPrecision vec2 v_texCoord; |
1401 uniform SamplerType y_texture; | 1452 uniform SamplerType y_texture; |
1402 uniform SamplerType u_texture; | 1453 uniform SamplerType u_texture; |
1403 uniform SamplerType v_texture; | 1454 uniform SamplerType v_texture; |
1404 uniform SamplerType a_texture; | 1455 uniform SamplerType a_texture; |
1405 uniform float alpha; | 1456 uniform float alpha; |
1406 uniform vec3 yuv_adj; | 1457 uniform vec3 yuv_adj; |
1407 uniform mat3 yuv_matrix; | 1458 uniform mat3 yuv_matrix; |
1408 void main() { | 1459 void main() { |
1409 float y_raw = TextureLookup(y_texture, v_texCoord).x; | 1460 float y_raw = TextureLookup(y_texture, v_texCoord).x; |
1410 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; | 1461 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; |
1411 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; | 1462 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; |
1412 float a_raw = TextureLookup(a_texture, v_texCoord).x; | 1463 float a_raw = TextureLookup(a_texture, v_texCoord).x; |
1413 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 1464 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
1414 vec3 rgb = yuv_matrix * yuv; | 1465 vec3 rgb = yuv_matrix * yuv; |
1415 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); | 1466 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); |
1416 } | 1467 } |
1417 ); // NOLINT(whitespace/parens) | 1468 ); // NOLINT(whitespace/parens) |
1469 // clang-format on | |
1418 } | 1470 } |
1419 | 1471 |
1420 FragmentShaderColor::FragmentShaderColor() | 1472 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { |
1421 : color_location_(-1) {} | 1473 } |
1422 | 1474 |
1423 void FragmentShaderColor::Init(GLES2Interface* context, | 1475 void FragmentShaderColor::Init(GLES2Interface* context, |
1424 unsigned program, | 1476 unsigned program, |
1425 int* base_uniform_index) { | 1477 int* base_uniform_index) { |
1426 static const char* uniforms[] = { | 1478 static const char* uniforms[] = { |
1427 "color", | 1479 "color", |
1428 }; | 1480 }; |
1429 int locations[arraysize(uniforms)]; | 1481 int locations[arraysize(uniforms)]; |
1430 | 1482 |
1431 GetProgramUniformLocations(context, | 1483 GetProgramUniformLocations(context, |
1432 program, | 1484 program, |
1433 arraysize(uniforms), | 1485 arraysize(uniforms), |
1434 uniforms, | 1486 uniforms, |
1435 locations, | 1487 locations, |
1436 base_uniform_index); | 1488 base_uniform_index); |
1437 color_location_ = locations[0]; | 1489 color_location_ = locations[0]; |
1438 } | 1490 } |
1439 | 1491 |
1440 std::string FragmentShaderColor::GetShaderString( | 1492 std::string FragmentShaderColor::GetShaderString(TexCoordPrecision precision, |
1441 TexCoordPrecision precision, SamplerType sampler) const { | 1493 SamplerType sampler) const { |
1494 // clang-format off | |
1442 return FRAGMENT_SHADER( | 1495 return FRAGMENT_SHADER( |
1443 precision mediump float; | 1496 precision mediump float; |
1444 uniform vec4 color; | 1497 uniform vec4 color; |
1445 void main() { | 1498 void main() { |
1446 gl_FragColor = color; | 1499 gl_FragColor = color; |
1447 } | 1500 } |
1448 ); // NOLINT(whitespace/parens) | 1501 ); // NOLINT(whitespace/parens) |
1502 // clang-format on | |
1449 } | 1503 } |
1450 | 1504 |
1451 FragmentShaderColorAA::FragmentShaderColorAA() | 1505 FragmentShaderColorAA::FragmentShaderColorAA() : color_location_(-1) { |
1452 : color_location_(-1) {} | 1506 } |
1453 | 1507 |
1454 void FragmentShaderColorAA::Init(GLES2Interface* context, | 1508 void FragmentShaderColorAA::Init(GLES2Interface* context, |
1455 unsigned program, | 1509 unsigned program, |
1456 int* base_uniform_index) { | 1510 int* base_uniform_index) { |
1457 static const char* uniforms[] = { | 1511 static const char* uniforms[] = { |
1458 "color", | 1512 "color", |
1459 }; | 1513 }; |
1460 int locations[arraysize(uniforms)]; | 1514 int locations[arraysize(uniforms)]; |
1461 | 1515 |
1462 GetProgramUniformLocations(context, | 1516 GetProgramUniformLocations(context, |
1463 program, | 1517 program, |
1464 arraysize(uniforms), | 1518 arraysize(uniforms), |
1465 uniforms, | 1519 uniforms, |
1466 locations, | 1520 locations, |
1467 base_uniform_index); | 1521 base_uniform_index); |
1468 color_location_ = locations[0]; | 1522 color_location_ = locations[0]; |
1469 } | 1523 } |
1470 | 1524 |
1471 std::string FragmentShaderColorAA::GetShaderString( | 1525 std::string FragmentShaderColorAA::GetShaderString(TexCoordPrecision precision, |
1472 TexCoordPrecision precision, SamplerType sampler) const { | 1526 SamplerType sampler) const { |
1527 // clang-format off | |
1473 return FRAGMENT_SHADER( | 1528 return FRAGMENT_SHADER( |
1474 precision mediump float; | 1529 precision mediump float; |
1475 uniform vec4 color; | 1530 uniform vec4 color; |
1476 varying vec4 edge_dist[2]; // 8 edge distances. | 1531 varying vec4 edge_dist[2]; // 8 edge distances. |
1477 | 1532 |
1478 void main() { | 1533 void main() { |
1479 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1534 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1480 vec2 d2 = min(d4.xz, d4.yw); | 1535 vec2 d2 = min(d4.xz, d4.yw); |
1481 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1536 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1482 gl_FragColor = color * aa; | 1537 gl_FragColor = color * aa; |
1483 } | 1538 } |
1484 ); // NOLINT(whitespace/parens) | 1539 ); // NOLINT(whitespace/parens) |
1540 // clang-format on | |
1485 } | 1541 } |
1486 | 1542 |
1487 FragmentShaderCheckerboard::FragmentShaderCheckerboard() | 1543 FragmentShaderCheckerboard::FragmentShaderCheckerboard() |
1488 : alpha_location_(-1), | 1544 : alpha_location_(-1), |
1489 tex_transform_location_(-1), | 1545 tex_transform_location_(-1), |
1490 frequency_location_(-1) {} | 1546 frequency_location_(-1) { |
1547 } | |
1491 | 1548 |
1492 void FragmentShaderCheckerboard::Init(GLES2Interface* context, | 1549 void FragmentShaderCheckerboard::Init(GLES2Interface* context, |
1493 unsigned program, | 1550 unsigned program, |
1494 int* base_uniform_index) { | 1551 int* base_uniform_index) { |
1495 static const char* uniforms[] = { | 1552 static const char* uniforms[] = { |
1496 "alpha", | 1553 "alpha", "texTransform", "frequency", "color", |
1497 "texTransform", | |
1498 "frequency", | |
1499 "color", | |
1500 }; | 1554 }; |
1501 int locations[arraysize(uniforms)]; | 1555 int locations[arraysize(uniforms)]; |
1502 | 1556 |
1503 GetProgramUniformLocations(context, | 1557 GetProgramUniformLocations(context, |
1504 program, | 1558 program, |
1505 arraysize(uniforms), | 1559 arraysize(uniforms), |
1506 uniforms, | 1560 uniforms, |
1507 locations, | 1561 locations, |
1508 base_uniform_index); | 1562 base_uniform_index); |
1509 alpha_location_ = locations[0]; | 1563 alpha_location_ = locations[0]; |
1510 tex_transform_location_ = locations[1]; | 1564 tex_transform_location_ = locations[1]; |
1511 frequency_location_ = locations[2]; | 1565 frequency_location_ = locations[2]; |
1512 color_location_ = locations[3]; | 1566 color_location_ = locations[3]; |
1513 } | 1567 } |
1514 | 1568 |
1515 std::string FragmentShaderCheckerboard::GetShaderString( | 1569 std::string FragmentShaderCheckerboard::GetShaderString( |
1516 TexCoordPrecision precision, SamplerType sampler) const { | 1570 TexCoordPrecision precision, |
1571 SamplerType sampler) const { | |
1517 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | 1572 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
1518 // by Munshi, Ginsburg, Shreiner. | 1573 // by Munshi, Ginsburg, Shreiner. |
1574 // clang-format off | |
1519 return FRAGMENT_SHADER( | 1575 return FRAGMENT_SHADER( |
1520 precision mediump float; | 1576 precision mediump float; |
1521 precision mediump int; | 1577 precision mediump int; |
1522 varying vec2 v_texCoord; | 1578 varying vec2 v_texCoord; |
1523 uniform float alpha; | 1579 uniform float alpha; |
1524 uniform float frequency; | 1580 uniform float frequency; |
1525 uniform vec4 texTransform; | 1581 uniform vec4 texTransform; |
1526 uniform vec4 color; | 1582 uniform vec4 color; |
1527 void main() { | 1583 void main() { |
1528 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | 1584 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
1529 vec4 color2 = color; | 1585 vec4 color2 = color; |
1530 vec2 texCoord = | 1586 vec2 texCoord = |
1531 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 1587 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
1532 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1588 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1533 float picker = abs(coord.x - coord.y); // NOLINT | 1589 float picker = abs(coord.x - coord.y); // NOLINT |
1534 gl_FragColor = mix(color1, color2, picker) * alpha; | 1590 gl_FragColor = mix(color1, color2, picker) * alpha; |
1535 } | 1591 } |
1536 ); // NOLINT(whitespace/parens) | 1592 ); // NOLINT(whitespace/parens) |
1593 // clang-format on | |
1537 } | 1594 } |
1538 | 1595 |
1539 } // namespace cc | 1596 } // namespace cc |
OLD | NEW |