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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 , fSetupFragPosition(false) | 72 , fSetupFragPosition(false) |
73 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey) | 73 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey) |
74 , fCustomColorOutputIndex(-1) | 74 , fCustomColorOutputIndex(-1) |
75 , fHasReadDstColor(false) | 75 , fHasReadDstColor(false) |
76 , fHasReadFragmentPosition(false) { | 76 , fHasReadFragmentPosition(false) { |
77 } | 77 } |
78 | 78 |
79 bool GrGLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { | 79 bool GrGLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { |
80 switch (feature) { | 80 switch (feature) { |
81 case kStandardDerivatives_GLSLFeature: { | 81 case kStandardDerivatives_GLSLFeature: { |
82 GrGpuGL* gpu = fProgramBuilder->gpu(); | 82 GrGLGpu* gpu = fProgramBuilder->gpu(); |
83 if (!gpu->glCaps().shaderDerivativeSupport()) { | 83 if (!gpu->glCaps().shaderDerivativeSupport()) { |
84 return false; | 84 return false; |
85 } | 85 } |
86 if (kGLES_GrGLStandard == gpu->glStandard() && | 86 if (kGLES_GrGLStandard == gpu->glStandard() && |
87 k110_GrGLSLGeneration == gpu->glslGeneration()) { | 87 k110_GrGLSLGeneration == gpu->glslGeneration()) { |
88 this->addFeature(1 << kStandardDerivatives_GLSLFeature, | 88 this->addFeature(1 << kStandardDerivatives_GLSLFeature, |
89 "GL_OES_standard_derivatives"); | 89 "GL_OES_standard_derivatives"); |
90 } | 90 } |
91 return true; | 91 return true; |
92 } | 92 } |
(...skipping 15 matching lines...) Expand all Loading... |
108 coords2D.appendf("_%i", index); | 108 coords2D.appendf("_%i", index); |
109 } | 109 } |
110 this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", | 110 this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", |
111 coords2D.c_str(), coords[index].c_str(), coords[index].c_s
tr()); | 111 coords2D.c_str(), coords[index].c_str(), coords[index].c_s
tr()); |
112 return coords2D; | 112 return coords2D; |
113 } | 113 } |
114 | 114 |
115 const char* GrGLFragmentShaderBuilder::fragmentPosition() { | 115 const char* GrGLFragmentShaderBuilder::fragmentPosition() { |
116 fHasReadFragmentPosition = true; | 116 fHasReadFragmentPosition = true; |
117 | 117 |
118 GrGpuGL* gpu = fProgramBuilder->gpu(); | 118 GrGLGpu* gpu = fProgramBuilder->gpu(); |
119 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers | 119 // We only declare "gl_FragCoord" when we're in the case where we want to us
e layout qualifiers |
120 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the | 120 // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier
appears in the |
121 // declaration varies in earlier GLSL specs. So it is simpler to omit it. | 121 // declaration varies in earlier GLSL specs. So it is simpler to omit it. |
122 if (fTopLeftFragPosRead) { | 122 if (fTopLeftFragPosRead) { |
123 fSetupFragPosition = true; | 123 fSetupFragPosition = true; |
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, |
(...skipping 30 matching lines...) Expand all Loading... |
159 fSetupFragPosition = true; | 159 fSetupFragPosition = true; |
160 } | 160 } |
161 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); | 161 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); |
162 return kCoordName; | 162 return kCoordName; |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 const char* GrGLFragmentShaderBuilder::dstColor() { | 166 const char* GrGLFragmentShaderBuilder::dstColor() { |
167 fHasReadDstColor = true; | 167 fHasReadDstColor = true; |
168 | 168 |
169 GrGpuGL* gpu = fProgramBuilder->gpu(); | 169 GrGLGpu* gpu = fProgramBuilder->gpu(); |
170 if (gpu->glCaps().fbFetchSupport()) { | 170 if (gpu->glCaps().fbFetchSupport()) { |
171 this->addFeature(1 << (GrGLFragmentShaderBuilder::kLastGLSLPrivateFeatur
e + 1), | 171 this->addFeature(1 << (GrGLFragmentShaderBuilder::kLastGLSLPrivateFeatur
e + 1), |
172 gpu->glCaps().fbFetchExtensionString()); | 172 gpu->glCaps().fbFetchExtensionString()); |
173 | 173 |
174 // On ES 3.0 we have to declare this, and use the custom color output na
me | 174 // On ES 3.0 we have to declare this, and use the custom color output na
me |
175 const char* fbFetchColorName = gpu->glCaps().fbFetchColorName(); | 175 const char* fbFetchColorName = gpu->glCaps().fbFetchColorName(); |
176 if (gpu->glslGeneration() >= k330_GrGLSLGeneration) { | 176 if (gpu->glslGeneration() >= k330_GrGLSLGeneration) { |
177 this->enableCustomOutput(); | 177 this->enableCustomOutput(); |
178 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOu
t_TypeModifier); | 178 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOu
t_TypeModifier); |
179 fbFetchColorName = declared_color_output_name(); | 179 fbFetchColorName = declared_color_output_name(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, | 259 bool GrGLFragmentShaderBuilder::compileAndAttachShaders(GrGLuint programId, |
260 SkTDArray<GrGLuint>* sha
derIds) const { | 260 SkTDArray<GrGLuint>* sha
derIds) const { |
261 GrGpuGL* gpu = fProgramBuilder->gpu(); | 261 GrGLGpu* gpu = fProgramBuilder->gpu(); |
262 SkString fragShaderSrc(GrGetGLSLVersionDecl(gpu->ctxInfo())); | 262 SkString fragShaderSrc(GrGetGLSLVersionDecl(gpu->ctxInfo())); |
263 fragShaderSrc.append(fExtensions); | 263 fragShaderSrc.append(fExtensions); |
264 append_default_precision_qualifier(kDefault_GrSLPrecision, | 264 append_default_precision_qualifier(kDefault_GrSLPrecision, |
265 gpu->glStandard(), | 265 gpu->glStandard(), |
266 &fragShaderSrc); | 266 &fragShaderSrc); |
267 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, &fragShaderSrc); | 267 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kFragment_Visibility
, &fragShaderSrc); |
268 this->appendDecls(fInputs, &fragShaderSrc); | 268 this->appendDecls(fInputs, &fragShaderSrc); |
269 // We shouldn't have declared outputs on 1.10 | 269 // We shouldn't have declared outputs on 1.10 |
270 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; | 270 SkASSERT(k110_GrGLSLGeneration != gpu->glslGeneration() || fOutputs.empty())
; |
271 this->appendDecls(fOutputs, &fragShaderSrc); | 271 this->appendDecls(fOutputs, &fragShaderSrc); |
(...skipping 25 matching lines...) Expand all Loading... |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ | 300 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ |
301 v->fFsIn = v->fVsOut; | 301 v->fFsIn = v->fVsOut; |
302 if (v->fGsOut) { | 302 if (v->fGsOut) { |
303 v->fFsIn = v->fGsOut; | 303 v->fFsIn = v->fGsOut; |
304 } | 304 } |
305 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); | 305 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); |
306 } | 306 } |
OLD | NEW |