| 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 "GrGLFragmentShaderBuilder.h" | 8 #include "GrGLFragmentShaderBuilder.h" |
| 9 #include "GrGLShaderStringBuilder.h" | 9 #include "GrGLShaderStringBuilder.h" |
| 10 #include "GrGLProgramBuilder.h" | 10 #include "GrGLProgramBuilder.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 break; | 35 break; |
| 36 case GrGLShaderVar::kDefault_Precision: | 36 case GrGLShaderVar::kDefault_Precision: |
| 37 SkFAIL("Default precision now allowed."); | 37 SkFAIL("Default precision now allowed."); |
| 38 default: | 38 default: |
| 39 SkFAIL("Unknown precision value."); | 39 SkFAIL("Unknown precision value."); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 GrGLFragmentShaderBuilder::DstReadKey | 44 GrGLFragmentShaderBuilder::DstReadKey |
| 45 GrGLFragmentShaderBuilder::KeyForDstRead(const GrTexture* dstCopy, const GrGLCap
s& caps) { | 45 GrGLFragmentShaderBuilder::KeyForDstRead(const GrTexture* dstCopy, |
| 46 const GrGLCaps&
caps) { |
| 46 uint32_t key = kYesDstRead_DstReadKeyBit; | 47 uint32_t key = kYesDstRead_DstReadKeyBit; |
| 47 if (caps.fbFetchSupport()) { | 48 if (caps.fbFetchSupport()) { |
| 48 return key; | 49 return key; |
| 49 } | 50 } |
| 50 SkASSERT(dstCopy); | 51 SkASSERT(dstCopy); |
| 51 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi
g())) { | 52 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi
g())) { |
| 52 // The fact that the config is alpha-only must be considered when genera
ting code. | 53 // The fact that the config is alpha-only must be considered when genera
ting code. |
| 53 key |= kUseAlphaConfig_DstReadKeyBit; | 54 key |= kUseAlphaConfig_DstReadKeyBit; |
| 54 } | 55 } |
| 55 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { | 56 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { |
| 56 key |= kTopLeftOrigin_DstReadKeyBit; | 57 key |= kTopLeftOrigin_DstReadKeyBit; |
| 57 } | 58 } |
| 58 SkASSERT(static_cast<DstReadKey>(key) == key); | 59 SkASSERT(static_cast<DstReadKey>(key) == key); |
| 59 return static_cast<DstReadKey>(key); | 60 return static_cast<DstReadKey>(key); |
| 60 } | 61 } |
| 61 | 62 |
| 62 GrGLFragmentShaderBuilder::FragPosKey | 63 GrGLFragmentShaderBuilder::FragPosKey |
| 63 GrGLFragmentShaderBuilder::KeyForFragmentPosition(const GrRenderTarget* dst, con
st GrGLCaps&) { | 64 GrGLFragmentShaderBuilder::KeyForFragmentPosition(const GrRenderTarget* dst, |
| 65 const
GrGLCaps&) { |
| 64 if (kTopLeft_GrSurfaceOrigin == dst->origin()) { | 66 if (kTopLeft_GrSurfaceOrigin == dst->origin()) { |
| 65 return kTopLeftFragPosRead_FragPosKey; | 67 return kTopLeftFragPosRead_FragPosKey; |
| 66 } else { | 68 } else { |
| 67 return kBottomLeftFragPosRead_FragPosKey; | 69 return kBottomLeftFragPosRead_FragPosKey; |
| 68 } | 70 } |
| 69 } | 71 } |
| 70 | 72 |
| 71 GrGLFragmentShaderBuilder::GrGLFragmentShaderBuilder(GrGLProgramBuilder* program
, | 73 GrGLFragmentShaderBuilder::GrGLFragmentShaderBuilder(GrGLProgramBuilder* program
, |
| 72 const GrGLProgramDesc& desc
) | 74 const GrGLProgramDesc& desc
) |
| 73 : INHERITED(program) | 75 : INHERITED(program) |
| 74 , fHasCustomColorOutput(false) | 76 , fHasCustomColorOutput(false) |
| 75 , fHasSecondaryOutput(false) | 77 , fHasSecondaryOutput(false) |
| 76 , fSetupFragPosition(false) | 78 , fSetupFragPosition(false) |
| 77 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr
agPosKey) | 79 , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFr
agPosKey) |
| 78 , fHasReadDstColor(false) | 80 , fHasReadDstColor(false) |
| 79 , fHasReadFragmentPosition(false) { | 81 , fHasReadFragmentPosition(false) { |
| 80 } | 82 } |
| 81 | 83 |
| 82 bool GrGLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { | 84 bool GrGLFragmentShaderBuilder::enableFeature(GLSLFeature feature) { |
| 83 switch (feature) { | 85 switch (feature) { |
| 84 case kStandardDerivatives_GLSLFeature: { | 86 case kStandardDerivatives_GLSLFeature: { |
| 85 GrGpuGL* gpu = fProgramBuilder->gpu(); | 87 GrGpuGL* gpu = fProgramBuilder->gpu(); |
| 86 if (!gpu->glCaps().shaderDerivativeSupport()) { | 88 if (!gpu->glCaps().shaderDerivativeSupport()) { |
| 87 return false; | 89 return false; |
| 88 } | 90 } |
| 89 if (kGLES_GrGLStandard == gpu->glStandard() && | 91 if (kGLES_GrGLStandard == gpu->glStandard()) { |
| 90 k110_GrGLSLGeneration == gpu->glslGeneration()) { | |
| 91 this->addFeature(1 << kStandardDerivatives_GLSLFeature, | 92 this->addFeature(1 << kStandardDerivatives_GLSLFeature, |
| 92 "GL_OES_standard_derivatives"); | 93 "GL_OES_standard_derivatives"); |
| 93 } | 94 } |
| 94 return true; | 95 return true; |
| 95 } | 96 } |
| 96 default: | 97 default: |
| 97 SkFAIL("Unexpected GLSLFeature requested."); | 98 SkFAIL("Unexpected GLSLFeature requested."); |
| 98 return false; | 99 return false; |
| 99 } | 100 } |
| 100 } | 101 } |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 if (!fragShaderId) { | 319 if (!fragShaderId) { |
| 319 return false; | 320 return false; |
| 320 } | 321 } |
| 321 | 322 |
| 322 *shaderIds->append() = fragShaderId; | 323 *shaderIds->append() = fragShaderId; |
| 323 | 324 |
| 324 return true; | 325 return true; |
| 325 } | 326 } |
| 326 | 327 |
| 327 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID)
{ | 328 void GrGLFragmentShaderBuilder::bindFragmentShaderLocations(GrGLuint programID)
{ |
| 328 // ES 3.00 requires custom color output but doesn't support bindFragDataLoca
tion | 329 if (fHasCustomColorOutput) { |
| 329 if (fHasCustomColorOutput && | |
| 330 kGLES_GrGLStandard != fProgramBuilder->gpu()->ctxInfo().standard()) { | |
| 331 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); | 330 GL_CALL(BindFragDataLocation(programID, 0, declared_color_output_name())
); |
| 332 } | 331 } |
| 333 if (fHasSecondaryOutput) { | 332 if (fHasSecondaryOutput) { |
| 334 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); | 333 GL_CALL(BindFragDataLocationIndexed(programID, 0, 1, dual_source_output_
name())); |
| 335 } | 334 } |
| 336 } | 335 } |
| 337 | 336 |
| 338 void GrGLFragmentShaderBuilder::addVarying(GrSLType type, | 337 void GrGLFragmentShaderBuilder::addVarying(GrSLType type, |
| 339 const char* name, | 338 const char* name, |
| 340 const char** fsInName, | 339 const char** fsInName, |
| 341 GrGLShaderVar::Precision fsPrecision) { | 340 GrGLShaderVar::Precision fsPrecision) { |
| 342 fInputs.push_back().set(type, GrGLShaderVar::kVaryingIn_TypeModifier, name,
fsPrecision); | 341 fInputs.push_back().set(type, GrGLShaderVar::kVaryingIn_TypeModifier, name,
fsPrecision); |
| 343 if (fsInName) { | 342 if (fsInName) { |
| 344 *fsInName = name; | 343 *fsInName = name; |
| 345 } | 344 } |
| 346 } | 345 } |
| OLD | NEW |