| 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 } | |
| 38 | 18 |
| 39 static const char* specific_layout_qualifier_name(GrBlendEquation equation) { | 19 static const char* specific_layout_qualifier_name(GrBlendEquation equation) { |
| 40 SkASSERT(GrBlendEquationIsAdvanced(equation)); | 20 SkASSERT(GrBlendEquationIsAdvanced(equation)); |
| 41 | 21 |
| 42 static const char* kLayoutQualifierNames[] = { | 22 static const char* kLayoutQualifierNames[] = { |
| 43 "blend_support_screen", | 23 "blend_support_screen", |
| 44 "blend_support_overlay", | 24 "blend_support_overlay", |
| 45 "blend_support_darken", | 25 "blend_support_darken", |
| 46 "blend_support_lighten", | 26 "blend_support_lighten", |
| 47 "blend_support_colordodge", | 27 "blend_support_colordodge", |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 243 } |
| 264 | 244 |
| 265 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { | 245 const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const { |
| 266 return dual_source_output_name(); | 246 return dual_source_output_name(); |
| 267 } | 247 } |
| 268 | 248 |
| 269 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, | 249 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, |
| 270 SkTDArray<GrGLuint>* sha
derIds) { | 250 SkTDArray<GrGLuint>* sha
derIds) { |
| 271 GrGLGpu* gpu = fProgramBuilder->gpu(); | 251 GrGLGpu* gpu = fProgramBuilder->gpu(); |
| 272 this->versionDecl() = GrGetGLSLVersionDecl(gpu->ctxInfo()); | 252 this->versionDecl() = GrGetGLSLVersionDecl(gpu->ctxInfo()); |
| 273 append_default_precision_qualifier(kDefault_GrSLPrecision, | 253 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, |
| 274 gpu->glStandard(), | 254 gpu->glStandard(), |
| 275 &this->precisionQualifier()); | 255 &this->precisionQualifier()); |
| 276 this->compileAndAppendLayoutQualifiers(); | 256 this->compileAndAppendLayoutQualifiers(); |
| 277 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, | 257 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, |
| 278 &this->uniforms()); | 258 &this->uniforms()); |
| 279 this->appendDecls(fInputs, &this->inputs()); | 259 this->appendDecls(fInputs, &this->inputs()); |
| 280 // We shouldn't have declared outputs on 1.10 | 260 // We shouldn't have declared outputs on 1.10 |
| 281 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; | 261 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; |
| 282 this->appendDecls(fOutputs, &this->outputs()); | 262 this->appendDecls(fOutputs, &this->outputs()); |
| 283 return this->finalize(programId, GR_GL_FRAGMENT_SHADER, shaderIds); | 263 return this->finalize(programId, GR_GL_FRAGMENT_SHADER, shaderIds); |
| 284 } | 264 } |
| 285 | 265 |
| 286 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID)
{ | 266 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID)
{ |
| 287 // ES 3.00 requires custom color output but doesn't support bindFragDataLoca
tion | 267 // ES 3.00 requires custom color output but doesn't support bindFragDataLoca
tion |
| 288 if (fHasCustomColorOutput && | 268 if (fHasCustomColorOutput && |
| 289 kGLES_GrGLStandard != fProgramBuilder->gpu()->ctxInfo().standard()) { | 269 kGLES_GrGLStandard != fProgramBuilder->gpu()->ctxInfo().standard()) { |
| 290 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); | 270 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); |
| 291 } | 271 } |
| 292 if (fHasSecondaryOutput) { | 272 if (fHasSecondaryOutput) { |
| 293 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); | 273 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); |
| 294 } | 274 } |
| 295 } | 275 } |
| 296 | 276 |
| 297 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ | 277 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ |
| 298 v->fFsIn = v->fVsOut; | 278 v->fFsIn = v->fVsOut; |
| 299 if (v->fGsOut) { | 279 if (v->fGsOut) { |
| 300 v->fFsIn = v->fGsOut; | 280 v->fFsIn = v->fGsOut; |
| 301 } | 281 } |
| 302 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); | 282 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); |
| 303 } | 283 } |
| OLD | NEW |