| 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 "GrRenderTargetPriv.h" | 10 #include "GrRenderTargetPriv.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 static const char* kTempName = "tmpXYFragCoord"; | 169 static const char* kTempName = "tmpXYFragCoord"; |
| 170 static const char* kCoordName = "fragCoordYDown"; | 170 static const char* kCoordName = "fragCoordYDown"; |
| 171 if (!fSetupFragPosition) { | 171 if (!fSetupFragPosition) { |
| 172 const char* rtHeightName; | 172 const char* rtHeightName; |
| 173 | 173 |
| 174 fProgramBuilder->addRTHeightUniform("RTHeight", &rtHeightName); | 174 fProgramBuilder->addRTHeightUniform("RTHeight", &rtHeightName); |
| 175 | 175 |
| 176 // The Adreno compiler seems to be very touchy about access to "gl_F
ragCoord". | 176 // The Adreno compiler seems to be very touchy about access to "gl_F
ragCoord". |
| 177 // Accessing glFragCoord.zw can cause a program to fail to link. Add
itionally, | 177 // Accessing glFragCoord.zw can cause a program to fail to link. Add
itionally, |
| 178 // depending on the surrounding code, accessing .xy with a uniform i
nvolved can | 178 // depending on the surrounding code, accessing .xy with a uniform i
nvolved can |
| 179 // do the same thing. Copying gl_FragCoord.xy into a temp vec2 befor
ehand | 179 // do the same thing. Copying gl_FragCoord.xy into a temp vec2 befor
ehand |
| 180 // (and only accessing .xy) seems to "fix" things. | 180 // (and only accessing .xy) seems to "fix" things. |
| 181 const char* precision = glslCaps->usesPrecisionModifiers() ? "highp
" : ""; | 181 const char* precision = glslCaps->usesPrecisionModifiers() ? "highp
" : ""; |
| 182 this->codePrependf("\t%svec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n
", | 182 this->codePrependf("\t%svec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n
", |
| 183 precision, kCoordName, kTempName, rtHeightName, k
TempName); | 183 precision, kCoordName, kTempName, rtHeightName, k
TempName); |
| 184 this->codePrependf("%svec2 %s = gl_FragCoord.xy;", precision, kTempN
ame); | 184 this->codePrependf("%svec2 %s = gl_FragCoord.xy;", precision, kTempN
ame); |
| 185 fSetupFragPosition = true; | 185 fSetupFragPosition = true; |
| 186 } | 186 } |
| 187 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); | 187 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); |
| 188 return kCoordName; | 188 return kCoordName; |
| 189 } | 189 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // Some versions of this extension string require declaring custom color
output on ES 3.0+ | 257 // Some versions of this extension string require declaring custom color
output on ES 3.0+ |
| 258 const char* fbFetchColorName = glslCaps->fbFetchColorName(); | 258 const char* fbFetchColorName = glslCaps->fbFetchColorName(); |
| 259 if (glslCaps->fbFetchNeedsCustomOutput()) { | 259 if (glslCaps->fbFetchNeedsCustomOutput()) { |
| 260 this->enableCustomOutput(); | 260 this->enableCustomOutput(); |
| 261 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOu
t_TypeModifier); | 261 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOu
t_TypeModifier); |
| 262 fbFetchColorName = DeclaredColorOutputName(); | 262 fbFetchColorName = DeclaredColorOutputName(); |
| 263 } | 263 } |
| 264 return fbFetchColorName; | 264 return fbFetchColorName; |
| 265 } else { | 265 } else { |
| 266 return kDstTextureColorName; | 266 return kDstTextureColorName; |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 | 269 |
| 270 void GrGLSLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEqu
ation equation) { | 270 void GrGLSLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEqu
ation equation) { |
| 271 SkASSERT(GrBlendEquationIsAdvanced(equation)); | 271 SkASSERT(GrBlendEquationIsAdvanced(equation)); |
| 272 | 272 |
| 273 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); | 273 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
| 274 if (!caps.mustEnableAdvBlendEqs()) { | 274 if (!caps.mustEnableAdvBlendEqs()) { |
| 275 return; | 275 return; |
| 276 } | 276 } |
| 277 | 277 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 315 } |
| 316 | 316 |
| 317 const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const { | 317 const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const { |
| 318 return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor"; | 318 return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor"; |
| 319 } | 319 } |
| 320 | 320 |
| 321 void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) { | 321 void GrGLSLFragmentBuilder::declAppendf(const char* fmt, ...) { |
| 322 va_list argp; | 322 va_list argp; |
| 323 va_start(argp, fmt); | 323 va_start(argp, fmt); |
| 324 inputs().appendVAList(fmt, argp); | 324 inputs().appendVAList(fmt, argp); |
| 325 va_end(argp); | 325 va_end(argp); |
| 326 } | 326 } |
| 327 | 327 |
| 328 const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const { | 328 const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const { |
| 329 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); | 329 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
| 330 return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutput
Name() | 330 return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutput
Name() |
| 331 : "gl_SecondaryFragColorEXT"; | 331 : "gl_SecondaryFragColorEXT"; |
| 332 } | 332 } |
| 333 | 333 |
| 334 GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const { | 334 GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const { |
| 335 SkASSERT(fProgramBuilder->header().fSurfaceOriginKey); | 335 SkASSERT(fProgramBuilder->header().fSurfaceOriginKey); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]
); | 385 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]
); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { | 388 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { |
| 389 SkASSERT(fSubstageIndices.count() >= 2); | 389 SkASSERT(fSubstageIndices.count() >= 2); |
| 390 fSubstageIndices.pop_back(); | 390 fSubstageIndices.pop_back(); |
| 391 fSubstageIndices.back()++; | 391 fSubstageIndices.back()++; |
| 392 int removeAt = fMangleString.findLastOf('_'); | 392 int removeAt = fMangleString.findLastOf('_'); |
| 393 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 393 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
| 394 } | 394 } |
| 395 | |
| OLD | NEW |