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