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::appendSampleOffset(const char* sampleIdx) { | |
174 SkASSERT(fProgramBuilder->pipeline().hasSampleLocations()); | |
Chris Dalton
2016/02/23 01:51:01
I guess maskSampleCoverage() does a test/SkDEBUGFA
| |
175 this->codeAppendf("sampleOffsets[%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 sampleOffsets[] = vec2[]("); | |
323 for (int i = 0; i < effectiveSampleCnt; ++i) { | |
324 this->definitions().appendf("vec2(%f, %f)%s", | |
325 sampleLocations[i].x() - 0.5f, | |
326 sampleLocations[i].y() - 0.5f, | |
327 i + 1 != effectiveSampleCnt ? ", " : "); \n"); | |
328 } | |
329 SkASSERT(fProgramBuilder->header().fSamplePatternKey == pipeline.getSamp lePatternID()); | |
330 } | |
309 } | 331 } |
310 | 332 |
311 void GrGLSLFragmentShaderBuilder::onBeforeChildProcEmitCode() { | 333 void GrGLSLFragmentShaderBuilder::onBeforeChildProcEmitCode() { |
312 SkASSERT(fSubstageIndices.count() >= 1); | 334 SkASSERT(fSubstageIndices.count() >= 1); |
313 fSubstageIndices.push_back(0); | 335 fSubstageIndices.push_back(0); |
314 // second-to-last value in the fSubstageIndices stack is the index of the ch ild proc | 336 // 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. | 337 // at that level which is currently emitting code. |
316 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2] ); | 338 fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2] ); |
317 } | 339 } |
318 | 340 |
319 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { | 341 void GrGLSLFragmentShaderBuilder::onAfterChildProcEmitCode() { |
320 SkASSERT(fSubstageIndices.count() >= 2); | 342 SkASSERT(fSubstageIndices.count() >= 2); |
321 fSubstageIndices.pop_back(); | 343 fSubstageIndices.pop_back(); |
322 fSubstageIndices.back()++; | 344 fSubstageIndices.back()++; |
323 int removeAt = fMangleString.findLastOf('_'); | 345 int removeAt = fMangleString.findLastOf('_'); |
324 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 346 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
325 } | 347 } |
326 | 348 |
OLD | NEW |