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