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