Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/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" | |
|
Sami
2013/02/26 11:56:40
Nit: alpha order.
brianderson
2013/02/26 19:08:21
Presubmit complained when I put khronos before Web
| |
| 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) { | |
|
Vangelis Kokkevis
2013/02/26 01:35:04
Open bracket goes in its own line
| |
| 38 // texCoordPrecisionHigh is used for cases where we absolutely need high pre cision or | |
|
Vangelis Kokkevis
2013/02/26 01:35:04
80 cols. Here and below.
| |
| 39 // where the texture coordinates are not mutated in the fragment shader. | |
| 40 // Some cases that benefit from high precision are: | |
| 41 // * Sampling from textures with width or height > 1024. | |
| 42 // * Linear filtering of scaled textures. | |
| 43 // texCoordPrecisionLow is used for cases where we don't need the high preci sion | |
|
Sami
2013/02/26 11:56:40
Should we call this texCoordPrecisionMedium instea
brianderson
2013/02/26 19:08:21
That's a good idea. I'll change it to texCoordPre
| |
| 44 // unless needsHighPrecisionThroughout is true. | |
| 45 std::string texCoordPrecisionHigh; | |
| 46 std::string texCoordPrecisionLow; | |
| 47 | |
| 48 GLint range[2]; | |
| 49 GLint precision = 0; | |
| 50 GLC(context, context->getShaderPrecisionFormat(GL_FRAGMENT_SHADER, | |
| 51 GL_HIGH_FLOAT, | |
| 52 range, &precision)); | |
| 53 | |
| 54 if (precision || range[0] || range[1]) { | |
| 55 DCHECK(precision >= 16); | |
| 56 DCHECK(range[0] >= 62); | |
| 57 DCHECK(range[1] >= 62); | |
| 58 texCoordPrecisionHigh = "highp"; | |
| 59 texCoordPrecisionLow = "mediump"; | |
| 60 } | |
| 61 else { | |
|
Vangelis Kokkevis
2013/02/26 01:35:04
else needs to go to the previous line
| |
| 62 texCoordPrecisionHigh = "mediump"; | |
| 63 texCoordPrecisionLow = "mediump"; | |
| 64 } | |
| 65 | |
| 66 return "#define TexCoordPrecisionHigh " + texCoordPrecisionHigh + "\n" + | |
| 67 "#define TexCoordPrecisionLow " + texCoordPrecisionLow + "\n" + | |
| 68 std::string(shaderString); | |
| 69 } | |
| 70 | |
| 71 static std::string setVertexTexCoordPrecision(WebGraphicsContext3D* context, | |
| 72 const char* shaderString) { | |
| 73 return "#define TexCoordPrecisionHigh highp\n" + | |
| 74 std::string(shaderString); | |
| 75 } | |
| 76 | |
| 33 } | 77 } |
| 34 | 78 |
| 35 VertexShaderPosTex::VertexShaderPosTex() | 79 VertexShaderPosTex::VertexShaderPosTex() |
| 36 : m_matrixLocation(-1) | 80 : m_matrixLocation(-1) |
| 37 { | 81 { |
| 38 } | 82 } |
| 39 | 83 |
| 40 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b ool usingBindUniform, int* baseUniformIndex) | 84 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b ool usingBindUniform, int* baseUniformIndex) |
| 41 { | 85 { |
| 42 static const char* shaderUniforms[] = { | 86 static const char* shaderUniforms[] = { |
| 43 "matrix", | 87 "matrix", |
| 44 }; | 88 }; |
| 45 int locations[1]; | 89 int locations[1]; |
| 46 | 90 |
| 47 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 91 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 48 | 92 |
| 49 m_matrixLocation = locations[0]; | 93 m_matrixLocation = locations[0]; |
| 50 DCHECK(m_matrixLocation != -1); | 94 DCHECK(m_matrixLocation != -1); |
| 51 } | 95 } |
| 52 | 96 |
| 53 std::string VertexShaderPosTex::getShaderString() const | 97 std::string VertexShaderPosTex::getShaderString(WebGraphicsContext3D* context) c onst |
| 54 { | 98 { |
| 55 return SHADER( | 99 return VERTEX_SHADER( |
| 56 attribute vec4 a_position; | 100 attribute vec4 a_position; |
| 57 attribute vec2 a_texCoord; | 101 attribute TexCoordPrecisionHigh vec2 a_texCoord; |
| 58 uniform mat4 matrix; | 102 uniform mat4 matrix; |
| 59 varying vec2 v_texCoord; | 103 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 60 void main() | 104 void main() |
| 61 { | 105 { |
| 62 gl_Position = matrix * a_position; | 106 gl_Position = matrix * a_position; |
| 63 v_texCoord = a_texCoord; | 107 v_texCoord = a_texCoord; |
| 64 } | 108 } |
| 65 ); | 109 ); |
| 66 } | 110 } |
| 67 | 111 |
| 68 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() | 112 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() |
| 69 : m_matrixLocation(-1) | 113 : m_matrixLocation(-1) |
| 70 , m_texScaleLocation(-1) | 114 , m_texScaleLocation(-1) |
| 71 { | 115 { |
| 72 } | 116 } |
| 73 | 117 |
| 74 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) | 118 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) |
| 75 { | 119 { |
| 76 static const char* shaderUniforms[] = { | 120 static const char* shaderUniforms[] = { |
| 77 "matrix", | 121 "matrix", |
| 78 "texScale", | 122 "texScale", |
| 79 }; | 123 }; |
| 80 int locations[2]; | 124 int locations[2]; |
| 81 | 125 |
| 82 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 126 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 83 | 127 |
| 84 m_matrixLocation = locations[0]; | 128 m_matrixLocation = locations[0]; |
| 85 m_texScaleLocation = locations[1]; | 129 m_texScaleLocation = locations[1]; |
| 86 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1); | 130 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1); |
| 87 } | 131 } |
| 88 | 132 |
| 89 std::string VertexShaderPosTexYUVStretch::getShaderString() const | 133 std::string VertexShaderPosTexYUVStretch::getShaderString(WebGraphicsContext3D* context) const |
| 90 { | 134 { |
| 91 return SHADER( | 135 return VERTEX_SHADER( |
| 92 precision mediump float; | 136 precision mediump float; |
| 93 attribute vec4 a_position; | 137 attribute vec4 a_position; |
| 94 attribute vec2 a_texCoord; | 138 attribute TexCoordPrecisionHigh vec2 a_texCoord; |
| 95 uniform mat4 matrix; | 139 uniform mat4 matrix; |
| 96 varying vec2 v_texCoord; | 140 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 97 uniform vec2 texScale; | 141 uniform TexCoordPrecisionHigh vec2 texScale; |
| 98 void main() | 142 void main() |
| 99 { | 143 { |
| 100 gl_Position = matrix * a_position; | 144 gl_Position = matrix * a_position; |
| 101 v_texCoord = a_texCoord * texScale; | 145 v_texCoord = a_texCoord * texScale; |
| 102 } | 146 } |
| 103 ); | 147 ); |
| 104 } | 148 } |
| 105 | 149 |
| 106 VertexShaderPos::VertexShaderPos() | 150 VertexShaderPos::VertexShaderPos() |
| 107 : m_matrixLocation(-1) | 151 : m_matrixLocation(-1) |
| 108 { | 152 { |
| 109 } | 153 } |
| 110 | 154 |
| 111 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) | 155 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) |
| 112 { | 156 { |
| 113 static const char* shaderUniforms[] = { | 157 static const char* shaderUniforms[] = { |
| 114 "matrix", | 158 "matrix", |
| 115 }; | 159 }; |
| 116 int locations[1]; | 160 int locations[1]; |
| 117 | 161 |
| 118 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 162 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 119 | 163 |
| 120 m_matrixLocation = locations[0]; | 164 m_matrixLocation = locations[0]; |
| 121 DCHECK(m_matrixLocation != -1); | 165 DCHECK(m_matrixLocation != -1); |
| 122 } | 166 } |
| 123 | 167 |
| 124 std::string VertexShaderPos::getShaderString() const | 168 std::string VertexShaderPos::getShaderString(WebGraphicsContext3D* context) cons t |
| 125 { | 169 { |
| 126 return SHADER( | 170 return VERTEX_SHADER( |
| 127 attribute vec4 a_position; | 171 attribute vec4 a_position; |
| 128 uniform mat4 matrix; | 172 uniform mat4 matrix; |
| 129 void main() | 173 void main() |
| 130 { | 174 { |
| 131 gl_Position = matrix * a_position; | 175 gl_Position = matrix * a_position; |
| 132 } | 176 } |
| 133 ); | 177 ); |
| 134 } | 178 } |
| 135 | 179 |
| 136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | 180 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 150 int locations[3]; | 194 int locations[3]; |
| 151 | 195 |
| 152 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 196 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 153 | 197 |
| 154 m_matrixLocation = locations[0]; | 198 m_matrixLocation = locations[0]; |
| 155 m_texTransformLocation = locations[1]; | 199 m_texTransformLocation = locations[1]; |
| 156 m_vertexOpacityLocation = locations[2]; | 200 m_vertexOpacityLocation = locations[2]; |
| 157 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1); | 201 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1); |
| 158 } | 202 } |
| 159 | 203 |
| 160 std::string VertexShaderPosTexTransform::getShaderString() const | 204 std::string VertexShaderPosTexTransform::getShaderString(WebGraphicsContext3D* c ontext) const |
| 161 { | 205 { |
| 162 return SHADER( | 206 return VERTEX_SHADER( |
| 163 attribute vec4 a_position; | 207 attribute vec4 a_position; |
| 164 attribute vec2 a_texCoord; | 208 attribute TexCoordPrecisionHigh vec2 a_texCoord; |
| 165 attribute float a_index; | 209 attribute float a_index; |
| 166 uniform mat4 matrix[8]; | 210 uniform mat4 matrix[8]; |
| 167 uniform vec4 texTransform[8]; | 211 uniform TexCoordPrecisionHigh vec4 texTransform[8]; |
| 168 uniform float opacity[32]; | 212 uniform float opacity[32]; |
| 169 varying vec2 v_texCoord; | 213 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 170 varying float v_alpha; | 214 varying float v_alpha; |
| 171 void main() | 215 void main() |
| 172 { | 216 { |
| 173 gl_Position = matrix[int(a_index * 0.25)] * a_position; | 217 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
| 174 vec4 texTrans = texTransform[int(a_index * 0.25)]; | 218 TexCoordPrecisionHigh vec4 texTrans = texTransform[int(a_index * 0.2 5)]; |
| 175 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 219 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 176 v_alpha = opacity[int(a_index)]; | 220 v_alpha = opacity[int(a_index)]; |
| 177 } | 221 } |
| 178 ); | 222 ); |
| 179 } | 223 } |
| 180 | 224 |
| 181 std::string VertexShaderPosTexTransformFlip::getShaderString() const | 225 std::string VertexShaderPosTexTransformFlip::getShaderString(WebGraphicsContext3 D* context) const |
| 182 { | 226 { |
| 183 return SHADER( | 227 return VERTEX_SHADER( |
| 184 attribute vec4 a_position; | 228 attribute vec4 a_position; |
| 185 attribute vec2 a_texCoord; | 229 attribute TexCoordPrecisionHigh vec2 a_texCoord; |
| 186 attribute float a_index; | 230 attribute float a_index; |
| 187 uniform mat4 matrix[8]; | 231 uniform mat4 matrix[8]; |
| 188 uniform vec4 texTransform[8]; | 232 uniform TexCoordPrecisionHigh vec4 texTransform[8]; |
| 189 uniform float opacity[32]; | 233 uniform float opacity[32]; |
| 190 varying vec2 v_texCoord; | 234 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 191 varying float v_alpha; | 235 varying float v_alpha; |
| 192 void main() | 236 void main() |
| 193 { | 237 { |
| 194 gl_Position = matrix[int(a_index * 0.25)] * a_position; | 238 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
| 195 vec4 texTrans = texTransform[int(a_index * 0.25)]; | 239 TexCoordPrecisionHigh vec4 texTrans = texTransform[int(a_index * 0.2 5)]; |
| 196 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 240 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 197 v_texCoord.y = 1.0 - v_texCoord.y; | 241 v_texCoord.y = 1.0 - v_texCoord.y; |
| 198 v_alpha = opacity[int(a_index)]; | 242 v_alpha = opacity[int(a_index)]; |
| 199 } | 243 } |
| 200 ); | 244 ); |
| 201 } | 245 } |
| 202 | 246 |
| 203 std::string VertexShaderPosTexIdentity::getShaderString() const | 247 std::string VertexShaderPosTexIdentity::getShaderString(WebGraphicsContext3D* co ntext) const |
| 204 { | 248 { |
| 205 return SHADER( | 249 return VERTEX_SHADER( |
| 206 attribute vec4 a_position; | 250 attribute vec4 a_position; |
| 207 varying vec2 v_texCoord; | 251 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 208 void main() | 252 void main() |
| 209 { | 253 { |
| 210 gl_Position = a_position; | 254 gl_Position = a_position; |
| 211 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 255 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
| 212 } | 256 } |
| 213 ); | 257 ); |
| 214 } | 258 } |
| 215 | 259 |
| 216 VertexShaderQuad::VertexShaderQuad() | 260 VertexShaderQuad::VertexShaderQuad() |
| 217 : m_matrixLocation(-1) | 261 : m_matrixLocation(-1) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 232 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 276 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 233 | 277 |
| 234 m_matrixLocation = locations[0]; | 278 m_matrixLocation = locations[0]; |
| 235 m_pointLocation = locations[1]; | 279 m_pointLocation = locations[1]; |
| 236 m_texScaleLocation = locations[2]; | 280 m_texScaleLocation = locations[2]; |
| 237 DCHECK_NE(m_matrixLocation, -1); | 281 DCHECK_NE(m_matrixLocation, -1); |
| 238 DCHECK_NE(m_pointLocation, -1); | 282 DCHECK_NE(m_pointLocation, -1); |
| 239 DCHECK_NE(m_texScaleLocation, -1); | 283 DCHECK_NE(m_texScaleLocation, -1); |
| 240 } | 284 } |
| 241 | 285 |
| 242 std::string VertexShaderQuad::getShaderString() const | 286 std::string VertexShaderQuad::getShaderString(WebGraphicsContext3D* context) con st |
| 243 { | 287 { |
| 244 return SHADER( | 288 return VERTEX_SHADER( |
| 245 attribute vec4 a_position; | 289 attribute TexCoordPrecisionHigh vec4 a_position; |
| 246 attribute vec2 a_texCoord; | 290 attribute TexCoordPrecisionHigh vec2 a_texCoord; |
| 247 uniform mat4 matrix; | 291 uniform mat4 matrix; |
| 248 uniform vec2 point[4]; | 292 uniform TexCoordPrecisionHigh vec2 point[4]; |
| 249 uniform vec2 texScale; | 293 uniform TexCoordPrecisionHigh vec2 texScale; |
| 250 varying vec2 v_texCoord; | 294 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 251 void main() | 295 void main() |
| 252 { | 296 { |
| 253 vec2 complement = abs(a_texCoord - 1.0); | 297 TexCoordPrecisionHigh vec2 complement = abs(a_texCoord - 1.0); |
| 254 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 298 TexCoordPrecisionHigh vec4 pos = vec4(0.0, 0.0, a_position.z, a_posi tion.w); |
| 255 pos.xy += (complement.x * complement.y) * point[0]; | 299 pos.xy += (complement.x * complement.y) * point[0]; |
| 256 pos.xy += (a_texCoord.x * complement.y) * point[1]; | 300 pos.xy += (a_texCoord.x * complement.y) * point[1]; |
| 257 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | 301 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; |
| 258 pos.xy += (complement.x * a_texCoord.y) * point[3]; | 302 pos.xy += (complement.x * a_texCoord.y) * point[3]; |
| 259 gl_Position = matrix * pos; | 303 gl_Position = matrix * pos; |
| 260 v_texCoord = (pos.xy + vec2(0.5)) * texScale; | 304 v_texCoord = (pos.xy + vec2(0.5)) * texScale; |
| 261 } | 305 } |
| 262 ); | 306 ); |
| 263 } | 307 } |
| 264 | 308 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 279 int locations[3]; | 323 int locations[3]; |
| 280 | 324 |
| 281 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 325 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 282 | 326 |
| 283 m_matrixLocation = locations[0]; | 327 m_matrixLocation = locations[0]; |
| 284 m_pointLocation = locations[1]; | 328 m_pointLocation = locations[1]; |
| 285 m_vertexTexTransformLocation = locations[2]; | 329 m_vertexTexTransformLocation = locations[2]; |
| 286 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1); | 330 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1); |
| 287 } | 331 } |
| 288 | 332 |
| 289 std::string VertexShaderTile::getShaderString() const | 333 std::string VertexShaderTile::getShaderString(WebGraphicsContext3D* context) con st |
| 290 { | 334 { |
| 291 return SHADER( | 335 return VERTEX_SHADER( |
| 292 attribute vec4 a_position; | 336 attribute TexCoordPrecisionHigh vec4 a_position; |
| 293 attribute vec2 a_texCoord; | 337 attribute TexCoordPrecisionHigh vec2 a_texCoord; |
| 294 uniform mat4 matrix; | 338 uniform mat4 matrix; |
| 295 uniform vec2 point[4]; | 339 uniform TexCoordPrecisionHigh vec2 point[4]; |
| 296 uniform vec4 vertexTexTransform; | 340 uniform TexCoordPrecisionHigh vec4 vertexTexTransform; |
| 297 varying vec2 v_texCoord; | 341 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 298 void main() | 342 void main() |
| 299 { | 343 { |
| 300 vec2 complement = abs(a_texCoord - 1.0); | 344 vec2 complement = abs(a_texCoord - 1.0); |
| 301 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 345 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 302 pos.xy += (complement.x * complement.y) * point[0]; | 346 pos.xy += (complement.x * complement.y) * point[0]; |
| 303 pos.xy += (a_texCoord.x * complement.y) * point[1]; | 347 pos.xy += (a_texCoord.x * complement.y) * point[1]; |
| 304 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | 348 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; |
| 305 pos.xy += (complement.x * a_texCoord.y) * point[3]; | 349 pos.xy += (complement.x * a_texCoord.y) * point[3]; |
| 306 gl_Position = matrix * pos; | 350 gl_Position = matrix * pos; |
| 307 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | 351 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 323 }; | 367 }; |
| 324 int locations[2]; | 368 int locations[2]; |
| 325 | 369 |
| 326 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 370 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 327 | 371 |
| 328 m_matrixLocation = locations[0]; | 372 m_matrixLocation = locations[0]; |
| 329 m_texMatrixLocation = locations[1]; | 373 m_texMatrixLocation = locations[1]; |
| 330 return m_matrixLocation != -1 && m_texMatrixLocation != -1; | 374 return m_matrixLocation != -1 && m_texMatrixLocation != -1; |
| 331 } | 375 } |
| 332 | 376 |
| 333 std::string VertexShaderVideoTransform::getShaderString() const | 377 std::string VertexShaderVideoTransform::getShaderString(WebGraphicsContext3D* co ntext) const |
| 334 { | 378 { |
| 335 return SHADER( | 379 return VERTEX_SHADER( |
| 336 attribute vec4 a_position; | 380 attribute vec4 a_position; |
| 337 attribute vec2 a_texCoord; | 381 attribute TexCoordPrecisionHigh vec2 a_texCoord; |
| 338 uniform mat4 matrix; | 382 uniform mat4 matrix; |
| 339 uniform mat4 texMatrix; | 383 uniform TexCoordPrecisionHigh mat4 texMatrix; |
| 340 varying vec2 v_texCoord; | 384 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 341 void main() | 385 void main() |
| 342 { | 386 { |
| 343 gl_Position = matrix * a_position; | 387 gl_Position = matrix * a_position; |
| 344 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 388 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
| 345 } | 389 } |
| 346 ); | 390 ); |
| 347 } | 391 } |
| 348 | 392 |
| 349 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | 393 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
| 350 : m_samplerLocation(-1) | 394 : m_samplerLocation(-1) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 "s_texture", | 435 "s_texture", |
| 392 }; | 436 }; |
| 393 int locations[1]; | 437 int locations[1]; |
| 394 | 438 |
| 395 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 439 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 396 | 440 |
| 397 m_samplerLocation = locations[0]; | 441 m_samplerLocation = locations[0]; |
| 398 return m_samplerLocation != -1; | 442 return m_samplerLocation != -1; |
| 399 } | 443 } |
| 400 | 444 |
| 401 std::string FragmentShaderOESImageExternal::getShaderString() const | 445 std::string FragmentShaderOESImageExternal::getShaderString(WebGraphicsContext3D * context) const |
| 402 { | 446 { |
| 403 // Cannot use the SHADER() macro because of the '#' char | 447 // Cannot use the FRAGMENT_SHADER() macro because of the '#' char |
| 404 return "#extension GL_OES_EGL_image_external : require \n" | 448 return setFragTexCoordPrecision(context, |
| 449 "#extension GL_OES_EGL_image_external : require \n" | |
| 405 "precision mediump float;\n" | 450 "precision mediump float;\n" |
| 406 "varying vec2 v_texCoord;\n" | 451 "varying TexCoordPrecisionHigh vec2 v_texCoord;\n" |
| 407 "uniform samplerExternalOES s_texture;\n" | 452 "uniform samplerExternalOES s_texture;\n" |
| 408 "void main()\n" | 453 "void main()\n" |
| 409 "{\n" | 454 "{\n" |
| 410 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" | 455 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" |
| 411 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor .w);\n" | 456 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor .w);\n" |
| 412 "}\n"; | 457 "}\n"); |
| 413 } | 458 } |
| 414 | 459 |
| 415 std::string FragmentShaderRGBATexAlpha::getShaderString() const | 460 std::string FragmentShaderRGBATexAlpha::getShaderString(WebGraphicsContext3D* co ntext) const |
| 416 { | 461 { |
| 417 return SHADER( | 462 return FRAGMENT_SHADER( |
| 418 precision mediump float; | 463 precision mediump float; |
| 419 varying vec2 v_texCoord; | 464 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 420 uniform sampler2D s_texture; | 465 uniform sampler2D s_texture; |
| 421 uniform float alpha; | 466 uniform float alpha; |
| 422 void main() | 467 void main() |
| 423 { | 468 { |
| 424 vec4 texColor = texture2D(s_texture, v_texCoord); | 469 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 425 gl_FragColor = texColor * alpha; | 470 gl_FragColor = texColor * alpha; |
| 426 } | 471 } |
| 427 ); | 472 ); |
| 428 } | 473 } |
| 429 | 474 |
| 430 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const | 475 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString(WebGraphicsContex t3D* context) const |
| 431 { | 476 { |
| 432 return SHADER( | 477 return FRAGMENT_SHADER( |
| 433 precision mediump float; | 478 precision mediump float; |
| 434 varying vec2 v_texCoord; | 479 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 435 varying float v_alpha; | 480 varying float v_alpha; |
| 436 uniform sampler2D s_texture; | 481 uniform sampler2D s_texture; |
| 437 void main() | 482 void main() |
| 438 { | 483 { |
| 439 vec4 texColor = texture2D(s_texture, v_texCoord); | 484 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 440 gl_FragColor = texColor * v_alpha; | 485 gl_FragColor = texColor * v_alpha; |
| 441 } | 486 } |
| 442 ); | 487 ); |
| 443 } | 488 } |
| 444 | 489 |
| 445 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const | 490 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString(WebGraphicsCo ntext3D* context) const |
| 446 { | 491 { |
| 447 return "#extension GL_ARB_texture_rectangle : require\n" | 492 return setFragTexCoordPrecision(context, |
| 493 "#extension GL_ARB_texture_rectangle : require\n" | |
| 448 "precision mediump float;\n" | 494 "precision mediump float;\n" |
| 449 "varying vec2 v_texCoord;\n" | 495 "varying TexCoordPrecisionHigh vec2 v_texCoord;\n" |
| 450 "varying float v_alpha;\n" | 496 "varying float v_alpha;\n" |
| 451 "uniform sampler2DRect s_texture;\n" | 497 "uniform sampler2DRect s_texture;\n" |
| 452 "void main()\n" | 498 "void main()\n" |
| 453 "{\n" | 499 "{\n" |
| 454 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | 500 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" |
| 455 " gl_FragColor = texColor * v_alpha;\n" | 501 " gl_FragColor = texColor * v_alpha;\n" |
| 456 "}\n"; | 502 "}\n"); |
| 457 } | 503 } |
| 458 | 504 |
| 459 std::string FragmentShaderRGBATexOpaque::getShaderString() const | 505 std::string FragmentShaderRGBATexOpaque::getShaderString(WebGraphicsContext3D* c ontext) const |
| 460 { | 506 { |
| 461 return SHADER( | 507 return FRAGMENT_SHADER( |
| 462 precision mediump float; | 508 precision mediump float; |
| 463 varying vec2 v_texCoord; | 509 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 464 uniform sampler2D s_texture; | 510 uniform sampler2D s_texture; |
| 465 void main() | 511 void main() |
| 466 { | 512 { |
| 467 vec4 texColor = texture2D(s_texture, v_texCoord); | 513 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 468 gl_FragColor = vec4(texColor.rgb, 1.0); | 514 gl_FragColor = vec4(texColor.rgb, 1.0); |
| 469 } | 515 } |
| 470 ); | 516 ); |
| 471 } | 517 } |
| 472 | 518 |
| 473 std::string FragmentShaderRGBATex::getShaderString() const | 519 std::string FragmentShaderRGBATex::getShaderString(WebGraphicsContext3D* context ) const |
| 474 { | 520 { |
| 475 return SHADER( | 521 return FRAGMENT_SHADER( |
| 476 precision mediump float; | 522 precision mediump float; |
| 477 varying vec2 v_texCoord; | 523 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 478 uniform sampler2D s_texture; | 524 uniform sampler2D s_texture; |
| 479 void main() | 525 void main() |
| 480 { | 526 { |
| 481 gl_FragColor = texture2D(s_texture, v_texCoord); | 527 gl_FragColor = texture2D(s_texture, v_texCoord); |
| 482 } | 528 } |
| 483 ); | 529 ); |
| 484 } | 530 } |
| 485 | 531 |
| 486 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const | 532 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString(WebGraphicsContex t3D* context) const |
| 487 { | 533 { |
| 488 return SHADER( | 534 return FRAGMENT_SHADER( |
| 489 precision mediump float; | 535 precision mediump float; |
| 490 varying vec2 v_texCoord; | 536 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 491 uniform sampler2D s_texture; | 537 uniform sampler2D s_texture; |
| 492 uniform float alpha; | 538 uniform float alpha; |
| 493 void main() | 539 void main() |
| 494 { | 540 { |
| 495 vec4 texColor = texture2D(s_texture, v_texCoord); | 541 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 496 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; | 542 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; |
| 497 } | 543 } |
| 498 ); | 544 ); |
| 499 } | 545 } |
| 500 | 546 |
| 501 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const | 547 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString(WebGraphicsConte xt3D* context) const |
| 502 { | 548 { |
| 503 return SHADER( | 549 return FRAGMENT_SHADER( |
| 504 precision mediump float; | 550 precision mediump float; |
| 505 varying vec2 v_texCoord; | 551 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 506 uniform sampler2D s_texture; | 552 uniform sampler2D s_texture; |
| 507 void main() | 553 void main() |
| 508 { | 554 { |
| 509 vec4 texColor = texture2D(s_texture, v_texCoord); | 555 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 510 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 556 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
| 511 } | 557 } |
| 512 ); | 558 ); |
| 513 } | 559 } |
| 514 | 560 |
| 515 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 561 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 529 int locations[3]; | 575 int locations[3]; |
| 530 | 576 |
| 531 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 577 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 532 | 578 |
| 533 m_samplerLocation = locations[0]; | 579 m_samplerLocation = locations[0]; |
| 534 m_alphaLocation = locations[1]; | 580 m_alphaLocation = locations[1]; |
| 535 m_edgeLocation = locations[2]; | 581 m_edgeLocation = locations[2]; |
| 536 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1); | 582 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1); |
| 537 } | 583 } |
| 538 | 584 |
| 539 std::string FragmentShaderRGBATexAlphaAA::getShaderString() const | 585 std::string FragmentShaderRGBATexAlphaAA::getShaderString(WebGraphicsContext3D* context) const |
| 540 { | 586 { |
| 541 return SHADER( | 587 return FRAGMENT_SHADER( |
| 542 precision mediump float; | 588 precision mediump float; |
| 543 varying vec2 v_texCoord; | 589 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 544 uniform sampler2D s_texture; | 590 uniform sampler2D s_texture; |
| 545 uniform float alpha; | 591 uniform float alpha; |
| 546 uniform vec3 edge[8]; | 592 uniform vec3 edge[8]; |
| 547 void main() | 593 void main() |
| 548 { | 594 { |
| 549 vec4 texColor = texture2D(s_texture, v_texCoord); | 595 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 550 vec3 pos = vec3(gl_FragCoord.xy, 1); | 596 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 551 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 597 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 552 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 598 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 553 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 599 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 581 | 627 |
| 582 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 628 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 583 | 629 |
| 584 m_samplerLocation = locations[0]; | 630 m_samplerLocation = locations[0]; |
| 585 m_alphaLocation = locations[1]; | 631 m_alphaLocation = locations[1]; |
| 586 m_fragmentTexTransformLocation = locations[2]; | 632 m_fragmentTexTransformLocation = locations[2]; |
| 587 m_edgeLocation = locations[3]; | 633 m_edgeLocation = locations[3]; |
| 588 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1); | 634 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1); |
| 589 } | 635 } |
| 590 | 636 |
| 591 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString() const | 637 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString(WebGraphicsContex t3D* context) 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 TexCoordPrecisionLow 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 TexCoordPrecisionLow 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 TexCoordPrecisionLow vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * f ragmentTexTransform.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) const |
| 619 { | 665 { |
| 620 return SHADER( | 666 return FRAGMENT_SHADER( |
| 621 precision mediump float; | 667 precision mediump float; |
| 622 varying vec2 v_texCoord; | 668 varying TexCoordPrecisionLow vec2 v_texCoord; |
| 623 uniform sampler2D s_texture; | 669 uniform sampler2D s_texture; |
| 624 uniform float alpha; | 670 uniform float alpha; |
| 625 uniform vec4 fragmentTexTransform; | 671 uniform TexCoordPrecisionLow vec4 fragmentTexTransform; |
| 626 uniform vec3 edge[8]; | 672 uniform vec3 edge[8]; |
| 627 void main() | 673 void main() |
| 628 { | 674 { |
| 629 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy; | 675 TexCoordPrecisionLow vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * f ragmentTexTransform.zw + fragmentTexTransform.xy; |
| 630 vec4 texColor = texture2D(s_texture, texCoord); | 676 vec4 texColor = texture2D(s_texture, texCoord); |
| 631 vec3 pos = vec3(gl_FragCoord.xy, 1); | 677 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 632 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 678 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 633 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 679 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 634 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 680 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 635 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 681 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 636 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 682 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 637 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 683 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 638 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 684 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 639 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 685 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 664 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 710 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 665 | 711 |
| 666 m_samplerLocation = locations[0]; | 712 m_samplerLocation = locations[0]; |
| 667 m_maskSamplerLocation = locations[1]; | 713 m_maskSamplerLocation = locations[1]; |
| 668 m_alphaLocation = locations[2]; | 714 m_alphaLocation = locations[2]; |
| 669 m_maskTexCoordScaleLocation = locations[3]; | 715 m_maskTexCoordScaleLocation = locations[3]; |
| 670 m_maskTexCoordOffsetLocation = locations[4]; | 716 m_maskTexCoordOffsetLocation = locations[4]; |
| 671 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1); | 717 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1); |
| 672 } | 718 } |
| 673 | 719 |
| 674 std::string FragmentShaderRGBATexAlphaMask::getShaderString() const | 720 std::string FragmentShaderRGBATexAlphaMask::getShaderString(WebGraphicsContext3D * context) const |
| 675 { | 721 { |
| 676 return SHADER( | 722 return FRAGMENT_SHADER( |
| 677 precision mediump float; | 723 precision mediump float; |
| 678 varying vec2 v_texCoord; | 724 varying TexCoordPrecisionLow vec2 v_texCoord; |
| 679 uniform sampler2D s_texture; | 725 uniform sampler2D s_texture; |
| 680 uniform sampler2D s_mask; | 726 uniform sampler2D s_mask; |
| 681 uniform vec2 maskTexCoordScale; | 727 uniform TexCoordPrecisionLow vec2 maskTexCoordScale; |
| 682 uniform vec2 maskTexCoordOffset; | 728 uniform TexCoordPrecisionLow vec2 maskTexCoordOffset; |
| 683 uniform float alpha; | 729 uniform float alpha; |
| 684 void main() | 730 void main() |
| 685 { | 731 { |
| 686 vec4 texColor = texture2D(s_texture, v_texCoord); | 732 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); | 733 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); | 734 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 689 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w; | 735 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w; |
| 690 } | 736 } |
| 691 ); | 737 ); |
| 692 } | 738 } |
| 693 | 739 |
| 694 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 740 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
| 695 : m_samplerLocation(-1) | 741 : m_samplerLocation(-1) |
| 696 , m_maskSamplerLocation(-1) | 742 , m_maskSamplerLocation(-1) |
| 697 , m_alphaLocation(-1) | 743 , m_alphaLocation(-1) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 716 | 762 |
| 717 m_samplerLocation = locations[0]; | 763 m_samplerLocation = locations[0]; |
| 718 m_maskSamplerLocation = locations[1]; | 764 m_maskSamplerLocation = locations[1]; |
| 719 m_alphaLocation = locations[2]; | 765 m_alphaLocation = locations[2]; |
| 720 m_edgeLocation = locations[3]; | 766 m_edgeLocation = locations[3]; |
| 721 m_maskTexCoordScaleLocation = locations[4]; | 767 m_maskTexCoordScaleLocation = locations[4]; |
| 722 m_maskTexCoordOffsetLocation = locations[5]; | 768 m_maskTexCoordOffsetLocation = locations[5]; |
| 723 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1 && m_edgeLocation != -1); | 769 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1 && m_edgeLocation != -1); |
| 724 } | 770 } |
| 725 | 771 |
| 726 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString() const | 772 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString(WebGraphicsContext 3D* context) const |
| 727 { | 773 { |
| 728 return SHADER( | 774 return FRAGMENT_SHADER( |
| 729 precision mediump float; | 775 precision mediump float; |
| 730 varying vec2 v_texCoord; | 776 varying TexCoordPrecisionLow vec2 v_texCoord; |
| 731 uniform sampler2D s_texture; | 777 uniform sampler2D s_texture; |
| 732 uniform sampler2D s_mask; | 778 uniform sampler2D s_mask; |
| 733 uniform vec2 maskTexCoordScale; | 779 uniform TexCoordPrecisionLow vec2 maskTexCoordScale; |
| 734 uniform vec2 maskTexCoordOffset; | 780 uniform TexCoordPrecisionLow vec2 maskTexCoordOffset; |
| 735 uniform float alpha; | 781 uniform float alpha; |
| 736 uniform vec3 edge[8]; | 782 uniform vec3 edge[8]; |
| 737 void main() | 783 void main() |
| 738 { | 784 { |
| 739 vec4 texColor = texture2D(s_texture, v_texCoord); | 785 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); | 786 TexCoordPrecisionLow vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskT exCoordScale.y); |
| 741 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 787 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 742 vec3 pos = vec3(gl_FragCoord.xy, 1); | 788 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 743 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 789 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 744 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 790 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 745 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 791 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 746 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 792 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 747 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 793 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 748 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 794 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 749 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 795 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 750 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 796 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 781 m_uTextureLocation = locations[1]; | 827 m_uTextureLocation = locations[1]; |
| 782 m_vTextureLocation = locations[2]; | 828 m_vTextureLocation = locations[2]; |
| 783 m_alphaLocation = locations[3]; | 829 m_alphaLocation = locations[3]; |
| 784 m_yuvMatrixLocation = locations[4]; | 830 m_yuvMatrixLocation = locations[4]; |
| 785 m_yuvAdjLocation = locations[5]; | 831 m_yuvAdjLocation = locations[5]; |
| 786 | 832 |
| 787 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1 | 833 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1 |
| 788 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1); | 834 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1); |
| 789 } | 835 } |
| 790 | 836 |
| 791 std::string FragmentShaderYUVVideo::getShaderString() const | 837 std::string FragmentShaderYUVVideo::getShaderString(WebGraphicsContext3D* contex t) const |
| 792 { | 838 { |
| 793 return SHADER( | 839 return FRAGMENT_SHADER( |
| 794 precision mediump float; | 840 precision mediump float; |
| 795 precision mediump int; | 841 precision mediump int; |
| 796 varying vec2 v_texCoord; | 842 varying TexCoordPrecisionHigh vec2 v_texCoord; |
| 797 uniform sampler2D y_texture; | 843 uniform sampler2D y_texture; |
| 798 uniform sampler2D u_texture; | 844 uniform sampler2D u_texture; |
| 799 uniform sampler2D v_texture; | 845 uniform sampler2D v_texture; |
| 800 uniform float alpha; | 846 uniform float alpha; |
| 801 uniform vec3 yuv_adj; | 847 uniform vec3 yuv_adj; |
| 802 uniform mat3 yuv_matrix; | 848 uniform mat3 yuv_matrix; |
| 803 void main() | 849 void main() |
| 804 { | 850 { |
| 805 float y_raw = texture2D(y_texture, v_texCoord).x; | 851 float y_raw = texture2D(y_texture, v_texCoord).x; |
| 806 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 852 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 823 "color", | 869 "color", |
| 824 }; | 870 }; |
| 825 int locations[1]; | 871 int locations[1]; |
| 826 | 872 |
| 827 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 873 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 828 | 874 |
| 829 m_colorLocation = locations[0]; | 875 m_colorLocation = locations[0]; |
| 830 DCHECK(m_colorLocation != -1); | 876 DCHECK(m_colorLocation != -1); |
| 831 } | 877 } |
| 832 | 878 |
| 833 std::string FragmentShaderColor::getShaderString() const | 879 std::string FragmentShaderColor::getShaderString(WebGraphicsContext3D* context) const |
| 834 { | 880 { |
| 835 return SHADER( | 881 return FRAGMENT_SHADER( |
| 836 precision mediump float; | 882 precision mediump float; |
| 837 uniform vec4 color; | 883 uniform vec4 color; |
| 838 void main() | 884 void main() |
| 839 { | 885 { |
| 840 gl_FragColor = color; | 886 gl_FragColor = color; |
| 841 } | 887 } |
| 842 ); | 888 ); |
| 843 } | 889 } |
| 844 | 890 |
| 845 FragmentShaderCheckerboard::FragmentShaderCheckerboard() | 891 FragmentShaderCheckerboard::FragmentShaderCheckerboard() |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 861 | 907 |
| 862 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 908 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
| 863 | 909 |
| 864 m_alphaLocation = locations[0]; | 910 m_alphaLocation = locations[0]; |
| 865 m_texTransformLocation = locations[1]; | 911 m_texTransformLocation = locations[1]; |
| 866 m_frequencyLocation = locations[2]; | 912 m_frequencyLocation = locations[2]; |
| 867 m_colorLocation = locations[3]; | 913 m_colorLocation = locations[3]; |
| 868 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL ocation != -1 && m_colorLocation != -1); | 914 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL ocation != -1 && m_colorLocation != -1); |
| 869 } | 915 } |
| 870 | 916 |
| 871 std::string FragmentShaderCheckerboard::getShaderString() const | 917 std::string FragmentShaderCheckerboard::getShaderString(WebGraphicsContext3D* co ntext) const |
| 872 { | 918 { |
| 873 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | 919 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
| 874 // by Munshi, Ginsburg, Shreiner. | 920 // by Munshi, Ginsburg, Shreiner. |
| 875 return SHADER( | 921 return FRAGMENT_SHADER( |
| 876 precision mediump float; | 922 precision mediump float; |
| 877 precision mediump int; | 923 precision mediump int; |
| 878 varying vec2 v_texCoord; | 924 varying TexCoordPrecisionLow vec2 v_texCoord; |
| 879 uniform float alpha; | 925 uniform float alpha; |
| 880 uniform float frequency; | 926 uniform float frequency; |
| 881 uniform vec4 texTransform; | 927 uniform vec4 texTransform; |
| 882 uniform vec4 color; | 928 uniform vec4 color; |
| 883 void main() | 929 void main() |
| 884 { | 930 { |
| 885 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | 931 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
| 886 vec4 color2 = color; | 932 vec4 color2 = color; |
| 887 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; | 933 TexCoordPrecisionLow vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * t exTransform.zw + texTransform.xy; |
| 888 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 934 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 889 float picker = abs(coord.x - coord.y); | 935 float picker = abs(coord.x - coord.y); |
| 890 gl_FragColor = mix(color1, color2, picker) * alpha; | 936 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 891 } | 937 } |
| 892 ); | 938 ); |
| 893 } | 939 } |
| 894 | 940 |
| 895 } // namespace cc | 941 } // namespace cc |
| OLD | NEW |