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" |
11 #include "SkFloatingPoint.h" | 11 #include "SkFloatingPoint.h" |
| 12 #include "gl/GrGLContext.h" |
12 #include "gl/GrGLFragmentProcessor.h" | 13 #include "gl/GrGLFragmentProcessor.h" |
13 #include "gl/builders/GrGLProgramBuilder.h" | 14 #include "gl/builders/GrGLProgramBuilder.h" |
14 | 15 |
15 GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index) | 16 GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index) |
16 : fIndex(index) { | 17 : fIndex(index) { |
17 | 18 |
18 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; | 19 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; |
19 if (domain.contains(kFullRect) && kClamp_Mode == mode) { | 20 if (domain.contains(kFullRect) && kClamp_Mode == mode) { |
20 fMode = kIgnore_Mode; | 21 fMode = kIgnore_Mode; |
21 } else { | 22 } else { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // may require a gradient calculation inside a conditional block | 93 // may require a gradient calculation inside a conditional block |
93 // may return undefined results". This appears to be an issue wi
th | 94 // may return undefined results". This appears to be an issue wi
th |
94 // the 'any' call since even the simple "result=black; if (any()
) | 95 // the 'any' call since even the simple "result=black; if (any()
) |
95 // result=white;" code fails to compile. | 96 // result=white;" code fails to compile. |
96 builder->codeAppend("vec4 outside = vec4(0.0, 0.0, 0.0, 0.0);"); | 97 builder->codeAppend("vec4 outside = vec4(0.0, 0.0, 0.0, 0.0);"); |
97 builder->codeAppend("vec4 inside = "); | 98 builder->codeAppend("vec4 inside = "); |
98 builder->appendTextureLookupAndModulate(inModulateColor, sampler
, | 99 builder->appendTextureLookupAndModulate(inModulateColor, sampler
, |
99 inCoords.c_str()); | 100 inCoords.c_str()); |
100 builder->codeAppend(";"); | 101 builder->codeAppend(";"); |
101 | 102 |
102 builder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPre
cision, | 103 builder->codeAppend(GrGLShaderVar::PrecisionString(program->glsl
Caps(), |
103 program->ctxI
nfo().standard())); | 104 kHigh_GrSLPre
cision)); |
104 builder->codeAppendf("float x = (%s).x;", inCoords.c_str()); | 105 builder->codeAppendf("float x = (%s).x;", inCoords.c_str()); |
105 builder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPre
cision, | 106 builder->codeAppend(GrGLShaderVar::PrecisionString(program->glsl
Caps(), |
106 program->ctxI
nfo().standard())); | 107 kHigh_GrSLPre
cision)); |
107 builder->codeAppendf("float y = (%s).y;", inCoords.c_str()); | 108 builder->codeAppendf("float y = (%s).y;", inCoords.c_str()); |
108 | 109 |
109 builder->codeAppendf("x = abs(2.0*(x - %s.x)/(%s.z - %s.x) - 1.0
);", | 110 builder->codeAppendf("x = abs(2.0*(x - %s.x)/(%s.z - %s.x) - 1.0
);", |
110 domain, domain, domain); | 111 domain, domain, domain); |
111 builder->codeAppendf("y = abs(2.0*(y - %s.y)/(%s.w - %s.y) - 1.0
);", | 112 builder->codeAppendf("y = abs(2.0*(y - %s.y)/(%s.w - %s.y) - 1.0
);", |
112 domain, domain, domain); | 113 domain, domain, domain); |
113 builder->codeAppend("float blend = step(1.0, max(x, y));"); | 114 builder->codeAppend("float blend = step(1.0, max(x, y));"); |
114 builder->codeAppendf("%s = mix(inside, outside, blend);", outCol
or); | 115 builder->codeAppendf("%s = mix(inside, outside, blend);", outCol
or); |
115 } else { | 116 } else { |
116 builder->codeAppend("bvec4 outside;\n"); | 117 builder->codeAppend("bvec4 outside;\n"); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool()
: false; | 290 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool()
: false; |
290 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC
oordSet; | 291 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC
oordSet; |
291 return GrTextureDomainEffect::Create( | 292 return GrTextureDomainEffect::Create( |
292 d->fTextures[texIdx], | 293 d->fTextures[texIdx], |
293 matrix, | 294 matrix, |
294 domain, | 295 domain, |
295 mode, | 296 mode, |
296 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi
lterMode, | 297 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi
lterMode, |
297 coords); | 298 coords); |
298 } | 299 } |
OLD | NEW |