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 |
11 #include "GrGLFragmentShaderBuilder.h" | 11 #include "GrGLFragmentShaderBuilder.h" |
12 #include "GrGLGeometryShaderBuilder.h" | 12 #include "GrGLGeometryShaderBuilder.h" |
13 #include "GrGLVertexShaderBuilder.h" | 13 #include "GrGLVertexShaderBuilder.h" |
14 #include "../GrGLProgramDataManager.h" | 14 #include "../GrGLProgramDataManager.h" |
15 #include "../GrGLUniformHandle.h" | 15 #include "../GrGLUniformHandle.h" |
16 #include "../GrGLGeometryProcessor.h" | 16 #include "../GrGLGeometryProcessor.h" |
17 #include "../GrGLXferProcessor.h" | |
17 #include "../../GrOptDrawState.h" | 18 #include "../../GrOptDrawState.h" |
18 #include "../../GrPendingFragmentStage.h" | 19 #include "../../GrPendingFragmentStage.h" |
19 | 20 |
20 /* | 21 /* |
21 * This is the base class for a series of interfaces. This base class *MUST* re main abstract with | 22 * This is the base class for a series of interfaces. This base class *MUST* re main abstract with |
22 * NO data members because it is used in multiple interface inheritance. | 23 * NO data members because it is used in multiple interface inheritance. |
23 * Heirarchy: | 24 * Heirarchy: |
24 * GrGLUniformBuilder | 25 * GrGLUniformBuilder |
25 * / \ | 26 * / \ |
26 * GrGLFPBuilder GrGLGPBuilder | 27 * GrGLFPBuilder GrGLGPBuilder |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 | 99 |
99 private: | 100 private: |
100 GrSLType fType; | 101 GrSLType fType; |
101 const char* fVsOut; | 102 const char* fVsOut; |
102 const char* fGsIn; | 103 const char* fGsIn; |
103 const char* fGsOut; | 104 const char* fGsOut; |
104 const char* fFsIn; | 105 const char* fFsIn; |
105 | 106 |
106 friend class GrGLVertexBuilder; | 107 friend class GrGLVertexBuilder; |
107 friend class GrGLGeometryBuilder; | 108 friend class GrGLGeometryBuilder; |
109 friend class GrGLXferBuilder; | |
108 friend class GrGLFragmentShaderBuilder; | 110 friend class GrGLFragmentShaderBuilder; |
109 }; | 111 }; |
110 | 112 |
111 struct GrGLVertToFrag : public GrGLVarying { | 113 struct GrGLVertToFrag : public GrGLVarying { |
112 GrGLVertToFrag(GrSLType type) | 114 GrGLVertToFrag(GrSLType type) |
113 : GrGLVarying(type, kVertToFrag_Varying) {} | 115 : GrGLVarying(type, kVertToFrag_Varying) {} |
114 }; | 116 }; |
115 | 117 |
116 struct GrGLVertToGeo : public GrGLVarying { | 118 struct GrGLVertToGeo : public GrGLVarying { |
117 GrGLVertToGeo(GrSLType type) | 119 GrGLVertToGeo(GrSLType type) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 /* a specializations for FPs. Lets the user add uniforms and FS code */ | 159 /* a specializations for FPs. Lets the user add uniforms and FS code */ |
158 class GrGLFPBuilder : public virtual GrGLUniformBuilder { | 160 class GrGLFPBuilder : public virtual GrGLUniformBuilder { |
159 public: | 161 public: |
160 virtual GrGLFPFragmentBuilder* getFragmentShaderBuilder() = 0; | 162 virtual GrGLFPFragmentBuilder* getFragmentShaderBuilder() = 0; |
161 | 163 |
162 /* | 164 /* |
163 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | 165 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE |
164 */ | 166 */ |
165 }; | 167 }; |
166 | 168 |
169 /* a specializations for XPs. Lets the user add uniforms and FS code */ | |
170 class GrGLXPBuilder : public virtual GrGLUniformBuilder { | |
171 public: | |
172 virtual GrGLFPFragmentBuilder* getFragmentShaderBuilder() = 0; | |
173 | |
174 /* | |
175 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | |
176 */ | |
177 }; | |
167 struct GrGLInstalledProc; | 178 struct GrGLInstalledProc; |
168 struct GrGLInstalledGeoProc; | 179 struct GrGLInstalledGeoProc; |
180 struct GrGLInstalledXferProc; | |
169 struct GrGLInstalledFragProc; | 181 struct GrGLInstalledFragProc; |
170 struct GrGLInstalledFragProcs; | 182 struct GrGLInstalledFragProcs; |
171 | 183 |
172 /* | 184 /* |
173 * Please note - no diamond problems because of virtual inheritance. Also, both base classes | 185 * Please note - no diamond problems because of virtual inheritance. Also, both base classes |
174 * are pure virtual with no data members. This is the base class for program bu ilding. | 186 * are pure virtual with no data members. This is the base class for program bu ilding. |
175 * Subclasses are nearly identical but each has their own way of emitting transf orms. State for | 187 * Subclasses are nearly identical but each has their own way of emitting transf orms. State for |
176 * each of the elements of the shader pipeline, ie vertex, fragment, geometry, e tc, lives in those | 188 * each of the elements of the shader pipeline, ie vertex, fragment, geometry, e tc, lives in those |
177 * respective builders | 189 * respective builders |
178 */ | 190 */ |
179 class GrGLProgramBuilder : public GrGLGPBuilder, | 191 class GrGLProgramBuilder : public GrGLGPBuilder, |
180 public GrGLFPBuilder { | 192 public GrGLFPBuilder, |
193 public GrGLXPBuilder { | |
181 public: | 194 public: |
182 /** Generates a shader program. | 195 /** Generates a shader program. |
183 * | 196 * |
184 * The program implements what is specified in the stages given as input. | 197 * The program implements what is specified in the stages given as input. |
185 * After successful generation, the builder result objects are available | 198 * After successful generation, the builder result objects are available |
186 * to be used. | 199 * to be used. |
187 * @return true if generation was successful. | 200 * @return true if generation was successful. |
188 */ | 201 */ |
189 static GrGLProgram* CreateProgram(const GrOptDrawState&, GrGpuGL*); | 202 static GrGLProgram* CreateProgram(const GrOptDrawState&, GrGpuGL*); |
190 | 203 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 GrGLSLExpr4* outputColor, | 288 GrGLSLExpr4* outputColor, |
276 GrGLSLExpr4* outputCoverage); | 289 GrGLSLExpr4* outputCoverage); |
277 | 290 |
278 // these emit functions help to keep the createAndEmitProcessors template ge neral | 291 // these emit functions help to keep the createAndEmitProcessors template ge neral |
279 void emitAndInstallProc(const GrPendingFragmentStage&, | 292 void emitAndInstallProc(const GrPendingFragmentStage&, |
280 const char* outColor, | 293 const char* outColor, |
281 const char* inColor); | 294 const char* inColor); |
282 void emitAndInstallProc(const GrGeometryProcessor&, | 295 void emitAndInstallProc(const GrGeometryProcessor&, |
283 const char* outColor, | 296 const char* outColor, |
284 const char* outCoverage); | 297 const char* outCoverage); |
298 void emitAndInstallXferProc(const GrXferProcessor&, | |
299 const GrGLSLExpr4& colorIn, | |
300 const GrGLSLExpr4& coverageIn); | |
285 | 301 |
286 void verify(const GrGeometryProcessor&); | 302 void verify(const GrGeometryProcessor&); |
303 void verify(const GrXferProcessor&); | |
287 void verify(const GrFragmentProcessor&); | 304 void verify(const GrFragmentProcessor&); |
288 void emitSamplers(const GrProcessor&, | 305 void emitSamplers(const GrProcessor&, |
289 GrGLProcessor::TextureSamplerArray* outSamplers, | 306 GrGLProcessor::TextureSamplerArray* outSamplers, |
290 GrGLInstalledProc*); | 307 GrGLInstalledProc*); |
291 | 308 |
292 // each specific program builder has a distinct transform and must override this function | 309 // each specific program builder has a distinct transform and must override this function |
293 virtual void emitTransforms(const GrPendingFragmentStage&, | 310 virtual void emitTransforms(const GrPendingFragmentStage&, |
294 GrGLProcessor::TransformedCoordsArray* outCoords , | 311 GrGLProcessor::TransformedCoordsArray* outCoords , |
295 GrGLInstalledFragProc*); | 312 GrGLInstalledFragProc*); |
296 GrGLProgram* finalize(); | 313 GrGLProgram* finalize(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 static const int kVarsPerBlock; | 373 static const int kVarsPerBlock; |
357 | 374 |
358 BuiltinUniformHandles fUniformHandles; | 375 BuiltinUniformHandles fUniformHandles; |
359 GrGLVertexBuilder fVS; | 376 GrGLVertexBuilder fVS; |
360 GrGLGeometryBuilder fGS; | 377 GrGLGeometryBuilder fGS; |
361 GrGLFragmentShaderBuilder fFS; | 378 GrGLFragmentShaderBuilder fFS; |
362 bool fOutOfStage; | 379 bool fOutOfStage; |
363 int fStageIndex; | 380 int fStageIndex; |
364 | 381 |
365 GrGLInstalledGeoProc* fGeometryProcessor; | 382 GrGLInstalledGeoProc* fGeometryProcessor; |
383 GrGLInstalledXferProc* fXferProcessor; | |
366 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; | 384 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; |
367 | 385 |
386 | |
joshualitt
2014/12/08 19:46:41
extra newline
egdaniel
2014/12/09 21:10:46
Done.
| |
368 const GrOptDrawState& fOptState; | 387 const GrOptDrawState& fOptState; |
369 const GrProgramDesc& fDesc; | 388 const GrProgramDesc& fDesc; |
370 GrGpuGL* fGpu; | 389 GrGpuGL* fGpu; |
371 UniformInfoArray fUniforms; | 390 UniformInfoArray fUniforms; |
372 SkSTArray<16, TransformVarying, true> fCoordVaryings; | 391 SkSTArray<16, TransformVarying, true> fCoordVaryings; |
373 | 392 |
374 friend class GrGLShaderBuilder; | 393 friend class GrGLShaderBuilder; |
375 friend class GrGLVertexBuilder; | 394 friend class GrGLVertexBuilder; |
376 friend class GrGLFragmentShaderBuilder; | 395 friend class GrGLFragmentShaderBuilder; |
377 friend class GrGLGeometryBuilder; | 396 friend class GrGLGeometryBuilder; |
(...skipping 11 matching lines...) Expand all Loading... | |
389 UniformHandle fUniform; | 408 UniformHandle fUniform; |
390 int fTextureUnit; | 409 int fTextureUnit; |
391 }; | 410 }; |
392 SkSTArray<4, Sampler, true> fSamplers; | 411 SkSTArray<4, Sampler, true> fSamplers; |
393 }; | 412 }; |
394 | 413 |
395 struct GrGLInstalledGeoProc : public GrGLInstalledProc { | 414 struct GrGLInstalledGeoProc : public GrGLInstalledProc { |
396 SkAutoTDelete<GrGLGeometryProcessor> fGLProc; | 415 SkAutoTDelete<GrGLGeometryProcessor> fGLProc; |
397 }; | 416 }; |
398 | 417 |
418 struct GrGLInstalledXferProc : public GrGLInstalledProc { | |
419 SkAutoTDelete<GrGLXferProcessor> fGLProc; | |
420 }; | |
421 | |
422 | |
joshualitt
2014/12/08 19:46:41
extra newline
egdaniel
2014/12/09 21:10:46
Done.
| |
399 struct GrGLInstalledFragProc : public GrGLInstalledProc { | 423 struct GrGLInstalledFragProc : public GrGLInstalledProc { |
400 GrGLInstalledFragProc() : fGLProc(NULL) {} | 424 GrGLInstalledFragProc() : fGLProc(NULL) {} |
401 class ShaderVarHandle { | 425 class ShaderVarHandle { |
402 public: | 426 public: |
403 bool isValid() const { return fHandle > -1; } | 427 bool isValid() const { return fHandle > -1; } |
404 ShaderVarHandle() : fHandle(-1) {} | 428 ShaderVarHandle() : fHandle(-1) {} |
405 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid()); } | 429 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid()); } |
406 int handle() const { SkASSERT(this->isValid()); return fHandle; } | 430 int handle() const { SkASSERT(this->isValid()); return fHandle; } |
407 UniformHandle convertToUniformHandle() { | 431 UniformHandle convertToUniformHandle() { |
408 SkASSERT(this->isValid()); | 432 SkASSERT(this->isValid()); |
(...skipping 14 matching lines...) Expand all Loading... | |
423 SkAutoTDelete<GrGLFragmentProcessor> fGLProc; | 447 SkAutoTDelete<GrGLFragmentProcessor> fGLProc; |
424 SkSTArray<2, Transform, true> fTransforms; | 448 SkSTArray<2, Transform, true> fTransforms; |
425 }; | 449 }; |
426 | 450 |
427 struct GrGLInstalledFragProcs : public SkRefCnt { | 451 struct GrGLInstalledFragProcs : public SkRefCnt { |
428 virtual ~GrGLInstalledFragProcs(); | 452 virtual ~GrGLInstalledFragProcs(); |
429 SkSTArray<8, GrGLInstalledFragProc*, true> fProcs; | 453 SkSTArray<8, GrGLInstalledFragProc*, true> fProcs; |
430 }; | 454 }; |
431 | 455 |
432 #endif | 456 #endif |
OLD | NEW |