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