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 GrGLProgramBuilder_DEFINED | 8 #ifndef GrGLProgramBuilder_DEFINED |
9 #define GrGLProgramBuilder_DEFINED | 9 #define GrGLProgramBuilder_DEFINED |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray; | 78 typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray; |
79 | 79 |
80 /** Generates a shader program. | 80 /** Generates a shader program. |
81 * | 81 * |
82 * The program implements what is specified in the stages given as input. | 82 * The program implements what is specified in the stages given as input. |
83 * After successful generation, the builder result objects are available | 83 * After successful generation, the builder result objects are available |
84 * to be used. | 84 * to be used. |
85 * @return true if generation was successful. | 85 * @return true if generation was successful. |
86 */ | 86 */ |
87 bool genProgram(const GrEffectStage* inColorStages[], | 87 |
| 88 bool genProgram(const GrEffectStage* inGeometryProcessor, |
| 89 const GrEffectStage* inColorStages[], |
88 const GrEffectStage* inCoverageStages[]); | 90 const GrEffectStage* inCoverageStages[]); |
89 | 91 |
90 // Below are the results of the shader generation. | 92 GrGLProgramEffects* getGeometryProcessor() const { |
91 | 93 SkASSERT(fProgramID); return fGeometryProcessor.get(); |
| 94 } |
92 GrGLProgramEffects* getColorEffects() const { SkASSERT(fProgramID); return f
ColorEffects.get(); } | 95 GrGLProgramEffects* getColorEffects() const { SkASSERT(fProgramID); return f
ColorEffects.get(); } |
93 GrGLProgramEffects* getCoverageEffects() const { SkASSERT(fProgramID); retur
n fCoverageEffects.get(); } | 96 GrGLProgramEffects* getCoverageEffects() const { SkASSERT(fProgramID); retur
n fCoverageEffects.get(); } |
94 const BuiltinUniformHandles& getBuiltinUniformHandles() const { | 97 const BuiltinUniformHandles& getBuiltinUniformHandles() const { |
95 SkASSERT(fProgramID); | 98 SkASSERT(fProgramID); |
96 return fUniformHandles; | 99 return fUniformHandles; |
97 } | 100 } |
98 GrGLuint getProgramID() const { SkASSERT(fProgramID); return fProgramID; } | 101 GrGLuint getProgramID() const { SkASSERT(fProgramID); return fProgramID; } |
99 bool hasVertexShader() const { SkASSERT(fProgramID); return !fFragOnly; } | 102 bool hasVertexShader() const { SkASSERT(fProgramID); return !fFragOnly; } |
100 int getTexCoordSetCount() const { SkASSERT(fProgramID); return fTexCoordSetC
nt; } | 103 int getTexCoordSetCount() const { SkASSERT(fProgramID); return fTexCoordSetC
nt; } |
101 const UniformInfoArray& getUniformInfos() const { return fUniforms; } | 104 const UniformInfoArray& getUniformInfos() const { return fUniforms; } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void nameVariable(SkString* out, char prefix, const char* name); | 161 void nameVariable(SkString* out, char prefix, const char* name); |
159 | 162 |
160 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const; | 163 virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>
* shaderIds) const; |
161 | 164 |
162 virtual void bindProgramLocations(GrGLuint programId); | 165 virtual void bindProgramLocations(GrGLuint programId); |
163 void resolveProgramLocations(GrGLuint programId); | 166 void resolveProgramLocations(GrGLuint programId); |
164 | 167 |
165 void appendDecls(const VarArray&, SkString*) const; | 168 void appendDecls(const VarArray&, SkString*) const; |
166 void appendUniformDecls(ShaderVisibility, SkString*) const; | 169 void appendUniformDecls(ShaderVisibility, SkString*) const; |
167 | 170 |
| 171 SkAutoTUnref<GrGLProgramEffects> fGeometryProcessor; |
168 SkAutoTUnref<GrGLProgramEffects> fColorEffects; | 172 SkAutoTUnref<GrGLProgramEffects> fColorEffects; |
169 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; | 173 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; |
170 BuiltinUniformHandles fUniformHandles; | 174 BuiltinUniformHandles fUniformHandles; |
171 bool fFragOnly; | 175 bool fFragOnly; |
172 int fTexCoordSetCnt; | 176 int fTexCoordSetCnt; |
173 GrGLuint fProgramID; | 177 GrGLuint fProgramID; |
174 GrGLFragmentShaderBuilder fFS; | 178 GrGLFragmentShaderBuilder fFS; |
175 SeparableVaryingInfoArray fSeparableVaryingInfos; | 179 SeparableVaryingInfoArray fSeparableVaryingInfos; |
176 private: | 180 |
177 class CodeStage : SkNoncopyable { | 181 class CodeStage : SkNoncopyable { |
178 public: | 182 public: |
179 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} | 183 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {} |
180 | 184 |
181 bool inStageCode() const { | 185 bool inStageCode() const { |
182 this->validate(); | 186 this->validate(); |
183 return NULL != fEffectStage; | 187 return NULL != fEffectStage; |
184 } | 188 } |
185 | 189 |
186 const GrEffectStage* effectStage() const { | 190 const GrEffectStage* effectStage() const { |
(...skipping 30 matching lines...) Expand all Loading... |
217 CodeStage* fCodeStage; | 221 CodeStage* fCodeStage; |
218 int fSavedIndex; | 222 int fSavedIndex; |
219 const GrEffectStage* fSavedEffectStage; | 223 const GrEffectStage* fSavedEffectStage; |
220 }; | 224 }; |
221 private: | 225 private: |
222 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } | 226 void validate() const { SkASSERT((NULL == fEffectStage) == (-1 == fCurre
ntIndex)); } |
223 int fNextIndex; | 227 int fNextIndex; |
224 int fCurrentIndex; | 228 int fCurrentIndex; |
225 const GrEffectStage* fEffectStage; | 229 const GrEffectStage* fEffectStage; |
226 } fCodeStage; | 230 } fCodeStage; |
| 231 private: |
227 | 232 |
228 /** | 233 /** |
229 * The base class will emit the fragment code that precedes the per-effect c
ode and then call | 234 * The base class will emit the fragment code that precedes the per-effect c
ode and then call |
230 * this function. The subclass can use it to insert additional fragment code
that should | 235 * this function. The subclass can use it to insert additional fragment code
that should |
231 * execute before the effects' code and/or emit other shaders (e.g. geometry
, vertex). | 236 * execute before the effects' code and/or emit other shaders (e.g. geometry
, vertex). |
232 * | 237 * |
233 * The subclass can modify the initial color or coverage | 238 * The subclass can modify the initial color or coverage |
234 */ | 239 */ |
235 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) = 0; | 240 virtual void emitCodeBeforeEffects(const GrEffectStage* geometryProcessor, |
| 241 GrGLSLExpr4* color, |
| 242 GrGLSLExpr4* coverage) = 0; |
236 | 243 |
237 /** | 244 /** |
238 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for | 245 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for |
239 * deleting it when finished. effectStages contains the effects to add. The e
ffect key provider | 246 * deleting it when finished. effectStages contains the effects to add. The e
ffect key provider |
240 * is used to communicate the key each effect created in its GenKey function.
inOutFSColor | 247 * is used to communicate the key each effect created in its GenKey function.
inOutFSColor |
241 * specifies the input color to the first stage and is updated to be the outp
ut color of the | 248 * specifies the input color to the first stage and is updated to be the outp
ut color of the |
242 * last stage. The handles to texture samplers for effectStage[i] are added t
o | 249 * last stage. The handles to texture samplers for effectStage[i] are added t
o |
243 * effectSamplerHandles[i]. | 250 * effectSamplerHandles[i]. |
244 */ | 251 */ |
245 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 252 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 * populate the variable. The APIs can refer to the variable through the ret
urned handle. | 296 * populate the variable. The APIs can refer to the variable through the ret
urned handle. |
290 */ | 297 */ |
291 VaryingHandle addSeparableVarying(GrSLType type, | 298 VaryingHandle addSeparableVarying(GrSLType type, |
292 const char* name, | 299 const char* name, |
293 const char** vsOutName, | 300 const char** vsOutName, |
294 const char** fsInName); | 301 const char** fsInName); |
295 | 302 |
296 GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; } | 303 GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; } |
297 | 304 |
298 private: | 305 private: |
299 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE; | 306 virtual void emitCodeBeforeEffects(const GrEffectStage* geometryProcessor, |
| 307 GrGLSLExpr4* color, |
| 308 GrGLSLExpr4* coverage) SK_OVERRIDE; |
300 | 309 |
301 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 310 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
302 int effectCnt, | 311 int effectCnt, |
303 const GrGLProgramDesc::Effe
ctKeyProvider&, | 312 const GrGLProgramDesc::Effe
ctKeyProvider&, |
304 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 313 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
305 | 314 |
| 315 /* |
| 316 * These functions are temporary and will eventually operate not on effects
but on |
| 317 * geometry processors |
| 318 */ |
| 319 void createAndEmitEffect(GrGLProgramEffectsBuilder*, |
| 320 const GrEffectStage* effectStage, |
| 321 const GrGLProgramDesc::EffectKeyProvider&, |
| 322 GrGLSLExpr4* inOutFSColor); |
| 323 |
| 324 GrGLProgramEffects* createAndEmitEffect(const GrEffectStage* geometryProcess
or, |
| 325 const GrGLProgramDesc::EffectKeyProv
ider&, |
| 326 GrGLSLExpr4* inOutFSColor); |
| 327 |
306 virtual void emitCodeAfterEffects() SK_OVERRIDE; | 328 virtual void emitCodeAfterEffects() SK_OVERRIDE; |
307 | 329 |
308 virtual bool compileAndAttachShaders(GrGLuint programId, | 330 virtual bool compileAndAttachShaders(GrGLuint programId, |
309 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; | 331 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; |
310 | 332 |
311 virtual void bindProgramLocations(GrGLuint programId) SK_OVERRIDE; | 333 virtual void bindProgramLocations(GrGLuint programId) SK_OVERRIDE; |
312 | 334 |
313 GrGLGeometryShaderBuilder fGS; | 335 GrGLGeometryShaderBuilder fGS; |
314 GrGLVertexShaderBuilder fVS; | 336 GrGLVertexShaderBuilder fVS; |
315 | 337 |
316 typedef GrGLProgramBuilder INHERITED; | 338 typedef GrGLProgramBuilder INHERITED; |
317 }; | 339 }; |
318 | 340 |
319 //////////////////////////////////////////////////////////////////////////////// | 341 //////////////////////////////////////////////////////////////////////////////// |
320 | 342 |
321 class GrGLFragmentOnlyProgramBuilder : public GrGLProgramBuilder { | 343 class GrGLFragmentOnlyProgramBuilder : public GrGLProgramBuilder { |
322 public: | 344 public: |
323 GrGLFragmentOnlyProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); | 345 GrGLFragmentOnlyProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); |
324 | 346 |
325 int addTexCoordSets(int count); | 347 int addTexCoordSets(int count); |
326 | 348 |
327 private: | 349 private: |
328 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE {} | 350 virtual void emitCodeBeforeEffects(const GrEffectStage*, |
| 351 GrGLSLExpr4* color, |
| 352 GrGLSLExpr4* coverage) SK_OVERRIDE {} |
329 | 353 |
330 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 354 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
331 int effectCnt, | 355 int effectCnt, |
332 const GrGLProgramDesc::Effe
ctKeyProvider&, | 356 const GrGLProgramDesc::Effe
ctKeyProvider&, |
333 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 357 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
334 | 358 |
335 virtual void emitCodeAfterEffects() SK_OVERRIDE {} | 359 virtual void emitCodeAfterEffects() SK_OVERRIDE {} |
336 | 360 |
337 typedef GrGLProgramBuilder INHERITED; | 361 typedef GrGLProgramBuilder INHERITED; |
338 }; | 362 }; |
339 | 363 |
340 #endif | 364 #endif |
OLD | NEW |