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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 GrGLFragmentShaderBuilder::GrGLFragmentShaderBuilder(GrGLProgramBuilder* program
, | 71 GrGLFragmentShaderBuilder::GrGLFragmentShaderBuilder(GrGLProgramBuilder* program
, |
72 const GrGLProgramDesc& desc
) | 72 const GrGLProgramDesc& desc
) |
73 : INHERITED(program) | 73 : INHERITED(program) |
74 , fHasCustomColorOutput(false) | 74 , fHasCustomColorOutput(false) |
75 , fHasSecondaryOutput(false) | 75 , fHasSecondaryOutput(false) |
76 , fSetupFragPosition(false) | 76 , fSetupFragPosition(false) |
77 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr
agPosKey) | 77 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr
agPosKey) |
| 78 , fCustomColorOutputIndex(-1) |
78 , fHasReadDstColor(false) | 79 , fHasReadDstColor(false) |
79 , fHasReadFragmentPosition(false) { | 80 , fHasReadFragmentPosition(false) { |
80 } | 81 } |
81 | 82 |
82 bool GrGLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { | 83 bool GrGLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { |
83 switch (feature) { | 84 switch (feature) { |
84 case kStandardDerivatives_GLSLFeature: { | 85 case kStandardDerivatives_GLSLFeature: { |
85 GrGpuGL* gpu = fProgramBuilder->gpu(); | 86 GrGpuGL* gpu = fProgramBuilder->gpu(); |
86 if (!gpu->glCaps().shaderDerivativeSupport()) { | 87 if (!gpu->glCaps().shaderDerivativeSupport()) { |
87 return false; | 88 return false; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 166 } |
166 } | 167 } |
167 | 168 |
168 const char* GrGLFragmentShaderBuilder::dstColor() { | 169 const char* GrGLFragmentShaderBuilder::dstColor() { |
169 fHasReadDstColor = true; | 170 fHasReadDstColor = true; |
170 | 171 |
171 GrGpuGL* gpu = fProgramBuilder->gpu(); | 172 GrGpuGL* gpu = fProgramBuilder->gpu(); |
172 if (gpu->glCaps().fbFetchSupport()) { | 173 if (gpu->glCaps().fbFetchSupport()) { |
173 this->addFeature(1 << (GrGLFragmentShaderBuilder::kLastGLSLPrivateFeatur
e + 1), | 174 this->addFeature(1 << (GrGLFragmentShaderBuilder::kLastGLSLPrivateFeatur
e + 1), |
174 gpu->glCaps().fbFetchExtensionString()); | 175 gpu->glCaps().fbFetchExtensionString()); |
175 return gpu->glCaps().fbFetchColorName(); | 176 |
| 177 // On ES 3.0 we have to declare this, and use the custom color output na
me |
| 178 const char* fbFetchColorName = gpu->glCaps().fbFetchColorName(); |
| 179 if (gpu->glslGeneration() >= k330_GrGLSLGeneration) { |
| 180 this->enableCustomOutput(); |
| 181 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOu
t_TypeModifier); |
| 182 fbFetchColorName = declared_color_output_name(); |
| 183 } |
| 184 return fbFetchColorName; |
176 } else if (fProgramBuilder->fUniformHandles.fDstCopySamplerUni.isValid()) { | 185 } else if (fProgramBuilder->fUniformHandles.fDstCopySamplerUni.isValid()) { |
177 return kDstCopyColorName; | 186 return kDstCopyColorName; |
178 } else { | 187 } else { |
179 return ""; | 188 return ""; |
180 } | 189 } |
181 } | 190 } |
182 | 191 |
183 void GrGLFragmentShaderBuilder::emitCodeToReadDstTexture() { | 192 void GrGLFragmentShaderBuilder::emitCodeToReadDstTexture() { |
184 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & fProgramBuilder->head
er().fDstReadKey); | 193 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & fProgramBuilder->head
er().fDstReadKey); |
185 const char* dstCopyTopLeftName; | 194 const char* dstCopyTopLeftName; |
(...skipping 30 matching lines...) Expand all Loading... |
216 } | 225 } |
217 this->codeAppendf("vec4 %s = ", GrGLFragmentShaderBuilder::kDstCopyColorName
); | 226 this->codeAppendf("vec4 %s = ", GrGLFragmentShaderBuilder::kDstCopyColorName
); |
218 this->appendTextureLookup(dstCopySamplerName, | 227 this->appendTextureLookup(dstCopySamplerName, |
219 "_dstTexCoord", | 228 "_dstTexCoord", |
220 configMask, | 229 configMask, |
221 "rgba"); | 230 "rgba"); |
222 this->codeAppend(";"); | 231 this->codeAppend(";"); |
223 } | 232 } |
224 | 233 |
225 void GrGLFragmentShaderBuilder::enableCustomOutput() { | 234 void GrGLFragmentShaderBuilder::enableCustomOutput() { |
226 SkASSERT(!fHasCustomColorOutput); | 235 if (!fHasCustomColorOutput) { |
227 fHasCustomColorOutput = true; | 236 fHasCustomColorOutput = true; |
228 fOutputs.push_back().set(kVec4f_GrSLType, | 237 fCustomColorOutputIndex = fOutputs.count(); |
229 GrGLShaderVar::kOut_TypeModifier, | 238 fOutputs.push_back().set(kVec4f_GrSLType, |
230 declared_color_output_name()); | 239 GrGLShaderVar::kOut_TypeModifier, |
| 240 declared_color_output_name()); |
| 241 } |
231 } | 242 } |
232 | 243 |
233 void GrGLFragmentShaderBuilder::enableSecondaryOutput() { | 244 void GrGLFragmentShaderBuilder::enableSecondaryOutput() { |
234 SkASSERT(!fHasSecondaryOutput); | 245 SkASSERT(!fHasSecondaryOutput); |
235 fHasSecondaryOutput = true; | 246 fHasSecondaryOutput = true; |
236 fOutputs.push_back().set(kVec4f_GrSLType, GrGLShaderVar::kOut_TypeModifier, | 247 fOutputs.push_back().set(kVec4f_GrSLType, GrGLShaderVar::kOut_TypeModifier, |
237 dual_source_output_name()); | 248 dual_source_output_name()); |
238 } | 249 } |
239 | 250 |
240 const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const { | 251 const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 348 |
338 void GrGLFragmentShaderBuilder::addVarying(GrSLType type, | 349 void GrGLFragmentShaderBuilder::addVarying(GrSLType type, |
339 const char* name, | 350 const char* name, |
340 const char** fsInName, | 351 const char** fsInName, |
341 GrGLShaderVar::Precision fsPrecision) { | 352 GrGLShaderVar::Precision fsPrecision) { |
342 fInputs.push_back().set(type, GrGLShaderVar::kVaryingIn_TypeModifier, name,
fsPrecision); | 353 fInputs.push_back().set(type, GrGLShaderVar::kVaryingIn_TypeModifier, name,
fsPrecision); |
343 if (fsInName) { | 354 if (fsInName) { |
344 *fsInName = name; | 355 *fsInName = name; |
345 } | 356 } |
346 } | 357 } |
OLD | NEW |