OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
9 #ifndef GrGLProgram_DEFINED | 9 #ifndef GrGLProgram_DEFINED |
10 #define GrGLProgram_DEFINED | 10 #define GrGLProgram_DEFINED |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 }; | 145 }; |
146 | 146 |
147 /** | 147 /** |
148 * This function uploads uniforms and calls each GrGLProcessor's setData. It
is called before a | 148 * This function uploads uniforms and calls each GrGLProcessor's setData. It
is called before a |
149 * draw occurs using the program after the program has already been bound. I
t also uses the | 149 * draw occurs using the program after the program has already been bound. I
t also uses the |
150 * GrGpuGL object to bind the textures required by the GrGLProcessors. The c
olor and coverage | 150 * GrGpuGL object to bind the textures required by the GrGLProcessors. The c
olor and coverage |
151 * stages come from GrGLProgramDesc::Build(). | 151 * stages come from GrGLProgramDesc::Build(). |
152 */ | 152 */ |
153 void setData(const GrOptDrawState&, | 153 void setData(const GrOptDrawState&, |
154 GrGpu::DrawType, | 154 GrGpu::DrawType, |
| 155 const GrGeometryStage* geometryProcessor, |
| 156 const GrFragmentStage* colorStages[], |
| 157 const GrFragmentStage* coverageStages[], |
155 const GrDeviceCoordTexture* dstCopy, // can be NULL | 158 const GrDeviceCoordTexture* dstCopy, // can be NULL |
156 SharedGLState*); | 159 SharedGLState*); |
157 | 160 |
158 protected: | 161 protected: |
159 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 162 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
160 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; | 163 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; |
161 | 164 |
162 GrGLProgram(GrGpuGL*, | 165 GrGLProgram(GrGpuGL*, |
163 const GrGLProgramDesc&, | 166 const GrGLProgramDesc&, |
164 const BuiltinUniformHandles&, | 167 const BuiltinUniformHandles&, |
165 GrGLuint programID, | 168 GrGLuint programID, |
166 const UniformInfoArray&, | 169 const UniformInfoArray&, |
167 GrGLInstalledGeoProc* geometryProcessor, | 170 GrGLInstalledProcessors* geometryProcessor, |
168 GrGLInstalledFragProcs* fragmentProcessors); | 171 GrGLInstalledProcessors* colorProcessors, |
| 172 GrGLInstalledProcessors* coverageProcessors); |
169 | 173 |
170 // Sets the texture units for samplers. | 174 // Sets the texture units for samplers. |
171 void initSamplerUniforms(); | 175 void initSamplerUniforms(); |
172 void initSamplers(GrGLInstalledProc*, int* texUnitIdx); | 176 void initSamplers(GrGLInstalledProcessors* processors, int* texUnitIdx); |
173 | 177 |
174 // Helper for setData(). Makes GL calls to specify the initial color when th
ere is not | 178 // Helper for setData(). Makes GL calls to specify the initial color when th
ere is not |
175 // per-vertex colors. | 179 // per-vertex colors. |
176 void setColor(const GrOptDrawState&, GrColor color, SharedGLState*); | 180 void setColor(const GrOptDrawState&, GrColor color, SharedGLState*); |
177 | 181 |
178 // Helper for setData(). Makes GL calls to specify the initial coverage when
there is not | 182 // Helper for setData(). Makes GL calls to specify the initial coverage when
there is not |
179 // per-vertex coverages. | 183 // per-vertex coverages. |
180 void setCoverage(const GrOptDrawState&, GrColor coverage, SharedGLState*); | 184 void setCoverage(const GrOptDrawState&, GrColor coverage, SharedGLState*); |
181 | 185 |
182 // A templated helper to loop over effects, set the transforms(via subclass)
and bind textures | 186 // A templated helper to loop over effects, set the transforms(via subclass)
and bind textures |
183 void setFragmentData(const GrOptDrawState&); | 187 template <class ProcessorStage> |
184 virtual void setTransformData(const GrFragmentStage& effectStage, GrGLInstal
ledFragProc* pe); | 188 void setData(const ProcessorStage* effectStages[], |
185 void bindTextures(const GrGLInstalledProc*, const GrProcessor&); | 189 GrGLInstalledProcessors* installedProcessors) { |
| 190 int numEffects = installedProcessors->fGLProcessors.count(); |
| 191 SkASSERT(numEffects == installedProcessors->fTransforms.count()); |
| 192 SkASSERT(numEffects == installedProcessors->fSamplers.count()); |
| 193 for (int e = 0; e < numEffects; ++e) { |
| 194 const GrProcessor& effect = *effectStages[e]->getProcessor(); |
| 195 installedProcessors->fGLProcessors[e]->setData(fProgramDataManager,
effect); |
| 196 this->setTransformData(*effectStages[e], e, installedProcessors); |
| 197 this->bindTextures(installedProcessors, effect, e); |
| 198 } |
| 199 } |
| 200 virtual void setTransformData(const GrProcessorStage& effectStage, |
| 201 int effectIdx, |
| 202 GrGLInstalledProcessors* pe); |
| 203 void bindTextures(const GrGLInstalledProcessors*, const GrProcessor&, int ef
fectIdx); |
186 | 204 |
187 /* | 205 /* |
188 * Legacy NVPR needs a hook here to flush path tex gen settings. | 206 * Legacy NVPR needs a hook here to flush path tex gen settings. |
189 * TODO when legacy nvpr is removed, remove this call. | 207 * TODO when legacy nvpr is removed, remove this call. |
190 */ | 208 */ |
191 virtual void didSetData(GrGpu::DrawType); | 209 virtual void didSetData(GrGpu::DrawType); |
192 | 210 |
193 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform | 211 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform |
194 void setMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&); | 212 void setMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&); |
195 virtual void onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDr
awState&); | 213 virtual void onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDr
awState&); |
196 | 214 |
197 // these reflect the current values of uniforms (GL uniform values travel wi
th program) | 215 // these reflect the current values of uniforms (GL uniform values travel wi
th program) |
198 MatrixState fMatrixState; | 216 MatrixState fMatrixState; |
199 GrColor fColor; | 217 GrColor fColor; |
200 GrColor fCoverage; | 218 GrColor fCoverage; |
201 int fDstCopyTexUnit; | 219 int fDstCopyTexUnit; |
202 BuiltinUniformHandles fBuiltinUniformHandles; | 220 BuiltinUniformHandles fBuiltinUniformHandles; |
203 GrGLuint fProgramID; | 221 GrGLuint fProgramID; |
204 | 222 |
205 // the installed effects | 223 // the installed effects |
206 SkAutoTDelete<GrGLInstalledGeoProc> fGeometryProcessor; | 224 SkAutoTUnref<GrGLInstalledProcessors> fGeometryProcessor; |
207 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; | 225 SkAutoTUnref<GrGLInstalledProcessors> fColorEffects; |
| 226 SkAutoTUnref<GrGLInstalledProcessors> fCoverageEffects; |
208 | 227 |
209 GrGLProgramDesc fDesc; | 228 GrGLProgramDesc fDesc; |
210 GrGpuGL* fGpu; | 229 GrGpuGL* fGpu; |
211 GrGLProgramDataManager fProgramDataManager; | 230 GrGLProgramDataManager fProgramDataManager; |
212 | 231 |
213 friend class GrGLProgramBuilder; | 232 friend class GrGLProgramBuilder; |
214 | 233 |
215 typedef SkRefCnt INHERITED; | 234 typedef SkRefCnt INHERITED; |
216 }; | 235 }; |
217 | 236 |
218 /* | 237 /* |
219 * Below are slight specializations of the program object for the different type
s of programs | 238 * Below are slight specializations of the program object for the different type
s of programs |
220 * The default GrGL programs consist of at the very least a vertex and fragment
shader. | 239 * The default GrGL programs consist of at the very least a vertex and fragment
shader. |
221 * Legacy Nvpr only has a fragment shader, 1.3+ Nvpr ignores the vertex shader,
but both require | 240 * Legacy Nvpr only has a fragment shader, 1.3+ Nvpr ignores the vertex shader,
but both require |
222 * specialized methods for setting transform data. Both types of NVPR also requi
re setting the | 241 * specialized methods for setting transform data. Both types of NVPR also requi
re setting the |
223 * projection matrix through a special function call | 242 * projection matrix through a special function call |
224 */ | 243 */ |
225 class GrGLNvprProgramBase : public GrGLProgram { | 244 class GrGLNvprProgramBase : public GrGLProgram { |
226 protected: | 245 protected: |
227 GrGLNvprProgramBase(GrGpuGL*, | 246 GrGLNvprProgramBase(GrGpuGL*, |
228 const GrGLProgramDesc&, | 247 const GrGLProgramDesc&, |
229 const BuiltinUniformHandles&, | 248 const BuiltinUniformHandles&, |
230 GrGLuint programID, | 249 GrGLuint programID, |
231 const UniformInfoArray&, | 250 const UniformInfoArray&, |
232 GrGLInstalledFragProcs* fragmentProcessors); | 251 GrGLInstalledProcessors* colorProcessors, |
| 252 GrGLInstalledProcessors* coverageProcessors); |
233 virtual void onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDr
awState&); | 253 virtual void onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDr
awState&); |
234 | 254 |
235 typedef GrGLProgram INHERITED; | 255 typedef GrGLProgram INHERITED; |
236 }; | 256 }; |
237 | 257 |
238 class GrGLNvprProgram : public GrGLNvprProgramBase { | 258 class GrGLNvprProgram : public GrGLNvprProgramBase { |
239 public: | 259 public: |
240 virtual bool hasVertexShader() const SK_OVERRIDE { return true; } | 260 virtual bool hasVertexShader() const SK_OVERRIDE { return true; } |
241 | 261 |
242 private: | 262 private: |
243 typedef GrGLNvprProgramBuilder::SeparableVaryingInfo SeparableVaryingInfo; | 263 typedef GrGLNvprProgramBuilder::SeparableVaryingInfo SeparableVaryingInfo; |
244 typedef GrGLNvprProgramBuilder::SeparableVaryingInfoArray SeparableVaryingIn
foArray; | 264 typedef GrGLNvprProgramBuilder::SeparableVaryingInfoArray SeparableVaryingIn
foArray; |
245 GrGLNvprProgram(GrGpuGL*, | 265 GrGLNvprProgram(GrGpuGL*, |
246 const GrGLProgramDesc&, | 266 const GrGLProgramDesc&, |
247 const BuiltinUniformHandles&, | 267 const BuiltinUniformHandles&, |
248 GrGLuint programID, | 268 GrGLuint programID, |
249 const UniformInfoArray&, | 269 const UniformInfoArray&, |
250 GrGLInstalledFragProcs* fragmentProcessors, | 270 GrGLInstalledProcessors* colorProcessors, |
| 271 GrGLInstalledProcessors* coverageProcessors, |
251 const SeparableVaryingInfoArray& separableVaryings); | 272 const SeparableVaryingInfoArray& separableVaryings); |
252 virtual void didSetData(GrGpu::DrawType) SK_OVERRIDE; | 273 virtual void didSetData(GrGpu::DrawType) SK_OVERRIDE; |
253 virtual void setTransformData(const GrFragmentStage&, GrGLInstalledFragProc*
) SK_OVERRIDE; | 274 virtual void setTransformData(const GrProcessorStage&, |
| 275 int effectIdx, |
| 276 GrGLInstalledProcessors*) SK_OVERRIDE; |
254 | 277 |
255 struct Varying { | 278 struct Varying { |
256 GrGLint fLocation; | 279 GrGLint fLocation; |
257 SkDEBUGCODE( | 280 SkDEBUGCODE( |
258 GrSLType fType; | 281 GrSLType fType; |
259 ); | 282 ); |
260 }; | 283 }; |
261 SkTArray<Varying, true> fVaryings; | 284 SkTArray<Varying, true> fVaryings; |
262 | 285 |
263 friend class GrGLNvprProgramBuilder; | 286 friend class GrGLNvprProgramBuilder; |
264 | 287 |
265 typedef GrGLNvprProgramBase INHERITED; | 288 typedef GrGLNvprProgramBase INHERITED; |
266 }; | 289 }; |
267 | 290 |
268 class GrGLLegacyNvprProgram : public GrGLNvprProgramBase { | 291 class GrGLLegacyNvprProgram : public GrGLNvprProgramBase { |
269 public: | 292 public: |
270 virtual bool hasVertexShader() const SK_OVERRIDE { return false; } | 293 virtual bool hasVertexShader() const SK_OVERRIDE { return false; } |
271 | 294 |
272 private: | 295 private: |
273 GrGLLegacyNvprProgram(GrGpuGL* gpu, | 296 GrGLLegacyNvprProgram(GrGpuGL* gpu, |
274 const GrGLProgramDesc& desc, | 297 const GrGLProgramDesc& desc, |
275 const BuiltinUniformHandles&, | 298 const BuiltinUniformHandles&, |
276 GrGLuint programID, | 299 GrGLuint programID, |
277 const UniformInfoArray&, | 300 const UniformInfoArray&, |
278 GrGLInstalledFragProcs* fragmentProcessors, | 301 GrGLInstalledProcessors* colorProcessors, |
| 302 GrGLInstalledProcessors* coverageProcessors, |
279 int texCoordSetCnt); | 303 int texCoordSetCnt); |
280 virtual void didSetData(GrGpu::DrawType) SK_OVERRIDE; | 304 virtual void didSetData(GrGpu::DrawType) SK_OVERRIDE; |
281 virtual void setTransformData(const GrFragmentStage&, GrGLInstalledFragProc*
) SK_OVERRIDE; | 305 virtual void setTransformData(const GrProcessorStage&, |
| 306 int effectIdx, |
| 307 GrGLInstalledProcessors*) SK_OVERRIDE; |
282 | 308 |
283 int fTexCoordSetCnt; | 309 int fTexCoordSetCnt; |
284 | 310 |
285 friend class GrGLLegacyNvprProgramBuilder; | 311 friend class GrGLLegacyNvprProgramBuilder; |
286 | 312 |
287 typedef GrGLNvprProgramBase INHERITED; | 313 typedef GrGLNvprProgramBase INHERITED; |
288 }; | 314 }; |
289 | 315 |
290 #endif | 316 #endif |
OLD | NEW |