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 "GrTextureDomain.h" | 8 #include "GrTextureDomain.h" |
9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
10 #include "GrSimpleTextureEffect.h" | 10 #include "GrSimpleTextureEffect.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 fDomain.fTop = SkScalarPin(domain.fTop, kFullRect.fTop, kFullRect.fBotto
m); | 35 fDomain.fTop = SkScalarPin(domain.fTop, kFullRect.fTop, kFullRect.fBotto
m); |
36 fDomain.fBottom = SkScalarPin(domain.fBottom, kFullRect.fTop, kFullRect.
fBottom); | 36 fDomain.fBottom = SkScalarPin(domain.fBottom, kFullRect.fTop, kFullRect.
fBottom); |
37 SkASSERT(fDomain.fLeft <= fDomain.fRight); | 37 SkASSERT(fDomain.fLeft <= fDomain.fRight); |
38 SkASSERT(fDomain.fTop <= fDomain.fBottom); | 38 SkASSERT(fDomain.fTop <= fDomain.fBottom); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 ////////////////////////////////////////////////////////////////////////////// | 42 ////////////////////////////////////////////////////////////////////////////// |
43 | 43 |
44 void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder, | 44 void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder, |
| 45 const GrGLSLCaps* glslCaps, |
45 const GrTextureDomain& textureDoma
in, | 46 const GrTextureDomain& textureDoma
in, |
46 const char* outColor, | 47 const char* outColor, |
47 const SkString& inCoords, | 48 const SkString& inCoords, |
48 const GrGLSLTextureSampler& sample
r, | 49 const GrGLSLTextureSampler& sample
r, |
49 const char* inModulateColor) { | 50 const char* inModulateColor) { |
50 SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode); | 51 SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode); |
51 SkDEBUGCODE(fMode = textureDomain.mode();) | 52 SkDEBUGCODE(fMode = textureDomain.mode();) |
52 | 53 |
53 GrGLSLProgramBuilder* program = builder->getProgramBuilder(); | 54 GrGLSLProgramBuilder* program = builder->getProgramBuilder(); |
54 | 55 |
(...skipping 26 matching lines...) Expand all Loading... |
81 builder->appendTextureLookupAndModulate(inModulateColor, sampler, | 82 builder->appendTextureLookupAndModulate(inModulateColor, sampler, |
82 clampedCoords.c_str()); | 83 clampedCoords.c_str()); |
83 builder->codeAppend(";"); | 84 builder->codeAppend(";"); |
84 break; | 85 break; |
85 } | 86 } |
86 case kDecal_Mode: { | 87 case kDecal_Mode: { |
87 // Add a block since we're going to declare variables. | 88 // Add a block since we're going to declare variables. |
88 GrGLSLShaderBuilder::ShaderBlock block(builder); | 89 GrGLSLShaderBuilder::ShaderBlock block(builder); |
89 | 90 |
90 const char* domain = fDomainName.c_str(); | 91 const char* domain = fDomainName.c_str(); |
91 if (!program->glslCaps()->canUseAnyFunctionInShader()) { | 92 if (!glslCaps->canUseAnyFunctionInShader()) { |
92 // On the NexusS and GalaxyNexus, the other path (with the 'any' | 93 // On the NexusS and GalaxyNexus, the other path (with the 'any' |
93 // call) causes the compilation error "Calls to any function tha
t | 94 // call) causes the compilation error "Calls to any function tha
t |
94 // may require a gradient calculation inside a conditional block | 95 // may require a gradient calculation inside a conditional block |
95 // may return undefined results". This appears to be an issue wi
th | 96 // may return undefined results". This appears to be an issue wi
th |
96 // the 'any' call since even the simple "result=black; if (any()
) | 97 // the 'any' call since even the simple "result=black; if (any()
) |
97 // result=white;" code fails to compile. | 98 // result=white;" code fails to compile. |
98 builder->codeAppend("vec4 outside = vec4(0.0, 0.0, 0.0, 0.0);"); | 99 builder->codeAppend("vec4 outside = vec4(0.0, 0.0, 0.0, 0.0);"); |
99 builder->codeAppend("vec4 inside = "); | 100 builder->codeAppend("vec4 inside = "); |
100 builder->appendTextureLookupAndModulate(inModulateColor, sampler
, | 101 builder->appendTextureLookupAndModulate(inModulateColor, sampler
, |
101 inCoords.c_str()); | 102 inCoords.c_str()); |
102 builder->codeAppend(";"); | 103 builder->codeAppend(";"); |
103 | 104 |
104 builder->codeAppend(GrGLSLShaderVar::PrecisionString(program->gl
slCaps(), | 105 builder->codeAppend(GrGLSLShaderVar::PrecisionString(glslCaps, |
105 kHigh_GrSLP
recision)); | 106 kHigh_GrSLP
recision)); |
106 builder->codeAppendf("float x = (%s).x;", inCoords.c_str()); | 107 builder->codeAppendf("float x = (%s).x;", inCoords.c_str()); |
107 builder->codeAppend(GrGLSLShaderVar::PrecisionString(program->gl
slCaps(), | 108 builder->codeAppend(GrGLSLShaderVar::PrecisionString(glslCaps, |
108 kHigh_GrSLP
recision)); | 109 kHigh_GrSLP
recision)); |
109 builder->codeAppendf("float y = (%s).y;", inCoords.c_str()); | 110 builder->codeAppendf("float y = (%s).y;", inCoords.c_str()); |
110 | 111 |
111 builder->codeAppendf("x = abs(2.0*(x - %s.x)/(%s.z - %s.x) - 1.0
);", | 112 builder->codeAppendf("x = abs(2.0*(x - %s.x)/(%s.z - %s.x) - 1.0
);", |
112 domain, domain, domain); | 113 domain, domain, domain); |
113 builder->codeAppendf("y = abs(2.0*(y - %s.y)/(%s.w - %s.y) - 1.0
);", | 114 builder->codeAppendf("y = abs(2.0*(y - %s.y)/(%s.w - %s.y) - 1.0
);", |
114 domain, domain, domain); | 115 domain, domain, domain); |
115 builder->codeAppend("float blend = step(1.0, max(x, y));"); | 116 builder->codeAppend("float blend = step(1.0, max(x, y));"); |
116 builder->codeAppendf("%s = mix(inside, outside, blend);", outCol
or); | 117 builder->codeAppendf("%s = mix(inside, outside, blend);", outCol
or); |
117 } else { | 118 } else { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 191 |
191 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProcessor&) { | 192 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProcessor&) { |
192 } | 193 } |
193 | 194 |
194 void GrGLTextureDomainEffect::emitCode(EmitArgs& args) { | 195 void GrGLTextureDomainEffect::emitCode(EmitArgs& args) { |
195 const GrTextureDomainEffect& textureDomainEffect = args.fFp.cast<GrTextureDo
mainEffect>(); | 196 const GrTextureDomainEffect& textureDomainEffect = args.fFp.cast<GrTextureDo
mainEffect>(); |
196 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); | 197 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); |
197 | 198 |
198 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 199 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
199 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0); | 200 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0); |
200 fGLDomain.sampleTexture(fragBuilder, domain, args.fOutputColor, coords2D, ar
gs.fSamplers[0], | 201 fGLDomain.sampleTexture(fragBuilder, |
| 202 args.fGLSLCaps, |
| 203 domain, |
| 204 args.fOutputColor, |
| 205 coords2D, |
| 206 args.fSamplers[0], |
201 args.fInputColor); | 207 args.fInputColor); |
202 } | 208 } |
203 | 209 |
204 void GrGLTextureDomainEffect::onSetData(const GrGLSLProgramDataManager& pdman, | 210 void GrGLTextureDomainEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
205 const GrProcessor& processor) { | 211 const GrProcessor& processor) { |
206 const GrTextureDomainEffect& textureDomainEffect = processor.cast<GrTextureD
omainEffect>(); | 212 const GrTextureDomainEffect& textureDomainEffect = processor.cast<GrTextureD
omainEffect>(); |
207 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); | 213 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); |
208 fGLDomain.setData(pdman, domain, processor.texture(0)->origin()); | 214 fGLDomain.setData(pdman, domain, processor.texture(0)->origin()); |
209 } | 215 } |
210 | 216 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool()
: false; | 297 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool()
: false; |
292 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC
oordSet; | 298 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC
oordSet; |
293 return GrTextureDomainEffect::Create( | 299 return GrTextureDomainEffect::Create( |
294 d->fTextures[texIdx], | 300 d->fTextures[texIdx], |
295 matrix, | 301 matrix, |
296 domain, | 302 domain, |
297 mode, | 303 mode, |
298 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi
lterMode, | 304 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi
lterMode, |
299 coords); | 305 coords); |
300 } | 306 } |
OLD | NEW |