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