| 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" |
| 11 #include "../GrGpuGL.h" | 11 #include "../GrGpuGL.h" |
| 12 | 12 |
| 13 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) | 13 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) |
| 14 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) | 14 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) |
| 15 | 15 |
| 16 const char* GrGLFragmentShaderBuilder::kDstCopyColorName = "_dstColor"; | 16 const char* GrGLFragmentShaderBuilder::kDstCopyColorName = "_dstColor"; |
| 17 static const char* declared_color_output_name() { return "fsColorOut"; } | 17 static const char* declared_color_output_name() { return "fsColorOut"; } |
| 18 static const char* dual_source_output_name() { return "dualSourceOut"; } | 18 static const char* dual_source_output_name() { return "dualSourceOut"; } |
| 19 static void append_default_precision_qualifier(GrGLShaderVar::Precision p, | 19 static void append_default_precision_qualifier(GrSLPrecision p, |
| 20 GrGLStandard standard, | 20 GrGLStandard standard, |
| 21 SkString* str) { | 21 SkString* str) { |
| 22 // Desktop GLSL has added precision qualifiers but they don't do anything. | 22 // Desktop GLSL has added precision qualifiers but they don't do anything. |
| 23 if (kGLES_GrGLStandard == standard) { | 23 if (kGLES_GrGLStandard == standard) { |
| 24 switch (p) { | 24 switch (p) { |
| 25 case GrGLShaderVar::kHigh_Precision: | 25 case kHigh_GrSLPrecision: |
| 26 str->append("precision highp float;\n"); | 26 str->append("precision highp float;\n"); |
| 27 break; | 27 break; |
| 28 case GrGLShaderVar::kMedium_Precision: | 28 case kMedium_GrSLPrecision: |
| 29 str->append("precision mediump float;\n"); | 29 str->append("precision mediump float;\n"); |
| 30 break; | 30 break; |
| 31 case GrGLShaderVar::kLow_Precision: | 31 case kLow_GrSLPrecision: |
| 32 str->append("precision lowp float;\n"); | 32 str->append("precision lowp float;\n"); |
| 33 break; | 33 break; |
| 34 default: | 34 default: |
| 35 SkFAIL("Unknown precision value."); | 35 SkFAIL("Unknown precision value."); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 GrGLFragmentShaderBuilder::DstReadKey | 40 GrGLFragmentShaderBuilder::DstReadKey |
| 41 GrGLFragmentShaderBuilder::KeyForDstRead(const GrTexture* dstCopy, const GrGLCap
s& caps) { | 41 GrGLFragmentShaderBuilder::KeyForDstRead(const GrTexture* dstCopy, const GrGLCap
s& caps) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return "gl_FragCoord"; | 124 return "gl_FragCoord"; |
| 125 } else if (gpu->glCaps().fragCoordConventionsSupport()) { | 125 } else if (gpu->glCaps().fragCoordConventionsSupport()) { |
| 126 if (!fSetupFragPosition) { | 126 if (!fSetupFragPosition) { |
| 127 if (gpu->glslGeneration() < k150_GrGLSLGeneration) { | 127 if (gpu->glslGeneration() < k150_GrGLSLGeneration) { |
| 128 this->addFeature(1 << kFragCoordConventions_GLSLPrivateFeature, | 128 this->addFeature(1 << kFragCoordConventions_GLSLPrivateFeature, |
| 129 "GL_ARB_fragment_coord_conventions"); | 129 "GL_ARB_fragment_coord_conventions"); |
| 130 } | 130 } |
| 131 fInputs.push_back().set(kVec4f_GrSLType, | 131 fInputs.push_back().set(kVec4f_GrSLType, |
| 132 GrGLShaderVar::kIn_TypeModifier, | 132 GrGLShaderVar::kIn_TypeModifier, |
| 133 "gl_FragCoord", | 133 "gl_FragCoord", |
| 134 GrGLShaderVar::kDefault_Precision, | 134 kDefault_GrSLPrecision, |
| 135 GrGLShaderVar::kUpperLeft_Origin); | 135 GrGLShaderVar::kUpperLeft_Origin); |
| 136 fSetupFragPosition = true; | 136 fSetupFragPosition = true; |
| 137 } | 137 } |
| 138 return "gl_FragCoord"; | 138 return "gl_FragCoord"; |
| 139 } else { | 139 } else { |
| 140 static const char* kCoordName = "fragCoordYDown"; | 140 static const char* kCoordName = "fragCoordYDown"; |
| 141 if (!fSetupFragPosition) { | 141 if (!fSetupFragPosition) { |
| 142 // temporarily change the stage index because we're inserting non-st
age code. | 142 // temporarily change the stage index because we're inserting non-st
age code. |
| 143 GrGLProgramBuilder::AutoStageRestore asr(fProgramBuilder); | 143 GrGLProgramBuilder::AutoStageRestore asr(fProgramBuilder); |
| 144 SkASSERT(!fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); | 144 SkASSERT(!fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 } | 299 } |
| 300 | 300 |
| 301 this->codeAppendf("\t%s = %s;\n", this->getPrimaryColorOutputName(), fragCol
or.c_str()); | 301 this->codeAppendf("\t%s = %s;\n", this->getPrimaryColorOutputName(), fragCol
or.c_str()); |
| 302 } | 302 } |
| 303 | 303 |
| 304 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, | 304 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, |
| 305 SkTDArray<GrGLuint>* sha
derIds) const { | 305 SkTDArray<GrGLuint>* sha
derIds) const { |
| 306 GrGpuGL* gpu = fProgramBuilder->gpu(); | 306 GrGpuGL* gpu = fProgramBuilder->gpu(); |
| 307 SkString fragShaderSrc(GrGetGLSLVersionDecl(gpu->ctxInfo())); | 307 SkString fragShaderSrc(GrGetGLSLVersionDecl(gpu->ctxInfo())); |
| 308 fragShaderSrc.append(fExtensions); | 308 fragShaderSrc.append(fExtensions); |
| 309 append_default_precision_qualifier(GrShaderVar::kDefault_Precision, | 309 append_default_precision_qualifier(kDefault_GrSLPrecision, |
| 310 gpu->glStandard(), | 310 gpu->glStandard(), |
| 311 &fragShaderSrc); | 311 &fragShaderSrc); |
| 312 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, &fragShaderSrc); | 312 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, &fragShaderSrc); |
| 313 this->appendDecls(fInputs, &fragShaderSrc); | 313 this->appendDecls(fInputs, &fragShaderSrc); |
| 314 // We shouldn't have declared outputs on 1.10 | 314 // We shouldn't have declared outputs on 1.10 |
| 315 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; | 315 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; |
| 316 this->appendDecls(fOutputs, &fragShaderSrc); | 316 this->appendDecls(fOutputs, &fragShaderSrc); |
| 317 fragShaderSrc.append(fFunctions); | 317 fragShaderSrc.append(fFunctions); |
| 318 fragShaderSrc.append("void main() {\n"); | 318 fragShaderSrc.append("void main() {\n"); |
| 319 fragShaderSrc.append(fCode); | 319 fragShaderSrc.append(fCode); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 335 // ES 3.00 requires custom color output but doesn't support bindFragDataLoca
tion | 335 // ES 3.00 requires custom color output but doesn't support bindFragDataLoca
tion |
| 336 if (fHasCustomColorOutput && | 336 if (fHasCustomColorOutput && |
| 337 kGLES_GrGLStandard != fProgramBuilder->gpu()->ctxInfo().standard()) { | 337 kGLES_GrGLStandard != fProgramBuilder->gpu()->ctxInfo().standard()) { |
| 338 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); | 338 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); |
| 339 } | 339 } |
| 340 if (fHasSecondaryOutput) { | 340 if (fHasSecondaryOutput) { |
| 341 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); | 341 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| 345 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrGLShaderVar::Precis
ion fsPrec) { | 345 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ |
| 346 v->fFsIn = v->fVsOut; | 346 v->fFsIn = v->fVsOut; |
| 347 if (v->fGsOut) { | 347 if (v->fGsOut) { |
| 348 v->fFsIn = v->fGsOut; | 348 v->fFsIn = v->fGsOut; |
| 349 } | 349 } |
| 350 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); | 350 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); |
| 351 } | 351 } |
| OLD | NEW |