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 |
(...skipping 21 matching lines...) Expand all Loading... |
32 typedef GrGLProgramDataManager::VaryingHandle VaryingHandle; | 32 typedef GrGLProgramDataManager::VaryingHandle VaryingHandle; |
33 | 33 |
34 /** | 34 /** |
35 * This class emits some of the code inserted into the shaders for an effect
. The code it | 35 * This class emits some of the code inserted into the shaders for an effect
. The code it |
36 * creates may be dependent on properties of the effect that the effect itse
lf doesn't use | 36 * creates may be dependent on properties of the effect that the effect itse
lf doesn't use |
37 * in its key (e.g. the pixel format of textures used). So this class insert
s a meta-key for | 37 * in its key (e.g. the pixel format of textures used). So this class insert
s a meta-key for |
38 * every effect using this function. It is also responsible for inserting th
e effect's class ID | 38 * every effect using this function. It is also responsible for inserting th
e effect's class ID |
39 * which must be different for every GrEffect subclass. It can fail if an ef
fect uses too many | 39 * which must be different for every GrEffect subclass. It can fail if an ef
fect uses too many |
40 * textures, attributes, etc for the space allotted in the meta-key. | 40 * textures, attributes, etc for the space allotted in the meta-key. |
41 */ | 41 */ |
42 static bool GenEffectMetaKey(const GrEffectStage&, | 42 static bool GenEffectMetaKey(const GrDrawEffect&, const GrGLCaps&, GrEffectK
eyBuilder*); |
43 bool, | |
44 const GrGLCaps&, | |
45 GrEffectKeyBuilder*); | |
46 | 43 |
47 virtual ~GrGLProgramEffects(); | 44 virtual ~GrGLProgramEffects(); |
48 | 45 |
49 /** | 46 /** |
50 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ
es the next | 47 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ
es the next |
51 * available unit to *texUnitIdx when it returns. | 48 * available unit to *texUnitIdx when it returns. |
52 */ | 49 */ |
53 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); | 50 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); |
54 | 51 |
55 /** | 52 /** |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 char fSwizzle[5]; | 107 char fSwizzle[5]; |
111 }; | 108 }; |
112 | 109 |
113 typedef SkTArray<TextureSampler> TextureSamplerArray; | 110 typedef SkTArray<TextureSampler> TextureSamplerArray; |
114 | 111 |
115 protected: | 112 protected: |
116 | 113 |
117 /** | 114 /** |
118 * Helpers for GenEffectMetaKey. | 115 * Helpers for GenEffectMetaKey. |
119 */ | 116 */ |
120 static uint32_t GenAttribKey(const GrEffect*); | 117 static uint32_t GenAttribKey(const GrEffect&); |
121 static uint32_t GenTransformKey(const GrEffectStage&, bool useExplicitLocalC
oords); | 118 static uint32_t GenTransformKey(const GrDrawEffect&); |
122 static uint32_t GenTextureKey(const GrEffect*, const GrGLCaps&); | 119 static uint32_t GenTextureKey(const GrDrawEffect&, const GrGLCaps&); |
123 | 120 |
124 GrGLProgramEffects(int reserveCount) | 121 GrGLProgramEffects(int reserveCount) |
125 : fGLEffects(reserveCount) | 122 : fGLEffects(reserveCount) |
126 , fSamplers(reserveCount) { | 123 , fSamplers(reserveCount) { |
127 } | 124 } |
128 | 125 |
129 /** | 126 /** |
130 * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's t
exture accesses and | 127 * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's t
exture accesses and |
131 * appends the necessary data to the TextureSamplerArray* object so effects
can add texture | 128 * appends the necessary data to the TextureSamplerArray* object so effects
can add texture |
132 * lookups to their code. This method is only meant to be called during the
construction phase. | 129 * lookups to their code. This method is only meant to be called during the
construction phase. |
133 */ | 130 */ |
134 void emitSamplers(GrGLProgramBuilder*, const GrEffect&, TextureSamplerArray*
); | 131 void emitSamplers(GrGLProgramBuilder*, const GrEffect*, TextureSamplerArray*
); |
135 | 132 |
136 /** | 133 /** |
137 * Helper for setData(). Binds all the textures for an effect. | 134 * Helper for setData(). Binds all the textures for an effect. |
138 */ | 135 */ |
139 void bindTextures(GrGpuGL*, const GrEffect&, int effectIdx); | 136 void bindTextures(GrGpuGL*, const GrEffect*, int effectIdx); |
140 | 137 |
141 struct Sampler { | 138 struct Sampler { |
142 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {}) | 139 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {}) |
143 UniformHandle fUniform; | 140 UniformHandle fUniform; |
144 int fTextureUnit; | 141 int fTextureUnit; |
145 }; | 142 }; |
146 | 143 |
147 SkTArray<GrGLEffect*> fGLEffects; | 144 SkTArray<GrGLEffect*> fGLEffects; |
148 SkTArray<SkSTArray<4, Sampler, true> > fSamplers; | 145 SkTArray<SkSTArray<4, Sampler, true> > fSamplers; |
149 | 146 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 void emitAttributes(GrGLFullProgramBuilder*, const GrEffectStage&); | 205 void emitAttributes(GrGLFullProgramBuilder*, const GrEffectStage&); |
209 | 206 |
210 /** | 207 /** |
211 * Helper for emitEffect(). Emits code to implement an effect's coord transf
orms in the VS. | 208 * Helper for emitEffect(). Emits code to implement an effect's coord transf
orms in the VS. |
212 * Varyings are added as an outputs of the VS and inputs to the FS. The vary
ings may be either a | 209 * Varyings are added as an outputs of the VS and inputs to the FS. The vary
ings may be either a |
213 * vec2f or vec3f depending upon whether perspective interpolation is requir
ed or not. The names | 210 * vec2f or vec3f depending upon whether perspective interpolation is requir
ed or not. The names |
214 * of the varyings in the VS and FS as well their types are appended to the | 211 * of the varyings in the VS and FS as well their types are appended to the |
215 * TransformedCoordsArray* object, which is in turn passed to the effect's e
mitCode() function. | 212 * TransformedCoordsArray* object, which is in turn passed to the effect's e
mitCode() function. |
216 */ | 213 */ |
217 void emitTransforms(GrGLFullProgramBuilder*, | 214 void emitTransforms(GrGLFullProgramBuilder*, |
218 const GrEffectStage&, | 215 const GrDrawEffect&, |
219 TransformedCoordsArray*); | 216 TransformedCoordsArray*); |
220 | 217 |
221 /** | 218 /** |
222 * Helper for setData(). Sets all the transform matrices for an effect. | 219 * Helper for setData(). Sets all the transform matrices for an effect. |
223 */ | 220 */ |
224 void setTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const GrE
ffectStage&, | 221 void setTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const GrD
rawEffect&, int effectIdx); |
225 int effectIdx); | 222 void setPathTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const
GrDrawEffect&, |
226 void setPathTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const
GrEffectStage&, | |
227 int effectIdx); | 223 int effectIdx); |
228 | 224 |
229 struct Transform { | 225 struct Transform { |
230 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } | 226 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
231 UniformHandle fHandle; | 227 UniformHandle fHandle; |
232 SkMatrix fCurrentValue; | 228 SkMatrix fCurrentValue; |
233 }; | 229 }; |
234 | 230 |
235 struct PathTransform { | 231 struct PathTransform { |
236 PathTransform() { fCurrentValue = SkMatrix::InvalidMatrix(); } | 232 PathTransform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 300 |
305 /** | 301 /** |
306 * Helper for emitEffect(). Allocates texture units from the builder for eac
h transform in an | 302 * Helper for emitEffect(). Allocates texture units from the builder for eac
h transform in an |
307 * effect. The transforms all use adjacent texture units. They either use tw
o or three of the | 303 * effect. The transforms all use adjacent texture units. They either use tw
o or three of the |
308 * coordinates at a given texture unit, depending on if they need perspectiv
e interpolation. | 304 * coordinates at a given texture unit, depending on if they need perspectiv
e interpolation. |
309 * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[
0])') as well as the | 305 * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[
0])') as well as the |
310 * types are appended to the TransformedCoordsArray* object, which is in tur
n passed to the | 306 * types are appended to the TransformedCoordsArray* object, which is in tur
n passed to the |
311 * effect's emitCode() function. | 307 * effect's emitCode() function. |
312 */ | 308 */ |
313 void setupPathTexGen(GrGLFragmentOnlyProgramBuilder*, | 309 void setupPathTexGen(GrGLFragmentOnlyProgramBuilder*, |
314 const GrEffectStage&, | 310 const GrDrawEffect&, |
315 TransformedCoordsArray*); | 311 TransformedCoordsArray*); |
316 | 312 |
317 /** | 313 /** |
318 * Helper for setData(). Sets the PathTexGen state for each transform in an
effect. | 314 * Helper for setData(). Sets the PathTexGen state for each transform in an
effect. |
319 */ | 315 */ |
320 void setPathTexGenState(GrGpuGL*, const GrEffectStage&, int effectIdx); | 316 void setPathTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx); |
321 | 317 |
322 struct Transforms { | 318 struct Transforms { |
323 Transforms(uint32_t transformKey, int texCoordIndex) | 319 Transforms(uint32_t transformKey, int texCoordIndex) |
324 : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {} | 320 : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {} |
325 uint32_t fTransformKey; | 321 uint32_t fTransformKey; |
326 int fTexCoordIndex; | 322 int fTexCoordIndex; |
327 }; | 323 }; |
328 | 324 |
329 SkTArray<Transforms> fTransforms; | 325 SkTArray<Transforms> fTransforms; |
330 | 326 |
(...skipping 19 matching lines...) Expand all Loading... |
350 */ | 346 */ |
351 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } | 347 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } |
352 private: | 348 private: |
353 GrGLFragmentOnlyProgramBuilder* fBuilder; | 349 GrGLFragmentOnlyProgramBuilder* fBuilder; |
354 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; | 350 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; |
355 typedef GrGLProgramEffectsBuilder INHERITED; | 351 typedef GrGLProgramEffectsBuilder INHERITED; |
356 }; | 352 }; |
357 | 353 |
358 | 354 |
359 #endif | 355 #endif |
OLD | NEW |