OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrGLSLVarying_DEFINED | 8 #ifndef GrGLSLVarying_DEFINED |
9 #define GrGLSLVarying_DEFINED | 9 #define GrGLSLVarying_DEFINED |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 struct GrGLSLGeoToFrag : public GrGLSLVarying { | 64 struct GrGLSLGeoToFrag : public GrGLSLVarying { |
65 GrGLSLGeoToFrag(GrSLType type) | 65 GrGLSLGeoToFrag(GrSLType type) |
66 : GrGLSLVarying(type, kGeoToFrag_Varying) {} | 66 : GrGLSLVarying(type, kGeoToFrag_Varying) {} |
67 }; | 67 }; |
68 | 68 |
69 static const int kVaryingsPerBlock = 8; | 69 static const int kVaryingsPerBlock = 8; |
70 | 70 |
71 class GrGLSLVaryingHandler { | 71 class GrGLSLVaryingHandler { |
72 public: | 72 public: |
73 explicit GrGLSLVaryingHandler(GrGLSLProgramBuilder* program) | 73 explicit GrGLSLVaryingHandler(GrGLSLProgramBuilder* program) |
74 : fVertexInputs(kVaryingsPerBlock) | 74 : fVaryings(kVaryingsPerBlock) |
| 75 , fVertexInputs(kVaryingsPerBlock) |
75 , fVertexOutputs(kVaryingsPerBlock) | 76 , fVertexOutputs(kVaryingsPerBlock) |
76 , fGeomInputs(kVaryingsPerBlock) | 77 , fGeomInputs(kVaryingsPerBlock) |
77 , fGeomOutputs(kVaryingsPerBlock) | 78 , fGeomOutputs(kVaryingsPerBlock) |
78 , fFragInputs(kVaryingsPerBlock) | 79 , fFragInputs(kVaryingsPerBlock) |
79 , fFragOutputs(kVaryingsPerBlock) | 80 , fFragOutputs(kVaryingsPerBlock) |
80 , fProgramBuilder(program) {} | 81 , fProgramBuilder(program) |
| 82 , fDefaultInterpolationModifier(nullptr) {} |
81 | 83 |
82 virtual ~GrGLSLVaryingHandler() {} | 84 virtual ~GrGLSLVaryingHandler() {} |
83 | 85 |
84 typedef GrTAllocator<GrGLSLShaderVar> VarArray; | 86 /* |
85 typedef GrGLSLProgramDataManager::VaryingHandle VaryingHandle; | 87 * Notifies the varying handler that this shader will never emit geometry in
perspective and |
| 88 * therefore does not require perspective-correct interpolation. When suppor
ted, this allows |
| 89 * varyings to use the "noperspective" keyword, which means the GPU can use
cheaper math for |
| 90 * interpolation. |
| 91 */ |
| 92 void setNoPerspective(); |
86 | 93 |
87 /* | 94 /* |
88 * addVarying allows fine grained control for setting up varyings between st
ages. Calling this | 95 * addVarying allows fine grained control for setting up varyings between st
ages. Calling this |
89 * functions will make sure all necessary decls are setup for the client. Th
e client however is | 96 * functions will make sure all necessary decls are setup for the client. Th
e client however is |
90 * responsible for setting up all shader code (e.g "vOut = vIn;") If you jus
t need to take an | 97 * responsible for setting up all shader code (e.g "vOut = vIn;") If you jus
t need to take an |
91 * attribute and pass it through to an output value in a fragment shader, us
e | 98 * attribute and pass it through to an output value in a fragment shader, us
e |
92 * addPassThroughAttribute. | 99 * addPassThroughAttribute. |
93 * TODO convert most uses of addVarying to addPassThroughAttribute | 100 * TODO convert most uses of addVarying to addPassThroughAttribute |
94 */ | 101 */ |
95 void addVarying(const char* name, | 102 void addVarying(const char* name, |
96 GrGLSLVarying*, | 103 GrGLSLVarying* varying, |
97 GrSLPrecision precision = kDefault_GrSLPrecision); | 104 GrSLPrecision precision = kDefault_GrSLPrecision) { |
| 105 SkASSERT(GrSLTypeIsFloatType(varying->type())); // Integers must use add
FlatVarying. |
| 106 this->internalAddVarying(name, varying, precision, false /*flat*/); |
| 107 } |
98 | 108 |
99 /* | 109 /* |
100 * This call can be used by GP to pass an attribute through all shaders dire
ctly to 'output' in | 110 * addFlatVarying sets up a varying whose value is constant across every fra
gment. The graphics |
101 * the fragment shader. Though this call effects both the vertex shader and
fragment shader, | 111 * pipeline will pull its value from the final vertex of the draw primitive
(provoking vertex). |
102 * it expects 'output' to be defined in the fragment shader before this call
is made. If there | 112 * Flat interpolation is not always supported and the user must check the ca
ps before using. |
| 113 * TODO: Some platforms can change the provoking vertex. Should we be resett
ing this knob? |
| 114 */ |
| 115 void addFlatVarying(const char* name, |
| 116 GrGLSLVarying* varying, |
| 117 GrSLPrecision precision = kDefault_GrSLPrecision) { |
| 118 this->internalAddVarying(name, varying, precision, true /*flat*/); |
| 119 } |
| 120 |
| 121 /* |
| 122 * The GP can use these calls to pass an attribute through all shaders direc
tly to 'output' in |
| 123 * the fragment shader. Though these calls affect both the vertex shader an
d fragment shader, |
| 124 * they expect 'output' to be defined in the fragment shader before the call
is made. If there |
103 * is a geometry shader, we will simply take the value of the varying from t
he first vertex and | 125 * is a geometry shader, we will simply take the value of the varying from t
he first vertex and |
104 * that will be set as the output varying for all emitted vertices. | 126 * that will be set as the output varying for all emitted vertices. |
105 * TODO it might be nicer behavior to have a flag to declare output inside t
his call | 127 * TODO it might be nicer behavior to have a flag to declare output inside t
hese calls |
106 */ | 128 */ |
107 void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, const ch
ar* output); | 129 void addPassThroughAttribute(const GrGeometryProcessor::Attribute*, const ch
ar* output, |
| 130 GrSLPrecision = kDefault_GrSLPrecision); |
| 131 void addFlatPassThroughAttribute(const GrGeometryProcessor::Attribute*, cons
t char* output, |
| 132 GrSLPrecision = kDefault_GrSLPrecision); |
108 | 133 |
109 void emitAttributes(const GrGeometryProcessor& gp); | 134 void emitAttributes(const GrGeometryProcessor& gp); |
110 | 135 |
111 // This should be called once all attributes and varyings have been added to
the | 136 // This should be called once all attributes and varyings have been added to
the |
112 // GrGLSLVaryingHanlder and before getting/adding any of the declarations to
the shaders. | 137 // GrGLSLVaryingHanlder and before getting/adding any of the declarations to
the shaders. |
113 void finalize(); | 138 void finalize(); |
114 | 139 |
115 void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const; | 140 void getVertexDecls(SkString* inputDecls, SkString* outputDecls) const; |
116 void getGeomDecls(SkString* inputDecls, SkString* outputDecls) const; | 141 void getGeomDecls(SkString* inputDecls, SkString* outputDecls) const; |
117 void getFragDecls(SkString* inputDecls, SkString* outputDecls) const; | 142 void getFragDecls(SkString* inputDecls, SkString* outputDecls) const; |
| 143 |
118 protected: | 144 protected: |
119 VarArray fVertexInputs; | 145 struct VaryingInfo { |
120 VarArray fVertexOutputs; | 146 GrSLType fType; |
121 VarArray fGeomInputs; | 147 GrSLPrecision fPrecision; |
122 VarArray fGeomOutputs; | 148 bool fIsFlat; |
123 VarArray fFragInputs; | 149 SkString fVsOut; |
124 VarArray fFragOutputs; | 150 SkString fGsOut; |
| 151 GrShaderFlags fVisibility; |
| 152 }; |
| 153 |
| 154 typedef GrTAllocator<VaryingInfo> VaryingList; |
| 155 typedef GrTAllocator<GrGLSLShaderVar> VarArray; |
| 156 typedef GrGLSLProgramDataManager::VaryingHandle VaryingHandle; |
| 157 |
| 158 VaryingList fVaryings; |
| 159 VarArray fVertexInputs; |
| 160 VarArray fVertexOutputs; |
| 161 VarArray fGeomInputs; |
| 162 VarArray fGeomOutputs; |
| 163 VarArray fFragInputs; |
| 164 VarArray fFragOutputs; |
125 | 165 |
126 // This is not owned by the class | 166 // This is not owned by the class |
127 GrGLSLProgramBuilder* fProgramBuilder; | 167 GrGLSLProgramBuilder* fProgramBuilder; |
128 | 168 |
129 private: | 169 private: |
130 void addVertexVarying(const char* name, GrSLPrecision precision, GrGLSLVaryi
ng* v); | 170 void internalAddVarying(const char* name, GrGLSLVarying*, GrSLPrecision, boo
l flat); |
131 void addGeomVarying(const char* name, GrSLPrecision precision, GrGLSLVarying
* v); | 171 void writePassThroughAttribute(const GrGeometryProcessor::Attribute*, const
char* output, |
132 void addFragVarying(GrSLPrecision precision, GrGLSLVarying* v); | 172 const GrGLSLVarying&); |
133 | 173 |
134 void addAttribute(const GrShaderVar& var); | 174 void addAttribute(const GrShaderVar& var); |
135 | 175 |
136 virtual void onFinalize() = 0; | 176 virtual void onFinalize() = 0; |
137 | 177 |
138 // helper function for get*Decls | 178 // helper function for get*Decls |
139 void appendDecls(const VarArray& vars, SkString* out) const; | 179 void appendDecls(const VarArray& vars, SkString* out) const; |
140 | 180 |
| 181 const char* fDefaultInterpolationModifier; |
| 182 |
141 friend class GrGLSLProgramBuilder; | 183 friend class GrGLSLProgramBuilder; |
142 }; | 184 }; |
143 | 185 |
144 #endif | 186 #endif |
OLD | NEW |