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 "GrGLSLFragmentShaderBuilder.h" | 8 #include "GrGLSLFragmentShaderBuilder.h" |
9 #include "GrRenderTarget.h" | 9 #include "GrRenderTarget.h" |
10 #include "gl/GrGLGpu.h" | 10 #include "gl/GrGLGpu.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
212 void GrGLSLFragmentShaderBuilder::enableCustomOutput() { | 212 void GrGLSLFragmentShaderBuilder::enableCustomOutput() { |
213 if (!fHasCustomColorOutput) { | 213 if (!fHasCustomColorOutput) { |
214 fHasCustomColorOutput = true; | 214 fHasCustomColorOutput = true; |
215 fCustomColorOutputIndex = fOutputs.count(); | 215 fCustomColorOutputIndex = fOutputs.count(); |
216 fOutputs.push_back().set(kVec4f_GrSLType, | 216 fOutputs.push_back().set(kVec4f_GrSLType, |
217 GrGLSLShaderVar::kOut_TypeModifier, | 217 GrGLSLShaderVar::kOut_TypeModifier, |
218 DeclaredColorOutputName()); | 218 DeclaredColorOutputName()); |
| 219 fProgramBuilder->finalizeFragmentOutputColor(fOutputs.back()); |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
222 void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() { | 223 void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() { |
223 SkASSERT(!fHasSecondaryOutput); | 224 SkASSERT(!fHasSecondaryOutput); |
224 fHasSecondaryOutput = true; | 225 fHasSecondaryOutput = true; |
225 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); | 226 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
226 if (const char* extension = caps.secondaryOutputExtensionString()) { | 227 if (const char* extension = caps.secondaryOutputExtensionString()) { |
227 this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension); | 228 this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension); |
228 } | 229 } |
229 | 230 |
230 // If the primary output is declared, we must declare also the secondary out
put | 231 // If the primary output is declared, we must declare also the secondary out
put |
231 // and vice versa, since it is not allowed to use a built-in gl_FragColor an
d a custom | 232 // and vice versa, since it is not allowed to use a built-in gl_FragColor an
d a custom |
232 // output. The condition also co-incides with the condition in whici GLES SL
2.0 | 233 // output. The condition also co-incides with the condition in whici GLES SL
2.0 |
233 // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a c
ustom output. | 234 // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a c
ustom output. |
234 if (caps.mustDeclareFragmentShaderOutput()) { | 235 if (caps.mustDeclareFragmentShaderOutput()) { |
235 fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModi
fier, | 236 fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModi
fier, |
236 DeclaredSecondaryColorOutputName()); | 237 DeclaredSecondaryColorOutputName()); |
| 238 fProgramBuilder->finalizeFragmentSecondaryColor(fOutputs.back()); |
237 } | 239 } |
238 } | 240 } |
239 | 241 |
240 const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const { | 242 const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const { |
241 return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor"; | 243 return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor"; |
242 } | 244 } |
243 | 245 |
244 void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) { | 246 void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) { |
245 va_list argp; | 247 va_list argp; |
246 va_start(argp, fmt); | 248 va_start(argp, fmt); |
(...skipping 23 matching lines...) Expand all Loading... |
270 } | 272 } |
271 | 273 |
272 void GrGLSLFragmentBuilder::onAfterChildProcEmitCode() { | 274 void GrGLSLFragmentBuilder::onAfterChildProcEmitCode() { |
273 SkASSERT(fSubstageIndices.count() >= 2); | 275 SkASSERT(fSubstageIndices.count() >= 2); |
274 fSubstageIndices.pop_back(); | 276 fSubstageIndices.pop_back(); |
275 fSubstageIndices.back()++; | 277 fSubstageIndices.back()++; |
276 int removeAt = fMangleString.findLastOf('_'); | 278 int removeAt = fMangleString.findLastOf('_'); |
277 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 279 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
278 } | 280 } |
279 | 281 |
OLD | NEW |