OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrGLSLProgramBuilder_DEFINED | 8 #ifndef GrGLSLProgramBuilder_DEFINED |
9 #define GrGLSLProgramBuilder_DEFINED | 9 #define GrGLSLProgramBuilder_DEFINED |
10 | 10 |
11 #include "GrGeometryProcessor.h" | 11 #include "GrGeometryProcessor.h" |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
14 #include "glsl/GrGLSLGeometryShaderBuilder.h" | 14 #include "glsl/GrGLSLGeometryShaderBuilder.h" |
15 #include "glsl/GrGLSLProgramDataManager.h" | 15 #include "glsl/GrGLSLProgramDataManager.h" |
16 #include "glsl/GrGLSLVertexShaderBuilder.h" | 16 #include "glsl/GrGLSLVertexShaderBuilder.h" |
17 | 17 |
18 class GrGLSLCaps; | 18 class GrGLSLCaps; |
19 class GrGLSLShaderVar; | 19 class GrGLSLShaderVar; |
| 20 class GrGLSLVaryingHandler; |
20 | 21 |
21 // Enough precision to represent 1 / 2048 accurately in printf | 22 // Enough precision to represent 1 / 2048 accurately in printf |
22 #define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11 | 23 #define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11 |
23 | 24 |
24 class GrGLSLUniformBuilder { | 25 class GrGLSLUniformBuilder { |
25 public: | 26 public: |
26 enum ShaderVisibility { | 27 enum ShaderVisibility { |
27 kVertex_Visibility = 1 << kVertex_GrShaderType, | 28 kVertex_Visibility = 1 << kVertex_GrShaderType, |
28 kGeometry_Visibility = 1 << kGeometry_GrShaderType, | 29 kGeometry_Visibility = 1 << kGeometry_GrShaderType, |
29 kFragment_Visibility = 1 << kFragment_GrShaderType, | 30 kFragment_Visibility = 1 << kFragment_GrShaderType, |
30 }; | 31 }; |
31 | 32 |
32 virtual ~GrGLSLUniformBuilder() {} | 33 virtual ~GrGLSLUniformBuilder() {} |
33 | 34 |
34 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 35 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
35 typedef GrGLSLProgramDataManager::SeparableVaryingHandle SeparableVaryingHan
dle; | |
36 | 36 |
37 /** Add a uniform variable to the current program, that has visibility in on
e or more shaders. | 37 /** Add a uniform variable to the current program, that has visibility in on
e or more shaders. |
38 visibility is a bitfield of ShaderVisibility values indicating from whic
h shaders the | 38 visibility is a bitfield of ShaderVisibility values indicating from whic
h shaders the |
39 uniform should be accessible. At least one bit must be set. Geometry sha
der uniforms are not | 39 uniform should be accessible. At least one bit must be set. Geometry sha
der uniforms are not |
40 supported at this time. The actual uniform name will be mangled. If outN
ame is not nullptr | 40 supported at this time. The actual uniform name will be mangled. If outN
ame is not nullptr |
41 then it will refer to the final uniform name after return. Use the addUn
iformArray variant | 41 then it will refer to the final uniform name after return. Use the addUn
iformArray variant |
42 to add an array of uniforms. */ | 42 to add an array of uniforms. */ |
43 UniformHandle addUniform(uint32_t visibility, | 43 UniformHandle addUniform(uint32_t visibility, |
44 GrSLType type, | 44 GrSLType type, |
45 GrSLPrecision precision, | 45 GrSLPrecision precision, |
(...skipping 26 matching lines...) Expand all Loading... |
72 virtual UniformHandle internalAddUniformArray( | 72 virtual UniformHandle internalAddUniformArray( |
73 uint32_t visibility, | 73 uint32_t visibility, |
74 GrSLType type, | 74 GrSLType type, |
75 GrSLPrecision precision, | 75 GrSLPrecision precision, |
76 const char* name, | 76 const char* name, |
77 bool mangleName, | 77 bool mangleName, |
78 int arrayCount, | 78 int arrayCount, |
79 const char** outName) = 0; | 79 const char** outName) = 0; |
80 }; | 80 }; |
81 | 81 |
82 // TODO move this into GrGLSLGPBuilder and move them both out of this file | |
83 class GrGLSLVarying { | |
84 public: | |
85 bool vsVarying() const { return kVertToFrag_Varying == fVarying || | |
86 kVertToGeo_Varying == fVarying; } | |
87 bool fsVarying() const { return kVertToFrag_Varying == fVarying || | |
88 kGeoToFrag_Varying == fVarying; } | |
89 const char* vsOut() const { return fVsOut; } | |
90 const char* gsIn() const { return fGsIn; } | |
91 const char* gsOut() const { return fGsOut; } | |
92 const char* fsIn() const { return fFsIn; } | |
93 GrSLType type() const { return fType; } | |
94 | |
95 protected: | |
96 enum Varying { | |
97 kVertToFrag_Varying, | |
98 kVertToGeo_Varying, | |
99 kGeoToFrag_Varying, | |
100 }; | |
101 | |
102 GrGLSLVarying(GrSLType type, Varying varying) | |
103 : fVarying(varying), fType(type), fVsOut(nullptr), fGsIn(nullptr), fGsOu
t(nullptr), | |
104 fFsIn(nullptr) {} | |
105 | |
106 Varying fVarying; | |
107 | |
108 private: | |
109 GrSLType fType; | |
110 const char* fVsOut; | |
111 const char* fGsIn; | |
112 const char* fGsOut; | |
113 const char* fFsIn; | |
114 | |
115 friend class GrGLSLVertexBuilder; | |
116 friend class GrGLSLGeometryBuilder; | |
117 friend class GrGLSLXferBuilder; | |
118 friend class GrGLSLFragmentShaderBuilder; | |
119 }; | |
120 | |
121 struct GrGLSLVertToFrag : public GrGLSLVarying { | |
122 GrGLSLVertToFrag(GrSLType type) | |
123 : GrGLSLVarying(type, kVertToFrag_Varying) {} | |
124 }; | |
125 | |
126 struct GrGLSLVertToGeo : public GrGLSLVarying { | |
127 GrGLSLVertToGeo(GrSLType type) | |
128 : GrGLSLVarying(type, kVertToGeo_Varying) {} | |
129 }; | |
130 | |
131 struct GrGLSLGeoToFrag : public GrGLSLVarying { | |
132 GrGLSLGeoToFrag(GrSLType type) | |
133 : GrGLSLVarying(type, kGeoToFrag_Varying) {} | |
134 }; | |
135 | |
136 /* a specialization of the above for GPs. Lets the user add uniforms, varyings,
and VS / FS code */ | 82 /* a specialization of the above for GPs. Lets the user add uniforms, varyings,
and VS / FS code */ |
137 class GrGLSLGPBuilder : public virtual GrGLSLUniformBuilder { | 83 class GrGLSLGPBuilder : public virtual GrGLSLUniformBuilder { |
138 public: | 84 public: |
139 /* | 85 /* |
140 * addVarying allows fine grained control for setting up varyings between st
ages. If you just | |
141 * need to take an attribute and pass it through to an output value in a fra
gment shader, use | |
142 * addPassThroughAttribute. | |
143 * TODO convert most uses of addVarying to addPassThroughAttribute | |
144 */ | |
145 virtual void addVarying(const char* name, | |
146 GrGLSLVarying*, | |
147 GrSLPrecision precision = kDefault_GrSLPrecision) =
0; | |
148 | |
149 /* | |
150 * This call can be used by GP to pass an attribute through all shaders dire
ctly to 'output' in | |
151 * the fragment shader. Though this call effects both the vertex shader and
fragment shader, | |
152 * it expects 'output' to be defined in the fragment shader before this call
is made. | |
153 * TODO it might be nicer behavior to have a flag to declare output inside t
his call | |
154 */ | |
155 virtual void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, | |
156 const char* output) = 0; | |
157 | |
158 /* | |
159 * Creates a fragment shader varying that can be referred to. | |
160 * Comparable to GrGLSLUniformBuilder::addUniform(). | |
161 */ | |
162 virtual SeparableVaryingHandle addSeparableVarying( | |
163 const char* name, GrGLSLVertToFrag*, | |
164 GrSLPrecision fsPrecision = kDefault_GrSLPrecision) = 0; | |
165 | |
166 /* | |
167 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | 86 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE |
168 */ | 87 */ |
169 }; | 88 }; |
170 | 89 |
171 | 90 |
172 /* a specializations for FPs. Lets the user add uniforms and FS code */ | 91 /* a specializations for FPs. Lets the user add uniforms and FS code */ |
173 class GrGLSLFPBuilder : public virtual GrGLSLUniformBuilder { | 92 class GrGLSLFPBuilder : public virtual GrGLSLUniformBuilder { |
174 public: | 93 public: |
175 /* | 94 /* |
176 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | 95 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 return this->internalAddUniformArray(visibility, type, precision, name,
false, 0, outName); | 141 return this->internalAddUniformArray(visibility, type, precision, name,
false, 0, outName); |
223 } | 142 } |
224 | 143 |
225 const char* rtAdjustment() const { return "rtAdjustment"; } | 144 const char* rtAdjustment() const { return "rtAdjustment"; } |
226 | 145 |
227 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix | 146 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix |
228 // char (unless the prefix is '\0'). It also will mangle the name to be stag
e-specific unless | 147 // char (unless the prefix is '\0'). It also will mangle the name to be stag
e-specific unless |
229 // explicitly asked not to. | 148 // explicitly asked not to. |
230 void nameVariable(SkString* out, char prefix, const char* name, bool mangle
= true); | 149 void nameVariable(SkString* out, char prefix, const char* name, bool mangle
= true); |
231 | 150 |
| 151 virtual GrGLSLVaryingHandler* varyingHandler() = 0; |
| 152 |
232 // number of each input/output type in a single allocation block, used by ma
ny builders | 153 // number of each input/output type in a single allocation block, used by ma
ny builders |
233 static const int kVarsPerBlock; | 154 static const int kVarsPerBlock; |
234 | 155 |
235 GrGLSLVertexBuilder fVS; | 156 GrGLSLVertexBuilder fVS; |
236 GrGLSLGeometryBuilder fGS; | 157 GrGLSLGeometryBuilder fGS; |
237 GrGLSLFragmentShaderBuilder fFS; | 158 GrGLSLFragmentShaderBuilder fFS; |
| 159 |
238 int fStageIndex; | 160 int fStageIndex; |
239 | 161 |
240 BuiltinUniformHandles fUniformHandles; | 162 BuiltinUniformHandles fUniformHandles; |
241 | 163 |
242 const DrawArgs& fArgs; | 164 const DrawArgs& fArgs; |
243 | 165 |
244 private: | 166 private: |
245 virtual void onAppendUniformDecls(ShaderVisibility visibility, SkString* out
) const = 0; | 167 virtual void onAppendUniformDecls(ShaderVisibility visibility, SkString* out
) const = 0; |
246 | 168 |
247 friend class GrGLSLShaderBuilder; | 169 friend class GrGLSLShaderBuilder; |
248 friend class GrGLSLVertexBuilder; | 170 friend class GrGLSLVertexBuilder; |
249 friend class GrGLSLFragmentShaderBuilder; | 171 friend class GrGLSLFragmentShaderBuilder; |
250 friend class GrGLSLGeometryBuilder; | 172 friend class GrGLSLGeometryBuilder; |
| 173 friend class GrGLSLVaryingHandler; |
251 }; | 174 }; |
252 | 175 |
253 #endif | 176 #endif |
OLD | NEW |