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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 const char** outName = nullptr) { | 61 const char** outName = nullptr) { |
62 return this->addUniformArray(visibility, type, precision, name, 0, outNa
me); | 62 return this->addUniformArray(visibility, type, precision, name, 0, outNa
me); |
63 } | 63 } |
64 | 64 |
65 virtual UniformHandle addUniformArray( | 65 virtual UniformHandle addUniformArray( |
66 uint32_t visibility, | 66 uint32_t visibility, |
67 GrSLType type, | 67 GrSLType type, |
68 GrSLPrecision precision, | 68 GrSLPrecision precision, |
69 const char* name, | 69 const char* name, |
70 int arrayCount, | 70 int arrayCount, |
71 const char** outName = nullptr) = 0; | 71 const char** outName = nullptr) { |
| 72 return this->internalAddUniformArray(visibility, type, precision, name,
true, arrayCount, |
| 73 outName); |
| 74 } |
| 75 |
72 | 76 |
73 virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0
; | 77 virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0
; |
74 | 78 |
75 /** | 79 /** |
76 * Shortcut for getUniformVariable(u).c_str() | 80 * Shortcut for getUniformVariable(u).c_str() |
77 */ | 81 */ |
78 virtual const char* getUniformCStr(UniformHandle u) const = 0; | 82 virtual const char* getUniformCStr(UniformHandle u) const = 0; |
79 | 83 |
80 virtual const GrGLContextInfo& ctxInfo() const = 0; | 84 virtual const GrGLContextInfo& ctxInfo() const = 0; |
81 | 85 |
82 virtual const GrGLSLCaps* glslCaps() const = 0; | 86 virtual const GrGLSLCaps* glslCaps() const = 0; |
83 | 87 |
84 virtual GrGLGpu* gpu() const = 0; | 88 virtual GrGLGpu* gpu() const = 0; |
85 | 89 |
86 /* | 90 /* |
87 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE | 91 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE |
88 */ | 92 */ |
| 93 private: |
| 94 virtual UniformHandle internalAddUniformArray( |
| 95 uint32_t visibility, |
| 96 GrSLType type, |
| 97 GrSLPrecision precision, |
| 98 const char* name, |
| 99 bool mangleName, |
| 100 int arrayCount, |
| 101 const char** outName) = 0; |
89 }; | 102 }; |
90 | 103 |
91 // TODO move this into GrGLGPBuilder and move them both out of this file | 104 // TODO move this into GrGLGPBuilder and move them both out of this file |
92 class GrGLVarying { | 105 class GrGLVarying { |
93 public: | 106 public: |
94 bool vsVarying() const { return kVertToFrag_Varying == fVarying || | 107 bool vsVarying() const { return kVertToFrag_Varying == fVarying || |
95 kVertToGeo_Varying == fVarying; } | 108 kVertToGeo_Varying == fVarying; } |
96 bool fsVarying() const { return kVertToFrag_Varying == fVarying || | 109 bool fsVarying() const { return kVertToFrag_Varying == fVarying || |
97 kGeoToFrag_Varying == fVarying; } | 110 kGeoToFrag_Varying == fVarying; } |
98 const char* vsOut() const { return fVsOut; } | 111 const char* vsOut() const { return fVsOut; } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 typedef GrGpu::DrawArgs DrawArgs; | 245 typedef GrGpu::DrawArgs DrawArgs; |
233 /** Generates a shader program. | 246 /** Generates a shader program. |
234 * | 247 * |
235 * The program implements what is specified in the stages given as input. | 248 * The program implements what is specified in the stages given as input. |
236 * After successful generation, the builder result objects are available | 249 * After successful generation, the builder result objects are available |
237 * to be used. | 250 * to be used. |
238 * @return true if generation was successful. | 251 * @return true if generation was successful. |
239 */ | 252 */ |
240 static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*); | 253 static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*); |
241 | 254 |
242 UniformHandle addUniformArray(uint32_t visibility, | |
243 GrSLType type, | |
244 GrSLPrecision precision, | |
245 const char* name, | |
246 int arrayCount, | |
247 const char** outName) override; | |
248 | |
249 const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override { | 255 const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override { |
250 return fUniforms[u.toIndex()].fVariable; | 256 return fUniforms[u.toIndex()].fVariable; |
251 } | 257 } |
252 | 258 |
253 const char* getUniformCStr(UniformHandle u) const override { | 259 const char* getUniformCStr(UniformHandle u) const override { |
254 return this->getUniformVariable(u).c_str(); | 260 return this->getUniformVariable(u).c_str(); |
255 } | 261 } |
256 | 262 |
257 const GrGLContextInfo& ctxInfo() const override; | 263 const GrGLContextInfo& ctxInfo() const override; |
258 | 264 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 typedef GrGLProgramDataManager::SeparableVaryingInfo SeparableVaryingInfo; | 297 typedef GrGLProgramDataManager::SeparableVaryingInfo SeparableVaryingInfo; |
292 typedef GrGLProgramDataManager::SeparableVaryingInfoArray SeparableVaryingIn
foArray; | 298 typedef GrGLProgramDataManager::SeparableVaryingInfoArray SeparableVaryingIn
foArray; |
293 | 299 |
294 GrGLProgramBuilder(GrGLGpu*, const DrawArgs&); | 300 GrGLProgramBuilder(GrGLGpu*, const DrawArgs&); |
295 | 301 |
296 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim
itiveProcessor; } | 302 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim
itiveProcessor; } |
297 const GrPipeline& pipeline() const { return *fArgs.fPipeline; } | 303 const GrPipeline& pipeline() const { return *fArgs.fPipeline; } |
298 const GrProgramDesc& desc() const { return *fArgs.fDesc; } | 304 const GrProgramDesc& desc() const { return *fArgs.fDesc; } |
299 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(
); } | 305 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(
); } |
300 | 306 |
| 307 UniformHandle internalAddUniformArray(uint32_t visibility, |
| 308 GrSLType type, |
| 309 GrSLPrecision precision, |
| 310 const char* name, |
| 311 bool mangleName, |
| 312 int arrayCount, |
| 313 const char** outName) override; |
| 314 |
| 315 // Used to add a uniform for frag position without mangling the name of the
uniform inside of a |
| 316 // stage. |
| 317 UniformHandle addFragPosUniform(uint32_t visibility, |
| 318 GrSLType type, |
| 319 GrSLPrecision precision, |
| 320 const char* name, |
| 321 const char** outName) { |
| 322 SkDebugf("in my frag pos thing\n"); |
| 323 return this->internalAddUniformArray(visibility, type, precision, name,
false, 0, outName); |
| 324 } |
| 325 |
301 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix | 326 // Generates a name for a variable. The generated string will be name prefix
ed by the prefix |
302 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp
ecific if we're | 327 // char (unless the prefix is '\0'). It also will mangle the name to be stag
e-specific unless |
303 // generating stage code. | 328 // explicitly asked not to. |
304 void nameVariable(SkString* out, char prefix, const char* name); | 329 void nameVariable(SkString* out, char prefix, const char* name, bool mangle
= true); |
305 // Generates a possibly mangled name for a stage variable and writes it to t
he fragment shader. | 330 // Generates a possibly mangled name for a stage variable and writes it to t
he fragment shader. |
306 // If GrGLSLExpr4 has a valid name then it will use that instead | 331 // If GrGLSLExpr4 has a valid name then it will use that instead |
307 void nameExpression(GrGLSLExpr4*, const char* baseName); | 332 void nameExpression(GrGLSLExpr4*, const char* baseName); |
308 bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage
); | 333 bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage
); |
309 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu
t); | 334 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu
t); |
310 void emitAndInstallProc(const GrFragmentProcessor&, | 335 void emitAndInstallProc(const GrFragmentProcessor&, |
311 int index, | 336 int index, |
312 const GrGLSLExpr4& input, | 337 const GrGLSLExpr4& input, |
313 GrGLSLExpr4* output); | 338 GrGLSLExpr4* output); |
314 | 339 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 374 |
350 // Subclasses create different programs | 375 // Subclasses create different programs |
351 virtual GrGLProgram* createProgram(GrGLuint programID); | 376 virtual GrGLProgram* createProgram(GrGLuint programID); |
352 | 377 |
353 void appendUniformDecls(ShaderVisibility, SkString*) const; | 378 void appendUniformDecls(ShaderVisibility, SkString*) const; |
354 | 379 |
355 // reset is called by program creator between each processor's emit code. I
t increments the | 380 // reset is called by program creator between each processor's emit code. I
t increments the |
356 // stage offset for variable name mangling, and also ensures verfication var
iables in the | 381 // stage offset for variable name mangling, and also ensures verfication var
iables in the |
357 // fragment shader are cleared. | 382 // fragment shader are cleared. |
358 void reset() { | 383 void reset() { |
359 this->enterStage(); | |
360 this->addStage(); | 384 this->addStage(); |
361 fFS.reset(); | 385 fFS.reset(); |
362 } | 386 } |
363 void addStage() { fStageIndex++; } | 387 void addStage() { fStageIndex++; } |
364 | 388 |
365 // This simple class exits the stage and then restores the stage when it goe
s out of scope | |
366 class AutoStageRestore { | |
367 public: | |
368 AutoStageRestore(GrGLProgramBuilder* pb) | |
369 : fPB(pb), fOutOfStage(pb->fOutOfStage) { pb->exitStage(); } | |
370 ~AutoStageRestore() { fPB->fOutOfStage = fOutOfStage; } | |
371 private: | |
372 GrGLProgramBuilder* fPB; | |
373 bool fOutOfStage; | |
374 }; | |
375 class AutoStageAdvance { | 389 class AutoStageAdvance { |
376 public: | 390 public: |
377 AutoStageAdvance(GrGLProgramBuilder* pb) | 391 AutoStageAdvance(GrGLProgramBuilder* pb) |
378 : fPB(pb) { | 392 : fPB(pb) { |
379 fPB->reset(); | 393 fPB->reset(); |
380 // Each output to the fragment processor gets its own code section | 394 // Each output to the fragment processor gets its own code section |
381 fPB->fFS.nextStage(); | 395 fPB->fFS.nextStage(); |
382 } | 396 } |
383 ~AutoStageAdvance() { fPB->exitStage(); } | 397 ~AutoStageAdvance() {} |
384 private: | 398 private: |
385 GrGLProgramBuilder* fPB; | 399 GrGLProgramBuilder* fPB; |
386 }; | 400 }; |
387 void exitStage() { fOutOfStage = true; } | |
388 void enterStage() { fOutOfStage = false; } | |
389 int stageIndex() const { return fStageIndex; } | 401 int stageIndex() const { return fStageIndex; } |
390 | 402 |
391 const char* rtAdjustment() const { return "rtAdjustment"; } | 403 const char* rtAdjustment() const { return "rtAdjustment"; } |
392 | 404 |
393 // number of each input/output type in a single allocation block, used by ma
ny builders | 405 // number of each input/output type in a single allocation block, used by ma
ny builders |
394 static const int kVarsPerBlock; | 406 static const int kVarsPerBlock; |
395 | 407 |
396 BuiltinUniformHandles fUniformHandles; | 408 BuiltinUniformHandles fUniformHandles; |
397 GrGLVertexBuilder fVS; | 409 GrGLVertexBuilder fVS; |
398 GrGLGeometryBuilder fGS; | 410 GrGLGeometryBuilder fGS; |
399 GrGLFragmentShaderBuilder fFS; | 411 GrGLFragmentShaderBuilder fFS; |
400 bool fOutOfStage; | |
401 int fStageIndex; | 412 int fStageIndex; |
402 | 413 |
403 GrGLInstalledGeoProc* fGeometryProcessor; | 414 GrGLInstalledGeoProc* fGeometryProcessor; |
404 GrGLInstalledXferProc* fXferProcessor; | 415 GrGLInstalledXferProc* fXferProcessor; |
405 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; | 416 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; |
406 | 417 |
407 const DrawArgs& fArgs; | 418 const DrawArgs& fArgs; |
408 GrGLGpu* fGpu; | 419 GrGLGpu* fGpu; |
409 UniformInfoArray fUniforms; | 420 UniformInfoArray fUniforms; |
410 GrGLPrimitiveProcessor::TransformsIn fCoordTransforms; | 421 GrGLPrimitiveProcessor::TransformsIn fCoordTransforms; |
411 GrGLPrimitiveProcessor::TransformsOut fOutCoords; | 422 GrGLPrimitiveProcessor::TransformsOut fOutCoords; |
412 SkTArray<UniformHandle> fSamplerUniforms; | 423 SkTArray<UniformHandle> fSamplerUniforms; |
413 SeparableVaryingInfoArray fSeparableVaryingInfos; | 424 SeparableVaryingInfoArray fSeparableVaryingInfos; |
414 | 425 |
415 friend class GrGLShaderBuilder; | 426 friend class GrGLShaderBuilder; |
416 friend class GrGLVertexBuilder; | 427 friend class GrGLVertexBuilder; |
417 friend class GrGLFragmentShaderBuilder; | 428 friend class GrGLFragmentShaderBuilder; |
418 friend class GrGLGeometryBuilder; | 429 friend class GrGLGeometryBuilder; |
419 }; | 430 }; |
420 #endif | 431 #endif |
OLD | NEW |