| 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 "GrGLProgramBuilder.h" | 9 #include "GrGLProgramBuilder.h" |
| 10 #include "../GrGLGpu.h" | 10 #include "../GrGLGpu.h" |
| 11 | 11 |
| 12 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) | 12 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) |
| 13 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) | 13 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) |
| 14 | 14 |
| 15 const char* GrGLFragmentShaderBuilder::kDstCopyColorName = "_dstColor"; | 15 const char* GrGLFragmentShaderBuilder::kDstCopyColorName = "_dstColor"; |
| 16 static const char* declared_color_output_name() { return "fsColorOut"; } | 16 static const char* declared_color_output_name() { return "fsColorOut"; } |
| 17 static const char* dual_source_output_name() { return "dualSourceOut"; } | 17 static const char* dual_source_output_name() { return "dualSourceOut"; } |
| 18 static void append_default_precision_qualifier(GrSLPrecision p, |
| 19 GrGLStandard standard, |
| 20 SkString* str) { |
| 21 // Desktop GLSL has added precision qualifiers but they don't do anything. |
| 22 if (kGLES_GrGLStandard == standard) { |
| 23 switch (p) { |
| 24 case kHigh_GrSLPrecision: |
| 25 str->append("precision highp float;\n"); |
| 26 break; |
| 27 case kMedium_GrSLPrecision: |
| 28 str->append("precision mediump float;\n"); |
| 29 break; |
| 30 case kLow_GrSLPrecision: |
| 31 str->append("precision lowp float;\n"); |
| 32 break; |
| 33 default: |
| 34 SkFAIL("Unknown precision value."); |
| 35 } |
| 36 } |
| 37 } |
| 18 | 38 |
| 19 static const char* specific_layout_qualifier_name(GrBlendEquation equation) { | 39 static const char* specific_layout_qualifier_name(GrBlendEquation equation) { |
| 20 SkASSERT(GrBlendEquationIsAdvanced(equation)); | 40 SkASSERT(GrBlendEquationIsAdvanced(equation)); |
| 21 | 41 |
| 22 static const char* kLayoutQualifierNames[] = { | 42 static const char* kLayoutQualifierNames[] = { |
| 23 "blend_support_screen", | 43 "blend_support_screen", |
| 24 "blend_support_overlay", | 44 "blend_support_overlay", |
| 25 "blend_support_darken", | 45 "blend_support_darken", |
| 26 "blend_support_lighten", | 46 "blend_support_lighten", |
| 27 "blend_support_colordodge", | 47 "blend_support_colordodge", |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 263 } |
| 244 | 264 |
| 245 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { | 265 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { |
| 246 return dual_source_output_name(); | 266 return dual_source_output_name(); |
| 247 } | 267 } |
| 248 | 268 |
| 249 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, | 269 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, |
| 250 SkTDArray<GrGLuint>* sha
derIds) { | 270 SkTDArray<GrGLuint>* sha
derIds) { |
| 251 GrGLGpu* gpu = fProgramBuilder->gpu(); | 271 GrGLGpu* gpu = fProgramBuilder->gpu(); |
| 252 this->versionDecl() = GrGetGLSLVersionDecl(gpu->ctxInfo()); | 272 this->versionDecl() = GrGetGLSLVersionDecl(gpu->ctxInfo()); |
| 253 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, | 273 append_default_precision_qualifier(kDefault_GrSLPrecision, |
| 254 gpu->glStandard(), | 274 gpu->glStandard(), |
| 255 &this->precisionQualifier()); | 275 &this->precisionQualifier()); |
| 256 this->compileAndAppendLayoutQualifiers(); | 276 this->compileAndAppendLayoutQualifiers(); |
| 257 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, | 277 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, |
| 258 &this->uniforms()); | 278 &this->uniforms()); |
| 259 this->appendDecls(fInputs, &this->inputs()); | 279 this->appendDecls(fInputs, &this->inputs()); |
| 260 // We shouldn't have declared outputs on 1.10 | 280 // We shouldn't have declared outputs on 1.10 |
| 261 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; | 281 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; |
| 262 this->appendDecls(fOutputs, &this->outputs()); | 282 this->appendDecls(fOutputs, &this->outputs()); |
| 263 return this->finalize(programId, GR_GL_FRAGMENT_SHADER, shaderIds); | 283 return this->finalize(programId, GR_GL_FRAGMENT_SHADER, shaderIds); |
| 264 } | 284 } |
| 265 | 285 |
| 266 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID)
{ | 286 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID)
{ |
| 267 // ES 3.00 requires custom color output but doesn't support bindFragDataLoca
tion | 287 // ES 3.00 requires custom color output but doesn't support bindFragDataLoca
tion |
| 268 if (fHasCustomColorOutput && | 288 if (fHasCustomColorOutput && |
| 269 kGLES_GrGLStandard != fProgramBuilder->gpu()->ctxInfo().standard()) { | 289 kGLES_GrGLStandard != fProgramBuilder->gpu()->ctxInfo().standard()) { |
| 270 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); | 290 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); |
| 271 } | 291 } |
| 272 if (fHasSecondaryOutput) { | 292 if (fHasSecondaryOutput) { |
| 273 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); | 293 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); |
| 274 } | 294 } |
| 275 } | 295 } |
| 276 | 296 |
| 277 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ | 297 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ |
| 278 v->fFsIn = v->fVsOut; | 298 v->fFsIn = v->fVsOut; |
| 279 if (v->fGsOut) { | 299 if (v->fGsOut) { |
| 280 v->fFsIn = v->fGsOut; | 300 v->fFsIn = v->fGsOut; |
| 281 } | 301 } |
| 282 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); | 302 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); |
| 283 } | 303 } |
| OLD | NEW |