OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrTextureDomainEffect.h" | 8 #include "GrTextureDomainEffect.h" |
9 #include "GrSimpleTextureEffect.h" | 9 #include "GrSimpleTextureEffect.h" |
10 #include "GrTBackendEffectFactory.h" | 10 #include "GrTBackendEffectFactory.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder, | 45 void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder, |
46 const GrDrawEffect& drawEffect, | 46 const GrDrawEffect& drawEffect, |
47 EffectKey key, | 47 EffectKey key, |
48 const char* outputColor, | 48 const char* outputColor, |
49 const char* inputColor, | 49 const char* inputColor, |
50 const TextureSamplerArray& samplers) { | 50 const TextureSamplerArray& samplers) { |
51 const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainE
ffect>(); | 51 const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainE
ffect>(); |
52 | 52 |
53 const char* coords; | 53 SkString coords; |
54 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); | 54 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); |
55 const char* domain; | 55 const char* domain; |
56 fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 56 fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
57 kVec4f_GrSLType, "TexDom", &domain); | 57 kVec4f_GrSLType, "TexDom", &domain); |
58 if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) { | 58 if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) { |
59 | 59 |
60 builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n", | 60 builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n", |
61 coords, domain, domain); | 61 coords.c_str(), domain, domain); |
62 | 62 |
63 builder->fsCodeAppendf("\t%s = ", outputColor); | 63 builder->fsCodeAppendf("\t%s = ", outputColor); |
64 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_Sha
derType, | 64 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_Sha
derType, |
65 inputColor, | 65 inputColor, |
66 samplers[0], | 66 samplers[0], |
67 "clampCoord"); | 67 "clampCoord"); |
68 builder->fsCodeAppend(";\n"); | 68 builder->fsCodeAppend(";\n"); |
69 } else { | 69 } else { |
70 SkASSERT(GrTextureDomainEffect::kDecal_WrapMode == texDom.wrapMode()); | 70 SkASSERT(GrTextureDomainEffect::kDecal_WrapMode == texDom.wrapMode()); |
71 | 71 |
72 if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { | 72 if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { |
73 // On the NexusS and GalaxyNexus, the other path (with the 'any' | 73 // On the NexusS and GalaxyNexus, the other path (with the 'any' |
74 // call) causes the compilation error "Calls to any function that | 74 // call) causes the compilation error "Calls to any function that |
75 // may require a gradient calculation inside a conditional block | 75 // may require a gradient calculation inside a conditional block |
76 // may return undefined results". This appears to be an issue with | 76 // may return undefined results". This appears to be an issue with |
77 // the 'any' call since even the simple "result=black; if (any()) | 77 // the 'any' call since even the simple "result=black; if (any()) |
78 // result=white;" code fails to compile. | 78 // result=white;" code fails to compile. |
79 builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"
); | 79 builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"
); |
80 builder->fsCodeAppend("\tvec4 inside = "); | 80 builder->fsCodeAppend("\tvec4 inside = "); |
81 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment
_ShaderType, | 81 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment
_ShaderType, |
82 inputColor, | 82 inputColor, |
83 samplers[0], | 83 samplers[0], |
84 coords); | 84 coords.c_str()); |
85 builder->fsCodeAppend(";\n"); | 85 builder->fsCodeAppend(";\n"); |
86 | 86 |
87 builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s
.x) - 1.0);\n", | 87 builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s
.x) - 1.0);\n", |
88 coords, domain, domain, domain); | 88 coords.c_str(), domain, domain, domain); |
89 builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s
.y) - 1.0);\n", | 89 builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s
.y) - 1.0);\n", |
90 coords, domain, domain, domain); | 90 coords.c_str(), domain, domain, domain); |
91 builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); | 91 builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); |
92 builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outp
utColor); | 92 builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outp
utColor); |
93 } else { | 93 } else { |
94 builder->fsCodeAppend("\tbvec4 outside;\n"); | 94 builder->fsCodeAppend("\tbvec4 outside;\n"); |
95 builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coor
ds, domain); | 95 builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coor
ds.c_str(), domain); |
96 builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", c
oords, domain); | 96 builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", c
oords.c_str(), domain); |
97 builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.
0) : ", outputColor); | 97 builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.
0) : ", outputColor); |
98 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment
_ShaderType, | 98 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment
_ShaderType, |
99 inputColor, | 99 inputColor, |
100 samplers[0], | 100 samplers[0], |
101 coords); | 101 coords.c_str()); |
102 builder->fsCodeAppend(";\n"); | 102 builder->fsCodeAppend(";\n"); |
103 } | 103 } |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, | 107 void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, |
108 const GrDrawEffect& drawEffect) { | 108 const GrDrawEffect& drawEffect) { |
109 const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainE
ffect>(); | 109 const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainE
ffect>(); |
110 const SkRect& domain = texDom.domain(); | 110 const SkRect& domain = texDom.domain(); |
111 | 111 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); | 234 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); |
235 bool bilerp = random->nextBool(); | 235 bool bilerp = random->nextBool(); |
236 CoordsType coords = random->nextBool() ? kLocal_CoordsType : kPosition_Coord
sType; | 236 CoordsType coords = random->nextBool() ? kLocal_CoordsType : kPosition_Coord
sType; |
237 return GrTextureDomainEffect::Create(textures[texIdx], | 237 return GrTextureDomainEffect::Create(textures[texIdx], |
238 matrix, | 238 matrix, |
239 domain, | 239 domain, |
240 wrapMode, | 240 wrapMode, |
241 bilerp ? GrTextureParams::kBilerp_Filte
rMode : GrTextureParams::kNone_FilterMode, | 241 bilerp ? GrTextureParams::kBilerp_Filte
rMode : GrTextureParams::kNone_FilterMode, |
242 coords); | 242 coords); |
243 } | 243 } |
OLD | NEW |