Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: cc/shader.cc

Issue 12314003: cc: Use highp precision for texture coordinates if available (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use getShaderPrecisionFormat instead of GL_FRAGMENT_PRECISION_HIGH Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/shader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/shader.h" 5 #include "cc/shader.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "cc/gl_renderer.h" // For the GLC() macro.
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
11 #include "third_party/khronos/GLES2/gl2.h"
10 12
11 #define SHADER0(Src) #Src 13 #define SHADER0(Src) #Src
12 #define SHADER(Src) SHADER0(Src) 14 #define VERTEX_SHADER(Src) setVertexTexCoordPrecision(context, SHADER0(Src))
15 #define FRAGMENT_SHADER(Src) setFragTexCoordPrecision(context, SHADER0(Src))
13 16
14 using WebKit::WebGraphicsContext3D; 17 using WebKit::WebGraphicsContext3D;
15 18
16 namespace cc { 19 namespace cc {
17 20
18 namespace { 21 namespace {
19 22
20 static void getProgramUniformLocations(WebGraphicsContext3D* context, unsigned p rogram, const char** shaderUniforms, size_t count, size_t maxLocations, int* loc ations, bool usingBindUniform, int* baseUniformIndex) 23 static void getProgramUniformLocations(WebGraphicsContext3D* context, unsigned p rogram, const char** shaderUniforms, size_t count, size_t maxLocations, int* loc ations, bool usingBindUniform, int* baseUniformIndex)
21 { 24 {
22 for (size_t uniformIndex = 0; uniformIndex < count; uniformIndex ++) { 25 for (size_t uniformIndex = 0; uniformIndex < count; uniformIndex ++) {
23 DCHECK(uniformIndex < maxLocations); 26 DCHECK(uniformIndex < maxLocations);
24 27
25 if (usingBindUniform) { 28 if (usingBindUniform) {
26 locations[uniformIndex] = (*baseUniformIndex)++; 29 locations[uniformIndex] = (*baseUniformIndex)++;
27 context->bindUniformLocationCHROMIUM(program, locations[uniformIndex ], shaderUniforms[uniformIndex]); 30 context->bindUniformLocationCHROMIUM(program, locations[uniformIndex ], shaderUniforms[uniformIndex]);
28 } else 31 } else
29 locations[uniformIndex] = context->getUniformLocation(program, shade rUniforms[uniformIndex]); 32 locations[uniformIndex] = context->getUniformLocation(program, shade rUniforms[uniformIndex]);
30 } 33 }
31 } 34 }
32 35
36 static std::string setFragTexCoordPrecision(WebGraphicsContext3D* context,
37 const char* shaderString) {
38 GLint range[2];
39 GLint precision = 0;
40 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER,
41 GL_HIGH_FLOAT,
42 range, &precision));
43
44 std::string texCoordPrecision = (precision != 0) ? "highp" : "mediump";
Sami 2013/02/22 11:52:19 For extra paranoia let's add DCHECKs here that mak
45
46 return "#define TexCoordPrecision " + texCoordPrecision + "\n" +
47 std::string(shaderString);
48 }
49
50 static std::string setVertexTexCoordPrecision(WebGraphicsContext3D* context,
51 const char* shaderString) {
52 return "#define TexCoordPrecision highp\n"
53 + std::string(shaderString);
Sami 2013/02/22 11:52:19 Nit: move the + to the previous line for consisten
54 }
55
33 } 56 }
34 57
35 VertexShaderPosTex::VertexShaderPosTex() 58 VertexShaderPosTex::VertexShaderPosTex()
36 : m_matrixLocation(-1) 59 : m_matrixLocation(-1)
37 { 60 {
38 } 61 }
39 62
40 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b ool usingBindUniform, int* baseUniformIndex) 63 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b ool usingBindUniform, int* baseUniformIndex)
41 { 64 {
42 static const char* shaderUniforms[] = { 65 static const char* shaderUniforms[] = {
43 "matrix", 66 "matrix",
44 }; 67 };
45 int locations[1]; 68 int locations[1];
46 69
47 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 70 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
48 71
49 m_matrixLocation = locations[0]; 72 m_matrixLocation = locations[0];
50 DCHECK(m_matrixLocation != -1); 73 DCHECK(m_matrixLocation != -1);
51 } 74 }
52 75
53 std::string VertexShaderPosTex::getShaderString() const 76 std::string VertexShaderPosTex::getShaderString(WebGraphicsContext3D* context) c onst
54 { 77 {
55 return SHADER( 78 return VERTEX_SHADER(
56 attribute vec4 a_position; 79 attribute vec4 a_position;
57 attribute vec2 a_texCoord; 80 attribute TexCoordPrecision vec2 a_texCoord;
58 uniform mat4 matrix; 81 uniform mat4 matrix;
59 varying vec2 v_texCoord; 82 varying TexCoordPrecision vec2 v_texCoord;
60 void main() 83 void main()
61 { 84 {
62 gl_Position = matrix * a_position; 85 gl_Position = matrix * a_position;
63 v_texCoord = a_texCoord; 86 v_texCoord = a_texCoord;
64 } 87 }
65 ); 88 );
66 } 89 }
67 90
68 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() 91 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch()
69 : m_matrixLocation(-1) 92 : m_matrixLocation(-1)
70 , m_texScaleLocation(-1) 93 , m_texScaleLocation(-1)
71 { 94 {
72 } 95 }
73 96
74 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) 97 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex)
75 { 98 {
76 static const char* shaderUniforms[] = { 99 static const char* shaderUniforms[] = {
77 "matrix", 100 "matrix",
78 "texScale", 101 "texScale",
79 }; 102 };
80 int locations[2]; 103 int locations[2];
81 104
82 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 105 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
83 106
84 m_matrixLocation = locations[0]; 107 m_matrixLocation = locations[0];
85 m_texScaleLocation = locations[1]; 108 m_texScaleLocation = locations[1];
86 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1); 109 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1);
87 } 110 }
88 111
89 std::string VertexShaderPosTexYUVStretch::getShaderString() const 112 std::string VertexShaderPosTexYUVStretch::getShaderString(WebGraphicsContext3D* context) const
90 { 113 {
91 return SHADER( 114 return VERTEX_SHADER(
92 precision mediump float; 115 precision mediump float;
93 attribute vec4 a_position; 116 attribute vec4 a_position;
94 attribute vec2 a_texCoord; 117 attribute TexCoordPrecision vec2 a_texCoord;
95 uniform mat4 matrix; 118 uniform mat4 matrix;
96 varying vec2 v_texCoord; 119 varying TexCoordPrecision vec2 v_texCoord;
97 uniform vec2 texScale; 120 uniform TexCoordPrecision vec2 texScale;
98 void main() 121 void main()
99 { 122 {
100 gl_Position = matrix * a_position; 123 gl_Position = matrix * a_position;
101 v_texCoord = a_texCoord * texScale; 124 v_texCoord = a_texCoord * texScale;
102 } 125 }
103 ); 126 );
104 } 127 }
105 128
106 VertexShaderPos::VertexShaderPos() 129 VertexShaderPos::VertexShaderPos()
107 : m_matrixLocation(-1) 130 : m_matrixLocation(-1)
108 { 131 {
109 } 132 }
110 133
111 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) 134 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex)
112 { 135 {
113 static const char* shaderUniforms[] = { 136 static const char* shaderUniforms[] = {
114 "matrix", 137 "matrix",
115 }; 138 };
116 int locations[1]; 139 int locations[1];
117 140
118 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 141 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
119 142
120 m_matrixLocation = locations[0]; 143 m_matrixLocation = locations[0];
121 DCHECK(m_matrixLocation != -1); 144 DCHECK(m_matrixLocation != -1);
122 } 145 }
123 146
124 std::string VertexShaderPos::getShaderString() const 147 std::string VertexShaderPos::getShaderString(WebGraphicsContext3D* context) cons t
125 { 148 {
126 return SHADER( 149 return VERTEX_SHADER(
127 attribute vec4 a_position; 150 attribute vec4 a_position;
128 uniform mat4 matrix; 151 uniform mat4 matrix;
129 void main() 152 void main()
130 { 153 {
131 gl_Position = matrix * a_position; 154 gl_Position = matrix * a_position;
132 } 155 }
133 ); 156 );
134 } 157 }
135 158
136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() 159 VertexShaderPosTexTransform::VertexShaderPosTexTransform()
(...skipping 13 matching lines...) Expand all
150 int locations[3]; 173 int locations[3];
151 174
152 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 175 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
153 176
154 m_matrixLocation = locations[0]; 177 m_matrixLocation = locations[0];
155 m_texTransformLocation = locations[1]; 178 m_texTransformLocation = locations[1];
156 m_vertexOpacityLocation = locations[2]; 179 m_vertexOpacityLocation = locations[2];
157 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1); 180 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1);
158 } 181 }
159 182
160 std::string VertexShaderPosTexTransform::getShaderString() const 183 std::string VertexShaderPosTexTransform::getShaderString(WebGraphicsContext3D* c ontext) const
161 { 184 {
162 return SHADER( 185 return VERTEX_SHADER(
163 attribute vec4 a_position; 186 attribute vec4 a_position;
164 attribute vec2 a_texCoord; 187 attribute TexCoordPrecision vec2 a_texCoord;
165 attribute float a_index; 188 attribute float a_index;
166 uniform mat4 matrix[8]; 189 uniform mat4 matrix[8];
167 uniform vec4 texTransform[8]; 190 uniform TexCoordPrecision vec4 texTransform[8];
168 uniform float opacity[32]; 191 uniform float opacity[32];
169 varying vec2 v_texCoord; 192 varying TexCoordPrecision vec2 v_texCoord;
170 varying float v_alpha; 193 varying float v_alpha;
171 void main() 194 void main()
172 { 195 {
173 gl_Position = matrix[int(a_index * 0.25)] * a_position; 196 gl_Position = matrix[int(a_index * 0.25)] * a_position;
174 vec4 texTrans = texTransform[int(a_index * 0.25)]; 197 TexCoordPrecision vec4 texTrans = texTransform[int(a_index * 0.25)];
175 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; 198 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy;
176 v_alpha = opacity[int(a_index)]; 199 v_alpha = opacity[int(a_index)];
177 } 200 }
178 ); 201 );
179 } 202 }
180 203
181 std::string VertexShaderPosTexIdentity::getShaderString() const 204 std::string VertexShaderPosTexIdentity::getShaderString(WebGraphicsContext3D* co ntext) const
182 { 205 {
183 return SHADER( 206 return VERTEX_SHADER(
184 attribute vec4 a_position; 207 attribute vec4 a_position;
185 varying vec2 v_texCoord; 208 varying TexCoordPrecision vec2 v_texCoord;
186 void main() 209 void main()
187 { 210 {
188 gl_Position = a_position; 211 gl_Position = a_position;
189 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; 212 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5;
190 } 213 }
191 ); 214 );
192 } 215 }
193 216
194 VertexShaderQuad::VertexShaderQuad() 217 VertexShaderQuad::VertexShaderQuad()
195 : m_matrixLocation(-1) 218 : m_matrixLocation(-1)
(...skipping 14 matching lines...) Expand all
210 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 233 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
211 234
212 m_matrixLocation = locations[0]; 235 m_matrixLocation = locations[0];
213 m_pointLocation = locations[1]; 236 m_pointLocation = locations[1];
214 m_texScaleLocation = locations[2]; 237 m_texScaleLocation = locations[2];
215 DCHECK_NE(m_matrixLocation, -1); 238 DCHECK_NE(m_matrixLocation, -1);
216 DCHECK_NE(m_pointLocation, -1); 239 DCHECK_NE(m_pointLocation, -1);
217 DCHECK_NE(m_texScaleLocation, -1); 240 DCHECK_NE(m_texScaleLocation, -1);
218 } 241 }
219 242
220 std::string VertexShaderQuad::getShaderString() const 243 std::string VertexShaderQuad::getShaderString(WebGraphicsContext3D* context) con st
221 { 244 {
222 return SHADER( 245 return VERTEX_SHADER(
223 attribute vec4 a_position; 246 attribute TexCoordPrecision vec4 a_position;
224 attribute vec2 a_texCoord; 247 attribute TexCoordPrecision vec2 a_texCoord;
225 uniform mat4 matrix; 248 uniform mat4 matrix;
226 uniform vec2 point[4]; 249 uniform TexCoordPrecision vec2 point[4];
227 uniform vec2 texScale; 250 uniform TexCoordPrecision vec2 texScale;
228 varying vec2 v_texCoord; 251 varying TexCoordPrecision vec2 v_texCoord;
229 void main() 252 void main()
230 { 253 {
231 vec2 complement = abs(a_texCoord - 1.0); 254 TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0);
232 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); 255 TexCoordPrecision vec4 pos = vec4(0.0, 0.0, a_position.z, a_position .w);
233 pos.xy += (complement.x * complement.y) * point[0]; 256 pos.xy += (complement.x * complement.y) * point[0];
234 pos.xy += (a_texCoord.x * complement.y) * point[1]; 257 pos.xy += (a_texCoord.x * complement.y) * point[1];
235 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; 258 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2];
236 pos.xy += (complement.x * a_texCoord.y) * point[3]; 259 pos.xy += (complement.x * a_texCoord.y) * point[3];
237 gl_Position = matrix * pos; 260 gl_Position = matrix * pos;
238 v_texCoord = (pos.xy + vec2(0.5)) * texScale; 261 v_texCoord = (pos.xy + vec2(0.5)) * texScale;
239 } 262 }
240 ); 263 );
241 } 264 }
242 265
(...skipping 14 matching lines...) Expand all
257 int locations[3]; 280 int locations[3];
258 281
259 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 282 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
260 283
261 m_matrixLocation = locations[0]; 284 m_matrixLocation = locations[0];
262 m_pointLocation = locations[1]; 285 m_pointLocation = locations[1];
263 m_vertexTexTransformLocation = locations[2]; 286 m_vertexTexTransformLocation = locations[2];
264 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1); 287 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1);
265 } 288 }
266 289
267 std::string VertexShaderTile::getShaderString() const 290 std::string VertexShaderTile::getShaderString(WebGraphicsContext3D* context) con st
268 { 291 {
269 return SHADER( 292 return VERTEX_SHADER(
270 attribute vec4 a_position; 293 attribute TexCoordPrecision vec4 a_position;
271 attribute vec2 a_texCoord; 294 attribute TexCoordPrecision vec2 a_texCoord;
272 uniform mat4 matrix; 295 uniform mat4 matrix;
273 uniform vec2 point[4]; 296 uniform TexCoordPrecision vec2 point[4];
274 uniform vec4 vertexTexTransform; 297 uniform TexCoordPrecision vec4 vertexTexTransform;
275 varying vec2 v_texCoord; 298 varying TexCoordPrecision vec2 v_texCoord;
276 void main() 299 void main()
277 { 300 {
278 vec2 complement = abs(a_texCoord - 1.0); 301 vec2 complement = abs(a_texCoord - 1.0);
279 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); 302 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w);
280 pos.xy += (complement.x * complement.y) * point[0]; 303 pos.xy += (complement.x * complement.y) * point[0];
281 pos.xy += (a_texCoord.x * complement.y) * point[1]; 304 pos.xy += (a_texCoord.x * complement.y) * point[1];
282 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; 305 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2];
283 pos.xy += (complement.x * a_texCoord.y) * point[3]; 306 pos.xy += (complement.x * a_texCoord.y) * point[3];
284 gl_Position = matrix * pos; 307 gl_Position = matrix * pos;
285 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; 308 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy;
(...skipping 15 matching lines...) Expand all
301 }; 324 };
302 int locations[2]; 325 int locations[2];
303 326
304 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 327 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
305 328
306 m_matrixLocation = locations[0]; 329 m_matrixLocation = locations[0];
307 m_texMatrixLocation = locations[1]; 330 m_texMatrixLocation = locations[1];
308 return m_matrixLocation != -1 && m_texMatrixLocation != -1; 331 return m_matrixLocation != -1 && m_texMatrixLocation != -1;
309 } 332 }
310 333
311 std::string VertexShaderVideoTransform::getShaderString() const 334 std::string VertexShaderVideoTransform::getShaderString(WebGraphicsContext3D* co ntext) const
312 { 335 {
313 return SHADER( 336 return VERTEX_SHADER(
314 attribute vec4 a_position; 337 attribute vec4 a_position;
315 attribute vec2 a_texCoord; 338 attribute TexCoordPrecision vec2 a_texCoord;
316 uniform mat4 matrix; 339 uniform mat4 matrix;
317 uniform mat4 texMatrix; 340 uniform TexCoordPrecision mat4 texMatrix;
318 varying vec2 v_texCoord; 341 varying TexCoordPrecision vec2 v_texCoord;
319 void main() 342 void main()
320 { 343 {
321 gl_Position = matrix * a_position; 344 gl_Position = matrix * a_position;
322 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); 345 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0));
323 } 346 }
324 ); 347 );
325 } 348 }
326 349
327 FragmentTexAlphaBinding::FragmentTexAlphaBinding() 350 FragmentTexAlphaBinding::FragmentTexAlphaBinding()
328 : m_samplerLocation(-1) 351 : m_samplerLocation(-1)
(...skipping 27 matching lines...) Expand all
356 "s_texture", 379 "s_texture",
357 }; 380 };
358 int locations[1]; 381 int locations[1];
359 382
360 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 383 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
361 384
362 m_samplerLocation = locations[0]; 385 m_samplerLocation = locations[0];
363 DCHECK(m_samplerLocation != -1); 386 DCHECK(m_samplerLocation != -1);
364 } 387 }
365 388
366 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const 389 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString(WebGraphicsCo ntext3D* context) const
367 { 390 {
368 return SHADER( 391 return FRAGMENT_SHADER(
369 precision mediump float; 392 precision mediump float;
370 varying vec2 v_texCoord; 393 varying TexCoordPrecision vec2 v_texCoord;
371 varying float v_alpha; 394 varying float v_alpha;
372 uniform sampler2D s_texture; 395 uniform sampler2D s_texture;
373 void main() 396 void main()
374 { 397 {
375 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC oord.y)); 398 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC oord.y));
376 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * v_alpha; 399 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * v_alpha;
377 } 400 }
378 ); 401 );
379 } 402 }
380 403
381 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne d program, bool usingBindUniform, int* baseUniformIndex) 404 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne d program, bool usingBindUniform, int* baseUniformIndex)
382 { 405 {
383 static const char* shaderUniforms[] = { 406 static const char* shaderUniforms[] = {
384 "s_texture", 407 "s_texture",
385 }; 408 };
386 int locations[1]; 409 int locations[1];
387 410
388 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 411 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
389 412
390 m_samplerLocation = locations[0]; 413 m_samplerLocation = locations[0];
391 return m_samplerLocation != -1; 414 return m_samplerLocation != -1;
392 } 415 }
393 416
394 std::string FragmentShaderOESImageExternal::getShaderString() const 417 std::string FragmentShaderOESImageExternal::getShaderString(WebGraphicsContext3D * context) const
395 { 418 {
396 // Cannot use the SHADER() macro because of the '#' char 419 // Cannot use the FRAGMENT_SHADER() macro because of the '#' char
397 return "#extension GL_OES_EGL_image_external : require \n" 420 return setFragTexCoordPrecision(context,
421 "#extension GL_OES_EGL_image_external : require \n"
398 "precision mediump float;\n" 422 "precision mediump float;\n"
399 "varying vec2 v_texCoord;\n" 423 "varying TexCoordPrecision vec2 v_texCoord;\n"
400 "uniform samplerExternalOES s_texture;\n" 424 "uniform samplerExternalOES s_texture;\n"
401 "void main()\n" 425 "void main()\n"
402 "{\n" 426 "{\n"
403 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" 427 " vec4 texColor = texture2D(s_texture, v_texCoord);\n"
404 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor .w);\n" 428 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor .w);\n"
405 "}\n"; 429 "}\n");
406 } 430 }
407 431
408 std::string FragmentShaderRGBATexAlpha::getShaderString() const 432 std::string FragmentShaderRGBATexAlpha::getShaderString(WebGraphicsContext3D* co ntext) const
409 { 433 {
410 return SHADER( 434 return FRAGMENT_SHADER(
411 precision mediump float; 435 precision mediump float;
412 varying vec2 v_texCoord; 436 varying TexCoordPrecision vec2 v_texCoord;
413 uniform sampler2D s_texture; 437 uniform sampler2D s_texture;
414 uniform float alpha; 438 uniform float alpha;
415 void main() 439 void main()
416 { 440 {
417 vec4 texColor = texture2D(s_texture, v_texCoord); 441 vec4 texColor = texture2D(s_texture, v_texCoord);
418 gl_FragColor = texColor * alpha; 442 gl_FragColor = texColor * alpha;
419 } 443 }
420 ); 444 );
421 } 445 }
422 446
423 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const 447 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString(WebGraphicsContex t3D* context) const
424 { 448 {
425 return SHADER( 449 return FRAGMENT_SHADER(
426 precision mediump float; 450 precision mediump float;
427 varying vec2 v_texCoord; 451 varying TexCoordPrecision vec2 v_texCoord;
428 varying float v_alpha; 452 varying float v_alpha;
429 uniform sampler2D s_texture; 453 uniform sampler2D s_texture;
430 void main() 454 void main()
431 { 455 {
432 vec4 texColor = texture2D(s_texture, v_texCoord); 456 vec4 texColor = texture2D(s_texture, v_texCoord);
433 gl_FragColor = texColor * v_alpha; 457 gl_FragColor = texColor * v_alpha;
434 } 458 }
435 ); 459 );
436 } 460 }
437 461
438 std::string FragmentShaderRGBATexRectFlipVaryingAlpha::getShaderString() const 462 std::string FragmentShaderRGBATexRectFlipVaryingAlpha::getShaderString(WebGraphi csContext3D* context) const
439 { 463 {
440 // This must be paired with VertexShaderPosTexTransform to pick up the texTr ansform uniform. 464 // This must be paired with VertexShaderPosTexTransform to pick up the texTr ansform uniform.
441 // The necessary #extension preprocessing directive breaks the SHADER and SH ADER0 macros. 465 // The necessary #extension preprocessing directive breaks the SHADER and SH ADER0 macros.
442 return "#extension GL_ARB_texture_rectangle : require\n" 466 return setFragTexCoordPrecision(context,
467 "#extension GL_ARB_texture_rectangle : require\n"
443 "precision mediump float;\n" 468 "precision mediump float;\n"
444 "varying vec2 v_texCoord;\n" 469 "varying TexCoordPrecision vec2 v_texCoord;\n"
445 "varying float v_alpha;\n" 470 "varying float v_alpha;\n"
446 "uniform vec4 texTransform;\n" 471 "uniform TexCoordPrecision vec4 texTransform;\n"
447 "uniform sampler2DRect s_texture;\n" 472 "uniform sampler2DRect s_texture;\n"
448 "void main()\n" 473 "void main()\n"
449 "{\n" 474 "{\n"
450 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex Transform.w - v_texCoord.y));\n" 475 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex Transform.w - v_texCoord.y));\n"
451 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo r.w) * v_alpha;\n" 476 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo r.w) * v_alpha;\n"
452 "}\n"; 477 "}\n");
453 } 478 }
454 479
455 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const 480 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString(WebGraphicsCo ntext3D* context) const
456 { 481 {
457 return "#extension GL_ARB_texture_rectangle : require\n" 482 return setFragTexCoordPrecision(context,
483 "#extension GL_ARB_texture_rectangle : require\n"
458 "precision mediump float;\n" 484 "precision mediump float;\n"
459 "varying vec2 v_texCoord;\n" 485 "varying TexCoordPrecision vec2 v_texCoord;\n"
460 "varying float v_alpha;\n" 486 "varying float v_alpha;\n"
461 "uniform sampler2DRect s_texture;\n" 487 "uniform sampler2DRect s_texture;\n"
462 "void main()\n" 488 "void main()\n"
463 "{\n" 489 "{\n"
464 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" 490 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n"
465 " gl_FragColor = texColor * v_alpha;\n" 491 " gl_FragColor = texColor * v_alpha;\n"
466 "}\n"; 492 "}\n");
467 } 493 }
468 494
469 std::string FragmentShaderRGBATexOpaque::getShaderString() const 495 std::string FragmentShaderRGBATexOpaque::getShaderString(WebGraphicsContext3D* c ontext) const
470 { 496 {
471 return SHADER( 497 return FRAGMENT_SHADER(
472 precision mediump float; 498 precision mediump float;
473 varying vec2 v_texCoord; 499 varying TexCoordPrecision vec2 v_texCoord;
474 uniform sampler2D s_texture; 500 uniform sampler2D s_texture;
475 void main() 501 void main()
476 { 502 {
477 vec4 texColor = texture2D(s_texture, v_texCoord); 503 vec4 texColor = texture2D(s_texture, v_texCoord);
478 gl_FragColor = vec4(texColor.rgb, 1.0); 504 gl_FragColor = vec4(texColor.rgb, 1.0);
479 } 505 }
480 ); 506 );
481 } 507 }
482 508
483 std::string FragmentShaderRGBATex::getShaderString() const 509 std::string FragmentShaderRGBATex::getShaderString(WebGraphicsContext3D* context ) const
484 { 510 {
485 return SHADER( 511 return FRAGMENT_SHADER(
486 precision mediump float; 512 precision mediump float;
487 varying vec2 v_texCoord; 513 varying TexCoordPrecision vec2 v_texCoord;
488 uniform sampler2D s_texture; 514 uniform sampler2D s_texture;
489 void main() 515 void main()
490 { 516 {
491 gl_FragColor = texture2D(s_texture, v_texCoord); 517 gl_FragColor = texture2D(s_texture, v_texCoord);
492 } 518 }
493 ); 519 );
494 } 520 }
495 521
496 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const 522 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString(WebGraphicsContex t3D* context) const
497 { 523 {
498 return SHADER( 524 return FRAGMENT_SHADER(
499 precision mediump float; 525 precision mediump float;
500 varying vec2 v_texCoord; 526 varying TexCoordPrecision vec2 v_texCoord;
501 uniform sampler2D s_texture; 527 uniform sampler2D s_texture;
502 uniform float alpha; 528 uniform float alpha;
503 void main() 529 void main()
504 { 530 {
505 vec4 texColor = texture2D(s_texture, v_texCoord); 531 vec4 texColor = texture2D(s_texture, v_texCoord);
506 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; 532 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha;
507 } 533 }
508 ); 534 );
509 } 535 }
510 536
511 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const 537 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString(WebGraphicsConte xt3D* context) const
512 { 538 {
513 return SHADER( 539 return FRAGMENT_SHADER(
514 precision mediump float; 540 precision mediump float;
515 varying vec2 v_texCoord; 541 varying TexCoordPrecision vec2 v_texCoord;
516 uniform sampler2D s_texture; 542 uniform sampler2D s_texture;
517 void main() 543 void main()
518 { 544 {
519 vec4 texColor = texture2D(s_texture, v_texCoord); 545 vec4 texColor = texture2D(s_texture, v_texCoord);
520 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); 546 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0);
521 } 547 }
522 ); 548 );
523 } 549 }
524 550
525 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() 551 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA()
(...skipping 13 matching lines...) Expand all
539 int locations[3]; 565 int locations[3];
540 566
541 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 567 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
542 568
543 m_samplerLocation = locations[0]; 569 m_samplerLocation = locations[0];
544 m_alphaLocation = locations[1]; 570 m_alphaLocation = locations[1];
545 m_edgeLocation = locations[2]; 571 m_edgeLocation = locations[2];
546 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1); 572 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1);
547 } 573 }
548 574
549 std::string FragmentShaderRGBATexAlphaAA::getShaderString() const 575 std::string FragmentShaderRGBATexAlphaAA::getShaderString(WebGraphicsContext3D* context) const
550 { 576 {
551 return SHADER( 577 return FRAGMENT_SHADER(
552 precision mediump float; 578 precision mediump float;
553 varying vec2 v_texCoord; 579 varying TexCoordPrecision vec2 v_texCoord;
554 uniform sampler2D s_texture; 580 uniform sampler2D s_texture;
555 uniform float alpha; 581 uniform float alpha;
556 uniform vec3 edge[8]; 582 uniform vec3 edge[8];
557 void main() 583 void main()
558 { 584 {
559 vec4 texColor = texture2D(s_texture, v_texCoord); 585 vec4 texColor = texture2D(s_texture, v_texCoord);
560 vec3 pos = vec3(gl_FragCoord.xy, 1); 586 vec3 pos = vec3(gl_FragCoord.xy, 1);
561 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); 587 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
562 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); 588 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
563 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); 589 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
(...skipping 27 matching lines...) Expand all
591 617
592 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 618 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
593 619
594 m_samplerLocation = locations[0]; 620 m_samplerLocation = locations[0];
595 m_alphaLocation = locations[1]; 621 m_alphaLocation = locations[1];
596 m_fragmentTexTransformLocation = locations[2]; 622 m_fragmentTexTransformLocation = locations[2];
597 m_edgeLocation = locations[3]; 623 m_edgeLocation = locations[3];
598 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1); 624 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1);
599 } 625 }
600 626
601 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString() const 627 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString(WebGraphicsContex t3D* context) const
602 { 628 {
603 return SHADER( 629 return FRAGMENT_SHADER(
604 precision mediump float; 630 precision mediump float;
605 varying vec2 v_texCoord; 631 varying TexCoordPrecision vec2 v_texCoord;
606 uniform sampler2D s_texture; 632 uniform sampler2D s_texture;
607 uniform float alpha; 633 uniform float alpha;
608 uniform vec4 fragmentTexTransform; 634 uniform TexCoordPrecision vec4 fragmentTexTransform;
609 uniform vec3 edge[8]; 635 uniform vec3 edge[8];
610 void main() 636 void main()
611 { 637 {
612 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy; 638 TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * frag mentTexTransform.zw + fragmentTexTransform.xy;
613 vec4 texColor = texture2D(s_texture, texCoord); 639 vec4 texColor = texture2D(s_texture, texCoord);
614 vec3 pos = vec3(gl_FragCoord.xy, 1); 640 vec3 pos = vec3(gl_FragCoord.xy, 1);
615 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); 641 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
616 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); 642 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
617 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); 643 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
618 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); 644 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
619 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); 645 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0);
620 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); 646 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0);
621 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); 647 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0);
622 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); 648 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0);
623 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min (a4, a6) * min(a5, a7)); 649 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min (a4, a6) * min(a5, a7));
624 } 650 }
625 ); 651 );
626 } 652 }
627 653
628 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const 654 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString(WebGraphic sContext3D* context) const
629 { 655 {
630 return SHADER( 656 return FRAGMENT_SHADER(
631 precision mediump float; 657 precision mediump float;
632 varying vec2 v_texCoord; 658 varying TexCoordPrecision vec2 v_texCoord;
633 uniform sampler2D s_texture; 659 uniform sampler2D s_texture;
634 uniform float alpha; 660 uniform float alpha;
635 uniform vec4 fragmentTexTransform; 661 uniform TexCoordPrecision vec4 fragmentTexTransform;
636 uniform vec3 edge[8]; 662 uniform vec3 edge[8];
637 void main() 663 void main()
638 { 664 {
639 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy; 665 TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * frag mentTexTransform.zw + fragmentTexTransform.xy;
640 vec4 texColor = texture2D(s_texture, texCoord); 666 vec4 texColor = texture2D(s_texture, texCoord);
641 vec3 pos = vec3(gl_FragCoord.xy, 1); 667 vec3 pos = vec3(gl_FragCoord.xy, 1);
642 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); 668 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
643 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); 669 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
644 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); 670 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
645 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); 671 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
646 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); 672 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0);
647 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); 673 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0);
648 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); 674 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0);
649 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); 675 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0);
(...skipping 24 matching lines...) Expand all
674 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 700 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
675 701
676 m_samplerLocation = locations[0]; 702 m_samplerLocation = locations[0];
677 m_maskSamplerLocation = locations[1]; 703 m_maskSamplerLocation = locations[1];
678 m_alphaLocation = locations[2]; 704 m_alphaLocation = locations[2];
679 m_maskTexCoordScaleLocation = locations[3]; 705 m_maskTexCoordScaleLocation = locations[3];
680 m_maskTexCoordOffsetLocation = locations[4]; 706 m_maskTexCoordOffsetLocation = locations[4];
681 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1); 707 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1);
682 } 708 }
683 709
684 std::string FragmentShaderRGBATexAlphaMask::getShaderString() const 710 std::string FragmentShaderRGBATexAlphaMask::getShaderString(WebGraphicsContext3D * context) const
685 { 711 {
686 return SHADER( 712 return FRAGMENT_SHADER(
687 precision mediump float; 713 precision mediump float;
688 varying vec2 v_texCoord; 714 varying TexCoordPrecision vec2 v_texCoord;
689 uniform sampler2D s_texture; 715 uniform sampler2D s_texture;
690 uniform sampler2D s_mask; 716 uniform sampler2D s_mask;
691 uniform vec2 maskTexCoordScale; 717 uniform TexCoordPrecision vec2 maskTexCoordScale;
692 uniform vec2 maskTexCoordOffset; 718 uniform TexCoordPrecision vec2 maskTexCoordOffset;
693 uniform float alpha; 719 uniform float alpha;
694 void main() 720 void main()
695 { 721 {
696 vec4 texColor = texture2D(s_texture, v_texCoord); 722 vec4 texColor = texture2D(s_texture, v_texCoord);
697 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 723 TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_ texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexC oordScale.y);
698 vec4 maskColor = texture2D(s_mask, maskTexCoord); 724 vec4 maskColor = texture2D(s_mask, maskTexCoord);
699 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w; 725 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w;
700 } 726 }
701 ); 727 );
702 } 728 }
703 729
704 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() 730 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
705 : m_samplerLocation(-1) 731 : m_samplerLocation(-1)
706 , m_maskSamplerLocation(-1) 732 , m_maskSamplerLocation(-1)
707 , m_alphaLocation(-1) 733 , m_alphaLocation(-1)
(...skipping 18 matching lines...) Expand all
726 752
727 m_samplerLocation = locations[0]; 753 m_samplerLocation = locations[0];
728 m_maskSamplerLocation = locations[1]; 754 m_maskSamplerLocation = locations[1];
729 m_alphaLocation = locations[2]; 755 m_alphaLocation = locations[2];
730 m_edgeLocation = locations[3]; 756 m_edgeLocation = locations[3];
731 m_maskTexCoordScaleLocation = locations[4]; 757 m_maskTexCoordScaleLocation = locations[4];
732 m_maskTexCoordOffsetLocation = locations[5]; 758 m_maskTexCoordOffsetLocation = locations[5];
733 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1 && m_edgeLocation != -1); 759 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1 && m_edgeLocation != -1);
734 } 760 }
735 761
736 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString() const 762 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString(WebGraphicsContext 3D* context) const
737 { 763 {
738 return SHADER( 764 return FRAGMENT_SHADER(
739 precision mediump float; 765 precision mediump float;
740 varying vec2 v_texCoord; 766 varying TexCoordPrecision vec2 v_texCoord;
741 uniform sampler2D s_texture; 767 uniform sampler2D s_texture;
742 uniform sampler2D s_mask; 768 uniform sampler2D s_mask;
743 uniform vec2 maskTexCoordScale; 769 uniform TexCoordPrecision vec2 maskTexCoordScale;
744 uniform vec2 maskTexCoordOffset; 770 uniform TexCoordPrecision vec2 maskTexCoordOffset;
745 uniform float alpha; 771 uniform float alpha;
746 uniform vec3 edge[8]; 772 uniform vec3 edge[8];
747 void main() 773 void main()
748 { 774 {
749 vec4 texColor = texture2D(s_texture, v_texCoord); 775 vec4 texColor = texture2D(s_texture, v_texCoord);
750 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 776 TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_ texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexC oordScale.y);
751 vec4 maskColor = texture2D(s_mask, maskTexCoord); 777 vec4 maskColor = texture2D(s_mask, maskTexCoord);
752 vec3 pos = vec3(gl_FragCoord.xy, 1); 778 vec3 pos = vec3(gl_FragCoord.xy, 1);
753 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); 779 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
754 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); 780 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
755 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); 781 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
756 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); 782 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
757 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); 783 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0);
758 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); 784 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0);
759 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); 785 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0);
760 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); 786 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0);
(...skipping 30 matching lines...) Expand all
791 m_uTextureLocation = locations[1]; 817 m_uTextureLocation = locations[1];
792 m_vTextureLocation = locations[2]; 818 m_vTextureLocation = locations[2];
793 m_alphaLocation = locations[3]; 819 m_alphaLocation = locations[3];
794 m_yuvMatrixLocation = locations[4]; 820 m_yuvMatrixLocation = locations[4];
795 m_yuvAdjLocation = locations[5]; 821 m_yuvAdjLocation = locations[5];
796 822
797 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1 823 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1
798 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1); 824 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1);
799 } 825 }
800 826
801 std::string FragmentShaderYUVVideo::getShaderString() const 827 std::string FragmentShaderYUVVideo::getShaderString(WebGraphicsContext3D* contex t) const
802 { 828 {
803 return SHADER( 829 return FRAGMENT_SHADER(
804 precision mediump float; 830 precision mediump float;
805 precision mediump int; 831 precision mediump int;
806 varying vec2 v_texCoord; 832 varying TexCoordPrecision vec2 v_texCoord;
807 uniform sampler2D y_texture; 833 uniform sampler2D y_texture;
808 uniform sampler2D u_texture; 834 uniform sampler2D u_texture;
809 uniform sampler2D v_texture; 835 uniform sampler2D v_texture;
810 uniform float alpha; 836 uniform float alpha;
811 uniform vec3 yuv_adj; 837 uniform vec3 yuv_adj;
812 uniform mat3 yuv_matrix; 838 uniform mat3 yuv_matrix;
813 void main() 839 void main()
814 { 840 {
815 float y_raw = texture2D(y_texture, v_texCoord).x; 841 float y_raw = texture2D(y_texture, v_texCoord).x;
816 float u_unsigned = texture2D(u_texture, v_texCoord).x; 842 float u_unsigned = texture2D(u_texture, v_texCoord).x;
(...skipping 16 matching lines...) Expand all
833 "color", 859 "color",
834 }; 860 };
835 int locations[1]; 861 int locations[1];
836 862
837 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 863 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
838 864
839 m_colorLocation = locations[0]; 865 m_colorLocation = locations[0];
840 DCHECK(m_colorLocation != -1); 866 DCHECK(m_colorLocation != -1);
841 } 867 }
842 868
843 std::string FragmentShaderColor::getShaderString() const 869 std::string FragmentShaderColor::getShaderString(WebGraphicsContext3D* context) const
844 { 870 {
845 return SHADER( 871 return FRAGMENT_SHADER(
846 precision mediump float; 872 precision mediump float;
847 uniform vec4 color; 873 uniform vec4 color;
848 void main() 874 void main()
849 { 875 {
850 gl_FragColor = color; 876 gl_FragColor = color;
851 } 877 }
852 ); 878 );
853 } 879 }
854 880
855 FragmentShaderCheckerboard::FragmentShaderCheckerboard() 881 FragmentShaderCheckerboard::FragmentShaderCheckerboard()
(...skipping 15 matching lines...) Expand all
871 897
872 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 898 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
873 899
874 m_alphaLocation = locations[0]; 900 m_alphaLocation = locations[0];
875 m_texTransformLocation = locations[1]; 901 m_texTransformLocation = locations[1];
876 m_frequencyLocation = locations[2]; 902 m_frequencyLocation = locations[2];
877 m_colorLocation = locations[3]; 903 m_colorLocation = locations[3];
878 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL ocation != -1 && m_colorLocation != -1); 904 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL ocation != -1 && m_colorLocation != -1);
879 } 905 }
880 906
881 std::string FragmentShaderCheckerboard::getShaderString() const 907 std::string FragmentShaderCheckerboard::getShaderString(WebGraphicsContext3D* co ntext) const
882 { 908 {
883 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" 909 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide"
884 // by Munshi, Ginsburg, Shreiner. 910 // by Munshi, Ginsburg, Shreiner.
885 return SHADER( 911 return FRAGMENT_SHADER(
886 precision mediump float; 912 precision mediump float;
887 precision mediump int; 913 precision mediump int;
888 varying vec2 v_texCoord; 914 varying TexCoordPrecision vec2 v_texCoord;
889 uniform float alpha; 915 uniform float alpha;
890 uniform float frequency; 916 uniform float frequency;
891 uniform vec4 texTransform; 917 uniform vec4 texTransform;
892 uniform vec4 color; 918 uniform vec4 color;
893 void main() 919 void main()
894 { 920 {
895 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); 921 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0);
896 vec4 color2 = color; 922 vec4 color2 = color;
897 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; 923 TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texT ransform.zw + texTransform.xy;
898 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 924 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
899 float picker = abs(coord.x - coord.y); 925 float picker = abs(coord.x - coord.y);
900 gl_FragColor = mix(color1, color2, picker) * alpha; 926 gl_FragColor = mix(color1, color2, picker) * alpha;
901 } 927 }
902 ); 928 );
903 } 929 }
904 930
905 } // namespace cc 931 } // namespace cc
OLDNEW
« no previous file with comments | « cc/shader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698