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