| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 this->codePrependf("\t%svec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n
", | 163 this->codePrependf("\t%svec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n
", |
| 164 precision, kCoordName, kTempName, rtHeightName, k
TempName); | 164 precision, kCoordName, kTempName, rtHeightName, k
TempName); |
| 165 this->codePrependf("%svec2 %s = gl_FragCoord.xy;", precision, kTempN
ame); | 165 this->codePrependf("%svec2 %s = gl_FragCoord.xy;", precision, kTempN
ame); |
| 166 fSetupFragPosition = true; | 166 fSetupFragPosition = true; |
| 167 } | 167 } |
| 168 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); | 168 SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid()); |
| 169 return kCoordName; | 169 return kCoordName; |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 void GrGLSLFragmentShaderBuilder::appendSampleLocation(const char* sampleIdx) { |
| 174 SkASSERT(fProgramBuilder->pipeline().hasSampleLocations()); |
| 175 this->codeAppendf("sampleLocations[%s]", sampleIdx); |
| 176 } |
| 177 |
| 173 void GrGLSLFragmentShaderBuilder::maskSampleCoverage(const char* mask, bool inve
rt) { | 178 void GrGLSLFragmentShaderBuilder::maskSampleCoverage(const char* mask, bool inve
rt) { |
| 174 const GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps(); | 179 const GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps(); |
| 175 if (!glslCaps.sampleVariablesSupport()) { | 180 if (!glslCaps.sampleVariablesSupport()) { |
| 176 SkDEBUGFAIL("Attempted to mask sample coverage without support."); | 181 SkDEBUGFAIL("Attempted to mask sample coverage without support."); |
| 177 return; | 182 return; |
| 178 } | 183 } |
| 179 if (const char* extension = glslCaps.sampleVariablesExtensionString()) { | 184 if (const char* extension = glslCaps.sampleVariablesExtensionString()) { |
| 180 this->addFeature(1 << kSampleVariables_GLSLPrivateFeature, extension); | 185 this->addFeature(1 << kSampleVariables_GLSLPrivateFeature, extension); |
| 181 } | 186 } |
| 182 if (!fHasInitializedSampleMask) { | 187 if (!fHasInitializedSampleMask) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); | 304 const GrGLSLCaps& caps = *fProgramBuilder->glslCaps(); |
| 300 return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutput
Name() | 305 return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutput
Name() |
| 301 : "gl_SecondaryFragColorEXT"; | 306 : "gl_SecondaryFragColorEXT"; |
| 302 } | 307 } |
| 303 | 308 |
| 304 void GrGLSLFragmentShaderBuilder::onFinalize() { | 309 void GrGLSLFragmentShaderBuilder::onFinalize() { |
| 305 fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outp
uts()); | 310 fProgramBuilder->varyingHandler()->getFragDecls(&this->inputs(), &this->outp
uts()); |
| 306 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, | 311 GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision, |
| 307 *fProgramBuilder->glslCaps(), | 312 *fProgramBuilder->glslCaps(), |
| 308 &this->precisionQualifier()); | 313 &this->precisionQualifier()); |
| 314 if (fProgramBuilder->pipeline().hasSampleLocations()) { |
| 315 const GrPipeline& pipeline = fProgramBuilder->pipeline(); |
| 316 int effectiveSampleCnt = pipeline.effectiveSampleCount(); |
| 317 const SkPoint* sampleLocations = pipeline.getSampleLocations(); |
| 318 this->definitions().append("const "); |
| 319 if (fProgramBuilder->glslCaps()->usesPrecisionModifiers()) { |
| 320 this->definitions().append("highp "); |
| 321 } |
| 322 this->definitions().appendf("vec2 sampleLocations[] = vec2[]("); |
| 323 for (int i = 0; i < effectiveSampleCnt; ++i) { |
| 324 this->definitions().appendf("vec2(%f, %f)%s", |
| 325 sampleLocations[i].x(), sampleLocations[
i].y(), |
| 326 i + 1 != effectiveSampleCnt ? ", " : ");
\n"); |
| 327 } |
| 328 SkASSERT(fProgramBuilder->header().fSamplePatternKey == pipeline.getSamp
lePatternID()); |
| 329 } |
| 309 } | 330 } |
| 310 | 331 |
| 311 void GrGLSLFragmentShaderBuilder::onBeforeChildProcEmitCode() { | 332 void GrGLSLFragmentShaderBuilder::onBeforeChildProcEmitCode() { |
| 312 SkASSERT(fSubstageIndices.count() >= 1); | 333 SkASSERT(fSubstageIndices.count() >= 1); |
| 313 fSubstageIndices.push_back(0); | 334 fSubstageIndices.push_back(0); |
| 314 // second-to-last value in the fSubstageIndices stack is the index of the ch
ild proc | 335 // second-to-last value in the fSubstageIndices stack is the index of the ch
ild proc |
| 315 // at that level which is currently emitting code. | 336 // at that level which is currently emitting code. |
| 316 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]
); | 337 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]
); |
| 317 } | 338 } |
| 318 | 339 |
| 319 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { | 340 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { |
| 320 SkASSERT(fSubstageIndices.count() >= 2); | 341 SkASSERT(fSubstageIndices.count() >= 2); |
| 321 fSubstageIndices.pop_back(); | 342 fSubstageIndices.pop_back(); |
| 322 fSubstageIndices.back()++; | 343 fSubstageIndices.back()++; |
| 323 int removeAt = fMangleString.findLastOf('_'); | 344 int removeAt = fMangleString.findLastOf('_'); |
| 324 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 345 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
| 325 } | 346 } |
| 326 | 347 |
| OLD | NEW |