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 "gl/GrGLShaderBuilder.h" | 8 #include "gl/GrGLShaderBuilder.h" |
9 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
10 #include "gl/GrGLUniformHandle.h" | 10 #include "gl/GrGLUniformHandle.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 return glslGen >= k130_GrGLSLGeneration ? "textureProj" : "texture2DProj "; | 33 return glslGen >= k130_GrGLSLGeneration ? "textureProj" : "texture2DProj "; |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 /** | 37 /** |
38 * Do we need to either map r,g,b->a or a->r. | 38 * Do we need to either map r,g,b->a or a->r. |
39 */ | 39 */ |
40 inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, | 40 inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, |
41 const GrTextureAccess& access) { | 41 const GrTextureAccess& access) { |
42 if (GrPixelConfigIsAlphaOnly(access.getTexture()->config())) { | 42 if (GrPixelConfigIsAlphaOnly(access.getTexture()->config())) { |
43 if (caps.textureRedSupport() && (GrTextureAccess::kA_SwizzleFlag & acces s.swizzleMask())) { | 43 if (caps.textureRedSupport() && (kA_GrColorComponentFlag & access.swizzl eMask())) { |
44 return true; | 44 return true; |
45 } | 45 } |
46 if (GrTextureAccess::kRGB_SwizzleMask & access.swizzleMask()) { | 46 if (kRGB_GrColorComponentFlags & access.swizzleMask()) { |
47 return true; | 47 return true; |
48 } | 48 } |
49 } | 49 } |
50 return false; | 50 return false; |
51 } | 51 } |
52 | 52 |
53 void append_swizzle(SkString* outAppend, | 53 void append_swizzle(SkString* outAppend, |
54 const GrTextureAccess& access, | 54 const GrGLShaderBuilder::TextureSampler& texSampler, |
55 const GrGLCaps& caps) { | 55 const GrGLCaps& caps) { |
56 const char* swizzle = access.getSwizzle(); | 56 const char* swizzle = texSampler.swizzle(); |
57 char mangledSwizzle[5]; | 57 char mangledSwizzle[5]; |
58 | 58 |
59 // The swizzling occurs using texture params instead of shader-mangling if A RB_texture_swizzle | 59 // The swizzling occurs using texture params instead of shader-mangling if A RB_texture_swizzle |
60 // is available. | 60 // is available. |
61 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(access.getText ure()->config())) { | 61 if (!caps.textureSwizzleSupport() && |
robertphillips
2013/03/28 13:38:29
Doesn't this change the semantics from "only has a
bsalomon
2013/03/28 13:46:00
Yikes, changed & to ==
| |
62 (kA_GrColorComponentFlag & texSampler.configComponentMask())) { | |
62 char alphaChar = caps.textureRedSupport() ? 'r' : 'a'; | 63 char alphaChar = caps.textureRedSupport() ? 'r' : 'a'; |
63 int i; | 64 int i; |
64 for (i = 0; '\0' != swizzle[i]; ++i) { | 65 for (i = 0; '\0' != swizzle[i]; ++i) { |
65 mangledSwizzle[i] = alphaChar; | 66 mangledSwizzle[i] = alphaChar; |
66 } | 67 } |
67 mangledSwizzle[i] ='\0'; | 68 mangledSwizzle[i] ='\0'; |
68 swizzle = mangledSwizzle; | 69 swizzle = mangledSwizzle; |
69 } | 70 } |
70 // For shader prettiness we omit the swizzle rather than appending ".rgba". | 71 // For shader prettiness we omit the swizzle rather than appending ".rgba". |
71 if (memcmp(swizzle, "rgba", 4)) { | 72 if (memcmp(swizzle, "rgba", 4)) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 default: | 145 default: |
145 GrCrash("Invalid shader type"); | 146 GrCrash("Invalid shader type"); |
146 } | 147 } |
147 string->append(str); | 148 string->append(str); |
148 } | 149 } |
149 | 150 |
150 void GrGLShaderBuilder::appendTextureLookup(SkString* out, | 151 void GrGLShaderBuilder::appendTextureLookup(SkString* out, |
151 const GrGLShaderBuilder::TextureSamp ler& sampler, | 152 const GrGLShaderBuilder::TextureSamp ler& sampler, |
152 const char* coordName, | 153 const char* coordName, |
153 GrSLType varyingType) const { | 154 GrSLType varyingType) const { |
154 GrAssert(NULL != sampler.textureAccess()); | |
155 GrAssert(NULL != coordName); | 155 GrAssert(NULL != coordName); |
156 | 156 |
157 out->appendf("%s(%s, %s)", | 157 out->appendf("%s(%s, %s)", |
158 sample_function_name(varyingType, fCtxInfo.glslGeneration()), | 158 sample_function_name(varyingType, fCtxInfo.glslGeneration()), |
159 this->getUniformCStr(sampler.fSamplerUniform), | 159 this->getUniformCStr(sampler.fSamplerUniform), |
160 coordName); | 160 coordName); |
161 append_swizzle(out, *sampler.textureAccess(), *fCtxInfo.caps()); | 161 append_swizzle(out, sampler, *fCtxInfo.caps()); |
162 } | 162 } |
163 | 163 |
164 void GrGLShaderBuilder::appendTextureLookup(ShaderType type, | 164 void GrGLShaderBuilder::appendTextureLookup(ShaderType type, |
165 const GrGLShaderBuilder::TextureSamp ler& sampler, | 165 const GrGLShaderBuilder::TextureSamp ler& sampler, |
166 const char* coordName, | 166 const char* coordName, |
167 GrSLType varyingType) { | 167 GrSLType varyingType) { |
168 GrAssert(kFragment_ShaderType == type); | 168 GrAssert(kFragment_ShaderType == type); |
169 this->appendTextureLookup(&fFSCode, sampler, coordName, varyingType); | 169 this->appendTextureLookup(&fFSCode, sampler, coordName, varyingType); |
170 } | 170 } |
171 | 171 |
(...skipping 12 matching lines...) Expand all Loading... | |
184 GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess( | 184 GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess( |
185 const GrTextureAcces s& access, | 185 const GrTextureAcces s& access, |
186 const GrGLCaps& caps ) { | 186 const GrGLCaps& caps ) { |
187 GrBackendEffectFactory::EffectKey key = 0; | 187 GrBackendEffectFactory::EffectKey key = 0; |
188 | 188 |
189 // Assume that swizzle support implies that we never have to modify a shader to adjust | 189 // Assume that swizzle support implies that we never have to modify a shader to adjust |
190 // for texture format/swizzle settings. | 190 // for texture format/swizzle settings. |
191 if (!caps.textureSwizzleSupport() && swizzle_requires_alpha_remapping(caps, access)) { | 191 if (!caps.textureSwizzleSupport() && swizzle_requires_alpha_remapping(caps, access)) { |
192 key = 1; | 192 key = 1; |
193 } | 193 } |
194 #if GR_DEBUG | |
195 // Assert that key is set iff the swizzle will be modified. | |
196 SkString origString(access.getSwizzle()); | |
197 origString.prepend("."); | |
198 SkString modifiedString; | |
199 append_swizzle(&modifiedString, access, caps); | |
200 if (!modifiedString.size()) { | |
201 modifiedString = ".rgba"; | |
202 } | |
203 GrAssert(SkToBool(key) == (modifiedString != origString)); | |
204 #endif | |
205 return key; | 194 return key; |
206 } | 195 } |
207 | 196 |
208 const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, cons t GrGLCaps& caps) { | 197 const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, cons t GrGLCaps& caps) { |
209 if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) { | 198 if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) { |
210 if (caps.textureRedSupport()) { | 199 if (caps.textureRedSupport()) { |
211 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE D, GR_GL_RED }; | 200 static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RE D, GR_GL_RED }; |
212 return gRedSmear; | 201 return gRedSmear; |
213 } else { | 202 } else { |
214 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA, | 203 static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA, |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 for (const AttributePair* attrib = this->getEffectAttributes().begin(); | 541 for (const AttributePair* attrib = this->getEffectAttributes().begin(); |
553 attrib != attribEnd; | 542 attrib != attribEnd; |
554 ++attrib) { | 543 ++attrib) { |
555 if (attrib->fIndex == attributeIndex) { | 544 if (attrib->fIndex == attributeIndex) { |
556 return &attrib->fName; | 545 return &attrib->fName; |
557 } | 546 } |
558 } | 547 } |
559 | 548 |
560 return NULL; | 549 return NULL; |
561 } | 550 } |
OLD | NEW |