bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 GrGLShaderVar_DEFINED |
| 9 | #define GrGLShaderVar_DEFINED |
| 10 | |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 11 | #include "GrGLContextInfo.h" |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 12 | #include "GrGLSL.h" |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 13 | #include "SkString.h" |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 14 | |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 15 | #define USE_UNIFORM_FLOAT_ARRAYS true |
| 16 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 17 | /** |
| 18 | * Represents a variable in a shader |
| 19 | */ |
| 20 | class GrGLShaderVar { |
| 21 | public: |
| 22 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 23 | /** |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 24 | * Early versions of GLSL have Varying and Attribute; those are later |
| 25 | * deprecated, but we still need to know whether a Varying variable |
| 26 | * should be treated as In or Out. |
| 27 | */ |
| 28 | enum TypeModifier { |
| 29 | kNone_TypeModifier, |
| 30 | kOut_TypeModifier, |
| 31 | kIn_TypeModifier, |
| 32 | kUniform_TypeModifier, |
| 33 | kAttribute_TypeModifier |
| 34 | }; |
| 35 | |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 36 | enum Precision { |
| 37 | kLow_Precision, // lowp |
| 38 | kMedium_Precision, // mediump |
| 39 | kHigh_Precision, // highp |
| 40 | kDefault_Precision, // Default for the current context. We make |
| 41 | // fragment shaders default to mediump on ES2 |
| 42 | // because highp support is not guaranteed (and |
| 43 | // we haven't been motivated to test for it). |
| 44 | // Otherwise, highp. |
| 45 | }; |
| 46 | |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 47 | /** |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 48 | * Defaults to a float with no precision specifier |
| 49 | */ |
| 50 | GrGLShaderVar() { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 51 | fType = kFloat_GrSLType; |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 52 | fTypeModifier = kNone_TypeModifier; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 53 | fCount = kNonArray; |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 54 | fPrecision = kDefault_Precision; |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 55 | fUseUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | GrGLShaderVar(const GrGLShaderVar& var) |
| 59 | : fType(var.fType) |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 60 | , fTypeModifier(var.fTypeModifier) |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 61 | , fName(var.fName) |
| 62 | , fCount(var.fCount) |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 63 | , fPrecision(var.fPrecision) |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 64 | , fUseUniformFloatArrays(var.fUseUniformFloatArrays) {} |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Values for array count that have special meaning. We allow 1-sized arrays. |
| 68 | */ |
| 69 | enum { |
| 70 | kNonArray = 0, // not an array |
| 71 | kUnsizedArray = -1, // an unsized array (declared with []) |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * Sets as a non-array. |
| 76 | */ |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 77 | void set(GrSLType type, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 78 | TypeModifier typeModifier, |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 79 | const SkString& name, |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 80 | Precision precision = kDefault_Precision, |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 81 | bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 82 | fType = type; |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 83 | fTypeModifier = typeModifier; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 84 | fName = name; |
| 85 | fCount = kNonArray; |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 86 | fPrecision = precision; |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 87 | fUseUniformFloatArrays = useUniformFloatArrays; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Sets as a non-array. |
| 92 | */ |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 93 | void set(GrSLType type, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 94 | TypeModifier typeModifier, |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 95 | const char* name, |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 96 | Precision precision = kDefault_Precision, |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 97 | bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 98 | fType = type; |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 99 | fTypeModifier = typeModifier; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 100 | fName = name; |
| 101 | fCount = kNonArray; |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 102 | fPrecision = precision; |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 103 | fUseUniformFloatArrays = useUniformFloatArrays; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Set all var options |
| 108 | */ |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 109 | void set(GrSLType type, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 110 | TypeModifier typeModifier, |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 111 | const SkString& name, |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 112 | int count, |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 113 | Precision precision = kDefault_Precision, |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 114 | bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 115 | fType = type; |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 116 | fTypeModifier = typeModifier; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 117 | fName = name; |
| 118 | fCount = count; |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 119 | fPrecision = precision; |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 120 | fUseUniformFloatArrays = useUniformFloatArrays; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Set all var options |
| 125 | */ |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 126 | void set(GrSLType type, |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 127 | TypeModifier typeModifier, |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 128 | const char* name, |
| 129 | int count, |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 130 | Precision precision = kDefault_Precision, |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 131 | bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 132 | fType = type; |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 133 | fTypeModifier = typeModifier; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 134 | fName = name; |
| 135 | fCount = count; |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 136 | fPrecision = precision; |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 137 | fUseUniformFloatArrays = useUniformFloatArrays; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Is the var an array. |
| 142 | */ |
| 143 | bool isArray() const { return kNonArray != fCount; } |
| 144 | /** |
| 145 | * Is this an unsized array, (i.e. declared with []). |
| 146 | */ |
| 147 | bool isUnsizedArray() const { return kUnsizedArray == fCount; } |
| 148 | /** |
| 149 | * Get the array length of the var. |
| 150 | */ |
| 151 | int getArrayCount() const { return fCount; } |
| 152 | /** |
| 153 | * Set the array length of the var |
| 154 | */ |
| 155 | void setArrayCount(int count) { fCount = count; } |
| 156 | /** |
| 157 | * Set to be a non-array. |
| 158 | */ |
| 159 | void setNonArray() { fCount = kNonArray; } |
| 160 | /** |
| 161 | * Set to be an unsized array. |
| 162 | */ |
| 163 | void setUnsizedArray() { fCount = kUnsizedArray; } |
| 164 | |
| 165 | /** |
| 166 | * Access the var name as a writable string |
| 167 | */ |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 168 | SkString* accessName() { return &fName; } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 169 | /** |
| 170 | * Set the var name |
| 171 | */ |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 172 | void setName(const SkString& n) { fName = n; } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 173 | void setName(const char* n) { fName = n; } |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame^] | 174 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 175 | /** |
| 176 | * Get the var name. |
| 177 | */ |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 178 | const SkString& getName() const { return fName; } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 179 | |
| 180 | /** |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame^] | 181 | * Shortcut for this->getName().c_str(); |
| 182 | */ |
| 183 | const char* c_str() const { return this->getName().c_str(); } |
| 184 | |
| 185 | /** |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 186 | * Get the type of the var |
| 187 | */ |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 188 | GrSLType getType() const { return fType; } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 189 | /** |
| 190 | * Set the type of the var |
| 191 | */ |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 192 | void setType(GrSLType type) { fType = type; } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 193 | |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 194 | TypeModifier getTypeModifier() const { return fTypeModifier; } |
| 195 | void setTypeModifier(TypeModifier type) { fTypeModifier = type; } |
| 196 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 197 | /** |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 198 | * Get the precision of the var |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 199 | */ |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 200 | Precision getPrecision() const { return fPrecision; } |
| 201 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 202 | /** |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 203 | * Set the precision of the var |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 204 | */ |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 205 | void setPrecision(Precision p) { fPrecision = p; } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * Write a declaration of this variable to out. |
| 209 | */ |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 210 | void appendDecl(const GrGLContextInfo& gl, SkString* out) const { |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 211 | if (this->getTypeModifier() != kNone_TypeModifier) { |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 212 | out->append(TypeModifierString(this->getTypeModifier(), |
| 213 | gl.glslGeneration())); |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 214 | out->append(" "); |
| 215 | } |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 216 | out->append(PrecisionString(fPrecision, gl.binding())); |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 217 | GrSLType effectiveType = this->getType(); |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 218 | if (this->isArray()) { |
| 219 | if (this->isUnsizedArray()) { |
| 220 | out->appendf("%s %s[]", |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 221 | TypeString(effectiveType), |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 222 | this->getName().c_str()); |
| 223 | } else { |
| 224 | GrAssert(this->getArrayCount() > 0); |
| 225 | out->appendf("%s %s[%d]", |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 226 | TypeString(effectiveType), |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 227 | this->getName().c_str(), |
| 228 | this->getArrayCount()); |
| 229 | } |
| 230 | } else { |
| 231 | out->appendf("%s %s", |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 232 | TypeString(effectiveType), |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 233 | this->getName().c_str()); |
| 234 | } |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 235 | out->append(";\n"); |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 236 | } |
| 237 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 238 | static const char* TypeString(GrSLType t) { |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 239 | switch (t) { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 240 | case kFloat_GrSLType: |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 241 | return "float"; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 242 | case kVec2f_GrSLType: |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 243 | return "vec2"; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 244 | case kVec3f_GrSLType: |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 245 | return "vec3"; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 246 | case kVec4f_GrSLType: |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 247 | return "vec4"; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 248 | case kMat33f_GrSLType: |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 249 | return "mat3"; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 250 | case kMat44f_GrSLType: |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 251 | return "mat4"; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 252 | case kSampler2D_GrSLType: |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 253 | return "sampler2D"; |
| 254 | default: |
| 255 | GrCrash("Unknown shader var type."); |
| 256 | return ""; // suppress warning |
| 257 | } |
| 258 | } |
| 259 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 260 | void appendArrayAccess(int index, SkString* out) const { |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 261 | out->appendf("%s[%d]%s", |
| 262 | this->getName().c_str(), |
| 263 | index, |
| 264 | fUseUniformFloatArrays ? "" : ".x"); |
| 265 | } |
| 266 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 267 | void appendArrayAccess(const char* indexName, SkString* out) const { |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 268 | out->appendf("%s[%s]%s", |
| 269 | this->getName().c_str(), |
| 270 | indexName, |
| 271 | fUseUniformFloatArrays ? "" : ".x"); |
| 272 | } |
| 273 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 274 | private: |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 275 | static const char* TypeModifierString(TypeModifier t, GrGLSLGeneration gen) { |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 276 | switch (t) { |
| 277 | case kNone_TypeModifier: |
| 278 | return ""; |
| 279 | case kOut_TypeModifier: |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 280 | return k110_GrGLSLGeneration == gen ? "varying" : "out"; |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 281 | case kIn_TypeModifier: |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 282 | return k110_GrGLSLGeneration == gen ? "varying" : "in"; |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 283 | case kUniform_TypeModifier: |
| 284 | return "uniform"; |
| 285 | case kAttribute_TypeModifier: |
bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 286 | return k110_GrGLSLGeneration == gen ? "attribute" : "in"; |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 287 | default: |
| 288 | GrCrash("Unknown shader variable type modifier."); |
| 289 | return ""; // suppress warning |
| 290 | } |
| 291 | } |
| 292 | |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 293 | static const char* PrecisionString(Precision p, GrGLBinding binding) { |
| 294 | // Desktop GLSL has added precision qualifiers but they don't do anything. |
| 295 | if (kES2_GrGLBinding == binding) { |
| 296 | switch (p) { |
| 297 | case kLow_Precision: |
| 298 | return "lowp "; |
| 299 | case kMedium_Precision: |
| 300 | return "mediump "; |
| 301 | case kHigh_Precision: |
| 302 | return "highp "; |
| 303 | case kDefault_Precision: |
| 304 | return ""; |
| 305 | default: |
| 306 | GrCrash("Unexpected precision type."); |
| 307 | } |
| 308 | } |
| 309 | return ""; |
| 310 | } |
| 311 | |
| 312 | GrSLType fType; |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 313 | TypeModifier fTypeModifier; |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 314 | SkString fName; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 315 | int fCount; |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 316 | Precision fPrecision; |
tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 317 | /// Work around driver bugs on some hardware that don't correctly |
| 318 | /// support uniform float [] |
| 319 | bool fUseUniformFloatArrays; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 320 | }; |
| 321 | |
| 322 | #endif |