OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 GrGLProgramEffects_DEFINED | 8 #ifndef GrGLProgramEffects_DEFINED |
9 #define GrGLProgramEffects_DEFINED | 9 #define GrGLProgramEffects_DEFINED |
10 | 10 |
11 #include "GrBackendEffectFactory.h" | 11 #include "GrBackendProcessorFactory.h" |
12 #include "GrGLProgramDataManager.h" | 12 #include "GrGLProgramDataManager.h" |
13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
14 #include "GrTexture.h" | 14 #include "GrTexture.h" |
15 #include "GrTextureAccess.h" | 15 #include "GrTextureAccess.h" |
16 | 16 |
17 class GrEffect; | 17 class GrProcessor; |
18 class GrEffectStage; | 18 class GrProcessorStage; |
19 class GrGLVertexProgramEffectsBuilder; | 19 class GrGLVertexProgramEffectsBuilder; |
20 class GrGLProgramBuilder; | 20 class GrGLProgramBuilder; |
21 class GrGLFullProgramBuilder; | 21 class GrGLFullProgramBuilder; |
22 class GrGLFragmentOnlyProgramBuilder; | 22 class GrGLFragmentOnlyProgramBuilder; |
23 | 23 |
24 /** | 24 /** |
25 * This class encapsulates an array of GrGLEffects and their supporting data (co
ord transforms | 25 * This class encapsulates an array of GrGLProcessors and their supporting data
(coord transforms |
26 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag
e the necessary GL | 26 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag
e the necessary GL |
27 * state and shader uniforms. | 27 * state and shader uniforms. |
28 */ | 28 */ |
29 class GrGLProgramEffects : public SkRefCnt { | 29 class GrGLProgramEffects : public SkRefCnt { |
30 public: | 30 public: |
31 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 31 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
32 typedef GrGLProgramDataManager::VaryingHandle VaryingHandle; | 32 typedef GrGLProgramDataManager::VaryingHandle VaryingHandle; |
33 | |
34 virtual ~GrGLProgramEffects(); | 33 virtual ~GrGLProgramEffects(); |
35 | 34 |
36 /** | 35 /** |
37 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ
es the next | 36 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ
es the next |
38 * available unit to *texUnitIdx when it returns. | 37 * available unit to *texUnitIdx when it returns. |
39 */ | 38 */ |
40 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); | 39 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); |
41 | 40 |
42 /** | 41 /** |
43 * Calls setData() on each effect, and sets their transformation matrices an
d texture bindings. | 42 * Calls setData() on each effect, and sets their transformation matrices an
d texture bindings. |
44 */ | 43 */ |
45 virtual void setData(GrGpuGL*, | 44 virtual void setData(GrGpuGL*, |
46 GrGpu::DrawType, | 45 GrGpu::DrawType, |
47 const GrGLProgramDataManager&, | 46 const GrGLProgramDataManager&, |
48 const GrEffectStage* effectStages[]) = 0; | 47 const GrGeometryStage* effectStages) { |
| 48 SkFAIL("For geometry processor only"); |
| 49 } |
| 50 |
| 51 virtual void setData(GrGpuGL*, |
| 52 GrGpu::DrawType, |
| 53 const GrGLProgramDataManager&, |
| 54 const GrFragmentStage* effectStages[]) = 0; |
49 | 55 |
50 protected: | 56 protected: |
51 GrGLProgramEffects(int reserveCount) | 57 GrGLProgramEffects(int reserveCount) |
52 : fGLEffects(reserveCount) | 58 : fGLProcessors(reserveCount) |
53 , fSamplers(reserveCount) { | 59 , fSamplers(reserveCount) { |
54 } | 60 } |
55 | 61 |
56 /** | 62 /** |
57 * Helper for setData(). Binds all the textures for an effect. | 63 * Helper for setData(). Binds all the textures for an effect. |
58 */ | 64 */ |
59 void bindTextures(GrGpuGL*, const GrEffect&, int effectIdx); | 65 void bindTextures(GrGpuGL*, const GrProcessor&, int effectIdx); |
60 | 66 |
61 struct Sampler { | 67 struct Sampler { |
62 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {}) | 68 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {}) |
63 UniformHandle fUniform; | 69 UniformHandle fUniform; |
64 int fTextureUnit; | 70 int fTextureUnit; |
65 }; | 71 }; |
66 | 72 |
67 /* | 73 /* |
68 * Helpers for shader builders to build up program effects objects alongside
shader code | 74 * Helpers for shader builders to build up program effects objects alongside
shader code |
69 */ | 75 */ |
70 void addEffect(GrGLEffect* effect) { fGLEffects.push_back(effect); } | 76 void addEffect(GrGLProcessor* effect) { fGLProcessors.push_back(effect); } |
71 SkTArray<Sampler, true>& addSamplers() { return fSamplers.push_back(); } | 77 SkTArray<Sampler, true>& addSamplers() { return fSamplers.push_back(); } |
72 | 78 |
73 SkTArray<GrGLEffect*> fGLEffects; | 79 SkTArray<GrGLProcessor*> fGLProcessors; |
74 SkTArray<SkSTArray<4, Sampler, true> > fSamplers; | 80 SkTArray<SkSTArray<4, Sampler, true> > fSamplers; |
75 | 81 |
76 private: | 82 private: |
77 friend class GrGLProgramBuilder; | 83 friend class GrGLProgramBuilder; |
78 friend class GrGLFullProgramBuilder; | 84 friend class GrGLFullProgramBuilder; |
79 friend class GrGLFragmentOnlyShaderBuilder; | 85 friend class GrGLFragmentOnlyShaderBuilder; |
80 | 86 |
81 typedef SkRefCnt INHERITED; | 87 typedef SkRefCnt INHERITED; |
82 }; | 88 }; |
83 | 89 |
84 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
85 | 91 |
86 /** | 92 /** |
87 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. | 93 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. |
88 */ | 94 */ |
89 class GrGLVertexProgramEffects : public GrGLProgramEffects { | 95 class GrGLVertexProgramEffects : public GrGLProgramEffects { |
90 public: | 96 public: |
91 virtual void setData(GrGpuGL*, | 97 virtual void setData(GrGpuGL*, |
92 GrGpu::DrawType, | 98 GrGpu::DrawType, |
93 const GrGLProgramDataManager&, | 99 const GrGLProgramDataManager&, |
94 const GrEffectStage* effectStages[]) SK_OVERRIDE; | 100 const GrGeometryStage* effectStages) SK_OVERRIDE; |
| 101 |
| 102 virtual void setData(GrGpuGL*, |
| 103 GrGpu::DrawType, |
| 104 const GrGLProgramDataManager&, |
| 105 const GrFragmentStage* effectStages[]) SK_OVERRIDE; |
95 | 106 |
96 private: | 107 private: |
97 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) | 108 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) |
98 : INHERITED(reserveCount) | 109 : INHERITED(reserveCount) |
99 , fTransforms(reserveCount) | 110 , fTransforms(reserveCount) |
100 , fHasExplicitLocalCoords(explicitLocalCoords) { | 111 , fHasExplicitLocalCoords(explicitLocalCoords) { |
101 } | 112 } |
102 | 113 |
103 struct Transform { | 114 struct Transform { |
104 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } | 115 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
(...skipping 11 matching lines...) Expand all Loading... |
116 /* | 127 /* |
117 * These functions are used by the builders to build up program effects alon
g side the shader | 128 * These functions are used by the builders to build up program effects alon
g side the shader |
118 * code itself | 129 * code itself |
119 */ | 130 */ |
120 SkSTArray<2, Transform, true>& addTransforms() { return fTransforms.push_bac
k(); } | 131 SkSTArray<2, Transform, true>& addTransforms() { return fTransforms.push_bac
k(); } |
121 SkTArray<PathTransform, true>& addPathTransforms() { return fPathTransforms.
push_back(); } | 132 SkTArray<PathTransform, true>& addPathTransforms() { return fPathTransforms.
push_back(); } |
122 | 133 |
123 /** | 134 /** |
124 * Helper for setData(). Sets all the transform matrices for an effect. | 135 * Helper for setData(). Sets all the transform matrices for an effect. |
125 */ | 136 */ |
126 void setTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const GrE
ffectStage&, | 137 void setDataInternal(GrGpuGL* gpu, |
| 138 GrGpu::DrawType drawType, |
| 139 const GrGLProgramDataManager& programDataManager, |
| 140 const GrProcessorStage& effectStage, |
| 141 int index); |
| 142 void setTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const GrP
rocessorStage&, |
127 int effectIdx); | 143 int effectIdx); |
128 void setPathTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const
GrEffectStage&, | 144 void setPathTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, |
129 int effectIdx); | 145 const GrProcessorStage&, int effectIdx); |
| 146 |
130 | 147 |
131 SkTArray<SkSTArray<2, Transform, true> > fTransforms; | 148 SkTArray<SkSTArray<2, Transform, true> > fTransforms; |
132 SkTArray<SkTArray<PathTransform, true> > fPathTransforms; | 149 SkTArray<SkTArray<PathTransform, true> > fPathTransforms; |
133 bool fHasExplicitLocalCoords; | 150 bool fHasExplicitLocalCoords; |
134 | 151 |
135 friend class GrGLFullProgramBuilder; | 152 friend class GrGLFullProgramBuilder; |
136 | 153 |
137 typedef GrGLProgramEffects INHERITED; | 154 typedef GrGLProgramEffects INHERITED; |
138 }; | 155 }; |
139 | 156 |
140 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
141 | 158 |
142 /** | 159 /** |
143 * This is a GrGLProgramEffects implementation that does coord transforms with | 160 * This is a GrGLProgramEffects implementation that does coord transforms with |
144 * the the NV_path_rendering PathTexGen functionality. | 161 * the the NV_path_rendering PathTexGen functionality. |
145 */ | 162 */ |
146 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { | 163 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { |
147 public: | 164 public: |
148 virtual void setData(GrGpuGL*, | 165 virtual void setData(GrGpuGL*, |
149 GrGpu::DrawType, | 166 GrGpu::DrawType, |
150 const GrGLProgramDataManager&, | 167 const GrGLProgramDataManager&, |
151 const GrEffectStage* effectStages[]) SK_OVERRIDE; | 168 const GrFragmentStage* effectStages[]) SK_OVERRIDE; |
152 | 169 |
153 private: | 170 private: |
154 GrGLPathTexGenProgramEffects(int reserveCount) | 171 GrGLPathTexGenProgramEffects(int reserveCount) |
155 : INHERITED(reserveCount) | 172 : INHERITED(reserveCount) |
156 , fTransforms(reserveCount) { | 173 , fTransforms(reserveCount) { |
157 } | 174 } |
158 | 175 |
159 /** | 176 /** |
160 * Helper for setData(). Sets the PathTexGen state for each transform in an
effect. | 177 * Helper for setData(). Sets the PathTexGen state for each transform in an
effect. |
161 */ | 178 */ |
162 void setPathTexGenState(GrGpuGL*, const GrEffectStage&, int effectIdx); | 179 void setPathTexGenState(GrGpuGL*, const GrProcessorStage&, int effectIdx); |
163 | 180 |
164 struct Transforms { | 181 struct Transforms { |
165 Transforms(int texCoordIndex) | 182 Transforms(int texCoordIndex) |
166 : fTexCoordIndex(texCoordIndex) {} | 183 : fTexCoordIndex(texCoordIndex) {} |
167 int fTexCoordIndex; | 184 int fTexCoordIndex; |
168 }; | 185 }; |
169 | 186 |
170 /* | 187 /* |
171 * Helper for fragment only shader builder to build up the program effects a
longside the shader | 188 * Helper for fragment only shader builder to build up the program effects a
longside the shader |
172 */ | 189 */ |
173 void addTransforms(int coordIndex) { | 190 void addTransforms(int coordIndex) { |
174 fTransforms.push_back(Transforms(coordIndex)); | 191 fTransforms.push_back(Transforms(coordIndex)); |
175 } | 192 } |
176 | 193 |
177 SkTArray<Transforms> fTransforms; | 194 SkTArray<Transforms> fTransforms; |
178 | 195 |
179 friend class GrGLFragmentOnlyProgramBuilder; | 196 friend class GrGLFragmentOnlyProgramBuilder; |
180 | 197 |
181 typedef GrGLProgramEffects INHERITED; | 198 typedef GrGLProgramEffects INHERITED; |
182 }; | 199 }; |
183 | 200 |
184 #endif | 201 #endif |
OLD | NEW |