commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrGLProgramEffects_DEFINED |
| 9 | #define GrGLProgramEffects_DEFINED |
| 10 | |
| 11 | #include "GrBackendEffectFactory.h" |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 12 | #include "GrGLProgramDataManager.h" |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 13 | #include "GrTexture.h" |
| 14 | #include "GrTextureAccess.h" |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 15 | |
bsalomon | f99f884 | 2014-07-07 11:54:23 -0700 | [diff] [blame] | 16 | class GrEffect; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 17 | class GrEffectStage; |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 18 | class GrGLVertexProgramEffectsBuilder; |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 19 | class GrGLProgramBuilder; |
| 20 | class GrGLFullProgramBuilder; |
| 21 | class GrGLFragmentOnlyProgramBuilder; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * This class encapsulates an array of GrGLEffects and their supporting data (coord transforms |
| 25 | * and textures). It is built with GrGLProgramEffectsBuilder, then used to manage the necessary GL |
| 26 | * state and shader uniforms. |
| 27 | */ |
commit-bot@chromium.org | a05fa06 | 2014-05-30 18:55:03 +0000 | [diff] [blame] | 28 | class GrGLProgramEffects : public SkRefCnt { |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 29 | public: |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 30 | typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 33 | * 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 itself doesn't use |
| 35 | * in its key (e.g. the pixel format of textures used). So this class inserts a meta-key for |
| 36 | * every effect using this function. It is also responsible for inserting the effect's class ID |
| 37 | * which must be different for every GrEffect subclass. It can fail if an effect uses too many |
| 38 | * textures, attributes, etc for the space allotted in the meta-key. |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 39 | */ |
bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 40 | static bool GenEffectMetaKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*); |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 41 | |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 42 | virtual ~GrGLProgramEffects(); |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writes the next |
| 46 | * available unit to *texUnitIdx when it returns. |
| 47 | */ |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 48 | void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Calls setData() on each effect, and sets their transformation matrices and texture bindings. |
| 52 | */ |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 53 | virtual void setData(GrGpuGL*, |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 54 | const GrGLProgramDataManager&, |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 55 | const GrEffectStage* effectStages[]) = 0; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 56 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 57 | void addEffect(GrGLEffect* effect) { fGLEffects.push_back(effect); } |
| 58 | |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 59 | /** |
| 60 | * Passed to GrGLEffects so they can add transformed coordinates to their shader code. |
| 61 | */ |
| 62 | class TransformedCoords { |
| 63 | public: |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 64 | TransformedCoords(const SkString& name, GrSLType type) |
commit-bot@chromium.org | 5fd7d5c | 2013-10-04 01:20:09 +0000 | [diff] [blame] | 65 | : fName(name), fType(type) { |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | const char* c_str() const { return fName.c_str(); } |
| 69 | GrSLType type() const { return fType; } |
| 70 | const SkString& getName() const { return fName; } |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 71 | |
| 72 | private: |
| 73 | SkString fName; |
| 74 | GrSLType fType; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | typedef SkTArray<TransformedCoords> TransformedCoordsArray; |
| 78 | |
| 79 | /** |
| 80 | * Passed to GrGLEffects so they can add texture reads to their shader code. |
| 81 | */ |
| 82 | class TextureSampler { |
| 83 | public: |
| 84 | TextureSampler(UniformHandle uniform, const GrTextureAccess& access) |
| 85 | : fSamplerUniform(uniform) |
| 86 | , fConfigComponentMask(GrPixelConfigComponentMask(access.getTexture()->config())) { |
| 87 | SkASSERT(0 != fConfigComponentMask); |
| 88 | memcpy(fSwizzle, access.getSwizzle(), 5); |
| 89 | } |
| 90 | |
| 91 | UniformHandle samplerUniform() const { return fSamplerUniform; } |
| 92 | // bitfield of GrColorComponentFlags present in the texture's config. |
| 93 | uint32_t configComponentMask() const { return fConfigComponentMask; } |
| 94 | const char* swizzle() const { return fSwizzle; } |
| 95 | |
| 96 | private: |
| 97 | UniformHandle fSamplerUniform; |
| 98 | uint32_t fConfigComponentMask; |
| 99 | char fSwizzle[5]; |
| 100 | }; |
| 101 | |
| 102 | typedef SkTArray<TextureSampler> TextureSamplerArray; |
| 103 | |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 104 | protected: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 105 | |
bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 106 | /** |
| 107 | * Helpers for GenEffectMetaKey. |
| 108 | */ |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 109 | static uint32_t GenAttribKey(const GrDrawEffect&); |
| 110 | static uint32_t GenTransformKey(const GrDrawEffect&); |
| 111 | static uint32_t GenTextureKey(const GrDrawEffect&, const GrGLCaps&); |
bsalomon | 929f29a | 2014-07-17 07:55:11 -0700 | [diff] [blame] | 112 | |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 113 | GrGLProgramEffects(int reserveCount) |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 114 | : fGLEffects(reserveCount) |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 115 | , fSamplers(reserveCount) { |
| 116 | } |
| 117 | |
| 118 | /** |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 119 | * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's texture accesses and |
| 120 | * appends the necessary data to the TextureSamplerArray* object so effects can add texture |
| 121 | * lookups to their code. This method is only meant to be called during the construction phase. |
| 122 | */ |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 123 | void emitSamplers(GrGLProgramBuilder*, const GrEffect*, TextureSamplerArray*); |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 124 | |
| 125 | /** |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 126 | * Helper for setData(). Binds all the textures for an effect. |
| 127 | */ |
bsalomon | f99f884 | 2014-07-07 11:54:23 -0700 | [diff] [blame] | 128 | void bindTextures(GrGpuGL*, const GrEffect*, int effectIdx); |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 129 | |
| 130 | struct Sampler { |
| 131 | SkDEBUGCODE(Sampler() : fTextureUnit(-1) {}) |
| 132 | UniformHandle fUniform; |
| 133 | int fTextureUnit; |
| 134 | }; |
| 135 | |
| 136 | SkTArray<GrGLEffect*> fGLEffects; |
| 137 | SkTArray<SkSTArray<4, Sampler, true> > fSamplers; |
commit-bot@chromium.org | a05fa06 | 2014-05-30 18:55:03 +0000 | [diff] [blame] | 138 | |
| 139 | private: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 140 | friend class GrGLFragmentO; |
commit-bot@chromium.org | a05fa06 | 2014-05-30 18:55:03 +0000 | [diff] [blame] | 141 | typedef SkRefCnt INHERITED; |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | /** |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 145 | * This is an abstract base class for constructing different types of GrGLProgramEffects objects. |
| 146 | */ |
| 147 | class GrGLProgramEffectsBuilder { |
| 148 | public: |
mtklein@google.com | f1077f9 | 2013-11-20 15:13:49 +0000 | [diff] [blame] | 149 | virtual ~GrGLProgramEffectsBuilder() { } |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 150 | /** |
| 151 | * Emits the effect's shader code, and stores the necessary uniforms internally. |
| 152 | */ |
| 153 | virtual void emitEffect(const GrEffectStage&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 154 | const GrEffectKey&, |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 155 | const char* outColor, |
| 156 | const char* inColor, |
| 157 | int stageIndex) = 0; |
| 158 | }; |
| 159 | |
| 160 | //////////////////////////////////////////////////////////////////////////////// |
| 161 | |
| 162 | /** |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 163 | * This is a GrGLProgramEffects implementation that does coord transforms with the vertex shader. |
| 164 | */ |
| 165 | class GrGLVertexProgramEffects : public GrGLProgramEffects { |
| 166 | public: |
| 167 | virtual void setData(GrGpuGL*, |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 168 | const GrGLProgramDataManager&, |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 169 | const GrEffectStage* effectStages[]) SK_OVERRIDE; |
| 170 | |
| 171 | private: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 172 | friend class GrGLFullProgramBuilder; |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 173 | |
| 174 | GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) |
| 175 | : INHERITED(reserveCount) |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 176 | , fTransforms(reserveCount) |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 177 | , fHasExplicitLocalCoords(explicitLocalCoords) { |
| 178 | } |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 179 | /** |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 180 | * This method is meant to only be called during the construction phase. |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 181 | */ |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 182 | void emitEffect(GrGLFullProgramBuilder*, |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 183 | const GrEffectStage&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 184 | const GrEffectKey&, |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 185 | const char* outColor, |
| 186 | const char* inColor, |
| 187 | int stageIndex); |
| 188 | |
| 189 | /** |
| 190 | * Helper for emitEffect(). Emits any attributes an effect may have. |
| 191 | */ |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 192 | void emitAttributes(GrGLFullProgramBuilder*, const GrEffectStage&); |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * Helper for emitEffect(). Emits code to implement an effect's coord transforms in the VS. |
| 196 | * Varyings are added as an outputs of the VS and inputs to the FS. The varyings may be either a |
| 197 | * vec2f or vec3f depending upon whether perspective interpolation is required or not. The names |
| 198 | * 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 emitCode() function. |
| 200 | */ |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 201 | void emitTransforms(GrGLFullProgramBuilder*, |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 202 | const GrDrawEffect&, |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 203 | TransformedCoordsArray*); |
| 204 | |
| 205 | /** |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 206 | * Helper for setData(). Sets all the transform matrices for an effect. |
| 207 | */ |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 208 | void setTransformData(const GrGLProgramDataManager&, const GrDrawEffect&, int effectIdx); |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 209 | |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 210 | struct Transform { |
| 211 | Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
| 212 | UniformHandle fHandle; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 213 | SkMatrix fCurrentValue; |
| 214 | }; |
| 215 | |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 216 | SkTArray<SkSTArray<2, Transform, true> > fTransforms; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 217 | bool fHasExplicitLocalCoords; |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 218 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 219 | friend class GrGLVertexProgramEffectsBuilder; |
| 220 | |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 221 | typedef GrGLProgramEffects INHERITED; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 224 | /** |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 225 | * This class is used to construct a GrGLVertexProgramEffects* object. |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 226 | */ |
| 227 | class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder { |
| 228 | public: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 229 | GrGLVertexProgramEffectsBuilder(GrGLFullProgramBuilder*, int reserveCount); |
mtklein@google.com | f1077f9 | 2013-11-20 15:13:49 +0000 | [diff] [blame] | 230 | virtual ~GrGLVertexProgramEffectsBuilder() { } |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 231 | virtual void emitEffect(const GrEffectStage&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 232 | const GrEffectKey&, |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 233 | const char* outColor, |
| 234 | const char* inColor, |
| 235 | int stageIndex) SK_OVERRIDE; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 236 | /** |
| 237 | * Finalizes the building process and returns the effect array. After this call, the builder |
| 238 | * becomes invalid. |
| 239 | */ |
| 240 | GrGLProgramEffects* finish() { return fProgramEffects.detach(); } |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 241 | private: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 242 | GrGLFullProgramBuilder* fBuilder; |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 243 | SkAutoTDelete<GrGLVertexProgramEffects> fProgramEffects; |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 244 | typedef GrGLProgramEffectsBuilder INHERITED; |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 247 | //////////////////////////////////////////////////////////////////////////////// |
| 248 | |
| 249 | /** |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 250 | * This is a GrGLProgramEffects implementation that does coord transforms with |
| 251 | * the the NV_path_rendering PathTexGen functionality. |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 252 | */ |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 253 | class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 254 | public: |
| 255 | virtual void setData(GrGpuGL*, |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 256 | const GrGLProgramDataManager&, |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 257 | const GrEffectStage* effectStages[]) SK_OVERRIDE; |
| 258 | |
| 259 | private: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 260 | friend class GrGLFragmentOnlyProgramBuilder; |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 261 | |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 262 | GrGLPathTexGenProgramEffects(int reserveCount) |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 263 | : INHERITED(reserveCount) |
| 264 | , fTransforms(reserveCount) { |
| 265 | } |
| 266 | |
| 267 | /** |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 268 | * This method is meant to only be called during the construction phase. |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 269 | */ |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 270 | void emitEffect(GrGLFragmentOnlyProgramBuilder*, |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 271 | const GrEffectStage&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 272 | const GrEffectKey&, |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 273 | const char* outColor, |
| 274 | const char* inColor, |
| 275 | int stageIndex); |
| 276 | |
| 277 | /** |
| 278 | * Helper for emitEffect(). Allocates texture units from the builder for each transform in an |
| 279 | * effect. The transforms all use adjacent texture units. They either use two or three of the |
| 280 | * coordinates at a given texture unit, depending on if they need perspective interpolation. |
| 281 | * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[0])') as well as the |
| 282 | * types are appended to the TransformedCoordsArray* object, which is in turn passed to the |
| 283 | * effect's emitCode() function. |
| 284 | */ |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 285 | void setupPathTexGen(GrGLFragmentOnlyProgramBuilder*, |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 286 | const GrDrawEffect&, |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 287 | TransformedCoordsArray*); |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 288 | |
| 289 | /** |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 290 | * Helper for setData(). Sets the PathTexGen state for each transform in an effect. |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 291 | */ |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 292 | void setPathTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx); |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 293 | |
| 294 | struct Transforms { |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 295 | Transforms(uint32_t transformKey, int texCoordIndex) |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 296 | : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {} |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 297 | uint32_t fTransformKey; |
| 298 | int fTexCoordIndex; |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | SkTArray<Transforms> fTransforms; |
| 302 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 303 | friend class GrGLPathTexGenProgramEffectsBuilder; |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 304 | typedef GrGLProgramEffects INHERITED; |
| 305 | }; |
| 306 | |
| 307 | /** |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 308 | * This class is used to construct a GrGLPathTexGenProgramEffects* object. |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 309 | */ |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 310 | class GrGLPathTexGenProgramEffectsBuilder : public GrGLProgramEffectsBuilder { |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 311 | public: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 312 | GrGLPathTexGenProgramEffectsBuilder(GrGLFragmentOnlyProgramBuilder*, int reserveCount); |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 313 | virtual ~GrGLPathTexGenProgramEffectsBuilder() { } |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 314 | virtual void emitEffect(const GrEffectStage&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 315 | const GrEffectKey&, |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 316 | const char* outColor, |
| 317 | const char* inColor, |
| 318 | int stageIndex) SK_OVERRIDE; |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 319 | /** |
| 320 | * Finalizes the building process and returns the effect array. After this call, the builder |
| 321 | * becomes invalid. |
| 322 | */ |
| 323 | GrGLProgramEffects* finish() { return fProgramEffects.detach(); } |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 324 | private: |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 325 | GrGLFragmentOnlyProgramBuilder* fBuilder; |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 326 | SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 327 | typedef GrGLProgramEffectsBuilder INHERITED; |
| 328 | }; |
| 329 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame^] | 330 | |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 331 | #endif |