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