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 "GrGLFragmentShaderBuilder.h" | 8 #include "GrGLFragmentShaderBuilder.h" |
9 #include "GrGLShaderStringBuilder.h" | 9 #include "GrGLShaderStringBuilder.h" |
10 #include "GrGLProgramBuilder.h" | 10 #include "GrGLProgramBuilder.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 249 } |
250 | 250 |
251 const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const { | 251 const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const { |
252 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor"
; | 252 return fHasCustomColorOutput ? declared_color_output_name() : "gl_FragColor"
; |
253 } | 253 } |
254 | 254 |
255 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { | 255 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { |
256 return dual_source_output_name(); | 256 return dual_source_output_name(); |
257 } | 257 } |
258 | 258 |
| 259 void GrGLFragmentShaderBuilder::enableSecondaryOutput(const GrGLSLExpr4& inputCo
lor, |
| 260 const GrGLSLExpr4& inputCo
verage) { |
| 261 this->enableSecondaryOutput(); |
| 262 const char* secondaryOutputName = this->getSecondaryColorOutputName(); |
| 263 GrGLSLExpr4 coeff(1); |
| 264 switch (fProgramBuilder->header().fSecondaryOutputType) { |
| 265 case GrProgramDesc::kCoverage_SecondaryOutputType: |
| 266 break; |
| 267 case GrProgramDesc::kCoverageISA_SecondaryOutputType: |
| 268 // Get (1-A) into coeff |
| 269 coeff = GrGLSLExpr4::VectorCast(GrGLSLExpr1(1) - inputColor.a()); |
| 270 break; |
| 271 case GrProgramDesc::kCoverageISC_SecondaryOutputType: |
| 272 // Get (1-RGBA) into coeff |
| 273 coeff = GrGLSLExpr4(1) - inputColor; |
| 274 break; |
| 275 default: |
| 276 SkFAIL("Unexpected Secondary Output"); |
| 277 } |
| 278 // Get coeff * coverage into modulate and then write that to the dual source
output. |
| 279 this->codeAppendf("\t%s = %s;\n", secondaryOutputName, (coeff * inputCoverag
e).c_str()); |
| 280 } |
| 281 |
| 282 void GrGLFragmentShaderBuilder::combineColorAndCoverage(const GrGLSLExpr4& input
Color, |
| 283 const GrGLSLExpr4& input
Coverage) { |
| 284 GrGLSLExpr4 fragColor = inputColor * inputCoverage; |
| 285 switch (fProgramBuilder->header().fPrimaryOutputType) { |
| 286 case GrProgramDesc::kModulate_PrimaryOutputType: |
| 287 break; |
| 288 case GrProgramDesc::kCombineWithDst_PrimaryOutputType: |
| 289 { |
| 290 // Tack on "+(1-coverage)dst onto the frag color. |
| 291 GrGLSLExpr4 dstCoeff = GrGLSLExpr4(1) - inputCoverage; |
| 292 GrGLSLExpr4 dstContribution = dstCoeff * GrGLSLExpr4(this->dstCo
lor()); |
| 293 fragColor = fragColor + dstContribution; |
| 294 } |
| 295 break; |
| 296 default: |
| 297 SkFAIL("Unknown Primary Output"); |
| 298 } |
| 299 |
| 300 // On any post 1.10 GLSL supporting GPU, we declare custom output |
| 301 if (k110_GrGLSLGeneration != fProgramBuilder->gpu()->glslGeneration()) { |
| 302 this->enableCustomOutput(); |
| 303 } |
| 304 |
| 305 this->codeAppendf("\t%s = %s;\n", this->getPrimaryColorOutputName(), fragCol
or.c_str()); |
| 306 } |
| 307 |
259 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, | 308 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, |
260 SkTDArray<GrGLuint>* sha
derIds) const { | 309 SkTDArray<GrGLuint>* sha
derIds) const { |
261 GrGpuGL* gpu = fProgramBuilder->gpu(); | 310 GrGpuGL* gpu = fProgramBuilder->gpu(); |
262 SkString fragShaderSrc(GrGetGLSLVersionDecl(gpu->ctxInfo())); | 311 SkString fragShaderSrc(GrGetGLSLVersionDecl(gpu->ctxInfo())); |
263 fragShaderSrc.append(fExtensions); | 312 fragShaderSrc.append(fExtensions); |
264 append_default_precision_qualifier(kDefault_GrSLPrecision, | 313 append_default_precision_qualifier(kDefault_GrSLPrecision, |
265 gpu->glStandard(), | 314 gpu->glStandard(), |
266 &fragShaderSrc); | 315 &fragShaderSrc); |
267 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, &fragShaderSrc); | 316 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, &fragShaderSrc); |
268 this->appendDecls(fInputs, &fragShaderSrc); | 317 this->appendDecls(fInputs, &fragShaderSrc); |
(...skipping 28 matching lines...) Expand all Loading... |
297 } | 346 } |
298 } | 347 } |
299 | 348 |
300 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ | 349 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ |
301 v->fFsIn = v->fVsOut; | 350 v->fFsIn = v->fVsOut; |
302 if (v->fGsOut) { | 351 if (v->fGsOut) { |
303 v->fFsIn = v->fGsOut; | 352 v->fFsIn = v->fGsOut; |
304 } | 353 } |
305 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); | 354 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); |
306 } | 355 } |
OLD | NEW |