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