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 GrGLFragmentShaderBuilder_DEFINED | 8 #ifndef GrGLFragmentShaderBuilder_DEFINED |
9 #define GrGLFragmentShaderBuilder_DEFINED | 9 #define GrGLFragmentShaderBuilder_DEFINED |
10 #include "GrGLShaderBuilder.h" | 10 #include "GrGLShaderBuilder.h" |
11 | 11 |
12 class GrGLProgramBuilder; | 12 class GrGLProgramBuilder; |
13 | 13 |
14 class GrGLFragmentShaderBuilder : public GrGLShaderBuilder { | 14 class GrGLBaseFragmentShaderBuilder : public GrGLShaderBuilder { |
bsalomon
2014/09/22 15:35:24
The name's are starting to get a bit confusing, I
joshua.litt
2014/09/22 18:14:44
I will use these names for now. Immediately after
| |
15 public: | 15 public: |
16 typedef uint8_t DstReadKey; | 16 GrGLBaseFragmentShaderBuilder(GrGLProgramBuilder* program) : INHERITED(progr am) {} |
17 typedef uint8_t FragPosKey; | 17 virtual ~GrGLBaseFragmentShaderBuilder() {} |
18 | |
19 /** Returns a key for adding code to read the copy-of-dst color in service of effects that | |
20 require reading the dst. It must not return 0 because 0 indicates that t here is no dst | |
21 copy read at all (in which case this function should not be called). */ | |
22 static DstReadKey KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps&); | |
23 | |
24 /** Returns a key for reading the fragment location. This should only be cal led if there is an | |
25 effect that will requires the fragment position. If the fragment position is not required, | |
26 the key is 0. */ | |
27 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst, const Gr GLCaps&); | |
28 | |
29 GrGLFragmentShaderBuilder(GrGLProgramBuilder* program, const GrGLProgramDesc & desc); | |
30 | |
31 /** Returns the variable name that holds the color of the destination pixel. This may be NULL if | |
32 no effect advertised that it will read the destination. */ | |
33 const char* dstColor(); | |
34 | |
35 /** | 18 /** |
36 * Use of these features may require a GLSL extension to be enabled. Shaders may not compile | 19 * Use of these features may require a GLSL extension to be enabled. Shaders may not compile |
37 * if code is added that uses one of these features without calling enableFe ature() | 20 * if code is added that uses one of these features without calling enableFe ature() |
38 */ | 21 */ |
39 enum GLSLFeature { | 22 enum GLSLFeature { |
40 kStandardDerivatives_GLSLFeature = 0, | 23 kStandardDerivatives_GLSLFeature = 0, |
41 kLastGLSLFeature = kStandardDerivatives_GLSLFeature | 24 kLastGLSLFeature = kStandardDerivatives_GLSLFeature |
42 }; | 25 }; |
43 | 26 |
44 /** | 27 /** |
45 * If the feature is supported then true is returned and any necessary #exte nsion declarations | 28 * If the feature is supported then true is returned and any necessary #exte nsion declarations |
46 * are added to the shaders. If the feature is not supported then false will be returned. | 29 * are added to the shaders. If the feature is not supported then false will be returned. |
47 */ | 30 */ |
48 bool enableFeature(GLSLFeature); | 31 virtual bool enableFeature(GLSLFeature) = 0; |
49 | 32 |
50 /** | 33 /** |
51 * This returns a variable name to access the 2D, perspective correct versio n of the coords in | 34 * This returns a variable name to access the 2D, perspective correct versio n of the coords in |
52 * the fragment shader. If the coordinates at index are 3-dimensional, it im mediately emits a | 35 * the fragment shader. If the coordinates at index are 3-dimensional, it im mediately emits a |
53 * perspective divide into the fragment shader (xy / z) to convert them to 2 D. | 36 * perspective divide into the fragment shader (xy / z) to convert them to 2 D. |
54 */ | 37 */ |
55 SkString ensureFSCoords2D(const TransformedCoordsArray& coords, int index); | 38 virtual SkString ensureFSCoords2D(const GrGLProcessor::TransformedCoordsArra y& coords, |
39 int index) = 0; | |
56 | 40 |
57 | 41 |
58 /** Returns a variable name that represents the position of the fragment in the FS. The position | 42 /** Returns a variable name that represents the position of the fragment in the FS. The position |
59 is in device space (e.g. 0,0 is the top left and pixel centers are at ha lf-integers). */ | 43 is in device space (e.g. 0,0 is the top left and pixel centers are at ha lf-integers). */ |
60 const char* fragmentPosition(); | 44 virtual const char* fragmentPosition() = 0; |
45 | |
46 private: | |
47 typedef GrGLShaderBuilder INHERITED; | |
48 }; | |
49 | |
50 class GrGLFullFragmentShaderBuilder : public GrGLBaseFragmentShaderBuilder { | |
51 public: | |
52 GrGLFullFragmentShaderBuilder(GrGLProgramBuilder* program) : INHERITED(progr am) {} | |
53 /** Returns the variable name that holds the color of the destination pixel. This may be NULL if | |
54 no effect advertised that it will read the destination. */ | |
55 virtual const char* dstColor() = 0; | |
56 | |
57 private: | |
58 typedef GrGLBaseFragmentShaderBuilder INHERITED; | |
59 }; | |
60 | |
61 class GrGLFragmentShaderBuilder : public GrGLFullFragmentShaderBuilder { | |
62 public: | |
63 typedef uint8_t DstReadKey; | |
64 typedef uint8_t FragPosKey; | |
65 | |
66 /** Returns a key for adding code to read the copy-of-dst color in service of effects that | |
67 require reading the dst. It must not return 0 because 0 indicates that t here is no dst | |
68 copy read at all (in which case this function should not be called). */ | |
69 static DstReadKey KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps&); | |
70 | |
71 /** Returns a key for reading the fragment location. This should only be cal led if there is an | |
72 effect that will requires the fragment position. If the fragment position is not required, | |
73 the key is 0. */ | |
74 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst, const Gr GLCaps&); | |
75 | |
76 GrGLFragmentShaderBuilder(GrGLProgramBuilder* program, const GrGLProgramDesc & desc); | |
77 | |
78 virtual const char* dstColor() SK_OVERRIDE; | |
79 | |
80 virtual bool enableFeature(GLSLFeature) SK_OVERRIDE; | |
81 | |
82 virtual SkString ensureFSCoords2D(const GrGLProcessor::TransformedCoordsArra y& coords, | |
83 int index) SK_OVERRIDE; | |
84 | |
85 virtual const char* fragmentPosition() SK_OVERRIDE; | |
61 | 86 |
62 private: | 87 private: |
63 /* | 88 /* |
64 * An internal call for GrGLFullProgramBuilder to use to add varyings to the vertex shader | 89 * An internal call for GrGLFullProgramBuilder to use to add varyings to the vertex shader |
65 */ | 90 */ |
66 void addVarying(GrSLType type, | 91 void addVarying(GrSLType type, |
67 const char* name, | 92 const char* name, |
68 const char** fsInName, | 93 const char** fsInName, |
69 GrGLShaderVar::Precision fsPrecision = GrGLShaderVar::kDefaul t_Precision); | 94 GrGLShaderVar::Precision fsPrecision = GrGLShaderVar::kDefaul t_Precision); |
70 | 95 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 }; | 131 }; |
107 | 132 |
108 bool fHasCustomColorOutput; | 133 bool fHasCustomColorOutput; |
109 bool fHasSecondaryOutput; | 134 bool fHasSecondaryOutput; |
110 bool fSetupFragPosition; | 135 bool fSetupFragPosition; |
111 bool fTopLeftFragPosRead; | 136 bool fTopLeftFragPosRead; |
112 | 137 |
113 friend class GrGLProgramBuilder; | 138 friend class GrGLProgramBuilder; |
114 friend class GrGLFullProgramBuilder; | 139 friend class GrGLFullProgramBuilder; |
115 | 140 |
116 typedef GrGLShaderBuilder INHERITED; | 141 typedef GrGLFullFragmentShaderBuilder INHERITED; |
117 }; | 142 }; |
118 | 143 |
119 #endif | 144 #endif |
OLD | NEW |