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 GrGLSLProgramBuilder_DEFINED | 8 #ifndef GrGLSLProgramBuilder_DEFINED |
9 #define GrGLSLProgramBuilder_DEFINED | 9 #define GrGLSLProgramBuilder_DEFINED |
10 | 10 |
11 #include "GrGeometryProcessor.h" | 11 #include "GrGeometryProcessor.h" |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
14 #include "glsl/GrGLSLGeometryShaderBuilder.h" | 14 #include "glsl/GrGLSLGeometryShaderBuilder.h" |
| 15 #include "glsl/GrGLSLPrimitiveProcessor.h" |
15 #include "glsl/GrGLSLProgramDataManager.h" | 16 #include "glsl/GrGLSLProgramDataManager.h" |
16 #include "glsl/GrGLSLUniformHandler.h" | 17 #include "glsl/GrGLSLUniformHandler.h" |
| 18 #include "glsl/GrGLSLTextureSampler.h" |
17 #include "glsl/GrGLSLVertexShaderBuilder.h" | 19 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 20 #include "glsl/GrGLSLXferProcessor.h" |
18 | 21 |
19 class GrGLSLCaps; | 22 class GrGLSLCaps; |
20 class GrGLSLShaderVar; | 23 class GrGLSLShaderVar; |
21 class GrGLSLVaryingHandler; | 24 class GrGLSLVaryingHandler; |
22 | 25 |
| 26 typedef SkSTArray<8, GrGLSLFragmentProcessor*, true> GrGLSLFragProcs; |
| 27 |
23 class GrGLSLProgramBuilder { | 28 class GrGLSLProgramBuilder { |
24 public: | 29 public: |
25 typedef GrGpu::DrawArgs DrawArgs; | 30 typedef GrGpu::DrawArgs DrawArgs; |
26 typedef GrGLSLUniformHandler::ShaderVisibility ShaderVisibility; | 31 typedef GrGLSLUniformHandler::ShaderVisibility ShaderVisibility; |
27 typedef GrGLSLUniformHandler::UniformHandle UniformHandle; | 32 typedef GrGLSLUniformHandler::UniformHandle UniformHandle; |
28 | 33 |
29 virtual ~GrGLSLProgramBuilder() {} | 34 virtual ~GrGLSLProgramBuilder() {} |
30 | 35 |
| 36 virtual const GrCaps* caps() const = 0; |
31 virtual const GrGLSLCaps* glslCaps() const = 0; | 37 virtual const GrGLSLCaps* glslCaps() const = 0; |
32 | 38 |
33 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim
itiveProcessor; } | 39 const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrim
itiveProcessor; } |
34 const GrPipeline& pipeline() const { return *fArgs.fPipeline; } | 40 const GrPipeline& pipeline() const { return *fArgs.fPipeline; } |
35 const GrProgramDesc& desc() const { return *fArgs.fDesc; } | 41 const GrProgramDesc& desc() const { return *fArgs.fDesc; } |
36 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(
); } | 42 const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(
); } |
37 | 43 |
38 void appendUniformDecls(ShaderVisibility, SkString*) const; | 44 void appendUniformDecls(ShaderVisibility, SkString*) const; |
39 | 45 |
40 // Handles for program uniforms (other than per-effect uniforms) | 46 // Handles for program uniforms (other than per-effect uniforms) |
(...skipping 28 matching lines...) Expand all Loading... |
69 GrGLSLVertexBuilder fVS; | 75 GrGLSLVertexBuilder fVS; |
70 GrGLSLGeometryBuilder fGS; | 76 GrGLSLGeometryBuilder fGS; |
71 GrGLSLFragmentShaderBuilder fFS; | 77 GrGLSLFragmentShaderBuilder fFS; |
72 | 78 |
73 int fStageIndex; | 79 int fStageIndex; |
74 | 80 |
75 const DrawArgs& fArgs; | 81 const DrawArgs& fArgs; |
76 | 82 |
77 BuiltinUniformHandles fUniformHandles; | 83 BuiltinUniformHandles fUniformHandles; |
78 | 84 |
| 85 GrGLSLPrimitiveProcessor* fGeometryProcessor; |
| 86 GrGLSLXferProcessor* fXferProcessor; |
| 87 GrGLSLFragProcs fFragmentProcessors; |
| 88 |
79 protected: | 89 protected: |
80 explicit GrGLSLProgramBuilder(const DrawArgs& args); | 90 explicit GrGLSLProgramBuilder(const DrawArgs& args); |
| 91 |
| 92 bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage
, int maxTextures); |
| 93 |
| 94 void cleanupFragmentProcessors(); |
| 95 |
| 96 private: |
| 97 // reset is called by program creator between each processor's emit code. I
t increments the |
| 98 // stage offset for variable name mangling, and also ensures verfication var
iables in the |
| 99 // fragment shader are cleared. |
| 100 void reset() { |
| 101 this->addStage(); |
| 102 fFS.reset(); |
| 103 } |
| 104 void addStage() { fStageIndex++; } |
| 105 |
| 106 class AutoStageAdvance { |
| 107 public: |
| 108 AutoStageAdvance(GrGLSLProgramBuilder* pb) |
| 109 : fPB(pb) { |
| 110 fPB->reset(); |
| 111 // Each output to the fragment processor gets its own code section |
| 112 fPB->fFS.nextStage(); |
| 113 } |
| 114 ~AutoStageAdvance() {} |
| 115 private: |
| 116 GrGLSLProgramBuilder* fPB; |
| 117 }; |
| 118 |
| 119 // Generates a possibly mangled name for a stage variable and writes it to t
he fragment shader. |
| 120 // If GrGLSLExpr4 has a valid name then it will use that instead |
| 121 void nameExpression(GrGLSLExpr4*, const char* baseName); |
| 122 |
| 123 void emitAndInstallPrimProc(const GrPrimitiveProcessor&, |
| 124 GrGLSLExpr4* outputColor, |
| 125 GrGLSLExpr4* outputCoverage); |
| 126 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOu
t); |
| 127 void emitAndInstallFragProc(const GrFragmentProcessor&, |
| 128 int index, |
| 129 const GrGLSLExpr4& input, |
| 130 GrGLSLExpr4* output); |
| 131 void emitAndInstallXferProc(const GrXferProcessor&, |
| 132 const GrGLSLExpr4& colorIn, |
| 133 const GrGLSLExpr4& coverageIn, |
| 134 bool ignoresCoverage); |
| 135 void emitFSOutputSwizzle(bool hasSecondaryOutput); |
| 136 |
| 137 void verify(const GrPrimitiveProcessor&); |
| 138 void verify(const GrXferProcessor&); |
| 139 void verify(const GrFragmentProcessor&); |
| 140 |
| 141 virtual void emitSamplers(const GrProcessor& processor, |
| 142 GrGLSLTextureSampler::TextureSamplerArray* outSamp
lers) = 0; |
| 143 |
| 144 GrGLSLPrimitiveProcessor::TransformsIn fCoordTransforms; |
| 145 GrGLSLPrimitiveProcessor::TransformsOut fOutCoords; |
81 }; | 146 }; |
82 | 147 |
83 #endif | 148 #endif |
OLD | NEW |