| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 uint8_t fragPosKey) | 70 uint8_t fragPosKey) |
| 71 : INHERITED(program) | 71 : INHERITED(program) |
| 72 , fSetupFragPosition(false) | 72 , fSetupFragPosition(false) |
| 73 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey) | 73 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey) |
| 74 , fCustomColorOutputIndex(-1) | 74 , fCustomColorOutputIndex(-1) |
| 75 , fHasReadDstColor(false) | 75 , fHasReadDstColor(false) |
| 76 , fHasReadFragmentPosition(false) { | 76 , fHasReadFragmentPosition(false) { |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { | 79 bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { |
| 80 const GrGLSLCaps& glslCaps = *fProgramBuilder->glslCaps(); |
| 80 switch (feature) { | 81 switch (feature) { |
| 81 case kStandardDerivatives_GLSLFeature: { | 82 case kStandardDerivatives_GLSLFeature: |
| 82 if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) { | 83 if (!glslCaps.shaderDerivativeSupport()) { |
| 83 return false; | 84 return false; |
| 84 } | 85 } |
| 85 const char* extension = fProgramBuilder->glslCaps()->shaderDerivativ
eExtensionString(); | 86 if (const char* extension = glslCaps.shaderDerivativeExtensionString
()) { |
| 86 if (extension) { | |
| 87 this->addFeature(1 << kStandardDerivatives_GLSLFeature, extensio
n); | 87 this->addFeature(1 << kStandardDerivatives_GLSLFeature, extensio
n); |
| 88 } | 88 } |
| 89 return true; | 89 return true; |
| 90 } | 90 case kPixelLocalStorage_GLSLFeature: |
| 91 case kPixelLocalStorage_GLSLFeature: { | |
| 92 if (fProgramBuilder->glslCaps()->pixelLocalStorageSize() <= 0) { | 91 if (fProgramBuilder->glslCaps()->pixelLocalStorageSize() <= 0) { |
| 93 return false; | 92 return false; |
| 94 } | 93 } |
| 95 this->addFeature(1 << kPixelLocalStorage_GLSLFeature, | 94 this->addFeature(1 << kPixelLocalStorage_GLSLFeature, |
| 96 "GL_EXT_shader_pixel_local_storage"); | 95 "GL_EXT_shader_pixel_local_storage"); |
| 97 return true; | 96 return true; |
| 98 } | 97 case kSampleVariables_GLSLFeature: |
| 98 if (!glslCaps.sampleVariablesSupport()) { |
| 99 return false; |
| 100 } |
| 101 if (const char* extension = glslCaps.sampleVariablesExtensionString(
)) { |
| 102 this->addFeature(1 << kSampleVariables_GLSLFeature, extension); |
| 103 } |
| 104 return true; |
| 105 case kSampleMaskOverrideCoverage_GLSLFeature: |
| 106 if (!glslCaps.sampleMaskOverrideCoverageSupport()) { |
| 107 return false; |
| 108 } |
| 109 if (!this->enableFeature(kSampleVariables_GLSLFeature)) { |
| 110 return false; |
| 111 } |
| 112 if (this->addFeature(1 << kSampleMaskOverrideCoverage_GLSLFeature, |
| 113 "GL_NV_sample_mask_override_coverage")) { |
| 114 // Redeclare gl_SampleMask with layout(override_coverage) if we
haven't already. |
| 115 fOutputs.push_back().set(kInt_GrSLType, GrShaderVar::kOut_TypeMo
difier, |
| 116 "gl_SampleMask", 1, kHigh_GrSLPrecision
, |
| 117 "override_coverage"); |
| 118 } |
| 119 return true; |
| 99 default: | 120 default: |
| 100 SkFAIL("Unexpected GLSLFeature requested."); | 121 SkFAIL("Unexpected GLSLFeature requested."); |
| 101 return false; | 122 return false; |
| 102 } | 123 } |
| 103 } | 124 } |
| 104 | 125 |
| 105 SkString GrGLSLFragmentShaderBuilder::ensureFSCoords2D(const GrGLSLTransformedCo
ordsArray& coords, | 126 SkString GrGLSLFragmentShaderBuilder::ensureFSCoords2D(const GrGLSLTransformedCo
ordsArray& coords, |
| 106 int index) { | 127 int index) { |
| 107 if (kVec3f_GrSLType != coords[index].getType()) { | 128 if (kVec3f_GrSLType != coords[index].getType()) { |
| 108 SkASSERT(kVec2f_GrSLType == coords[index].getType()); | 129 SkASSERT(kVec2f_GrSLType == coords[index].getType()); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 293 } |
| 273 | 294 |
| 274 void GrGLSLFragmentBuilder::onAfterChildProcEmitCode() { | 295 void GrGLSLFragmentBuilder::onAfterChildProcEmitCode() { |
| 275 SkASSERT(fSubstageIndices.count() >= 2); | 296 SkASSERT(fSubstageIndices.count() >= 2); |
| 276 fSubstageIndices.pop_back(); | 297 fSubstageIndices.pop_back(); |
| 277 fSubstageIndices.back()++; | 298 fSubstageIndices.back()++; |
| 278 int removeAt = fMangleString.findLastOf('_'); | 299 int removeAt = fMangleString.findLastOf('_'); |
| 279 fMangleString.remove(removeAt, fMangleString.size() - removeAt); | 300 fMangleString.remove(removeAt, fMangleString.size() - removeAt); |
| 280 } | 301 } |
| 281 | 302 |
| OLD | NEW |