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 "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" |
| 10 | 10 |
| 11 #define SHADER0(Src) #Src | 11 #define SHADER0(Src) #Src |
| 12 #define SHADER(Src) SHADER0(Src) | 12 #define SHADER(Src) SHADER0(Src) |
| 13 | 13 |
| 14 using WebKit::WebGraphicsContext3D; | 14 using WebKit::WebGraphicsContext3D; |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 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) | 20 static void GetProgramUniformLocations(WebGraphicsContext3D* context, |
| 21 { | 21 unsigned program, |
| 22 for (size_t uniformIndex = 0; uniformIndex < count; uniformIndex ++) { | 22 const char** shader_uniforms, |
| 23 DCHECK(uniformIndex < maxLocations); | 23 size_t count, |
| 24 | 24 size_t max_locations, |
| 25 if (usingBindUniform) { | 25 int* locations, |
| 26 locations[uniformIndex] = (*baseUniformIndex)++; | 26 bool using_bind_uniform, |
| 27 context->bindUniformLocationCHROMIUM(program, locations[uniformIndex ], shaderUniforms[uniformIndex]); | 27 int* base_uniform_index) { |
| 28 } else | 28 for (size_t uniform_index = 0; uniform_index < count; uniform_index ++) { |
| 29 locations[uniformIndex] = context->getUniformLocation(program, shade rUniforms[uniformIndex]); | 29 DCHECK(uniform_index < max_locations); |
| 30 } | 30 |
| 31 if (using_bind_uniform) { | |
| 32 locations[uniform_index] = (*base_uniform_index)++; | |
| 33 context->bindUniformLocationCHROMIUM(program, | |
| 34 locations[uniform_index], | |
| 35 shader_uniforms[uniform_index]); | |
| 36 } else { | |
| 37 locations[uniform_index] = | |
| 38 context->getUniformLocation(program, shader_uniforms[uniform_index]); | |
| 39 } | |
| 40 } | |
| 31 } | 41 } |
| 32 | 42 |
| 33 } | 43 } |
| 34 | 44 |
| 35 VertexShaderPosTex::VertexShaderPosTex() | 45 VertexShaderPosTex::VertexShaderPosTex() |
| 36 : m_matrixLocation(-1) | 46 : matrix_location_(-1) { } |
| 37 { | 47 |
| 38 } | 48 void VertexShaderPosTex::Init(WebGraphicsContext3D* context, |
| 39 | 49 unsigned program, |
| 40 void VertexShaderPosTex::init(WebGraphicsContext3D* context, unsigned program, b ool usingBindUniform, int* baseUniformIndex) | 50 bool using_bind_uniform, |
| 41 { | 51 int* base_uniform_index) { |
| 42 static const char* shaderUniforms[] = { | 52 static const char* shader_uniforms[] = { |
| 43 "matrix", | 53 "matrix", |
| 44 }; | 54 }; |
| 45 int locations[1]; | 55 int locations[1]; |
| 46 | 56 |
| 47 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 57 GetProgramUniformLocations(context, |
| 48 | 58 program, |
| 49 m_matrixLocation = locations[0]; | 59 shader_uniforms, |
| 50 DCHECK(m_matrixLocation != -1); | 60 arraysize(shader_uniforms), |
| 51 } | 61 arraysize(locations), |
| 52 | 62 locations, |
| 53 std::string VertexShaderPosTex::getShaderString() const | 63 using_bind_uniform, |
| 54 { | 64 base_uniform_index); |
|
piman
2013/03/20 07:01:41
note: this is valid style, but you can also do mor
danakj
2013/03/20 16:51:44
We've been following the rule of "put it all on on
| |
| 55 return SHADER( | 65 |
| 56 attribute vec4 a_position; | 66 matrix_location_ = locations[0]; |
| 57 attribute vec2 a_texCoord; | 67 DCHECK(matrix_location_ != -1); |
| 58 uniform mat4 matrix; | 68 } |
| 59 varying vec2 v_texCoord; | 69 |
| 60 void main() | 70 std::string VertexShaderPosTex::GetShaderString() const { |
| 61 { | 71 return SHADER( |
| 62 gl_Position = matrix * a_position; | 72 attribute vec4 a_position; |
| 63 v_texCoord = a_texCoord; | 73 attribute vec2 a_texCoord; |
| 64 } | 74 uniform mat4 matrix; |
| 65 ); | 75 varying vec2 v_texCoord; |
| 76 void main() { | |
| 77 gl_Position = matrix * a_position; | |
| 78 v_texCoord = a_texCoord; | |
| 79 } | |
| 80 ); | |
| 66 } | 81 } |
| 67 | 82 |
| 68 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() | 83 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() |
| 69 : m_matrixLocation(-1) | 84 : matrix_location_(-1) |
| 70 , m_texScaleLocation(-1) | 85 , tex_scale_location_(-1) { } |
|
piman
2013/03/20 07:01:41
nit: chrome style for initializers:
VertexShaderPo
enne (OOO)
2013/03/20 07:40:13
http://go/clang-format will fix this automatically
| |
| 71 { | 86 |
| 72 } | 87 void VertexShaderPosTexYUVStretch::Init(WebGraphicsContext3D* context, |
| 73 | 88 unsigned program, |
| 74 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) | 89 bool using_bind_uniform, |
| 75 { | 90 int* base_uniform_index) { |
| 76 static const char* shaderUniforms[] = { | 91 static const char* shader_uniforms[] = { |
| 77 "matrix", | 92 "matrix", |
| 78 "texScale", | 93 "texScale", |
| 79 }; | 94 }; |
| 80 int locations[2]; | 95 int locations[2]; |
| 81 | 96 |
| 82 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 97 GetProgramUniformLocations(context, |
| 83 | 98 program, |
| 84 m_matrixLocation = locations[0]; | 99 shader_uniforms, |
| 85 m_texScaleLocation = locations[1]; | 100 arraysize(shader_uniforms), |
| 86 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1); | 101 arraysize(locations), |
| 87 } | 102 locations, |
| 88 | 103 using_bind_uniform, |
| 89 std::string VertexShaderPosTexYUVStretch::getShaderString() const | 104 base_uniform_index); |
| 90 { | 105 |
| 91 return SHADER( | 106 matrix_location_ = locations[0]; |
| 92 precision mediump float; | 107 tex_scale_location_ = locations[1]; |
| 93 attribute vec4 a_position; | 108 DCHECK(matrix_location_ != -1 && tex_scale_location_ != -1); |
| 94 attribute vec2 a_texCoord; | 109 } |
| 95 uniform mat4 matrix; | 110 |
| 96 varying vec2 v_texCoord; | 111 std::string VertexShaderPosTexYUVStretch::GetShaderString() const { |
| 97 uniform vec2 texScale; | 112 return SHADER( |
| 98 void main() | 113 precision mediump float; |
| 99 { | 114 attribute vec4 a_position; |
| 100 gl_Position = matrix * a_position; | 115 attribute vec2 a_texCoord; |
| 101 v_texCoord = a_texCoord * texScale; | 116 uniform mat4 matrix; |
| 102 } | 117 varying vec2 v_texCoord; |
| 103 ); | 118 uniform vec2 texScale; |
| 119 void main() { | |
| 120 gl_Position = matrix * a_position; | |
| 121 v_texCoord = a_texCoord * texScale; | |
| 122 } | |
| 123 ); | |
| 104 } | 124 } |
| 105 | 125 |
| 106 VertexShaderPos::VertexShaderPos() | 126 VertexShaderPos::VertexShaderPos() |
| 107 : m_matrixLocation(-1) | 127 : matrix_location_(-1) { } |
| 108 { | 128 |
| 109 } | 129 void VertexShaderPos::Init(WebGraphicsContext3D* context, |
| 110 | 130 unsigned program, |
| 111 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) | 131 bool using_bind_uniform, |
| 112 { | 132 int* base_uniform_index) { |
| 113 static const char* shaderUniforms[] = { | 133 static const char* shader_uniforms[] = { |
| 114 "matrix", | 134 "matrix", |
| 115 }; | 135 }; |
| 116 int locations[1]; | 136 int locations[1]; |
| 117 | 137 |
| 118 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 138 GetProgramUniformLocations(context, |
| 119 | 139 program, |
| 120 m_matrixLocation = locations[0]; | 140 shader_uniforms, |
| 121 DCHECK(m_matrixLocation != -1); | 141 arraysize(shader_uniforms), |
| 122 } | 142 arraysize(locations), |
| 123 | 143 locations, |
| 124 std::string VertexShaderPos::getShaderString() const | 144 using_bind_uniform, |
| 125 { | 145 base_uniform_index); |
| 126 return SHADER( | 146 |
| 127 attribute vec4 a_position; | 147 matrix_location_ = locations[0]; |
| 128 uniform mat4 matrix; | 148 DCHECK(matrix_location_ != -1); |
| 129 void main() | 149 } |
| 130 { | 150 |
| 131 gl_Position = matrix * a_position; | 151 std::string VertexShaderPos::GetShaderString() const { |
| 132 } | 152 return SHADER( |
| 133 ); | 153 attribute vec4 a_position; |
| 154 uniform mat4 matrix; | |
| 155 void main() { | |
| 156 gl_Position = matrix * a_position; | |
| 157 } | |
| 158 ); | |
| 134 } | 159 } |
| 135 | 160 |
| 136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | 161 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
| 137 : m_matrixLocation(-1) | 162 : matrix_location_(-1) |
| 138 , m_texTransformLocation(-1) | 163 , tex_transform_location_(-1) |
| 139 , m_vertexOpacityLocation(-1) | 164 , vertex_opacity_location_(-1) { } |
| 140 { | 165 |
| 141 } | 166 void VertexShaderPosTexTransform::Init(WebGraphicsContext3D* context, |
| 142 | 167 unsigned program, |
| 143 void VertexShaderPosTexTransform::init(WebGraphicsContext3D* context, unsigned p rogram, bool usingBindUniform, int* baseUniformIndex) | 168 bool using_bind_uniform, |
| 144 { | 169 int* base_uniform_index) { |
| 145 static const char* shaderUniforms[] = { | 170 static const char* shader_uniforms[] = { |
| 146 "matrix", | 171 "matrix", |
| 147 "texTransform", | 172 "texTransform", |
| 148 "opacity", | 173 "opacity", |
| 149 }; | 174 }; |
| 150 int locations[3]; | 175 int locations[3]; |
| 151 | 176 |
| 152 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 177 GetProgramUniformLocations(context, |
| 153 | 178 program, |
| 154 m_matrixLocation = locations[0]; | 179 shader_uniforms, |
| 155 m_texTransformLocation = locations[1]; | 180 arraysize(shader_uniforms), |
| 156 m_vertexOpacityLocation = locations[2]; | 181 arraysize(locations), |
| 157 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1); | 182 locations, |
| 158 } | 183 using_bind_uniform, |
| 159 | 184 base_uniform_index); |
| 160 std::string VertexShaderPosTexTransform::getShaderString() const | 185 |
| 161 { | 186 matrix_location_ = locations[0]; |
| 162 return SHADER( | 187 tex_transform_location_ = locations[1]; |
| 163 attribute vec4 a_position; | 188 vertex_opacity_location_ = locations[2]; |
| 164 attribute vec2 a_texCoord; | 189 DCHECK(matrix_location_ != -1 && tex_transform_location_ != -1 && |
| 165 attribute float a_index; | 190 vertex_opacity_location_ != -1); |
| 166 uniform mat4 matrix[8]; | 191 } |
| 167 uniform vec4 texTransform[8]; | 192 |
| 168 uniform float opacity[32]; | 193 std::string VertexShaderPosTexTransform::GetShaderString() const { |
| 169 varying vec2 v_texCoord; | 194 return SHADER( |
| 170 varying float v_alpha; | 195 attribute vec4 a_position; |
| 171 void main() | 196 attribute vec2 a_texCoord; |
| 172 { | 197 attribute float a_index; |
| 173 gl_Position = matrix[int(a_index * 0.25)] * a_position; | 198 uniform mat4 matrix[8]; |
| 174 vec4 texTrans = texTransform[int(a_index * 0.25)]; | 199 uniform vec4 texTransform[8]; |
| 175 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 200 uniform float opacity[32]; |
| 176 v_alpha = opacity[int(a_index)]; | 201 varying vec2 v_texCoord; |
| 177 } | 202 varying float v_alpha; |
| 178 ); | 203 void main() { |
| 179 } | 204 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
| 180 | 205 vec4 texTrans = texTransform[int(a_index * 0.25)]; |
| 181 std::string VertexShaderPosTexTransformFlip::getShaderString() const | 206 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 182 { | 207 v_alpha = opacity[int(a_index)]; |
| 183 return SHADER( | 208 } |
| 184 attribute vec4 a_position; | 209 ); |
| 185 attribute vec2 a_texCoord; | 210 } |
| 186 attribute float a_index; | 211 |
| 187 uniform mat4 matrix[8]; | 212 std::string VertexShaderPosTexTransformFlip::GetShaderString() const { |
| 188 uniform vec4 texTransform[8]; | 213 return SHADER( |
| 189 uniform float opacity[32]; | 214 attribute vec4 a_position; |
| 190 varying vec2 v_texCoord; | 215 attribute vec2 a_texCoord; |
| 191 varying float v_alpha; | 216 attribute float a_index; |
| 192 void main() | 217 uniform mat4 matrix[8]; |
| 193 { | 218 uniform vec4 texTransform[8]; |
| 194 gl_Position = matrix[int(a_index * 0.25)] * a_position; | 219 uniform float opacity[32]; |
| 195 vec4 texTrans = texTransform[int(a_index * 0.25)]; | 220 varying vec2 v_texCoord; |
| 196 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 221 varying float v_alpha; |
| 197 v_texCoord.y = 1.0 - v_texCoord.y; | 222 void main() { |
| 198 v_alpha = opacity[int(a_index)]; | 223 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
| 199 } | 224 vec4 texTrans = texTransform[int(a_index * 0.25)]; |
| 200 ); | 225 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 201 } | 226 v_texCoord.y = 1.0 - v_texCoord.y; |
| 202 | 227 v_alpha = opacity[int(a_index)]; |
| 203 std::string VertexShaderPosTexIdentity::getShaderString() const | 228 } |
| 204 { | 229 ); |
| 205 return SHADER( | 230 } |
| 206 attribute vec4 a_position; | 231 |
| 207 varying vec2 v_texCoord; | 232 std::string VertexShaderPosTexIdentity::GetShaderString() const { |
| 208 void main() | 233 return SHADER( |
| 209 { | 234 attribute vec4 a_position; |
| 210 gl_Position = a_position; | 235 varying vec2 v_texCoord; |
| 211 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 236 void main() { |
| 212 } | 237 gl_Position = a_position; |
| 213 ); | 238 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
| 239 } | |
| 240 ); | |
| 214 } | 241 } |
| 215 | 242 |
| 216 VertexShaderQuad::VertexShaderQuad() | 243 VertexShaderQuad::VertexShaderQuad() |
| 217 : m_matrixLocation(-1) | 244 : matrix_location_(-1) |
| 218 , m_pointLocation(-1) | 245 , point_location_(-1) |
| 219 , m_texScaleLocation(-1) | 246 , tex_scale_location_(-1) { } |
| 220 { | 247 |
| 221 } | 248 void VertexShaderQuad::Init(WebGraphicsContext3D* context, |
| 222 | 249 unsigned program, |
| 223 void VertexShaderQuad::init(WebGraphicsContext3D* context, unsigned program, boo l usingBindUniform, int* baseUniformIndex) | 250 bool using_bind_uniform, |
| 224 { | 251 int* base_uniform_index) { |
| 225 static const char* shaderUniforms[] = { | 252 static const char* shader_uniforms[] = { |
| 226 "matrix", | 253 "matrix", |
| 227 "point", | 254 "point", |
| 228 "texScale", | 255 "texScale", |
| 229 }; | 256 }; |
| 230 int locations[3]; | 257 int locations[3]; |
| 231 | 258 |
| 232 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 259 GetProgramUniformLocations(context, |
| 233 | 260 program, |
| 234 m_matrixLocation = locations[0]; | 261 shader_uniforms, |
| 235 m_pointLocation = locations[1]; | 262 arraysize(shader_uniforms), |
| 236 m_texScaleLocation = locations[2]; | 263 arraysize(locations), |
| 237 DCHECK_NE(m_matrixLocation, -1); | 264 locations, |
| 238 DCHECK_NE(m_pointLocation, -1); | 265 using_bind_uniform, |
| 239 DCHECK_NE(m_texScaleLocation, -1); | 266 base_uniform_index); |
| 240 } | 267 |
| 241 | 268 matrix_location_ = locations[0]; |
| 242 std::string VertexShaderQuad::getShaderString() const | 269 point_location_ = locations[1]; |
| 243 { | 270 tex_scale_location_ = locations[2]; |
| 244 return SHADER( | 271 DCHECK_NE(matrix_location_, -1); |
| 245 attribute vec4 a_position; | 272 DCHECK_NE(point_location_, -1); |
| 246 attribute vec2 a_texCoord; | 273 DCHECK_NE(tex_scale_location_, -1); |
| 247 uniform mat4 matrix; | 274 } |
| 248 uniform vec2 point[4]; | 275 |
| 249 uniform vec2 texScale; | 276 std::string VertexShaderQuad::GetShaderString() const { |
| 250 varying vec2 v_texCoord; | 277 return SHADER( |
| 251 void main() | 278 attribute vec4 a_position; |
| 252 { | 279 attribute vec2 a_texCoord; |
| 253 vec2 complement = abs(a_texCoord - 1.0); | 280 uniform mat4 matrix; |
| 254 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 281 uniform vec2 point[4]; |
| 255 pos.xy += (complement.x * complement.y) * point[0]; | 282 uniform vec2 texScale; |
| 256 pos.xy += (a_texCoord.x * complement.y) * point[1]; | 283 varying vec2 v_texCoord; |
| 257 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | 284 void main() { |
| 258 pos.xy += (complement.x * a_texCoord.y) * point[3]; | 285 vec2 complement = abs(a_texCoord - 1.0); |
| 259 gl_Position = matrix * pos; | 286 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 260 v_texCoord = (pos.xy + vec2(0.5)) * texScale; | 287 pos.xy += (complement.x * complement.y) * point[0]; |
| 261 } | 288 pos.xy += (a_texCoord.x * complement.y) * point[1]; |
| 262 ); | 289 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; |
| 290 pos.xy += (complement.x * a_texCoord.y) * point[3]; | |
| 291 gl_Position = matrix * pos; | |
| 292 v_texCoord = (pos.xy + vec2(0.5)) * texScale; | |
| 293 } | |
| 294 ); | |
| 263 } | 295 } |
| 264 | 296 |
| 265 VertexShaderTile::VertexShaderTile() | 297 VertexShaderTile::VertexShaderTile() |
| 266 : m_matrixLocation(-1) | 298 : matrix_location_(-1) |
| 267 , m_pointLocation(-1) | 299 , point_location_(-1) |
| 268 , m_vertexTexTransformLocation(-1) | 300 , vertex_tex_transform_location_(-1) { } |
| 269 { | 301 |
| 270 } | 302 void VertexShaderTile::Init(WebGraphicsContext3D* context, |
| 271 | 303 unsigned program, |
| 272 void VertexShaderTile::init(WebGraphicsContext3D* context, unsigned program, boo l usingBindUniform, int* baseUniformIndex) | 304 bool using_bind_uniform, |
| 273 { | 305 int* base_uniform_index) { |
| 274 static const char* shaderUniforms[] = { | 306 static const char* shader_uniforms[] = { |
| 275 "matrix", | 307 "matrix", |
| 276 "point", | 308 "point", |
| 277 "vertexTexTransform", | 309 "vertexTexTransform", |
| 278 }; | 310 }; |
| 279 int locations[3]; | 311 int locations[3]; |
| 280 | 312 |
| 281 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 313 GetProgramUniformLocations(context, |
| 282 | 314 program, |
| 283 m_matrixLocation = locations[0]; | 315 shader_uniforms, |
| 284 m_pointLocation = locations[1]; | 316 arraysize(shader_uniforms), |
| 285 m_vertexTexTransformLocation = locations[2]; | 317 arraysize(locations), |
| 286 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1); | 318 locations, |
| 287 } | 319 using_bind_uniform, |
| 288 | 320 base_uniform_index); |
| 289 std::string VertexShaderTile::getShaderString() const | 321 |
| 290 { | 322 matrix_location_ = locations[0]; |
| 291 return SHADER( | 323 point_location_ = locations[1]; |
| 292 attribute vec4 a_position; | 324 vertex_tex_transform_location_ = locations[2]; |
| 293 attribute vec2 a_texCoord; | 325 DCHECK(matrix_location_ != -1 && point_location_ != -1 && |
| 294 uniform mat4 matrix; | 326 vertex_tex_transform_location_ != -1); |
| 295 uniform vec2 point[4]; | 327 } |
| 296 uniform vec4 vertexTexTransform; | 328 |
| 297 varying vec2 v_texCoord; | 329 std::string VertexShaderTile::GetShaderString() const { |
| 298 void main() | 330 return SHADER( |
| 299 { | 331 attribute vec4 a_position; |
| 300 vec2 complement = abs(a_texCoord - 1.0); | 332 attribute vec2 a_texCoord; |
| 301 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 333 uniform mat4 matrix; |
| 302 pos.xy += (complement.x * complement.y) * point[0]; | 334 uniform vec2 point[4]; |
| 303 pos.xy += (a_texCoord.x * complement.y) * point[1]; | 335 uniform vec4 vertexTexTransform; |
| 304 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | 336 varying vec2 v_texCoord; |
| 305 pos.xy += (complement.x * a_texCoord.y) * point[3]; | 337 void main() { |
| 306 gl_Position = matrix * pos; | 338 vec2 complement = abs(a_texCoord - 1.0); |
| 307 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | 339 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 308 } | 340 pos.xy += (complement.x * complement.y) * point[0]; |
| 309 ); | 341 pos.xy += (a_texCoord.x * complement.y) * point[1]; |
| 342 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | |
| 343 pos.xy += (complement.x * a_texCoord.y) * point[3]; | |
| 344 gl_Position = matrix * pos; | |
| 345 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | |
| 346 } | |
| 347 ); | |
| 310 } | 348 } |
| 311 | 349 |
| 312 VertexShaderVideoTransform::VertexShaderVideoTransform() | 350 VertexShaderVideoTransform::VertexShaderVideoTransform() |
| 313 : m_matrixLocation(-1) | 351 : matrix_location_(-1) |
| 314 , m_texMatrixLocation(-1) | 352 , tex_matrix_location_(-1) { } |
| 315 { | 353 |
| 316 } | 354 bool VertexShaderVideoTransform::Init(WebGraphicsContext3D* context, |
| 317 | 355 unsigned program, |
| 318 bool VertexShaderVideoTransform::init(WebGraphicsContext3D* context, unsigned pr ogram, bool usingBindUniform, int* baseUniformIndex) | 356 bool using_bind_uniform, |
| 319 { | 357 int* base_uniform_index) { |
| 320 static const char* shaderUniforms[] = { | 358 static const char* shader_uniforms[] = { |
| 321 "matrix", | 359 "matrix", |
| 322 "texMatrix", | 360 "texMatrix", |
| 323 }; | 361 }; |
| 324 int locations[2]; | 362 int locations[2]; |
| 325 | 363 |
| 326 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 364 GetProgramUniformLocations(context, |
| 327 | 365 program, |
| 328 m_matrixLocation = locations[0]; | 366 shader_uniforms, |
| 329 m_texMatrixLocation = locations[1]; | 367 arraysize(shader_uniforms), |
| 330 return m_matrixLocation != -1 && m_texMatrixLocation != -1; | 368 arraysize(locations), |
| 331 } | 369 locations, |
| 332 | 370 using_bind_uniform, |
| 333 std::string VertexShaderVideoTransform::getShaderString() const | 371 base_uniform_index); |
| 334 { | 372 |
| 335 return SHADER( | 373 matrix_location_ = locations[0]; |
| 336 attribute vec4 a_position; | 374 tex_matrix_location_ = locations[1]; |
| 337 attribute vec2 a_texCoord; | 375 return matrix_location_ != -1 && tex_matrix_location_ != -1; |
| 338 uniform mat4 matrix; | 376 } |
| 339 uniform mat4 texMatrix; | 377 |
| 340 varying vec2 v_texCoord; | 378 std::string VertexShaderVideoTransform::GetShaderString() const { |
| 341 void main() | 379 return SHADER( |
| 342 { | 380 attribute vec4 a_position; |
| 343 gl_Position = matrix * a_position; | 381 attribute vec2 a_texCoord; |
| 344 v_texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 382 uniform mat4 matrix; |
| 345 } | 383 uniform mat4 texMatrix; |
| 346 ); | 384 varying vec2 v_texCoord; |
| 385 void main() { | |
| 386 gl_Position = matrix * a_position; | |
| 387 v_texCoord = | |
| 388 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | |
| 389 } | |
| 390 ); | |
| 347 } | 391 } |
| 348 | 392 |
| 349 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | 393 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
| 350 : m_samplerLocation(-1) | 394 : sampler_location_(-1) |
| 351 , m_alphaLocation(-1) | 395 , alpha_location_(-1) { } |
| 352 { | 396 |
| 353 } | 397 void FragmentTexAlphaBinding::Init(WebGraphicsContext3D* context, |
| 354 | 398 unsigned program, |
| 355 void FragmentTexAlphaBinding::init(WebGraphicsContext3D* context, unsigned progr am, bool usingBindUniform, int* baseUniformIndex) | 399 bool using_bind_uniform, |
| 356 { | 400 int* base_uniform_index) { |
| 357 static const char* shaderUniforms[] = { | 401 static const char* shader_uniforms[] = { |
| 358 "s_texture", | 402 "s_texture", |
| 359 "alpha", | 403 "alpha", |
| 360 }; | 404 }; |
| 361 int locations[2]; | 405 int locations[2]; |
| 362 | 406 |
| 363 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 407 GetProgramUniformLocations(context, |
| 364 | 408 program, |
| 365 m_samplerLocation = locations[0]; | 409 shader_uniforms, |
| 366 m_alphaLocation = locations[1]; | 410 arraysize(shader_uniforms), |
| 367 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1); | 411 arraysize(locations), |
| 412 locations, | |
| 413 using_bind_uniform, | |
| 414 base_uniform_index); | |
| 415 | |
| 416 sampler_location_ = locations[0]; | |
| 417 alpha_location_ = locations[1]; | |
| 418 DCHECK(sampler_location_ != -1 && alpha_location_ != -1); | |
| 368 } | 419 } |
| 369 | 420 |
| 370 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() | 421 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() |
| 371 : m_samplerLocation(-1) | 422 : sampler_location_(-1) { } |
| 372 { | 423 |
| 373 } | 424 void FragmentTexOpaqueBinding::Init(WebGraphicsContext3D* context, |
| 374 | 425 unsigned program, |
| 375 void FragmentTexOpaqueBinding::init(WebGraphicsContext3D* context, unsigned prog ram, bool usingBindUniform, int* baseUniformIndex) | 426 bool using_bind_uniform, |
| 376 { | 427 int* base_uniform_index) { |
| 377 static const char* shaderUniforms[] = { | 428 static const char* shader_uniforms[] = { |
| 378 "s_texture", | 429 "s_texture", |
| 379 }; | 430 }; |
| 380 int locations[1]; | 431 int locations[1]; |
| 381 | 432 |
| 382 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 433 GetProgramUniformLocations(context, |
| 383 | 434 program, |
| 384 m_samplerLocation = locations[0]; | 435 shader_uniforms, |
| 385 DCHECK(m_samplerLocation != -1); | 436 arraysize(shader_uniforms), |
| 386 } | 437 arraysize(locations), |
| 387 | 438 locations, |
| 388 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne d program, bool usingBindUniform, int* baseUniformIndex) | 439 using_bind_uniform, |
| 389 { | 440 base_uniform_index); |
| 390 static const char* shaderUniforms[] = { | 441 |
| 391 "s_texture", | 442 sampler_location_ = locations[0]; |
| 392 }; | 443 DCHECK(sampler_location_ != -1); |
| 393 int locations[1]; | 444 } |
| 394 | 445 |
| 395 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 446 bool FragmentShaderOESImageExternal::Init(WebGraphicsContext3D* context, |
| 396 | 447 unsigned program, |
| 397 m_samplerLocation = locations[0]; | 448 bool using_bind_uniform, |
| 398 return m_samplerLocation != -1; | 449 int* base_uniform_index) { |
| 399 } | 450 static const char* shader_uniforms[] = { |
| 400 | 451 "s_texture", |
| 401 std::string FragmentShaderOESImageExternal::getShaderString() const | 452 }; |
| 402 { | 453 int locations[1]; |
| 403 // Cannot use the SHADER() macro because of the '#' char | 454 |
| 404 return "#extension GL_OES_EGL_image_external : require \n" | 455 GetProgramUniformLocations(context, |
| 405 "precision mediump float;\n" | 456 program, |
| 406 "varying vec2 v_texCoord;\n" | 457 shader_uniforms, |
| 407 "uniform samplerExternalOES s_texture;\n" | 458 arraysize(shader_uniforms), |
| 408 "void main()\n" | 459 arraysize(locations), |
| 409 "{\n" | 460 locations, |
| 410 " vec4 texColor = texture2D(s_texture, v_texCoord);\n" | 461 using_bind_uniform, |
| 411 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor .w);\n" | 462 base_uniform_index); |
| 412 "}\n"; | 463 |
| 413 } | 464 sampler_location_ = locations[0]; |
| 414 | 465 return sampler_location_ != -1; |
| 415 std::string FragmentShaderRGBATexAlpha::getShaderString() const | 466 } |
| 416 { | 467 |
| 417 return SHADER( | 468 std::string FragmentShaderOESImageExternal::GetShaderString() const { |
| 418 precision mediump float; | 469 // Cannot use the SHADER() macro because of the '#' char |
| 419 varying vec2 v_texCoord; | 470 return "#extension GL_OES_EGL_image_external : require\n" |
| 420 uniform sampler2D s_texture; | 471 SHADER( |
| 421 uniform float alpha; | 472 precision mediump float; |
| 422 void main() | 473 varying vec2 v_texCoord; |
| 423 { | 474 uniform samplerExternalOES s_texture; |
| 424 vec4 texColor = texture2D(s_texture, v_texCoord); | 475 void main() { |
| 425 gl_FragColor = texColor * alpha; | 476 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 426 } | 477 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w); |
| 427 ); | 478 } |
| 428 } | 479 ); |
| 429 | 480 } |
| 430 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const | 481 |
| 431 { | 482 std::string FragmentShaderRGBATexAlpha::GetShaderString() const { |
| 432 return SHADER( | 483 return SHADER( |
| 484 precision mediump float; | |
| 485 varying vec2 v_texCoord; | |
| 486 uniform sampler2D s_texture; | |
| 487 uniform float alpha; | |
| 488 void main() { | |
| 489 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 490 gl_FragColor = texColor * alpha; | |
| 491 } | |
| 492 ); | |
| 493 } | |
| 494 | |
| 495 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString() const { | |
| 496 return SHADER( | |
| 497 precision mediump float; | |
| 498 varying vec2 v_texCoord; | |
| 499 varying float v_alpha; | |
| 500 uniform sampler2D s_texture; | |
| 501 void main() { | |
| 502 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 503 gl_FragColor = texColor * v_alpha; | |
| 504 } | |
| 505 ); | |
| 506 } | |
| 507 | |
| 508 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString() const { | |
| 509 return "#extension GL_ARB_texture_rectangle : require\n" | |
| 510 SHADER( | |
| 433 precision mediump float; | 511 precision mediump float; |
| 434 varying vec2 v_texCoord; | 512 varying vec2 v_texCoord; |
| 435 varying float v_alpha; | 513 varying float v_alpha; |
| 436 uniform sampler2D s_texture; | 514 uniform sampler2DRect s_texture; |
| 437 void main() | 515 void main() { |
| 438 { | 516 vec4 texColor = texture2DRect(s_texture, v_texCoord); |
| 439 vec4 texColor = texture2D(s_texture, v_texCoord); | 517 gl_FragColor = texColor * v_alpha; |
| 440 gl_FragColor = texColor * v_alpha; | |
| 441 } | 518 } |
| 442 ); | 519 ); |
| 443 } | 520 } |
| 444 | 521 |
| 445 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const | 522 std::string FragmentShaderRGBATexOpaque::GetShaderString() const { |
| 446 { | 523 return SHADER( |
| 447 return "#extension GL_ARB_texture_rectangle : require\n" | 524 precision mediump float; |
| 448 "precision mediump float;\n" | 525 varying vec2 v_texCoord; |
| 449 "varying vec2 v_texCoord;\n" | 526 uniform sampler2D s_texture; |
| 450 "varying float v_alpha;\n" | 527 void main() { |
| 451 "uniform sampler2DRect s_texture;\n" | 528 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 452 "void main()\n" | 529 gl_FragColor = vec4(texColor.rgb, 1.0); |
| 453 "{\n" | 530 } |
| 454 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | 531 ); |
| 455 " gl_FragColor = texColor * v_alpha;\n" | 532 } |
| 456 "}\n"; | 533 |
| 457 } | 534 std::string FragmentShaderRGBATex::GetShaderString() const { |
| 458 | 535 return SHADER( |
| 459 std::string FragmentShaderRGBATexOpaque::getShaderString() const | 536 precision mediump float; |
| 460 { | 537 varying vec2 v_texCoord; |
| 461 return SHADER( | 538 uniform sampler2D s_texture; |
| 462 precision mediump float; | 539 void main() { |
| 463 varying vec2 v_texCoord; | 540 gl_FragColor = texture2D(s_texture, v_texCoord); |
| 464 uniform sampler2D s_texture; | 541 } |
| 465 void main() | 542 ); |
| 466 { | 543 } |
| 467 vec4 texColor = texture2D(s_texture, v_texCoord); | 544 |
| 468 gl_FragColor = vec4(texColor.rgb, 1.0); | 545 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString() const { |
| 469 } | 546 return SHADER( |
| 470 ); | 547 precision mediump float; |
| 471 } | 548 varying vec2 v_texCoord; |
| 472 | 549 uniform sampler2D s_texture; |
| 473 std::string FragmentShaderRGBATex::getShaderString() const | 550 uniform float alpha; |
| 474 { | 551 void main() { |
| 475 return SHADER( | 552 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 476 precision mediump float; | 553 gl_FragColor = |
| 477 varying vec2 v_texCoord; | 554 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; |
| 478 uniform sampler2D s_texture; | 555 } |
| 479 void main() | 556 ); |
| 480 { | 557 } |
| 481 gl_FragColor = texture2D(s_texture, v_texCoord); | 558 |
| 482 } | 559 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString() const { |
| 483 ); | 560 return SHADER( |
| 484 } | 561 precision mediump float; |
| 485 | 562 varying vec2 v_texCoord; |
| 486 std::string FragmentShaderRGBATexSwizzleAlpha::getShaderString() const | 563 uniform sampler2D s_texture; |
| 487 { | 564 void main() { |
| 488 return SHADER( | 565 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 489 precision mediump float; | 566 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
| 490 varying vec2 v_texCoord; | 567 } |
| 491 uniform sampler2D s_texture; | 568 ); |
| 492 uniform float alpha; | |
| 493 void main() | |
| 494 { | |
| 495 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 496 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; | |
| 497 } | |
| 498 ); | |
| 499 } | |
| 500 | |
| 501 std::string FragmentShaderRGBATexSwizzleOpaque::getShaderString() const | |
| 502 { | |
| 503 return SHADER( | |
| 504 precision mediump float; | |
| 505 varying vec2 v_texCoord; | |
| 506 uniform sampler2D s_texture; | |
| 507 void main() | |
| 508 { | |
| 509 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 510 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | |
| 511 } | |
| 512 ); | |
| 513 } | 569 } |
| 514 | 570 |
| 515 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 571 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
| 516 : m_samplerLocation(-1) | 572 : sampler_location_(-1) |
| 517 , m_alphaLocation(-1) | 573 , alpha_location_(-1) |
| 518 , m_edgeLocation(-1) | 574 , edge_location_(-1) { } |
| 519 { | 575 |
| 520 } | 576 void FragmentShaderRGBATexAlphaAA::Init(WebGraphicsContext3D* context, |
| 521 | 577 unsigned program, |
| 522 void FragmentShaderRGBATexAlphaAA::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) | 578 bool using_bind_uniform, |
| 523 { | 579 int* base_uniform_index) { |
| 524 static const char* shaderUniforms[] = { | 580 static const char* shader_uniforms[] = { |
| 525 "s_texture", | 581 "s_texture", |
| 526 "alpha", | 582 "alpha", |
| 527 "edge", | 583 "edge", |
| 528 }; | 584 }; |
| 529 int locations[3]; | 585 int locations[3]; |
| 530 | 586 |
| 531 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 587 GetProgramUniformLocations(context, |
| 532 | 588 program, |
| 533 m_samplerLocation = locations[0]; | 589 shader_uniforms, |
| 534 m_alphaLocation = locations[1]; | 590 arraysize(shader_uniforms), |
| 535 m_edgeLocation = locations[2]; | 591 arraysize(locations), |
| 536 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_edgeLocation != -1); | 592 locations, |
| 537 } | 593 using_bind_uniform, |
| 538 | 594 base_uniform_index); |
| 539 std::string FragmentShaderRGBATexAlphaAA::getShaderString() const | 595 |
| 540 { | 596 sampler_location_ = locations[0]; |
| 541 return SHADER( | 597 alpha_location_ = locations[1]; |
| 542 precision mediump float; | 598 edge_location_ = locations[2]; |
| 543 varying vec2 v_texCoord; | 599 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && |
| 544 uniform sampler2D s_texture; | 600 edge_location_ != -1); |
| 545 uniform float alpha; | 601 } |
| 546 uniform vec3 edge[8]; | 602 |
| 547 void main() | 603 std::string FragmentShaderRGBATexAlphaAA::GetShaderString() const { |
| 548 { | 604 return SHADER( |
| 549 vec4 texColor = texture2D(s_texture, v_texCoord); | 605 precision mediump float; |
| 550 vec3 pos = vec3(gl_FragCoord.xy, 1); | 606 varying vec2 v_texCoord; |
| 551 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 607 uniform sampler2D s_texture; |
| 552 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 608 uniform float alpha; |
| 553 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 609 uniform vec3 edge[8]; |
| 554 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 610 void main() { |
| 555 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 611 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 556 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 612 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 557 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 613 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 558 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 614 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 559 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min (a4, a6) * min(a5, a7)); | 615 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 560 } | 616 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 561 ); | 617 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 618 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
| 619 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
| 620 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
| 621 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), | |
| 622 min(a4, a6) * min(a5, a7)); | |
| 623 } | |
| 624 ); | |
| 562 } | 625 } |
| 563 | 626 |
| 564 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() | 627 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() |
| 565 : m_samplerLocation(-1) | 628 : sampler_location_(-1) |
| 566 , m_alphaLocation(-1) | 629 , alpha_location_(-1) |
| 567 , m_fragmentTexTransformLocation(-1) | 630 , fragment_tex_transform_location_(-1) |
| 568 , m_edgeLocation(-1) | 631 , edge_location_(-1) { } |
| 569 { | 632 |
| 570 } | 633 void FragmentTexClampAlphaAABinding::Init(WebGraphicsContext3D* context, |
| 571 | 634 unsigned program, |
| 572 void FragmentTexClampAlphaAABinding::init(WebGraphicsContext3D* context, unsigne d program, bool usingBindUniform, int* baseUniformIndex) | 635 bool using_bind_uniform, |
| 573 { | 636 int* base_uniform_index) { |
| 574 static const char* shaderUniforms[] = { | 637 static const char* shader_uniforms[] = { |
| 575 "s_texture", | 638 "s_texture", |
| 576 "alpha", | 639 "alpha", |
| 577 "fragmentTexTransform", | 640 "fragmentTexTransform", |
| 578 "edge", | 641 "edge", |
| 579 }; | 642 }; |
| 580 int locations[4]; | 643 int locations[4]; |
| 581 | 644 |
| 582 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 645 GetProgramUniformLocations(context, |
| 583 | 646 program, |
| 584 m_samplerLocation = locations[0]; | 647 shader_uniforms, |
| 585 m_alphaLocation = locations[1]; | 648 arraysize(shader_uniforms), |
| 586 m_fragmentTexTransformLocation = locations[2]; | 649 arraysize(locations), |
| 587 m_edgeLocation = locations[3]; | 650 locations, |
| 588 DCHECK(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1); | 651 using_bind_uniform, |
| 589 } | 652 base_uniform_index); |
| 590 | 653 |
| 591 std::string FragmentShaderRGBATexClampAlphaAA::getShaderString() const | 654 sampler_location_ = locations[0]; |
| 592 { | 655 alpha_location_ = locations[1]; |
| 593 return SHADER( | 656 fragment_tex_transform_location_ = locations[2]; |
| 594 precision mediump float; | 657 edge_location_ = locations[3]; |
| 595 varying vec2 v_texCoord; | 658 DCHECK(sampler_location_ != -1 && alpha_location_ != -1 && |
| 596 uniform sampler2D s_texture; | 659 fragment_tex_transform_location_ != -1 && edge_location_ != -1); |
| 597 uniform float alpha; | 660 } |
| 598 uniform vec4 fragmentTexTransform; | 661 |
| 599 uniform vec3 edge[8]; | 662 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString() const { |
| 600 void main() | 663 return SHADER( |
| 601 { | 664 precision mediump float; |
| 602 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy; | 665 varying vec2 v_texCoord; |
| 603 vec4 texColor = texture2D(s_texture, texCoord); | 666 uniform sampler2D s_texture; |
| 604 vec3 pos = vec3(gl_FragCoord.xy, 1); | 667 uniform float alpha; |
| 605 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 668 uniform vec4 fragmentTexTransform; |
| 606 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 669 uniform vec3 edge[8]; |
| 607 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 670 void main() { |
| 608 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 671 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
| 609 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 672 fragmentTexTransform.xy; |
| 610 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 673 vec4 texColor = texture2D(s_texture, texCoord); |
| 611 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 674 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 612 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 675 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 613 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), min (a4, a6) * min(a5, a7)); | 676 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 614 } | 677 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 615 ); | 678 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 616 } | 679 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 617 | 680 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 618 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::getShaderString() const | 681 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); |
| 619 { | 682 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); |
| 620 return SHADER( | 683 gl_FragColor = texColor * alpha * min(min(a0, a2) * min(a1, a3), |
| 621 precision mediump float; | 684 min(a4, a6) * min(a5, a7)); |
| 622 varying vec2 v_texCoord; | 685 } |
| 623 uniform sampler2D s_texture; | 686 ); |
| 624 uniform float alpha; | 687 } |
| 625 uniform vec4 fragmentTexTransform; | 688 |
| 626 uniform vec3 edge[8]; | 689 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString() const { |
| 627 void main() | 690 return SHADER( |
| 628 { | 691 precision mediump float; |
| 629 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy; | 692 varying vec2 v_texCoord; |
| 630 vec4 texColor = texture2D(s_texture, texCoord); | 693 uniform sampler2D s_texture; |
| 631 vec3 pos = vec3(gl_FragCoord.xy, 1); | 694 uniform float alpha; |
| 632 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 695 uniform vec4 fragmentTexTransform; |
| 633 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 696 uniform vec3 edge[8]; |
| 634 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 697 void main() { |
| 635 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 698 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
| 636 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 699 fragmentTexTransform.xy; |
| 637 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 700 vec4 texColor = texture2D(s_texture, texCoord); |
| 638 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 701 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 639 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 702 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 640 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * min(min(a0, a2) * min(a1, a3), min(a4, a6) * min(a5, a7)); | 703 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 641 } | 704 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 642 ); | 705 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 706 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
| 707 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
| 708 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
| 709 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
| 710 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * | |
| 711 alpha * min(min(a0, a2) * min(a1, a3), min(a4, a6) * min(a5, a7)); | |
| 712 } | |
| 713 ); | |
| 643 } | 714 } |
| 644 | 715 |
| 645 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() | 716 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() |
| 646 : m_samplerLocation(-1) | 717 : sampler_location_(-1) |
| 647 , m_maskSamplerLocation(-1) | 718 , mask_sampler_location_(-1) |
| 648 , m_alphaLocation(-1) | 719 , alpha_location_(-1) |
| 649 , m_maskTexCoordScaleLocation(-1) | 720 , mask_tex_coord_scale_location_(-1) { } |
| 650 { | 721 |
| 651 } | 722 void FragmentShaderRGBATexAlphaMask::Init(WebGraphicsContext3D* context, |
| 652 | 723 unsigned program, |
| 653 void FragmentShaderRGBATexAlphaMask::init(WebGraphicsContext3D* context, unsigne d program, bool usingBindUniform, int* baseUniformIndex) | 724 bool using_bind_uniform, |
| 654 { | 725 int* base_uniform_index) { |
| 655 static const char* shaderUniforms[] = { | 726 static const char* shader_uniforms[] = { |
| 656 "s_texture", | 727 "s_texture", |
| 657 "s_mask", | 728 "s_mask", |
| 658 "alpha", | 729 "alpha", |
| 659 "maskTexCoordScale", | 730 "maskTexCoordScale", |
| 660 "maskTexCoordOffset", | 731 "maskTexCoordOffset", |
| 661 }; | 732 }; |
| 662 int locations[5]; | 733 int locations[5]; |
| 663 | 734 |
| 664 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 735 GetProgramUniformLocations(context, |
| 665 | 736 program, |
| 666 m_samplerLocation = locations[0]; | 737 shader_uniforms, |
| 667 m_maskSamplerLocation = locations[1]; | 738 arraysize(shader_uniforms), |
| 668 m_alphaLocation = locations[2]; | 739 arraysize(locations), |
| 669 m_maskTexCoordScaleLocation = locations[3]; | 740 locations, |
| 670 m_maskTexCoordOffsetLocation = locations[4]; | 741 using_bind_uniform, |
| 671 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1); | 742 base_uniform_index); |
| 672 } | 743 |
| 673 | 744 sampler_location_ = locations[0]; |
| 674 std::string FragmentShaderRGBATexAlphaMask::getShaderString() const | 745 mask_sampler_location_ = locations[1]; |
| 675 { | 746 alpha_location_ = locations[2]; |
| 676 return SHADER( | 747 mask_tex_coord_scale_location_ = locations[3]; |
| 677 precision mediump float; | 748 mask_tex_coord_offset_location_ = locations[4]; |
| 678 varying vec2 v_texCoord; | 749 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && |
| 679 uniform sampler2D s_texture; | 750 alpha_location_ != -1); |
| 680 uniform sampler2D s_mask; | 751 } |
| 681 uniform vec2 maskTexCoordScale; | 752 |
| 682 uniform vec2 maskTexCoordOffset; | 753 std::string FragmentShaderRGBATexAlphaMask::GetShaderString() const { |
| 683 uniform float alpha; | 754 return SHADER( |
| 684 void main() | 755 precision mediump float; |
| 685 { | 756 varying vec2 v_texCoord; |
| 686 vec4 texColor = texture2D(s_texture, v_texCoord); | 757 uniform sampler2D s_texture; |
| 687 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 758 uniform sampler2D s_mask; |
| 688 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 759 uniform vec2 maskTexCoordScale; |
| 689 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w; | 760 uniform vec2 maskTexCoordOffset; |
| 690 } | 761 uniform float alpha; |
| 691 ); | 762 void main() { |
| 763 vec4 texColor = texture2D(s_texture, v_texCoord); | |
| 764 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * | |
| 765 maskTexCoordScale.x, | |
| 766 maskTexCoordOffset.y + v_texCoord.y * | |
| 767 maskTexCoordScale.y); | |
|
piman
2013/03/20 07:01:41
I think it's a bit more readable / less confusing
| |
| 768 vec4 maskColor = texture2D(s_mask, maskTexCoord); | |
| 769 gl_FragColor = vec4(texColor.x, texColor.y, | |
| 770 texColor.z, texColor.w) * alpha * maskColor.w; | |
| 771 } | |
| 772 ); | |
| 692 } | 773 } |
| 693 | 774 |
| 694 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 775 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
| 695 : m_samplerLocation(-1) | 776 : sampler_location_(-1) |
| 696 , m_maskSamplerLocation(-1) | 777 , mask_sampler_location_(-1) |
| 697 , m_alphaLocation(-1) | 778 , alpha_location_(-1) |
| 698 , m_edgeLocation(-1) | 779 , edge_location_(-1) |
| 699 , m_maskTexCoordScaleLocation(-1) | 780 , mask_tex_coord_scale_location_(-1) { } |
| 700 { | 781 |
| 701 } | 782 void FragmentShaderRGBATexAlphaMaskAA::Init(WebGraphicsContext3D* context, |
| 702 | 783 unsigned program, |
| 703 void FragmentShaderRGBATexAlphaMaskAA::init(WebGraphicsContext3D* context, unsig ned program, bool usingBindUniform, int* baseUniformIndex) | 784 bool using_bind_uniform, |
| 704 { | 785 int* base_uniform_index) { |
| 705 static const char* shaderUniforms[] = { | 786 static const char* shader_uniforms[] = { |
| 706 "s_texture", | 787 "s_texture", |
| 707 "s_mask", | 788 "s_mask", |
| 708 "alpha", | 789 "alpha", |
| 709 "edge", | 790 "edge", |
| 710 "maskTexCoordScale", | 791 "maskTexCoordScale", |
| 711 "maskTexCoordOffset", | 792 "maskTexCoordOffset", |
| 712 }; | 793 }; |
| 713 int locations[6]; | 794 int locations[6]; |
| 714 | 795 |
| 715 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 796 GetProgramUniformLocations(context, |
| 716 | 797 program, |
| 717 m_samplerLocation = locations[0]; | 798 shader_uniforms, |
| 718 m_maskSamplerLocation = locations[1]; | 799 arraysize(shader_uniforms), |
| 719 m_alphaLocation = locations[2]; | 800 arraysize(locations), |
| 720 m_edgeLocation = locations[3]; | 801 locations, |
| 721 m_maskTexCoordScaleLocation = locations[4]; | 802 using_bind_uniform, |
| 722 m_maskTexCoordOffsetLocation = locations[5]; | 803 base_uniform_index); |
| 723 DCHECK(m_samplerLocation != -1 && m_maskSamplerLocation != -1 && m_alphaLoca tion != -1 && m_edgeLocation != -1); | 804 |
| 724 } | 805 sampler_location_ = locations[0]; |
| 725 | 806 mask_sampler_location_ = locations[1]; |
| 726 std::string FragmentShaderRGBATexAlphaMaskAA::getShaderString() const | 807 alpha_location_ = locations[2]; |
| 727 { | 808 edge_location_ = locations[3]; |
| 728 return SHADER( | 809 mask_tex_coord_scale_location_ = locations[4]; |
| 729 precision mediump float; | 810 mask_tex_coord_offset_location_ = locations[5]; |
| 730 varying vec2 v_texCoord; | 811 DCHECK(sampler_location_ != -1 && mask_sampler_location_ != -1 && |
| 731 uniform sampler2D s_texture; | 812 alpha_location_ != -1 && edge_location_ != -1); |
| 732 uniform sampler2D s_mask; | 813 } |
| 733 uniform vec2 maskTexCoordScale; | 814 |
| 734 uniform vec2 maskTexCoordOffset; | 815 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString() const { |
| 735 uniform float alpha; | 816 return SHADER( |
| 736 uniform vec3 edge[8]; | 817 precision mediump float; |
| 737 void main() | 818 varying vec2 v_texCoord; |
| 738 { | 819 uniform sampler2D s_texture; |
| 739 vec4 texColor = texture2D(s_texture, v_texCoord); | 820 uniform sampler2D s_mask; |
| 740 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * maskT exCoordScale.x, maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 821 uniform vec2 maskTexCoordScale; |
| 741 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 822 uniform vec2 maskTexCoordOffset; |
| 742 vec3 pos = vec3(gl_FragCoord.xy, 1); | 823 uniform float alpha; |
| 743 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 824 uniform vec3 edge[8]; |
| 744 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 825 void main() { |
| 745 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 826 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 746 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 827 vec2 maskTexCoord = vec2(maskTexCoordOffset.x + v_texCoord.x * |
| 747 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 828 maskTexCoordScale.x, |
| 748 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 829 maskTexCoordOffset.y + v_texCoord.y * |
| 749 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 830 maskTexCoordScale.y); |
| 750 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 831 vec4 maskColor = texture2D(s_mask, maskTexCoord); |
| 751 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha * maskColor.w * min(min(a0, a2) * min(a1, a3), min(a4, a6) * min(a5, a7) ); | 832 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 752 } | 833 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 753 ); | 834 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 835 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | |
| 836 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | |
| 837 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | |
| 838 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | |
| 839 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
| 840 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
| 841 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * | |
| 842 alpha * maskColor.w * min(min(a0, a2) * min(a1, a3), | |
| 843 min(a4, a6) * min(a5, a7)); | |
| 844 } | |
| 845 ); | |
| 754 } | 846 } |
| 755 | 847 |
| 756 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 848 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
| 757 : m_yTextureLocation(-1) | 849 : y_texture_location_(-1) |
| 758 , m_uTextureLocation(-1) | 850 , u_texture_location_(-1) |
| 759 , m_vTextureLocation(-1) | 851 , v_texture_location_(-1) |
| 760 , m_alphaLocation(-1) | 852 , alpha_location_(-1) |
| 761 , m_yuvMatrixLocation(-1) | 853 , yuv_matrix_location_(-1) |
| 762 , m_yuvAdjLocation(-1) | 854 , yuv_adj_location_(-1) { } |
| 763 { | 855 |
| 764 } | 856 void FragmentShaderYUVVideo::Init(WebGraphicsContext3D* context, |
| 765 | 857 unsigned program, |
| 766 void FragmentShaderYUVVideo::init(WebGraphicsContext3D* context, unsigned progra m, bool usingBindUniform, int* baseUniformIndex) | 858 bool using_bind_uniform, |
| 767 { | 859 int* base_uniform_index) { |
| 768 static const char* shaderUniforms[] = { | 860 static const char* shader_uniforms[] = { |
| 769 "y_texture", | 861 "y_texture", |
| 770 "u_texture", | 862 "u_texture", |
| 771 "v_texture", | 863 "v_texture", |
| 772 "alpha", | 864 "alpha", |
| 773 "yuv_matrix", | 865 "yuv_matrix", |
| 774 "yuv_adj", | 866 "yuv_adj", |
| 775 }; | 867 }; |
| 776 int locations[6]; | 868 int locations[6]; |
| 777 | 869 |
| 778 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 870 GetProgramUniformLocations(context, |
| 779 | 871 program, |
| 780 m_yTextureLocation = locations[0]; | 872 shader_uniforms, |
| 781 m_uTextureLocation = locations[1]; | 873 arraysize(shader_uniforms), |
| 782 m_vTextureLocation = locations[2]; | 874 arraysize(locations), |
| 783 m_alphaLocation = locations[3]; | 875 locations, |
| 784 m_yuvMatrixLocation = locations[4]; | 876 using_bind_uniform, |
| 785 m_yuvAdjLocation = locations[5]; | 877 base_uniform_index); |
| 786 | 878 |
| 787 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1 | 879 y_texture_location_ = locations[0]; |
| 788 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1); | 880 u_texture_location_ = locations[1]; |
| 789 } | 881 v_texture_location_ = locations[2]; |
| 790 | 882 alpha_location_ = locations[3]; |
| 791 std::string FragmentShaderYUVVideo::getShaderString() const | 883 yuv_matrix_location_ = locations[4]; |
| 792 { | 884 yuv_adj_location_ = locations[5]; |
| 793 return SHADER( | 885 |
| 794 precision mediump float; | 886 DCHECK(y_texture_location_ != -1 && u_texture_location_ != -1 && |
| 795 precision mediump int; | 887 v_texture_location_ != -1 && alpha_location_ != -1 && |
| 796 varying vec2 v_texCoord; | 888 yuv_matrix_location_ != -1 && yuv_adj_location_ != -1); |
| 797 uniform sampler2D y_texture; | 889 } |
| 798 uniform sampler2D u_texture; | 890 |
| 799 uniform sampler2D v_texture; | 891 std::string FragmentShaderYUVVideo::GetShaderString() const { |
| 800 uniform float alpha; | 892 return SHADER( |
| 801 uniform vec3 yuv_adj; | 893 precision mediump float; |
| 802 uniform mat3 yuv_matrix; | 894 precision mediump int; |
| 803 void main() | 895 varying vec2 v_texCoord; |
| 804 { | 896 uniform sampler2D y_texture; |
| 805 float y_raw = texture2D(y_texture, v_texCoord).x; | 897 uniform sampler2D u_texture; |
| 806 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 898 uniform sampler2D v_texture; |
| 807 float v_unsigned = texture2D(v_texture, v_texCoord).x; | 899 uniform float alpha; |
| 808 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 900 uniform vec3 yuv_adj; |
| 809 vec3 rgb = yuv_matrix * yuv; | 901 uniform mat3 yuv_matrix; |
| 810 gl_FragColor = vec4(rgb, float(1)) * alpha; | 902 void main() { |
| 811 } | 903 float y_raw = texture2D(y_texture, v_texCoord).x; |
| 812 ); | 904 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
| 905 float v_unsigned = texture2D(v_texture, v_texCoord).x; | |
| 906 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | |
| 907 vec3 rgb = yuv_matrix * yuv; | |
| 908 gl_FragColor = vec4(rgb, float(1)) * alpha; | |
| 909 } | |
| 910 ); | |
| 813 } | 911 } |
| 814 | 912 |
| 815 FragmentShaderColor::FragmentShaderColor() | 913 FragmentShaderColor::FragmentShaderColor() |
| 816 : m_colorLocation(-1) | 914 : color_location_(-1) { } |
| 817 { | 915 |
| 818 } | 916 void FragmentShaderColor::Init(WebGraphicsContext3D* context, |
| 819 | 917 unsigned program, |
| 820 void FragmentShaderColor::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) | 918 bool using_bind_uniform, |
| 821 { | 919 int* base_uniform_index) { |
| 822 static const char* shaderUniforms[] = { | 920 static const char* shader_uniforms[] = { |
| 823 "color", | 921 "color", |
| 824 }; | 922 }; |
| 825 int locations[1]; | 923 int locations[1]; |
| 826 | 924 |
| 827 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 925 GetProgramUniformLocations(context, |
| 828 | 926 program, |
| 829 m_colorLocation = locations[0]; | 927 shader_uniforms, |
| 830 DCHECK(m_colorLocation != -1); | 928 arraysize(shader_uniforms), |
| 831 } | 929 arraysize(locations), |
| 832 | 930 locations, |
| 833 std::string FragmentShaderColor::getShaderString() const | 931 using_bind_uniform, |
| 834 { | 932 base_uniform_index); |
| 835 return SHADER( | 933 |
| 836 precision mediump float; | 934 color_location_ = locations[0]; |
| 837 uniform vec4 color; | 935 DCHECK(color_location_ != -1); |
| 838 void main() | 936 } |
| 839 { | 937 |
| 840 gl_FragColor = color; | 938 std::string FragmentShaderColor::GetShaderString() const { |
| 841 } | 939 return SHADER( |
| 842 ); | 940 precision mediump float; |
| 941 uniform vec4 color; | |
| 942 void main() { | |
| 943 gl_FragColor = color; | |
| 944 } | |
| 945 ); | |
| 843 } | 946 } |
| 844 | 947 |
| 845 FragmentShaderColorAA::FragmentShaderColorAA() | 948 FragmentShaderColorAA::FragmentShaderColorAA() |
| 846 : m_edgeLocation(-1) | 949 : edge_location_(-1) |
| 847 , m_colorLocation(-1) | 950 , color_location_(-1) { } |
| 848 { | 951 |
| 849 } | 952 void FragmentShaderColorAA::Init(WebGraphicsContext3D* context, |
| 850 | 953 unsigned program, |
| 851 void FragmentShaderColorAA::init(WebGraphicsContext3D* context, unsigned program , bool usingBindUniform, int* baseUniformIndex) | 954 bool using_bind_uniform, |
| 852 { | 955 int* base_uniform_index) { |
| 853 static const char* shaderUniforms[] = { | 956 static const char* shader_uniforms[] = { |
| 854 "edge", | 957 "edge", |
| 855 "color", | 958 "color", |
| 856 }; | 959 }; |
| 857 int locations[2]; | 960 int locations[2]; |
| 858 | 961 |
| 859 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 962 GetProgramUniformLocations(context, |
| 860 | 963 program, |
| 861 m_edgeLocation = locations[0]; | 964 shader_uniforms, |
| 862 m_colorLocation = locations[1]; | 965 arraysize(shader_uniforms), |
| 863 DCHECK(m_edgeLocation != -1 && m_colorLocation != -1); | 966 arraysize(locations), |
| 864 } | 967 locations, |
| 865 | 968 using_bind_uniform, |
| 866 std::string FragmentShaderColorAA::getShaderString() const | 969 base_uniform_index); |
| 867 { | 970 |
| 868 return SHADER( | 971 edge_location_ = locations[0]; |
| 869 precision mediump float; | 972 color_location_ = locations[1]; |
| 870 uniform vec4 color; | 973 DCHECK(edge_location_ != -1 && color_location_ != -1); |
| 871 uniform vec3 edge[8]; | 974 } |
| 872 void main() | 975 |
| 873 { | 976 std::string FragmentShaderColorAA::GetShaderString() const { |
| 874 vec3 pos = vec3(gl_FragCoord.xy, 1); | 977 return SHADER( |
| 875 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); | 978 precision mediump float; |
| 876 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); | 979 uniform vec4 color; |
| 877 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); | 980 uniform vec3 edge[8]; |
| 878 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); | 981 void main() { |
| 879 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); | 982 vec3 pos = vec3(gl_FragCoord.xy, 1); |
| 880 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); | 983 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0); |
| 881 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | 984 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0); |
| 882 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | 985 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0); |
| 883 gl_FragColor = color * min(min(a0, a2) * min(a1, a3), min(a4, a6) * min(a5, a7)); | 986 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0); |
| 884 } | 987 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0); |
| 885 ); | 988 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0); |
| 989 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0); | |
| 990 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0); | |
| 991 gl_FragColor = color * min(min(a0, a2) * min(a1, a3), | |
| 992 min(a4, a6) * min(a5, a7)); | |
| 993 } | |
| 994 ); | |
| 886 } | 995 } |
| 887 | 996 |
| 888 FragmentShaderCheckerboard::FragmentShaderCheckerboard() | 997 FragmentShaderCheckerboard::FragmentShaderCheckerboard() |
| 889 : m_alphaLocation(-1) | 998 : alpha_location_(-1) |
| 890 , m_texTransformLocation(-1) | 999 , tex_transform_location_(-1) |
| 891 , m_frequencyLocation(-1) | 1000 , frequency_location_(-1) { } |
| 892 { | 1001 |
| 893 } | 1002 void FragmentShaderCheckerboard::Init(WebGraphicsContext3D* context, |
| 894 | 1003 unsigned program, |
| 895 void FragmentShaderCheckerboard::init(WebGraphicsContext3D* context, unsigned pr ogram, bool usingBindUniform, int* baseUniformIndex) | 1004 bool using_bind_uniform, |
| 896 { | 1005 int* base_uniform_index) { |
| 897 static const char* shaderUniforms[] = { | 1006 static const char* shader_uniforms[] = { |
| 898 "alpha", | 1007 "alpha", |
| 899 "texTransform", | 1008 "texTransform", |
| 900 "frequency", | 1009 "frequency", |
| 901 "color", | 1010 "color", |
| 902 }; | 1011 }; |
| 903 int locations[4]; | 1012 int locations[4]; |
| 904 | 1013 |
| 905 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 1014 GetProgramUniformLocations(context, |
| 906 | 1015 program, |
| 907 m_alphaLocation = locations[0]; | 1016 shader_uniforms, |
| 908 m_texTransformLocation = locations[1]; | 1017 arraysize(shader_uniforms), |
| 909 m_frequencyLocation = locations[2]; | 1018 arraysize(locations), |
| 910 m_colorLocation = locations[3]; | 1019 locations, |
| 911 DCHECK(m_alphaLocation != -1 && m_texTransformLocation != -1 && m_frequencyL ocation != -1 && m_colorLocation != -1); | 1020 using_bind_uniform, |
| 912 } | 1021 base_uniform_index); |
| 913 | 1022 |
| 914 std::string FragmentShaderCheckerboard::getShaderString() const | 1023 alpha_location_ = locations[0]; |
| 915 { | 1024 tex_transform_location_ = locations[1]; |
| 916 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | 1025 frequency_location_ = locations[2]; |
| 917 // by Munshi, Ginsburg, Shreiner. | 1026 color_location_ = locations[3]; |
| 918 return SHADER( | 1027 DCHECK(alpha_location_ != -1 && tex_transform_location_ != -1 && |
| 919 precision mediump float; | 1028 frequency_location_ != -1 && color_location_ != -1); |
| 920 precision mediump int; | 1029 } |
| 921 varying vec2 v_texCoord; | 1030 |
| 922 uniform float alpha; | 1031 std::string FragmentShaderCheckerboard::GetShaderString() const { |
| 923 uniform float frequency; | 1032 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
| 924 uniform vec4 texTransform; | 1033 // by Munshi, Ginsburg, Shreiner. |
| 925 uniform vec4 color; | 1034 return SHADER( |
| 926 void main() | 1035 precision mediump float; |
| 927 { | 1036 precision mediump int; |
| 928 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | 1037 varying vec2 v_texCoord; |
| 929 vec4 color2 = color; | 1038 uniform float alpha; |
| 930 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; | 1039 uniform float frequency; |
| 931 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1040 uniform vec4 texTransform; |
| 932 float picker = abs(coord.x - coord.y); | 1041 uniform vec4 color; |
| 933 gl_FragColor = mix(color1, color2, picker) * alpha; | 1042 void main() { |
| 934 } | 1043 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
| 935 ); | 1044 vec4 color2 = color; |
| 1045 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + | |
| 1046 texTransform.xy; | |
| 1047 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | |
| 1048 float picker = abs(coord.x - coord.y); | |
| 1049 gl_FragColor = mix(color1, color2, picker) * alpha; | |
| 1050 } | |
| 1051 ); | |
| 936 } | 1052 } |
| 937 | 1053 |
| 938 } // namespace cc | 1054 } // namespace cc |
| OLD | NEW |