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" |
11 #include "GrTexture.h" | 11 #include "GrTexture.h" |
12 | 12 |
13 // number of each input/output type in a single allocation block | 13 // number of each input/output type in a single allocation block |
14 static const int kVarsPerBlock = 8; | 14 static const int kVarsPerBlock = 8; |
15 | 15 |
16 // except FS outputs where we expect 2 at most. | 16 // except FS outputs where we expect 2 at most. |
17 static const int kMaxFSOutputs = 2; | 17 static const int kMaxFSOutputs = 2; |
18 | 18 |
19 // ES2 FS only guarantees mediump and lowp support | 19 // ES2 FS only guarantees mediump and lowp support |
20 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar:
:kMedium_Precision; | 20 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar:
:kMedium_Precision; |
21 | 21 |
22 typedef GrGLUniformManager::UniformHandle UniformHandle; | 22 typedef GrGLUniformManager::UniformHandle UniformHandle; |
23 /////////////////////////////////////////////////////////////////////////////// | 23 /////////////////////////////////////////////////////////////////////////////// |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 inline const char* sample_function_name(GrSLType type) { | 27 inline const char* sample_function_name(GrSLType type, GrGLSLGeneration glslGen)
{ |
28 if (kVec2f_GrSLType == type) { | 28 if (kVec2f_GrSLType == type) { |
29 return "texture2D"; | 29 return glslGen >= k130_GrGLSLGeneration ? "texture" : "texture2D"; |
30 } else { | 30 } else { |
31 GrAssert(kVec3f_GrSLType == type); | 31 GrAssert(kVec3f_GrSLType == type); |
32 return "texture2DProj"; | 32 return glslGen >= k130_GrGLSLGeneration ? "textureProj" : "texture2DProj
"; |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 /** | 36 /** |
37 * Do we need to either map r,g,b->a or a->r. | 37 * Do we need to either map r,g,b->a or a->r. |
38 */ | 38 */ |
39 inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, | 39 inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, |
40 const GrTextureAccess& access) { | 40 const GrTextureAccess& access) { |
41 if (GrPixelConfigIsAlphaOnly(access.getTexture()->config())) { | 41 if (GrPixelConfigIsAlphaOnly(access.getTexture()->config())) { |
42 if (caps.textureRedSupport() && (GrTextureAccess::kA_SwizzleFlag & acces
s.swizzleMask())) { | 42 if (caps.textureRedSupport() && (GrTextureAccess::kA_SwizzleFlag & acces
s.swizzleMask())) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 | 102 |
103 void GrGLShaderBuilder::appendTextureLookup(SkString* out, | 103 void GrGLShaderBuilder::appendTextureLookup(SkString* out, |
104 const GrGLShaderBuilder::TextureSamp
ler& sampler, | 104 const GrGLShaderBuilder::TextureSamp
ler& sampler, |
105 const char* coordName, | 105 const char* coordName, |
106 GrSLType varyingType) const { | 106 GrSLType varyingType) const { |
107 GrAssert(NULL != sampler.textureAccess()); | 107 GrAssert(NULL != sampler.textureAccess()); |
108 GrAssert(NULL != coordName); | 108 GrAssert(NULL != coordName); |
109 | 109 |
110 out->appendf("%s(%s, %s)", | 110 out->appendf("%s(%s, %s)", |
111 sample_function_name(varyingType), | 111 sample_function_name(varyingType, fContext.glslGeneration()), |
112 this->getUniformCStr(sampler.fSamplerUniform), | 112 this->getUniformCStr(sampler.fSamplerUniform), |
113 coordName); | 113 coordName); |
114 append_swizzle(out, *sampler.textureAccess(), fContext.caps()); | 114 append_swizzle(out, *sampler.textureAccess(), fContext.caps()); |
115 } | 115 } |
116 | 116 |
117 void GrGLShaderBuilder::appendTextureLookupAndModulate( | 117 void GrGLShaderBuilder::appendTextureLookupAndModulate( |
118 SkString* out, | 118 SkString* out, |
119 const char* modulation, | 119 const char* modulation, |
120 const GrGLShaderBuilder::TextureSamp
ler& sampler, | 120 const GrGLShaderBuilder::TextureSamp
ler& sampler, |
121 const char* coordName, | 121 const char* coordName, |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 key, | 454 key, |
455 vsInCoord, | 455 vsInCoord, |
456 fsOutColor, | 456 fsOutColor, |
457 fsInColor, | 457 fsInColor, |
458 textureSamplers); | 458 textureSamplers); |
459 this->fVSCode.appendf("\t}\n"); | 459 this->fVSCode.appendf("\t}\n"); |
460 this->fFSCode.appendf("\t}\n"); | 460 this->fFSCode.appendf("\t}\n"); |
461 | 461 |
462 return glEffect; | 462 return glEffect; |
463 } | 463 } |
OLD | NEW |