blob: 6e990aad01b17c56150221d47cda0b869a250545 [file] [log] [blame]
tomhudson@google.comf9ad8862012-05-11 20:38:48 +00001/*
2 * Copyright 2012 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 GrGLShaderBuilder_DEFINED
9#define GrGLShaderBuilder_DEFINED
10
11#include "GrAllocator.h"
bsalomon@google.com2eaaefd2012-10-29 19:51:22 +000012#include "GrBackendEffectFactory.h"
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000013#include "GrColor.h"
bsalomon@google.coma469c282012-10-24 18:28:34 +000014#include "GrEffect.h"
tomhudson@google.comf9ad8862012-05-11 20:38:48 +000015#include "gl/GrGLSL.h"
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000016#include "gl/GrGLUniformManager.h"
tomhudson@google.comf9ad8862012-05-11 20:38:48 +000017
bsalomon@google.comf910d3b2013-03-07 17:06:57 +000018#include <stdarg.h>
19
bsalomon@google.comad5e9372012-07-11 18:11:27 +000020class GrGLContextInfo;
bsalomon@google.comc7818882013-03-20 19:19:53 +000021class GrEffectStage;
bsalomon@google.com26e18b52013-03-29 19:22:36 +000022class GrGLProgramDesc;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000023
tomhudson@google.comf9ad8862012-05-11 20:38:48 +000024/**
bsalomon@google.comeb715c82012-07-11 15:03:31 +000025 Contains all the incremental state of a shader as it is being built,as well as helpers to
26 manipulate that state.
tomhudson@google.comf9ad8862012-05-11 20:38:48 +000027*/
tomhudson@google.comf9ad8862012-05-11 20:38:48 +000028class GrGLShaderBuilder {
tomhudson@google.comf9ad8862012-05-11 20:38:48 +000029public:
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000030 /**
bsalomon@google.com34cccde2013-01-04 18:34:30 +000031 * Passed to GrGLEffects to add texture reads to their shader code.
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000032 */
33 class TextureSampler {
34 public:
35 TextureSampler()
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000036 : fConfigComponentMask(0)
37 , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) {
38 // we will memcpy the first 4 bytes from passed in swizzle. This ensures the string is
39 // terminated.
40 fSwizzle[4] = '\0';
41 }
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000042
43 TextureSampler(const TextureSampler& other) { *this = other; }
44
45 TextureSampler& operator= (const TextureSampler& other) {
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000046 GrAssert(0 == fConfigComponentMask);
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000047 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform);
48
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000049 fConfigComponentMask = other.fConfigComponentMask;
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000050 fSamplerUniform = other.fSamplerUniform;
51 return *this;
52 }
53
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000054 // bitfield of GrColorComponentFlags present in the texture's config.
55 uint32_t configComponentMask() const { return fConfigComponentMask; }
56
57 const char* swizzle() const { return fSwizzle; }
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000058
bsalomon@google.com26e18b52013-03-29 19:22:36 +000059 bool isInitialized() const { return 0 != fConfigComponentMask; }
60
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000061 private:
bsalomon@google.com34cccde2013-01-04 18:34:30 +000062 // The idx param is used to ensure multiple samplers within a single effect have unique
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000063 // uniform names. swizzle is a four char max string made up of chars 'r', 'g', 'b', and 'a'.
64 void init(GrGLShaderBuilder* builder,
65 uint32_t configComponentMask,
66 const char* swizzle,
67 int idx) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +000068 GrAssert(!this->isInitialized());
69 GrAssert(0 != configComponentMask);
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000070 GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform);
71
72 GrAssert(NULL != builder);
bsalomon@google.com34cccde2013-01-04 18:34:30 +000073 SkString name;
bsalomon@google.com504976e2013-05-09 13:45:02 +000074 name.printf("Sampler%d", idx);
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000075 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
76 kSampler2D_GrSLType,
bsalomon@google.com34cccde2013-01-04 18:34:30 +000077 name.c_str());
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000078 GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUniform);
79
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000080 fConfigComponentMask = configComponentMask;
81 memcpy(fSwizzle, swizzle, 4);
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000082 }
83
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000084 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) {
85 GrAssert(NULL != access);
86 this->init(builder,
87 GrPixelConfigComponentMask(access->getTexture()->config()),
88 access->getSwizzle(),
89 idx);
90 }
91
92 uint32_t fConfigComponentMask;
93 char fSwizzle[5];
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000094 GrGLUniformManager::UniformHandle fSamplerUniform;
95
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000096 friend class GrGLShaderBuilder; // to call init().
bsalomon@google.comf06df1b2012-09-06 20:22:31 +000097 };
98
99 typedef SkTArray<TextureSampler> TextureSamplerArray;
100
bsalomon@google.comeb715c82012-07-11 15:03:31 +0000101 enum ShaderType {
102 kVertex_ShaderType = 0x1,
103 kGeometry_ShaderType = 0x2,
104 kFragment_ShaderType = 0x4,
105 };
106
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000107 GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&, const GrGLProgramDesc&);
tomhudson@google.comf9ad8862012-05-11 20:38:48 +0000108
bsalomon@google.comf910d3b2013-03-07 17:06:57 +0000109 /**
bsalomon@google.com42eff162013-04-02 12:50:49 +0000110 * Use of these features may require a GLSL extension to be enabled. Shaders may not compile
111 * if code is added that uses one of these features without calling enableFeature()
112 */
113 enum GLSLFeature {
114 kStandardDerivatives_GLSLFeature = 0,
115
116 kLastGLSLFeature = kStandardDerivatives_GLSLFeature
117 };
118
119 /**
120 * If the feature is supported then true is returned and any necessary #extension declarations
121 * are added to the shaders. If the feature is not supported then false will be returned.
122 */
123 bool enableFeature(GLSLFeature);
124
125 /**
bsalomon@google.comf910d3b2013-03-07 17:06:57 +0000126 * Called by GrGLEffects to add code to one of the shaders.
127 */
128 void vsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
129 va_list args;
130 va_start(args, format);
131 this->codeAppendf(kVertex_ShaderType, format, args);
132 va_end(args);
133 }
134
135 void gsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
136 va_list args;
137 va_start(args, format);
138 this->codeAppendf(kGeometry_ShaderType, format, args);
139 va_end(args);
140 }
141
142 void fsCodeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
143 va_list args;
144 va_start(args, format);
145 this->codeAppendf(kFragment_ShaderType, format, args);
146 va_end(args);
147 }
148
149 void vsCodeAppend(const char* str) { this->codeAppend(kVertex_ShaderType, str); }
150 void gsCodeAppend(const char* str) { this->codeAppend(kGeometry_ShaderType, str); }
151 void fsCodeAppend(const char* str) { this->codeAppend(kFragment_ShaderType, str); }
152
bsalomon@google.comdbe49f72012-11-05 16:36:02 +0000153 /** Appends a 2D texture sample with projection if necessary. coordType must either be Vec2f or
154 Vec3f. The latter is interpreted as projective texture coords. The vec length and swizzle
155 order of the result depends on the GrTextureAccess associated with the TextureSampler. */
bsalomon@google.com868a8e72012-08-30 19:11:34 +0000156 void appendTextureLookup(SkString* out,
bsalomon@google.comf06df1b2012-09-06 20:22:31 +0000157 const TextureSampler&,
bsalomon@google.comdbe49f72012-11-05 16:36:02 +0000158 const char* coordName,
bsalomon@google.com868a8e72012-08-30 19:11:34 +0000159 GrSLType coordType = kVec2f_GrSLType) const;
tomhudson@google.com52598142012-05-24 17:44:30 +0000160
bsalomon@google.comf910d3b2013-03-07 17:06:57 +0000161 /** Version of above that appends the result to the shader code rather than an SkString.
162 Currently the shader type must be kFragment */
163 void appendTextureLookup(ShaderType,
164 const TextureSampler&,
165 const char* coordName,
166 GrSLType coordType = kVec2f_GrSLType);
167
168
bsalomon@google.com2d8edaf2012-09-07 14:47:31 +0000169 /** Does the work of appendTextureLookup and modulates the result by modulation. The result is
170 always a vec4. modulation and the swizzle specified by TextureSampler must both be vec4 or
171 float. If modulation is "" or NULL it this function acts as though appendTextureLookup were
172 called. */
bsalomon@google.comf910d3b2013-03-07 17:06:57 +0000173 void appendTextureLookupAndModulate(ShaderType,
bsalomon@google.com868a8e72012-08-30 19:11:34 +0000174 const char* modulation,
bsalomon@google.comf06df1b2012-09-06 20:22:31 +0000175 const TextureSampler&,
bsalomon@google.comdbe49f72012-11-05 16:36:02 +0000176 const char* coordName,
bsalomon@google.comf910d3b2013-03-07 17:06:57 +0000177 GrSLType coordType = kVec2f_GrSLType);
bsalomon@google.com34bcb9f2012-08-28 18:20:18 +0000178
bsalomon@google.coma1bf0ff2012-08-07 17:36:29 +0000179 /** Emits a helper function outside of main(). Currently ShaderType must be
180 kFragment_ShaderType. */
181 void emitFunction(ShaderType shader,
182 GrSLType returnType,
183 const char* name,
184 int argCnt,
185 const GrGLShaderVar* args,
186 const char* body,
187 SkString* outName);
188
bsalomon@google.com46fba0d2012-10-25 21:42:05 +0000189 /** Generates a EffectKey for the shader code based on the texture access parameters and the
twiz@google.coma5e65ec2012-08-02 15:15:16 +0000190 capabilities of the GL context. This is useful for keying the shader programs that may
191 have multiple representations, based on the type/format of textures used. */
bsalomon@google.com2eaaefd2012-10-29 19:51:22 +0000192 static GrBackendEffectFactory::EffectKey KeyForTextureAccess(const GrTextureAccess&,
193 const GrGLCaps&);
twiz@google.coma5e65ec2012-08-02 15:15:16 +0000194
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000195 typedef uint8_t DstReadKey;
196
197 /** Returns a key for adding code to read the copy-of-dst color in service of effects that
198 require reading the dst. It must not return 0 because 0 indicates that there is no dst
199 copy read at all. */
200 static DstReadKey KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps&);
201
bsalomon@google.com6d003d12012-09-11 15:45:20 +0000202 /** If texture swizzling is available using tex parameters then it is preferred over mangling
203 the generated shader code. This potentially allows greater reuse of cached shaders. */
204 static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCaps& caps);
205
bsalomon@google.com706f6682012-10-23 14:53:55 +0000206 /** Add a uniform variable to the current program, that has visibility in one or more shaders.
bsalomon@google.com777c3aa2012-07-25 20:58:20 +0000207 visibility is a bitfield of ShaderType values indicating from which shaders the uniform
208 should be accessible. At least one bit must be set. Geometry shader uniforms are not
209 supported at this time. The actual uniform name will be mangled. If outName is not NULL then
210 it will refer to the final uniform name after return. Use the addUniformArray variant to add
211 an array of uniforms.
tomhudson@google.com242ed6f2012-05-30 17:38:57 +0000212 */
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000213 GrGLUniformManager::UniformHandle addUniform(uint32_t visibility,
214 GrSLType type,
215 const char* name,
bsalomon@google.com777c3aa2012-07-25 20:58:20 +0000216 const char** outName = NULL) {
217 return this->addUniformArray(visibility, type, name, GrGLShaderVar::kNonArray, outName);
218 }
219 GrGLUniformManager::UniformHandle addUniformArray(uint32_t visibility,
220 GrSLType type,
221 const char* name,
222 int arrayCount,
223 const char** outName = NULL);
bsalomon@google.com032b2212012-07-16 13:36:18 +0000224
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000225 const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle) const;
bsalomon@google.com032b2212012-07-16 13:36:18 +0000226
227 /**
bsalomon@google.com706f6682012-10-23 14:53:55 +0000228 * Shortcut for getUniformVariable(u).c_str()
bsalomon@google.com032b2212012-07-16 13:36:18 +0000229 */
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000230 const char* getUniformCStr(GrGLUniformManager::UniformHandle u) const {
bsalomon@google.com032b2212012-07-16 13:36:18 +0000231 return this->getUniformVariable(u).c_str();
232 }
tomhudson@google.com242ed6f2012-05-30 17:38:57 +0000233
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000234 /** Add a vertex attribute to the current program that is passed in from the vertex data.
235 Returns false if the attribute was already there, true otherwise. */
236 bool addAttribute(GrSLType type, const char* name);
237
238 /** Add a varying variable to the current program to pass values between vertex and fragment
bsalomon@google.comeb715c82012-07-11 15:03:31 +0000239 shaders. If the last two parameters are non-NULL, they are filled in with the name
240 generated. */
tomhudson@google.com23cb2292012-05-30 18:26:03 +0000241 void addVarying(GrSLType type,
242 const char* name,
243 const char** vsOutName = NULL,
244 const char** fsInName = NULL);
245
bsalomon@google.com706f6682012-10-23 14:53:55 +0000246 /** Returns a variable name that represents the position of the fragment in the FS. The position
247 is in device space (e.g. 0,0 is the top left and pixel centers are at half-integers). */
248 const char* fragmentPosition();
249
bsalomon@google.com17504f52012-10-30 12:34:25 +0000250 /** Returns a vertex attribute that represents the vertex position in the VS. This is the
251 pre-matrix position and is commonly used by effects to compute texture coords via a matrix.
252 */
253 const GrGLShaderVar& positionAttribute() const { return *fPositionVar; }
254
bsalomon@google.comc7818882013-03-20 19:19:53 +0000255 /** Returns a vertex attribute that represents the local coords in the VS. This may be the same
256 as positionAttribute() or it may not be. It depends upon whether the rendering code
257 specified explicit local coords or not in the GrDrawState. */
258 const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar; }
259
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000260 /** Returns the color of the destination pixel. This may be NULL if no effect advertised
261 that it will read the destination. */
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000262 const char* dstColor();
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000263
bsalomon@google.comc7818882013-03-20 19:19:53 +0000264 /**
265 * Are explicit local coordinates provided as input to the vertex shader.
266 */
267 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVar); }
268
bsalomon@google.com34cccde2013-01-04 18:34:30 +0000269 /**
270 * Interfaces used by GrGLProgram.
271 * TODO: Hide these from the GrEffects using friend or splitting this into two related classes.
272 * Also, GrGLProgram's shader string construction should be moved to this class.
273 */
274
bsalomon@google.comad5e9372012-07-11 18:11:27 +0000275 /** Called after building is complete to get the final shader string. */
276 void getShader(ShaderType, SkString*) const;
277
bsalomon@google.com504976e2013-05-09 13:45:02 +0000278 /**
279 * Adds code for effects. effectStages contains the effects to add. effectKeys[i] is the key
280 * generated from effectStages[i]. An entry in effectStages can be NULL, in which case it is
281 * skipped. Moreover, if the corresponding key is GrGLEffect::NoEffectKey then it is skipped.
282 * inOutFSColor specifies the input color to the first stage and is updated to be the
283 * output color of the last stage. fsInOutColorKnownValue specifies whether the input color
284 * has a known constant value and is updated to refer to the status of the output color.
285 * The handles to texture samplers for effectStage[i] are added to effectSamplerHandles[i]. The
286 * glEffects array is updated to contain the GrGLEffect generated for each entry in
287 * effectStages.
288 */
289 void emitEffects(const GrEffectStage* effectStages[],
290 const GrBackendEffectFactory::EffectKey effectKeys[],
291 int effectCnt,
292 SkString* inOutFSColor,
293 GrSLConstantVec* fsInOutColorKnownValue,
294 SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[],
295 GrGLEffect* glEffects[]);
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000296
bsalomon@google.com706f6682012-10-23 14:53:55 +0000297 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000298 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const {
299 return fDstCopyTopLeftUniform;
300 }
301 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const {
302 return fDstCopyScaleUniform;
303 }
304 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const {
305 return fDstCopySampler.fSamplerUniform;
306 }
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000307
308 struct AttributePair {
309 void set(int index, const SkString& name) {
310 fIndex = index; fName = name;
311 }
312 int fIndex;
313 SkString fName;
314 };
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000315 const SkTArray<AttributePair, true>& getEffectAttributes() const {
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000316 return fEffectAttributes;
317 }
318 const SkString* getEffectAttributeName(int attributeIndex) const;
319
bsalomon@google.com34cccde2013-01-04 18:34:30 +0000320 // TODO: Make this do all the compiling, linking, etc.
321 void finished(GrGLuint programID);
bsalomon@google.com706f6682012-10-23 14:53:55 +0000322
robertphillips@google.com13f181f2013-03-02 12:02:08 +0000323 const GrGLContextInfo& ctxInfo() const { return fCtxInfo; }
324
bsalomon@google.com032b2212012-07-16 13:36:18 +0000325private:
bsalomon@google.comf910d3b2013-03-07 17:06:57 +0000326 void codeAppendf(ShaderType type, const char format[], va_list args);
327 void codeAppend(ShaderType type, const char* str);
328
bsalomon@google.com032b2212012-07-16 13:36:18 +0000329 typedef GrTAllocator<GrGLShaderVar> VarArray;
330
bsalomon@google.com032b2212012-07-16 13:36:18 +0000331 void appendDecls(const VarArray&, SkString*) const;
332 void appendUniformDecls(ShaderType, SkString*) const;
333
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000334 typedef GrGLUniformManager::BuilderUniform BuilderUniform;
335 GrGLUniformManager::BuilderUniformArray fUniforms;
bsalomon@google.com032b2212012-07-16 13:36:18 +0000336
bsalomon@google.comeb715c82012-07-11 15:03:31 +0000337 // TODO: Everything below here private.
bsalomon@google.com032b2212012-07-16 13:36:18 +0000338public:
bsalomon@google.comeb715c82012-07-11 15:03:31 +0000339
bsalomon@google.comf0a104e2012-07-10 17:51:07 +0000340 VarArray fVSAttrs;
341 VarArray fVSOutputs;
342 VarArray fGSInputs;
343 VarArray fGSOutputs;
344 VarArray fFSInputs;
345 SkString fGSHeader; // layout qualifiers specific to GS
bsalomon@google.comf0a104e2012-07-10 17:51:07 +0000346 VarArray fFSOutputs;
tomhudson@google.com040c41a2012-05-18 14:57:40 +0000347
bsalomon@google.comad5e9372012-07-11 18:11:27 +0000348private:
bsalomon@google.com504976e2013-05-09 13:45:02 +0000349 class CodeStage : GrNoncopyable {
350 public:
351 CodeStage() : fNextIndex(0), fCurrentIndex(-1), fEffectStage(NULL) {}
352
353 bool inStageCode() const {
354 this->validate();
355 return NULL != fEffectStage;
356 }
357
358 const GrEffectStage* effectStage() const {
359 this->validate();
360 return fEffectStage;
361 }
362
363 int stageIndex() const {
skia.committer@gmail.com0f20a3f2013-05-10 07:01:04 +0000364 this->validate();
bsalomon@google.com504976e2013-05-09 13:45:02 +0000365 return fCurrentIndex;
366 }
367
368 class AutoStageRestore : GrNoncopyable {
369 public:
370 AutoStageRestore(CodeStage* codeStage, const GrEffectStage* newStage) {
371 GrAssert(NULL != codeStage);
372 fSavedIndex = codeStage->fCurrentIndex;
373 fSavedEffectStage = codeStage->fEffectStage;
374
375 if (NULL == newStage) {
376 codeStage->fCurrentIndex = -1;
377 } else {
378 codeStage->fCurrentIndex = codeStage->fNextIndex++;
379 }
380 codeStage->fEffectStage = newStage;
381
382 fCodeStage = codeStage;
383 }
384 ~AutoStageRestore() {
385 fCodeStage->fCurrentIndex = fSavedIndex;
386 fCodeStage->fEffectStage = fSavedEffectStage;
387 }
388 private:
389 CodeStage* fCodeStage;
390 int fSavedIndex;
391 const GrEffectStage* fSavedEffectStage;
392 };
393 private:
394 void validate() const { GrAssert((NULL == fEffectStage) == (-1 == fCurrentIndex)); }
395 int fNextIndex;
396 int fCurrentIndex;
397 const GrEffectStage* fEffectStage;
398 } fCodeStage;
bsalomon@google.com777c3aa2012-07-25 20:58:20 +0000399
bsalomon@google.com42eff162013-04-02 12:50:49 +0000400 /**
401 * Features that should only be enabled by GrGLShaderBuilder itself.
402 */
403 enum GLSLPrivateFeature {
bsalomon@google.com6b0cf022013-05-03 13:35:14 +0000404 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1,
405 kEXTShaderFramebufferFetch_GLSLPrivateFeature,
406 kNVShaderFramebufferFetch_GLSLPrivateFeature,
bsalomon@google.com42eff162013-04-02 12:50:49 +0000407 };
408 bool enablePrivateFeature(GLSLPrivateFeature);
409
410 // If we ever have VS/GS features we can expand this to take a bitmask of ShaderType and track
411 // the enables separately for each shader.
412 void addFSFeature(uint32_t featureBit, const char* extensionName);
413
bsalomon@google.com504976e2013-05-09 13:45:02 +0000414 // Generates a name for a variable. The generated string will be name prefixed by the prefix
415 // char (unless the prefix is '\0'). It also mangles the name to be stage-specific if we're
416 // generating stage code.
417 void nameVariable(SkString* out, char prefix, const char* name);
418
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000419 // Interpretation of DstReadKey when generating code
420 enum {
421 kNoDstRead_DstReadKey = 0,
422 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read.
423 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alpha only.
424 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-left.
425 };
426
robertphillips@google.com6177e692013-02-28 20:16:25 +0000427 const GrGLContextInfo& fCtxInfo;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000428 GrGLUniformManager& fUniformManager;
bsalomon@google.com42eff162013-04-02 12:50:49 +0000429 uint32_t fFSFeaturesAddedMask;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000430 SkString fFSFunctions;
bsalomon@google.com42eff162013-04-02 12:50:49 +0000431 SkString fFSExtensions;
bsalomon@google.com706f6682012-10-23 14:53:55 +0000432
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000433 bool fUsesGS;
434
bsalomon@google.comf910d3b2013-03-07 17:06:57 +0000435 SkString fFSCode;
436 SkString fVSCode;
437 SkString fGSCode;
438
bsalomon@google.com706f6682012-10-23 14:53:55 +0000439 bool fSetupFragPosition;
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000440 TextureSampler fDstCopySampler;
441
bsalomon@google.com706f6682012-10-23 14:53:55 +0000442 GrGLUniformManager::UniformHandle fRTHeightUniform;
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000443 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform;
444 GrGLUniformManager::UniformHandle fDstCopyScaleUniform;
bsalomon@google.com34bcb9f2012-08-28 18:20:18 +0000445
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000446 SkSTArray<10, AttributePair, true> fEffectAttributes;
447
bsalomon@google.com17504f52012-10-30 12:34:25 +0000448 GrGLShaderVar* fPositionVar;
bsalomon@google.comc7818882013-03-20 19:19:53 +0000449 GrGLShaderVar* fLocalCoordsVar;
450
tomhudson@google.comf9ad8862012-05-11 20:38:48 +0000451};
452
453#endif