| 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 "GrBackendEffectFactory.h" |
| 12 #include "GrGLProgramDataManager.h" | 12 #include "GrGLProgramDataManager.h" |
| 13 #include "GrGpu.h" |
| 13 #include "GrTexture.h" | 14 #include "GrTexture.h" |
| 14 #include "GrTextureAccess.h" | 15 #include "GrTextureAccess.h" |
| 15 | 16 |
| 16 class GrEffect; | 17 class GrEffect; |
| 17 class GrEffectStage; | 18 class GrEffectStage; |
| 18 class GrGLVertexProgramEffectsBuilder; | 19 class GrGLVertexProgramEffectsBuilder; |
| 19 class GrGLProgramBuilder; | 20 class GrGLProgramBuilder; |
| 20 class GrGLFullProgramBuilder; | 21 class GrGLFullProgramBuilder; |
| 21 class GrGLFragmentOnlyProgramBuilder; | 22 class GrGLFragmentOnlyProgramBuilder; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * This class encapsulates an array of GrGLEffects and their supporting data (co
ord transforms | 25 * This class encapsulates an array of GrGLEffects and their supporting data (co
ord transforms |
| 25 * 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 |
| 26 * state and shader uniforms. | 27 * state and shader uniforms. |
| 27 */ | 28 */ |
| 28 class GrGLProgramEffects : public SkRefCnt { | 29 class GrGLProgramEffects : public SkRefCnt { |
| 29 public: | 30 public: |
| 30 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 31 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 32 typedef GrGLProgramDataManager::VaryingHandle VaryingHandle; |
| 31 | 33 |
| 32 /** | 34 /** |
| 33 * 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 |
| 34 * 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 |
| 35 * 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 |
| 36 * 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 |
| 37 * 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 |
| 38 * textures, attributes, etc for the space allotted in the meta-key. | 40 * textures, attributes, etc for the space allotted in the meta-key. |
| 39 */ | 41 */ |
| 40 static bool GenEffectMetaKey(const GrDrawEffect&, const GrGLCaps&, GrEffectK
eyBuilder*); | 42 static bool GenEffectMetaKey(const GrDrawEffect&, const GrGLCaps&, GrEffectK
eyBuilder*); |
| 41 | 43 |
| 42 virtual ~GrGLProgramEffects(); | 44 virtual ~GrGLProgramEffects(); |
| 43 | 45 |
| 44 /** | 46 /** |
| 45 * 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 |
| 46 * available unit to *texUnitIdx when it returns. | 48 * available unit to *texUnitIdx when it returns. |
| 47 */ | 49 */ |
| 48 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); | 50 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); |
| 49 | 51 |
| 50 /** | 52 /** |
| 51 * Calls setData() on each effect, and sets their transformation matrices an
d texture bindings. | 53 * Calls setData() on each effect, and sets their transformation matrices an
d texture bindings. |
| 52 */ | 54 */ |
| 53 virtual void setData(GrGpuGL*, | 55 virtual void setData(GrGpuGL*, |
| 56 GrGpu::DrawType, |
| 54 const GrGLProgramDataManager&, | 57 const GrGLProgramDataManager&, |
| 55 const GrEffectStage* effectStages[]) = 0; | 58 const GrEffectStage* effectStages[]) = 0; |
| 56 | 59 |
| 57 void addEffect(GrGLEffect* effect) { fGLEffects.push_back(effect); } | 60 void addEffect(GrGLEffect* effect) { fGLEffects.push_back(effect); } |
| 58 | 61 |
| 59 /** | 62 /** |
| 60 * Passed to GrGLEffects so they can add transformed coordinates to their sh
ader code. | 63 * Passed to GrGLEffects so they can add transformed coordinates to their sh
ader code. |
| 61 */ | 64 */ |
| 62 class TransformedCoords { | 65 class TransformedCoords { |
| 63 public: | 66 public: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 }; | 161 }; |
| 159 | 162 |
| 160 //////////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////////// |
| 161 | 164 |
| 162 /** | 165 /** |
| 163 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. | 166 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. |
| 164 */ | 167 */ |
| 165 class GrGLVertexProgramEffects : public GrGLProgramEffects { | 168 class GrGLVertexProgramEffects : public GrGLProgramEffects { |
| 166 public: | 169 public: |
| 167 virtual void setData(GrGpuGL*, | 170 virtual void setData(GrGpuGL*, |
| 171 GrGpu::DrawType, |
| 168 const GrGLProgramDataManager&, | 172 const GrGLProgramDataManager&, |
| 169 const GrEffectStage* effectStages[]) SK_OVERRIDE; | 173 const GrEffectStage* effectStages[]) SK_OVERRIDE; |
| 170 | 174 |
| 171 private: | 175 private: |
| 172 friend class GrGLFullProgramBuilder; | 176 friend class GrGLFullProgramBuilder; |
| 173 | 177 |
| 174 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) | 178 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) |
| 175 : INHERITED(reserveCount) | 179 : INHERITED(reserveCount) |
| 176 , fTransforms(reserveCount) | 180 , fTransforms(reserveCount) |
| 177 , fHasExplicitLocalCoords(explicitLocalCoords) { | 181 , fHasExplicitLocalCoords(explicitLocalCoords) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 198 * of the varyings in the VS and FS as well their types are appended to the | 202 * of the varyings in the VS and FS as well their types are appended to the |
| 199 * TransformedCoordsArray* object, which is in turn passed to the effect's e
mitCode() function. | 203 * TransformedCoordsArray* object, which is in turn passed to the effect's e
mitCode() function. |
| 200 */ | 204 */ |
| 201 void emitTransforms(GrGLFullProgramBuilder*, | 205 void emitTransforms(GrGLFullProgramBuilder*, |
| 202 const GrDrawEffect&, | 206 const GrDrawEffect&, |
| 203 TransformedCoordsArray*); | 207 TransformedCoordsArray*); |
| 204 | 208 |
| 205 /** | 209 /** |
| 206 * Helper for setData(). Sets all the transform matrices for an effect. | 210 * Helper for setData(). Sets all the transform matrices for an effect. |
| 207 */ | 211 */ |
| 208 void setTransformData(const GrGLProgramDataManager&, const GrDrawEffect&, in
t effectIdx); | 212 void setTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const GrD
rawEffect&, int effectIdx); |
| 213 void setPathTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const
GrDrawEffect&, |
| 214 int effectIdx); |
| 209 | 215 |
| 210 struct Transform { | 216 struct Transform { |
| 211 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } | 217 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
| 212 UniformHandle fHandle; | 218 UniformHandle fHandle; |
| 213 SkMatrix fCurrentValue; | 219 SkMatrix fCurrentValue; |
| 214 }; | 220 }; |
| 215 | 221 |
| 222 struct PathTransform { |
| 223 PathTransform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
| 224 VaryingHandle fHandle; |
| 225 SkMatrix fCurrentValue; |
| 226 GrSLType fType; |
| 227 }; |
| 228 |
| 216 SkTArray<SkSTArray<2, Transform, true> > fTransforms; | 229 SkTArray<SkSTArray<2, Transform, true> > fTransforms; |
| 230 SkTArray<SkTArray<PathTransform, true> > fPathTransforms; |
| 217 bool fHasExplicitLocalCoords; | 231 bool fHasExplicitLocalCoords; |
| 218 | 232 |
| 219 friend class GrGLVertexProgramEffectsBuilder; | 233 friend class GrGLVertexProgramEffectsBuilder; |
| 220 | 234 |
| 221 typedef GrGLProgramEffects INHERITED; | 235 typedef GrGLProgramEffects INHERITED; |
| 222 }; | 236 }; |
| 223 | 237 |
| 224 /** | 238 /** |
| 225 * This class is used to construct a GrGLVertexProgramEffects* object. | 239 * This class is used to construct a GrGLVertexProgramEffects* object. |
| 226 */ | 240 */ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 246 | 260 |
| 247 //////////////////////////////////////////////////////////////////////////////// | 261 //////////////////////////////////////////////////////////////////////////////// |
| 248 | 262 |
| 249 /** | 263 /** |
| 250 * This is a GrGLProgramEffects implementation that does coord transforms with | 264 * This is a GrGLProgramEffects implementation that does coord transforms with |
| 251 * the the NV_path_rendering PathTexGen functionality. | 265 * the the NV_path_rendering PathTexGen functionality. |
| 252 */ | 266 */ |
| 253 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { | 267 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { |
| 254 public: | 268 public: |
| 255 virtual void setData(GrGpuGL*, | 269 virtual void setData(GrGpuGL*, |
| 270 GrGpu::DrawType, |
| 256 const GrGLProgramDataManager&, | 271 const GrGLProgramDataManager&, |
| 257 const GrEffectStage* effectStages[]) SK_OVERRIDE; | 272 const GrEffectStage* effectStages[]) SK_OVERRIDE; |
| 258 | 273 |
| 259 private: | 274 private: |
| 260 friend class GrGLFragmentOnlyProgramBuilder; | 275 friend class GrGLFragmentOnlyProgramBuilder; |
| 261 | 276 |
| 262 GrGLPathTexGenProgramEffects(int reserveCount) | 277 GrGLPathTexGenProgramEffects(int reserveCount) |
| 263 : INHERITED(reserveCount) | 278 : INHERITED(reserveCount) |
| 264 , fTransforms(reserveCount) { | 279 , fTransforms(reserveCount) { |
| 265 } | 280 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 */ | 337 */ |
| 323 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } | 338 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } |
| 324 private: | 339 private: |
| 325 GrGLFragmentOnlyProgramBuilder* fBuilder; | 340 GrGLFragmentOnlyProgramBuilder* fBuilder; |
| 326 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; | 341 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; |
| 327 typedef GrGLProgramEffectsBuilder INHERITED; | 342 typedef GrGLProgramEffectsBuilder INHERITED; |
| 328 }; | 343 }; |
| 329 | 344 |
| 330 | 345 |
| 331 #endif | 346 #endif |
| OLD | NEW |