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