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 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 /** Generates a shader program. | 111 /** Generates a shader program. |
112 * | 112 * |
113 * The program implements what is specified in the stages given as input. | 113 * The program implements what is specified in the stages given as input. |
114 * After successful generation, the builder result objects are available | 114 * After successful generation, the builder result objects are available |
115 * to be used. | 115 * to be used. |
116 * @return true if generation was successful. | 116 * @return true if generation was successful. |
117 */ | 117 */ |
118 static GrGLProgram* CreateProgram(const GrOptDrawState&, | 118 static GrGLProgram* CreateProgram(const GrOptDrawState&, |
119 const GrGLProgramDesc&, | 119 const GrGLProgramDesc&, |
120 GrGpu::DrawType, | 120 GrGpu::DrawType, |
121 const GrGeometryStage* inGeometryProcessor , | |
122 const GrFragmentStage* inColorStages[], | |
123 const GrFragmentStage* inCoverageStages[], | |
124 GrGpuGL* gpu); | 121 GrGpuGL* gpu); |
125 | 122 |
126 virtual UniformHandle addUniform(uint32_t visibility, | 123 virtual UniformHandle addUniform(uint32_t visibility, |
127 GrSLType type, | 124 GrSLType type, |
128 const char* name, | 125 const char* name, |
129 const char** outName = NULL) SK_OVERRIDE { | 126 const char** outName = NULL) SK_OVERRIDE { |
130 return this->addUniformArray(visibility, type, name, GrGLShaderVar::kNon Array, outName); | 127 return this->addUniformArray(visibility, type, name, GrGLShaderVar::kNon Array, outName); |
131 } | 128 } |
132 virtual UniformHandle addUniformArray(uint32_t visibility, | 129 virtual UniformHandle addUniformArray(uint32_t visibility, |
133 GrSLType type, | 130 GrSLType type, |
134 const char* name, | 131 const char* name, |
135 int arrayCount, | 132 int arrayCount, |
136 const char** outName = NULL) SK_OVERRI DE; | 133 const char** outName = NULL) SK_OVERRI DE; |
137 | 134 |
138 virtual const GrGLShaderVar& getUniformVariable(UniformHandle u) const SK_OV ERRIDE { | 135 virtual const GrGLShaderVar& getUniformVariable(UniformHandle u) const SK_OV ERRIDE { |
139 return fUniforms[u.toShaderBuilderIndex()].fVariable; | 136 return fUniforms[u.toShaderBuilderIndex()].fVariable; |
140 } | 137 } |
141 | 138 |
142 virtual const char* getUniformCStr(UniformHandle u) const SK_OVERRIDE { | 139 virtual const char* getUniformCStr(UniformHandle u) const SK_OVERRIDE { |
143 return this->getUniformVariable(u).c_str(); | 140 return this->getUniformVariable(u).c_str(); |
144 } | 141 } |
145 | 142 |
146 virtual const GrGLContextInfo& ctxInfo() const SK_OVERRIDE; | 143 virtual const GrGLContextInfo& ctxInfo() const SK_OVERRIDE; |
147 | 144 |
148 virtual GrGpuGL* gpu() const SK_OVERRIDE { return fGpu; } | 145 virtual GrGpuGL* gpu() const SK_OVERRIDE { return fGpu; } |
149 | 146 |
150 virtual GrGLFragmentShaderBuilder* getFragmentShaderBuilder() SK_OVERRIDE { return &fFS; } | 147 virtual GrGLFragmentShaderBuilder* getFragmentShaderBuilder() SK_OVERRIDE { return &fFS; } |
151 virtual GrGLVertexBuilder* getVertexShaderBuilder() SK_OVERRIDE { return &fV S; } | 148 virtual GrGLVertexBuilder* getVertexShaderBuilder() SK_OVERRIDE { return &fV S; } |
152 | 149 |
153 virtual void addVarying(GrSLType type, | 150 virtual void addVarying( |
154 const char* name, | 151 GrSLType type, |
155 const char** vsOutName = NULL, | 152 const char* name, |
156 const char** fsInName = NULL, | 153 const char** vsOutName = NULL, |
157 GrGLShaderVar::Precision fsPrecision=GrGLShaderVar:: kDefault_Precision); | 154 const char** fsInName = NULL, |
155 GrGLShaderVar::Precision fsPrecision=GrGLShaderVar::kDefault_Precisi on) SK_OVERRIDE; | |
158 | 156 |
159 // Handles for program uniforms (other than per-effect uniforms) | 157 // Handles for program uniforms (other than per-effect uniforms) |
160 struct BuiltinUniformHandles { | 158 struct BuiltinUniformHandles { |
161 UniformHandle fViewMatrixUni; | 159 UniformHandle fViewMatrixUni; |
162 UniformHandle fRTAdjustmentUni; | 160 UniformHandle fRTAdjustmentUni; |
163 UniformHandle fColorUni; | 161 UniformHandle fColorUni; |
164 UniformHandle fCoverageUni; | 162 UniformHandle fCoverageUni; |
165 | 163 |
166 // We use the render target height to provide a y-down frag coord when s pecifying | 164 // We use the render target height to provide a y-down frag coord when s pecifying |
167 // origin_upper_left is not supported. | 165 // origin_upper_left is not supported. |
168 UniformHandle fRTHeightUni; | 166 UniformHandle fRTHeightUni; |
169 | 167 |
170 // Uniforms for computing texture coords to do the dst-copy lookup | 168 // Uniforms for computing texture coords to do the dst-copy lookup |
171 UniformHandle fDstCopyTopLeftUni; | 169 UniformHandle fDstCopyTopLeftUni; |
172 UniformHandle fDstCopyScaleUni; | 170 UniformHandle fDstCopyScaleUni; |
173 UniformHandle fDstCopySamplerUni; | 171 UniformHandle fDstCopySamplerUni; |
174 }; | 172 }; |
175 | 173 |
176 protected: | 174 protected: |
175 typedef GrGLProgramDesc::EffectKeyProvider EffectKeyProvider; | |
176 typedef GrGLProgramDataManager::UniformInfo UniformInfo; | |
177 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; | |
178 | |
177 static GrGLProgramBuilder* CreateProgramBuilder(const GrGLProgramDesc&, | 179 static GrGLProgramBuilder* CreateProgramBuilder(const GrGLProgramDesc&, |
178 const GrOptDrawState&, | 180 const GrOptDrawState&, |
179 GrGpu::DrawType, | 181 GrGpu::DrawType, |
180 bool hasGeometryProcessor, | 182 bool hasGeometryProcessor, |
181 GrGpuGL*); | 183 GrGpuGL*); |
182 | 184 |
183 GrGLProgramBuilder(GrGpuGL*, const GrOptDrawState&, const GrGLProgramDesc&); | 185 GrGLProgramBuilder(GrGpuGL*, const GrOptDrawState&, const GrGLProgramDesc&); |
184 | 186 |
185 const GrOptDrawState& optState() const { return fOptState; } | 187 const GrOptDrawState& optState() const { return fOptState; } |
186 const GrGLProgramDesc& desc() const { return fDesc; } | 188 const GrGLProgramDesc& desc() const { return fDesc; } |
187 const GrGLProgramDesc::KeyHeader& header() const { return fDesc.getHeader(); } | 189 const GrGLProgramDesc::KeyHeader& header() const { return fDesc.getHeader(); } |
188 | 190 |
189 // Generates a name for a variable. The generated string will be name prefix ed by the prefix | 191 // Generates a name for a variable. The generated string will be name prefix ed by the prefix |
190 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp ecific if we're | 192 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp ecific if we're |
191 // generating stage code. | 193 // generating stage code. |
192 void nameVariable(SkString* out, char prefix, const char* name); | 194 void nameVariable(SkString* out, char prefix, const char* name); |
193 void setupUniformColorAndCoverageIfNeeded(GrGLSLExpr4* inputColor, GrGLSLExp r4* inputCoverage); | 195 void setupUniformColorAndCoverageIfNeeded(GrGLSLExpr4* inputColor, GrGLSLExp r4* inputCoverage); |
194 void createAndEmitProcessors(const GrGeometryStage* geometryProcessor, | 196 template <class ClassMap> |
195 const GrFragmentStage* colorStages[], | 197 void createAndEmitProcessors(const EffectKeyProvider::EffectType, |
bsalomon
2014/10/09 18:35:45
Another place where it seems like we're trying to
| |
196 const GrFragmentStage* coverageStages[], | 198 bool useLocalCoords, |
197 GrGLSLExpr4* inputColor, | 199 SkAutoTUnref<GrGLInstalledProcessors>*, |
198 GrGLSLExpr4* inputCoverage); | 200 GrGLSLExpr4* fsInOutColor); |
199 template <class ProcessorStage> | |
200 void createAndEmitProcessors(const ProcessorStage*[], | |
201 int effectCnt, | |
202 const GrGLProgramDesc::EffectKeyProvider&, | |
203 GrGLSLExpr4* fsInOutColor, | |
204 GrGLInstalledProcessors*); | |
205 void verify(const GrGeometryProcessor&); | 201 void verify(const GrGeometryProcessor&); |
206 void verify(const GrFragmentProcessor&); | 202 void verify(const GrFragmentProcessor&); |
207 void emitSamplers(const GrProcessor&, | 203 void emitSamplers(const GrProcessor&, |
208 GrGLProcessor::TextureSamplerArray* outSamplers, | 204 GrGLProcessor::TextureSamplerArray* outSamplers, |
209 GrGLInstalledProcessors*); | 205 GrGLInstalledProcessors*); |
210 | 206 |
207 // these emit functions help to keep the createAndEmitProcessors template ge neral | |
208 void emit(const GrFragmentStage&, | |
209 const GrProcessorKey&, | |
210 const char* outColor, | |
211 const char* inColor, | |
212 const GrGLProcessor::TextureSamplerArray&, | |
213 GrGLInstalledProcessors*, | |
214 GrGLFragmentProcessor*); | |
215 void emit(const GrGeometryProcessor&, | |
216 const GrProcessorKey&, | |
217 const char* outColor, | |
218 const char* inColor, | |
219 const GrGLProcessor::TextureSamplerArray&, | |
220 GrGLInstalledProcessors*, | |
221 GrGLGeometryProcessor*); | |
222 | |
211 // each specific program builder has a distinct transform and must override this function | 223 // each specific program builder has a distinct transform and must override this function |
212 virtual void emitTransforms(const GrProcessorStage&, | 224 virtual void emitTransforms(const GrFragmentStage&, |
213 GrGLProcessor::TransformedCoordsArray* outCoords , | 225 GrGLProcessor::TransformedCoordsArray* outCoords , |
214 GrGLInstalledProcessors*); | 226 GrGLInstalledProcessors*); |
215 GrGLProgram* finalize(); | 227 GrGLProgram* finalize(); |
216 void bindUniformLocations(GrGLuint programID); | 228 void bindUniformLocations(GrGLuint programID); |
217 bool checkLinkStatus(GrGLuint programID); | 229 bool checkLinkStatus(GrGLuint programID); |
218 void resolveUniformLocations(GrGLuint programID); | 230 void resolveUniformLocations(GrGLuint programID); |
219 | |
220 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs ); | 231 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs ); |
221 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); | 232 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); |
222 | 233 |
223 // Subclasses create different programs | 234 // Subclasses create different programs |
224 virtual GrGLProgram* createProgram(GrGLuint programID); | 235 virtual GrGLProgram* createProgram(GrGLuint programID); |
225 | 236 |
226 void appendUniformDecls(ShaderVisibility, SkString*) const; | 237 void appendUniformDecls(ShaderVisibility, SkString*) const; |
227 | 238 |
228 // reset is called by program creator between each processor's emit code. I t increments the | 239 // reset is called by program creator between each processor's emit code. I t increments the |
229 // stage offset for variable name mangling, and also ensures verfication var iables in the | 240 // stage offset for variable name mangling, and also ensures verfication var iables in the |
(...skipping 19 matching lines...) Expand all Loading... | |
249 public: | 260 public: |
250 AutoStageAdvance(GrGLProgramBuilder* pb) : fPB(pb) { fPB->reset(); } | 261 AutoStageAdvance(GrGLProgramBuilder* pb) : fPB(pb) { fPB->reset(); } |
251 ~AutoStageAdvance() { fPB->exitStage(); } | 262 ~AutoStageAdvance() { fPB->exitStage(); } |
252 private: | 263 private: |
253 GrGLProgramBuilder* fPB; | 264 GrGLProgramBuilder* fPB; |
254 }; | 265 }; |
255 void exitStage() { fOutOfStage = true; } | 266 void exitStage() { fOutOfStage = true; } |
256 void enterStage() { fOutOfStage = false; } | 267 void enterStage() { fOutOfStage = false; } |
257 int stageIndex() const { return fStageIndex; } | 268 int stageIndex() const { return fStageIndex; } |
258 | 269 |
259 typedef GrGLProgramDesc::EffectKeyProvider EffectKeyProvider; | |
260 typedef GrGLProgramDataManager::UniformInfo UniformInfo; | |
261 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; | |
262 | |
263 // number of each input/output type in a single allocation block, used by ma ny builders | 270 // number of each input/output type in a single allocation block, used by ma ny builders |
264 static const int kVarsPerBlock; | 271 static const int kVarsPerBlock; |
265 | 272 |
266 BuiltinUniformHandles fUniformHandles; | 273 BuiltinUniformHandles fUniformHandles; |
267 GrGLVertexBuilder fVS; | 274 GrGLVertexBuilder fVS; |
268 GrGLGeometryBuilder fGS; | 275 GrGLGeometryBuilder fGS; |
269 GrGLFragmentShaderBuilder fFS; | 276 GrGLFragmentShaderBuilder fFS; |
270 bool fOutOfStage; | 277 bool fOutOfStage; |
271 int fStageIndex; | 278 int fStageIndex; |
272 | 279 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 SkTArray<SkSTArray<2, Transform, true> > fTransforms; | 350 SkTArray<SkSTArray<2, Transform, true> > fTransforms; |
344 bool fHasExplicitLocalCoords; | 351 bool fHasExplicitLocalCoords; |
345 | 352 |
346 friend class GrGLShaderBuilder; | 353 friend class GrGLShaderBuilder; |
347 friend class GrGLVertexShaderBuilder; | 354 friend class GrGLVertexShaderBuilder; |
348 friend class GrGLFragmentShaderBuilder; | 355 friend class GrGLFragmentShaderBuilder; |
349 friend class GrGLGeometryShaderBuilder; | 356 friend class GrGLGeometryShaderBuilder; |
350 }; | 357 }; |
351 | 358 |
352 #endif | 359 #endif |
OLD | NEW |