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 #ifndef GrGLFragmentShaderBuilder_DEFINED | 8 #ifndef GrGLSLFragmentShaderBuilder_DEFINED |
9 #define GrGLFragmentShaderBuilder_DEFINED | 9 #define GrGLSLFragmentShaderBuilder_DEFINED |
10 | 10 |
11 #include "GrGLShaderBuilder.h" | 11 #include "GrGLSLShaderBuilder.h" |
12 | 12 |
13 #include "glsl/GrGLSLProcessorTypes.h" | 13 #include "glsl/GrGLSLProcessorTypes.h" |
14 | 14 |
15 class GrRenderTarget; | 15 class GrRenderTarget; |
16 class GrGLSLVarying; | 16 class GrGLSLVarying; |
17 | 17 |
18 /* | 18 /* |
19 * This base class encapsulates the functionality which the GP uses to build fra
gment shaders | 19 * This base class encapsulates the functionality which the GP uses to build fra
gment shaders |
20 */ | 20 */ |
21 class GrGLFragmentBuilder : public GrGLShaderBuilder { | 21 class GrGLSLFragmentBuilder : public GrGLSLShaderBuilder { |
22 public: | 22 public: |
23 GrGLFragmentBuilder(GrGLSLProgramBuilder* program) | 23 GrGLSLFragmentBuilder(GrGLSLProgramBuilder* program) |
24 : INHERITED(program) | 24 : INHERITED(program) |
25 , fHasCustomColorOutput(false) | 25 , fHasCustomColorOutput(false) |
26 , fHasSecondaryOutput(false) { | 26 , fHasSecondaryOutput(false) { |
27 fSubstageIndices.push_back(0); | 27 fSubstageIndices.push_back(0); |
28 } | 28 } |
29 virtual ~GrGLFragmentBuilder() {} | 29 virtual ~GrGLSLFragmentBuilder() {} |
30 /** | 30 /** |
31 * Use of these features may require a GLSL extension to be enabled. Shaders
may not compile | 31 * Use of these features may require a GLSL extension to be enabled. Shaders
may not compile |
32 * if code is added that uses one of these features without calling enableFe
ature() | 32 * if code is added that uses one of these features without calling enableFe
ature() |
33 */ | 33 */ |
34 enum GLSLFeature { | 34 enum GLSLFeature { |
35 kStandardDerivatives_GLSLFeature = 0, | 35 kStandardDerivatives_GLSLFeature = 0, |
36 kLastGLSLFeature = kStandardDerivatives_GLSLFeature | 36 kLastGLSLFeature = kStandardDerivatives_GLSLFeature |
37 }; | 37 }; |
38 | 38 |
39 /** | 39 /** |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 * procs so no duplicate uniforms/functions appear in the generated shader p
rogram. The mangle | 86 * procs so no duplicate uniforms/functions appear in the generated shader p
rogram. The mangle |
87 * string is simply based on fSubstageIndices. For example, if fSubstageIndi
ces = [3, 1, 2, 0], | 87 * string is simply based on fSubstageIndices. For example, if fSubstageIndi
ces = [3, 1, 2, 0], |
88 * then the manglestring will be "_c3_c1_c2", and any uniform/function emitt
ed by that proc will | 88 * then the manglestring will be "_c3_c1_c2", and any uniform/function emitt
ed by that proc will |
89 * have "_c3_c1_c2" appended to its name, which can be interpreted as "base
proc's 3rd child's | 89 * have "_c3_c1_c2" appended to its name, which can be interpreted as "base
proc's 3rd child's |
90 * 1st child's 2nd child". | 90 * 1st child's 2nd child". |
91 */ | 91 */ |
92 SkString fMangleString; | 92 SkString fMangleString; |
93 | 93 |
94 friend class GrGLPathProcessor; | 94 friend class GrGLPathProcessor; |
95 | 95 |
96 typedef GrGLShaderBuilder INHERITED; | 96 typedef GrGLSLShaderBuilder INHERITED; |
97 }; | 97 }; |
98 | 98 |
99 /* | 99 /* |
100 * Fragment processor's, in addition to all of the above, may need to use dst co
lor so they use | 100 * Fragment processor's, in addition to all of the above, may need to use dst co
lor so they use |
101 * this builder to create their shader. Because this is the only shader builder
the FP sees, we | 101 * this builder to create their shader. Because this is the only shader builder
the FP sees, we |
102 * just call it FPShaderBuilder | 102 * just call it FPShaderBuilder |
103 */ | 103 */ |
104 class GrGLXPFragmentBuilder : public GrGLFragmentBuilder { | 104 class GrGLSLXPFragmentBuilder : public GrGLSLFragmentBuilder { |
105 public: | 105 public: |
106 GrGLXPFragmentBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {} | 106 GrGLSLXPFragmentBuilder(GrGLSLProgramBuilder* program) : INHERITED(program)
{} |
107 | 107 |
108 /** Returns the variable name that holds the color of the destination pixel.
This may be nullptr if | 108 /** Returns the variable name that holds the color of the destination pixel.
This may be nullptr if |
109 no effect advertised that it will read the destination. */ | 109 no effect advertised that it will read the destination. */ |
110 virtual const char* dstColor() = 0; | 110 virtual const char* dstColor() = 0; |
111 | 111 |
112 /** Adds any necessary layout qualifiers in order to legalize the supplied b
lend equation with | 112 /** Adds any necessary layout qualifiers in order to legalize the supplied b
lend equation with |
113 this shader. It is only legal to call this method with an advanced blend
equation, and only | 113 this shader. It is only legal to call this method with an advanced blend
equation, and only |
114 if these equations are supported. */ | 114 if these equations are supported. */ |
115 virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0; | 115 virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0; |
116 | 116 |
117 private: | 117 private: |
118 typedef GrGLFragmentBuilder INHERITED; | 118 typedef GrGLSLFragmentBuilder INHERITED; |
119 }; | 119 }; |
120 | 120 |
121 // TODO rename to Fragment Builder | 121 // TODO rename to Fragment Builder |
122 class GrGLFragmentShaderBuilder : public GrGLXPFragmentBuilder { | 122 class GrGLSLFragmentShaderBuilder : public GrGLSLXPFragmentBuilder { |
123 public: | 123 public: |
124 typedef uint8_t FragPosKey; | 124 typedef uint8_t FragPosKey; |
125 | 125 |
126 /** Returns a key for reading the fragment location. This should only be cal
led if there is an | 126 /** Returns a key for reading the fragment location. This should only be cal
led if there is an |
127 effect that will requires the fragment position. If the fragment position
is not required, | 127 effect that will requires the fragment position. If the fragment position
is not required, |
128 the key is 0. */ | 128 the key is 0. */ |
129 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst); | 129 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst); |
130 | 130 |
131 GrGLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKey)
; | 131 GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKe
y); |
132 | 132 |
133 // true public interface, defined explicitly in the abstract interfaces abov
e | 133 // true public interface, defined explicitly in the abstract interfaces abov
e |
134 bool enableFeature(GLSLFeature) override; | 134 bool enableFeature(GLSLFeature) override; |
135 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords
, | 135 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords
, |
136 int index) override; | 136 int index) override; |
137 const char* fragmentPosition() override; | 137 const char* fragmentPosition() override; |
138 const char* dstColor() override; | 138 const char* dstColor() override; |
139 | 139 |
140 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override; | 140 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override; |
141 | 141 |
(...skipping 17 matching lines...) Expand all Loading... |
159 static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryC
olorOut"; } | 159 static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryC
olorOut"; } |
160 | 160 |
161 /* | 161 /* |
162 * An internal call for GrGLProgramBuilder to use to add varyings to the ver
tex shader | 162 * An internal call for GrGLProgramBuilder to use to add varyings to the ver
tex shader |
163 */ | 163 */ |
164 void addVarying(GrGLSLVarying*, GrSLPrecision); | 164 void addVarying(GrGLSLVarying*, GrSLPrecision); |
165 | 165 |
166 void onFinalize() override; | 166 void onFinalize() override; |
167 | 167 |
168 /** | 168 /** |
169 * Features that should only be enabled by GrGLFragmentShaderBuilder itself. | 169 * Features that should only be enabled by GrGLSLFragmentShaderBuilder itsel
f. |
170 */ | 170 */ |
171 enum GLSLPrivateFeature { | 171 enum GLSLPrivateFeature { |
172 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, | 172 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, |
173 kBlendEquationAdvanced_GLSLPrivateFeature, | 173 kBlendEquationAdvanced_GLSLPrivateFeature, |
174 kBlendFuncExtended_GLSLPrivateFeature, | 174 kBlendFuncExtended_GLSLPrivateFeature, |
175 kLastGLSLPrivateFeature = kBlendFuncExtended_GLSLPrivateFeature | 175 kLastGLSLPrivateFeature = kBlendFuncExtended_GLSLPrivateFeature |
176 }; | 176 }; |
177 | 177 |
178 // Interpretation of FragPosKey when generating code | 178 // Interpretation of FragPosKey when generating code |
179 enum { | 179 enum { |
180 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil
l not be needed. | 180 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil
l not be needed. |
181 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t
op-left. | 181 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t
op-left. |
182 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b
ottom-left. | 182 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b
ottom-left. |
183 }; | 183 }; |
184 | 184 |
185 static const char* kDstTextureColorName; | 185 static const char* kDstTextureColorName; |
186 | 186 |
187 bool fSetupFragPosition; | 187 bool fSetupFragPosition; |
188 bool fTopLeftFragPosRead; | 188 bool fTopLeftFragPosRead; |
189 int fCustomColorOutputIndex; | 189 int fCustomColorOutputIndex; |
190 | 190 |
191 // some state to verify shaders and effects are consistent, this is reset be
tween effects by | 191 // some state to verify shaders and effects are consistent, this is reset be
tween effects by |
192 // the program creator | 192 // the program creator |
193 bool fHasReadDstColor; | 193 bool fHasReadDstColor; |
194 bool fHasReadFragmentPosition; | 194 bool fHasReadFragmentPosition; |
195 | 195 |
196 friend class GrGLProgramBuilder; | 196 friend class GrGLProgramBuilder; |
197 | 197 |
198 typedef GrGLXPFragmentBuilder INHERITED; | 198 typedef GrGLSLXPFragmentBuilder INHERITED; |
199 }; | 199 }; |
200 | 200 |
201 #endif | 201 #endif |
OLD | NEW |