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