OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrBezierEffect.h" | 8 #include "GrBezierEffect.h" |
9 | 9 |
10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); | 38 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); |
39 fEdgeType = ce.getEdgeType(); | 39 fEdgeType = ce.getEdgeType(); |
40 } | 40 } |
41 | 41 |
42 void GrGLConicEffect::emitCode(GrGLShaderBuilder* builder, | 42 void GrGLConicEffect::emitCode(GrGLShaderBuilder* builder, |
43 const GrDrawEffect& drawEffect, | 43 const GrDrawEffect& drawEffect, |
44 EffectKey key, | 44 EffectKey key, |
45 const char* outputColor, | 45 const char* outputColor, |
46 const char* inputColor, | 46 const char* inputColor, |
47 const TextureSamplerArray& samplers) { | 47 const TextureSamplerArray& samplers) { |
| 48 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder(
); |
| 49 SkASSERT(NULL != vertexBuilder); |
| 50 |
48 const char *vsName, *fsName; | 51 const char *vsName, *fsName; |
49 | 52 |
50 builder->addVarying(kVec4f_GrSLType, "ConicCoeffs", | 53 vertexBuilder->addVarying(kVec4f_GrSLType, "ConicCoeffs", |
51 &vsName, &fsName); | 54 &vsName, &fsName); |
52 const SkString* attr0Name = | 55 const SkString* attr0Name = |
53 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); | 56 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices(
)[0]); |
54 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); | 57 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); |
55 | 58 |
56 builder->fsCodeAppend("\t\tfloat edgeAlpha;\n"); | 59 builder->fsCodeAppend("\t\tfloat edgeAlpha;\n"); |
57 | 60 |
58 switch (fEdgeType) { | 61 switch (fEdgeType) { |
59 case kHairAA_GrBezierEdgeType: { | 62 case kHairAA_GrBezierEdgeType: { |
60 SkAssertResult(builder->enableFeature( | 63 SkAssertResult(builder->enableFeature( |
61 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature)); | 64 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature)); |
62 builder->fsCodeAppendf("\t\tvec3 dklmdx = dFdx(%s.xyz);\n", fsName); | 65 builder->fsCodeAppendf("\t\tvec3 dklmdx = dFdx(%s.xyz);\n", fsName); |
63 builder->fsCodeAppendf("\t\tvec3 dklmdy = dFdy(%s.xyz);\n", fsName); | 66 builder->fsCodeAppendf("\t\tvec3 dklmdy = dFdy(%s.xyz);\n", fsName); |
64 builder->fsCodeAppendf("\t\tfloat dfdx =\n" | 67 builder->fsCodeAppendf("\t\tfloat dfdx =\n" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); | 181 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); |
179 fEdgeType = ce.getEdgeType(); | 182 fEdgeType = ce.getEdgeType(); |
180 } | 183 } |
181 | 184 |
182 void GrGLQuadEffect::emitCode(GrGLShaderBuilder* builder, | 185 void GrGLQuadEffect::emitCode(GrGLShaderBuilder* builder, |
183 const GrDrawEffect& drawEffect, | 186 const GrDrawEffect& drawEffect, |
184 EffectKey key, | 187 EffectKey key, |
185 const char* outputColor, | 188 const char* outputColor, |
186 const char* inputColor, | 189 const char* inputColor, |
187 const TextureSamplerArray& samplers) { | 190 const TextureSamplerArray& samplers) { |
| 191 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder(
); |
| 192 SkASSERT(NULL != vertexBuilder); |
| 193 |
188 const char *vsName, *fsName; | 194 const char *vsName, *fsName; |
189 | 195 |
190 const SkString* attrName = | 196 const SkString* attrName = |
191 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); | 197 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices(
)[0]); |
192 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); | 198 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); |
193 | 199 |
194 builder->addVarying(kVec4f_GrSLType, "HairQuadEdge", &vsName, &fsName); | 200 vertexBuilder->addVarying(kVec4f_GrSLType, "HairQuadEdge", &vsName, &fsName)
; |
195 | 201 |
196 switch (fEdgeType) { | 202 switch (fEdgeType) { |
197 case kHairAA_GrBezierEdgeType: { | 203 case kHairAA_GrBezierEdgeType: { |
198 SkAssertResult(builder->enableFeature( | 204 SkAssertResult(builder->enableFeature( |
199 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature)); | 205 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature)); |
200 builder->fsCodeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName); | 206 builder->fsCodeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName); |
201 builder->fsCodeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName); | 207 builder->fsCodeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName); |
202 builder->fsCodeAppendf("\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.
y,\n" | 208 builder->fsCodeAppendf("\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.
y,\n" |
203 "\t\t 2.0*%s.x*duvdy.x - duvdy.
y);\n", | 209 "\t\t 2.0*%s.x*duvdy.x - duvdy.
y);\n", |
204 fsName, fsName); | 210 fsName, fsName); |
(...skipping 26 matching lines...) Expand all Loading... |
231 fsName); | 237 fsName); |
232 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n"); | 238 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n"); |
233 break; | 239 break; |
234 } | 240 } |
235 } | 241 } |
236 | 242 |
237 SkString modulate; | 243 SkString modulate; |
238 GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); | 244 GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); |
239 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()); | 245 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()); |
240 | 246 |
241 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); | 247 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); |
242 } | 248 } |
243 | 249 |
244 GrGLEffect::EffectKey GrGLQuadEffect::GenKey(const GrDrawEffect& drawEffect, con
st GrGLCaps&) { | 250 GrGLEffect::EffectKey GrGLQuadEffect::GenKey(const GrDrawEffect& drawEffect, con
st GrGLCaps&) { |
245 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); | 251 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); |
246 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 252 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
247 } | 253 } |
248 | 254 |
249 ////////////////////////////////////////////////////////////////////////////// | 255 ////////////////////////////////////////////////////////////////////////////// |
250 | 256 |
251 GrQuadEffect::~GrQuadEffect() {} | 257 GrQuadEffect::~GrQuadEffect() {} |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); | 313 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); |
308 fEdgeType = ce.getEdgeType(); | 314 fEdgeType = ce.getEdgeType(); |
309 } | 315 } |
310 | 316 |
311 void GrGLCubicEffect::emitCode(GrGLShaderBuilder* builder, | 317 void GrGLCubicEffect::emitCode(GrGLShaderBuilder* builder, |
312 const GrDrawEffect& drawEffect, | 318 const GrDrawEffect& drawEffect, |
313 EffectKey key, | 319 EffectKey key, |
314 const char* outputColor, | 320 const char* outputColor, |
315 const char* inputColor, | 321 const char* inputColor, |
316 const TextureSamplerArray& samplers) { | 322 const TextureSamplerArray& samplers) { |
| 323 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder(
); |
| 324 SkASSERT(NULL != vertexBuilder); |
| 325 |
317 const char *vsName, *fsName; | 326 const char *vsName, *fsName; |
318 | 327 |
319 builder->addVarying(kVec4f_GrSLType, "CubicCoeffs", | 328 vertexBuilder->addVarying(kVec4f_GrSLType, "CubicCoeffs", |
320 &vsName, &fsName); | 329 &vsName, &fsName); |
321 const SkString* attr0Name = | 330 const SkString* attr0Name = |
322 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); | 331 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices(
)[0]); |
323 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); | 332 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); |
324 | 333 |
325 builder->fsCodeAppend("\t\tfloat edgeAlpha;\n"); | 334 builder->fsCodeAppend("\t\tfloat edgeAlpha;\n"); |
326 | 335 |
327 switch (fEdgeType) { | 336 switch (fEdgeType) { |
328 case kHairAA_GrBezierEdgeType: { | 337 case kHairAA_GrBezierEdgeType: { |
329 SkAssertResult(builder->enableFeature( | 338 SkAssertResult(builder->enableFeature( |
330 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature)); | 339 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature)); |
331 builder->fsCodeAppendf("\t\tvec3 dklmdx = dFdx(%s.xyz);\n", fsName); | 340 builder->fsCodeAppendf("\t\tvec3 dklmdx = dFdx(%s.xyz);\n", fsName); |
332 builder->fsCodeAppendf("\t\tvec3 dklmdy = dFdy(%s.xyz);\n", fsName); | 341 builder->fsCodeAppendf("\t\tvec3 dklmdy = dFdy(%s.xyz);\n", fsName); |
333 builder->fsCodeAppendf("\t\tfloat dfdx =\n" | 342 builder->fsCodeAppendf("\t\tfloat dfdx =\n" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 417 |
409 GR_DEFINE_EFFECT_TEST(GrCubicEffect); | 418 GR_DEFINE_EFFECT_TEST(GrCubicEffect); |
410 | 419 |
411 GrEffectRef* GrCubicEffect::TestCreate(SkMWCRandom* random, | 420 GrEffectRef* GrCubicEffect::TestCreate(SkMWCRandom* random, |
412 GrContext*, | 421 GrContext*, |
413 const GrDrawTargetCaps& caps, | 422 const GrDrawTargetCaps& caps, |
414 GrTexture*[]) { | 423 GrTexture*[]) { |
415 const GrBezierEdgeType edgeType = static_cast<GrBezierEdgeType>(random->next
ULessThan(3)); | 424 const GrBezierEdgeType edgeType = static_cast<GrBezierEdgeType>(random->next
ULessThan(3)); |
416 return GrCubicEffect::Create(edgeType, caps); | 425 return GrCubicEffect::Create(edgeType, caps); |
417 } | 426 } |
OLD | NEW |