| 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 "GrGLUniformManager.h" | 12 #include "GrGLUniformManager.h" |
| 13 #include "GrTexture.h" | 13 #include "GrTexture.h" |
| 14 #include "GrTextureAccess.h" | 14 #include "GrTextureAccess.h" |
| 15 | 15 |
| 16 class GrEffect; | 16 class GrEffect; |
| 17 class GrEffectStage; | 17 class GrEffectStage; |
| 18 class GrGLVertexProgramEffectsBuilder; | 18 class GrGLVertexProgramEffectsBuilder; |
| 19 class GrGLShaderBuilder; | 19 class GrGLShaderBuilder; |
| 20 class GrGLFullShaderBuilder; | 20 class GrGLFullShaderBuilder; |
| 21 class GrGLFragmentOnlyShaderBuilder; | 21 class GrGLFragmentOnlyShaderBuilder; |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * 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 |
| 25 * 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 |
| 26 * state and shader uniforms. | 26 * state and shader uniforms. |
| 27 */ | 27 */ |
| 28 class GrGLProgramEffects : public SkRefCnt { | 28 class GrGLProgramEffects : public SkRefCnt { |
| 29 public: | 29 public: |
| 30 typedef GrBackendEffectFactory::EffectKey EffectKey; | |
| 31 typedef GrGLUniformManager::UniformHandle UniformHandle; | 30 typedef GrGLUniformManager::UniformHandle UniformHandle; |
| 32 | 31 |
| 33 /** | 32 /** |
| 34 * This class emits some of the code inserted into the shaders for an effect
. The code it | 33 * This class emits some of the code inserted into the shaders for an effect
. The code it |
| 35 * creates may be dependent on properties of the effect that the effect itse
lf doesn't use | 34 * creates may be dependent on properties of the effect that the effect itse
lf doesn't use |
| 36 * in its key (e.g. the pixel format of textures used). So this class insert
s a meta-key for | 35 * in its key (e.g. the pixel format of textures used). So this class insert
s a meta-key for |
| 37 * every effect using this function. It is also responsible for inserting th
e effect's class ID | 36 * every effect using this function. It is also responsible for inserting th
e effect's class ID |
| 38 * which must be different for every GrEffect subclass. It can fail if an ef
fect uses too many | 37 * which must be different for every GrEffect subclass. It can fail if an ef
fect uses too many |
| 39 * textures, attributes, etc for the space allotted in the meta-key. | 38 * textures, attributes, etc for the space allotted in the meta-key. |
| 40 */ | 39 */ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 uint32_t fConfigComponentMask; | 96 uint32_t fConfigComponentMask; |
| 98 char fSwizzle[5]; | 97 char fSwizzle[5]; |
| 99 }; | 98 }; |
| 100 | 99 |
| 101 typedef SkTArray<TextureSampler> TextureSamplerArray; | 100 typedef SkTArray<TextureSampler> TextureSamplerArray; |
| 102 | 101 |
| 103 protected: | 102 protected: |
| 104 /** | 103 /** |
| 105 * Helpers for GenEffectMetaKey. | 104 * Helpers for GenEffectMetaKey. |
| 106 */ | 105 */ |
| 107 static EffectKey GenAttribKey(const GrDrawEffect&); | 106 static uint32_t GenAttribKey(const GrDrawEffect&); |
| 108 static EffectKey GenTransformKey(const GrDrawEffect&); | 107 static uint32_t GenTransformKey(const GrDrawEffect&); |
| 109 static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&); | 108 static uint32_t GenTextureKey(const GrDrawEffect&, const GrGLCaps&); |
| 110 | 109 |
| 111 GrGLProgramEffects(int reserveCount) | 110 GrGLProgramEffects(int reserveCount) |
| 112 : fGLEffects(reserveCount) | 111 : fGLEffects(reserveCount) |
| 113 , fSamplers(reserveCount) { | 112 , fSamplers(reserveCount) { |
| 114 } | 113 } |
| 115 | 114 |
| 116 /** | 115 /** |
| 117 * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's t
exture accesses and | 116 * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's t
exture accesses and |
| 118 * appends the necessary data to the TextureSamplerArray* object so effects
can add texture | 117 * appends the necessary data to the TextureSamplerArray* object so effects
can add texture |
| 119 * lookups to their code. This method is only meant to be called during the
construction phase. | 118 * lookups to their code. This method is only meant to be called during the
construction phase. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 142 * This is an abstract base class for constructing different types of GrGLProgra
mEffects objects. | 141 * This is an abstract base class for constructing different types of GrGLProgra
mEffects objects. |
| 143 */ | 142 */ |
| 144 class GrGLProgramEffectsBuilder { | 143 class GrGLProgramEffectsBuilder { |
| 145 public: | 144 public: |
| 146 virtual ~GrGLProgramEffectsBuilder() { } | 145 virtual ~GrGLProgramEffectsBuilder() { } |
| 147 | 146 |
| 148 /** | 147 /** |
| 149 * Emits the effect's shader code, and stores the necessary uniforms interna
lly. | 148 * Emits the effect's shader code, and stores the necessary uniforms interna
lly. |
| 150 */ | 149 */ |
| 151 virtual void emitEffect(const GrEffectStage&, | 150 virtual void emitEffect(const GrEffectStage&, |
| 152 GrGLProgramEffects::EffectKey, | 151 const GrEffectKey&, |
| 153 const char* outColor, | 152 const char* outColor, |
| 154 const char* inColor, | 153 const char* inColor, |
| 155 int stageIndex) = 0; | 154 int stageIndex) = 0; |
| 156 }; | 155 }; |
| 157 | 156 |
| 158 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
| 159 | 158 |
| 160 /** | 159 /** |
| 161 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. | 160 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. |
| 162 */ | 161 */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 174 , fTransforms(reserveCount) | 173 , fTransforms(reserveCount) |
| 175 , fHasExplicitLocalCoords(explicitLocalCoords) { | 174 , fHasExplicitLocalCoords(explicitLocalCoords) { |
| 176 } | 175 } |
| 177 | 176 |
| 178 /** | 177 /** |
| 179 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant
to only be called | 178 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant
to only be called |
| 180 * during the construction phase. | 179 * during the construction phase. |
| 181 */ | 180 */ |
| 182 void emitEffect(GrGLFullShaderBuilder*, | 181 void emitEffect(GrGLFullShaderBuilder*, |
| 183 const GrEffectStage&, | 182 const GrEffectStage&, |
| 184 GrGLProgramEffects::EffectKey, | 183 const GrEffectKey&, |
| 185 const char* outColor, | 184 const char* outColor, |
| 186 const char* inColor, | 185 const char* inColor, |
| 187 int stageIndex); | 186 int stageIndex); |
| 188 | 187 |
| 189 /** | 188 /** |
| 190 * Helper for emitEffect(). Emits any attributes an effect may have. | 189 * Helper for emitEffect(). Emits any attributes an effect may have. |
| 191 */ | 190 */ |
| 192 void emitAttributes(GrGLFullShaderBuilder*, const GrEffectStage&); | 191 void emitAttributes(GrGLFullShaderBuilder*, const GrEffectStage&); |
| 193 | 192 |
| 194 /** | 193 /** |
| (...skipping 26 matching lines...) Expand all Loading... |
| 221 | 220 |
| 222 /** | 221 /** |
| 223 * This class is used to construct a GrGLVertexProgramEffects* object. | 222 * This class is used to construct a GrGLVertexProgramEffects* object. |
| 224 */ | 223 */ |
| 225 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder { | 224 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder { |
| 226 public: | 225 public: |
| 227 GrGLVertexProgramEffectsBuilder(GrGLFullShaderBuilder*, int reserveCount); | 226 GrGLVertexProgramEffectsBuilder(GrGLFullShaderBuilder*, int reserveCount); |
| 228 virtual ~GrGLVertexProgramEffectsBuilder() { } | 227 virtual ~GrGLVertexProgramEffectsBuilder() { } |
| 229 | 228 |
| 230 virtual void emitEffect(const GrEffectStage&, | 229 virtual void emitEffect(const GrEffectStage&, |
| 231 GrGLProgramEffects::EffectKey, | 230 const GrEffectKey&, |
| 232 const char* outColor, | 231 const char* outColor, |
| 233 const char* inColor, | 232 const char* inColor, |
| 234 int stageIndex) SK_OVERRIDE; | 233 int stageIndex) SK_OVERRIDE; |
| 235 | 234 |
| 236 /** | 235 /** |
| 237 * Finalizes the building process and returns the effect array. After this c
all, the builder | 236 * Finalizes the building process and returns the effect array. After this c
all, the builder |
| 238 * becomes invalid. | 237 * becomes invalid. |
| 239 */ | 238 */ |
| 240 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } | 239 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } |
| 241 | 240 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 265 : INHERITED(reserveCount) | 264 : INHERITED(reserveCount) |
| 266 , fTransforms(reserveCount) { | 265 , fTransforms(reserveCount) { |
| 267 } | 266 } |
| 268 | 267 |
| 269 /** | 268 /** |
| 270 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant
to only be called | 269 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant
to only be called |
| 271 * during the construction phase. | 270 * during the construction phase. |
| 272 */ | 271 */ |
| 273 void emitEffect(GrGLFragmentOnlyShaderBuilder*, | 272 void emitEffect(GrGLFragmentOnlyShaderBuilder*, |
| 274 const GrEffectStage&, | 273 const GrEffectStage&, |
| 275 GrGLProgramEffects::EffectKey, | 274 const GrEffectKey&, |
| 276 const char* outColor, | 275 const char* outColor, |
| 277 const char* inColor, | 276 const char* inColor, |
| 278 int stageIndex); | 277 int stageIndex); |
| 279 | 278 |
| 280 /** | 279 /** |
| 281 * Helper for emitEffect(). Allocates texture units from the builder for eac
h transform in an | 280 * Helper for emitEffect(). Allocates texture units from the builder for eac
h transform in an |
| 282 * effect. The transforms all use adjacent texture units. They either use tw
o or three of the | 281 * effect. The transforms all use adjacent texture units. They either use tw
o or three of the |
| 283 * coordinates at a given texture unit, depending on if they need perspectiv
e interpolation. | 282 * coordinates at a given texture unit, depending on if they need perspectiv
e interpolation. |
| 284 * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[
0])') as well as the | 283 * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[
0])') as well as the |
| 285 * types are appended to the TransformedCoordsArray* object, which is in tur
n passed to the | 284 * types are appended to the TransformedCoordsArray* object, which is in tur
n passed to the |
| 286 * effect's emitCode() function. | 285 * effect's emitCode() function. |
| 287 */ | 286 */ |
| 288 void setupPathTexGen(GrGLFragmentOnlyShaderBuilder*, | 287 void setupPathTexGen(GrGLFragmentOnlyShaderBuilder*, |
| 289 const GrDrawEffect&, | 288 const GrDrawEffect&, |
| 290 TransformedCoordsArray*); | 289 TransformedCoordsArray*); |
| 291 | 290 |
| 292 /** | 291 /** |
| 293 * Helper for setData(). Sets the PathTexGen state for each transform in an
effect. | 292 * Helper for setData(). Sets the PathTexGen state for each transform in an
effect. |
| 294 */ | 293 */ |
| 295 void setPathTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx); | 294 void setPathTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx); |
| 296 | 295 |
| 297 struct Transforms { | 296 struct Transforms { |
| 298 Transforms(EffectKey transformKey, int texCoordIndex) | 297 Transforms(uint32_t transformKey, int texCoordIndex) |
| 299 : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {} | 298 : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {} |
| 300 EffectKey fTransformKey; | 299 uint32_t fTransformKey; |
| 301 int fTexCoordIndex; | 300 int fTexCoordIndex; |
| 302 }; | 301 }; |
| 303 | 302 |
| 304 SkTArray<Transforms> fTransforms; | 303 SkTArray<Transforms> fTransforms; |
| 305 | 304 |
| 306 typedef GrGLProgramEffects INHERITED; | 305 typedef GrGLProgramEffects INHERITED; |
| 307 }; | 306 }; |
| 308 | 307 |
| 309 /** | 308 /** |
| 310 * This class is used to construct a GrGLPathTexGenProgramEffects* object. | 309 * This class is used to construct a GrGLPathTexGenProgramEffects* object. |
| 311 */ | 310 */ |
| 312 class GrGLPathTexGenProgramEffectsBuilder : public GrGLProgramEffectsBuilder { | 311 class GrGLPathTexGenProgramEffectsBuilder : public GrGLProgramEffectsBuilder { |
| 313 public: | 312 public: |
| 314 GrGLPathTexGenProgramEffectsBuilder(GrGLFragmentOnlyShaderBuilder*, int rese
rveCount); | 313 GrGLPathTexGenProgramEffectsBuilder(GrGLFragmentOnlyShaderBuilder*, int rese
rveCount); |
| 315 virtual ~GrGLPathTexGenProgramEffectsBuilder() { } | 314 virtual ~GrGLPathTexGenProgramEffectsBuilder() { } |
| 316 | 315 |
| 317 virtual void emitEffect(const GrEffectStage&, | 316 virtual void emitEffect(const GrEffectStage&, |
| 318 GrGLProgramEffects::EffectKey, | 317 const GrEffectKey&, |
| 319 const char* outColor, | 318 const char* outColor, |
| 320 const char* inColor, | 319 const char* inColor, |
| 321 int stageIndex) SK_OVERRIDE; | 320 int stageIndex) SK_OVERRIDE; |
| 322 | 321 |
| 323 /** | 322 /** |
| 324 * Finalizes the building process and returns the effect array. After this c
all, the builder | 323 * Finalizes the building process and returns the effect array. After this c
all, the builder |
| 325 * becomes invalid. | 324 * becomes invalid. |
| 326 */ | 325 */ |
| 327 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } | 326 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } |
| 328 | 327 |
| 329 private: | 328 private: |
| 330 GrGLFragmentOnlyShaderBuilder* fBuilder; | 329 GrGLFragmentOnlyShaderBuilder* fBuilder; |
| 331 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; | 330 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; |
| 332 | 331 |
| 333 typedef GrGLProgramEffectsBuilder INHERITED; | 332 typedef GrGLProgramEffectsBuilder INHERITED; |
| 334 }; | 333 }; |
| 335 | 334 |
| 336 #endif | 335 #endif |
| OLD | NEW |