| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrShaderVar.h" | 8 #include "GrShaderVar.h" |
| 9 #include "GrShaderCaps.h" | 9 #include "GrShaderCaps.h" |
| 10 #include "GrSwizzle.h" | 10 #include "GrSwizzle.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 if (swizzle != GrSwizzle::RGBA()) { | 65 if (swizzle != GrSwizzle::RGBA()) { |
| 66 out->appendf(".%s", swizzle.c_str()); | 66 out->appendf(".%s", swizzle.c_str()); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 void GrGLSLShaderBuilder::appendTextureLookup(SkString* out, | 70 void GrGLSLShaderBuilder::appendTextureLookup(SkString* out, |
| 71 SamplerHandle samplerHandle, | 71 SamplerHandle samplerHandle, |
| 72 const char* coordName, | 72 const char* coordName, |
| 73 GrSLType varyingType) const { | 73 GrSLType varyingType) const { |
| 74 const GrShaderVar& sampler = fProgramBuilder->samplerVariable(samplerHandle)
; | 74 const GrShaderVar& sampler = fProgramBuilder->samplerVariable(samplerHandle)
; |
| 75 GrSLType samplerType = sampler.getType(); | 75 out->appendf("texture(%s, %s)", sampler.c_str(), coordName); |
| 76 if (samplerType == kTexture2DRectSampler_GrSLType) { | |
| 77 if (varyingType == kVec2f_GrSLType) { | |
| 78 out->appendf("texture(%s, textureSize(%s) * %s)", | |
| 79 sampler.c_str(), sampler.c_str(), coordName); | |
| 80 } else { | |
| 81 out->appendf("texture(%s, vec3(textureSize(%s) * %s.xy, %s.z))", | |
| 82 sampler.c_str(), sampler.c_str(), coordName, coordName)
; | |
| 83 } | |
| 84 } else { | |
| 85 out->appendf("texture(%s, %s)", sampler.c_str(), coordName); | |
| 86 } | |
| 87 append_texture_swizzle(out, fProgramBuilder->samplerSwizzle(samplerHandle)); | 76 append_texture_swizzle(out, fProgramBuilder->samplerSwizzle(samplerHandle)); |
| 88 } | 77 } |
| 89 | 78 |
| 90 void GrGLSLShaderBuilder::appendTextureLookup(SamplerHandle samplerHandle, | 79 void GrGLSLShaderBuilder::appendTextureLookup(SamplerHandle samplerHandle, |
| 91 const char* coordName, | 80 const char* coordName, |
| 92 GrSLType varyingType, | 81 GrSLType varyingType, |
| 93 GrGLSLColorSpaceXformHelper* color
XformHelper) { | 82 GrGLSLColorSpaceXformHelper* color
XformHelper) { |
| 94 if (colorXformHelper && colorXformHelper->isValid()) { | 83 if (colorXformHelper && colorXformHelper->isValid()) { |
| 95 // With a color gamut transform, we need to wrap the lookup in another f
unction call | 84 // With a color gamut transform, we need to wrap the lookup in another f
unction call |
| 96 SkString lookup; | 85 SkString lookup; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // append the 'footer' to code | 225 // append the 'footer' to code |
| 237 this->code().append("}"); | 226 this->code().append("}"); |
| 238 | 227 |
| 239 for (int i = 0; i <= fCodeIndex; i++) { | 228 for (int i = 0; i <= fCodeIndex; i++) { |
| 240 fCompilerStrings[i] = fShaderStrings[i].c_str(); | 229 fCompilerStrings[i] = fShaderStrings[i].c_str(); |
| 241 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); | 230 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); |
| 242 } | 231 } |
| 243 | 232 |
| 244 fFinalized = true; | 233 fFinalized = true; |
| 245 } | 234 } |
| OLD | NEW |