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(GrGLSLExpr4* color, |
| 241 GrGLSLExpr4* coverage) = 0; |
| 242 |
| 243 /* |
| 244 * Full shader builder needs to emit code after the color stages and before
the coverage stages |
| 245 */ |
| 246 virtual void emitGeometryProcessor(const GrEffectStage* geometryProcessor, |
| 247 GrGLSLExpr4* coverage) = 0; |
236 | 248 |
237 /** | 249 /** |
238 * Adds code for effects and returns a GrGLProgramEffects* object. The caller
is responsible for | 250 * 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 | 251 * 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 | 252 * 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 | 253 * 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 | 254 * last stage. The handles to texture samplers for effectStage[i] are added t
o |
243 * effectSamplerHandles[i]. | 255 * effectSamplerHandles[i]. |
244 */ | 256 */ |
245 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 257 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 * populate the variable. The APIs can refer to the variable through the ret
urned handle. | 302 * populate the variable. The APIs can refer to the variable through the ret
urned handle. |
291 */ | 303 */ |
292 VaryingHandle addSeparableVarying(GrSLType type, | 304 VaryingHandle addSeparableVarying(GrSLType type, |
293 const char* name, | 305 const char* name, |
294 const char** vsOutName, | 306 const char** vsOutName, |
295 const char** fsInName); | 307 const char** fsInName); |
296 | 308 |
297 GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; } | 309 GrGLVertexShaderBuilder* getVertexShaderBuilder() { return &fVS; } |
298 | 310 |
299 private: | 311 private: |
300 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE; | 312 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, |
| 313 GrGLSLExpr4* coverage) SK_OVERRIDE; |
| 314 |
| 315 virtual void emitGeometryProcessor(const GrEffectStage* geometryProcessor, |
| 316 GrGLSLExpr4* coverage) SK_OVERRIDE; |
301 | 317 |
302 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 318 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
303 int effectCnt, | 319 int effectCnt, |
304 const GrGLProgramDesc::Effe
ctKeyProvider&, | 320 const GrGLProgramDesc::Effe
ctKeyProvider&, |
305 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 321 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
306 | 322 |
| 323 /* |
| 324 * These functions are temporary and will eventually operate not on effects
but on |
| 325 * geometry processors |
| 326 */ |
| 327 void createAndEmitEffect(GrGLProgramEffectsBuilder*, |
| 328 const GrEffectStage* effectStage, |
| 329 const GrGLProgramDesc::EffectKeyProvider&, |
| 330 GrGLSLExpr4* inOutFSColor); |
| 331 |
| 332 GrGLProgramEffects* createAndEmitEffect(const GrEffectStage* geometryProcess
or, |
| 333 const GrGLProgramDesc::EffectKeyProv
ider&, |
| 334 GrGLSLExpr4* inOutFSColor); |
| 335 |
307 virtual void emitCodeAfterEffects() SK_OVERRIDE; | 336 virtual void emitCodeAfterEffects() SK_OVERRIDE; |
308 | 337 |
309 virtual bool compileAndAttachShaders(GrGLuint programId, | 338 virtual bool compileAndAttachShaders(GrGLuint programId, |
310 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; | 339 SkTDArray<GrGLuint>* shaderIds) const S
K_OVERRIDE; |
311 | 340 |
312 virtual void bindProgramLocations(GrGLuint programId) SK_OVERRIDE; | 341 virtual void bindProgramLocations(GrGLuint programId) SK_OVERRIDE; |
313 | 342 |
314 GrGLGeometryShaderBuilder fGS; | 343 GrGLGeometryShaderBuilder fGS; |
315 GrGLVertexShaderBuilder fVS; | 344 GrGLVertexShaderBuilder fVS; |
316 | 345 |
317 typedef GrGLProgramBuilder INHERITED; | 346 typedef GrGLProgramBuilder INHERITED; |
318 }; | 347 }; |
319 | 348 |
320 //////////////////////////////////////////////////////////////////////////////// | 349 //////////////////////////////////////////////////////////////////////////////// |
321 | 350 |
322 class GrGLFragmentOnlyProgramBuilder : public GrGLProgramBuilder { | 351 class GrGLFragmentOnlyProgramBuilder : public GrGLProgramBuilder { |
323 public: | 352 public: |
324 GrGLFragmentOnlyProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); | 353 GrGLFragmentOnlyProgramBuilder(GrGpuGL*, const GrGLProgramDesc&); |
325 | 354 |
326 int addTexCoordSets(int count); | 355 int addTexCoordSets(int count); |
327 | 356 |
328 private: | 357 private: |
329 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage
) SK_OVERRIDE {} | 358 virtual void emitCodeBeforeEffects(GrGLSLExpr4* color, |
| 359 GrGLSLExpr4* coverage) SK_OVERRIDE {} |
| 360 |
| 361 virtual void emitGeometryProcessor(const GrEffectStage* geometryProcessor, |
| 362 GrGLSLExpr4* coverage) SK_OVERRIDE { |
| 363 SkASSERT(NULL == geometryProcessor); |
| 364 } |
330 | 365 |
331 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], | 366 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect
Stages[], |
332 int effectCnt, | 367 int effectCnt, |
333 const GrGLProgramDesc::Effe
ctKeyProvider&, | 368 const GrGLProgramDesc::Effe
ctKeyProvider&, |
334 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; | 369 GrGLSLExpr4* inOutFSColor)
SK_OVERRIDE; |
335 | 370 |
336 virtual void emitCodeAfterEffects() SK_OVERRIDE {} | 371 virtual void emitCodeAfterEffects() SK_OVERRIDE {} |
337 | 372 |
338 typedef GrGLProgramBuilder INHERITED; | 373 typedef GrGLProgramBuilder INHERITED; |
339 }; | 374 }; |
340 | 375 |
341 #endif | 376 #endif |
OLD | NEW |