OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrGLShaderBuilder_DEFINED | 8 #ifndef GrGLShaderBuilder_DEFINED |
9 #define GrGLShaderBuilder_DEFINED | 9 #define GrGLShaderBuilder_DEFINED |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 /** | 26 /** |
27 Contains all the incremental state of a shader as it is being built,as well as
helpers to | 27 Contains all the incremental state of a shader as it is being built,as well as
helpers to |
28 manipulate that state. | 28 manipulate that state. |
29 */ | 29 */ |
30 class GrGLShaderBuilder { | 30 class GrGLShaderBuilder { |
31 public: | 31 public: |
32 typedef GrTAllocator<GrGLShaderVar> VarArray; | 32 typedef GrTAllocator<GrGLShaderVar> VarArray; |
33 typedef GrBackendEffectFactory::EffectKey EffectKey; | 33 typedef GrBackendEffectFactory::EffectKey EffectKey; |
34 typedef GrGLProgramEffects::TextureSampler TextureSampler; | 34 typedef GrGLProgramEffects::TextureSampler TextureSampler; |
35 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; | 35 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray; |
| 36 typedef GrGLUniformManager::BuilderUniform BuilderUniform; |
36 | 37 |
37 enum ShaderVisibility { | 38 enum ShaderVisibility { |
38 kVertex_Visibility = 0x1, | 39 kVertex_Visibility = 0x1, |
39 kGeometry_Visibility = 0x2, | 40 kGeometry_Visibility = 0x2, |
40 kFragment_Visibility = 0x4, | 41 kFragment_Visibility = 0x4, |
41 }; | 42 }; |
42 | 43 |
43 GrGLShaderBuilder(GrGpuGL*, | 44 GrGLShaderBuilder(GrGpuGL*, GrGLUniformManager&, const GrGLProgramDesc&); |
44 GrGLUniformManager&, | 45 virtual ~GrGLShaderBuilder() {} |
45 const GrGLProgramDesc&, | |
46 bool needsVertexShader); | |
47 | 46 |
48 /** | 47 /** |
49 * Use of these features may require a GLSL extension to be enabled. Shaders
may not compile | 48 * Use of these features may require a GLSL extension to be enabled. Shaders
may not compile |
50 * if code is added that uses one of these features without calling enableFe
ature() | 49 * if code is added that uses one of these features without calling enableFe
ature() |
51 */ | 50 */ |
52 enum GLSLFeature { | 51 enum GLSLFeature { |
53 kStandardDerivatives_GLSLFeature = 0, | 52 kStandardDerivatives_GLSLFeature = 0, |
54 | 53 |
55 kLastGLSLFeature = kStandardDerivatives_GLSLFeature | 54 kLastGLSLFeature = kStandardDerivatives_GLSLFeature |
56 }; | 55 }; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 GrSLType coordType = kVec2f_GrSLType); | 96 GrSLType coordType = kVec2f_GrSLType); |
98 | 97 |
99 /** Emits a helper function outside of main() in the fragment shader. */ | 98 /** Emits a helper function outside of main() in the fragment shader. */ |
100 void fsEmitFunction(GrSLType returnType, | 99 void fsEmitFunction(GrSLType returnType, |
101 const char* name, | 100 const char* name, |
102 int argCnt, | 101 int argCnt, |
103 const GrGLShaderVar* args, | 102 const GrGLShaderVar* args, |
104 const char* body, | 103 const char* body, |
105 SkString* outName); | 104 SkString* outName); |
106 | 105 |
107 /** Add input/output variable declarations (i.e. 'varying') to the fragment
shader. */ | |
108 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } | |
109 | |
110 typedef uint8_t DstReadKey; | 106 typedef uint8_t DstReadKey; |
111 typedef uint8_t FragPosKey; | 107 typedef uint8_t FragPosKey; |
112 | 108 |
113 /** Returns a key for adding code to read the copy-of-dst color in service
of effects that | 109 /** Returns a key for adding code to read the copy-of-dst color in service
of effects that |
114 require reading the dst. It must not return 0 because 0 indicates that
there is no dst | 110 require reading the dst. It must not return 0 because 0 indicates that
there is no dst |
115 copy read at all (in which case this function should not be called). */ | 111 copy read at all (in which case this function should not be called). */ |
116 static DstReadKey KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps&); | 112 static DstReadKey KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps&); |
117 | 113 |
118 /** Returns a key for reading the fragment location. This should only be cal
led if there is an | 114 /** Returns a key for reading the fragment location. This should only be cal
led if there is an |
119 effect that will requires the fragment position. If the fragment positio
n is not required, | 115 effect that will requires the fragment position. If the fragment positio
n is not required, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 163 |
168 /** Returns the color of the destination pixel. This may be NULL if no effec
t advertised | 164 /** Returns the color of the destination pixel. This may be NULL if no effec
t advertised |
169 that it will read the destination. */ | 165 that it will read the destination. */ |
170 const char* dstColor(); | 166 const char* dstColor(); |
171 | 167 |
172 /** | 168 /** |
173 * Interfaces used by GrGLProgram. | 169 * Interfaces used by GrGLProgram. |
174 * TODO: These are used by GrGLProgram to insert a mode color filter. Remove
these when the | 170 * TODO: These are used by GrGLProgram to insert a mode color filter. Remove
these when the |
175 * color filter is expressed as a GrEffect. | 171 * color filter is expressed as a GrEffect. |
176 */ | 172 */ |
177 const SkString& getInputColor() const { return fInputColor; } | 173 const SkString& getInputColor() const { |
178 GrSLConstantVec getKnownColorValue() const { return fKnownColorValue; } | 174 SkASSERT(fInputColor.isEmpty() != (kNone_GrSLConstantVec == fKnownColorV
alue)); |
179 const SkString& getInputCoverage() const { return fInputCoverage; } | 175 return fInputColor; |
180 GrSLConstantVec getKnownCoverageValue() const { return fKnownCoverageValue;
} | 176 } |
| 177 GrSLConstantVec getKnownColorValue() const { |
| 178 SkASSERT(fInputColor.isEmpty() != (kNone_GrSLConstantVec == fKnownColorV
alue)); |
| 179 return fKnownColorValue; |
| 180 } |
| 181 const SkString& getInputCoverage() const { |
| 182 SkASSERT(fInputCoverage.isEmpty() != (kNone_GrSLConstantVec == fKnownCov
erageValue)); |
| 183 return fInputCoverage; |
| 184 } |
| 185 GrSLConstantVec getKnownCoverageValue() const { |
| 186 SkASSERT(fInputCoverage.isEmpty() != (kNone_GrSLConstantVec == fKnownCov
erageValue)); |
| 187 return fKnownCoverageValue; |
| 188 } |
181 | 189 |
182 /** | 190 /** |
183 * Adds code for effects and returns a GrGLProgramEffects* object. The calle
r is responsible for | 191 * Adds code for effects and returns a GrGLProgramEffects* object. The calle
r is responsible for |
184 * deleting it when finished. effectStages contains the effects to add. effe
ctKeys[i] is the key | 192 * deleting it when finished. effectStages contains the effects to add. effe
ctKeys[i] is the key |
185 * generated from effectStages[i]. inOutFSColor specifies the input color to
the first stage and | 193 * generated from effectStages[i]. inOutFSColor specifies the input color to
the first stage and |
186 * is updated to be the output color of the last stage. fsInOutColorKnownVal
ue specifies whether | 194 * is updated to be the output color of the last stage. fsInOutColorKnownVal
ue specifies whether |
187 * the input color has a known constant value and is updated to refer to the
status of the | 195 * the input color has a known constant value and is updated to refer to the
status of the |
188 * output color. The handles to texture samplers for effectStage[i] are adde
d to | 196 * output color. The handles to texture samplers for effectStage[i] are adde
d to |
189 * effectSamplerHandles[i]. | 197 * effectSamplerHandles[i]. |
190 */ | 198 */ |
191 GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effectStages[]
, | 199 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
192 const EffectKey effectKeys[], | 200 const EffectKey effectKeys[
], |
193 int effectCnt, | 201 int effectCnt, |
194 SkString* inOutFSColor, | 202 SkString* inOutFSColor, |
195 GrSLConstantVec* fsInOutColorKnownV
alue); | 203 GrSLConstantVec* fsInOutCol
orKnownValue) = 0; |
196 | 204 |
197 const char* getColorOutputName() const; | 205 const char* getColorOutputName() const; |
198 const char* enableSecondaryOutput(); | 206 const char* enableSecondaryOutput(); |
199 | 207 |
200 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei
ghtUniform; } | 208 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei
ghtUniform; } |
201 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const { | 209 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const { |
202 return fDstCopyTopLeftUniform; | 210 return fDstCopyTopLeftUniform; |
203 } | 211 } |
204 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const { | 212 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const { |
205 return fDstCopyScaleUniform; | 213 return fDstCopyScaleUniform; |
206 } | 214 } |
207 GrGLUniformManager::UniformHandle getColorUniform() const { return fColorUni
form; } | 215 GrGLUniformManager::UniformHandle getColorUniform() const { return fColorUni
form; } |
208 GrGLUniformManager::UniformHandle getCoverageUniform() const { return fCover
ageUniform; } | 216 GrGLUniformManager::UniformHandle getCoverageUniform() const { return fCover
ageUniform; } |
209 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const { | 217 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const { |
210 return fDstCopySamplerUniform; | 218 return fDstCopySamplerUniform; |
211 } | 219 } |
212 | 220 |
213 /** Helper class used to build the vertex and geometry shaders. This functio
nality | |
214 is kept separate from the rest of GrGLShaderBuilder to allow for shaders
programs | |
215 that only use the fragment shader. */ | |
216 class VertexBuilder { | |
217 public: | |
218 VertexBuilder(GrGLShaderBuilder* parent, GrGpuGL* gpu, const GrGLProgram
Desc&); | |
219 | |
220 /** | |
221 * Called by GrGLEffects to add code to one of the shaders. | |
222 */ | |
223 void vsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { | |
224 va_list args; | |
225 va_start(args, format); | |
226 fVSCode.appendf(format, args); | |
227 va_end(args); | |
228 } | |
229 | |
230 void vsCodeAppend(const char* str) { fVSCode.append(str); } | |
231 | |
232 /** Add a vertex attribute to the current program that is passed in from
the vertex data. | |
233 Returns false if the attribute was already there, true otherwise. */ | |
234 bool addAttribute(GrSLType type, const char* name); | |
235 | |
236 /** Add a varying variable to the current program to pass values between
vertex and fragment | |
237 shaders. If the last two parameters are non-NULL, they are filled in
with the name | |
238 generated. */ | |
239 void addVarying(GrSLType type, | |
240 const char* name, | |
241 const char** vsOutName = NULL, | |
242 const char** fsInName = NULL); | |
243 | |
244 /** Returns a vertex attribute that represents the vertex position in th
e VS. This is the | |
245 pre-matrix position and is commonly used by effects to compute textu
re coords via a matrix. | |
246 */ | |
247 const GrGLShaderVar& positionAttribute() const { return *fPositionVar; } | |
248 | |
249 /** Returns a vertex attribute that represents the local coords in the V
S. This may be the same | |
250 as positionAttribute() or it may not be. It depends upon whether the
rendering code | |
251 specified explicit local coords or not in the GrDrawState. */ | |
252 const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoords
Var; } | |
253 | |
254 /** | |
255 * Are explicit local coordinates provided as input to the vertex shader
. | |
256 */ | |
257 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositi
onVar); } | |
258 | |
259 bool addEffectAttribute(int attributeIndex, GrSLType type, const SkStrin
g& name); | |
260 const SkString* getEffectAttributeName(int attributeIndex) const; | |
261 | |
262 GrGLUniformManager::UniformHandle getViewMatrixUniform() const { | |
263 return fViewMatrixUniform; | |
264 } | |
265 | |
266 bool compileAndAttachShaders(GrGLuint programId) const; | |
267 void bindProgramLocations(GrGLuint programId) const; | |
268 | |
269 private: | |
270 GrGLShaderBuilder* fParent; | |
271 GrGpuGL* fGpu; | |
272 const GrGLProgramDesc& fDesc; | |
273 VarArray fVSAttrs; | |
274 VarArray fVSOutputs; | |
275 VarArray fGSInputs; | |
276 VarArray fGSOutputs; | |
277 | |
278 SkString fVSCode; | |
279 | |
280 struct AttributePair { | |
281 void set(int index, const SkString& name) { | |
282 fIndex = index; fName = name; | |
283 } | |
284 int fIndex; | |
285 SkString fName; | |
286 }; | |
287 SkSTArray<10, AttributePair, true> fEffectAttributes; | |
288 | |
289 GrGLUniformManager::UniformHandle fViewMatrixUniform; | |
290 | |
291 GrGLShaderVar* fPositionVar; | |
292 GrGLShaderVar* fLocalCoordsVar; | |
293 }; | |
294 | |
295 /** Gets the vertex builder that is used to construct the vertex and geometr
y shaders. | |
296 It may be NULL if this shader program is only meant to have a fragment s
hader. */ | |
297 VertexBuilder* getVertexBuilder() const { return fVertexBuilder.get(); } | |
298 | |
299 bool finish(GrGLuint* outProgramId); | 221 bool finish(GrGLuint* outProgramId); |
300 | 222 |
301 const GrGLContextInfo& ctxInfo() const; | 223 const GrGLContextInfo& ctxInfo() const; |
302 | 224 |
303 private: | 225 protected: |
| 226 GrGpuGL* gpu() const { return fGpu; } |
| 227 |
| 228 void setInputColor(const char* inputColor) { fInputColor = inputColor; } |
| 229 void setInputCoverage(const char* inputCoverage) { fInputCoverage = inputCov
erage; } |
| 230 |
| 231 /** Add input/output variable declarations (i.e. 'varying') to the fragment
shader. */ |
| 232 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } |
| 233 |
| 234 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix |
| 235 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're |
| 236 // generating stage code. |
| 237 void nameVariable(SkString* out, char prefix, const char* name); |
| 238 |
| 239 // Helper for emitEffects(). |
| 240 void createAndEmitEffects(GrGLProgramEffectsBuilder*, |
| 241 const GrEffectStage* effectStages[], |
| 242 const EffectKey effectKeys[], |
| 243 int effectCnt, |
| 244 SkString* inOutFSColor, |
| 245 GrSLConstantVec* fsInOutColorKnownValue); |
| 246 |
| 247 virtual bool compileAndAttachShaders(GrGLuint programId) const; |
| 248 virtual void bindProgramLocations(GrGLuint programId) const; |
| 249 |
304 void appendDecls(const VarArray&, SkString*) const; | 250 void appendDecls(const VarArray&, SkString*) const; |
305 void appendUniformDecls(ShaderVisibility, SkString*) const; | 251 void appendUniformDecls(ShaderVisibility, SkString*) const; |
306 | 252 |
307 bool compileAndAttachShaders(GrGLuint programId) const; | |
308 void bindProgramLocations(GrGLuint programId) const; | |
309 | |
310 typedef GrGLUniformManager::BuilderUniform BuilderUniform; | |
311 GrGLUniformManager::BuilderUniformArray fUniforms; | |
312 | |
313 private: | 253 private: |
314 class CodeStage : public SkNoncopyable { | 254 class CodeStage : public SkNoncopyable { |
315 public: | 255 public: |
316 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} | 256 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} |
317 | 257 |
318 bool inStageCode() const { | 258 bool inStageCode() const { |
319 this->validate(); | 259 this->validate(); |
320 return NULL != fEffectStage; | 260 return NULL != fEffectStage; |
321 } | 261 } |
322 | 262 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, | 309 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, |
370 kEXTShaderFramebufferFetch_GLSLPrivateFeature, | 310 kEXTShaderFramebufferFetch_GLSLPrivateFeature, |
371 kNVShaderFramebufferFetch_GLSLPrivateFeature, | 311 kNVShaderFramebufferFetch_GLSLPrivateFeature, |
372 }; | 312 }; |
373 bool enablePrivateFeature(GLSLPrivateFeature); | 313 bool enablePrivateFeature(GLSLPrivateFeature); |
374 | 314 |
375 // If we ever have VS/GS features we can expand this to take a bitmask of Sh
aderVisibility and | 315 // If we ever have VS/GS features we can expand this to take a bitmask of Sh
aderVisibility and |
376 // track the enables separately for each shader. | 316 // track the enables separately for each shader. |
377 void addFSFeature(uint32_t featureBit, const char* extensionName); | 317 void addFSFeature(uint32_t featureBit, const char* extensionName); |
378 | 318 |
379 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix | |
380 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're | |
381 // generating stage code. | |
382 void nameVariable(SkString* out, char prefix, const char* name); | |
383 | |
384 // Interpretation of DstReadKey when generating code | 319 // Interpretation of DstReadKey when generating code |
385 enum { | 320 enum { |
386 kNoDstRead_DstReadKey = 0, | 321 kNoDstRead_DstReadKey = 0, |
387 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read. | 322 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read. |
388 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alpha
only. | 323 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alpha
only. |
389 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-le
ft. | 324 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-le
ft. |
390 }; | 325 }; |
391 | 326 |
392 enum { | 327 enum { |
393 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil
l not be needed. | 328 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil
l not be needed. |
394 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t
op-left. | 329 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t
op-left. |
395 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b
ottom-left. | 330 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b
ottom-left. |
396 }; | 331 }; |
397 | 332 |
398 GrGpuGL* fGpu; | 333 GrGpuGL* fGpu; |
399 GrGLUniformManager& fUniformManager; | 334 GrGLUniformManager& fUniformManager; |
400 uint32_t fFSFeaturesAddedMask; | 335 uint32_t fFSFeaturesAddedMask; |
401 SkString fFSFunctions; | 336 SkString fFSFunctions; |
402 SkString fFSExtensions; | 337 SkString fFSExtensions; |
403 VarArray fFSInputs; | 338 VarArray fFSInputs; |
404 VarArray fFSOutputs; | 339 VarArray fFSOutputs; |
| 340 GrGLUniformManager::BuilderUniformArray fUniforms; |
405 | 341 |
406 SkString fFSCode; | 342 SkString fFSCode; |
407 | 343 |
408 bool fSetupFragPosition; | 344 bool fSetupFragPosition; |
409 GrGLUniformManager::UniformHandle fDstCopySamplerUniform; | 345 GrGLUniformManager::UniformHandle fDstCopySamplerUniform; |
410 | 346 |
411 SkString fInputColor; | 347 SkString fInputColor; |
412 GrSLConstantVec fKnownColorValue; | 348 GrSLConstantVec fKnownColorValue; |
413 SkString fInputCoverage; | 349 SkString fInputCoverage; |
414 GrSLConstantVec fKnownCoverageValue; | 350 GrSLConstantVec fKnownCoverageValue; |
415 | 351 |
416 bool fHasCustomColorOutput; | 352 bool fHasCustomColorOutput; |
417 bool fHasSecondaryOutput; | 353 bool fHasSecondaryOutput; |
418 | 354 |
419 GrGLUniformManager::UniformHandle fRTHeightUniform; | 355 GrGLUniformManager::UniformHandle fRTHeightUniform; |
420 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform; | 356 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform; |
421 GrGLUniformManager::UniformHandle fDstCopyScaleUniform; | 357 GrGLUniformManager::UniformHandle fDstCopyScaleUniform; |
422 GrGLUniformManager::UniformHandle fColorUniform; | 358 GrGLUniformManager::UniformHandle fColorUniform; |
423 GrGLUniformManager::UniformHandle fCoverageUniform; | 359 GrGLUniformManager::UniformHandle fCoverageUniform; |
424 | 360 |
425 bool fTopLeftFragPosRead; | 361 bool fTopLeftFragPosRead; |
| 362 }; |
426 | 363 |
427 SkAutoTDelete<VertexBuilder> fVertexBuilder; | 364 //////////////////////////////////////////////////////////////////////////////// |
| 365 |
| 366 class GrGLFullShaderBuilder : public GrGLShaderBuilder { |
| 367 public: |
| 368 GrGLFullShaderBuilder(GrGpuGL*, GrGLUniformManager&, const GrGLProgramDesc&)
; |
| 369 |
| 370 /** |
| 371 * Called by GrGLEffects to add code to one of the shaders. |
| 372 */ |
| 373 void vsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { |
| 374 va_list args; |
| 375 va_start(args, format); |
| 376 fVSCode.appendf(format, args); |
| 377 va_end(args); |
| 378 } |
| 379 |
| 380 void vsCodeAppend(const char* str) { fVSCode.append(str); } |
| 381 |
| 382 /** Add a vertex attribute to the current program that is passed in from the
vertex data. |
| 383 Returns false if the attribute was already there, true otherwise. */ |
| 384 bool addAttribute(GrSLType type, const char* name); |
| 385 |
| 386 /** Add a varying variable to the current program to pass values between vert
ex and fragment |
| 387 shaders. If the last two parameters are non-NULL, they are filled in wit
h the name |
| 388 generated. */ |
| 389 void addVarying(GrSLType type, |
| 390 const char* name, |
| 391 const char** vsOutName = NULL, |
| 392 const char** fsInName = NULL); |
| 393 |
| 394 /** Returns a vertex attribute that represents the vertex position in the VS
. This is the |
| 395 pre-matrix position and is commonly used by effects to compute texture c
oords via a matrix. |
| 396 */ |
| 397 const GrGLShaderVar& positionAttribute() const { return *fPositionVar; } |
| 398 |
| 399 /** Returns a vertex attribute that represents the local coords in the VS. T
his may be the same |
| 400 as positionAttribute() or it may not be. It depends upon whether the ren
dering code |
| 401 specified explicit local coords or not in the GrDrawState. */ |
| 402 const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar;
} |
| 403 |
| 404 /** |
| 405 * Are explicit local coordinates provided as input to the vertex shader. |
| 406 */ |
| 407 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa
r); } |
| 408 |
| 409 bool addEffectAttribute(int attributeIndex, GrSLType type, const SkString& n
ame); |
| 410 const SkString* getEffectAttributeName(int attributeIndex) const; |
| 411 |
| 412 virtual GrGLProgramEffects* createAndEmitEffects( |
| 413 const GrEffectStage* effectStages[], |
| 414 const EffectKey effectKeys[], |
| 415 int effectCnt, |
| 416 SkString* inOutFSColor, |
| 417 GrSLConstantVec* fsInOutColorKnownValue) SK_OVERRIDE; |
| 418 |
| 419 GrGLUniformManager::UniformHandle getViewMatrixUniform() const { |
| 420 return fViewMatrixUniform; |
| 421 } |
| 422 |
| 423 protected: |
| 424 virtual bool compileAndAttachShaders(GrGLuint programId) const SK_OVERRIDE; |
| 425 virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE; |
| 426 |
| 427 private: |
| 428 const GrGLProgramDesc& fDesc; |
| 429 VarArray fVSAttrs; |
| 430 VarArray fVSOutputs; |
| 431 VarArray fGSInputs; |
| 432 VarArray fGSOutputs; |
| 433 |
| 434 SkString fVSCode; |
| 435 |
| 436 struct AttributePair { |
| 437 void set(int index, const SkString& name) { |
| 438 fIndex = index; fName = name; |
| 439 } |
| 440 int fIndex; |
| 441 SkString fName; |
| 442 }; |
| 443 SkSTArray<10, AttributePair, true> fEffectAttributes; |
| 444 |
| 445 GrGLUniformManager::UniformHandle fViewMatrixUniform; |
| 446 |
| 447 GrGLShaderVar* fPositionVar; |
| 448 GrGLShaderVar* fLocalCoordsVar; |
| 449 |
| 450 typedef GrGLShaderBuilder INHERITED; |
428 }; | 451 }; |
429 | 452 |
430 #endif | 453 #endif |
OLD | NEW |