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 "GrGLProgramBuilder.h" | 9 #include "GrGLProgramBuilder.h" |
10 #include "../GrGLGpu.h" | 10 #include "../GrGLGpu.h" |
11 | 11 |
12 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) | 12 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) |
13 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) | 13 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) |
14 | 14 |
15 const char* GrGLFragmentShaderBuilder::kDstTextureColorName = "_dstColor"; | 15 const char* GrGLFragmentShaderBuilder::kDstCopyColorName = "_dstColor"; |
16 static const char* declared_color_output_name() { return "fsColorOut"; } | 16 static const char* declared_color_output_name() { return "fsColorOut"; } |
17 static const char* dual_source_output_name() { return "dualSourceOut"; } | 17 static const char* dual_source_output_name() { return "dualSourceOut"; } |
18 static void append_default_precision_qualifier(GrSLPrecision p, | 18 static void append_default_precision_qualifier(GrSLPrecision p, |
19 GrGLStandard standard, | 19 GrGLStandard standard, |
20 SkString* str) { | 20 SkString* str) { |
21 // Desktop GLSL has added precision qualifiers but they don't do anything. | 21 // Desktop GLSL has added precision qualifiers but they don't do anything. |
22 if (kGLES_GrGLStandard == standard) { | 22 if (kGLES_GrGLStandard == standard) { |
23 switch (p) { | 23 switch (p) { |
24 case kHigh_GrSLPrecision: | 24 case kHigh_GrSLPrecision: |
25 str->append("precision highp float;\n"); | 25 str->append("precision highp float;\n"); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 GR_STATIC_ASSERT(10 == kMultiply_GrBlendEquation - kFirstAdvancedGrBlendEqua
tion); | 71 GR_STATIC_ASSERT(10 == kMultiply_GrBlendEquation - kFirstAdvancedGrBlendEqua
tion); |
72 GR_STATIC_ASSERT(11 == kHSLHue_GrBlendEquation - kFirstAdvancedGrBlendEquati
on); | 72 GR_STATIC_ASSERT(11 == kHSLHue_GrBlendEquation - kFirstAdvancedGrBlendEquati
on); |
73 GR_STATIC_ASSERT(12 == kHSLSaturation_GrBlendEquation - kFirstAdvancedGrBlen
dEquation); | 73 GR_STATIC_ASSERT(12 == kHSLSaturation_GrBlendEquation - kFirstAdvancedGrBlen
dEquation); |
74 GR_STATIC_ASSERT(13 == kHSLColor_GrBlendEquation - kFirstAdvancedGrBlendEqua
tion); | 74 GR_STATIC_ASSERT(13 == kHSLColor_GrBlendEquation - kFirstAdvancedGrBlendEqua
tion); |
75 GR_STATIC_ASSERT(14 == kHSLLuminosity_GrBlendEquation - kFirstAdvancedGrBlen
dEquation); | 75 GR_STATIC_ASSERT(14 == kHSLLuminosity_GrBlendEquation - kFirstAdvancedGrBlen
dEquation); |
76 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kLayoutQualifierNames) == | 76 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kLayoutQualifierNames) == |
77 kGrBlendEquationCnt - kFirstAdvancedGrBlendEquation); | 77 kGrBlendEquationCnt - kFirstAdvancedGrBlendEquation); |
78 } | 78 } |
79 | 79 |
80 GrGLFragmentShaderBuilder::DstReadKey | 80 GrGLFragmentShaderBuilder::DstReadKey |
81 GrGLFragmentShaderBuilder::KeyForDstRead(const GrTexture* dstTexture, const GrGL
Caps& caps) { | 81 GrGLFragmentShaderBuilder::KeyForDstRead(const GrTexture* dstCopy, const GrGLCap
s& caps) { |
82 uint32_t key = kYesDstRead_DstReadKeyBit; | 82 uint32_t key = kYesDstRead_DstReadKeyBit; |
83 if (caps.glslCaps()->fbFetchSupport()) { | 83 if (caps.glslCaps()->fbFetchSupport()) { |
84 return key; | 84 return key; |
85 } | 85 } |
86 SkASSERT(dstTexture); | 86 SkASSERT(dstCopy); |
87 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstTexture->co
nfig())) { | 87 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi
g())) { |
88 // The fact that the config is alpha-only must be considered when genera
ting code. | 88 // The fact that the config is alpha-only must be considered when genera
ting code. |
89 key |= kUseAlphaConfig_DstReadKeyBit; | 89 key |= kUseAlphaConfig_DstReadKeyBit; |
90 } | 90 } |
91 if (kTopLeft_GrSurfaceOrigin == dstTexture->origin()) { | 91 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { |
92 key |= kTopLeftOrigin_DstReadKeyBit; | 92 key |= kTopLeftOrigin_DstReadKeyBit; |
93 } | 93 } |
94 SkASSERT(static_cast<DstReadKey>(key) == key); | 94 SkASSERT(static_cast<DstReadKey>(key) == key); |
95 return static_cast<DstReadKey>(key); | 95 return static_cast<DstReadKey>(key); |
96 } | 96 } |
97 | 97 |
98 GrGLFragmentShaderBuilder::FragPosKey | 98 GrGLFragmentShaderBuilder::FragPosKey |
99 GrGLFragmentShaderBuilder::KeyForFragmentPosition(const GrRenderTarget* dst, con
st GrGLCaps&) { | 99 GrGLFragmentShaderBuilder::KeyForFragmentPosition(const GrRenderTarget* dst, con
st GrGLCaps&) { |
100 if (kTopLeft_GrSurfaceOrigin == dst->origin()) { | 100 if (kTopLeft_GrSurfaceOrigin == dst->origin()) { |
101 return kTopLeftFragPosRead_FragPosKey; | 101 return kTopLeftFragPosRead_FragPosKey; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 // Some versions of this extension string require declaring custom color
output on ES 3.0+ | 214 // Some versions of this extension string require declaring custom color
output on ES 3.0+ |
215 const char* fbFetchColorName = gpu->glCaps().glslCaps()->fbFetchColorNam
e(); | 215 const char* fbFetchColorName = gpu->glCaps().glslCaps()->fbFetchColorNam
e(); |
216 if (gpu->glCaps().glslCaps()->fbFetchNeedsCustomOutput()) { | 216 if (gpu->glCaps().glslCaps()->fbFetchNeedsCustomOutput()) { |
217 this->enableCustomOutput(); | 217 this->enableCustomOutput(); |
218 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOu
t_TypeModifier); | 218 fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOu
t_TypeModifier); |
219 fbFetchColorName = declared_color_output_name(); | 219 fbFetchColorName = declared_color_output_name(); |
220 } | 220 } |
221 return fbFetchColorName; | 221 return fbFetchColorName; |
222 } else { | 222 } else { |
223 return kDstTextureColorName; | 223 return kDstCopyColorName; |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 void GrGLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEquat
ion equation) { | 227 void GrGLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEquat
ion equation) { |
228 SkASSERT(GrBlendEquationIsAdvanced(equation)); | 228 SkASSERT(GrBlendEquationIsAdvanced(equation)); |
229 | 229 |
230 const GrGLSLCaps& caps = *fProgramBuilder->gpu()->glCaps().glslCaps(); | 230 const GrGLSLCaps& caps = *fProgramBuilder->gpu()->glCaps().glslCaps(); |
231 if (!caps.mustEnableAdvBlendEqs()) { | 231 if (!caps.mustEnableAdvBlendEqs()) { |
232 return; | 232 return; |
233 } | 233 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ | 297 void GrGLFragmentShaderBuilder::addVarying(GrGLVarying* v, GrSLPrecision fsPrec)
{ |
298 v->fFsIn = v->fVsOut; | 298 v->fFsIn = v->fVsOut; |
299 if (v->fGsOut) { | 299 if (v->fGsOut) { |
300 v->fFsIn = v->fGsOut; | 300 v->fFsIn = v->fGsOut; |
301 } | 301 } |
302 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); | 302 fInputs.push_back().set(v->fType, GrGLShaderVar::kVaryingIn_TypeModifier, v-
>fFsIn, fsPrec); |
303 } | 303 } |
OLD | NEW |