| 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 | 10 |
| 11 #include "GrGLShaderBuilder.h" | 11 #include "GrGLShaderBuilder.h" |
| 12 | 12 |
| 13 class GrGLVarying; | 13 class GrGLVarying; |
| 14 | 14 |
| 15 /* | 15 /* |
| 16 * This base class encapsulates the functionality which the GP uses to build fra
gment shaders | 16 * This base class encapsulates the functionality which the GP uses to build fra
gment shaders |
| 17 */ | 17 */ |
| 18 class GrGLFragmentBuilder : public GrGLShaderBuilder { | 18 class GrGLFragmentBuilder : public GrGLShaderBuilder { |
| 19 public: | 19 public: |
| 20 GrGLFragmentBuilder(GrGLProgramBuilder* program) : INHERITED(program) {} | 20 GrGLFragmentBuilder(GrGLProgramBuilder* program) |
| 21 : INHERITED(program) { |
| 22 fSubstageIndices.push_back(0); |
| 23 } |
| 21 virtual ~GrGLFragmentBuilder() {} | 24 virtual ~GrGLFragmentBuilder() {} |
| 22 /** | 25 /** |
| 23 * Use of these features may require a GLSL extension to be enabled. Shaders
may not compile | 26 * Use of these features may require a GLSL extension to be enabled. Shaders
may not compile |
| 24 * if code is added that uses one of these features without calling enableFe
ature() | 27 * if code is added that uses one of these features without calling enableFe
ature() |
| 25 */ | 28 */ |
| 26 enum GLSLFeature { | 29 enum GLSLFeature { |
| 27 kStandardDerivatives_GLSLFeature = 0, | 30 kStandardDerivatives_GLSLFeature = 0, |
| 28 kLastGLSLFeature = kStandardDerivatives_GLSLFeature | 31 kLastGLSLFeature = kStandardDerivatives_GLSLFeature |
| 29 }; | 32 }; |
| 30 | 33 |
| 31 /** | 34 /** |
| 32 * If the feature is supported then true is returned and any necessary #exte
nsion declarations | 35 * If the feature is supported then true is returned and any necessary #exte
nsion declarations |
| 33 * are added to the shaders. If the feature is not supported then false will
be returned. | 36 * are added to the shaders. If the feature is not supported then false will
be returned. |
| 34 */ | 37 */ |
| 35 virtual bool enableFeature(GLSLFeature) = 0; | 38 virtual bool enableFeature(GLSLFeature) = 0; |
| 36 | 39 |
| 37 /** | 40 /** |
| 38 * This returns a variable name to access the 2D, perspective correct versio
n of the coords in | 41 * This returns a variable name to access the 2D, perspective correct versio
n of the coords in |
| 39 * the fragment shader. If the coordinates at index are 3-dimensional, it im
mediately emits a | 42 * the fragment shader. If the coordinates at index are 3-dimensional, it im
mediately emits a |
| 40 * perspective divide into the fragment shader (xy / z) to convert them to 2
D. | 43 * perspective divide into the fragment shader (xy / z) to convert them to 2
D. |
| 41 */ | 44 */ |
| 42 virtual SkString ensureFSCoords2D(const GrGLProcessor::TransformedCoordsArra
y& coords, | 45 virtual SkString ensureFSCoords2D(const GrGLProcessor::TransformedCoordsArra
y& coords, |
| 43 int index) = 0; | 46 int index) = 0; |
| 44 | 47 |
| 45 | 48 |
| 46 /** Returns a variable name that represents the position of the fragment in
the FS. The position | 49 /** Returns a variable name that represents the position of the fragment in
the FS. The position |
| 47 is in device space (e.g. 0,0 is the top left and pixel centers are at ha
lf-integers). */ | 50 is in device space (e.g. 0,0 is the top left and pixel centers are at ha
lf-integers). */ |
| 48 virtual const char* fragmentPosition() = 0; | 51 virtual const char* fragmentPosition() = 0; |
| 49 | 52 |
| 53 /** |
| 54 * Fragment procs with child procs should call these functions before/after
calling emitCode |
| 55 * on a child proc. |
| 56 */ |
| 57 void onBeforeChildProcEmitCode(); |
| 58 void onAfterChildProcEmitCode(); |
| 59 |
| 60 int getChildNumberThisLevel() const { |
| 61 if (fSubstageIndices.count() > 1) { |
| 62 // second-to-last value in the fSubstageIndices stack is the index o
f the child proc |
| 63 // at that level which is currently emitting code. |
| 64 return fSubstageIndices[fSubstageIndices.count() - 2]; |
| 65 } |
| 66 return -1; |
| 67 } |
| 68 |
| 69 const SkString& getMangleString() const { return fMangleString; } |
| 70 |
| 71 SkString getMangleStringThisLevel() const { |
| 72 SkString ret; |
| 73 int childNumber = this->getChildNumberThisLevel(); |
| 74 if (childNumber >= 0) { |
| 75 ret.printf("_c%d", childNumber); |
| 76 } |
| 77 return ret; |
| 78 } |
| 79 |
| 50 private: | 80 private: |
| 81 /* |
| 82 * State that tracks which child proc in the proc tree is currently emitting
code. This is |
| 83 * used to update the fMangleString, which is used to mangle the names of un
iforms and functions |
| 84 * emitted by the proc. fSubstageIndices is a stack: its count indicates ho
w many levels deep |
| 85 * we are in the tree, and its second-to-last value is the index of the chil
d proc at that |
| 86 * level which is currently emitting code. For example, if fSubstageIndices
= [3, 1, 2, 0], that |
| 87 * means we're currently emitting code for the base proc's 3rd child's 1st c
hild's 2nd child. |
| 88 */ |
| 89 SkTArray<int> fSubstageIndices; |
| 90 |
| 91 /* |
| 92 * The mangle string is used to mangle the names of uniforms/functions emitt
ed by the child |
| 93 * procs so no duplicate uniforms/functions appear in the generated shader p
rogram. The mangle |
| 94 * string is simply based on fSubstageIndices. For example, if fSubstageIndi
ces = [3, 1, 2, 0], |
| 95 * then the manglestring will be "_c3_c1_c2", and any uniform/function emitt
ed by that proc will |
| 96 * have "_c3_c1_c2" appended to its name, which can be interpreted as "base
proc's 3rd child's |
| 97 * 1st child's 2nd child". |
| 98 */ |
| 99 SkString fMangleString; |
| 100 |
| 51 friend class GrGLPathProcessor; | 101 friend class GrGLPathProcessor; |
| 52 | 102 |
| 53 typedef GrGLShaderBuilder INHERITED; | 103 typedef GrGLShaderBuilder INHERITED; |
| 54 }; | 104 }; |
| 55 | 105 |
| 56 /* | 106 /* |
| 57 * Fragment processor's, in addition to all of the above, may need to use dst co
lor so they use | 107 * Fragment processor's, in addition to all of the above, may need to use dst co
lor so they use |
| 58 * this builder to create their shader. Because this is the only shader builder
the FP sees, we | 108 * this builder to create their shader. Because this is the only shader builder
the FP sees, we |
| 59 * just call it FPShaderBuilder | 109 * just call it FPShaderBuilder |
| 60 */ | 110 */ |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // the program creator | 212 // the program creator |
| 163 bool fHasReadDstColor; | 213 bool fHasReadDstColor; |
| 164 bool fHasReadFragmentPosition; | 214 bool fHasReadFragmentPosition; |
| 165 | 215 |
| 166 friend class GrGLProgramBuilder; | 216 friend class GrGLProgramBuilder; |
| 167 | 217 |
| 168 typedef GrGLXPFragmentBuilder INHERITED; | 218 typedef GrGLXPFragmentBuilder INHERITED; |
| 169 }; | 219 }; |
| 170 | 220 |
| 171 #endif | 221 #endif |
| OLD | NEW |