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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 }; | 224 }; |
225 | 225 |
226 protected: | 226 protected: |
227 typedef GrGLProgramDesc::ProcKeyProvider ProcKeyProvider; | 227 typedef GrGLProgramDesc::ProcKeyProvider ProcKeyProvider; |
228 typedef GrGLProgramDataManager::UniformInfo UniformInfo; | 228 typedef GrGLProgramDataManager::UniformInfo UniformInfo; |
229 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; | 229 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; |
230 | 230 |
231 static GrGLProgramBuilder* CreateProgramBuilder(const GrGLProgramDesc&, | 231 static GrGLProgramBuilder* CreateProgramBuilder(const GrGLProgramDesc&, |
232 const GrOptDrawState&, | 232 const GrOptDrawState&, |
233 GrGpu::DrawType, | 233 GrGpu::DrawType, |
234 bool hasGeometryProcessor, | |
235 GrGpuGL*); | 234 GrGpuGL*); |
| 235 virtual GrGLProgram* create(); |
236 | 236 |
237 GrGLProgramBuilder(GrGpuGL*, const GrOptDrawState&, const GrGLProgramDesc&); | 237 GrGLProgramBuilder(GrGpuGL*, const GrOptDrawState&, const GrGLProgramDesc&); |
238 | 238 |
239 const GrOptDrawState& optState() const { return fOptState; } | 239 const GrOptDrawState& optState() const { return fOptState; } |
240 const GrGLProgramDesc& desc() const { return fDesc; } | 240 const GrGLProgramDesc& desc() const { return fDesc; } |
241 const GrGLProgramDesc::KeyHeader& header() const { return fDesc.getHeader();
} | 241 const GrGLProgramDesc::KeyHeader& header() const { return fDesc.getHeader();
} |
242 | 242 |
243 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix | 243 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix |
244 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're | 244 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're |
245 // generating stage code. | 245 // generating stage code. |
246 void nameVariable(SkString* out, char prefix, const char* name); | 246 void nameVariable(SkString* out, char prefix, const char* name); |
247 void setupUniformColorAndCoverageIfNeeded(GrGLSLExpr4* inputColor, GrGLSLExp
r4* inputCoverage); | 247 void setupUniformColorAndCoverageIfNeeded(GrGLSLExpr4* inputColor, GrGLSLExp
r4* inputCoverage); |
248 void emitAndInstallProcs(const GrOptDrawState& optState, | 248 void emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage
); |
249 GrGLSLExpr4* inputColor, | |
250 GrGLSLExpr4* inputCoverage); | |
251 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu
t); | 249 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu
t); |
252 template <class Proc> | 250 template <class Proc> |
253 void emitAndInstallProc(const Proc&, | 251 void emitAndInstallProc(const Proc&, |
254 int index, | 252 int index, |
255 const ProcKeyProvider, | 253 const ProcKeyProvider, |
256 const GrGLSLExpr4& input, | 254 const GrGLSLExpr4& input, |
257 GrGLSLExpr4* output); | 255 GrGLSLExpr4* output); |
258 | 256 |
259 // these emit functions help to keep the createAndEmitProcessors template ge
neral | 257 // these emit functions help to keep the createAndEmitProcessors template ge
neral |
260 void emitAndInstallProc(const GrFragmentStage&, | 258 void emitAndInstallProc(const GrFragmentStage&, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 public: | 309 public: |
312 AutoStageAdvance(GrGLProgramBuilder* pb) : fPB(pb) { fPB->reset(); } | 310 AutoStageAdvance(GrGLProgramBuilder* pb) : fPB(pb) { fPB->reset(); } |
313 ~AutoStageAdvance() { fPB->exitStage(); } | 311 ~AutoStageAdvance() { fPB->exitStage(); } |
314 private: | 312 private: |
315 GrGLProgramBuilder* fPB; | 313 GrGLProgramBuilder* fPB; |
316 }; | 314 }; |
317 void exitStage() { fOutOfStage = true; } | 315 void exitStage() { fOutOfStage = true; } |
318 void enterStage() { fOutOfStage = false; } | 316 void enterStage() { fOutOfStage = false; } |
319 int stageIndex() const { return fStageIndex; } | 317 int stageIndex() const { return fStageIndex; } |
320 | 318 |
| 319 struct TransformVarying { |
| 320 TransformVarying(const GrGLVarying& v, const char* uniName, const char*
sourceCoords) |
| 321 : fV(v), fUniName(uniName), fSourceCoords(sourceCoords) {} |
| 322 GrGLVarying fV; |
| 323 SkString fUniName; |
| 324 SkString fSourceCoords; |
| 325 }; |
| 326 |
| 327 void addCoordVarying(const char* name, GrGLVarying* v, const char* uniName, |
| 328 const char* sourceCoords) { |
| 329 this->addVarying(name, v); |
| 330 fCoordVaryings.push_back(TransformVarying(*v, uniName, sourceCoords)); |
| 331 } |
| 332 |
| 333 const char* rtAdjustment() const { return "rtAdjustment"; } |
| 334 |
321 // number of each input/output type in a single allocation block, used by ma
ny builders | 335 // number of each input/output type in a single allocation block, used by ma
ny builders |
322 static const int kVarsPerBlock; | 336 static const int kVarsPerBlock; |
323 | 337 |
324 BuiltinUniformHandles fUniformHandles; | 338 BuiltinUniformHandles fUniformHandles; |
325 GrGLVertexBuilder fVS; | 339 GrGLVertexBuilder fVS; |
326 GrGLGeometryBuilder fGS; | 340 GrGLGeometryBuilder fGS; |
327 GrGLFragmentShaderBuilder fFS; | 341 GrGLFragmentShaderBuilder fFS; |
328 bool fOutOfStage; | 342 bool fOutOfStage; |
329 int fStageIndex; | 343 int fStageIndex; |
330 | 344 |
331 GrGLInstalledGeoProc* fGeometryProcessor; | 345 GrGLInstalledGeoProc* fGeometryProcessor; |
332 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; | 346 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; |
333 | 347 |
334 const GrOptDrawState& fOptState; | 348 const GrOptDrawState& fOptState; |
335 const GrGLProgramDesc& fDesc; | 349 const GrGLProgramDesc& fDesc; |
336 GrGpuGL* fGpu; | 350 GrGpuGL* fGpu; |
337 UniformInfoArray fUniforms; | 351 UniformInfoArray fUniforms; |
| 352 SkSTArray<16, TransformVarying, true> fCoordVaryings; |
338 | 353 |
339 friend class GrGLShaderBuilder; | 354 friend class GrGLShaderBuilder; |
340 friend class GrGLVertexBuilder; | 355 friend class GrGLVertexBuilder; |
341 friend class GrGLFragmentShaderBuilder; | 356 friend class GrGLFragmentShaderBuilder; |
342 friend class GrGLGeometryBuilder; | 357 friend class GrGLGeometryBuilder; |
343 }; | 358 }; |
344 | 359 |
345 /** | 360 /** |
346 * The below structs represent processors installed in programs. All processors
can have texture | 361 * The below structs represent processors installed in programs. All processors
can have texture |
347 * samplers, but only frag processors have coord transforms, hence the need for
different structs | 362 * samplers, but only frag processors have coord transforms, hence the need for
different structs |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 SkSTArray<2, Transform, true> fTransforms; | 404 SkSTArray<2, Transform, true> fTransforms; |
390 bool fLocalCoordAttrib; | 405 bool fLocalCoordAttrib; |
391 }; | 406 }; |
392 | 407 |
393 struct GrGLInstalledFragProcs : public SkRefCnt { | 408 struct GrGLInstalledFragProcs : public SkRefCnt { |
394 virtual ~GrGLInstalledFragProcs(); | 409 virtual ~GrGLInstalledFragProcs(); |
395 SkSTArray<8, GrGLInstalledFragProc*, true> fProcs; | 410 SkSTArray<8, GrGLInstalledFragProc*, true> fProcs; |
396 }; | 411 }; |
397 | 412 |
398 #endif | 413 #endif |
OLD | NEW |