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

Side by Side Diff: cc/output/shader.cc

Issue 12665005: cc: Use highp precision for texture coords if available and needed (Closed) Base URL: http://git.chromium.org/chromium/src.git@highp2
Patch Set: Cleanup highp shaders Created 7 years, 9 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
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/output/shader.h" 5 #include "cc/output/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/output/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, precision, SHADER 0(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 TexCoordPrecision requestedPrecision ,
38 const char* shaderString)
39 {
40 if (requestedPrecision == TexCoordPrecisionHigh) {
vangelis 2013/03/20 19:20:44 The context is no longer needed here, is it?
brianderson 2013/03/20 20:57:15 Context is no longer needed. Will remove it.
41 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
42 " #define TexCoordPrecision highp\n"
43 "#else\n"
44 " #define TexCoordPrecision mediump\n"
45 "#endif\n"+
46 std::string(shaderString);
47 } else {
48 return "#define TexCoordPrecision mediump\n" +
49 std::string(shaderString);
50 }
51 }
52
53 static std::string setVertexTexCoordPrecision(WebGraphicsContext3D* context,
54 const char* shaderString)
55 {
56 return "#define TexCoordPrecision highp\n" +
vangelis 2013/03/20 19:20:44 Not sure I understand why for the vertex shaders w
brianderson 2013/03/20 20:57:15 My thinking was that we're not likely to be vertex
57 std::string(shaderString);
58 }
59
33 } 60 }
34 61
62 TexCoordPrecision TexCoordPrecisionRequired(const gfx::Point &max_coordinate)
63 {
64 if (max_coordinate.x() > 1024 || max_coordinate.y() > 1024)
aelias_OOO_until_Jul13 2013/03/20 19:55:01 1280 is a common height on mid-end phones like the
brianderson 2013/03/20 20:57:15 mediump is only guaranteed to provide 10 bits of p
65 return TexCoordPrecisionHigh;
66 return TexCoordPrecisionMedium;
67 }
68
35 VertexShaderPosTex::VertexShaderPosTex() 69 VertexShaderPosTex::VertexShaderPosTex()
36 : m_matrixLocation(-1) 70 : m_matrixLocation(-1)
37 { 71 {
38 } 72 }
39 73
40 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b ool usingBindUniform, int* baseUniformIndex) 74 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b ool usingBindUniform, int* baseUniformIndex)
41 { 75 {
42 static const char* shaderUniforms[] = { 76 static const char* shaderUniforms[] = {
43 "matrix", 77 "matrix",
44 }; 78 };
45 int locations[1]; 79 int locations[1];
46 80
47 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 81 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
48 82
49 m_matrixLocation = locations[0]; 83 m_matrixLocation = locations[0];
50 DCHECK(m_matrixLocation != -1); 84 DCHECK(m_matrixLocation != -1);
51 } 85 }
52 86
53 std::string VertexShaderPosTex::getShaderString() const 87 std::string VertexShaderPosTex::getShaderString(WebGraphicsContext3D* context) c onst
54 { 88 {
55 return SHADER( 89 return VERTEX_SHADER(
56 attribute vec4 a_position; 90 attribute vec4 a_position;
57 attribute vec2 a_texCoord; 91 attribute TexCoordPrecision vec2 a_texCoord;
58 uniform mat4 matrix; 92 uniform mat4 matrix;
59 varying vec2 v_texCoord; 93 varying TexCoordPrecision vec2 v_texCoord;
60 void main() 94 void main()
61 { 95 {
62 gl_Position = matrix * a_position; 96 gl_Position = matrix * a_position;
63 v_texCoord = a_texCoord; 97 v_texCoord = a_texCoord;
64 } 98 }
65 ); 99 );
66 } 100 }
67 101
68 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() 102 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch()
69 : m_matrixLocation(-1) 103 : m_matrixLocation(-1)
70 , m_texScaleLocation(-1) 104 , m_texScaleLocation(-1)
71 { 105 {
72 } 106 }
73 107
74 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) 108 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex)
75 { 109 {
76 static const char* shaderUniforms[] = { 110 static const char* shaderUniforms[] = {
77 "matrix", 111 "matrix",
78 "texScale", 112 "texScale",
79 }; 113 };
80 int locations[2]; 114 int locations[2];
81 115
82 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 116 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
83 117
84 m_matrixLocation = locations[0]; 118 m_matrixLocation = locations[0];
85 m_texScaleLocation = locations[1]; 119 m_texScaleLocation = locations[1];
86 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1); 120 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1);
87 } 121 }
88 122
89 std::string VertexShaderPosTexYUVStretch::getShaderString() const 123 std::string VertexShaderPosTexYUVStretch::getShaderString(WebGraphicsContext3D* context) const
90 { 124 {
91 return SHADER( 125 return VERTEX_SHADER(
92 precision mediump float; 126 precision mediump float;
93 attribute vec4 a_position; 127 attribute vec4 a_position;
94 attribute vec2 a_texCoord; 128 attribute TexCoordPrecision vec2 a_texCoord;
95 uniform mat4 matrix; 129 uniform mat4 matrix;
96 varying vec2 v_texCoord; 130 varying TexCoordPrecision vec2 v_texCoord;
97 uniform vec2 texScale; 131 uniform TexCoordPrecision vec2 texScale;
98 void main() 132 void main()
99 { 133 {
100 gl_Position = matrix * a_position; 134 gl_Position = matrix * a_position;
101 v_texCoord = a_texCoord * texScale; 135 v_texCoord = a_texCoord * texScale;
102 } 136 }
103 ); 137 );
104 } 138 }
105 139
106 VertexShaderPos::VertexShaderPos() 140 VertexShaderPos::VertexShaderPos()
107 : m_matrixLocation(-1) 141 : m_matrixLocation(-1)
108 { 142 {
109 } 143 }
110 144
111 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) 145 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex)
112 { 146 {
113 static const char* shaderUniforms[] = { 147 static const char* shaderUniforms[] = {
114 "matrix", 148 "matrix",
115 }; 149 };
116 int locations[1]; 150 int locations[1];
117 151
118 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 152 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
119 153
120 m_matrixLocation = locations[0]; 154 m_matrixLocation = locations[0];
121 DCHECK(m_matrixLocation != -1); 155 DCHECK(m_matrixLocation != -1);
122 } 156 }
123 157
124 std::string VertexShaderPos::getShaderString() const 158 std::string VertexShaderPos::getShaderString(WebGraphicsContext3D* context) cons t
125 { 159 {
126 return SHADER( 160 return VERTEX_SHADER(
127 attribute vec4 a_position; 161 attribute vec4 a_position;
128 uniform mat4 matrix; 162 uniform mat4 matrix;
129 void main() 163 void main()
130 { 164 {
131 gl_Position = matrix * a_position; 165 gl_Position = matrix * a_position;
132 } 166 }
133 ); 167 );
134 } 168 }
135 169
136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() 170 VertexShaderPosTexTransform::VertexShaderPosTexTransform()
(...skipping 13 matching lines...) Expand all
150 int locations[3]; 184 int locations[3];
151 185
152 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 186 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
153 187
154 m_matrixLocation = locations[0]; 188 m_matrixLocation = locations[0];
155 m_texTransformLocation = locations[1]; 189 m_texTransformLocation = locations[1];
156 m_vertexOpacityLocation = locations[2]; 190 m_vertexOpacityLocation = locations[2];
157 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1); 191 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1);
158 } 192 }
159 193
160 std::string VertexShaderPosTexTransform::getShaderString() const 194 std::string VertexShaderPosTexTransform::getShaderString(WebGraphicsContext3D* c ontext) const
161 { 195 {
162 return SHADER( 196 return VERTEX_SHADER(
163 attribute vec4 a_position; 197 attribute vec4 a_position;
164 attribute vec2 a_texCoord; 198 attribute TexCoordPrecision vec2 a_texCoord;
165 attribute float a_index; 199 attribute float a_index;
166 uniform mat4 matrix[8]; 200 uniform mat4 matrix[8];
167 uniform vec4 texTransform[8]; 201 uniform TexCoordPrecision vec4 texTransform[8];
168 uniform float opacity[32]; 202 uniform float opacity[32];
169 varying vec2 v_texCoord; 203 varying TexCoordPrecision vec2 v_texCoord;
170 varying float v_alpha; 204 varying float v_alpha;
171 void main() 205 void main()
172 { 206 {
173 gl_Position = matrix[int(a_index * 0.25)] * a_position; 207 gl_Position = matrix[int(a_index * 0.25)] * a_position;
174 vec4 texTrans = texTransform[int(a_index * 0.25)]; 208 TexCoordPrecision vec4 texTrans = texTransform[int(a_index * 0.25)];
175 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; 209 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy;
176 v_alpha = opacity[int(a_index)]; 210 v_alpha = opacity[int(a_index)];
177 } 211 }
178 ); 212 );
179 } 213 }
180 214
181 std::string VertexShaderPosTexTransformFlip::getShaderString() const 215 std::string VertexShaderPosTexTransformFlip::getShaderString(WebGraphicsContext3 D* context) const
182 { 216 {
183 return SHADER( 217 return VERTEX_SHADER(
184 attribute vec4 a_position; 218 attribute vec4 a_position;
185 attribute vec2 a_texCoord; 219 attribute TexCoordPrecision vec2 a_texCoord;
186 attribute float a_index; 220 attribute float a_index;
187 uniform mat4 matrix[8]; 221 uniform mat4 matrix[8];
188 uniform vec4 texTransform[8]; 222 uniform TexCoordPrecision vec4 texTransform[8];
189 uniform float opacity[32]; 223 uniform float opacity[32];
190 varying vec2 v_texCoord; 224 varying TexCoordPrecision vec2 v_texCoord;
191 varying float v_alpha; 225 varying float v_alpha;
192 void main() 226 void main()
193 { 227 {
194 gl_Position = matrix[int(a_index * 0.25)] * a_position; 228 gl_Position = matrix[int(a_index * 0.25)] * a_position;
195 vec4 texTrans = texTransform[int(a_index * 0.25)]; 229 TexCoordPrecision vec4 texTrans = texTransform[int(a_index * 0.25)];
196 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; 230 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy;
197 v_texCoord.y = 1.0 - v_texCoord.y; 231 v_texCoord.y = 1.0 - v_texCoord.y;
198 v_alpha = opacity[int(a_index)]; 232 v_alpha = opacity[int(a_index)];
199 } 233 }
200 ); 234 );
201 } 235 }
202 236
203 std::string VertexShaderPosTexIdentity::getShaderString() const 237 std::string VertexShaderPosTexIdentity::getShaderString(WebGraphicsContext3D* co ntext) const
204 { 238 {
205 return SHADER( 239 return VERTEX_SHADER(
206 attribute vec4 a_position; 240 attribute vec4 a_position;
207 varying vec2 v_texCoord; 241 varying TexCoordPrecision vec2 v_texCoord;
208 void main() 242 void main()
209 { 243 {
210 gl_Position = a_position; 244 gl_Position = a_position;
211 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; 245 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5;
212 } 246 }
213 ); 247 );
214 } 248 }
215 249
216 VertexShaderQuad::VertexShaderQuad() 250 VertexShaderQuad::VertexShaderQuad()
217 : m_matrixLocation(-1) 251 : m_matrixLocation(-1)
(...skipping 14 matching lines...) Expand all
232 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 266 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
233 267
234 m_matrixLocation = locations[0]; 268 m_matrixLocation = locations[0];
235 m_pointLocation = locations[1]; 269 m_pointLocation = locations[1];
236 m_texScaleLocation = locations[2]; 270 m_texScaleLocation = locations[2];
237 DCHECK_NE(m_matrixLocation, -1); 271 DCHECK_NE(m_matrixLocation, -1);
238 DCHECK_NE(m_pointLocation, -1); 272 DCHECK_NE(m_pointLocation, -1);
239 DCHECK_NE(m_texScaleLocation, -1); 273 DCHECK_NE(m_texScaleLocation, -1);
240 } 274 }
241 275
242 std::string VertexShaderQuad::getShaderString() const 276 std::string VertexShaderQuad::getShaderString(WebGraphicsContext3D* context) con st
243 { 277 {
244 return SHADER( 278 return VERTEX_SHADER(
245 attribute vec4 a_position; 279 attribute TexCoordPrecision vec4 a_position;
246 attribute vec2 a_texCoord; 280 attribute TexCoordPrecision vec2 a_texCoord;
247 uniform mat4 matrix; 281 uniform mat4 matrix;
248 uniform vec2 point[4]; 282 uniform TexCoordPrecision vec2 point[4];
249 uniform vec2 texScale; 283 uniform TexCoordPrecision vec2 texScale;
250 varying vec2 v_texCoord; 284 varying TexCoordPrecision vec2 v_texCoord;
251 void main() 285 void main()
252 { 286 {
253 vec2 complement = abs(a_texCoord - 1.0); 287 TexCoordPrecision vec2 complement = abs(a_texCoord - 1.0);
254 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); 288 TexCoordPrecision vec4 pos = vec4(0.0, 0.0, a_position.z, a_position .w);
255 pos.xy += (complement.x * complement.y) * point[0]; 289 pos.xy += (complement.x * complement.y) * point[0];
256 pos.xy += (a_texCoord.x * complement.y) * point[1]; 290 pos.xy += (a_texCoord.x * complement.y) * point[1];
257 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; 291 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2];
258 pos.xy += (complement.x * a_texCoord.y) * point[3]; 292 pos.xy += (complement.x * a_texCoord.y) * point[3];
259 gl_Position = matrix * pos; 293 gl_Position = matrix * pos;
260 v_texCoord = (pos.xy + vec2(0.5)) * texScale; 294 v_texCoord = (pos.xy + vec2(0.5)) * texScale;
261 } 295 }
262 ); 296 );
263 } 297 }
264 298
(...skipping 14 matching lines...) Expand all
279 int locations[3]; 313 int locations[3];
280 314
281 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 315 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
282 316
283 m_matrixLocation = locations[0]; 317 m_matrixLocation = locations[0];
284 m_pointLocation = locations[1]; 318 m_pointLocation = locations[1];
285 m_vertexTexTransformLocation = locations[2]; 319 m_vertexTexTransformLocation = locations[2];
286 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1); 320 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1);
287 } 321 }
288 322
289 std::string VertexShaderTile::getShaderString() const 323 std::string VertexShaderTile::getShaderString(WebGraphicsContext3D* context) con st
290 { 324 {
291 return SHADER( 325 return VERTEX_SHADER(
292 attribute vec4 a_position; 326 attribute TexCoordPrecision vec4 a_position;
293 attribute vec2 a_texCoord; 327 attribute TexCoordPrecision vec2 a_texCoord;
294 uniform mat4 matrix; 328 uniform mat4 matrix;
295 uniform vec2 point[4]; 329 uniform TexCoordPrecision vec2 point[4];
296 uniform vec4 vertexTexTransform; 330 uniform TexCoordPrecision vec4 vertexTexTransform;
297 varying vec2 v_texCoord; 331 varying TexCoordPrecision vec2 v_texCoord;
298 void main() 332 void main()
299 { 333 {
300 vec2 complement = abs(a_texCoord - 1.0); 334 vec2 complement = abs(a_texCoord - 1.0);
301 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); 335 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w);
302 pos.xy += (complement.x * complement.y) * point[0]; 336 pos.xy += (complement.x * complement.y) * point[0];
303 pos.xy += (a_texCoord.x * complement.y) * point[1]; 337 pos.xy += (a_texCoord.x * complement.y) * point[1];
304 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; 338 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2];
305 pos.xy += (complement.x * a_texCoord.y) * point[3]; 339 pos.xy += (complement.x * a_texCoord.y) * point[3];
306 gl_Position = matrix * pos; 340 gl_Position = matrix * pos;
307 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; 341 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy;
(...skipping 15 matching lines...) Expand all
323 }; 357 };
324 int locations[2]; 358 int locations[2];
325 359
326 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 360 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
327 361
328 m_matrixLocation = locations[0]; 362 m_matrixLocation = locations[0];
329 m_texMatrixLocation = locations[1]; 363 m_texMatrixLocation = locations[1];
330 return m_matrixLocation != -1 && m_texMatrixLocation != -1; 364 return m_matrixLocation != -1 && m_texMatrixLocation != -1;
331 } 365 }
332 366
333 std::string VertexShaderVideoTransform::getShaderString() const 367 std::string VertexShaderVideoTransform::getShaderString(WebGraphicsContext3D* co ntext) const
334 { 368 {
335 return SHADER( 369 return VERTEX_SHADER(
336 attribute vec4 a_position; 370 attribute vec4 a_position;
337 attribute vec2 a_texCoord; 371 attribute TexCoordPrecision vec2 a_texCoord;
338 uniform mat4 matrix; 372 uniform mat4 matrix;
339 uniform mat4 texMatrix; 373 uniform TexCoordPrecision mat4 texMatrix;
340 varying vec2 v_texCoord; 374 varying TexCoordPrecision vec2 v_texCoord;
341 void main() 375 void main()
342 { 376 {
343 gl_Position = matrix * a_position; 377 gl_Position = matrix * a_position;
344 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); 378 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0));
345 } 379 }
346 ); 380 );
347 } 381 }
348 382
349 FragmentTexAlphaBinding::FragmentTexAlphaBinding() 383 FragmentTexAlphaBinding::FragmentTexAlphaBinding()
350 : m_samplerLocation(-1) 384 : m_samplerLocation(-1)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 "s_texture", 425 "s_texture",
392 }; 426 };
393 int locations[1]; 427 int locations[1];
394 428
395 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 429 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
396 430
397 m_samplerLocation = locations[0]; 431 m_samplerLocation = locations[0];
398 return m_samplerLocation != -1; 432 return m_samplerLocation != -1;
399 } 433 }
400 434
401 std::string FragmentShaderOESImageExternal::getShaderString() const 435 std::string FragmentShaderOESImageExternal::getShaderString(WebGraphicsContext3D * context,
436 TexCoordPrecision pr ecision) const
402 { 437 {
403 // Cannot use the SHADER() macro because of the '#' char 438 // Cannot use the FRAGMENT_SHADER() macro because of the '#' char
404 return "#extension GL_OES_EGL_image_external : require \n" 439 return setFragTexCoordPrecision(context, precision,
440 "#extension GL_OES_EGL_image_external : require \n"
405 "precision mediump float;\n" 441 "precision mediump float;\n"
406 "varying vec2 v_texCoord;\n" 442 "varying TexCoordPrecision vec2 v_texCoord;\n"
407 "uniform samplerExternalOES s_texture;\n" 443 "uniform samplerExternalOES s_texture;\n"
408 "void main()\n" 444 "void main()\n"
409 "{\n" 445 "{\n"
410 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" 446 " vec4 texColor = texture2D(s_texture, v_texCoord);\n"
411 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor .w);\n" 447 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor .w);\n"
412 "}\n"; 448 "}\n");
413 } 449 }
414 450
415 std::string FragmentShaderRGBATexAlpha::getShaderString() const 451 std::string FragmentShaderRGBATexAlpha::getShaderString(WebGraphicsContext3D* co ntext,
452 TexCoordPrecision precis ion) const
416 { 453 {
417 return SHADER( 454 return FRAGMENT_SHADER(
418 precision mediump float; 455 precision mediump float;
419 varying vec2 v_texCoord; 456 varying TexCoordPrecision vec2 v_texCoord;
420 uniform sampler2D s_texture; 457 uniform sampler2D s_texture;
421 uniform float alpha; 458 uniform float alpha;
422 void main() 459 void main()
423 { 460 {
424 vec4 texColor = texture2D(s_texture, v_texCoord); 461 vec4 texColor = texture2D(s_texture, v_texCoord);
425 gl_FragColor = texColor * alpha; 462 gl_FragColor = texColor * alpha;
426 } 463 }
427 ); 464 );
428 } 465 }
429 466
430 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const 467 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString(WebGraphicsContex t3D* context,
468 TexCoordPrecision precision) const
431 { 469 {
432 return SHADER( 470 return FRAGMENT_SHADER(
433 precision mediump float; 471 precision mediump float;
434 varying vec2 v_texCoord; 472 varying TexCoordPrecision vec2 v_texCoord;
435 varying float v_alpha; 473 varying float v_alpha;
436 uniform sampler2D s_texture; 474 uniform sampler2D s_texture;
437 void main() 475 void main()
438 { 476 {
439 vec4 texColor = texture2D(s_texture, v_texCoord); 477 vec4 texColor = texture2D(s_texture, v_texCoord);
440 gl_FragColor = texColor * v_alpha; 478 gl_FragColor = texColor * v_alpha;
441 } 479 }
442 ); 480 );
443 } 481 }
444 482
445 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const 483 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString(WebGraphicsCo ntext3D* context,
484 TexCoordPreci sion precision) const
446 { 485 {
447 return "#extension GL_ARB_texture_rectangle : require\n" 486 return setFragTexCoordPrecision(context, precision,
487 "#extension GL_ARB_texture_rectangle : require\n"
448 "precision mediump float;\n" 488 "precision mediump float;\n"
449 "varying vec2 v_texCoord;\n" 489 "varying TexCoordPrecision vec2 v_texCoord;\n"
450 "varying float v_alpha;\n" 490 "varying float v_alpha;\n"
451 "uniform sampler2DRect s_texture;\n" 491 "uniform sampler2DRect s_texture;\n"
452 "void main()\n" 492 "void main()\n"
453 "{\n" 493 "{\n"
454 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" 494 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n"
455 " gl_FragColor = texColor * v_alpha;\n" 495 " gl_FragColor = texColor * v_alpha;\n"
456 "}\n"; 496 "}\n");
457 } 497 }
458 498
459 std::string FragmentShaderRGBATexOpaque::getShaderString() const 499 std::string FragmentShaderRGBATexOpaque::getShaderString(WebGraphicsContext3D* c ontext,
500 TexCoordPrecision preci sion) const
460 { 501 {
461 return SHADER( 502 return FRAGMENT_SHADER(
462 precision mediump float; 503 precision mediump float;
463 varying vec2 v_texCoord; 504 varying TexCoordPrecision vec2 v_texCoord;
464 uniform sampler2D s_texture; 505 uniform sampler2D s_texture;
465 void main() 506 void main()
466 { 507 {
467 vec4 texColor = texture2D(s_texture, v_texCoord); 508 vec4 texColor = texture2D(s_texture, v_texCoord);
468 gl_FragColor = vec4(texColor.rgb, 1.0); 509 gl_FragColor = vec4(texColor.rgb, 1.0);
469 } 510 }
470 ); 511 );
471 } 512 }
472 513
473 std::string FragmentShaderRGBATex::getShaderString() const 514 std::string FragmentShaderRGBATex::getShaderString(WebGraphicsContext3D* context ,
515 TexCoordPrecision precision) const
474 { 516 {
475 return SHADER( 517 return FRAGMENT_SHADER(
476 precision mediump float; 518 precision mediump float;
477 varying vec2 v_texCoord; 519 varying TexCoordPrecision vec2 v_texCoord;
478 uniform sampler2D s_texture; 520 uniform sampler2D s_texture;
479 void main() 521 void main()
480 { 522 {
481 gl_FragColor = texture2D(s_texture, v_texCoord); 523 gl_FragColor = texture2D(s_texture, v_texCoord);
482 } 524 }
483 ); 525 );
484 } 526 }
485 527
486 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const 528 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString(WebGraphicsContex t3D* context,
529 TexCoordPrecision precision) const
487 { 530 {
488 return SHADER( 531 return FRAGMENT_SHADER(
489 precision mediump float; 532 precision mediump float;
490 varying vec2 v_texCoord; 533 varying TexCoordPrecision vec2 v_texCoord;
491 uniform sampler2D s_texture; 534 uniform sampler2D s_texture;
492 uniform float alpha; 535 uniform float alpha;
493 void main() 536 void main()
494 { 537 {
495 vec4 texColor = texture2D(s_texture, v_texCoord); 538 vec4 texColor = texture2D(s_texture, v_texCoord);
496 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; 539 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha;
497 } 540 }
498 ); 541 );
499 } 542 }
500 543
501 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const 544 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString(WebGraphicsConte xt3D* context,
545 TexCoordPrecisio n precision) const
502 { 546 {
503 return SHADER( 547 return FRAGMENT_SHADER(
504 precision mediump float; 548 precision mediump float;
505 varying vec2 v_texCoord; 549 varying TexCoordPrecision vec2 v_texCoord;
506 uniform sampler2D s_texture; 550 uniform sampler2D s_texture;
507 void main() 551 void main()
508 { 552 {
509 vec4 texColor = texture2D(s_texture, v_texCoord); 553 vec4 texColor = texture2D(s_texture, v_texCoord);
510 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); 554 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0);
511 } 555 }
512 ); 556 );
513 } 557 }
514 558
515 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() 559 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA()
(...skipping 13 matching lines...) Expand all
529 int locations[3]; 573 int locations[3];
530 574
531 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 575 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
532 576
533 m_samplerLocation = locations[0]; 577 m_samplerLocation = locations[0];
534 m_alphaLocation = locations[1]; 578 m_alphaLocation = locations[1];
535 m_edgeLocation = locations[2]; 579 m_edgeLocation = locations[2];
536 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1); 580 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1);
537 } 581 }
538 582
539 std::string FragmentShaderRGBATexAlphaAA::getShaderString() const 583 std::string FragmentShaderRGBATexAlphaAA::getShaderString(WebGraphicsContext3D* context,
584 TexCoordPrecision prec ision) const
540 { 585 {
541 return SHADER( 586 return FRAGMENT_SHADER(
542 precision mediump float; 587 precision mediump float;
543 varying vec2 v_texCoord; 588 varying TexCoordPrecision vec2 v_texCoord;
544 uniform sampler2D s_texture; 589 uniform sampler2D s_texture;
545 uniform float alpha; 590 uniform float alpha;
546 uniform vec3 edge[8]; 591 uniform vec3 edge[8];
547 void main() 592 void main()
548 { 593 {
549 vec4 texColor = texture2D(s_texture, v_texCoord); 594 vec4 texColor = texture2D(s_texture, v_texCoord);
550 vec3 pos = vec3(gl_FragCoord.xy, 1); 595 vec3 pos = vec3(gl_FragCoord.xy, 1);
551 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); 596 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
552 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); 597 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
553 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); 598 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
(...skipping 27 matching lines...) Expand all
581 626
582 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 627 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
583 628
584 m_samplerLocation = locations[0]; 629 m_samplerLocation = locations[0];
585 m_alphaLocation = locations[1]; 630 m_alphaLocation = locations[1];
586 m_fragmentTexTransformLocation = locations[2]; 631 m_fragmentTexTransformLocation = locations[2];
587 m_edgeLocation = locations[3]; 632 m_edgeLocation = locations[3];
588 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1); 633 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1);
589 } 634 }
590 635
591 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString() const 636 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString(WebGraphicsContex t3D* context,
637 TexCoordPrecision precision) const
592 { 638 {
593 return SHADER( 639 return FRAGMENT_SHADER(
594 precision mediump float; 640 precision mediump float;
595 varying vec2 v_texCoord; 641 varying TexCoordPrecision vec2 v_texCoord;
596 uniform sampler2D s_texture; 642 uniform sampler2D s_texture;
597 uniform float alpha; 643 uniform float alpha;
598 uniform vec4 fragmentTexTransform; 644 uniform TexCoordPrecision vec4 fragmentTexTransform;
599 uniform vec3 edge[8]; 645 uniform vec3 edge[8];
600 void main() 646 void main()
601 { 647 {
602 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy; 648 TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * frag mentTexTransform.zw + fragmentTexTransform.xy;
603 vec4 texColor = texture2D(s_texture, texCoord); 649 vec4 texColor = texture2D(s_texture, texCoord);
604 vec3 pos = vec3(gl_FragCoord.xy, 1); 650 vec3 pos = vec3(gl_FragCoord.xy, 1);
605 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); 651 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
606 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); 652 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
607 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); 653 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
608 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); 654 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
609 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); 655 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0);
610 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); 656 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0);
611 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); 657 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0);
612 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); 658 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0);
613 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min (a4, a6) * min(a5, a7)); 659 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min (a4, a6) * min(a5, a7));
614 } 660 }
615 ); 661 );
616 } 662 }
617 663
618 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const 664 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString(WebGraphic sContext3D* context,
665 TexCoordPr ecision precision) const
619 { 666 {
620 return SHADER( 667 return FRAGMENT_SHADER(
621 precision mediump float; 668 precision mediump float;
622 varying vec2 v_texCoord; 669 varying TexCoordPrecision vec2 v_texCoord;
623 uniform sampler2D s_texture; 670 uniform sampler2D s_texture;
624 uniform float alpha; 671 uniform float alpha;
625 uniform vec4 fragmentTexTransform; 672 uniform TexCoordPrecision vec4 fragmentTexTransform;
626 uniform vec3 edge[8]; 673 uniform vec3 edge[8];
627 void main() 674 void main()
628 { 675 {
629 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy; 676 TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * frag mentTexTransform.zw + fragmentTexTransform.xy;
630 vec4 texColor = texture2D(s_texture, texCoord); 677 vec4 texColor = texture2D(s_texture, texCoord);
631 vec3 pos = vec3(gl_FragCoord.xy, 1); 678 vec3 pos = vec3(gl_FragCoord.xy, 1);
632 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); 679 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
633 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); 680 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
634 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); 681 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
635 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); 682 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
636 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); 683 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0);
637 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); 684 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0);
638 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); 685 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0);
639 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); 686 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0);
(...skipping 24 matching lines...) Expand all
664 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 711 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
665 712
666 m_samplerLocation = locations[0]; 713 m_samplerLocation = locations[0];
667 m_maskSamplerLocation = locations[1]; 714 m_maskSamplerLocation = locations[1];
668 m_alphaLocation = locations[2]; 715 m_alphaLocation = locations[2];
669 m_maskTexCoordScaleLocation = locations[3]; 716 m_maskTexCoordScaleLocation = locations[3];
670 m_maskTexCoordOffsetLocation = locations[4]; 717 m_maskTexCoordOffsetLocation = locations[4];
671 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1); 718 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1);
672 } 719 }
673 720
674 std::string FragmentShaderRGBATexAlphaMask::getShaderString() const 721 std::string FragmentShaderRGBATexAlphaMask::getShaderString(WebGraphicsContext3D * context,
722 TexCoordPrecision pr ecision) const
675 { 723 {
676 return SHADER( 724 return FRAGMENT_SHADER(
677 precision mediump float; 725 precision mediump float;
678 varying vec2 v_texCoord; 726 varying TexCoordPrecision vec2 v_texCoord;
679 uniform sampler2D s_texture; 727 uniform sampler2D s_texture;
680 uniform sampler2D s_mask; 728 uniform sampler2D s_mask;
681 uniform vec2 maskTexCoordScale; 729 uniform TexCoordPrecision vec2 maskTexCoordScale;
682 uniform vec2 maskTexCoordOffset; 730 uniform TexCoordPrecision vec2 maskTexCoordOffset;
683 uniform float alpha; 731 uniform float alpha;
684 void main() 732 void main()
685 { 733 {
686 vec4 texColor = texture2D(s_texture, v_texCoord); 734 vec4 texColor = texture2D(s_texture, v_texCoord);
687 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 735 TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_ texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexC oordScale.y);
688 vec4 maskColor = texture2D(s_mask, maskTexCoord); 736 vec4 maskColor = texture2D(s_mask, maskTexCoord);
689 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w; 737 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w;
690 } 738 }
691 ); 739 );
692 } 740 }
693 741
694 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() 742 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
695 : m_samplerLocation(-1) 743 : m_samplerLocation(-1)
696 , m_maskSamplerLocation(-1) 744 , m_maskSamplerLocation(-1)
697 , m_alphaLocation(-1) 745 , m_alphaLocation(-1)
(...skipping 18 matching lines...) Expand all
716 764
717 m_samplerLocation = locations[0]; 765 m_samplerLocation = locations[0];
718 m_maskSamplerLocation = locations[1]; 766 m_maskSamplerLocation = locations[1];
719 m_alphaLocation = locations[2]; 767 m_alphaLocation = locations[2];
720 m_edgeLocation = locations[3]; 768 m_edgeLocation = locations[3];
721 m_maskTexCoordScaleLocation = locations[4]; 769 m_maskTexCoordScaleLocation = locations[4];
722 m_maskTexCoordOffsetLocation = locations[5]; 770 m_maskTexCoordOffsetLocation = locations[5];
723 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1 && m_edgeLocation != -1); 771 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1 && m_edgeLocation != -1);
724 } 772 }
725 773
726 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString() const 774 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString(WebGraphicsContext 3D* context,
775 TexCoordPrecision precision) const
727 { 776 {
728 return SHADER( 777 return FRAGMENT_SHADER(
729 precision mediump float; 778 precision mediump float;
730 varying vec2 v_texCoord; 779 varying TexCoordPrecision vec2 v_texCoord;
731 uniform sampler2D s_texture; 780 uniform sampler2D s_texture;
732 uniform sampler2D s_mask; 781 uniform sampler2D s_mask;
733 uniform vec2 maskTexCoordScale; 782 uniform TexCoordPrecision vec2 maskTexCoordScale;
734 uniform vec2 maskTexCoordOffset; 783 uniform TexCoordPrecision vec2 maskTexCoordOffset;
735 uniform float alpha; 784 uniform float alpha;
736 uniform vec3 edge[8]; 785 uniform vec3 edge[8];
737 void main() 786 void main()
738 { 787 {
739 vec4 texColor = texture2D(s_texture, v_texCoord); 788 vec4 texColor = texture2D(s_texture, v_texCoord);
740 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 789 TexCoordPrecision vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_ texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexC oordScale.y);
741 vec4 maskColor = texture2D(s_mask, maskTexCoord); 790 vec4 maskColor = texture2D(s_mask, maskTexCoord);
742 vec3 pos = vec3(gl_FragCoord.xy, 1); 791 vec3 pos = vec3(gl_FragCoord.xy, 1);
743 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); 792 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
744 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); 793 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
745 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); 794 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
746 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); 795 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
747 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); 796 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0);
748 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); 797 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0);
749 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); 798 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0);
750 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); 799 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0);
(...skipping 30 matching lines...) Expand all
781 m_uTextureLocation = locations[1]; 830 m_uTextureLocation = locations[1];
782 m_vTextureLocation = locations[2]; 831 m_vTextureLocation = locations[2];
783 m_alphaLocation = locations[3]; 832 m_alphaLocation = locations[3];
784 m_yuvMatrixLocation = locations[4]; 833 m_yuvMatrixLocation = locations[4];
785 m_yuvAdjLocation = locations[5]; 834 m_yuvAdjLocation = locations[5];
786 835
787 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1 836 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1
788 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1); 837 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1);
789 } 838 }
790 839
791 std::string FragmentShaderYUVVideo::getShaderString() const 840 std::string FragmentShaderYUVVideo::getShaderString(WebGraphicsContext3D* contex t,
841 TexCoordPrecision precision) const
792 { 842 {
793 return SHADER( 843 return FRAGMENT_SHADER(
794 precision mediump float; 844 precision mediump float;
795 precision mediump int; 845 precision mediump int;
796 varying vec2 v_texCoord; 846 varying TexCoordPrecision vec2 v_texCoord;
797 uniform sampler2D y_texture; 847 uniform sampler2D y_texture;
798 uniform sampler2D u_texture; 848 uniform sampler2D u_texture;
799 uniform sampler2D v_texture; 849 uniform sampler2D v_texture;
800 uniform float alpha; 850 uniform float alpha;
801 uniform vec3 yuv_adj; 851 uniform vec3 yuv_adj;
802 uniform mat3 yuv_matrix; 852 uniform mat3 yuv_matrix;
803 void main() 853 void main()
804 { 854 {
805 float y_raw = texture2D(y_texture, v_texCoord).x; 855 float y_raw = texture2D(y_texture, v_texCoord).x;
806 float u_unsigned = texture2D(u_texture, v_texCoord).x; 856 float u_unsigned = texture2D(u_texture, v_texCoord).x;
(...skipping 16 matching lines...) Expand all
823 "color", 873 "color",
824 }; 874 };
825 int locations[1]; 875 int locations[1];
826 876
827 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 877 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
828 878
829 m_colorLocation = locations[0]; 879 m_colorLocation = locations[0];
830 DCHECK(m_colorLocation != -1); 880 DCHECK(m_colorLocation != -1);
831 } 881 }
832 882
833 std::string FragmentShaderColor::getShaderString() const 883 std::string FragmentShaderColor::getShaderString(WebGraphicsContext3D* context,
884 TexCoordPrecision precision) co nst
834 { 885 {
835 return SHADER( 886 return FRAGMENT_SHADER(
836 precision mediump float; 887 precision mediump float;
837 uniform vec4 color; 888 uniform vec4 color;
838 void main() 889 void main()
839 { 890 {
840 gl_FragColor = color; 891 gl_FragColor = color;
841 } 892 }
842 ); 893 );
843 } 894 }
844 895
845 FragmentShaderColorAA::FragmentShaderColorAA() 896 FragmentShaderColorAA::FragmentShaderColorAA()
(...skipping 10 matching lines...) Expand all
856 }; 907 };
857 int locations[2]; 908 int locations[2];
858 909
859 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 910 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
860 911
861 m_edgeLocation = locations[0]; 912 m_edgeLocation = locations[0];
862 m_colorLocation = locations[1]; 913 m_colorLocation = locations[1];
863 DCHECK(m_edgeLocation != -1 && m_colorLocation != -1); 914 DCHECK(m_edgeLocation != -1 && m_colorLocation != -1);
864 } 915 }
865 916
866 std::string FragmentShaderColorAA::getShaderString() const 917 std::string FragmentShaderColorAA::getShaderString(WebGraphicsContext3D* context ,
918 TexCoordPrecision precision) const
867 { 919 {
868 return SHADER( 920 return FRAGMENT_SHADER(
869 precision mediump float; 921 precision mediump float;
870 uniform vec4 color; 922 uniform vec4 color;
871 uniform vec3 edge[8]; 923 uniform vec3 edge[8];
872 void main() 924 void main()
873 { 925 {
874 vec3 pos = vec3(gl_FragCoord.xy, 1); 926 vec3 pos = vec3(gl_FragCoord.xy, 1);
875 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); 927 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
876 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); 928 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
877 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); 929 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
878 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); 930 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
(...skipping 25 matching lines...) Expand all
904 956
905 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; 957 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
906 958
907 m_alphaLocation = locations[0]; 959 m_alphaLocation = locations[0];
908 m_texTransformLocation = locations[1]; 960 m_texTransformLocation = locations[1];
909 m_frequencyLocation = locations[2]; 961 m_frequencyLocation = locations[2];
910 m_colorLocation = locations[3]; 962 m_colorLocation = locations[3];
911 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL ocation != -1 && m_colorLocation != -1); 963 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL ocation != -1 && m_colorLocation != -1);
912 } 964 }
913 965
914 std::string FragmentShaderCheckerboard::getShaderString() const 966 std::string FragmentShaderCheckerboard::getShaderString(WebGraphicsContext3D* co ntext,
967 TexCoordPrecision precis ion) const
915 { 968 {
916 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" 969 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide"
917 // by Munshi, Ginsburg, Shreiner. 970 // by Munshi, Ginsburg, Shreiner.
918 return SHADER( 971 return FRAGMENT_SHADER(
919 precision mediump float; 972 precision mediump float;
920 precision mediump int; 973 precision mediump int;
921 varying vec2 v_texCoord; 974 varying TexCoordPrecision vec2 v_texCoord;
922 uniform float alpha; 975 uniform float alpha;
923 uniform float frequency; 976 uniform float frequency;
924 uniform vec4 texTransform; 977 uniform vec4 texTransform;
925 uniform vec4 color; 978 uniform vec4 color;
926 void main() 979 void main()
927 { 980 {
928 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); 981 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0);
929 vec4 color2 = color; 982 vec4 color2 = color;
930 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; 983 TexCoordPrecision vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texT ransform.zw + texTransform.xy;
931 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 984 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
932 float picker = abs(coord.x - coord.y); 985 float picker = abs(coord.x - coord.y);
933 gl_FragColor = mix(color1, color2, picker) * alpha; 986 gl_FragColor = mix(color1, color2, picker) * alpha;
934 } 987 }
935 ); 988 );
936 } 989 }
937 990
938 } // namespace cc 991 } // namespace cc
OLDNEW
« cc/output/gl_renderer.cc ('K') | « cc/output/shader.h ('k') | cc/output/texture_copier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698