| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 , fCtxInfo(ctxInfo) | 94 , fCtxInfo(ctxInfo) |
| 95 , fUniformManager(uniformManager) | 95 , fUniformManager(uniformManager) |
| 96 , fCurrentStageIdx(kNonStageIdx) | 96 , fCurrentStageIdx(kNonStageIdx) |
| 97 , fSetupFragPosition(false) | 97 , fSetupFragPosition(false) |
| 98 , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle) { | 98 , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle) { |
| 99 | 99 |
| 100 fPositionVar = &fVSAttrs.push_back(); | 100 fPositionVar = &fVSAttrs.push_back(); |
| 101 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
aPosition"); | 101 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
aPosition"); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_lis
t args) { |
| 105 SkString* string; |
| 106 switch (type) { |
| 107 case kVertex_ShaderType: |
| 108 string = &fVSCode; |
| 109 break; |
| 110 case kGeometry_ShaderType: |
| 111 string = &fGSCode; |
| 112 break; |
| 113 case kFragment_ShaderType: |
| 114 string = &fFSCode; |
| 115 break; |
| 116 default: |
| 117 GrCrash("Invalid shader type"); |
| 118 } |
| 119 string->appendf(format, args); |
| 120 } |
| 121 |
| 122 void GrGLShaderBuilder::codeAppend(ShaderType type, const char* str) { |
| 123 SkString* string; |
| 124 switch (type) { |
| 125 case kVertex_ShaderType: |
| 126 string = &fVSCode; |
| 127 break; |
| 128 case kGeometry_ShaderType: |
| 129 string = &fGSCode; |
| 130 break; |
| 131 case kFragment_ShaderType: |
| 132 string = &fFSCode; |
| 133 break; |
| 134 default: |
| 135 GrCrash("Invalid shader type"); |
| 136 } |
| 137 string->append(str); |
| 138 } |
| 139 |
| 104 void GrGLShaderBuilder::appendTextureLookup(SkString* out, | 140 void GrGLShaderBuilder::appendTextureLookup(SkString* out, |
| 105 const GrGLShaderBuilder::TextureSamp
ler& sampler, | 141 const GrGLShaderBuilder::TextureSamp
ler& sampler, |
| 106 const char* coordName, | 142 const char* coordName, |
| 107 GrSLType varyingType) const { | 143 GrSLType varyingType) const { |
| 108 GrAssert(NULL != sampler.textureAccess()); | 144 GrAssert(NULL != sampler.textureAccess()); |
| 109 GrAssert(NULL != coordName); | 145 GrAssert(NULL != coordName); |
| 110 | 146 |
| 111 out->appendf("%s(%s, %s)", | 147 out->appendf("%s(%s, %s)", |
| 112 sample_function_name(varyingType, fCtxInfo.glslGeneration()), | 148 sample_function_name(varyingType, fCtxInfo.glslGeneration()), |
| 113 this->getUniformCStr(sampler.fSamplerUniform), | 149 this->getUniformCStr(sampler.fSamplerUniform), |
| 114 coordName); | 150 coordName); |
| 115 append_swizzle(out, *sampler.textureAccess(), fCtxInfo.caps()); | 151 append_swizzle(out, *sampler.textureAccess(), fCtxInfo.caps()); |
| 116 } | 152 } |
| 117 | 153 |
| 154 void GrGLShaderBuilder::appendTextureLookup(ShaderType type, |
| 155 const GrGLShaderBuilder::TextureSamp
ler& sampler, |
| 156 const char* coordName, |
| 157 GrSLType varyingType) { |
| 158 GrAssert(kFragment_ShaderType == type); |
| 159 this->appendTextureLookup(&fFSCode, sampler, coordName, varyingType); |
| 160 } |
| 161 |
| 118 void GrGLShaderBuilder::appendTextureLookupAndModulate( | 162 void GrGLShaderBuilder::appendTextureLookupAndModulate( |
| 119 SkString* out, | 163 ShaderType type, |
| 120 const char* modulation, | 164 const char* modulation, |
| 121 const GrGLShaderBuilder::TextureSamp
ler& sampler, | 165 const GrGLShaderBuilder::TextureSamp
ler& sampler, |
| 122 const char* coordName, | 166 const char* coordName, |
| 123 GrSLType varyingType) const { | 167 GrSLType varyingType) { |
| 124 GrAssert(NULL != out); | 168 GrAssert(kFragment_ShaderType == type); |
| 125 SkString lookup; | 169 SkString lookup; |
| 126 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); | 170 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); |
| 127 GrGLSLModulate4f(out, modulation, lookup.c_str()); | 171 GrGLSLModulate4f(&fFSCode, modulation, lookup.c_str()); |
| 128 } | 172 } |
| 129 | 173 |
| 130 GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess( | 174 GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess( |
| 131 const GrTextureAcces
s& access, | 175 const GrTextureAcces
s& access, |
| 132 const GrGLCaps& caps
) { | 176 const GrGLCaps& caps
) { |
| 133 GrBackendEffectFactory::EffectKey key = 0; | 177 GrBackendEffectFactory::EffectKey key = 0; |
| 134 | 178 |
| 135 // Assume that swizzle support implies that we never have to modify a shader
to adjust | 179 // Assume that swizzle support implies that we never have to modify a shader
to adjust |
| 136 // for texture format/swizzle settings. | 180 // for texture format/swizzle settings. |
| 137 if (!caps.textureSwizzleSupport() && swizzle_requires_alpha_remapping(caps,
access)) { | 181 if (!caps.textureSwizzleSupport() && swizzle_requires_alpha_remapping(caps,
access)) { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 key, | 499 key, |
| 456 vsInCoord, | 500 vsInCoord, |
| 457 fsOutColor, | 501 fsOutColor, |
| 458 fsInColor, | 502 fsInColor, |
| 459 textureSamplers); | 503 textureSamplers); |
| 460 this->fVSCode.appendf("\t}\n"); | 504 this->fVSCode.appendf("\t}\n"); |
| 461 this->fFSCode.appendf("\t}\n"); | 505 this->fFSCode.appendf("\t}\n"); |
| 462 | 506 |
| 463 return glEffect; | 507 return glEffect; |
| 464 } | 508 } |
| OLD | NEW |