| 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 "GrTexture.h" | 12 #include "GrTexture.h" |
| 13 #include "GrTextureAccess.h" | 13 #include "GrTextureAccess.h" |
| 14 #include "GrGLUniformManager.h" | 14 #include "GrGLUniformManager.h" |
| 15 #include "GrGpu.h" |
| 15 | 16 |
| 16 class GrEffectStage; | 17 class GrEffectStage; |
| 17 class GrGLVertexProgramEffectsBuilder; | 18 class GrGLVertexProgramEffectsBuilder; |
| 18 class GrGLShaderBuilder; | 19 class GrGLShaderBuilder; |
| 19 class GrGLFullShaderBuilder; | 20 class GrGLFullShaderBuilder; |
| 20 class GrGLFragmentOnlyShaderBuilder; | 21 class GrGLFragmentOnlyShaderBuilder; |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * This class encapsulates an array of GrGLEffects and their supporting data (co
ord transforms | 24 * This class encapsulates an array of GrGLEffects and their supporting data (co
ord transforms |
| 24 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag
e the necessary GL | 25 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag
e the necessary GL |
| 25 * state and shader uniforms. | 26 * state and shader uniforms. |
| 26 */ | 27 */ |
| 27 class GrGLProgramEffects : public SkRefCnt { | 28 class GrGLProgramEffects : public SkRefCnt { |
| 28 public: | 29 public: |
| 29 typedef GrBackendEffectFactory::EffectKey EffectKey; | 30 typedef GrBackendEffectFactory::EffectKey EffectKey; |
| 30 typedef GrGLUniformManager::UniformHandle UniformHandle; | 31 typedef GrGLUniformManager::UniformHandle UniformHandle; |
| 32 typedef GrGLUniformManager::FragmentInputHandle FragmentInputHandle; |
| 31 | 33 |
| 32 /** | 34 /** |
| 33 * These methods generate different portions of an effect's final key. | 35 * These methods generate different portions of an effect's final key. |
| 34 */ | 36 */ |
| 35 static EffectKey GenAttribKey(const GrDrawEffect&); | 37 static EffectKey GenAttribKey(const GrDrawEffect&); |
| 36 static EffectKey GenTransformKey(const GrDrawEffect&); | 38 static EffectKey GenTransformKey(const GrDrawEffect&); |
| 37 static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&); | 39 static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&); |
| 38 | 40 |
| 39 virtual ~GrGLProgramEffects(); | 41 virtual ~GrGLProgramEffects(); |
| 40 | 42 |
| 41 /** | 43 /** |
| 42 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ
es the next | 44 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ
es the next |
| 43 * available unit to *texUnitIdx when it returns. | 45 * available unit to *texUnitIdx when it returns. |
| 44 */ | 46 */ |
| 45 void initSamplers(const GrGLUniformManager&, int* texUnitIdx); | 47 void initSamplers(const GrGLUniformManager&, int* texUnitIdx); |
| 46 | 48 |
| 47 /** | 49 /** |
| 48 * Calls setData() on each effect, and sets their transformation matrices an
d texture bindings. | 50 * Calls setData() on each effect, and sets their transformation matrices an
d texture bindings. |
| 49 */ | 51 */ |
| 50 virtual void setData(GrGpuGL*, | 52 virtual void setData(GrGpuGL*, |
| 53 GrGpu::DrawType, |
| 51 const GrGLUniformManager&, | 54 const GrGLUniformManager&, |
| 52 const GrEffectStage* effectStages[]) = 0; | 55 const GrEffectStage* effectStages[]) = 0; |
| 53 | 56 |
| 54 /** | 57 /** |
| 55 * Passed to GrGLEffects so they can add transformed coordinates to their sh
ader code. | 58 * Passed to GrGLEffects so they can add transformed coordinates to their sh
ader code. |
| 56 */ | 59 */ |
| 57 class TransformedCoords { | 60 class TransformedCoords { |
| 58 public: | 61 public: |
| 59 TransformedCoords(const SkString& name, GrSLType type) | 62 TransformedCoords(const SkString& name, GrSLType type) |
| 60 : fName(name), fType(type) { | 63 : fName(name), fType(type) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 }; | 148 }; |
| 146 | 149 |
| 147 //////////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////////// |
| 148 | 151 |
| 149 /** | 152 /** |
| 150 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. | 153 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. |
| 151 */ | 154 */ |
| 152 class GrGLVertexProgramEffects : public GrGLProgramEffects { | 155 class GrGLVertexProgramEffects : public GrGLProgramEffects { |
| 153 public: | 156 public: |
| 154 virtual void setData(GrGpuGL*, | 157 virtual void setData(GrGpuGL*, |
| 158 GrGpu::DrawType, |
| 155 const GrGLUniformManager&, | 159 const GrGLUniformManager&, |
| 156 const GrEffectStage* effectStages[]) SK_OVERRIDE; | 160 const GrEffectStage* effectStages[]) SK_OVERRIDE; |
| 157 | 161 |
| 158 private: | 162 private: |
| 159 friend class GrGLVertexProgramEffectsBuilder; | 163 friend class GrGLVertexProgramEffectsBuilder; |
| 160 | 164 |
| 161 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) | 165 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) |
| 162 : INHERITED(reserveCount) | 166 : INHERITED(reserveCount) |
| 163 , fTransforms(reserveCount) | 167 , fTransforms(reserveCount) |
| 164 , fHasExplicitLocalCoords(explicitLocalCoords) { | 168 , fHasExplicitLocalCoords(explicitLocalCoords) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 188 * TransformedCoordsArray* object, which is in turn passed to the effect's e
mitCode() function. | 192 * TransformedCoordsArray* object, which is in turn passed to the effect's e
mitCode() function. |
| 189 */ | 193 */ |
| 190 void emitTransforms(GrGLFullShaderBuilder*, | 194 void emitTransforms(GrGLFullShaderBuilder*, |
| 191 const GrEffectRef&, | 195 const GrEffectRef&, |
| 192 EffectKey, | 196 EffectKey, |
| 193 TransformedCoordsArray*); | 197 TransformedCoordsArray*); |
| 194 | 198 |
| 195 /** | 199 /** |
| 196 * Helper for setData(). Sets all the transform matrices for an effect. | 200 * Helper for setData(). Sets all the transform matrices for an effect. |
| 197 */ | 201 */ |
| 198 void setTransformData(const GrGLUniformManager&, const GrDrawEffect&, int ef
fectIdx); | 202 void setTransformData(GrGpuGL* gpu, const GrGLUniformManager&, const GrDrawE
ffect&, int effectIdx); |
| 203 void setFragmentInputTransformData(GrGpuGL* gpu, const GrGLUniformManager&,
const GrDrawEffect&, |
| 204 int effectIdx); |
| 199 | 205 |
| 200 struct Transform { | 206 struct Transform { |
| 201 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } | 207 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
| 202 UniformHandle fHandle; | 208 UniformHandle fHandle; |
| 203 SkMatrix fCurrentValue; | 209 SkMatrix fCurrentValue; |
| 204 }; | 210 }; |
| 205 | 211 struct FragmentInputTransform { |
| 212 FragmentInputTransform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
| 213 FragmentInputHandle fHandle; |
| 214 SkMatrix fCurrentValue; |
| 215 GrSLType fType; |
| 216 }; |
| 206 SkTArray<SkSTArray<2, Transform, true> > fTransforms; | 217 SkTArray<SkSTArray<2, Transform, true> > fTransforms; |
| 218 SkTArray<SkTArray<FragmentInputTransform, true> > fFragmentInputTransforms; |
| 207 bool fHasExplicitLocalCoords; | 219 bool fHasExplicitLocalCoords; |
| 208 | 220 |
| 209 typedef GrGLProgramEffects INHERITED; | 221 typedef GrGLProgramEffects INHERITED; |
| 210 }; | 222 }; |
| 211 | 223 |
| 212 /** | 224 /** |
| 213 * This class is used to construct a GrGLVertexProgramEffects* object. | 225 * This class is used to construct a GrGLVertexProgramEffects* object. |
| 214 */ | 226 */ |
| 215 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder { | 227 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder { |
| 216 public: | 228 public: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 238 | 250 |
| 239 //////////////////////////////////////////////////////////////////////////////// | 251 //////////////////////////////////////////////////////////////////////////////// |
| 240 | 252 |
| 241 /** | 253 /** |
| 242 * This is a GrGLProgramEffects implementation that does coord transforms with | 254 * This is a GrGLProgramEffects implementation that does coord transforms with |
| 243 * the the NV_path_rendering PathTexGen functionality. | 255 * the the NV_path_rendering PathTexGen functionality. |
| 244 */ | 256 */ |
| 245 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { | 257 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { |
| 246 public: | 258 public: |
| 247 virtual void setData(GrGpuGL*, | 259 virtual void setData(GrGpuGL*, |
| 260 GrGpu::DrawType, |
| 248 const GrGLUniformManager&, | 261 const GrGLUniformManager&, |
| 249 const GrEffectStage* effectStages[]) SK_OVERRIDE; | 262 const GrEffectStage* effectStages[]) SK_OVERRIDE; |
| 250 | 263 |
| 251 private: | 264 private: |
| 252 friend class GrGLPathTexGenProgramEffectsBuilder; | 265 friend class GrGLPathTexGenProgramEffectsBuilder; |
| 253 | 266 |
| 254 GrGLPathTexGenProgramEffects(int reserveCount) | 267 GrGLPathTexGenProgramEffects(int reserveCount) |
| 255 : INHERITED(reserveCount) | 268 : INHERITED(reserveCount) |
| 256 , fTransforms(reserveCount) { | 269 , fTransforms(reserveCount) { |
| 257 } | 270 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } | 331 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } |
| 319 | 332 |
| 320 private: | 333 private: |
| 321 GrGLFragmentOnlyShaderBuilder* fBuilder; | 334 GrGLFragmentOnlyShaderBuilder* fBuilder; |
| 322 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; | 335 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; |
| 323 | 336 |
| 324 typedef GrGLProgramEffectsBuilder INHERITED; | 337 typedef GrGLProgramEffectsBuilder INHERITED; |
| 325 }; | 338 }; |
| 326 | 339 |
| 327 #endif | 340 #endif |
| OLD | NEW |